linterna-magica-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[linterna-magica-commit] [105] Initial rework for tasks #11216.


From: Ivaylo Valkov
Subject: [linterna-magica-commit] [105] Initial rework for tasks #11216.
Date: Fri, 01 Jul 2011 09:50:25 +0000

Revision: 105
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=linterna-magica&revision=105
Author:   valkov
Date:     2011-07-01 09:50:24 +0000 (Fri, 01 Jul 2011)
Log Message:
-----------
Initial rework for tasks #11216. The sites object is created. A rule to be 
executed before options initialisation. Part of the code for ted.com code uses 
the new framework.

Ticket Links:
------------
    http://savannah.gnu.org/task/?11216

Modified Paths:
--------------
    branches/task-11216/src/lm_constructors.js
    branches/task-11216/src/lm_site_tedcom.js

Added Paths:
-----------
    branches/task-11216/src/lm_sites.js

Modified: branches/task-11216/src/lm_constructors.js
===================================================================
--- branches/task-11216/src/lm_constructors.js  2011-06-30 12:02:35 UTC (rev 
104)
+++ branches/task-11216/src/lm_constructors.js  2011-07-01 09:50:24 UTC (rev 
105)
@@ -81,15 +81,12 @@
        this.log_to = "console";
     }
 
-    // Skip ted.com at the front page. With Gnash installed the flash
-    // object is created. The flashvars attrubute value is 24 KB
-    // (kilo*bytes*) and Firefox and forks block 
-    if (/ted\.com/i.test(window.location.hostname) &&
-       !/[A-Za-z0-9]+/i.test(window.location.pathname))
-    {  
-       this.log("LinternaMagica.constructor:\n"+
-                "Skipping TED front page!"+
-                " Blocks Firefox and forks.");
+    var self = this;
+    var val = this.sites.call_site_function_at_position.apply(self,[
+       "before_options_init",
+       window.location.hostname]);
+    if (!val)
+    {
        return null;
     }
 

Modified: branches/task-11216/src/lm_site_tedcom.js
===================================================================
--- branches/task-11216/src/lm_site_tedcom.js   2011-06-30 12:02:35 UTC (rev 
104)
+++ branches/task-11216/src/lm_site_tedcom.js   2011-07-01 09:50:24 UTC (rev 
105)
@@ -55,7 +55,9 @@
     var links = unescape(data).match(links_re);
 
     if (!links)
-       return;
+    {
+       return false;
+    }
 
     // Work-around for links extracted from <param> of a DOM object
     // There is a problem with generalized regular expression
@@ -106,3 +108,25 @@
 
     return null;
 }
+
+LinternaMagica.prototype.sites["ted.com"] = new Object();
+
+// Reference
+LinternaMagica.prototype.sites["www.ted.com"] = "ted.com";
+
+LinternaMagica.prototype.sites["ted.com"].before_options_init = function()
+{
+     // Skip ted.com at the front page. With Gnash installed the flash
+    // object is created. The flashvars attrubute value is 24 KB
+    // (kilo*bytes*) and Firefox and forks block 
+    if(!/[A-Za-z0-9]+/i.test(window.location.pathname))
+    {  
+          this.log("LinternaMagica.constructor:\n"+
+                   "Skipping TED front page!"+
+                   " Blocks Firefox and forks.");
+
+       return false;
+    }
+
+    return true;
+}

