]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Added a check to ensure the script was loaded before the mustache object was being...
authorDavid Seifried <david.c.seifried@gmail.com>
Fri, 3 Jun 2011 16:02:22 +0000 (12:02 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Fri, 3 Jun 2011 16:02:22 +0000 (12:02 -0400)
plugins/mustache/popcorn.mustache.js

index 97a8c769f58ffce53681afa6aff7516df5bf40bd..a39e19b63223d22e8e9e1fb1cdfe72e32e209461 100644 (file)
 
   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,
 
     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 ) {