From b05b9c34f8956f33a4286bffd044835da27163f3 Mon Sep 17 00:00:00 2001 From: David Seifried Date: Fri, 3 Jun 2011 12:02:22 -0400 Subject: [PATCH] Added a check to ensure the script was loaded before the mustache object was being accessed --- plugins/mustache/popcorn.mustache.js | 41 ++++++++++++++++++---------- 1 file changed, 26 insertions(+), 15 deletions(-) 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 ) { -- 2.43.0