Skip to content

Commit

Permalink
2.7.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
johndyer committed Mar 9, 2012
1 parent 5bb3530 commit aedef32
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 215 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -93,9 +93,10 @@ You can use this as a standalone library if you wish, or just stick with the ful
* Possible issues with < IE8 centering resolved * Possible issues with < IE8 centering resolved
* Full set of controls under Silverlight ([Birol2010](https://github.com/Birol2010/)) * Full set of controls under Silverlight ([Birol2010](https://github.com/Birol2010/))
* YouTube fix [raknam] * YouTube fix [raknam]
* Source Chooser plugin [markomarkovic]
* shim now has a .tagName property, and other DOM-like methods [tantalic] * shim now has a .tagName property, and other DOM-like methods [tantalic]
* Poster display fix when HTML5, Flash, and Silverlight are all missing [bruha] * Poster display fix when HTML5, Flash, and Silverlight are all missing [bruha]
* Source Chooser plugin [markomarkovic]
* Fix for flash audio mute [lbernau]


*2.6.5 (2012/02/01)* *2.6.5 (2012/02/01)*


Expand Down
Binary file modified build/controls.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
224 changes: 153 additions & 71 deletions build/mediaelement-and-player.js
Expand Up @@ -15,7 +15,7 @@
var mejs = mejs || {}; var mejs = mejs || {};


// version number // version number
mejs.version = '2.6.5'; mejs.version = '2.7.0';


// player number (for missing, same id attr) // player number (for missing, same id attr)
mejs.meIndex = 0; mejs.meIndex = 0;
Expand Down Expand Up @@ -438,6 +438,7 @@ mejs.PluginMediaElement.prototype = {
seeking: false, seeking: false,
duration: 0, duration: 0,
error: null, error: null,
tagName: '',


// HTML5 get/set properties, but only set (updated by event handlers) // HTML5 get/set properties, but only set (updated by event handlers)
muted: false, muted: false,
Expand Down Expand Up @@ -652,6 +653,24 @@ mejs.PluginMediaElement.prototype = {
}, },
// end: fake events // end: fake events


// fake DOM attribute methods
attributes: {},
hasAttribute: function(name){
return (name in this.attributes);
},
removeAttribute: function(name){
delete this.attributes[name];
},
getAttribute: function(name){
if (this.hasAttribute(name)) {
return this.attributes[name];
}
return '';
},
setAttribute: function(name, value){
this.attributes[name] = value;
},

remove: function() { remove: function() {
mejs.Utility.removeSwf(this.pluginElement.id); mejs.Utility.removeSwf(this.pluginElement.id);
} }
Expand Down Expand Up @@ -1023,7 +1042,7 @@ mejs.HtmlMediaElementShim = {
} catch (e) {} } catch (e) {}


errorContainer.innerHTML = (poster !== '') ? errorContainer.innerHTML = (poster !== '') ?
'<a href="' + playback.url + '"><img src="' + poster + '" /></a>' : '<a href="' + playback.url + '"><img src="' + poster + '" width="100%" height="100%" /></a>' :
'<a href="' + playback.url + '"><span>Download File</span></a>'; '<a href="' + playback.url + '"><span>Download File</span></a>';


htmlMediaElement.parentNode.insertBefore(errorContainer, htmlMediaElement); htmlMediaElement.parentNode.insertBefore(errorContainer, htmlMediaElement);
Expand All @@ -1044,6 +1063,17 @@ mejs.HtmlMediaElementShim = {
node, node,
initVars; initVars;


// copy tagName from html media element
pluginMediaElement.tagName = htmlMediaElement.tagName

// copy attributes from html media element to plugin media element
for (var i = 0; i < htmlMediaElement.attributes.length; i++) {
var attribute = htmlMediaElement.attributes[i];
if (attribute.specified == true) {
pluginMediaElement.setAttribute(attribute.name, attribute.value);
}
}

// check for placement inside a <p> tag (sometimes WYSIWYG editors do this) // check for placement inside a <p> tag (sometimes WYSIWYG editors do this)
node = htmlMediaElement.parentNode; node = htmlMediaElement.parentNode;
while (node !== null && node.tagName.toLowerCase() != 'body') { while (node !== null && node.tagName.toLowerCase() != 'body') {
Expand Down Expand Up @@ -1363,6 +1393,7 @@ mejs.YouTubeApi = {


iFrameReady: function() { iFrameReady: function() {


this.isLoaded = true;
this.isIframeLoaded = true; this.isIframeLoaded = true;


while (this.iframeQueue.length > 0) { while (this.iframeQueue.length > 0) {
Expand Down Expand Up @@ -1543,9 +1574,9 @@ if (typeof jQuery != 'undefined') {
alwaysShowControls: false, alwaysShowControls: false,
// force iPad's native controls // force iPad's native controls
iPadUseNativeControls: false, iPadUseNativeControls: false,
// force iPad's native controls // force iPhone's native controls
iPhoneUseNativeControls: false, iPhoneUseNativeControls: false,
// force iPad's native controls // force Android's native controls
AndroidUseNativeControls: false, AndroidUseNativeControls: false,
// features to show // features to show
features: ['playpause','current','progress','duration','tracks','volume','fullscreen'], features: ['playpause','current','progress','duration','tracks','volume','fullscreen'],
Expand Down Expand Up @@ -2197,8 +2228,14 @@ if (typeof jQuery != 'undefined') {


setPlayerSize: function(width,height) { setPlayerSize: function(width,height) {
var t = this; var t = this;


// testing for 100% code if (typeof width != 'undefined')
t.width = width;

if (typeof height != 'undefined')
t.height = height;

// detect 100% mode
if (t.height.toString().indexOf('%') > 0) { if (t.height.toString().indexOf('%') > 0) {


// do we have the native dimensions yet? // do we have the native dimensions yet?
Expand Down Expand Up @@ -2474,7 +2511,7 @@ if (typeof jQuery != 'undefined') {
}, },
changeSkin: function(className) { changeSkin: function(className) {
this.container[0].className = 'mejs-container ' + className; this.container[0].className = 'mejs-container ' + className;
this.setPlayerSize(); this.setPlayerSize(this.width, this.height);
this.setControlsSize(); this.setControlsSize();
}, },
play: function() { play: function() {
Expand Down Expand Up @@ -2868,18 +2905,36 @@ if (typeof jQuery != 'undefined') {


$.extend(mejs.MepDefaults, { $.extend(mejs.MepDefaults, {
muteText: 'Mute Toggle', muteText: 'Mute Toggle',
hideVolumeOnTouchDevices: true hideVolumeOnTouchDevices: true,

audioVolume: 'horizontal',
videoVolume: 'vertical'
}); });


$.extend(MediaElementPlayer.prototype, { $.extend(MediaElementPlayer.prototype, {
buildvolume: function(player, controls, layers, media) { buildvolume: function(player, controls, layers, media) {

// Android and iOS don't support volume controls // Android and iOS don't support volume controls
if (mejs.MediaFeatures.hasTouch && this.options.hideVolumeOnTouchDevices) if (mejs.MediaFeatures.hasTouch && this.options.hideVolumeOnTouchDevices)
return; return;


var t = this, var t = this,
mute = mode = (t.isVideo) ? t.options.videoVolume : t.options.audioVolume,
mute = (mode == 'horizontal') ?

// horizontal version
$('<div class="mejs-button mejs-volume-button mejs-mute">'+
'<button type="button" aria-controls="' + t.id + '" title="' + t.options.muteText + '"></button>'+
'</div>' +
'<div class="mejs-horizontal-volume-slider">'+ // outer background
'<div class="mejs-horizontal-volume-total"></div>'+ // line background
'<div class="mejs-horizontal-volume-current"></div>'+ // current volume
'<div class="mejs-horizontal-volume-handle"></div>'+ // handle
'</div>'
)
.appendTo(controls) :

// vertical version
$('<div class="mejs-button mejs-volume-button mejs-mute">'+ $('<div class="mejs-button mejs-volume-button mejs-mute">'+
'<button type="button" aria-controls="' + t.id + '" title="' + t.options.muteText + '"></button>'+ '<button type="button" aria-controls="' + t.id + '" title="' + t.options.muteText + '"></button>'+
'<div class="mejs-volume-slider">'+ // outer background '<div class="mejs-volume-slider">'+ // outer background
Expand All @@ -2888,11 +2943,11 @@ if (typeof jQuery != 'undefined') {
'<div class="mejs-volume-handle"></div>'+ // handle '<div class="mejs-volume-handle"></div>'+ // handle
'</div>'+ '</div>'+
'</div>') '</div>')
.appendTo(controls), .appendTo(controls),
volumeSlider = mute.find('.mejs-volume-slider'), volumeSlider = t.container.find('.mejs-volume-slider, .mejs-horizontal-volume-slider'),
volumeTotal = mute.find('.mejs-volume-total'), volumeTotal = t.container.find('.mejs-volume-total, .mejs-horizontal-volume-total'),
volumeCurrent = mute.find('.mejs-volume-current'), volumeCurrent = t.container.find('.mejs-volume-current, .mejs-horizontal-volume-current'),
volumeHandle = mute.find('.mejs-volume-handle'), volumeHandle = t.container.find('.mejs-volume-handle, .mejs-horizontal-volume-handle'),


positionVolumeHandle = function(volume) { positionVolumeHandle = function(volume) {


Expand All @@ -2902,83 +2957,112 @@ if (typeof jQuery != 'undefined') {
volumeSlider.hide() volumeSlider.hide()
return; return;
} }


var // correct to 0-1
volume = Math.max(0,volume);
volume = Math.min(volume,1);


// height of the full size volume slider background // ajust mute button style
totalHeight = volumeTotal.height(), if (volume == 0) {
mute.removeClass('mejs-mute').addClass('mejs-unmute');
} else {
mute.removeClass('mejs-unmute').addClass('mejs-mute');
}

// position slider
if (mode == 'vertical') {
var


// top/left of full size volume slider background // height of the full size volume slider background
totalPosition = volumeTotal.position(), totalHeight = volumeTotal.height(),

// top/left of full size volume slider background
totalPosition = volumeTotal.position(),

// the new top position based on the current volume
// 70% volume on 100px height == top:30px
newTop = totalHeight - (totalHeight * volume);

// handle
volumeHandle.css('top', totalPosition.top + newTop - (volumeHandle.height() / 2));

// show the current visibility
volumeCurrent.height(totalHeight - newTop );
volumeCurrent.css('top', totalPosition.top + newTop);
} else {
var


// the new top position based on the current volume // height of the full size volume slider background
// 70% volume on 100px height == top:30px totalWidth = volumeTotal.width(),
newTop = totalHeight - (totalHeight * volume);

// top/left of full size volume slider background
// handle totalPosition = volumeTotal.position(),
volumeHandle.css('top', totalPosition.top + newTop - (volumeHandle.height() / 2));

// the new left position based on the current volume
// show the current visibility newLeft = totalWidth * volume;
volumeCurrent.height(totalHeight - newTop );
volumeCurrent.css('top', totalPosition.top + newTop); // handle
volumeHandle.css('left', totalPosition.left + newLeft - (volumeHandle.width() / 2));

// rezize the current part of the volume bar
volumeCurrent.width( newLeft );
}
}, },
handleVolumeMove = function(e) { handleVolumeMove = function(e) {
var
railHeight = volumeTotal.height(), var volume = null,
totalOffset = volumeTotal.offset(), totalOffset = volumeTotal.offset();
totalTop = parseInt(volumeTotal.css('top').replace(/px/,''),10),
newY = e.pageY - totalOffset.top, // calculate the new volume based on the moust position
volume = (railHeight - newY) / railHeight if (mode == 'vertical') {


// the controls just hide themselves (usually when mouse moves too far up) var
if (totalOffset.top == 0 || totalOffset.left == 0) railHeight = volumeTotal.height(),
return; totalTop = parseInt(volumeTotal.css('top').replace(/px/,''),10),
newY = e.pageY - totalOffset.top;

volume = (railHeight - newY) / railHeight;

// the controls just hide themselves (usually when mouse moves too far up)
if (totalOffset.top == 0 || totalOffset.left == 0)
return;


// 0-1 } else {
var
railWidth = volumeTotal.width(),
newX = e.pageX - totalOffset.left;

volume = newX / railWidth;
}

// ensure the volume isn't outside 0-1
volume = Math.max(0,volume); volume = Math.max(0,volume);
volume = Math.min(volume,1); volume = Math.min(volume,1);


// TODO: handle vertical and horizontal CSS // position the slider and handle
// only allow it to move within the rail positionVolumeHandle(volume);
if (newY < 0)
newY = 0; // set the media object (this will trigger the volumechanged event)
else if (newY > railHeight)
newY = railHeight;

// move the handle to match the mouse
volumeHandle.css('top', newY - (volumeHandle.height() / 2) + totalTop );

// show the current visibility
volumeCurrent.height(railHeight-newY);
volumeCurrent.css('top',newY+totalTop);

// set mute status
if (volume == 0) { if (volume == 0) {
media.setMuted(true); media.setMuted(true);
mute.removeClass('mejs-mute').addClass('mejs-unmute');
} else { } else {
media.setMuted(false); media.setMuted(false);
mute.removeClass('mejs-unmute').addClass('mejs-mute');
} }

media.setVolume(volume);
volume = Math.max(0,volume);
volume = Math.min(volume,1);

// set the volume
media.setVolume(volume);
}, },
mouseIsDown = false, mouseIsDown = false,
mouseIsOver = false; mouseIsOver = false;


// SLIDER // SLIDER

mute mute
.hover(function() { .hover(function() {
volumeSlider.show(); volumeSlider.show();
mouseIsOver = true; mouseIsOver = true;
}, function() { }, function() {
mouseIsOver = false; mouseIsOver = false;


if (!mouseIsDown) { if (!mouseIsDown && mode == 'vertical') {
volumeSlider.hide(); volumeSlider.hide();
} }
}); });
Expand All @@ -2998,7 +3082,7 @@ if (typeof jQuery != 'undefined') {
.bind('mouseup', function (e) { .bind('mouseup', function (e) {
mouseIsDown = false; mouseIsDown = false;


if (!mouseIsOver) { if (!mouseIsOver && mode == 'vertical') {
volumeSlider.hide(); volumeSlider.hide();
} }
}) })
Expand All @@ -3011,9 +3095,7 @@ if (typeof jQuery != 'undefined') {


// MUTE button // MUTE button
mute.find('button').click(function() { mute.find('button').click(function() {

media.setMuted( !media.muted ); media.setMuted( !media.muted );

}); });


// listen for volume change events from other sources // listen for volume change events from other sources
Expand Down

0 comments on commit aedef32

Please sign in to comment.