зеркало из 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
|
// get the article text and remove any special characters
|
||||||
_text = data.parse.text[ "*" ].substr( data.parse.text[ "*" ].indexOf( "<p>" ) );
|
_text = data.parse.text[ "*" ].substr( data.parse.text[ "*" ].indexOf( "<p>" ) );
|
||||||
_text = _text.replace( /((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "" );
|
_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;
|
options._fired = true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
test("Popcorn wikipedia Plugin", function () {
|
test("Popcorn wikipedia Plugin", function () {
|
||||||
|
|
||||||
var popped = Popcorn( "#video" ),
|
var popped = Popcorn( "#video" ),
|
||||||
expects = 11,
|
expects = 13,
|
||||||
count = 0,
|
count = 0,
|
||||||
theArticle = document.getElementById( "wikidiv" );
|
theArticle = document.getElementById( "wikidiv" );
|
||||||
|
|
||||||
|
@ -26,25 +26,30 @@ test("Popcorn wikipedia Plugin", function () {
|
||||||
end: 3, // seconds
|
end: 3, // seconds
|
||||||
src: "http://en.wikipedia.org/wiki/Cape_Town",
|
src: "http://en.wikipedia.org/wiki/Cape_Town",
|
||||||
title: "this is an article",
|
title: "this is an article",
|
||||||
target: "wikidiv"
|
target: "wikidiv",
|
||||||
|
numberofwords: 22
|
||||||
} )
|
} )
|
||||||
.wikipedia({
|
.wikipedia({
|
||||||
start: 4, // seconds
|
start: 4, // seconds
|
||||||
end: 5, // seconds
|
end: 5, // seconds
|
||||||
src: "http://en.wikipedia.org/wiki/S%C3%A3o_Paulo",
|
src: "http://en.wikipedia.org/wiki/S%C3%A3o_Paulo",
|
||||||
target: "wikidiv"
|
target: "wikidiv",
|
||||||
|
numberofwords: 43
|
||||||
} )
|
} )
|
||||||
.volume(0)
|
.volume(0)
|
||||||
.play();
|
.play();
|
||||||
|
|
||||||
popped.exec( 2, function() {
|
popped.exec( 2, function() {
|
||||||
ok ( theArticle.innerHTML !== "", "wikidiv now contains information" );
|
notEqual( theArticle.innerHTML, "", "wikidiv now contains information" );
|
||||||
plus();
|
plus();
|
||||||
equals( theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
|
equals( theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
|
||||||
plus();
|
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();
|
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();
|
plus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -54,11 +59,14 @@ test("Popcorn wikipedia Plugin", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
popped.exec( 4, function() {
|
popped.exec( 4, function() {
|
||||||
ok ( theArticle.innerHTML !== "", "wikidiv now contains information" );
|
notEqual( theArticle.innerHTML, "", "wikidiv now contains information" );
|
||||||
plus();
|
plus();
|
||||||
equals( theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
|
equals( theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
|
||||||
plus();
|
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();
|
plus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче