]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
updated wikipedia plugin to _actually_ pull in the requested number of words, instead... t667
authorChristopher De Cairos <chris.decairos@gmail.com>
Tue, 23 Aug 2011 15:16:39 +0000 (11:16 -0400)
committerChristopher De Cairos <chris.decairos@gmail.com>
Tue, 23 Aug 2011 15:16:39 +0000 (11:16 -0400)
plugins/wikipedia/popcorn.wikipedia.js
plugins/wikipedia/popcorn.wikipedia.unit.js

index dfa775b8f0455248770034e72e1303baa7983ff8..c0b5d8cae6a8a67a130bbd97290df2fd3c8571bd 100755 (executable)
@@ -113,7 +113,9 @@ var wikiCallback;
         // get the article text and remove any special characters
         _text = data.parse.text[ "*" ].substr( data.parse.text[ "*" ].indexOf( "<p>" ) );
         _text = _text.replace( /((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "" );
-        options._desc.innerHTML = _text.substr( 0,  options.numberofwords ) + " ...";
+        
+        _text = _text.split( " " );
+        options._desc.innerHTML = ( _text.slice( 0, ( _text.length >= options.numberofwords ? options.numberofwords : _text.length ) ).join (" ") + " ..." ) ;
         
         options._fired = true;
       };
index d30de47bbb5103c6335a185e7b6a7346972156c8..6ed4207b8fa6464ec94ec88e5785c4538cdd2428 100755 (executable)
@@ -1,7 +1,7 @@
 test("Popcorn wikipedia Plugin", function () {
   
   var popped        = Popcorn( "#video" ),
-      expects       = 11, 
+      expects       = 13, 
       count         = 0,
       theArticle    = document.getElementById( "wikidiv" );
        
@@ -26,45 +26,53 @@ test("Popcorn wikipedia Plugin", function () {
       end: 3, // seconds
       src: "http://en.wikipedia.org/wiki/Cape_Town",
       title: "this is an article",
-      target: "wikidiv"
+      target: "wikidiv",
+      numberofwords: 22
     } )
     .wikipedia({
       start: 4, // seconds
       end: 5, // seconds
       src: "http://en.wikipedia.org/wiki/S%C3%A3o_Paulo",
-      target: "wikidiv"
+      target: "wikidiv",
+      numberofwords: 43
     } )
     .volume(0)
     .play();
     
   popped.exec( 2, function() {
-    ok ( theArticle.innerHTML !== "", "wikidiv now contains information" );
+    notEqual( theArticle.innerHTML, "", "wikidiv now contains information" );
     plus();
-    equals ( theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
+    equals( theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
     plus();
-    equals ( theArticle.children[ 0 ].innerHTML, "this is an article", "wikidiv has the right title" );
+    equals( theArticle.children[ 0 ].innerHTML, "this is an article", "wikidiv has the right title" );
     plus();
-    ok ( theArticle.children[ 1 ].innerHTML !=="", "wikidiv has some content" );
+    notEqual( theArticle.children[ 1 ].innerHTML, "", "wikidiv has some content" );
+    plus();
+    // subtract 1 from length for the  '...' added in by the plugin
+    equals( theArticle.children[ 1 ].innerHTML.split( " " ).length -1, 22, "wikidiv contains 22 words" )
     plus();
   });
   
   popped.exec( 3, function() {
-    equals ( theArticle.innerHTML, "", "wikidiv was cleared properly" );
+    equals( theArticle.innerHTML, "", "wikidiv was cleared properly" );
     plus();
   });
   
   popped.exec( 4, function() {
-    ok ( theArticle.innerHTML !== "", "wikidiv now contains information" );
+    notEqual( theArticle.innerHTML, "", "wikidiv now contains information" );
+    plus();
+    equals( theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
     plus();
-    equals ( theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
+    notEqual( theArticle.children[ 1 ].innerHTML, "", "wikidiv has the right content" );
     plus();
-    ok ( theArticle.children[ 1 ].innerHTML !== "", "wikidiv has the right content" );
+    // subtract 1 from length for the  '...' added in by the plugin
+    equals( theArticle.children[ 1 ].innerHTML.split(" ").length - 1, 43, "wikidiv contains 43 words" );
     plus();
   });
 
   popped.exec( 6, function() {
     popped.pause().removeTrackEvent( popped.data.trackEvents.byStart[ 4 ]._id );
-    equals ( theArticle.innerHTML, "", "wikidiv is now empty" );
+    equals( theArticle.innerHTML, "", "wikidiv is now empty" );
     plus();
   });
 });