From 7f7448d8f66f4f4f550f3318b0391398e48dd0ff Mon Sep 17 00:00:00 2001 From: Christopher De Cairos Date: Tue, 23 Aug 2011 11:16:39 -0400 Subject: [PATCH] updated wikipedia plugin to _actually_ pull in the requested number of words, instead of a number of letters --- plugins/wikipedia/popcorn.wikipedia.js | 4 ++- plugins/wikipedia/popcorn.wikipedia.unit.js | 32 +++++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/plugins/wikipedia/popcorn.wikipedia.js b/plugins/wikipedia/popcorn.wikipedia.js index dfa775b8..c0b5d8ca 100755 --- a/plugins/wikipedia/popcorn.wikipedia.js +++ b/plugins/wikipedia/popcorn.wikipedia.js @@ -113,7 +113,9 @@ var wikiCallback; // get the article text and remove any special characters _text = data.parse.text[ "*" ].substr( data.parse.text[ "*" ].indexOf( "

" ) ); _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; }; diff --git a/plugins/wikipedia/popcorn.wikipedia.unit.js b/plugins/wikipedia/popcorn.wikipedia.unit.js index d30de47b..6ed4207b 100755 --- a/plugins/wikipedia/popcorn.wikipedia.unit.js +++ b/plugins/wikipedia/popcorn.wikipedia.unit.js @@ -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" ); + equals( theArticle.childElementCount, 2, "wikidiv now contains two child elements" ); plus(); - ok ( theArticle.children[ 1 ].innerHTML !== "", "wikidiv has the right content" ); + notEqual( theArticle.children[ 1 ].innerHTML, "", "wikidiv has the right content" ); + plus(); + // 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(); }); });