Author: andre
Date: 2010-06-24 12:47:50 +0200 (Thu, 24 Jun 2010)
New Revision: 42676

Modified:
   openimages/trunk/src/main/webapp/oiplayer/js/jquery.oiplayer.js
Log:
prevent control events from being bound twice, sometimes this happens


Modified: openimages/trunk/src/main/webapp/oiplayer/js/jquery.oiplayer.js
===================================================================
--- openimages/trunk/src/main/webapp/oiplayer/js/jquery.oiplayer.js     
2010-06-24 10:19:28 UTC (rev 42675)
+++ openimages/trunk/src/main/webapp/oiplayer/js/jquery.oiplayer.js     
2010-06-24 10:47:50 UTC (rev 42676)
@@ -38,8 +38,10 @@
         flash : '/oiplayer/plugins/flowplayer-3.1.5.swf',
         controls : true
     };
+    
     if (settings) $.extend(config, settings);
-    var self = this;
+    
+    var current = this;
     var players = new Array();
     this.each(function() {
         var mediatags = $(this).find('video, audio');
@@ -48,7 +50,7 @@
             if (sources.length == 0) {
                 //alert("no sources found in mediatag, will use first 
available");
                 /* at least this works in MSIE (and other browsers that don't 
know html5 video or audio ?) */
-                sources = $(self).find('source');
+                sources = $(current).find('source');
             }
             
             $(mt).wrap('<div class="oiplayer"><div 
class="player"></div></div>');
@@ -61,7 +63,6 @@
                 $(div).find('div.player').append(player.player);
             }
             
-            
             $(div).width(player.width).height(player.height);
             
             var poster = createPoster(div, player);
@@ -101,66 +102,66 @@
             players.push(player);
 
         }); // end for each
+    });
+    
+    /* html ready, bind controls */
+    $.each(players, function(i, pl) {
+        $(pl.div).find('.preview').click(function(ev) {
+            ev.preventDefault();
+            start(pl);
+        });
         
-        /* html ready, bind controls */
-        $.each(players, function(i, pl) {
-            $(pl.div).find('.preview').click(function(ev) {
+        if (config.controls) {
+            $(pl.ctrls).find('li.play a').click(function(ev) {
                 ev.preventDefault();
-                start(pl);
+                if (pl.state == 'pause') {
+                    pl.play();
+                    if ($(pl.ctrls).find('li.pause').length == 0) {
+                        $(pl.ctrls).find('li.play').addClass('pause');
+                    }
+                    $.oiplayer.follow(pl);
+                } else if (pl.state == 'play') {
+                    pl.pause();
+                    $(pl.ctrls).find('li.play').removeClass('pause');
+                } else {
+                    start(pl);
+                }
+                //console.log("player state: " + pl.state);
             });
+
+            $(pl.ctrls).find('li.sound a').click(function(ev){
+                ev.preventDefault();
+                $(pl.ctrls).find('li.sound').toggleClass('muted');
+                pl.mute();
+            });
+            $(pl.ctrls).find('li.screen a').click(function(ev){
+                ev.preventDefault();
+                fullscreen(pl);
+            });
             
-            if (config.controls) {
-                $(pl.ctrls).find('li.play a').click(function(ev) {
-                    ev.preventDefault();
-                    if (pl.state == 'pause') {
-                        pl.play();
-                        if ($(pl.ctrls).find('li.pause').length == 0) {
-                            $(pl.ctrls).find('li.play').addClass('pause');
+            if (pl.duration) {  // else no use
+                $.oiplayer.slider(pl)
+            }
+
+            // show/hide
+            if (pl.ctrlspos == 'top' && pl.type != 'audio') {
+                $(pl.div).hover(
+                    function() { 
+                        $(pl.ctrls).fadeIn(); 
+                    },
+                    function() {
+                        if (pl.state != 'init') { 
+                            $(pl.ctrls).fadeOut('slow'); 
                         }
-                        $.oiplayer.follow(pl);
-                    } else if (pl.state == 'play') {
-                        pl.pause();
-                        $(pl.ctrls).find('li.play').removeClass('pause');
-                    } else {
-                        start(pl);
                     }
-                    //console.log("player state: " + pl.state);
-                });
+                );
+            }
+        } // config.controls
 
-                $(pl.ctrls).find('li.sound a').click(function(ev){
-                    ev.preventDefault();
-                    $(pl.ctrls).find('li.sound').toggleClass('muted');
-                    pl.mute();
-                });
-                $(pl.ctrls).find('li.screen a').click(function(ev){
-                    ev.preventDefault();
-                    fullscreen(pl);
-                });
-                
-                if (pl.duration) {  // else no use
-                    $.oiplayer.slider(pl)
-                }
-
-                // show/hide
-                if (pl.ctrlspos == 'top' && pl.type != 'audio') {
-                    $(pl.div).hover(
-                        function() { 
-                            $(pl.ctrls).fadeIn(); 
-                        },
-                        function() {
-                            if (pl.state != 'init') { 
-                                $(pl.ctrls).fadeOut('slow'); 
-                            }
-                        }
-                    );
-                }
-            } // config.controls
-
-            $(pl.div).bind("oiplayerended", function(ev, pl) {
-                $(pl.ctrls).fadeIn('slow');
-            });
-            
+        $(pl.div).bind("oiplayerended", function(ev, pl) {
+            $(pl.ctrls).fadeIn('slow');
         });
+        
     });
     
     /* Mainly user interface stuff on first start of playing */
@@ -481,6 +482,7 @@
     return this; // plugin convention
 };
 
+
 //  
------------------------------------------------------------------------------------------------
 //  Global functions
 //  
------------------------------------------------------------------------------------------------
@@ -610,7 +612,6 @@
 }
 
 
-
 //  
------------------------------------------------------------------------------------------------
 //  Prototypes of several players
 //  
------------------------------------------------------------------------------------------------

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to