Skip to content

Commit

Permalink
Release v0.11.5
Browse files Browse the repository at this point in the history
  • Loading branch information
RickEyre committed Apr 12, 2014
1 parent 1df37ec commit 65ae2da
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 51 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vtt.js",
"description": "A JavaScript implementation of the WebVTT specification.",
"version": "0.11.4",
"version": "0.11.5",
"homepage": "https://github.com/mozilla/vtt.js",
"authors": [
"Andreas Gal <gal@mozilla.com>",
Expand Down
88 changes: 42 additions & 46 deletions dist/vtt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! vtt.js - https://github.com/mozilla/vtt.js (built on 09-04-2014) */
/*! vtt.js - https://github.com/mozilla/vtt.js (built on 11-04-2014) */
/**
* Copyright 2013 vtt.js Contributors
*
Expand Down Expand Up @@ -518,7 +518,6 @@
// Accept a setting if its a valid (signed) integer.
integer: function(k, v) {
if (/^-?\d+$/.test(v)) { // integer
// Only take values in the range of -1000 ~ 1000
this.set(k, parseInt(v, 10));
}
},
Expand Down Expand Up @@ -1224,40 +1223,28 @@
this.lineHeight = lh !== undefined ? lh : obj.lineHeight;
}

var axesMaps = {
"x": { edges: [ "left", "right" ], ref: "width" },
"y": { edges: [ "top", "bottom" ], ref: "height" }
};

// Move the box along a particular axis. Optionally pass in an amount to move
// or a container box to clamp the max amount moved to through the options
// parameter.
BoxPosition.prototype.move = function(axis, options) {
options = options || {};

var axes = axesMaps[axis.replace(/(\+|-)/, "")];
if (!axes) {
throw new Error("You must pass in a valid axis (+x, -x, +y, -y).");
}

var toMove = options.toMove !== undefined ? options.toMove : this.lineHeight;
if (options.container) {
var step = this.lineHeight,
maxSteps = Math.floor((options.container[axes.ref] / step) + 1);
if (maxSteps < (toMove / step)) {
toMove = maxSteps * step;
}
}

// Negate the amount to move the box since we're moving along the
// neagtive axis.
if (axis.indexOf("-") !== -1) {
toMove *= -1;
}

var edges = axes.edges;
for (var i = 0; i < edges.length; i++) {
this[edges[i]] += toMove;
// the box. If no amount is passed then the default is the line height of the
// box.
BoxPosition.prototype.move = function(axis, toMove) {
toMove = toMove !== undefined ? toMove : this.lineHeight;
switch (axis) {
case "+x":
this.left += toMove;
this.right += toMove;
break;
case "-x":
this.left -= toMove;
this.right -= toMove;
break;
case "+y":
this.top += toMove;
this.bottom += toMove;
break;
case "-y":
this.top -= toMove;
this.bottom -= toMove;
break;
}
};

Expand Down Expand Up @@ -1381,45 +1368,54 @@
return bestPosition || specifiedPosition;
}

function reverseAxis(axis) {
return axis.map(function(a) {
return a.indexOf("+") !== -1 ? a.replace("+", "-") : a.replace("-", "+");
});
}

var boxPosition = new BoxPosition(styleBox),
cue = styleBox.cue,
linePos = computeLinePos(cue),
axis = [];

// If we have a line number to align the cue to.
if (cue.snapToLines) {
var size;
switch (cue.vertical) {
case "":
axis = [ "+y", "-y" ];
size = "height";
break;
case "rl":
axis = [ "+x", "-x" ];
size = "width";
break;
case "lr":
axis = [ "-x", "+x" ];
size = "width";
break;
}

var step = boxPosition.lineHeight,
position = step * Math.round(linePos),
maxPosition = containerBox[size] + step,
initialAxis = axis[0];

// If the specified intial position is greater then the max position then
// clamp the box to the amount of steps it would take for the box to
// reach the max position.
if (Math.abs(position) > maxPosition) {
position = position < 0 ? -1 : 1;
position *= Math.ceil(maxPosition / step) * step;
}

// If computed line position returns negative then line numbers are
// relative to the bottom of the video instead of the top. Therefore, we
// need to increase our initial position by the length or width of the
// video, depending on the writing direction, and reverse our axis directions.
var initialPosition = boxPosition.lineHeight * Math.floor(linePos + 0.5),
initialAxis = axis[0];
if (linePos < 0) {
initialPosition += cue.vertical === "" ? containerBox.height : containerBox.width;
axis = reverseAxis(axis);
position += cue.vertical === "" ? containerBox.height : containerBox.width;
axis = axis.reverse();
}

// Move the box to the specified position. This may not be its best
// position.
boxPosition.move(initialAxis, { toMove: initialPosition, container: containerBox });
boxPosition.move(initialAxis, position);

} else {
// If we have a percentage line value for the cue.
Expand Down
6 changes: 3 additions & 3 deletions dist/vtt.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Andreas Gal <gal@mozilla.com>",
"name": "vtt.js",
"description": "A JavaScript implementation of the WebVTT specification.",
"version": "0.11.4",
"version": "0.11.5",
"repository": {
"type": "git",
"url": "https://github.com/mozilla/vtt.js.git"
Expand Down

0 comments on commit 65ae2da

Please sign in to comment.