From 192aff6435890bd898bebc9d862858facc1e730e Mon Sep 17 00:00:00 2001 From: David Seifried Date: Fri, 3 Jun 2011 15:28:35 -0400 Subject: [PATCH] [#469] Fixed error throwing to use Popcorn.error and also switched to using setTimeout instead of setInterval as per requested --- plugins/mustache/popcorn.mustache.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/mustache/popcorn.mustache.js b/plugins/mustache/popcorn.mustache.js index a39e19b..90256d3 100644 --- a/plugins/mustache/popcorn.mustache.js +++ b/plugins/mustache/popcorn.mustache.js @@ -105,7 +105,7 @@ } else if ( typeOfTemplate === 'string' ) { template = options.template; } else { - throw 'Mustache Plugin Error: options.template must be a String or a Function.'; + Popcorn.error( 'Mustache Plugin Error: options.template must be a String or a Function.' ); } if ( typeOfData === 'function' ) { @@ -119,17 +119,19 @@ } else if ( typeOfData === 'object' ) { data = options.data; } else { - throw 'Mustache Plugin Error: options.data must be a String, Object, or Function.'; + Popcorn.error( 'Mustache Plugin Error: options.data must be a String, Object, or Function.' ); } return { start: function( event, options ) { - var interval = window.setInterval( function() { - - if( loaded ) { - - window.clearInterval( interval ); + var interval = function() { + + if( !loaded ) { + setTimeout( function() { + interval(); + }, 10 ); + } else { // if dynamic, freshen json data on every call to start, just in case. if ( getData ) { @@ -145,7 +147,10 @@ ).replace( /^\s*/mg, '' ); document.getElementById( options.target ).innerHTML = html; } - }, 10 ); + } + + interval(); + }, end: function( event, options ) { -- 2.43.0