From: David Seifried Date: Fri, 3 Jun 2011 16:02:22 +0000 (-0400) Subject: Added a check to ensure the script was loaded before the mustache object was being... X-Git-Tag: v0.7^2~52^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b05b9c34f8956f33a4286bffd044835da27163f3;p=popcorn-js.git Added a check to ensure the script was loaded before the mustache object was being accessed --- diff --git a/plugins/mustache/popcorn.mustache.js b/plugins/mustache/popcorn.mustache.js index 97a8c76..a39e19b 100644 --- a/plugins/mustache/popcorn.mustache.js +++ b/plugins/mustache/popcorn.mustache.js @@ -86,9 +86,11 @@ Popcorn.plugin( 'mustache' , function( options ) { - Popcorn.getScript('https://github.com/janl/mustache.js/raw/master/mustache.js'); + var getData, data, getTemplate, template, loaded = false; - var getData, data, getTemplate, template; + Popcorn.getScript('https://github.com/janl/mustache.js/raw/master/mustache.js', function() { + loaded = true; + }); var shouldReload = !!options.dynamic, typeOfTemplate = typeof options.template, @@ -122,19 +124,28 @@ return { start: function( event, options ) { - // if dynamic, freshen json data on every call to start, just in case. - if ( getData ) { - data = getData( options ); - } - - if ( getTemplate ) { - template = getTemplate( options ); - } - - var html = Mustache.to_html( template, - data - ).replace( /^\s*/mg, '' ); - document.getElementById( options.target ).innerHTML = html; + + var interval = window.setInterval( function() { + + if( loaded ) { + + window.clearInterval( interval ); + + // if dynamic, freshen json data on every call to start, just in case. + if ( getData ) { + data = getData( options ); + } + + if ( getTemplate ) { + template = getTemplate( options ); + } + + var html = Mustache.to_html( template, + data + ).replace( /^\s*/mg, '' ); + document.getElementById( options.target ).innerHTML = html; + } + }, 10 ); }, end: function( event, options ) {