зеркало из https://github.com/mozilla/popcorn-js.git
updated wikipedia plugin to _actually_ pull in the requested number of words, instead of a number of letters
This commit is contained in:
Родитель
47ce320a21
Коммит
7f7448d8f6
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче