]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
fixed as per review [#158 state:peer-review-requested]
authorAnna Sobiepanek <annaopensource@gmail.com>
Thu, 23 Dec 2010 01:49:34 +0000 (20:49 -0500)
committerAnna Sobiepanek <annaopensource@gmail.com>
Thu, 23 Dec 2010 01:49:34 +0000 (20:49 -0500)
plugins/wikipedia/popcorn.wikipedia.html
plugins/wikipedia/popcorn.wikipedia.js

index 9c74d2fc5a6fcadf9a512c89b1be20c414c98ffe..8026a922b8c054125f35511d7a23968dc0ac1dff 100644 (file)
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
 <head>
-  <title>Popcorn WebPage Plug-in Demo</title>
+  <title>Popcorn Wikipedia Plug-in Demo</title>
   
   <script src="../../popcorn.js"></script>
   <script src="popcorn.wikipedia.js"></script>
@@ -28,7 +28,7 @@
   </script>
 </head>
 <body>
-  <h1 id="qunit-header">Popcorn WebPage Plug-in Demo</h1>
+  <h1 id="qunit-header">Popcorn Wikipedia Plug-in Demo</h1>
   <p> A Wiki article about Cape Town will appear at 0 seconds and disappear at 10 seconds.</p>
   <p> A Wiki article about Sao Paolo will appear at 7 seconds and disappear at 20 seconds.</p>
   <div>
index fd273e896bc121b21807ed55629249b51724341e..f9794b45ebee2702277c82f8e490782a03ea5203 100644 (file)
@@ -9,11 +9,11 @@ var wikiCallback;
    * 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
@@ -27,114 +27,98 @@ var wikiCallback;
           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