[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[linterna-magica-commit] [91] Backporting the framework changes in r90 m
From: |
Ivaylo Valkov |
Subject: |
[linterna-magica-commit] [91] Backporting the framework changes in r90 manualy. |
Date: |
Tue, 14 Jun 2011 16:14:24 +0000 |
Revision: 91
http://svn.sv.gnu.org/viewvc/?view=rev&root=linterna-magica&revision=91
Author: valkov
Date: 2011-06-14 16:14:24 +0000 (Tue, 14 Jun 2011)
Log Message:
-----------
Backporting the framework changes in r90 manualy. These are needed for the
Blip.tv support that will be backported from trunk. Too much conflicts to use
svn merge.
Revision Links:
--------------
http://svn.sv.gnu.org/viewvc/?view=rev&root=linterna-magica&revision=90
Modified Paths:
--------------
branches/0.0.9/src/lm_check_for_updates.js
Added Paths:
-----------
branches/0.0.9/src/lm_jsonp_requests.js
Modified: branches/0.0.9/src/lm_check_for_updates.js
===================================================================
--- branches/0.0.9/src/lm_check_for_updates.js 2011-06-14 15:23:55 UTC (rev 90)
+++ branches/0.0.9/src/lm_check_for_updates.js 2011-06-14 16:14:24 UTC (rev 91)
@@ -100,139 +100,73 @@
return null;
}
- if (!this.updates_timeout)
- {
- this.updates_timeout_counter = 0;
- var self = this;
+ var jsonp_request_data = new Object();
- // Polling. The data will be retrieved in the main window =>
- // the LinternaMagica object.
- this.updates_timeout =
- setInterval(function()
- {
- self.parse_updated_version_data.apply(self);
- }, 10);
- }
+ jsonp_request_data.frame_id = "linterna-magica-updates-checker";
+ jsonp_request_data.parser_timeout = this.updates_timeout;
+ jsonp_request_data.parser_timeout_counter =
+ this.updates_timeout_counter;
+ jsonp_request_data.jsonp_script_link = this.updates_page;
+ jsonp_request_data.jsonp_function = "linterna_magica_latest_version";
+ jsonp_request_data.parser_function = this.parse_updated_version_data;
- // The script is wrapped inside a data URI scheme. This way the
- // page where the user was (referrer) is not sent. Cross-domain
- // frame communcication with hashed messages
- // (original-link#message=) is used to access the data.
- var checker_frame = document.createElement("object");
- checker_frame.setAttribute("id", "linterna-magica-updates-checker");
-
- var frame_script = function()
- {
- window.linterna_magica_latest_version = function (data)
- {
- var hash = /#/i.test(receiver_location) ? "" : "#";
-
- window.parent.location = decodeURI(receiver_location)+hash+
- encodeURI("&linterna_magica&lm_version="+data.version+
- "&lm_date="+data.date+"&linterna_magica");
- };
- };
-
- var frame_data =
- "<html><head>"+
- "<script async='async' defer='defer' type='text/javascript'>"+
- "var receiver_location='"+
- encodeURI(window.location)+"';("+frame_script.toString()+")();"+
- "</script>"+
- "<script async='async' defer='defer' type='text/javascript' src='"+
- this.updates_page+"'>"+
- "</script>"+
- "</head><body></body></html>";
-
- checker_frame.setAttribute("data", "data:text/html;charset=UTF-8;base64,"+
- btoa(frame_data));
-
- checker_frame.setAttribute("width","1px");
- checker_frame.setAttribute("height", "1px");
-
- document.getElementsByTagName("body")[0].appendChild(checker_frame);
+ this.create_checker_frame(jsonp_request_data);
}
// Get the new version data at window.location#<data> set by the child
// "frame" (object)
-LinternaMagica.prototype.parse_updated_version_data = function()
+LinternaMagica.prototype.parse_updated_version_data = function(data)
{
- this.updates_timeout_counter++;
+ var version = data.version;
- // With default timeout 10mS this will be 10 sec. Stop
- // checking. Something must be wrong.
- if (this.updates_timeout_counter >= 10000)
+ if ( version != this.version)
{
- clearInterval(this.updates_timeout);
- }
- if (/linterna_magica/i.test(window.location))
- {
- clearInterval(this.updates_timeout);
- var data = window.location.toString().split("&linterna_magica");
+ var date = data.date;
- // Clear our data from the address field
- window.location = data[0]+data[data.length-1];
-
- // Cleanup the checker object/frame
- var o = document.getElementById("linterna-magica-updates-checker");
- if (o)
- {
- o.parentNode.removeChild(o);
- }
+ // *** JavaScript demands mS! ***
+ date = new Date (parseInt(date)*1000);
+ var format_date = date.toString().replace(/[0-9]+:[0-9]+.*/,"");
- var version = data[1].split("lm_version=")[1].split("&")[0];
+ // 0 - day name ; 1 - Month ; 2 - day of month; 3 - year
+ // 0 - Mon, Tue, Wed, Thu, Fri, Sun, Sat
+ // 1 - Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Noe, Dec
+ format_date = format_date.split(" ");
- if ( version != this.version)
- {
+ // To be used by other functions
+ this.updates_data = new Object();
+ this.updates_data.date = date;
+ this.updates_data.version = version;
+ this.updates_data.format_date = format_date;
- var date = data[1].split("lm_date=")[1];
- // *** JavaScript demands mS! ***
- date = new Date (parseInt(date)*1000);
+ var self = this;
+ // Add notifier in the headers of all video objects
+ for (var n=0; n< this.dirty_objects.length; n++)
+ {
+ // header
+ var h = document.getElementById("linterna-magica-header-"+n);
- var format_date = date.toString().replace(/[0-9]+:[0-9]+.*/,"");
-
- // 0 - day name ; 1 - Month ; 2 - day of month; 3 - year
- // 0 - Mon, Tue, Wed, Thu, Fri, Sun, Sat
- // 1 - Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Noe, Dec
- format_date = format_date.split(" ");
+ // container
+ var lm = document.getElementById("linterna-magica-"+n);
- // To be used by other functions
- this.updates_data = new Object();
- this.updates_data.date = date;
- this.updates_data.version = version;
- this.updates_data.format_date = format_date;
-
-
- var self = this;
- // Add notifier in the headers of all video objects
- for (var n=0; n< this.dirty_objects.length; n++)
+ if (h && lm)
{
- // header
- var h = document.getElementById("linterna-magica-header-"+n);
- // container
- var lm = document.getElementById("linterna-magica-"+n);
+ var notifier = this.create_update_notifier_link(n);
+ var update_info = this.create_update_info_box(n);
- if (h && lm)
- {
+ notifier.
+ addEventListener("click", function(ev)
+ {
+ var el = this;
+ self.show_or_hide_update_info.
+ apply(self, [ev, el]);
+ }, false);
- var notifier = this.create_update_notifier_link(n);
- var update_info = this.create_update_info_box(n);
-
- notifier.
- addEventListener("click", function(ev)
- {
- var el = this;
- self.show_or_hide_update_info.
- apply(self, [ev, el]);
- }, false);
-
- h.appendChild(notifier);
- lm.appendChild(update_info);
- }
+ h.appendChild(notifier);
+ lm.appendChild(update_info);
}
}
}
Copied: branches/0.0.9/src/lm_jsonp_requests.js (from rev 90,
trunk/src/lm_jsonp_requests.js)
===================================================================
--- branches/0.0.9/src/lm_jsonp_requests.js (rev 0)
+++ branches/0.0.9/src/lm_jsonp_requests.js 2011-06-14 16:14:24 UTC (rev 91)
@@ -0,0 +1,207 @@
+// @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) 2010, 2011 Ivaylo Valkov <address@hidden>
+// Copyright (C) 2010 Anton Katsarov <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://e-valkov.org/linterna-magica
+
+// END OF LICENSE HEADER
+
+// Create the object/frame that will fetch the script with JSONP data
+// without sending referrer.
+// data =
+// {
+// // Where to save the setInterval id
+// parser_timeout: object,
+// // The counter object/variable used to count the time that passed
+// // since checking started
+// parser_timeout_counter: object,
+// // The URL where the JSONP data is
+// jsonp_script_link: string,
+// // The function to parse the data inside the frame
+// jsonp_function: string
+// // The function in LM that will use and parse the data.
+// parser_function: object,
+// // The id for the frame
+// frame_id: string
+// // Custom data to be passed to the parser_function
+// user_data: object
+// }
+LinternaMagica.prototype.create_checker_frame = function(data)
+{
+
+ if (!data || typeof(data) != "object")
+ {
+ return null;
+ }
+
+ if (!data.parser_timeout)
+ {
+ data.parser_timeout_counter = 0;
+ var self = this;
+
+ // Polling. The data will be retrieved in the main window =>
+ // the LinternaMagica object.
+ data.parser_timeout =
+ setInterval(function()
+ {
+ self.jsonp_data_parser.apply(self,[data]);
+ }, 10);
+ }
+
+ // The script is wrapped inside a data URI scheme. This way the
+ // page where the user was (referrer) is not sent. Cross-domain
+ // frame communcication with hashed messages
+ // (original-link#message=) is used to access the data.
+ var checker_frame = document.createElement("object");
+ checker_frame.setAttribute("id", data.frame_id);
+
+ var frame_script = function()
+ {
+ window[jsonp_function] = function (request_data)
+ {
+ var hash = /#/i.test(receiver_location) ? "" : "#";
+
+ // Pack the data
+ var packed_data =btoa(json_parser.json_to_string(request_data));
+
+ // If packed_data is null, native JSON is missing. At least
+ // updates should have backup. For updates the JSON object
+ // is simple and conversion is easy.
+ window.parent.location = decodeURI(receiver_location)+hash+
+ encodeURI("&linterna_magica&lm_request_data="+
+ packed_data+
+ "&linterna_magica");
+ };
+ };
+
+ var frame_data =
+ "<html><head>"+
+ "<script async='async' defer='defer' type='text/javascript'>"+
+ "var json_parser = new Object(); json_parser.json_to_string = "+
+ this.json_to_string.toString()+"; "+
+ "var jsonp_function ='"+data.jsonp_function+"'; "+
+ "var receiver_location='"+
+ encodeURI(window.location)+"';("+frame_script.toString()+")();"+
+ "</script>"+
+ "<script async='async' defer='defer' type='text/javascript' src='"+
+ data.jsonp_script_link+"'>"+
+ "</script>"+
+ "</head><body></body></html>";
+
+ checker_frame.setAttribute("data",
+ "data:text/html;charset=UTF-8;base64,"+
+ btoa(frame_data));
+
+ checker_frame.setAttribute("width","1px");
+ checker_frame.setAttribute("height", "1px");
+
+ document.getElementsByTagName("body")[0].appendChild(checker_frame);
+}
+
+// Parses the JSONP data and clears the frame/object. Passes the JSONP
+// data to the data.parser_function function. The format of the data
+// object is documented in create_checker_frame().
+LinternaMagica.prototype.jsonp_data_parser = function(data)
+{
+ if (!data || typeof(data) !== "object")
+ {
+ return null;
+ }
+
+ data.parser_timeout_counter++;
+
+ // With default timeout 10mS this will be 10 sec. Stop
+ // checking. Something must be wrong.
+ if (data.parser_timeout_counter >= 10000)
+ {
+ clearInterval(data.parser_timeout);
+ }
+
+ if (/linterna_magica/i.test(window.location))
+ {
+ clearInterval(data.parser_timeout);
+ var jsonp_data =
+ window.location.toString().split("&linterna_magica");
+
+ // Clear our data from the address field
+ window.location = jsonp_data[0]+jsonp_data[jsonp_data.length-1];
+
+ // Cleanup the checker object/frame
+ var o = document.getElementById(data.frame_id);
+ if (o)
+ {
+ o.parentNode.removeChild(o);
+ }
+
+ // The real data
+ jsonp_data = jsonp_data[1].split("lm_request_data=")[1].split("&")[0];
+
+ // Unpack
+ jsonp_data = this.string_to_json(atob(jsonp_data));
+
+ data.parser_function.apply(this, [jsonp_data, data.user_data]);
+ }
+}
+
+// Convert JSON to string. Older browsers lack native JSON
+// object. They will require custom code.
+LinternaMagica.prototype.json_to_string = function (json_object)
+{
+ var json_as_string = null;
+
+ if (typeof(JSON) == "object" &&
+ typeof(JSON.stringify) == "function")
+ {
+ try
+ {
+ json_as_string = JSON.stringify(json_object);
+ }
+ catch(e)
+ {
+ }
+ }
+
+ return json_as_string;
+}
+
+// Convert string to JSON. Older browsers lack native JSON
+// object. They will require custom code.
+LinternaMagica.prototype.string_to_json = function (json_string)
+{
+ var json_object = null;
+
+ if (typeof(JSON) == "object" &&
+ typeof(JSON.parse) == "function")
+ {
+ try
+ {
+ json_object = JSON.parse(json_string)
+ }
+ catch(e)
+ {
+ }
+ }
+
+ return json_object;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [linterna-magica-commit] [91] Backporting the framework changes in r90 manualy.,
Ivaylo Valkov <=