Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mousemove callback event not showing which mouse button is pressed safari

Im developing a HTML5 Player. It's working ok on all browser, except safari for osx. (This player is supposed to work only on desktop browser).

I'm having a problem with a seek bar e a volume bar.

Basically its a slider, but implemented with divs and stuff. I did the following.

Registered a callback on the element for the 'mousemove' event. When this callbacks is triggered, i check the event for buttons. When use safari, this attribute is always 'undefined'.

The code is very simple:

this.controls.$seekBar.on('mousemove', (function(_this){
            return function(event){
                if (event.buttons == 1) {
                    // Do some stuff
                }
            }
        })(this))
            .on('mousedown', (function(_this){
                return function(event){
                    if (event.buttons == 1) {
                        // Do some stuff
                    }
                }
            })(this));

Since it's a jQuery plugin, i need to use closures to pass the plugin context to the callback, but this isn't the problem. I tested without being a jQuery plugin and the same error happens.

Event object generated in safari:

altKey: false
bubbles: true
button: 0
buttons: undefined
cancelable: true
clientX: 529
clientY: 674
ctrlKey: false
currentTarget: div#seekBar1.vjs-progress-holder vjs-slider
data: undefined
delegateTarget: div#seekBar1.vjs-progress-holder vjs-slider
eventPhase: 2
fromElement: null
handleObj: Object
isDefaultPrevented: function bb() {return!1;}
jQuery111103980477461591363: true
metaKey: false
offsetX: 150
offsetY: 8
originalEvent: MouseEvent
pageX: 529
pageY: 781
relatedTarget: null
screenX: 530
screenY: 759
shiftKey: false
target: div#seekBar1.vjs-progress-holder vjs-slider
timeStamp: 1438352150671
toElement: div#seekBar1.vjs-progress-holder vjs-slider
type: "mousedown"
view: Window
which: 1
__proto__: Object

Event object generated in firefox:

altKey: false
bubbles:    true
button: 0
buttons:    1
cancelable: true
clientX:    587
clientY:    563
ctrlKey:    false
currentTarget:  div#seekBar1.vjs-progress-holder.vjs-slider
data:   undefined
delegateTarget: div#seekBar1.vjs-progress-holder.vjs-slider
eventPhase: 3
fromElement:    undefined
handleObj:  Object { type="mousedown", origType="mousedown", guid=36, more...}
jQuery111105827101769842828:    true
metaKey:    false
offsetX:    undefined
offsetY:    undefined
originalEvent:  mousedown clientX=587, clientY=563
pageX:  587
pageY:  780
relatedTarget:  null
screenX:    587
screenY:    665
shiftKey:   false
target: div#progressBar1.vjs-play-progress
timeStamp:  1175114810
toElement:  undefined
type:   "mousedown"
view:   Window 561
which:  1
isDefaultPrevented: bb()
isImmediatePropagationStopped:  bb()
isPropagationStopped:   bb()
preventDefault: function()
stopImmediatePropagation:   function()
stopPropagation:    function()
__proto__:  Object { isDefaultPrevented=bb(),    isPropagationStopped=bb(), isImmediatePropagationStopped=bb(), more..    
like image 530
dvtelles Avatar asked Sep 28 '22 04:09

dvtelles


1 Answers

You can simply modify your code like below:

   this.controls.$seekBar.on('mousemove', (function(_this){
        return function(event){
            var buttons = (e.buttons === undefined ? e.which : e.buttons);
            if (buttons == 1) {
                // Do some stuff
            }
        }
    })(this))
        .on('mousedown', (function(_this){
            return function(event){
                var buttons = (e.buttons === undefined ? e.which : e.buttons);
                if (event.buttons == 1) {
                    // Do some stuff
                }
            }
        })(this));

It will works for all browser you need.

like image 148
guvenckardas Avatar answered Oct 03 '22 03:10

guvenckardas