* Wikipedia popcorn plug-in
* Displays a wikipedia aricle in the target specified by the user by using
* new DOM element instead overwriting them
- * Options parameter will need a start, end, target, lang, src, and numOfWords.
+ * Options parameter will need a start, end, target, lang, src, title and numOfWords.
* -Start is the time that you want this plug-in to execute
* -End is the time that you want this plug-in to stop executing
- * -Target is the id of the document element that the iframe needs to be attached to,
- * this target element must exist on the DOM
+ * -Target is the id of the document element that the text from the article needs to be
+ * attached to, this target element must exist on the DOM
* -Lang (optional, defaults to english) is the language in which the article is in.
* -Src is the url of the article
* -Title (optional) is the title of the article
start: 5, // seconds
end: 15, // seconds
src: 'http://en.wikipedia.org/wiki/Cape_Town',
- target: 'webpagediv'
+ target: 'wikidiv'
} )
*
*/
- Popcorn.plugin( "wikipedia" , (function(){
+ Popcorn.plugin( "wikipedia" , {
- return {
- /**
- * @member wikipedia
- * The setup function will get all of the needed
- * items in place before the start function is called.
- * This includes getting data from wikipedia, if the data
- * is not received and processed before start is called start
- * will not do anything
- */
- _setup : function( options ) {
- // declare needed variables
- // get a guid to use for the global wikicallback function
- var _text, _guid = Popcorn.guid();
-
- // if the user didn't specify a language default to english
- if (typeof options.lang === 'undefined') { options.lang ="en"; }
- // if the user didn't specify number of words to use default to 200
- options.numOfWords = options.numOfWords || 200;
- // replace the user specified target with the actual DOM element
- options.target = document.getElementById( options.target );
-
- // 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');
- // add the title of the article to the link
- options._link.innerHTML = data.parse.displaytitle;
- // 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, "");
- options._desc.innerHTML = _text.substr(0, options.numOfWords ) + " ...";
-
- options._fired = true;
- };
-
- // get the wiki article on a separate thread
- // call the wikiCallback function above once the script is loaded
- //setTimeout(function() {
- // getJson("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);
- //}, 500);
+ /**
+ * @member wikipedia
+ * The setup function will get all of the needed
+ * items in place before the start function is called.
+ * This includes getting data from wikipedia, if the data
+ * is not received and processed before start is called start
+ * will not do anything
+ */
+ _setup : function( options ) {
+ // declare needed variables
+ // get a guid to use for the global wikicallback function
+ var _text, _guid = Popcorn.guid();
+
+ // if the user didn't specify a language default to english
+ if (typeof options.lang === 'undefined') { options.lang ="en"; }
+ // if the user didn't specify number of words to use default to 200
+ options.numOfWords = options.numOfWords || 200;
+ // replace the user specified target with the actual DOM element
+ options.target = document.getElementById( options.target );
+
+ // 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');
+ // add the title of the article to the link
+ options._link.innerHTML = data.parse.displaytitle;
+ // 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, "");
+ options._desc.innerHTML = _text.substr(0, options.numOfWords ) + " ...";
- // add the script to the DOM
- /*var getJson = function(url) {
- var head = document.getElementsByTagName("head")[0];
- var script = document.createElement("script");
- script.src = url;
- head.insertBefore( script, head.firstChild );
- }; */
- 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;
+ 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;
- head.insertBefore( script, head.firstChild );
- },
- /**
- * @member wikipedia
- * The start function will be executed when the currentTime
- * of the video reaches the start time provided by the
- * options variable
- */
- start: function(event, options){
- // dont do anything if the information didn't come back from wiki
- var isReady = function () {
-
- if ( !options._fired ) {
- setTimeout(function () {
- isReady();
- }, 13);
- } else {
+ head.insertBefore( script, head.firstChild );
+ },
+ /**
+ * @member wikipedia
+ * The start function will be executed when the currentTime
+ * of the video reaches the start time provided by the
+ * options variable
+ */
+ start: function(event, options){
+ // dont do anything if the information didn't come back from wiki
+ var isReady = function () {
- if (options._link && options._desc) {
- options.target.appendChild(options._link);
- options.target.appendChild(options._desc);
- options._added = true;
- }
+ if ( !options._fired ) {
+ setTimeout(function () {
+ isReady();
+ }, 13);
+ } else {
+
+ if (options._link && options._desc) {
+ options.target.appendChild(options._link);
+ options.target.appendChild(options._desc);
+ options._added = true;
}
- };
-
- isReady();
- },
- /**
- * @member wikipedia
- * The end function will be executed when the currentTime
- * of the video reaches the end time provided by the
- * options variable
- */
- end: function(event, options){
- // ensure that the data was actually added to the
- // DOM before removal
- if (options._added) {
- options.target.removeChild(options._link);
- options.target.removeChild(options._desc);
}
- }
+ };
- };
-
- })());
+ isReady();
+ },
+ /**
+ * @member wikipedia
+ * The end function will be executed when the currentTime
+ * of the video reaches the end time provided by the
+ * options variable
+ */
+ end: function(event, options){
+ // ensure that the data was actually added to the
+ // DOM before removal
+ if (options._added) {
+ options.target.removeChild(options._link);
+ options.target.removeChild(options._desc);
+ }
+ }
+
+ });
})( Popcorn );
\ No newline at end of file