]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
starting tests
authorAnna Sobiepanek <annaopensource@gmail.com>
Sun, 19 Dec 2010 19:40:53 +0000 (14:40 -0500)
committerAnna Sobiepanek <annaopensource@gmail.com>
Sun, 19 Dec 2010 19:40:53 +0000 (14:40 -0500)
plugins/wikipedia/popcorn.wikipedia.html
plugins/wikipedia/popcorn.wikipedia.js
plugins/wikipedia/popcorn.wikipedia.unit.html
plugins/wikipedia/popcorn.wikipedia.unit.js

index 6d45ed745b54bb9936438522e3cfc9c39cf3c3ab..b85d4b5155d62d9e9634a72b49f2dd5c5cd1c118 100644 (file)
       .volume(0)
       .play() 
       .wikipedia({
-        start: 10, // seconds
-        end: 50, // seconds
+        start: 5, // seconds
+        end: 10, // seconds
         src: 'http://en.wikipedia.org/wiki/Cape_Town',
         target: 'wikidiv'
+      } )
+      .wikipedia({
+        start: 12, // seconds
+        end: 20, // seconds
+        src: 'http://en.wikipedia.org/wiki/S%C3%A3o_Paulo',
+        target: 'wikidiv2'
       } );
 
     }, false);
 </head>
 <body>
   <h1 id="qunit-header">Popcorn WebPage Plug-in Demo</h1>
-  <p> A Webpage displaying webmademovies.org will appear at 5 seconds and disappear at 15 seconds.</p>
-  <p> A Webpage displaying zenit Processing.js wiki will appear at 20 seconds and disappear at 45 seconds.</p>
+  <p> A Wiki article about Cape Town will appear at 5 seconds and disappear at 10 seconds.</p>
+  <p> A Wiki article about Sao Paolo will appear at 12 seconds and disappear at 20 seconds.</p>
   <div>
     <video id='video' 
-      controls preload='none' 
+      controls 
       width= '250px'
       poster="../../test/poster.png"> 
 
@@ -44,6 +50,9 @@
     </video> 
   </div>
   <div id="wikidiv" width="50%" height="50%">
+    
+
   </div>
+  <div id="wikidiv2" width="50%" height="50%"></div>
 </body>
 </html>
index 722c6f2a89f4d66dba9f5945092aa415ed332eef..03510e0ad40179e82b2fdbde1d0c8223a9da08f7 100644 (file)
@@ -1,12 +1,7 @@
 // PLUGIN: WIKIPEDIA
 
 
