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

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

[linterna-magica-commit] [80] Work on tasks #11193 and tasks #11122.


From: Ivaylo Valkov
Subject: [linterna-magica-commit] [80] Work on tasks #11193 and tasks #11122.
Date: Sat, 11 Jun 2011 09:18:10 +0000

Revision: 80
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=linterna-magica&revision=80
Author:   valkov
Date:     2011-06-11 09:18:09 +0000 (Sat, 11 Jun 2011)
Log Message:
-----------
Work on tasks #11193 and tasks #11122. Seems fine so far, but needs more 
testing before closing the tasks.

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

Modified Paths:
--------------
    trunk/src/lm_extract_dom_objects.js
    trunk/src/lm_player_button_functions.js
    trunk/src/lm_video_and_flash_objects_helper_functions.js
    trunk/src/lm_xhr.js

Modified: trunk/src/lm_extract_dom_objects.js
===================================================================
--- trunk/src/lm_extract_dom_objects.js 2011-05-24 14:20:50 UTC (rev 79)
+++ trunk/src/lm_extract_dom_objects.js 2011-06-11 09:18:09 UTC (rev 80)
@@ -41,9 +41,8 @@
     {
        var object = objects[i];
 
-       if (object.hasAttribute("class") && 
-           this.object_has_css_class(object, 
-                                     this.marked_object_template+".*"))
+       // Zero is an option
+       if (object.linterna_magica_id != undefined)
        {
            this.log("LinternaMagica.extract_objects_from_dom:\n"+
                     "Skipping processed object with linterna_magica_id:"+

Modified: trunk/src/lm_player_button_functions.js
===================================================================
--- trunk/src/lm_player_button_functions.js     2011-05-24 14:20:50 UTC (rev 79)
+++ trunk/src/lm_player_button_functions.js     2011-06-11 09:18:09 UTC (rev 80)
@@ -27,7 +27,8 @@
 
 // END OF LICENSE HEADER
 
-// Set player_name attribute to video objects.
+
+// Set lm_player_name property
 // This is used to know wchich API to use
 // navigator.plugins[x].name:
 // Tototem:  VLC Multimedia Plugin (compatible Totem 2.30.1)
@@ -37,10 +38,17 @@
 // NOTE:
 // navigator.mimeTypes["video/flv"].enabledPlugin.name is not
 // reliable if more than one plugin is installed.
+// This is done once, and all the other functions just check a string.
 LinternaMagica.prototype.player.set_player_name = function(id)
 {
     var name = null;
     var video_object = this.get_video_object(id);
+
+    if (!video_object)
+    {
+       return null;
+    }
+
     var mimeTypes = navigator.mimeTypes;
 
     var mime = mimeTypes[video_object.getAttribute("type")];
@@ -58,12 +66,26 @@
     {
        this.log("LinternaMagica.player.set_player_name:\n"+
                 "Name set to "+name,3);
-       video_object.setAttribute("player_name", name);
+       video_object.lm_player_name = name;
     }
 
     return name;
 }
 
+// Return the name ofthe plugin that will play the video.
+LinternaMagica.prototype.get_player_name = function(id)
+{
+    var name = null;
+    var video_object = this.get_video_object(id);
+
+    if (video_object)
+    {
+       name = video_object.lm_player_name;
+    }
+
+    return name;
+}
+
 // Returns an object with
 //  video duration
 //  current position,
@@ -79,12 +101,13 @@
 LinternaMagica.prototype.player.state = function(id)
 {
     var video_object = this.get_video_object(id);
+    var player_name = this.get_player_name(id);
 
-    if (!video_object)
+    if (!video_object || !player_name)
+    {
        return null;
+    }
 
-    var player_name = video_object.getAttribute("player_name");
-
     var time = new Object();
     time.duration = null;
     time.position = null;
@@ -142,7 +165,7 @@
 
        if (!time.state && video_object.input)
        {
-           // Fix exception when switching between
+           // Fixes exception when switching between
            // Linterna Mágica and flash plugin
            try
            {
@@ -178,7 +201,7 @@
 
        if (!time.state)
        {
-           // Fix exception when switching between
+           // Fixes exception when switching between
            // Linterna Mágica and flash plugin
            try
            {
@@ -186,7 +209,7 @@
                time.duration = video_object.controls.GetLength()/1000;
                // Xine does not have percent
                time.percent =  (time.position/time.duration);
-               // Fix NaN result (division by 0)
+               // Fixes NaN result (division by 0)
                time.percent = time.percent ? time.percent : 0;
            }
            catch(e)
@@ -220,7 +243,7 @@
 
        if (!time.state)
        {
-           // Fix exception when switching between
+           // Fixes exception when switching between
            // Linterna Mágica and flash plugin
            try
            {
@@ -230,7 +253,7 @@
                // return the same format as getPercent() in
                // gecko-mediaplayer
                time.percent = (time.position/time.duration);
-               // Fix NaN result (division by 0)
+               // Fixes NaN result (division by 0)
                time.percent = time.percent ? time.percent : 0;
            }
            catch(e)
@@ -249,7 +272,6 @@
        }
     }
 
-    // new
     var sec_pos = Math.round(time.position) % 60;
     var min_pos = Math.round(time.position / 60) % 60;
     var hour_pos = Math.round(time.position / 3600);
@@ -273,8 +295,13 @@
 LinternaMagica.prototype.player.pause = function(id)
 {
     var video_object = this.get_video_object(id);
-    var player_name = video_object.getAttribute("player_name");
+    var player_name = this.get_player_name(id);
 
+    if (!video_object || !player_name)
+    {
+       return null;
+    }
+
     if (/gecko-mediaplayer/.test(player_name))
     {
        video_object.Pause();
@@ -299,11 +326,16 @@
 LinternaMagica.prototype.player.play = function(id)
 {
     var video_object = this.get_video_object(id);
-    var player_name = video_object.getAttribute("player_name");
+    var player_name = this.get_player_name(id);
 
-    if (/gecko-mediaplayer/.test(player_name)
-       || /totem/.test(player_name))
+    if (!video_object || !player_name)
     {
+       return null;
+    }
+
+    if (/gecko-mediaplayer/.test(player_name) ||
+       /totem/.test(player_name))
+    {
        video_object.Play();
     }
     else if (/vlc/i.test(player_name))
@@ -325,8 +357,13 @@
 LinternaMagica.prototype.player.stop = function(id)
 {
     var video_object = this.get_video_object(id);
-    var player_name = video_object.getAttribute("player_name");
+    var player_name = this.get_player_name(id);
 
+    if(!video_object || !player_name)
+    {
+       return null;
+    }
+
     if (/gecko-mediaplayer/.test(player_name))
     {
        video_object.Stop();
@@ -351,15 +388,21 @@
 LinternaMagica.prototype.player.forward = function(id,time)
 {
     var video_object = this.get_video_object(id);
-    var player_name = video_object.getAttribute("player_name");
+    var player_name = this.get_player_name(id);
+
+    if (!video_object || !player_name)
+    {
+       return null;
+    }
+
     // 10 seconds
     if (!time)
     {
        time = 10000;
     }
 
-    if (/gecko-mediaplayer/.test(player_name)
-       || /quicktime plug-in/i.test(player_name))
+    if (/gecko-mediaplayer/.test(player_name) ||
+       /quicktime plug-in/i.test(player_name))
     {
        if (/%/.test(time))
        {
@@ -421,8 +464,13 @@
 LinternaMagica.prototype.player.rewind = function(id,time)
 {
     var video_object = this.get_video_object(id);
-    var player_name = video_object.getAttribute("player_name");
+    var player_name = this.get_player_name(id);
 
+    if (!video_object || !player_name)
+    {
+       return null;
+    }
+
     if (!time)
        time = 10000;
 
@@ -487,8 +535,13 @@
 LinternaMagica.prototype.player.fullscreen = function(id)
 {
     var video_object = this.get_video_object(id);
-    var player_name = video_object.getAttribute("player_name");
+    var player_name = this.get_player_name(id);
 
+    if (!video_object || !player_name)
+    {
+       return null;
+    }
+
     if (/gecko-mediaplayer/.test(player_name))
     {
        video_object.fullscreen = true;
@@ -516,8 +569,13 @@
 LinternaMagica.prototype.player.set_volume = function (id, volume)
 {
     var video_object = this.get_video_object(id);
-    var player_name = video_object.getAttribute("player_name");
+    var player_name = this.get_player_name(id);
 
+    if (!video_object || !player_name)
+    {
+       return null;
+    }
+
     // The slider control function returns values as string with % in
     // them.
     volume  = parseInt(volume.replace(/%/,""));
@@ -547,30 +605,35 @@
 LinternaMagica.prototype.player.toggle_mute = function (id)
 {
     var video_object = this.get_video_object(id);
-    var player_name = video_object.getAttribute("player_name");
+    var player_name = this.get_player_name(id);
 
+    if (!video_object || !player_name)
+    {
+       return null;
+    }
+
     var vol = null;
 
-    if (/gecko-mediaplayer/.test(player_name)
+    if (/gecko-mediaplayer/.test(player_name) ||
        // totemNarrowspace plugin (quicktime)
-       || /quicktime plug-in/i.test(player_name))
+       /quicktime plug-in/i.test(player_name))
     {
        // totemNarrowspace has get/set mute but
        // can not make it work
        // gecko do not have mute method in the API
        // Mute
-       if (!video_object.hasAttribute("linterna_magica_volume"))
+       if (!video_object.lm_player_volume)
        {
            vol = video_object.GetVolume();
-           video_object.setAttribute("linterna_magica_volume", vol);
+           video_object.lm_player_volume, vol;
            video_object.SetVolume(0);
        }
        // unMute
        else
        {
-           vol = video_object.getAttribute("linterna_magica_volume");
+           vol = video_object.lm_player_volume;
            video_object.SetVolume(parseInt(vol));
-           video_object.removeAttribute("linterna_magica_volume");
+           delete video_object.lm_player_volume;
            // totemNarrowspace uses 255 as max value
            // calculcate as 100
            if (/quicktime/i.test(player_name))
@@ -628,7 +691,9 @@
     }
 
     if (!knob)
+    {
        return null;
+    }
 
     var move = null;
     if (this.languages[this.lang].__direction == "ltr" ||
@@ -775,13 +840,15 @@
     // With it the logic kills the ticker before  the plugin starts
 
     if (!time_and_state)
+    {
        return;
+    }
 
     // Prevent clearing before the clip starts
     // Clear when the video end is reached
     // or null returned (no video_object found)
-    if ((time_and_state.position && time_and_state.duration)
-       && (time_and_state.position >= time_and_state.duration))
+    if ((time_and_state.position && time_and_state.duration) &&
+       (time_and_state.position >= time_and_state.duration))
     {
        clearInterval(self.player_timers[id]);
        delete self.player_timers[id];

Modified: trunk/src/lm_video_and_flash_objects_helper_functions.js
===================================================================
--- trunk/src/lm_video_and_flash_objects_helper_functions.js    2011-05-24 
14:20:50 UTC (rev 79)
+++ trunk/src/lm_video_and_flash_objects_helper_functions.js    2011-06-11 
09:18:09 UTC (rev 80)
@@ -41,13 +41,7 @@
     // 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);
+       element.linterna_magica_id = this.found_flash_video_objects;
     }
 
     return this.found_flash_video_objects;
@@ -57,30 +51,33 @@
 LinternaMagica.prototype.get_flash_video_object =
 function(linterna_magica_id)
 {
-    return this.getElementByClass(this.marked_object_template+
-                                 linterna_magica_id);
+    // Scan the document object for object, embed and iframe objects
+    var object_list = this.create_object_list();
+
+    for (var i=0, l=object_list.length; i<l; i++)
+    {
+       var o = object_list[i];
+
+       if (o.linterna_magica_id != undefined)
+       {
+           return o;
+       }
+    }
+
+    return null;
 }
 
 // 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;
+    return element.linterna_magica_id;
 }
 
 // Get the first element matching CSS class. Without the parent node
 // searches trough document.
-LinternaMagica.prototype.getElementByClass = function(className, parent)
+LinternaMagica.prototype.get_first_element_by_class =
+function(className, parent)
 {
     var top = parent ? parent : document;
 

Modified: trunk/src/lm_xhr.js
===================================================================
--- trunk/src/lm_xhr.js 2011-05-24 14:20:50 UTC (rev 79)
+++ trunk/src/lm_xhr.js 2011-06-11 09:18:09 UTC (rev 80)
@@ -375,7 +375,7 @@
                body.innerHTML = original_body_data;
 
                object_data.parent = 
-                   this.getElementByClass("dmpi_video_playerv[0-9]+");
+                   this.get_first_element_by_class("dmpi_video_playerv[0-9]+");
 
                if (!object_data.parent)
                {




reply via email to

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