Skip to content

Commit

Permalink
Merge branch 'hotfix/options-width-fix'
Browse files Browse the repository at this point in the history
Conflicts:
	src/core.js
  • Loading branch information
heff committed Apr 6, 2012
2 parents 1d680a9 + 2ef7617 commit 2d2e711
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 49 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ CHANGELOG
* Created new 'loadedalldata' event for when the source is completely downloaded
* Improved player.destroy(). Now removes elements and references.
* Refactored API to be more immediately available.

---- 3.2.1 / 2012-04-06 / options-width-fix ------------------------------------
* Fixed setting width/height with javascript options
4 changes: 2 additions & 2 deletions VERSION.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
major: 3
patch: 0
minor: 2
major: 3
patch: 1
4 changes: 2 additions & 2 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ VideoJS.options = {
flash: { swf: "http://vjs.zencdn.net/c/video-js.swf" },

// Default of web browser is 300x150. Should rely on source width/height.
width: "auto",
height: "auto",
width: 300,
height: 150,

// defaultVolume: 0.85,
defaultVolume: 0.00, // The freakin seaguls are driving me crazy!
Expand Down
121 changes: 121 additions & 0 deletions src/core.js.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// HTML5 Shiv. Must be in <head> to support older browsers.
document.createElement("video");document.createElement("audio");

var VideoJS = function(id, addOptions, ready){
var tag; // Element of ID

// Allow for element or ID to be passed in
// String ID
if (typeof id == "string") {

// Adjust for jQuery ID syntax
if (id.indexOf("#") === 0) {
id = id.slice(1);
}

// If a player instance has already been created for this ID return it.
if (_V_.players[id]) {
return _V_.players[id];

// Otherwise get element for ID
} else {
tag = _V_.el(id)
}

// ID is a media element
} else {
tag = id;
}

// Check for a useable element
if (!tag || !tag.nodeName) { // re: nodeName, could be a box div also
throw new TypeError("The element or ID supplied is not valid. (VideoJS)"); // Returns
}

// Element may have a player attr referring to an already created player instance.
// If not, set up a new player and return the instance.
return tag.player || new _V_.Player(tag, addOptions, ready);
},

// Shortcut
_V_ = VideoJS,

// CDN Version. Used to target right flash swf.
CDN_VERSION = "GENERATED_CDN_VSN";

VideoJS.players = {};

VideoJS.options = {

// Default order of fallback technology
techOrder: ["html5","flash"],
// techOrder: ["flash","html5"],

html5: {},
flash: { swf: "http://vjs.zencdn.net/c/video-js.swf" },

// Default of web browser is 300x150. Should rely on source width/height.
<<<<<<< HEAD
width: "auto",
height: "auto",
=======
width: 300,
height: 150,
>>>>>>> hotfix/options-width-fix

// defaultVolume: 0.85,
defaultVolume: 0.00, // The freakin seaguls are driving me crazy!

// Included control sets
components: {
"posterImage": {},
"textTrackDisplay": {},
"loadingSpinner": {},
"bigPlayButton": {},
"controlBar": {}
}

// components: [
// "poster",
// "loadingSpinner",
// "bigPlayButton",
// { name: "controlBar", options: {
// components: [
// "playToggle",
// "fullscreenToggle",
// "currentTimeDisplay",
// "timeDivider",
// "durationDisplay",
// "remainingTimeDisplay",
// { name: "progressControl", options: {
// components: [
// { name: "seekBar", options: {
// components: [
// "loadProgressBar",
// "playProgressBar",
// "seekHandle"
// ]}
// }
// ]}
// },
// { name: "volumeControl", options: {
// components: [
// { name: "volumeBar", options: {
// components: [
// "volumeLevel",
// "volumeHandle"
// ]}
// }
// ]}
// },
// "muteToggle"
// ]
// }},
// "subtitlesDisplay"/*, "replay"*/
// ]
};

// Set CDN Version of swf
if (CDN_VERSION != "GENERATED_CDN_VSN") {
_V_.options.flash.swf = "http://vjs.zencdn.net/"+CDN_VERSION+"/video-js.swf"
}
90 changes: 45 additions & 45 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,34 @@ _V_.Player = _V_.Component.extend({
this.tag = tag; // Store the original tag used to set options

var el = this.el = _V_.createElement("div"), // Div to contain video and controls
options = this.options = {},
width = options.width = tag.getAttribute('width'),
height = options.height = tag.getAttribute('height'),
options = this.options = {};

// Browsers default to 300x150 if there's no width/height or video size data.
initWidth = width || 300,
initHeight = height || 150;

// Make player findable on elements
tag.player = el.player = this;
// Set Options
_V_.merge(options, _V_.options); // Copy Global Defaults
_V_.merge(options, this.getVideoTagSettings()); // Override with Video Tag Options
_V_.merge(options, addOptions); // Override/extend with options from setup call

// Add callback to ready queue
this.ready(ready);

// Store controls setting, and then remove immediately so native controls don't flash.
tag.removeAttribute("controls");

// Poster will be handled by a manual <img>
tag.removeAttribute("poster");

// Make player findable on elements
tag.player = el.player = this;

// Wrap video tag in div (el/box) container
tag.parentNode.insertBefore(el, tag);
el.appendChild(tag); // Breaks iPhone, fixed in HTML5 setup.

// Give video tag properties to box
el.id = this.id = tag.id; // ID will now reference box, not the video tag
// ID will now reference box, not the video tag
this.id = el.id = tag.id;
el.className = tag.className;

// Update tag id/class for use as HTML5 playback tech
tag.id += "_html5_api";
tag.className = "vjs-tech";
Expand All @@ -36,27 +43,18 @@ _V_.Player = _V_.Component.extend({
_V_.players[el.id] = this;

// Make box use width/height of tag, or default 300x150
el.setAttribute("width", initWidth);
el.setAttribute("height", initHeight);
el.setAttribute("width", options.width);
el.setAttribute("height", options.height);

// Enforce with CSS since width/height attrs don't work on divs
el.style.width = initWidth+"px";
el.style.height = initHeight+"px";
el.style.width = options.width+"px";
el.style.height = options.height+"px";

// Remove width/height attrs from tag so CSS can make it 100% width/height
tag.removeAttribute("width");
tag.removeAttribute("height");

// Set Options
_V_.merge(options, _V_.options); // Copy Global Defaults
_V_.merge(options, this.getVideoTagSettings()); // Override with Video Tag Options
_V_.merge(options, addOptions); // Override/extend with options from setup call

// Store controls setting, and then remove immediately so native controls don't flash.
tag.removeAttribute("controls");

// Poster will be handled by a manual <img>
tag.removeAttribute("poster");

// Empty video tag sources and tracks so the built in player doesn't use them also.
// Empty video tag sources and tracks so the built-in player doesn't use them also.
if (tag.hasChildNodes()) {
var nrOfChildNodes = tag.childNodes.length;
for (var i=0,j=tag.childNodes;i<nrOfChildNodes;i++) {
Expand Down Expand Up @@ -130,35 +128,37 @@ _V_.Player = _V_.Component.extend({
var options = {
sources: [],
tracks: []
};

options.src = this.tag.getAttribute("src");
options.controls = this.tag.getAttribute("controls") !== null;
options.poster = this.tag.getAttribute("poster");
options.preload = this.tag.getAttribute("preload");
options.autoplay = this.tag.getAttribute("autoplay") !== null; // hasAttribute not IE <8 compatible
options.loop = this.tag.getAttribute("loop") !== null;
options.muted = this.tag.getAttribute("muted") !== null;
},
tag = this.tag,
getAttribute = "getAttribute"; // For better minification

options.src = tag[getAttribute]("src");
options.controls = tag[getAttribute]("controls") !== null;
options.poster = tag[getAttribute]("poster");
options.preload = tag[getAttribute]("preload");
options.autoplay = tag[getAttribute]("autoplay") !== null; // hasAttribute not IE <8 compatible
options.loop = tag[getAttribute]("loop") !== null;
options.muted = tag[getAttribute]("muted") !== null;

if (this.tag.hasChildNodes()) {
for (var c,i=0,j=this.tag.childNodes;i<j.length;i++) {
c = j[i];
if (c.nodeName.toLowerCase() == "source") {
options.sources.push({
src: c.getAttribute('src'),
type: c.getAttribute('type'),
media: c.getAttribute('media'),
title: c.getAttribute('title')
src: c[getAttribute]('src'),
type: c[getAttribute]('type'),
media: c[getAttribute]('media'),
title: c[getAttribute]('title')
});
}
if (c.nodeName.toLowerCase() == "track") {
options.tracks.push({
src: c.getAttribute("src"),
kind: c.getAttribute("kind"),
srclang: c.getAttribute("srclang"),
label: c.getAttribute("label"),
'default': c.getAttribute("default") !== null,
title: c.getAttribute("title")
src: c[getAttribute]("src"),
kind: c[getAttribute]("kind"),
srclang: c[getAttribute]("srclang"),
label: c[getAttribute]("label"),
'default': c[getAttribute]("default") !== null,
title: c[getAttribute]("title")
});
}
}
Expand Down

0 comments on commit 2d2e711

Please sign in to comment.