diff --git a/src/plugins/projekktor.controlbar.js b/src/plugins/projekktor.controlbar.js index bd74143..5c55900 100644 --- a/src/plugins/projekktor.controlbar.js +++ b/src/plugins/projekktor.controlbar.js @@ -598,7 +598,10 @@ jQuery(function ($) { var isVisible = this.cb.hasClass('active'), ref = this, fixed = this.getConfig('fixedVolume'), - toggleMute = (this.controlElements['mute'].hasClass('toggle') || this.controlElements['unmute'].hasClass('toggle') || this.getConfig('toggleMute')); + toggleMute = (this.controlElements['mute'].hasClass('toggle') || this.controlElements['unmute'].hasClass('toggle') || this.getConfig('toggleMute')), + // check if the volume is in the proper range and correct its value if it's not + volume = volume > 1 ? 1 : volume, + volume = volume < 0 ? 0 : volume; // hide volume mess in case volume is fixed this._active('mute', !fixed); @@ -612,12 +615,25 @@ jQuery(function ($) { // make controls visible in order to allow dom manipulations // this.cb.stop(true, true).show(); - if (this.controlElements['vslider'].width() > this.controlElements['vslider'].height()) { - this.controlElements['vmarker'].css('width', volume * 100 + "%"); - this.controlElements['vknob'].css('left', volume * 100 + "%"); - } else { - this.controlElements['vmarker'].css('height', volume * 100 + "%"); - this.controlElements['vknob'].css('top', (100 - volume * 100) + "%"); + var vslider = this.controlElements['vslider'], + vmarker = this.controlElements['vmarker'], + vknob = this.controlElements['vknob'], + orientation = vslider.width() > vslider.height() ? "horizontal" : "vertical"; + + switch(orientation){ + case "horizontal": + + vmarker.css('width', volume * 100 + "%"); + vknob.css('left', Math.round((vslider.width() * volume) - (vknob.width() * volume)) + "px" ); + + break; + + case "vertical": + + vmarker.css('height', volume * 100 + "%"); + vknob.css('bottom', Math.round((vslider.height() * volume) - (vknob.height() * volume)) + "px" ); + + break; } // "li" hack @@ -816,12 +832,16 @@ jQuery(function ($) { volumeHandler: function (value) { try { - if (value>0) + if (value>0){ this.cookie('muted', false); - - if (!this.cookie('muted')) + } + + if (!this.cookie('muted')){ this.cookie('volume', value); + } + } catch(e){console.log(e)} + this.displayVolume(this._getVolume()); }, @@ -1154,53 +1174,75 @@ jQuery(function ($) { this._vSliderAct = true; var ref = this, - sliderIdx = (this.pp.getInFullscreen() === true && this.controlElements['vslider'].length > 1) ? 1 : 0, - knob = $(domObj[sliderIdx]), - slider = $(this.controlElements['vslider'][sliderIdx]), - dx = Math.abs(parseFloat(knob.position().left) - event.clientX), - dy = Math.abs(parseFloat(knob.position().top) - event.clientY), + + vslider = ref.controlElements['vslider'], + vmarker = ref.controlElements['vmarker'], + vknob = ref.controlElements['vknob'], + + orientation = vslider.width() > vslider.height() ? "horizontal" : "vertical", volume = 0, - mouseUp = function (mouseupevt) { - ref.playerDom.unbind('mouseup', mouseUp); - slider.unbind('mousemove', mouseMove); - slider.unbind('mouseup', mouseUp); - knob.unbind('mousemove', mouseMove); - knob.unbind('mouseup', mouseUp); + + mouseUp = function (mouseUpEvent) { + if(window.onmouseup === undefined){ // IE < 9 has no window mouse events support + $(document).unbind('mousemove', mouseMove); + $(document).unbind('mouseup', mouseUp); + $(document).unbind('mouseleave', mouseUp); + } + else { + $(window).unbind('mousemove', mouseMove); + $(window).unbind('mouseup', mouseUp); + } + ref._vSliderAct = false; return false; }, - mouseMove = function (dragevent) { + mouseMove = function (dragEvent) { clearTimeout(ref._cTimer); - var newXPos = (dragevent.clientX - dx), - newXPos = (newXPos > slider.width() - knob.width() / 2) ? slider.width() - (knob.width() / 2) : newXPos, + + var newXPos = (dragEvent.clientX - vslider.offset().left), + newXPos = (newXPos > vslider.width()) ? vslider.width() : newXPos, newXPos = (newXPos < 0) ? 0 : newXPos, - newYPos = (dragevent.clientY - dy), - newYPos = (newYPos > slider.height() - knob.height() / 2) ? slider.height() - (knob.height() / 2) : newYPos, + + newYPos = (dragEvent.clientY - vslider.offset().top), + newYPos = (newYPos > vslider.height()) ? vslider.height() : newYPos, newYPos = (newYPos < 0) ? 0 : newYPos; - - if (ref.controlElements['vslider'].width() > ref.controlElements['vslider'].height()) { - knob.css('left', newXPos + 'px'); - volume = Math.abs(newXPos / (slider.width() - (knob.width() / 2))); - $(ref.controlElements['vmarker'][sliderIdx]).css('width', volume * 100 + "%"); - } else { - knob.css('top', newYPos + 'px'); - volume = 1 - Math.abs(newYPos / (slider.height() - (knob.height() / 2))); - $(ref.controlElements['vmarker'][sliderIdx]).css('height', volume * 100 + "%"); - } - }; + + + + switch(orientation){ + case "horizontal": + volume = Math.abs(newXPos / vslider.width()); + + vmarker.css('width', volume * 100 + "%"); + vknob.css('left', Math.round((vslider.width() * volume) - (vknob.width() * volume)) + "px" ); - // this.playerDom.mousemove(mouseMove); - this.playerDom.mouseup(mouseUp); + break; - slider.mousemove(mouseMove); - slider.mouseup(mouseUp); + case "vertical": + volume = 1 - Math.abs(newYPos / vslider.height()); + + vmarker.css('height', volume * 100 + "%"); + vknob.css('bottom', Math.round((vslider.height() * volume) - (vknob.height()* volume)) + "px" ); - knob.mousemove(mouseMove); - knob.mouseup(mouseUp); + break; + } + + ref.pp.setVolume(volume); + return false; + }; + if(window.onmouseup === undefined){ + $(document).mousemove(mouseMove); + $(document).mouseup(mouseUp); + $(document).mouseleave(mouseUp); + } + else { + $(window).mousemove(mouseMove); + $(window).mouseup(mouseUp); + } }, handleStartDragListener: function (evt, domObj) { @@ -1255,7 +1297,7 @@ jQuery(function ($) { *******************************/ _getVolume: function() { - var volume = parseFloat(this.cookie('volume') || this.getConfig('volume') || 0.5), + var volume = parseFloat(this.cookie('volume') || this.getConfig('volume')), muted = this.cookie('muted') || false; if (this.getConfig('fixedVolume') || volume==null) @@ -1298,4 +1340,4 @@ jQuery(function ($) { return result; } } -}); \ No newline at end of file +}); diff --git a/themes/maccaco/projekktor.style.css b/themes/maccaco/projekktor.style.css index 205721d..be2a5d8 100644 --- a/themes/maccaco/projekktor.style.css +++ b/themes/maccaco/projekktor.style.css @@ -314,6 +314,7 @@ controlbar plugin /* volume slider - right */ .ppvslider { margin: 13px 5px; + padding: 0 1px; height: 16px; width: 60px; background: url("maccaco.png") no-repeat -781px -13px transparent; @@ -335,7 +336,7 @@ controlbar plugin background: url("maccaco.png") no-repeat -699px -5px transparent; top: -13px; left:0; - width: 6px; + width: 4px; height: 20px; padding: 0;