-// wikipedia callback functions executes when data is retrieved from the wiki
-// stores the data in a global variable
-var wikidatastring;
-var wikiCallback = function (data) { 
-  wikidatastring = data; 
-};
+var wikiCallback;
 
 (function (Popcorn) {
   
@@ -61,28 +56,22 @@ var wikiCallback = function (data) {
         var getJson  = function(url) {
           var head   = document.getElementsByTagName("head")[0];
           var script = document.createElement("script");
-          // once you get the data store it
-          script.onload = function () {
-            if (wikidatastring) {
-              // create a link that the user can use to view the whole article
-              link = document.createElement('a');
-              link.setAttribute('href', options.src);
-              link.setAttribute('target', '_blank');
-              // create a paragraph that the title of the article can go into
-              p = document.createElement('p');
-              p.innerHTML = wikidatastring.parse.displaytitle;
-              link.appendChild(p);
-              // get the first 140 characters of the wiki content
-              desc = document.createElement('p');
-              text = wikidatastring.parse.text["*"].substr(wikidatastring.parse.text["*"].indexOf('<p>'));
-              text = text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "");
-              desc.innerHTML = text.substr(0,  length ) + " ...";
-            }
-          };  
           script.src = url;
           head.insertBefore( script, head.firstChild );
         };
-        
+        wikiCallback     = function (data) { 
+          wikidatastring = data; 
+          link = document.createElement('a');
+          link.setAttribute('href', options.src);
+          link.setAttribute('target', '_blank');
+          // add the title of the article to the link
+          link.innerHTML = wikidatastring.parse.displaytitle;
+          // get the content of the wiki article
+          desc = document.createElement('p');
+          text = wikidatastring.parse.text["*"].substr(wikidatastring.parse.text["*"].indexOf('<p>'));
+          text = text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "");
+          desc.innerHTML = text.substr(0,  length ) + " ...";
+        };
       },
       /**
        * @member wikipedia 
index 238ff9d67fd621811a6ac4730f8fad5a342e36e4..43cdc4b0d599c2fc7ddf568686abfba804e5fa3f 100644 (file)
   -->
   
   <script src="../../popcorn.js"></script>
-  <script src="popcorn.webpage.js"></script>
+  <script src="popcorn.wikipedia.js"></script>
 
-  <script src="popcorn.webpage.unit.js"></script>
+  <script src="popcorn.wikipedia.unit.js"></script>
 </head>
 <body>
-  <h1 id="qunit-header">Popcorn Webpage UI</h1>
+  <h1 id="qunit-header">Popcorn wikipedia UI</h1>
   <h2 id="qunit-banner"></h2>
   <div id="qunit-testrunner-toolbar"></div>
   <h2 id="qunit-userAgent"></h2>
@@ -23,7 +23,7 @@
   <div id="qunit-fixture">  </div>
   
   <video id='video' 
-    controls preload='none' 
+    controls 
     width= '250px'
     poster="../../test/poster.png"> 
 
@@ -38,6 +38,6 @@
     <p>Your user agent does not support the HTML5 Video element.</p> 
 
   </video> 
-  <div id="webpagediv"></div>  
+  <div id="wikidiv"></div>  
 </body>
 </html>
index a402670c0e861098924baa3922b5a52ab6344198..d4e260699bc6b273368ea5ab4621f55d5d520ee8 100644 (file)
@@ -1,13 +1,14 @@
-test("Popcorn Webpage Plugin", function () {
+test("Popcorn wikipedia Plugin", function () {
   
   var popped = Popcorn("#video"),
-      expects = 11, 
+      expects = 5, 
       count = 0,
-      iframeInterval,
-      iframeInterval2,
-      iframeInterval3,
-      iframeInterval4;
-      theiFrame = document.getElementsByTagName('iframe');
+      wikiInterval,
+      wikiInterval2,
+      wikiInterval3,
+      wikiInterval4;
+      theArticle = document.getElementById('wikidiv');
+      
   expect(expects);
   
   function plus() {
@@ -18,63 +19,57 @@ test("Popcorn Webpage Plugin", function () {
   
   stop();
    
-  ok ('webpage' in popped, "webpages is a mehtod of the popped instance");
+  ok ('wikipedia' in popped, "wikipedia is a mehtod of the popped instance");
   plus();
   
-  equals (theiFrame.length, 0, "initially, there is no iframes on the page" );
+  equals (theArticle.innerHTML, "", "initially, there is nothing in the wikidiv" );
   plus();
   
-  popped.webpage({
-      id: "webpages-a", 
+  popped.wikipedia({
       start: 5, // seconds
-      end: 25, // seconds
-      src: 'http://webmademovies.org',
-      target: 'webpagediv'
-    })
-    .webpage({
-      id: "webpages-b", 
-      start: 35, // seconds
-      end: 50, // seconds
-      src: 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js',
-      target: 'webpagediv'
-    })
+      end: 10, // seconds
+      src: 'http://en.wikipedia.org/wiki/Cape_Town',
+      target: 'wikidiv'
+    } )
+    .wikipedia({
+      start: 12, // seconds
+      end: 20, // seconds
+      src: 'http://en.wikipedia.org/wiki/S%C3%A3o_Paulo',
+      target: 'wikidiv'
+    } )
     .play();
   
   
-  iframeInterval = setInterval( function() {
-    if( popped.currentTime() > 7 && popped.currentTime() <= 25 ) {
-      ok (!!theiFrame[0], "iframe was created" );
+  wikiInterval = setInterval( function() {
+    if( popped.currentTime() > 7 && popped.currentTime() <= 10 ) {
+      ok (theArticle.innerHTML !== "", "wikidiv now contains information" );
       plus();
-      equals (theiFrame.length, 1, "there is only one iframe on the page" );
+      equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
       plus();
-      equals (theiFrame[0].id, "webpages-a", "iframe has the id 'webpages-a'" );
-      plus();
-      equals (theiFrame[0].src, "http://webmademovies.org/", "iframe has the src 'http://webmademovies.org/'" );
-      plus();
-      clearInterval( iframeInterval );
+      
+      clearInterval( wikiInterval );
     }
   }, 5000);
   
-  iframeInterval2 = setInterval( function() {
-    if( popped.currentTime() > 27 && popped.currentTime() < 35  ) {
-      equals (theiFrame.length, 0, "the iframe has been removed" );
+  wikiInterval2 = setInterval( function() {
+    if( popped.currentTime() > 10 && popped.currentTime() < 12  ) {
+      equals (theArticle.innerHTML, "", "wikidiv was cleared properly" );
       plus();
-      clearInterval( iframeInterval2 );
+      clearInterval( wikiInterval2 );
     }
   }, 5000);
   
-  iframeInterval3 = setInterval( function() {
-    if( popped.currentTime() > 37 && popped.currentTime() <= 50 ) {
-      ok (!!theiFrame[0], "iframe was created" );
-      plus();
-      equals (theiFrame.length, 1, "there is only one iframe on the page" );
+  wikiInterval3 = setInterval( function() {
+    if( popped.currentTime() > 13 && popped.currentTime() <= 20 ) {
+      ok (theArticle.innerHTML !== "", "wikidiv now contains information" );
       plus();
-      equals (theiFrame[0].id, "webpages-b", "iframe has the id 'webpages-b'" );
+      equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
       plus();
-      equals (theiFrame[0].src,"http://zenit.senecac.on.ca/wiki/index.php/Processing.js", "iframe has the src 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js'" );
-      plus();
-      clearInterval( iframeInterval3 );
+      
+      clearInterval( wikiInterval3 );
     }
   }, 5000);
   
+  
+  
 });