]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#249] loading twitter widget internally
authorScottDowne <sdowne@learn.senecac.on.ca>
Mon, 10 Jan 2011 20:00:22 +0000 (15:00 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Mon, 10 Jan 2011 20:00:22 +0000 (15:00 -0500)
plugins/twitter/popcorn.twitter.html
plugins/twitter/popcorn.twitter.js

index bfa3352140bba72e03eb637343c2697c1ce2f7aa..689bb796f7b91ca35bd0511e80ddb11141b3d689 100644 (file)
@@ -4,10 +4,7 @@
   <title>Popcorn Twitter Plug-in Demo</title>
   
   <script src="../../popcorn.js"></script>
-  <!-- 
-    script "http://widgets.twimg.com/j/2/widget.js" is needed for the Twitter widget
-  -->
-  <script src="http://widgets.twimg.com/j/2/widget.js"></script>
+
   <script src="popcorn.twitter.js"></script>
   <script>
     document.addEventListener('DOMContentLoaded', function () {
@@ -33,7 +30,6 @@
 </head>
 <body>
   <h1 id="qunit-header">Popcorn Twitter Plug-in Demo</h1>
-  <p>A script src="http://widgets.twimg.com/j/2/widget.js" must be loaded before popcorn.twitter.js</p>
   <p>Twitter profile '@stevesong' widget will appear at 5 seconds and disappear at 15 seconds.</p>
   <p>More Twitter hash '#oilspill' widget will appear at 20 seconds and disappear at 45 seconds.</p>
   <div>
index 8077935f44bb24934d6cc0f6fc6bb8a7aadf840a..a5b88b2b84d8e170e2d349cc5a654e1b487d1b1f 100644 (file)
@@ -1,5 +1,14 @@
 // PLUGIN: TWITTER
 
+if ( !window.TWTR ) {
+  var head = document.getElementsByTagName("head")[0] || document.documentElement,
+      script = document.createElement("script");
+
+    script.src = "http://widgets.twimg.com/j/2/widget.js";
+
+    head.insertBefore( script, head.firstChild );
+}
+
 (function (Popcorn) {
 
   /**
             };
 
         // create widget
-        if ( profile ) {
+        var isReady = function( that ) {
+          if ( window.TWTR ) {
+            if ( profile ) {
 
-          widgetOptions.type = "profile";
+              widgetOptions.type = "profile";
 
-          new TWTR.Widget( widgetOptions ).render().setUser( src ).start();
+              new TWTR.Widget( widgetOptions ).render().setUser( src ).start();
 
-        } else if ( hash ) {
+            } else if ( hash ) {
 
-          widgetOptions.type = "search";
-          widgetOptions.search = src;
-          widgetOptions.subject = src;
+              widgetOptions.type = "search";
+              widgetOptions.search = src;
+              widgetOptions.subject = src;
 
-          new TWTR.Widget( widgetOptions ).render().start();
+              new TWTR.Widget( widgetOptions ).render().start();
 
-        }
+            }
+          } else {
+            setTimeout( function() {
+              isReady( that );
+            }, 1);
+          }
+        };
+
+        isReady( this );
       },
 
       /**