[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[linterna-magica-commit] [61] Removing the array with found flash object
From: |
Ivaylo Valkov |
Subject: |
[linterna-magica-commit] [61] Removing the array with found flash objects. |
Date: |
Fri, 13 May 2011 08:51:45 +0000 |
Revision: 61
http://svn.sv.gnu.org/viewvc/?view=rev&root=linterna-magica&revision=61
Author: valkov
Date: 2011-05-13 08:51:45 +0000 (Fri, 13 May 2011)
Log Message:
-----------
Removing the array with found flash objects. See tasks #11122
Ticket Links:
------------
http://savannah.gnu.org/task/?11122
Modified Paths:
--------------
trunk/TODO
trunk/src/lm_check_for_updates.js
trunk/src/lm_constructors.js
trunk/src/lm_create_video_object.js
trunk/src/lm_extract_dom_objects.js
trunk/src/lm_extract_js_pokkariplayer.js
trunk/src/lm_extract_js_swfobject.js
trunk/src/lm_extract_js_ufo.js
trunk/src/lm_interface_toggle_plugin.js
trunk/src/lm_player_button_functions.js
trunk/src/lm_site_vimeo.js
trunk/src/lm_site_youtube.js
trunk/src/lm_xhr.js
Added Paths:
-----------
trunk/src/lm_video_and_flash_objects_helper_functions.js
Modified: trunk/TODO
===================================================================
--- trunk/TODO 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/TODO 2011-05-13 08:51:45 UTC (rev 61)
@@ -18,9 +18,6 @@
and parse it for video_id or video link (see previous)
- Video link is in separate <script> tag. Uses SWFObject
-* Might be better to not have an array with flash objects, but just to
- make them invisible.
-
* Fix metacafe.com high definition links
- At the moment high definition videos are played, but there is no
option to switch to other links
Modified: trunk/src/lm_check_for_updates.js
===================================================================
--- trunk/src/lm_check_for_updates.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_check_for_updates.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -210,7 +210,7 @@
var self = this;
// Add notifier in the headers of all video objects
- for (var n=0; n< this.dirty_objects.length; n++)
+ for (var n=0; n< this.found_flash_video_objects.length; n++)
{
// header
var h = document.getElementById("linterna-magica-header-"+n);
Modified: trunk/src/lm_constructors.js
===================================================================
--- trunk/src/lm_constructors.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_constructors.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -112,12 +112,10 @@
// Add the style sheet to the head of the document.
this.create_stylesheet();
- // Array of flash objects
- this.dirty_objects = new Array();
+ // Video flash objects counter. Counting starts from zero for the
+ // first found object with the first increment.
+ this.found_flash_video_objects = -1;
- // Array of created "video" objects
- this.video_objects = new Array();
-
// Object holding data for curently processed video ids with
// XMLHttpRequest. Keys video_id+host , values 1/0.
// Prevent creation of two video objects in YouTube
Modified: trunk/src/lm_create_video_object.js
===================================================================
--- trunk/src/lm_create_video_object.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_create_video_object.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -39,8 +39,6 @@
"Creating video object with linterna_magica_id "+id,2);
// Check if another object is created already there and skip.
- // this.dirty_objects[(id-1)] will brak for scripts, because it is
- // null
if (((id-1) >= 0))
{
// Will break if the there is object that is not created just
@@ -300,9 +298,10 @@
(parseInt(object_data.height)-20)+"px",
"important");
container.appendChild(about_box);
+
+ object_tag.setAttribute("class",
+ this.marked_object_template+"-video-"+id);
- object_tag.setAttribute("linterna_magica_id", id);
-
// Add link after the object/embed
// this.set_priority() has set this.priority
// to self if there is no plugin
@@ -318,7 +317,8 @@
"px", "important");
}
- var before = this.dirty_objects[id].nextSibling;
+ var before = this.get_flash_video_object(id).nextSibling;
+
if (before)
{
object_data.parent.insertBefore(toggle_plugin, before);
@@ -344,19 +344,19 @@
// then insert the new one, otherwise a loop is created
// in extract_objects_from_dom.
- // Remove the object if it is in DOM
- // Objects extracted from script has null value in this.dirty_objects
- if (/self/i.test(this.priority)
- && this.dirty_objects[id]
+ var dom_object = this.get_flash_video_object(id);
+ // Remove/hide the object if it is in DOM
+ if (/self/i.test(this.priority) &&
+ dom_object &&
// The object is still in DOM some scripts remove it
- && this.dirty_objects[id].parentNode)
+ dom_object.parentNode)
{
- if(this.dirty_objects[id].nextSibling)
+ if(dom_object.nextSibling)
{
- object_data.use_sibling = this.dirty_objects[id].nextSibling;
+ object_data.use_sibling = dom_object.nextSibling;
}
- object_data.parent.removeChild(this.dirty_objects[id]);
+ this.hide_flash_video_object(id,dom_object.parentNode);
}
if (/self/i.test(this.priority) && this.plugin_is_installed)
@@ -447,14 +447,15 @@
// }
}
+ var dom_object = this.get_flash_video_object(id);
// Objects extracted from script usually does not have cloned object
// For example youtube
- if (this.dirty_objects[id])
+ if (dom_object)
{
// Prevent the object to fill the container at 100% (if set)
// This way the toggle plugin link after the object is not
// overlaping elements.
- this.dirty_objects[id].style.setProperty("height",
+ dom_object.style.setProperty("height",
object_data.height+"px",
"important");
}
@@ -586,9 +587,6 @@
// Temporary
// parent.style.setProperty("border", "1px solid red", "important");
- // Push to video object list
- this.video_objects.push(container);
-
// Init the web controls functions
// only if Linterna Mágica has priority
if (this.controls &&
Modified: trunk/src/lm_extract_dom_objects.js
===================================================================
--- trunk/src/lm_extract_dom_objects.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_extract_dom_objects.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -41,11 +41,14 @@
{
var object = objects[i];
- if (object.hasAttribute("linterna_magica_id"))
+ if (object.hasAttribute("class") &&
+ this.object_has_css_class(object,
+ this.marked_object_template+".*"))
{
this.log("LinternaMagica.extract_objects_from_dom:\n"+
"Skipping processed object with linterna_magica_id:"+
- object.getAttribute("linterna_magica_id"),2);
+ this.get_marked_object_id(object), 2);
+
continue;
}
@@ -86,14 +89,12 @@
var extracted_data = this.extract_link_from_param_list();
}
-
object_data.remote_site_link = extracted_data.remote_site_link;
object_data.link = extracted_data.link;
object_data.video_id = extracted_data.video_id;
object_data.hd_links =
extracted_data.hd_links || null;
-
if (!object_data.link && !object_data.video_id &&
!object_data.remote_site_link)
@@ -102,6 +103,7 @@
"No video_id, link or remote site link"+
" found. Not creating video oject or remote"+
" video button.",1);
+
continue;
}
@@ -110,6 +112,7 @@
{
// See the comments for this function
object_data.link = this.create_myvideode_link();
+
// Now that we have a link remove the video_id
// so it is not processed
if (object_data.link)
@@ -119,70 +122,52 @@
}
var parent = object.parentNode.localName.toLowerCase();
+
// Remove all the junk.
if (parent === "object" ||
parent === "embed")
{
+ // Usually both have the same flashvars and movie.
this.log("LinternaMagica.extract_objects_from_dom:\n"+
"Using <"+object.localName+"> parentNode: <"+
object.parentNode.localName+">.",1);
-
- this.dirty_objects.push(object.parentNode);
-
- // Mark the parent object as procressed because it will
- // be detected again when the video object is
- // insterted/created
- object.parentNode.setAttribute("linterna_magica_id",
- (this.dirty_objects.length-1));
-
- object_data.parent = object.parentNode.parentNode;
-
- // We need to use parent object/emebd so if data is
- // missing it can be extracted from parent wrapper
- // element (div/span)
- object_data.width = this.extract_object_width(
- object.parentNode);
-
- object_data.height = this.extract_object_height(
- object.parentNode);
+ // The parentNode is marked last and only it will be
+ // processed. The child will have marker/id and will
+ // not be processed at all later.
+ this.mark_flash_video_object(object);
+ object = object.parentNode;
}
- else
+
+ // Do not process objects without parent. This bug
+ // showed up at i-kat.org. The site uses an object inline
+ // in another one and both have video link. When the
+ // parent object is processed and replaced with a video
+ // object, the second (child of the first) looses its
+ // parent and Linterna Mágica crashes. There might be a
+ // better solution to this. It acctualy crashes just
+ // before/after calling remove_plugin_install_warning.
+ if (!object.parentNode)
{
- // Do not process objects without parent. This bug
- // showed up at i-kat.org. The site uses an object inline
- // in another one and both have video link. When the
- // parent object is processed and replaced with a video
- // object, the second (child of the first) looses its
- // parent and Linterna Mágica crashes. There might be a
- // better solution to this. It acctualy crashes just
- // before/after calling remove_plugin_install_warning.
- if (!object.parentNode)
- {
- this.log("LinternaMagica.extract_objects_from_dom:\n"+
- "Object's parent node dissapeared."+
- " No link found (yet) in this object.",1);
- return null;
- }
+ this.log("LinternaMagica.extract_objects_from_dom:\n"+
+ "Object's parent node dissapeared."+
+ " No link found (yet) in this object.",1);
+ return null;
+ }
- this.dirty_objects.push(object);
- object_data.parent = object.parentNode;
+ this.mark_flash_object(object);
+ object_data.parent = object.parentNode;
- object_data.width = this.extract_object_width(object);
- object_data.height = this.extract_object_height(object);
- }
+ object_data.width = this.extract_object_width(object);
+ object_data.height = this.extract_object_height(object);
- // Prevent second processing of this object
- object.setAttribute("linterna_magica_id",
- (this.dirty_objects.length-1));
+ object_data.linterna_magica_id =
+ this.get_marked_object_id(object);
this.log("LinternaMagica.extract_objects_from_dom:\n"+
"Object linterna_magica_id set to: "+
- object.getAttribute("linterna_magica_id"),2);
+ object_data.linterna_magica_id,2);
- object_data.linterna_magica_id =
- object.getAttribute("linterna_magica_id");
-
if (object_data.remote_site_link)
{
this.log("LinternaMagica.extract_objects_from_dom:\n"+
@@ -191,23 +176,24 @@
var remote_site =
this.create_remote_site_link(object_data);
- var lm_id = object_data.linterna_magica_id;
- var before = this.dirty_objects[lm_id].nextSibling;
+ var before = object.nextSibling;
+
if (before)
{
object_data.parent.insertBefore(remote_site, before);
- }
+ }
else
{
object_data.parent.appendChild(remote_site);
}
+
// We only need:
- // * linetrna_magica_id attribute set;
- // * object_data.parent set;
+ // * linetrna_magica_id to be set;
+ // * object_data.parent to be set;
// * the <object><embed/><object> detected.
continue;
- }
+ }
else if (object_data.link)
{
this.log("LinternaMagica.extract_objects_from_dom:\n"+
@@ -335,7 +321,8 @@
// Fix small height in Google Video with IceCat, Abrowser etc.
// Skip to parent height. The object has embed child node with
// valid height. Because the parent is object we use it instead.
- else if (element.offsetHeight &&
!/video\.google\./i.test(window.location.href))
+ else if (element.offsetHeight &&
+ !/video\.google\./i.test(window.location.href))
{
height = element.offsetHeight;
}
Modified: trunk/src/lm_extract_js_pokkariplayer.js
===================================================================
--- trunk/src/lm_extract_js_pokkariplayer.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_extract_js_pokkariplayer.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -72,23 +72,20 @@
return null;
var embed_object = element.getElementsByTagName("object")[0];
+ var linterna_magica_id = null;
if (embed_object)
{
- this.dirty_objects.push(embed_object);
- embed_object.setAttribute("linterna_magica_id",
- this.dirty_objects.length-1);
-
+ linterna_magica_id = this.mark_flash_object(embed_object);
}
else
{
- // Ugly && dirty hack.
- // This way we have linterna_magica_id
- this.dirty_objects.push(null);
+ linterna_magica_id =
+ this.mark_flash_object("extracted-from-script");
}
var object_data = new Object();
- object_data.linterna_magica_id = this.dirty_objects.length-1;
+ object_data.linterna_magica_id = linterna_magica_id;
object_data.width = width;
object_data.height = height;
Modified: trunk/src/lm_extract_js_swfobject.js
===================================================================
--- trunk/src/lm_extract_js_swfobject.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_extract_js_swfobject.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -163,10 +163,9 @@
this.log("LinternaMagica.extract_object_from_script_swfobject:\n"+
"SWF object extracted from script ",1);
- // Ugly && dirty hack.
- // This way we have linterna_magica_id
- this.dirty_objects.push(null);
- object_data.linterna_magica_id = this.dirty_objects.length-1;
+ object_data.linterna_magica_id =
+ this.mark-flash_object("extracted-from-script");
+
return object_data;
}
Modified: trunk/src/lm_extract_js_ufo.js
===================================================================
--- trunk/src/lm_extract_js_ufo.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_extract_js_ufo.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -97,10 +97,9 @@
this.log("LinternaMagica.extract_object_from_script_ufo:\n"+
"SWF object extracted from script ",1);
- // Ugly && dirty hack.
- // This way we have linterna_magica_id
- this.dirty_objects.push(null);
- object_data.linterna_magica_id = this.dirty_objects.length-1;
+ object_data.linterna_magica_id =
+ this.mark_flash_object("extracted-from-script");
+
return object_data;
}
Modified: trunk/src/lm_interface_toggle_plugin.js
===================================================================
--- trunk/src/lm_interface_toggle_plugin.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_interface_toggle_plugin.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -53,7 +53,8 @@
{
toggle_plugin.textContent = "Linterna Mágica >>";
-
+ toggle_plugin.setAttribute("id",
+ "linterna-magica-toggle-plugin-"+id);
// Fix link displacement after an object (vbox7 and others)
wrapper = document.createElement("p");
wrapper.appendChild(toggle_plugin);
@@ -86,70 +87,74 @@
// for the external link
// element->p->div_with_object->object
- var parent = element.parentNode;
- if (parent.previousSibling &&
- /object|embed/i.test(parent.previousSibling.localName))
+ var linterna_magica_id = element.getAttribute("id");
+ linterna_magica_id = linterna_magica_id.split("-");
+ linterna_magica_id = linterna_magica_id[linterna_magica_id.length-1];
+
+ var video_object =
+ document.getElementById("linterna-magica-video-object-"+
+ linterna_magica_id);
+
+ var flash_object =
+ this.get_flash_video_object(linterna_magica_id,
+ // The parent of the div holding
+ // Linterna Mágica
+ video_object.parentNode.parentNode);
+
+ console.log("Flash "+flash_object+
+ " video "+video_object+
+ " lm "+linterna_magica_id);
+
+ if (!flash_object && !video_object)
{
- // Must be "external" toggle_plugin link (Linterna Mágica >>)
- var obj = parent.previousSibling;
+ return null;
}
- else
- {
- var id = element.getAttribute("id");
- id = id.split("-");
- id = id[id.length-1];
- // Must be toggle_plugin link in header
- var obj = document.getElementById("linterna-magica-video-object-"+id);
- // element.parentNode.parentNode.
- // getElementsByTagName("object")[0];
- }
- // Give up
- if (!obj)
- return null;
-
- var type = obj.getAttribute("type");
- // Not every swf has type
- // There might be a problem with <object><embed></object> structures
- // where the object has no attributes for flash detection
- if (this.is_swf_object(obj))
+ // Visible flash, hidden video object. Display has value (none)
+ // when the object is hidden.
+ if (!flash_object.style.getPropertyValue("display") &&
+ video_object.parentNode.style.getPropertyValue("display"))
{
this.log("LinternaMagica.toggle_plugin:\n"+
- "Replacing swf object (id:"+
- obj.getAttribute("linterna_magica_id")+
+ "Replacing/hiding swf object (id:"+
+ linterna_magica_id+
") with video object.", 4);
- var video_object = this.video_objects[
- obj.getAttribute("linterna_magica_id")];
+ this.hide_flash_video_object(linterna_magica_id,
+ flash_object.parentNode);
- // The link is in a paragraph (because of link displacement
- // fix in some sites)
- obj.parentNode.insertBefore(video_object, parent);
+ this.show_lm_video(linterna_magica_id);
// Init the web controls
if (this.controls)
{
- this.player.init.apply(this,[
- obj.getAttribute("linterna_magica_id")]);
+ this.player.init.apply(this,[linterna_magica_id]);
}
- obj.parentNode.removeChild(obj);
- parent.style.setProperty("display", "none", "important");
+
+ // Hide the external toggle plugin link
+ var ext_toggle_wrapper = video_object.parentNode.nextSibling;
+ ext_toggle_wrapper.style.setProperty("display", "none", "important");
+ console.log("Hiding flash, showing video, hiding ext toggle");
}
- else if(/video/i.test(type))
+ // Hidden flash, visible video object. Display has value (none)
+ // when the object is hidden.
+ else if (!video_object.parentNode.style.getPropertyValue("display") &&
+ flash_object.style.getPropertyValue("display"))
{
this.log("LinternaMagica.toggle_plugin:\n"+
- "Replacing video object (id:"+
- obj.getAttribute("linterna_magica_id")+
+ "Replacing/hiding video object (id:"+
+ linterna_magica_id+
") with swf object.", 4);
- // Must be the toggle plugin link
- obj.parentNode.nextSibling.style.removeProperty("display");
+ this.hide_lm_video(linterna_magica_id);
+ this.show_flash_video_object(linterna_magica_id,
+ flash_object.parentNode);
+
+ // External toggle plugin link
+ var ext_toggle_wrapper = video_object.parentNode.nextSibling;
+ ext_toggle_wrapper.style.removeProperty("display");
- var dirty_object = this.dirty_objects[
- obj.getAttribute("linterna_magica_id")];
- obj.parentNode.parentNode.insertBefore(dirty_object,
- obj.parentNode.nextSibling);
-
- obj.parentNode.parentNode.removeChild(obj.parentNode);
+ console.log("Showing flash, hiding video, showing ext toggle");
}
+ console.log("Post ifs ");
}
Modified: trunk/src/lm_player_button_functions.js
===================================================================
--- trunk/src/lm_player_button_functions.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_player_button_functions.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -27,19 +27,6 @@
// END OF LICENSE HEADER
-
-// Find the current video object in the DOM
-LinternaMagica.prototype.get_video_object = function(id)
-{
- var video_object = null;
-
- video_object = window.document.
- getElementById("linterna-magica-video-object-"+id);
-
- return video_object;
-}
-
-
// Set player_name attribute to video objects.
// This is used to know wchich API to use
// navigator.plugins[x].name:
Modified: trunk/src/lm_site_vimeo.js
===================================================================
--- trunk/src/lm_site_vimeo.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_site_vimeo.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -133,10 +133,9 @@
this.log("LinternaMagica.extract_object_from_script_vimeo:\n"+
"Object data extracted from script ",1);
- // Ugly && dirty hack.
- // This way we have linterna_magica_id
- this.dirty_objects.push(null);
- object_data.linterna_magica_id = this.dirty_objects.length-1;
+ object_data.linterna_magica_id =
+ this.mark_flash_object("extracted-from-script");
+
return object_data;
}
Modified: trunk/src/lm_site_youtube.js
===================================================================
--- trunk/src/lm_site_youtube.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_site_youtube.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -223,6 +223,7 @@
var object_data = new Object();
+ var linterna_magica_id = null;
object_data.width= width;
object_data.height= height;
@@ -235,7 +236,9 @@
{
if (this.plugin_is_installed)
{
- this.dirty_objects.push(embed_object);
+ linterna_magica_id =
+ this.mark_flash_object(embed_object);
+
object_data.parent = embed_object.parentNode;
}
}
@@ -246,12 +249,12 @@
(embed_object &&
!this.plugin_is_installed))
{
- // Ugly && dirty hack.
- // This way we have linterna_magica_id
- this.dirty_objects.push(null);
+ linterna_magica_id =
+ this.mark_flash_object("extracted-from-script");
+
object_data.parent = document.getElementById("watch-player");
}
- object_data.linterna_magica_id = this.dirty_objects.length-1;
+ object_data.linterna_magica_id = linterna_magica_id;
return object_data;
}
Added: trunk/src/lm_video_and_flash_objects_helper_functions.js
===================================================================
--- trunk/src/lm_video_and_flash_objects_helper_functions.js
(rev 0)
+++ trunk/src/lm_video_and_flash_objects_helper_functions.js 2011-05-13
08:51:45 UTC (rev 61)
@@ -0,0 +1,191 @@
+// @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://e-valkov.org/linterna-magica
+
+// END OF LICENSE HEADER
+
+// Used for class names of marked objects. Flash objects might have
+// id's already. It is not a good idea to replace them.
+LinternaMagica.prototype.marked_object_template =
+ "linterna-magica-processed-object-";
+
+// Increment the counter for found video flash objects, mark the
+// element with appropriate class attribute and return the new value.
+LinternaMagica.prototype.mark_flash_object = function(element)
+{
+ this.found_flash_video_objects ++;
+
+ // Video objects extracted from scripts usually do not exist in
+ // DOM. Then we just have to increment the counter.
+ if (element != "extracted-from-script")
+ {
+ var linterna_magica_id = this.marked_object_template+
+ this.found_flash_video_objects;
+
+ var original_class = element.hasAttribute("class") ?
+ ( element.getAttribute("class") +" "): "";
+
+ element.setAttribute("class", original_class + linterna_magica_id);
+ }
+
+ return this.found_flash_video_objects;
+}
+
+// Get the DOM object with Linterna Magica id
+LinternaMagica.prototype.get_flash_video_object =
+function(linterna_magica_id)
+{
+ return this.getElementByClass(this.marked_object_template+
+ linterna_magica_id);
+}
+
+// Get the id (linterna_magica_id) of marked flash object.
+LinternaMagica.prototype.get_marked_object_id =
+function(element)
+{
+ var class_name = this.marked_object_template +"(-[A-Za-z]+-)*([0-9]+)";
+
+ var matches_class = this.object_has_css_class(element, class_name);
+
+ if (element.hasAttribute("class") && matches_class)
+ {
+ // [0-9]+. Must be the last.
+ return matches_class.split("-")[matches_class.length-1];
+ }
+
+ return null;
+}
+
+// Get the first element matching CSS class. Without the parent node
+// searches trough document.
+LinternaMagica.prototype.getElementByClass = function(className, parent)
+{
+ var top = parent ? parent : document;
+
+ var children = top.getElementsByTagName("*");
+
+ if (!children)
+ {
+ return null;
+ }
+
+ for (var i=0, l=children.length; i <l; i++)
+ {
+ var el = children[i];
+ if (this.object_has_css_class(el, className))
+ {
+ return el;
+ }
+ }
+
+ return null;
+}
+
+// Check if DOM element has CSS class matching the string in className
+LinternaMagica.prototype.object_has_css_class = function (element, className)
+{
+ var class_regex = new RegExp ("\\\s*("+className+")\\\s*","");
+ var matches_class = element.hasAttribute("class") ?
+ element.getAttribute("class").match(class_regex) : null;
+
+ if (matches_class)
+ {
+ return matches_class[matches_class.length-1];
+ }
+
+ return false;
+}
+
+// Get the video object with id
+// "linterna-magica-video-object-"+linterna_magica_id from DOM
+LinternaMagica.prototype.get_video_object = function(linterna_magica_id)
+{
+ var video_object = null;
+
+ video_object = document.
+ getElementById("linterna-magica-video-object-"+linterna_magica_id);
+
+ return video_object;
+}
+
+// Show the video object and the interface
+LinternaMagica.prototype.show_lm_video = function(linterna_magica_id)
+{
+ var lm = this.get_video_object(linterna_magica_id).parentNode;
+
+ if (!lm)
+ {
+ return null;
+ }
+
+ lm.style.removeProperty("display");
+}
+
+// Hide the video object and the interface
+LinternaMagica.prototype.hide_lm_video = function(linterna_magica_id)
+{
+ var lm = this.get_video_object(linterna_magica_id).parentNode;
+
+ if (!lm)
+ {
+ return null;
+ }
+
+ lm.style.setProperty("display", "none", "important");
+}
+
+// Show the flash video object
+LinternaMagica.prototype.show_flash_video_object =
+function(linterna_magica_id,parent)
+{
+ var flash_object =
+ this.get_flash_video_object(linterna_magica_id,parent);
+
+ if (!flash_object)
+ {
+ return null;
+ }
+
+ flash_object.style.removeProperty("display");
+
+ return flash_object;
+}
+
+// Hide the flash video object
+LinternaMagica.prototype.hide_flash_video_object =
+function(linterna_magica_id, parent)
+{
+ var flash_object =
+ this.get_flash_video_object(linterna_magica_id, parent);
+
+ if (!flash_object)
+ {
+ return null;
+ }
+
+ flash_object.style.setProperty("display", "none", "important");
+
+ return flash_object;
+}
Modified: trunk/src/lm_xhr.js
===================================================================
--- trunk/src/lm_xhr.js 2011-05-10 06:51:51 UTC (rev 60)
+++ trunk/src/lm_xhr.js 2011-05-13 08:51:45 UTC (rev 61)
@@ -60,9 +60,10 @@
/youtube-nocookie\.com/i.test(window.location.hostname))
{
this.log("LinternaMagica.request_video_link:\n"+
- "Removing duplicate object ",1);
- object_data.parent.removeChild(this.dirty_objects[
- object_data.linterna_magica_id]);
+ "Removing/hiding duplicate object ",1);
+
+ this.hide_flash_video_object(object_data.linterna_magica_id,
+ object_data.parent);
}
return null;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [linterna-magica-commit] [61] Removing the array with found flash objects.,
Ivaylo Valkov <=