Skip to content
This repository was archived by the owner on Jun 29, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions plugins/wikipedia/popcorn.wikipedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,21 @@ var wikiCallback;
// and stores it by appending values to the options object
window[ "wikiCallback" + _guid ] = function ( data ) {

var pageId = Object.keys(data.query.pages)[0];
var content = data.query.pages[pageId];

options._link = document.createElement( "a" );
options._link.setAttribute( "href", options.src );
options._link.setAttribute( "target", "_blank" );

// add the title of the article to the link
options._link.innerHTML = options.title || data.parse.displaytitle;
options._link.innerHTML = options.title || content.title;

// get the content of the wiki article
options._desc = document.createElement( "p" );

// get the article text and remove any special characters
_text = data.parse.text[ "*" ].substr( data.parse.text[ "*" ].indexOf( "<p>" ) );
_text = _text.replace( /((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "" );
// get the article text
_text = content.extract;

_text = _text.split( " " );
options._desc.innerHTML = ( _text.slice( 0, ( _text.length >= options.numberofwords ? options.numberofwords : _text.length ) ).join (" ") + " ..." ) ;
Expand All @@ -128,7 +130,7 @@ var wikiCallback;
};

if ( options.src ) {
Popcorn.getScript( "//" + options.lang + ".wikipedia.org/w/api.php?action=parse&props=text&redirects&page=" +
Popcorn.getScript( "//" + options.lang + ".wikipedia.org/w/api.php?action=query&prop=extracts&exintro=&explaintext=&redirects&titles=" +
options.src.slice( options.src.lastIndexOf( "/" ) + 1 ) + "&format=json&callback=wikiCallback" + _guid );
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/wikipedia/popcorn.wikipedia.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test( "Popcorn wikipedia Plugin", function() {
src: "http://en.wikipedia.org/wiki/Bunny",
title: "This is an article about bunnies",
target: "wikidiv",
numberofwords: 1000
numberofwords: 80
})
.volume( 0 )
.play();
Expand All @@ -59,7 +59,7 @@ test( "Popcorn wikipedia Plugin", function() {
// subtract 1 from length for the '...' added in by the plugin
equal( theArticle.children[ 1 ].innerHTML.split( " " ).length -1, 22, "wikidiv contains 22 words" );
plus();
equal( theArticle.children[ 3 ].innerHTML.split( " " ).length - 1, 1000, "redirected article successfully retrieved 1000 words" );
equal( theArticle.children[ 3 ].innerHTML.split( " " ).length - 1, 80, "redirected article successfully retrieved 80 words" );
plus();
});

Expand Down