From 7ece093760eb43632a2473828f6ef1eeebae3ef8 Mon Sep 17 00:00:00 2001 From: Anna Sobiepanek Date: Mon, 31 Jan 2011 12:35:30 -0500 Subject: [PATCH 1/4] fixtd options.title and wrote tests [#293] --- plugins/wikipedia/popcorn.wikipedia.html | 1 + plugins/wikipedia/popcorn.wikipedia.js | 2 +- plugins/wikipedia/popcorn.wikipedia.unit.js | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/wikipedia/popcorn.wikipedia.html b/plugins/wikipedia/popcorn.wikipedia.html index 8026a922..067fab37 100644 --- a/plugins/wikipedia/popcorn.wikipedia.html +++ b/plugins/wikipedia/popcorn.wikipedia.html @@ -14,6 +14,7 @@ start: 0, // seconds end: 10, // seconds src: 'http://en.wikipedia.org/wiki/Cape_Town', + title: "this is an article", target: 'wikidiv' } ) .wikipedia({ diff --git a/plugins/wikipedia/popcorn.wikipedia.js b/plugins/wikipedia/popcorn.wikipedia.js index 75041ff9..190c2f36 100644 --- a/plugins/wikipedia/popcorn.wikipedia.js +++ b/plugins/wikipedia/popcorn.wikipedia.js @@ -76,7 +76,7 @@ var wikiCallback; options._link.setAttribute('href', options.src); options._link.setAttribute('target', '_blank'); // add the title of the article to the link - options._link.innerHTML = data.parse.displaytitle; + options._link.innerHTML = options.title || data.parse.displaytitle; // get the content of the wiki article options._desc = document.createElement('p'); // get the article text and remove any special characters diff --git a/plugins/wikipedia/popcorn.wikipedia.unit.js b/plugins/wikipedia/popcorn.wikipedia.unit.js index 6355ac94..89ff683a 100644 --- 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 = 7, + expects = 9, count = 0, theArticle = document.getElementById('wikidiv'), wikiInterval, @@ -30,6 +30,7 @@ test("Popcorn wikipedia Plugin", function () { start: 5, // seconds end: 10, // seconds src: 'http://en.wikipedia.org/wiki/Cape_Town', + title: "this is an article", target: 'wikidiv' } ) .wikipedia({ @@ -48,6 +49,8 @@ test("Popcorn wikipedia Plugin", function () { plus(); equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" ); plus(); + equals (theArticle.childElement[0].innerHTML, "this is an article", "wikidiv has the right title" ); + plus(); equals (theArticle.childElement[1].innerHTML, "Cape Town metropolitan municipality. It is the provincial capital and primate city ...", "wikidiv has the right content" ); plus(); clearInterval( wikiInterval ); From 7b20f0b744033ff2f45450a14f9b46b6dea9d745 Mon Sep 17 00:00:00 2001 From: Anna Sobiepanek Date: Mon, 31 Jan 2011 12:37:45 -0500 Subject: [PATCH 2/4] fixed spacing [#293] --- plugins/wikipedia/popcorn.wikipedia.js | 38 +++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/wikipedia/popcorn.wikipedia.js b/plugins/wikipedia/popcorn.wikipedia.js index 190c2f36..fccee4a6 100644 --- a/plugins/wikipedia/popcorn.wikipedia.js +++ b/plugins/wikipedia/popcorn.wikipedia.js @@ -71,25 +71,25 @@ var wikiCallback; // wiki global callback function with a unique id // function gets the needed information from wikipedia // and stores it by appending values to the options object - window["wikiCallback"+ _guid] = function (data) { - options._link = document.createElement('a'); - options._link.setAttribute('href', options.src); - options._link.setAttribute('target', '_blank'); + window["wikiCallback"+ _guid] = function ( data ) { + 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; // get the content of the wiki article - options._desc = document.createElement('p'); + options._desc = document.createElement( 'p' ); // get the article text and remove any special characters - _text = data.parse.text["*"].substr(data.parse.text["*"].indexOf('

')); + _text = data.parse.text["*"].substr( data.parse.text["*"].indexOf('

') ); _text = _text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, ""); - options._desc.innerHTML = _text.substr(0, options.numberofwords ) + " ..."; + options._desc.innerHTML = _text.substr( 0, options.numberofwords ) + " ..."; options._fired = true; }; - var head = document.getElementsByTagName("head")[0]; - var script = document.createElement("script"); - script.src = "http://"+options.lang+".wikipedia.org/w/api.php?action=parse&props=text&page=" + ( options.title || options.src.slice(options.src.lastIndexOf("/")+1)) + "&format=json&callback=wikiCallback"+ _guid; + var head = document.getElementsByTagName( "head" )[0]; + var script = document.createElement( "script" ); + script.src = "http://" + options.lang + ".wikipedia.org/w/api.php?action=parse&props=text&page=" + ( options.title || options.src.slice( options.src.lastIndexOf("/")+1) ) + "&format=json&callback=wikiCallback" + _guid; head.insertBefore( script, head.firstChild ); }, @@ -99,20 +99,20 @@ var wikiCallback; * of the video reaches the start time provided by the * options variable */ - start: function(event, options){ + start: function( event, options ){ // dont do anything if the information didn't come back from wiki var isReady = function () { if ( !options._fired ) { - setTimeout(function () { + setTimeout( function () { isReady(); }, 13); } else { - if (options._link && options._desc) { + if ( options._link && options._desc ) { if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild(options._link); - document.getElementById( options.target ).appendChild(options._desc); + document.getElementById( options.target ).appendChild( options._link ); + document.getElementById( options.target ).appendChild( options._desc ); options._added = true; } } @@ -127,12 +127,12 @@ var wikiCallback; * of the video reaches the end time provided by the * options variable */ - end: function(event, options){ + end: function( event, options ){ // ensure that the data was actually added to the // DOM before removal - if (options._added) { - document.getElementById( options.target ).removeChild(options._link); - document.getElementById( options.target ).removeChild(options._desc); + if ( options._added ) { + document.getElementById( options.target ).removeChild( options._link ); + document.getElementById( options.target ).removeChild( options._desc ); } } From 3036b6cd82d27e0d1e16c883db142e8229fe9d67 Mon Sep 17 00:00:00 2001 From: Anna Sobiepanek Date: Mon, 31 Jan 2011 12:42:17 -0500 Subject: [PATCH 3/4] fixed spacing [#293] --- plugins/wikipedia/popcorn.wikipedia.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wikipedia/popcorn.wikipedia.js b/plugins/wikipedia/popcorn.wikipedia.js index fccee4a6..b8bd767d 100644 --- a/plugins/wikipedia/popcorn.wikipedia.js +++ b/plugins/wikipedia/popcorn.wikipedia.js @@ -80,7 +80,7 @@ var wikiCallback; // 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('

') ); + _text = data.parse.text[ "*" ].substr( data.parse.text["*"].indexOf('

') ); _text = _text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, ""); options._desc.innerHTML = _text.substr( 0, options.numberofwords ) + " ..."; @@ -132,7 +132,7 @@ var wikiCallback; // DOM before removal if ( options._added ) { document.getElementById( options.target ).removeChild( options._link ); - document.getElementById( options.target ).removeChild( options._desc ); + document.getElementById( options.target ).removeChild( options._desc it ); } } From 70274cee3ba6677d1bee67903b59c7ba644ca309 Mon Sep 17 00:00:00 2001 From: Anna Sobiepanek Date: Mon, 31 Jan 2011 12:46:22 -0500 Subject: [PATCH 4/4] fixed spacing [#293] --- plugins/wikipedia/popcorn.wikipedia.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wikipedia/popcorn.wikipedia.js b/plugins/wikipedia/popcorn.wikipedia.js index b8bd767d..f81ee30a 100644 --- a/plugins/wikipedia/popcorn.wikipedia.js +++ b/plugins/wikipedia/popcorn.wikipedia.js @@ -80,7 +80,7 @@ var wikiCallback; // 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('

') ); + _text = data.parse.text[ "*" ].substr( data.parse.text[ "*" ].indexOf('

') ); _text = _text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, ""); options._desc.innerHTML = _text.substr( 0, options.numberofwords ) + " ..."; @@ -132,7 +132,7 @@ var wikiCallback; // DOM before removal if ( options._added ) { document.getElementById( options.target ).removeChild( options._link ); - document.getElementById( options.target ).removeChild( options._desc it ); + document.getElementById( options.target ).removeChild( options._desc ); } }