]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
made changes as per Ricks review [#158 state:peer-review-requested]
authorAnna Sobiepanek <annaopensource@gmail.com>
Mon, 20 Dec 2010 20:36:49 +0000 (15:36 -0500)
committerAnna Sobiepanek <annaopensource@gmail.com>
Mon, 20 Dec 2010 20:36:49 +0000 (15:36 -0500)
plugins/wikipedia/popcorn.wikipedia.html
plugins/wikipedia/popcorn.wikipedia.js

index 27138b4b67eeee53ac79f02382b2ae2462a60850..9c74d2fc5a6fcadf9a512c89b1be20c414c98ffe 100644 (file)
@@ -11,7 +11,7 @@
       .volume(0)
       .play() 
       .wikipedia({
-        start: 5, // seconds
+        start: 0, // seconds
         end: 10, // seconds
         src: 'http://en.wikipedia.org/wiki/Cape_Town',
         target: 'wikidiv'
@@ -29,7 +29,7 @@
 </head>
 <body>
   <h1 id="qunit-header">Popcorn WebPage Plug-in Demo</h1>
-  <p> A Wiki article about Cape Town will appear at 5 seconds and disappear at 10 seconds.</p>
+  <p> A Wiki article about Cape Town will appear at 0 seconds and disappear at 10 seconds.</p>
   <p> A Wiki article about Sao Paolo will appear at 7 seconds and disappear at 20 seconds.</p>
   <div>
     <video id='video' 
index 3295a3690e24e0878a0092f70b2eeba104e9f479..fd273e896bc121b21807ed55629249b51724341e 100644 (file)
@@ -69,21 +69,28 @@ var wikiCallback;
           _text = data.parse.text["*"].substr(data.parse.text["*"].indexOf('<p>'));
           _text = _text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "");
           options._desc.innerHTML = _text.substr(0,  options.numOfWords ) + " ...";
+          
+          options._fired = true;
         };
         
         // get the wiki article on a separate thread
         // call the wikiCallback function above once the script is loaded
-        setTimeout(function() {
-          getJson("http://"+options.lang+".wikipedia.org/w/api.php?action=parse&props=text&page=" + ( options.title || options.src.slice(options.src.lastIndexOf("/")+1)) + "&format=json&callback=wikiCallback"+ _guid);
-        }, 500);
+        //setTimeout(function() {
+         // getJson("http://"+options.lang+".wikipedia.org/w/api.php?action=parse&props=text&page=" + ( options.title || options.src.slice(options.src.lastIndexOf("/")+1)) + "&format=json&callback=wikiCallback"+ _guid);
+        //}, 500);
         
         // add the script to the DOM
-        var getJson  = function(url) {
+        /*var getJson  = function(url) {
           var head   = document.getElementsByTagName("head")[0];
           var script = document.createElement("script");
           script.src = url;
           head.insertBefore( script, head.firstChild );
-        };        
+        };  */
+          var head   = document.getElementsByTagName("head")[0];
+          var script = document.createElement("script");
+          script.src = "http://"+options.lang+".wikipedia.org/w/api.php?action=parse&props=text&page=" + ( options.title || options.src.slice(options.src.lastIndexOf("/")+1)) + "&format=json&callback=wikiCallback"+ _guid;
+
+          head.insertBefore( script, head.firstChild );        
       },
       /**
        * @member wikipedia 
@@ -93,11 +100,23 @@ var wikiCallback;
        */
       start: function(event, options){
         // dont do anything if the information didn't come back from wiki
-        if (options._link && options._desc) {
-          options.target.appendChild(options._link);
-          options.target.appendChild(options._desc);
-          options._added = true;
-        }
+        var isReady = function () {
+          
+          if ( !options._fired ) {
+            setTimeout(function () {
+              isReady();
+            }, 13);
+          } else {
+        
+            if (options._link && options._desc) {
+              options.target.appendChild(options._link);
+              options.target.appendChild(options._desc);
+              options._added = true;
+            }
+          }
+        };
+        
+        isReady();
       },
       /**
        * @member wikipedia 
@@ -106,6 +125,8 @@ var wikiCallback;
        * options variable
        */
       end: function(event, options){
+        // ensure that the data was actually added to the 
+        // DOM before removal
         if (options._added) {
           options.target.removeChild(options._link);
           options.target.removeChild(options._desc);