Added: branches/task-11216/src/lm_sites.js
===================================================================
--- branches/task-11216/src/lm_sites.js                         (rev 0)
+++ branches/task-11216/src/lm_sites.js 2011-07-01 09:50:24 UTC (rev 105)
@@ -0,0 +1,111 @@
+//  @licstart The following is the entire license notice for the
+//  JavaScript code in this page (or file).
+//
+//  This file is part of Linterna Mágica
+//
+//  Copyright (C) 2011  Ivaylo Valkov <address@hidden>
+//
+//  The JavaScript code in this page (or file) is free software: you
+//  can redistribute it and/or modify it under the terms of the GNU
+//  General Public License (GNU GPL) as published by the Free Software
+//  Foundation, either version 3 of the License, or (at your option)
+//  any later version.  The code is distributed WITHOUT ANY WARRANTY
+//  without even the implied warranty of MERCHANTABILITY or FITNESS
+//  FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
+//
+//  As additional permission under GNU GPL version 3 section 7, you
+//  may distribute non-source (e.g., minimized or compacted) forms of
+//  that code without the copy of the GNU GPL normally required by
+//  section 4, provided you include this license notice and a URL
+//  through which recipients can access the Corresponding Source.
+//
+//  @licend The above is the entire license notice for the JavaScript
+//  code in this page (or file).
+//
+// @source http://linterna-magica.nongnu.org
+
+// END OF LICENSE HEADER
+
+// Holds all the site specific config and function
+LinternaMagica.prototype.sites = new Object();
+
+// A function returns false/null, if the calling function should
+// exit/return after this function is executed.  Otherwise it should
+// return true.
+LinternaMagica.prototype.sites.__before_options_init = function ()
+{
+    // Take an action before options initialisation. This is the
+    // earliest position where site-specific action could be
+    // taken. The default config is to keep processing.
+    //
+    // For example, ted.com requires a different approach.
+    return true;
+}
+
+// LinternaMagica.prototype.sites.__no_flash_plugin_installed
+// LinternaMagica.prototype.sites.__process_cookies
+// LinternaMagica.prototype.sites.__css_style_fix
+// LinternaMagica.prototype.sites.__detect_flash_ // Useless?
+// LinternaMagica.prototype.sites.__skip_video_id_extract // DM force?
+// LinternaMagica.prototype.sites.__skip_xhr_if_video_id
+// LinternaMagica.prototype.sites.__wait_before_xhr
+// LinternaMagica.prototype.sites.__extract_scripts_extract_when // Condition 
? DM /ted? 
+// LinternaMagica.prototype.sites.__extract_scripts_once // YT ?
+// LinternaMagica.prototype.sites.__extract_scripts_wait_insert // FB
+// LinternaMagica.prototype.sites.__wait_before_inserting_object_from-script 
// FB
+// LinternaMagica.prototype.sites.__extract_swfobject_regex
+// LinternaMagica.prototype.sites.__extract_swfobject_hdlinks
+// LinternaMagica.prototype.sites.__extract_video_link_regex
+// LinternaMagica.prototype.sites.__extract_video_link_match
+// LinternaMagica.prototype.sites.__match_for_video_link
+// LinternaMagica.prototype.sites.__keep_amps_in_video_link
+// LinternaMagica.prototype.sites.__process_plugin_install_warning
+// LinternaMagica.prototype.sites.__prepare_xhr
+// LinternaMagica.prototype.sites.__process_xhr_responce
+// LinternaMagica.prototype.sites.__insert_object_after_xhr
+
+// Check if site specific config and function exists and call it. If
+// it doesn't, call the general/default function.  A function returns
+// false/null, if the calling function should exit/return after this
+// function is executed. Otherwise it should return true.
+LinternaMagica.prototype.sites.call_site_function_at_position =
+function (position_name, match_site, data)
+{
+    var self = this;
+
+    if (this.sites[match_site])
+    {
+       // All of the following will work when the referenced
+       // object/function is an object/function. A recursion is
+       // required to handle references to strings. 
+
+       if (typeof(this.sites[match_site]) == "object" &&
+           typeof(this.sites[match_site][position_name]) == "function")
+       {
+           // Defined site and function
+           return this.sites[match_site][position_name].apply(self,[data]);
+       }
+       else if (typeof(this.sites[match_site]) == "object" &&
+                typeof(this.sites[match_site][position_name]) == "string")
+       {
+           // Reference to a function of another site
+           var ref_to = this.sites[match_site][position_name];
+           return this.sites[ref_to][position_name].apply(self,[data]);
+       }
+       else if (typeof(this.sites[match_site]) == "string")
+       {
+           // Reference to a another site
+           var ref_to = this.sites[match_site];
+           return this.sites[ref_to][position_name].apply(self,[data]);
+       }
+    }
+    else if ((this.sites[match_site] &&
+             !this.sites[match_site][position_name]) ||
+            !this.sites[match_site])
+    {
+       // General-purpose / default function.
+       return this.sites["__"+position_name].apply(self, [data]);
+    }
+
+    return true;
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]