Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* Mac Pro webpage reverse video animation thing */
/* */
Object.defineProperties = Object.defineProperties || function() {};
(function() {
var b = 0;
var c = ["ms", "moz", "webkit", "o"];
for (var a = 0; a < c.length && !window.requestAnimationFrame; ++a) {
window.requestAnimationFrame = window[c[a] + "RequestAnimationFrame"];
window.cancelAnimationFrame =
window[c[a] + "CancelAnimationFrame"] ||
window[c[a] + "CancelRequestAnimationFrame"];
}
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(h, e) {
var d = new Date().getTime();
var f = Math.max(0, 16 - (d - b));
var g = window.setTimeout(function() {
h(d + f);
}, f);
b = d + f;
return g;
};
}
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(d) {
clearTimeout(d);
};
}
})();
(function(e, b) {
var g = "",
f,
a,
d;
if (e.addEventListener) {
f = "addEventListener";
} else {
f = "attachEvent";
g = "on";
}
d =
"onwheel" in b.createElement("div")
? "wheel"
: b.onmousewheel !== undefined ? "mousewheel" : "DOMMouseScroll";
e.addWheelListener = function(i, j, h) {
c(i, d, j, h);
if (d == "DOMMouseScroll") {
c(i, "MozMousePixelScroll", j, h);
}
};
function c(j, i, k, h) {
j[f](
g + i,
d == "wheel"
? k
: function(l) {
!l && (l = e.event);
var m = {
originalEvent: l,
target: l.target || l.srcElement,
type: "wheel",
deltaMode: l.type == "MozMousePixelScroll" ? 0 : 1,
deltaX: 0,
delatZ: 0,
preventDefault: function() {
l.preventDefault
? l.preventDefault()
: (l.returnValue = false);
}
};
if (d == "mousewheel") {
m.deltaY = -1 / 40 * l.wheelDelta;
l.wheelDeltaX && (m.deltaX = -1 / 40 * l.wheelDeltaX);
} else {
m.deltaY = l.detail;
}
return k(m);
},
h || false
);
}
})(window, document);
/*! @source http://purl.eligrey.com/github/classList.js/blob/master/classList.js*/
if (
typeof document !== "undefined" &&
!("classList" in document.createElement("a"))
) {
(function(j) {
if (!("HTMLElement" in j) && !("Element" in j)) {
return;
}
var a = "classList",
f = "prototype",
m = (j.HTMLElement || j.Element)[f],
b = Object,
k =
String[f].trim ||
function() {
return this.replace(/^\s+|\s+$/g, "");
},
c =
Array[f].indexOf ||
function(q) {
var p = 0,
o = this.length;
for (; p < o; p++) {
if (p in this && this[p] === q) {
return p;
}
}
return -1;
},
n = function(o, p) {
this.name = o;
this.code = DOMException[o];
this.message = p;
},
g = function(p, o) {
if (o === "") {
throw new n(
"SYNTAX_ERR",
"An invalid or illegal string was specified"
);
}
if (/\s/.test(o)) {
throw new n(
"INVALID_CHARACTER_ERR",
"String contains an invalid character"
);
}
return c.call(p, o);
},
d = function(t) {
var r = k.call(t.className),
q = r ? r.split(/\s+/) : [],
p = 0,
o = q.length;
for (; p < o; p++) {
this.push(q[p]);
}
this._updateClassName = function() {
t.className = this.toString();
};
},
e = (d[f] = []),
i = function() {
return new d(this);
};
n[f] = Error[f];
e.item = function(o) {
return this[o] || null;
};
e.contains = function(o) {
o += "";
return g(this, o) !== -1;
};
e.add = function() {
var t = arguments,
r = 0,
p = t.length,
q,
o = false;
do {
q = t[r] + "";
if (g(this, q) === -1) {
this.push(q);
o = true;
}
} while (++r < p);
if (o) {
this._updateClassName();
}
};
e.remove = function() {
var u = arguments,
t = 0,
p = u.length,
r,
o = false;
do {
r = u[t] + "";
var q = g(this, r);
if (q !== -1) {
this.splice(q, 1);
o = true;
}
} while (++t < p);
if (o) {
this._updateClassName();
}
};
e.toggle = function(p, q) {
p += "";
var o = this.contains(p),
r = o ? q !== true && "remove" : q !== false && "add";
if (r) {
this[r](p);
}
return !o;
};
e.toString = function() {
return this.join(" ");
};
if (b.defineProperty) {
var l = { get: i, enumerable: true, configurable: true };
try {
b.defineProperty(m, a, l);
} catch (h) {
if (h.number === -2146823252) {
l.enumerable = false;
b.defineProperty(m, a, l);
}
}
} else {
if (b[f].__defineGetter__) {
m.__defineGetter__(a, i);
}
}
})(self);
}
var _ = {
defaults: function(c, b) {
var a = {};
b = b || {};
for (var d in c) {
if (c.hasOwnProperty(d)) {
a[d] = b[d] != null ? b[d] : c[d];
}
}
return a;
}
};
AC.define("overview/shared/lib/utils", function() {});
AC.define("overview/shared/event/Emitter", ["require"], function(a) {
function c() {
this._events = [];
}
var b = c.prototype;
b.on = function(e, f) {
var d = this._events;
if (!d[e]) {
d[e] = [];
}
d[e].push(f);
};
b.trigger = function(e, f) {
var d = this._events;
var g = e.split(":")[0];
f = f || {};
f.type = e;
f.index = parseInt(e.split(":")[1], 10);
if (d[g]) {
d[g].forEach(
function(h) {
h.call(this, f);
}.bind(this)
);
}
if (d[e] && e.split(":").length > 1) {
d[e].forEach(
function(h) {
h.call(this, f);
}.bind(this)
);
}
};
return c;
});
AC.define("overview/shared/lib/analytics", ["require"], function(a) {
function c() {
this._trackingQueue = [];
this._interactionType = null;
this._interactionStart = null;
}
var b = c.prototype;
b.flush = function() {
var d;
while ((d = this._trackingQueue.shift())) {
this.trackProps(d);
}
};
b.initInteraction = function(d) {
this._interactionType = d;
this._interactionStart = +new Date();
};
b.queueInteraction = function(i, g, d) {
var f = +new Date();
var j = ((f - this._interactionStart) / 1000).toFixed(1);
var e = this.getTrackingString(g, d);
var h = { prop1: i, prop2: e, prop35: j };
this._trackingQueue.push(h);
};
b.getTrackingString = function(e, d) {
return (
AC.Tracking.pageName() + " - " + e.toLowerCase() + " - section " + d
);
};
b.trackProps = function(d) {
if (typeof d.prop2 !== "string") {
return;
}
var e = this._currentSection;
if (e) {
d.prop3 = this.getTrackingString(e.name, e.index);
}
AC.Tracking.trackClick(d, window, "o", d.prop3);
};
b.setCurrentSection = function(d) {
this._currentSection = d;
};
b.trackLink = function(f, e, d) {
if (arguments.length < 3) {
return;
}
window.setTimeout(function() {
AC.Tracking.trackClick(
{
prop1: f,
prop3:
AC.Tracking.pageName() +
" - " +
e.toString().toLowerCase() +
" - section " +
d
},
this,
"o",
AC.Tracking.pageName() +
" - " +
e.toLowerCase() +
" - section " +
d
);
}, 1000);
};
return c;
});
AC.define(
"overview/shared/app/Core",
[
"require",
"overview/shared/lib/utils",
"overview/shared/event/Emitter",
"overview/shared/lib/analytics"
],
function(a) {
a("overview/shared/lib/utils");
var c = a("overview/shared/event/Emitter");
var d = a("overview/shared/lib/analytics");
function b() {
this.analyzer = new d();
c.call(this);
}
b.prototype = new c();
(b.prototype.addTimelineEvents = function(e) {
e
.filter(function(f) {
return !isNaN(f.pause);
})
.forEach(function(g, f) {
if (g.events) {
g.events.forEach(function(h) {
this.sectionController.on(
h.type + ":" + f,
h.action
);
}, this);
}
}, this);
}),
(b.prototype.createFadeCurtain = function() {
var e = document.createElement("div");
e.id = "curtain";
document.getElementById("wrapper").appendChild(e);
});
b.prototype.convertSectionsToClips = function(f) {
var e = {};
e.clips = [];
e.events = { pauses: [] };
f.forEach(function(g) {
if (!isNaN(g.pause)) {
e.events.pauses.push(g.pause);
}
e.events.pauses.sort(function(i, h) {
return i > h ? 1 : -1;
});
e.clips = e.clips.concat(
g.clips.map(function(h) {
return {
start: g.time + h.start,
end: g.time + h.end,
media: h.media,
pauses: h.pauses
};
})
);
});
return e;
};
b.prototype.resizeFluidAreas = function() {
var e = this.resizeContainers();
this.resizePlaceholders(e);
};
b.prototype.enterAnalytics = function() {
this.analyzer.initInteraction();
this.analyzer.setCurrentSection(
app.sectionController.currentSection
);
clearTimeout(this._analyzerTimeout);
this._analyzerTimeout = window.setTimeout(
function() {
this.analyzer.flush();
}.bind(this),
1000
);
};
b.prototype.exitAnalytics = function(g) {
clearTimeout(this._analyzerTimeout);
var e = app.sectionController._pauseTimeline[g.from];
var f = app.sectionController.getSectionFromPausePoint(e).name;
var h = app.uiController._lastInteractionType;
this.analyzer.queueInteraction(h, f, g.from);
};
b.prototype.setupFocusEvents = function() {
var e = this.sectionController._pauses[0];
this.sectionController.on(
"pauseenter",
function(i) {
var j = i.section || e;
var f = document.querySelector(j.labelSelector);
var h = f.querySelector(".title");
var g = f.querySelector(".button");
h.tabIndex = -1;
if (g) {
g.tabIndex = 0;
}
h.focus();
}.bind(this)
);
this.sectionController.on("pauseexit", function(h) {
var i = h.section || e;
var f = document.querySelector(i.labelSelector);
var g = f.querySelector(".button");
if (g) {
g.tabIndex = -1;
}
});
};
b.prototype.addNextCarets = function() {
var g = document.querySelector("#hero .caret");
if (!g) {
return;
}
var f = [
document.querySelector("#hero"),
document.querySelector("#comingsoon"),
document.querySelector("#measurements")
];
var e = document.querySelectorAll("section", this.panelcontainer);
e = Array.prototype.slice.call(e);
e = e.filter(function(h) {
return f.indexOf(h) === -1;
});
e.forEach(
function(k) {
var m = g.cloneNode(true);
var l = k.querySelector(".copy");
var h = m.querySelector(".cta");
var i = m.querySelector(".button");
var j = function(n) {
if (
n.type === "click" ||
(n.type === "keydown" && n.keyCode === 13)
) {
this.sectionController.next();
}
}.bind(this);
i.id = "";
i.tabIndex = -1;
i.classList.add("next");
h.innerHTML = h.getAttribute("data-next");
m.addEventListener("click", j);
m.addEventListener("keydown", j);
if (document.getElementById("globalheader")) {
l.appendChild(m);
}
}.bind(this)
);
};
return b;
}
);
AC.define(
"overview/shared/controller/Clip",
["require", "overview/shared/event/Emitter"],
function(b) {
var d = b("overview/shared/event/Emitter");
function a(f, e) {
d.call(this);
this._mediaTimer = e;
this._clips = [].concat(f);
this._update = this._update.bind(this);
this._prevTime = this._mediaTimer.currentTime;
this._duration = 0;
this._clips.forEach(function(g) {
g.media.el.classList.add("clip");
if (!g.end) {
g.end = g.start + g.media.duration;
if (g.pauses) {
g.pauses.forEach(function(h) {
g.end += h.to - h.from;
});
}
}
this._duration = Math.max(this._duration, g.end);
}, this);
}
var c = (a.prototype = new d());
c.constructor = a;
(c._getActiveClips = function(e) {
return this._clips.filter(function(f) {
return (
f.media !== this._mediaTimer && f.start <= e && e <= f.end
);
}, this);
}),
(c._timeToClipTime = function(f) {
var e = 0;
if (f.pauses) {
f.pauses.forEach(
function(g) {
if (
this._mediaTimer.currentTime >= g.from &&
this._mediaTimer.currentTime >= g.to
) {
e += g.to - g.from;
} else {
if (
this._mediaTimer.currentTime >= g.from &&
this._mediaTimer.currentTime < g.to
) {
e += this._mediaTimer.currentTime - g.from;
}
}
}.bind(this)
);
}
return this._mediaTimer.currentTime - f.start - e;
});
c._processTransitoryClips = function(e, f) {
var g = this._getActiveClips(e),
h = this._getActiveClips(f);
g = g.filter(function(i) {
return h.indexOf(i) === -1;
});
g.forEach(function(i) {
if (i.media.el) {
i.media.el.classList.remove("visible");
}
i.media.currentTime = this._timeToClipTime(i);
}, this);
h.forEach(function(i) {
if (i.media.el) {
i.media.el.classList.add("visible");
}
i.media.currentTime = this._timeToClipTime(i);
}, this);
};
c._update = function(e, h) {
var g, f;
if (this.currentTime < 0) {
this.trigger("start");
this.pause();
this._mediaTimer.currentTime = 0;
}
this.trigger("timeupdate");
if (this._mediaTimer.update) {
this._mediaTimer.update();
}
if (this.currentTime >= this._duration || h) {
this.pause();
this.trigger("ended");
this._mediaTimer.currentTime = this._duration;
}
this._processTransitoryClips(this._prevTime, this.currentTime);
if (!this.paused) {
this._animationID = window.requestAnimationFrame(this._update);
}
this._prevTime = this.currentTime;
};
c.play = function() {
var e = true;
if (this.paused) {
if (this.currentTime < 0.5 && this.playbackRate < 0) {
this.currentTime = 0;
this.trigger("play");
return;
} else {
if (
this.currentTime > this.duration - 0.5 &&
this.playbackRate > 0
) {
this.currentTime = this.duration;
this.trigger("play");
return;
}
}
e = this._mediaTimer.play();
this.trigger("play");
this._animationID = window.requestAnimationFrame(this._update);
}
return e;
};
c.pause = function() {
if (!this.paused) {
this._mediaTimer.pause();
this.trigger("pause");
window.cancelAnimationFrame(this._animationID);
}
return this;
};
Object.defineProperties(a.prototype, {
currentTime: {
enumerable: true,
configurable: false,
get: function() {
return this._mediaTimer.currentTime;
},
set: function(e) {
this._mediaTimer.currentTime = e;
this._update();
}
},
playbackRate: {
get: function() {
return this._mediaTimer.playbackRate;
},
set: function(e) {
this._mediaTimer.playbackRate = e;
}
},
paused: {
get: function() {
return this._mediaTimer.paused;
},
set: function() {}
},
duration: {
get: function() {
return this._duration;
},
set: function() {}
}
});
return a;
}
);
AC.define("flow/diff/Loader", ["require", "assetLoader/AssetLoader"], function(
b
) {
var c,
a = b("assetLoader/AssetLoader");
function d(g, e) {
var f,
j,
h = g.match(/#/g).length;
this.imagesUrls = [];
if (!e) {
throw new Error("0 images provided");
}
for (f = 1; f <= e; f++) {
j = "0000" + f;
j = j.substring(j.length - h);
this.imagesUrls.push(g.replace(/#{2,}/g, j));
}
}
c = d.prototype;
c.load = function() {
return new a(this.imagesUrls).load();
};
return d;
});
AC.define(
"flow/diff/Render",
["require", "flow/diff/Loader", "defer/Deferred"],
function(d) {
var e,
c = d("flow/diff/Loader"),
b = d("defer/Deferred");
function a(g, f) {
this.flowData = g;
this.flowData.imageUrlPattern = f;
}
e = a.prototype;
e._storeImages = function(f) {
if (DEBUG) {
console.log("loaded images");
}
this.images = f;
this._blocksPerFullDiff =
f[0].width /
this.flowData.blockSize *
(f[0].height / this.flowData.blockSize);
return new b().resolve();
};
e._applyDiffRange = function(h, o) {
var m = o.block,
i = o.length,
g = h.canvas.width / this.flowData.blockSize,
k = Math.floor(m / this._blocksPerFullDiff),
u = this.images[k].width,
f = m % this._blocksPerFullDiff,
t = u / this.flowData.blockSize,
r = (f % t) * this.flowData.blockSize,
q = Math.floor(f / (t || 1)) * this.flowData.blockSize,
n = (o.location % g) * this.flowData.blockSize,
l = Math.floor(o.location / g) * this.flowData.blockSize,
j,
p;
while (i) {
j = Math.min(
i * this.flowData.blockSize,
h.canvas.width - n,
u - r
);
p = j / this.flowData.blockSize;
if (DEBUG) {
if (
typeof this.renderDebugger !== "undefined" &&
this._frameToRender > 0
) {
this.renderDebugger.registerComparison(
this._frameToRender,
{ image: k, block: m, x: r, y: q }
);
}
}
h.drawImage(
this.images[k],
r,
q,
j,
this.flowData.blockSize,
n,
l,
j,
this.flowData.blockSize
);
i -= p;
if (i) {
if ((r += j) >= u) {
r = 0;
q += this.flowData.blockSize;
}
if ((f += p) >= this._blocksPerFullDiff) {
f = 0;
r = 0;
q = 0;
k += 1;
if (k === this.flowData.imagesRequired - 1) {
u = this.images[k].width;
}
}
if ((n += j) >= h.canvas.width) {
n = 0;
l += this.flowData.blockSize;
}
m += p;
}
}
};
e.init = function() {
if (DEBUG) {
console.log("load images");
}
return new c(
this.flowData.imageUrlPattern,
this.flowData.imagesRequired
)
.load()
.then(this._storeImages.bind(this));
};
e.renderDiff = function(f, i) {
var g = f.getContext("2d");
i -= 1;
if (DEBUG) {
this._frameToRender = i;
console.log("applying diff frame : " + (i + 1));
}
this.frames[i].forEach(
function h(j) {
this._applyDiffRange(g, j);
}.bind(this)
);
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(e, {
frames: {
get: function() {
return this.flowData.frames;
},
set: function(f) {
this.flowData.frames = f;
},
enumerable: true
}
});
return a;
}
);
AC.define(
"flow/compositor/Sequence",
[
"require",
"assetLoader/AssetLoader",
"flow/diff/Render",
"defer/Deferred"
],
function(c) {
var e,
a = c("assetLoader/AssetLoader"),
f = c("flow/diff/Render"),
b = c("defer/Deferred");
function d(i, h, g) {
this._keyframes = i;
this._imageUrlPattern = h;
this._flowDataProvider = g;
}
e = d.prototype;
e._initDiffRender = function(g) {
this._images = g;
this.canvas.height = g[0].height;
this.canvas.width = g[0].width;
this.applyFrame(g[0]);
};
e.init = function(g) {
this.canvas = g || document.createElement("canvas");
return new a(this._keyframes)
.load()
.then(this._initDiffRender.bind(this))
.then(this._flowDataProvider.load.bind(this._flowDataProvider));
};
e.createDiffRender = function(g) {
this._diffRender = new f(g, this._imageUrlPattern);
return this._diffRender.init();
};
e.applyFrame = function(h) {
var g = this.canvas.getContext("2d");
g.drawImage(h, 0, 0);
};
e.calculateRenderCount = function(g, h) {
var i = 0;
if (Math.abs(h - g) >= h) {
g = 1;
i = 1;
} else {
if (Math.abs(h - g) >= this.frameCount - h && this._images[1]) {
g = this.frameCount - 2;
i = 1;
}
}
if (h > 0 && h < this.frameCount - 1) {
return Math.abs(g - h) + i;
} else {
return i;
}
};
e.compositeFrames = function(g, i) {
var h = new b();
i = this.frameCount < i ? this.frameCount - 1 : i < 0 ? 0 : i;
g = this.frameCount - 2 < g ? this.frameCount - 2 : g < 0 ? 0 : g;
var j;
if (DEBUG) {
console.groupCollapsed(
"Rendering diff frames: " + g + "..." + i
);
}
if (Math.abs(i - g) >= i) {
g = 1;
if (DEBUG) {
console.log("applying start keyframe");
}
this.applyFrame(this._images[0]);
} else {
if (Math.abs(i - g) >= this.frameCount - i && this._images[1]) {
g = this.frameCount - 2;
if (DEBUG) {
console.log("applying end keyframe");
}
this.applyFrame(this._images[1]);
}
}
j = g > i ? -1 : g < i ? 1 : 0;
if (i > 0 && i < this.frameCount - 1) {
while (g !== i) {
h.progress(g);
this._diffRender.renderDiff(this.canvas, g);
g += j;
h.progress(g);
}
}
if (DEBUG) {
console.groupEnd();
}
h.resolve(g);
return h.promise();
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(e, {
frameCount: {
get: function() {
return this._diffRender.frames.length + 2;
},
enumerable: true
},
canvas: {
get: function() {
return this._canvas;
},
set: function(g) {
return (this._canvas = g);
},
enumerable: true
},
mainCompositor: {
get: function() {
var g = this;
while (g._compositor) {
g = g._compositor;
}
return g;
},
enumerable: true
}
});
return d;
}
);
AC.define("flow/data/Manifest", [], function() {
function a() {}
return a;
});
AC.define("flow/data/Block", [], function() {
function a(b, c) {
this.location = b;
this.length = c;
}
return a;
});
AC.define(
"flow/data/processor",
["require", "flow/data/Manifest", "flow/data/Block"],
function(b) {
var e = b("flow/data/Manifest"),
a = b("flow/data/Block"),
d;
var c = {
parseData: function(f) {
d = 0;
var g = f.frames.map(this._parseFrame, this);
return Object.create(e.prototype, {
version: { value: f.version },
framecount: { value: f.frameCount },
blockSize: { value: f.blockSize },
imagesRequired: { value: f.imagesRequired },
reversible: { value: f.reversible },
superframeFrequency: { value: f.superframeFrequency },
frames: { value: g }
});
},
_valueForCharAt: function(h, f) {
var g = h.charCodeAt(f);
if (g > 64 && g < 91) {
return g - 65;
}
if (g > 96 && g < 123) {
return g - 71;
}
if (g > 47 && g < 58) {
return g + 4;
}
if (g === 43) {
return 62;
}
if (g === 47) {
return 63;
}
throw "Invalid Bas64 character: " + h.charAt(f);
},
_createNumberFromBase64Range: function(j, f, i) {
var h = 0,
g;
while (i--) {
g = this._valueForCharAt(j, f++);
h += g << (i * 6);
}
return h;
},
_parseFrame: function(g) {
var h,
k = [],
g = g.value || g,
j,
f;
for (h = 0; h < g.length; h += 5) {
f = this._createNumberFromBase64Range(g, h, 3);
j = this._createNumberFromBase64Range(g, h + 3, 2);
k.push(
Object.create(a.prototype, {
location: { value: f, enumerable: true },
length: { value: j, enumerable: true },
block: { value: (d += j) - j, enumerable: true }
})
);
}
return k;
}
};
return c;
}
);
AC.define(
"flow/data/provider/Async",
["require", "ajax/Ajax", "flow/data/processor"],
function(b) {
var d,
a = b("ajax/Ajax"),
e = b("flow/data/processor");
function c(f, g) {
this._url = f;
this._ajaxAdaptor = g || new a();
}
d = c.prototype;
d.load = function() {
var f = this;
return this._ajaxAdaptor
.get(this._url)
.then(function(h) {
try {
var g = h.response || h.responseText;
return JSON.parse(g);
} catch (i) {
if (DEBUG) {
console.log("Failed to parse manifest data");
}
}
})
.then(function(g) {
f._data = g;
return e.parseData(g);
});
};
return c;
}
);
AC.define(
"flow/data/provider/Sync",
["require", "defer/Deferred", "flow/data/processor"],
function(b) {
var d,
a = b("defer/Deferred"),
e = b("flow/data/processor");
function c(f) {
this._data = f;
}
d = c.prototype;
d.load = function() {
var f = new a();
f.resolve(e.parseData(this._data));
return f.promise();
};
return c;
}
);
AC.define("flow/Player", ["require", "defer/Deferred"], function(b) {
var d,
a = b("defer/Deferred");
function c(f, e) {
this._flow = e;
this._frameRate = 30;
this.element = f;
this.paused = true;
this.loop = false;
}
d = c.prototype;
d._dispatchEvent = function(e) {
var f = document.createEvent("Events");
f.initEvent(e, true, false);
f.data = this;
this.element.dispatchEvent(f);
return f;
};
d._timeToFrame = function(e) {
var f;
f = Math.round(e / this.duration * this._flow.frameCount);
f = f % (this._flow.frameCount + 1);
return f < 0 ? this._flow.frameCount + f : f;
};
d._advanceToTimeGlobal = function(e) {
this._prevTime = this._prevTime || e;
this._currentTime += (e - this._prevTime) / 1000 * this.playbackRate;
this._prevTime = e;
var f = this._timeToFrame(this._currentTime),
g = false;
if (!this.loop) {
if (this.playbackRate > 0 && this._currentTime > this.duration) {
f = this._flow.frameCount;
this._currentTime = this.duration;
g = true;
} else {
if (this.playbackRate < 0 && this._currentTime < 0) {
f = 0;
this._currentTime = 0;
g = true;
}
}
} else {
this._currentTime =
(this.duration + this._currentTime) % this.duration;
}
if (!this.paused && !this.seeking) {
return this._flow.gotoFrame(f).then(
function() {
this._dispatchEvent("timeupdate");
if (g) {
this.paused = true;
this._dispatchEvent("ended");
} else {
this._requestAnimationFrame = window.requestAnimationFrame(
this._advanceToTimeGlobal.bind(this)
);
}
}.bind(this)
);
} else {
return new a().reject();
}
};
d._advanceToTimeLocal = function(e) {
if (!this.seeking) {
this.seeking = true;
this._dispatchEvent("seeking");
this._currentTime = 1 * e;
this._prevTime = null;
window.cancelAnimationFrame(this._requestAnimationFrame);
this._flow.gotoFrame(this._timeToFrame(e)).then(
function() {
this.seeking = false;
this._dispatchEvent("timeupdate");
this._dispatchEvent("seeked");
this._requestAnimationFrame = window.requestAnimationFrame(
this._advanceToTimeGlobal.bind(this)
);
}.bind(this)
);
}
if (DEBUG) {
console.log("advance to time " + e + " from " + this._currentTime);
}
};
d.load = function() {
this._dispatchEvent("loadstart");
return this._flow
.init(this.element)
.then(this._dispatchEvent.bind(this, "canplaythrough"));
};
d.play = function() {
if (this.paused) {
this.paused = false;
this._dispatchEvent("play");
this._prevTime = null;
this._requestAnimationFrame = window.requestAnimationFrame(
this._advanceToTimeGlobal.bind(this)
);
}
return this;
};
d.pause = function() {
if (!this.paused) {
this.paused = true;
window.cancelAnimationFrame(this._requestAnimationFrame);
this._dispatchEvent("pause");
}
return this;
};
d.on = function() {
this.element.addEventListener.apply(this.element, arguments);
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(d, {
_currentTime: { value: 0, enumerable: false, writable: true },
_playbackRate: { value: 1, enumerable: false, writable: true },
currentTime: {
get: function() {
return this._currentTime * 1;
},
set: d._advanceToTimeLocal,
enumerable: true
},
frameRate: {
get: function() {
return this._frameRate;
},
set: function(e) {
if (isFinite(e)) {
this._frameRate = e;
this._dispatchEvent("durationchange");
}
},
enumerable: true
},
playbackRate: {
get: function() {
return this._playbackRate * 1;
},
set: function(e) {
if (isFinite(e)) {
this._playbackRate = 1 * e;
this._dispatchEvent("ratechange");
}
},
enumerable: true
},
duration: {
get: function() {
return this._flow.frameCount / this.frameRate;
},
enumerable: true
}
});
return c;
});
AC.define(
"flow/keyframe/Loader",
["require", "assetLoader/AssetLoader", "defer/Deferred"],
function(d) {
var e,
a = d("assetLoader/AssetLoader"),
c = d("defer/Deferred");
function b(f, i) {
var h,
g = f.match(/#/g).length;
this._keyframes = {};
f = f.replace(/([^#]+)(#+)(\..*)/, "$1key_$2$3");
this._imageUrls = [];
if (i.frames) {
i.frames.forEach(
function(k, j) {
if (k.type === "keyframe") {
h = "0000" + j;
h = h.substring(h.length - g);
this._imageUrls.push(f.replace(/#+/g, h));
this._keyframes[j] = k;
}
}.bind(this)
);
}
}
e = b.prototype;
e.load = function() {
if (this._imageUrls.length > 0) {
return new a(this._imageUrls).load();
}
return new c().resolve();
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(e, {
keyframes: {
get: function() {
return this._keyframes;
},
enumerable: true
}
});
return b;
}
);
AC.define("flow/keyframe/Render", ["require", "flow/keyframe/Loader"], function(
a
) {
var b,
d = a("flow/keyframe/Loader");
function c(f, e) {
this.flowData = f;
this.flowData.imageUrlPattern = e;
}
b = c.prototype;
b._storeImages = function(e) {
var g = 0,
h;
if (e && e.length > 0) {
if (DEBUG) {
console.log("loaded keyframe diff images");
}
for (var f in this._loader._keyframes) {
if (this._loader._keyframes.hasOwnProperty(f)) {
h = e[g];
this._loader._keyframes[f].image = h;
g += 1;
}
}
}
if (DEBUG) {
if (!e || e.length === 0) {
console.log("no keyframe diff images to load");
}
}
};
b.init = function() {
if (DEBUG) {
console.log("loading keyframe diff images");
}
this._loader = new d(this.flowData.imageUrlPattern, this.flowData);
return this._loader.load().then(this._storeImages.bind(this));
};
b.renderKeyframe = function(g, f, o) {
var e = g.getContext("2d"),
i = this._loader.keyframes[f],
j = i.image,
m = i.x,
l = i.y,
n = i.width,
k = i.height;
if (DEBUG) {
console.log("applying keyframe diff image: " + f);
console.log("x:" + m + " y:" + l + " w:" + n + " h:" + k);
}
if (o === true) {
if (DEBUG) {
console.log("drawing superKeyframe sub-rectangle");
}
e.drawImage(j, m, l, n, k, m, l, n, k);
} else {
if (this.flowData.reversible) {
if (DEBUG) {
console.log("drawing superKeyframe full image");
}
e.drawImage(j, 0, 0);
} else {
if (DEBUG) {
console.log("drawing keyframe full image");
}
e.drawImage(j, m, l, n, k);
}
}
};
return c;
});
AC.define(
"flow/compositor/decorator/Keyframe",
["require", "flow/keyframe/Render", "defer/Deferred"],
function(c) {
var d,
b = c("flow/keyframe/Render"),
a = c("defer/Deferred");
function e(f) {
this._compositor = f;
this._flowDataProvider = this.mainCompositor._flowDataProvider;
}
d = e.prototype;
d.init = function(f) {
this._keyframeDiffRender = new b(
this._flowDataProvider._data,
this.mainCompositor._imageUrlPattern
);
return this._keyframeDiffRender.init();
};
d.applyFrame = function(f) {
return this._compositor.applyFrame.apply(
this._compositor,
arguments
);
};
d.applyKeyframe = function(f, g) {
this._keyframeDiffRender.renderKeyframe(this.canvas, f, g);
};
d.compositeFrames = function(f, h) {
if (!this._isKeyframeDiff(h - 1)) {
return this._compositor.compositeFrames.apply(
this._compositor,
arguments
);
}
var g = new a();
if (DEBUG) {
console.groupCollapsed(
"Rendering keyframe diff image: " + (f - 1)
);
}
this.applyKeyframe(h - 1);
if (DEBUG) {
console.groupEnd();
}
g.resolve(f - 1);
return g.promise();
};
d._isKeyframeDiff = function(f) {
return f in this._keyframeDiffRender._loader._keyframes;
};
d.calculateRenderCount = function(f, g) {
return this._compositor.calculateRenderCount.apply(
this._compositor,
arguments
);
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(d, {
frameCount: {
get: function() {
return this._compositor.frameCount;
},
enumerable: true
},
canvas: {
get: function() {
return this._compositor.canvas;
},
set: function(f) {
return (this._compositor.canvas = f);
},
enumerable: true
},
mainCompositor: {
get: function() {
return this._compositor.mainCompositor;
},
enumerable: true
}
});
return e;
}
);
AC.define("flow/compositor/decorator/Superframe", [], function() {
var a;
function b(d, c) {
this._compositor = d;
this._superframeInterval = c || 4;
}
a = b.prototype;
a._getClosestSuperframe = function(c) {
return (
Math.round(c / this._superframeInterval) * this._superframeInterval
);
};
a.init = function(c) {
this._screenCanvas = c;
};
a.applyFrame = function() {
this._compositor.applyFrame.apply(this._compositor, arguments);
};
a.calculateRenderCount = function(c, e) {
var d = this._getClosestSuperframe(c);
if (Math.abs(d - e) > this._superframeInterval / 2) {
c = d + (c > e ? -1 : 1) * this._superframeInterval;
return this.calculateRenderCount(c, e) + 1;
} else {
return Math.abs(d - e) + 1;
}
};
a.compositeFrames = function(c, f) {
var g, d;
if (f <= 0 || f >= this.frameCount - 2) {
this._compositor.compositeFrames(c, f);
}
if (c > this.frameCount - 2) {
c = this.frameCount - 2;
} else {
if (c <= 0) {
c = 1;
}
}
d = this._getClosestSuperframe(c);
if (DEBUG) {
console.groupCollapsed("Rendering : " + c + "..." + f);
}
if (
this._compositor.calculateRenderCount(c, f) >
this.calculateRenderCount(c, f)
) {
if (DEBUG) {
console.groupCollapsed("Rendering (superframe) : " + d);
}
g = this._compositor.compositeFrames(d, d).then(
function e() {
if (DEBUG) {
console.groupEnd();
}
var h = d + (c > f ? -1 : 1) * this._superframeInterval;
this._compositor.compositeFrames(d, h).then(
function() {
return this.compositeFrames(h, f);
}.bind(this)
);
}.bind(this)
);
} else {
if (DEBUG) {
console.groupCollapsed(
"Rendering (final frames) : " + c + "..." + f
);
}
g = this._compositor.compositeFrames(c, f).then(
function e() {
if (DEBUG) {
console.groupEnd();
}
}.bind(this)
);
}
g.then(
function e() {
if (DEBUG) {
console.groupEnd();
}
}.bind(this)
);
return g;
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(a, {
frameCount: {
get: function() {
return this._compositor.frameCount;
},
enumerable: true
},
canvas: {
get: function() {
return this._compositor.canvas;
},
set: function(c) {
return (this._compositor.canvas = c);
},
enumerable: true
},
mainCompositor: {
get: function() {
return this._compositor.mainCompositor;
},
enumerable: true
}
});
return b;
});
AC.define(
"flow/compositor/decorator/SuperKeyframe",
["require", "defer/Deferred"],
function(b) {
var c,
a = b("defer/Deferred");
function d(e) {
this._compositor = e;
this._frames = this.mainCompositor._flowDataProvider._data.frames;
this._superframeInterval = this.mainCompositor._diffRender.flowData.superframeFrequency;
}
c = d.prototype;
c.init = function(e) {
return this._compositor.init.apply(this._compositor, arguments);
};
c.applyFrame = function(e) {
return this._compositor.applyFrame.apply(
this._compositor,
arguments
);
};
c.applyKeyframe = function(e, f) {
this._compositor.applyKeyframe.apply(this._compositor, arguments);
};
c.compositeFrames = function(e, h) {
var i,
g,
f = new a();
if (h < 1 || h > this.frameCount - 2) {
return this._compositor.compositeFrames.apply(
this._compositor,
arguments
);
}
if (this._isKeyframeDiff(h - 1)) {
i = Math.abs(e - h) === 1 ? true : false;
if (DEBUG) {
console.groupCollapsed(
"Drawing superKeyframe image: " + (h - 1)
);
}
this.applyKeyframe(h - 1, i);
if (DEBUG) {
console.groupEnd();
}
f.resolve(e - 1);
return f.promise();
}
if (Math.abs(h - e) > this._superframeInterval) {
g = this._getShortestRender(e, h);
if (
this._isKeyframeDiff(g - 1) ||
g <= 0 ||
g >= this.frameCount - 2
) {
return this._compositeFromSuperKeyframe(g, h);
}
}
if (DEBUG) {
console.log(
"SuperKeyframe compositor handing off to slave compositor: fromFrame:" +
e +
" toFrame:" +
h
);
}
return this._compositor.compositeFrames.apply(this._compositor, [
e,
h
]);
};
c._getShortestRender = function(e, g) {
var i = this._compositor.calculateRenderCount,
h = this._getClosestSuperKeyframe(g - 1),
f = i.apply(this._compositor, [h, g]) + 1,
j = i.apply(this._compositor, [e, g]);
if (f <= j) {
return h;
} else {
return e;
}
};
c._compositeFromSuperKeyframe = function(i, g) {
var e = this.canvas.getContext("2d"),
f =
i <= 0
? this.mainCompositor._images[0]
: i >= this.frameCount - 2
? this.mainCompositor._images[1]
: this._frames[i - 1].image,
h;
if (DEBUG) {
console.log(
"Drawing superKeyframe for composite base: superKeyframe " +
(i - 1)
);
}
e.drawImage(f, 0, 0);
return this._compositor.compositeFrames.call(
this._compositor,
i,
g
);
};
c._getClosestSuperFrame = function(e) {
return (
Math.round(e / this._superframeInterval) *
this._superframeInterval
);
};
c._getClosestSuperKeyframe = function(f) {
var j,
k,
h,
g,
e = this._frames.length;
if (f < e + 1 && f > 0) {
g = f - 1;
while (g >= 0) {
if (this._frames[g].type === "keyframe") {
j = g + 1;
break;
}
g -= 1;
}
g = f + 1;
while (g <= e - 1) {
if (this._frames[g].type === "keyframe") {
k = g + 1;
break;
}
g += 1;
}
}
j = j ? j : 0;
k = k ? k : this.frameCount;
h = f - j < k - f ? j : k;
return h;
};
c._isKeyframeDiff = function(e) {
return this._compositor._isKeyframeDiff.apply(
this._compositor,
arguments
);
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(c, {
frameCount: {
get: function() {
return this._compositor.frameCount;
},
enumerable: true
},
canvas: {
get: function() {
return this._compositor.canvas;
},
set: function(e) {
return (this._compositor.canvas = e);
},
enumerable: true
},
mainCompositor: {
get: function() {
return this._compositor.mainCompositor;
},
enumerable: true
}
});
return d;
}
);
AC.define("flow/compositor/decorator/Cache", [], function() {
var b;
function a(d, c) {
this._compositor = d;
this._keyframeInterval = c || 8;
this._keyframes = [];
}
b = a.prototype;
b._getClosestKeyframe = function(c) {
var d = c % this._keyframeInterval,
e =
Math.floor(c / this._keyframeInterval) +
(d > this._keyframeInterval / 2 ? 1 : 0);
return e;
};
b._getFrameFromKeyframe = function(c) {
return c * this._keyframeInterval;
};
b._saveKeyframe = function(e) {
var c,
d = Math.floor(e / this._keyframeInterval);
if (e % this._keyframeInterval === 0 && !this._keyframes[d]) {
if (DEBUG) {
console.log("saving keyframe " + e);
}
c = document.createElement("canvas");
c.width = this._compositor.canvas.width;
c.height = this._compositor.canvas.height;
c.getContext("2d").drawImage(this._compositor.canvas, 0, 0);
this._keyframes[d] = c;
}
};
b.init = function(c) {
return this._compositor.init.apply(this._compositor, arguments);
};
b.applyFrame = function() {
this._compositor.applyFrame.apply(this._compositor, arguments);
};
b.calculateRenderCount = function(c, d) {
c = this._getFrameFromKeyframe(this._getClosestKeyframe(d));
return this._compositor.calculateRenderCount(c, d) + 1;
};
b.compositeFrames = function(c, e) {
var f = this._getClosestKeyframe(e);
if (DEBUG) {
console.groupCollapsed("Rendering frames: " + c + "..." + e);
}
if (
this._keyframes[f] &&
this._compositor.calculateRenderCount(c, e) >
this.calculateRenderCount(c, e)
) {
c = this._getFrameFromKeyframe(f);
if (DEBUG) {
console.log("applying prerendered keyframe: " + c);
}
this.applyFrame(this._keyframes[f]);
return this._compositor.compositeFrames(c, e).then(function d() {
if (DEBUG) {
console.groupEnd();
}
});
} else {
return this._compositor.compositeFrames(c, e).then(
function d() {
if (DEBUG) {
console.groupEnd();
}
},
null,
this._saveKeyframe.bind(this)
);
}
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(b, {
frameCount: {
get: function() {
return this._compositor.frameCount;
},
enumerable: true
},
canvas: {
get: function() {
return this._compositor.canvas;
},
set: function(c) {
return (this._compositor.canvas = c);
},
enumerable: true
}
});
return a;
});
AC.define("stats/Benchmark", [], function() {
function a(b) {
this.name = b;
}
a.prototype.start = function() {
if (DEBUG) {
console.log("▼▼▼ start " + this.name + " benchmark");
this.startTime = new Date().getTime();
console.time(this.name);
}
};
a.prototype.end = function() {
if (DEBUG) {
this.endTime = new Date().getTime();
console.log(
"▲▲▲ end " +
this.name +
" benchmark " +
(this.endTime - this.startTime) / 1000 +
" sec"
);
console.time(this.timeEnd);
}
};
return a;
});
AC.define(
"flow/compositor/decorator/Benchmark",
["require", "stats/Benchmark"],
function(a) {
var b,
d = a("stats/Benchmark");
function c(e) {
this._compositor = e;
}
b = c.prototype;
b.init = function(e) {
var f = new d("init");
f.start();
return this._compositor.init
.apply(this._compositor, arguments)
.then(f.end.bind(f));
};
b.applyFrame = function() {
var e = new d("applyFrame");
e.start();
this._compositor.applyFrame.apply(this._compositor, arguments);
e.end.bind(e);
};
b.calculateRenderCount = function() {
return this._compositor.calculateRenderCount.apply(
this._compositor,
arguments
);
};
b.compositeFrames = function() {
var e = new d("renderFrames");
e.start();
return this._compositor.compositeFrames
.apply(this._compositor, arguments)
.then(e.end.bind(e));
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(b, {
frameCount: {
get: function() {
return this._compositor.frameCount;
},
enumerable: true
},
canvas: {
get: function() {
return this._compositor.canvas;
},
set: function(e) {
return (this._compositor.canvas = e);
},
enumerable: true
}
});
c.prototype = b;
return c;
}
);
AC.define(
"flow/Flow",
[
"require",
"defer/Deferred",
"flow/compositor/decorator/Keyframe",
"flow/compositor/decorator/Superframe",
"flow/compositor/decorator/SuperKeyframe",
"flow/compositor/decorator/Cache",
"flow/compositor/decorator/Benchmark"
],
function(a) {
var c,
f = a("defer/Deferred"),
g = a("flow/compositor/decorator/Keyframe"),
e = a("flow/compositor/decorator/Superframe"),
d = a("flow/compositor/decorator/SuperKeyframe"),
i = a("flow/compositor/decorator/Cache"),
h = a("flow/compositor/decorator/Benchmark");
function b(j, k) {
this._compositor = j;
this.options = k || {};
}
c = b.prototype;
c.gotoFrame = function(j) {
if (this._rendering) {
return new f().resolve();
} else {
if (this._currentFrame === j) {
return new f().resolve();
}
}
this._rendering = true;
if (DEBUG) {
console.groupCollapsed(
"gotoFrame:" + j + " currentFrame:" + this._currentFrame
);
}
return this._compositor.compositeFrames(this._currentFrame, j).then(
function() {
this._rendering = false;
this._currentFrame = j;
if (DEBUG) {
console.groupEnd();
}
}.bind(this)
);
};
c.init = function(k) {
var j;
if (k.nodeName === "CANVAS") {
j = k;
} else {
j = document.createElement("canvas");
k.appendChild(j);
}
return this._compositor.init(j).then(
function(l) {
return f.all([
this._compositor
.createDiffRender(l)
.then(this._decorateCompositor.bind(this))
]);
}.bind(this)
);
};
c._decorateCompositor = function() {
var j = this._compositor,
l = this._compositor._diffRender.flowData,
k = this._compositor.canvas;
if (l.superframeFrequency) {
j = new e(j, l.superframeFrequency);
}
if (l.version === 3) {
j = new g(j);
}
if (l.version === 3 && l.superframeFrequency) {
j = new d(j);
}
if (this.options.keyframeCache) {
j = new i(j, this.options.keyframeCache);
}
if (this.options.benchmark) {
j = new h(j);
}
if (j === this._compositor) {
return new f().resolve();
} else {
this._compositor = j;
return this._compositor.init(k);
}
};
if (typeof Object.defineProperties !== "function") {
return function() {};
}
Object.defineProperties(c, {
_currentFrame: { value: 0, enumerable: false, writable: true },
frameCount: {
get: function() {
return this._compositor.frameCount;
},
enumerable: true
}
});
return b;
}
);
AC.define(
"flow/playerFactory",
[
"require",
"flow/compositor/Sequence",
"flow/data/provider/Async",
"flow/data/provider/Sync",
"flow/Player",
"flow/Flow"
],
function(c) {
var b = c("flow/compositor/Sequence"),
g = c("flow/data/provider/Async"),
f = c("flow/data/provider/Sync"),
a = c("flow/Player"),
d = c("flow/Flow");
function e(l, n, k, m, j) {
var i, o, h;
j = j || {};
j = {
keyframeCache:
typeof j.keyframeCache === "undefined"
? 8
: j.keyframeCache,
benchmark:
typeof j.benchmark === "undefined" ? false : j.benchmark,
preload: typeof j.preload === "undefined" ? true : j.preload
};
n = n || [l.getAttribute("data-start-frame")];
if (l.getAttribute("data-end-frame")) {
n.push(l.getAttribute("data-end-frame"));
}
k = k || l.getAttribute("data-image-url-pattern");
h = typeof m === "string" ? new g(m) : new f(m);
i = new b(n, k, h);
o = new a(l, new d(i, j));
if (j.preload) {
o.load();
}
return o;
}
return e;
}
);
AC.define("overview/shared/MediaTimer", [], function() {
function b() {
this._currentTimeMS = 0;
this._playbackRate = 1;
this.playing = false;
this._paused = true;
this._resetStartTime();
}
var a = b.prototype;
a._updateCurrentTime = function() {
var d,
c = +new Date();
if (this.paused) {
d = 0;
} else {
d = c - this._startTime;
}
this._currentTimeMS += d * this._playbackRate;
this._startTime = c;
};
(a._resetStartTime = function() {
this._startTime = +new Date();
}),
(a.play = function() {
this._resetStartTime();
this.playing = true;
this._paused = false;
return this;
});
a.pause = function() {
this._updateCurrentTime();
this.playing = false;
this._paused = true;
return this;
};
Object.defineProperties(a, {
currentTime: {
get: function() {
this._updateCurrentTime();
return this._currentTimeMS / 1000;
},
set: function(c) {
this._resetStartTime();
this._currentTimeMS = c * 1000;
}
},
playbackRate: {
get: function() {
return this._playbackRate;
},
set: function(c) {
this._resetStartTime();
this._playbackRate = c;
}
},
paused: {
get: function() {
return this._paused;
},
set: function() {}
}
});
return b;
});
AC.define(
"overview/shared/media/TimedVideo",
["require", "overview/shared/MediaTimer", "defer/Deferred"],
function(c) {
var e = c("overview/shared/MediaTimer"),
b = c("defer/Deferred");
function a(i, f, h) {
this._deferred = new b();
this._paused = true;
this._playbackRate = 1;
this._backwardsTimer = new e();
this._video = document.createElement("video");
if (h) {
this._video.poster = h;
}
var g = function(j) {
this._video.removeEventListener("error", g);
this._video.parentNode.removeChild(this._video);
this._deferred.reject(j);
}.bind(this);
this._video.addEventListener("error", g);
this._video.addEventListener(
"canplay",
function(j) {
this._video.removeEventListener("error", g);
this.canplay = true;
this._deferred.resolve(j);
}.bind(this)
);
this._video.src = f;
i.appendChild(this._video);
}
var d = a.prototype;
d.promise = function() {
return this._deferred.promise();
};
d.update = function() {
if (this.playbackRate < 0) {
this._video.currentTime = this._backwardsTimer.currentTime;
}
};
d.play = function() {
if (this.paused) {
if (this.playbackRate >= 0) {
this._video.playbackRate = this.playbackRate;
this._video.play();
} else {
this._backwardsTimer.playbackRate = this.playbackRate;
this._backwardsTimer.play();
}
this._paused = false;
}
return true;
};
d.pause = function() {
if (!this.paused) {
this._video.pause();
this._backwardsTimer.pause();
this.currentTime = this.currentTime;
this._paused = true;
}
};
Object.defineProperties(d, {
currentTime: {
get: function() {
if (!this.paused && this.playbackRate >= 0) {
return this._video.currentTime;
} else {
return this._backwardsTimer.currentTime;
}
},
set: function(f) {
this._video.currentTime = f;
this._backwardsTimer.currentTime = f;
}
},
playbackRate: {
get: function() {
return this._playbackRate;
},
set: function(f) {
this._playbackRate = f;
}
},
paused: {
get: function() {
return this._paused;
},
set: function() {}
}
});
return a;
}
);
AC.define(
"overview/shared/media/BiVideo",
["require", "defer/Deferred", "overview/shared/MediaTimer"],
function(b) {
var a = b("defer/Deferred"),
e = b("overview/shared/MediaTimer");
function d(v, k, l, p, i) {
var g = new a(),
h = new a(),
t,
j,
u = 0,
o,
f;
i = i || 0;
this._paused = true;
this._playbackRate = 1;
this._mediaTimer = new e();
this._forwardsVideo = document.createElement("video");
if (p) {
this._forwardsVideo.poster = p;
}
if (l) {
this._backwardsVideo = document.createElement("video");
}
this._canPlayBackwards = false;
this._canPlayForwards = false;
var r = function(w) {
f = +new Date();
document.removeEventListener("touchstart", r);
this._forwardsVideo.addEventListener(
"canplaythrough",
function() {
document.addEventListener("touchstart", n);
}
);
this._forwardsVideo.load();
window.app.uiController.next();
w.preventDefault();
}.bind(this);
var n = function(w) {
document.removeEventListener("touchstart", n);
var x = setInterval(
function() {
var y;
try {
y = this._forwardsVideo.seekable.end(0);
} catch (z) {}
if (y === this._forwardsVideo.duration && this.paused) {
clearInterval(x);
this._forwardsVideo.addEventListener(
"seeked",
function(A) {
this._forwardsVideo.style.opacity = 1;
}.bind(this)
);
this._forwardsVideo.currentTime =
i || this.currentTime;
this._canPlayForwards = true;
app.uiController.enableInput();
}
}.bind(this),
100
);
w.preventDefault();
}.bind(this);
var m = function(w) {
this._forwardsVideo.removeEventListener("progress", m);
g.resolve(w);
}.bind(this);
var q = function(w) {
this._backwardsVideo.removeEventListener("progress", q);
h.resolve(w);
}.bind(this);
this._forwardsVideo.style.height = "100%";
this._forwardsVideo.style.width = "100%";
this._forwardsVideo.style.opacity = 0;
this._forwardsVideo.controls = false;
if (l) {
this._backwardsVideo.style.height = "100%";
this._backwardsVideo.style.width = "100%";
this._backwardsVideo.style.opacity = 0;
this._backwardsVideo.controls = false;
this._backwardsVideo.addEventListener("progress", q);
this._backwardsVideo.src = l;
v.appendChild(this._backwardsVideo);
} else {
h = true;
}
this._forwardsVideo.addEventListener("progress", m);
this._forwardsVideo.src = k;
v.appendChild(this._forwardsVideo);
this._promise = a.join(g, h).then(
function() {
document.addEventListener("touchstart", r);
}.bind(this)
);
}
var c = d.prototype;
c.promise = function() {
return this._promise;
};
c.play = function() {
var f = false;
if (this.paused) {
if (this.playbackRate >= 0) {
if (this._canPlayForwards) {
this._forwardsVideo.play();
this._forwardsVideo.style.opacity = "1";
if (this._backwardsVideo) {
this._backwardsVideo.style.opacity = "0";
}
this._paused = false;
f = true;
} else {
this._mediaTimer.play();
this._paused = false;
f = true;
}
} else {
if (this._canPlayBackwards) {
this._backwardsVideo.currentTime =
this._backwardsVideo.duration -
this._mediaTimer.currentTime;
this._backwardsVideo.play();
setTimeout(
function() {
this._forwardsVideo.style.opacity = "0";
this._backwardsVideo.style.opacity = "1";
}.bind(this),
300
);
this._paused = false;
f = true;
} else {
if (this._backwardsVideo) {
this._backwardsVideo.play();
this._backwardsVideo.pause();
if (
this._backwardsVideo.buffered.end(0) ===
this._backwardsVideo.duration
) {
this._canPlayBackwards = true;
this._backwardsVideo.currentTime =
this._backwardsVideo.duration -
this._mediaTimer.currentTime;
}
}
}
}
}
return f;
};
c.pause = function() {
if (this._playbackRate >= 0) {
if (this._canPlayForwards) {
this._forwardsVideo.pause();
this._mediaTimer.currentTime = this._forwardsVideo.currentTime;
if (this._canPlayBackwards) {
this._backwardsVideo.currentTime =
this._backwardsVideo.duration -
this._mediaTimer.currentTime;
}
}
} else {
if (this._canPlayBackwards) {
this._backwardsVideo.pause();
this._mediaTimer.currentTime =
this._backwardsVideo.duration -
this._backwardsVideo.currentTime;
this._forwardsVideo.currentTime = this._mediaTimer.currentTime;
}
}
this._mediaTimer.pause();
this._paused = true;
};
Object.defineProperties(c, {
currentTime: {
get: function() {
if (this._playbackRate >= 0 && this._canPlayForwards) {
return this._forwardsVideo.currentTime;
} else {
if (this._playbackRate < 0 && this._canPlayBackwards) {
return (
this._backwardsVideo.duration -
this._backwardsVideo.currentTime
);
} else {
return this._mediaTimer.currentTime;
}
}
},
set: function(g) {
if (this._paused) {
this._mediaTimer.currentTime = g;
try {
this._forwardsVideo.currentTime = g;
this._forwardsVideo.play();
this._forwardsVideo.pause();
} catch (f) {}
if (this._backwardsVideo) {
try {
this._backwardsVideo.currentTime =
this._backwardsVideo.duration - g;
} catch (f) {}
}
}
}
},
playbackRate: {
get: function() {
return this._playbackRate;
},
set: function(g) {
if (this._paused) {
var f = this.currentTime;
this._playbackRate = g;
this.currentTime = f;
}
}
},
paused: {
get: function() {
return this._paused;
},
set: function() {}
}
});
return d;
}
);
AC.define(
"overview/shared/ClipContainer",
[
"require",
"overview/shared/controller/Clip",
"flow/playerFactory",
"overview/shared/media/TimedVideo",
"overview/shared/media/BiVideo",
"overview/shared/MediaTimer",
"defer/Deferred",
"assetLoader/AssetLoader"
],
function(b) {
var a = b("overview/shared/controller/Clip"),
e = b("flow/playerFactory"),
d = b("overview/shared/media/TimedVideo"),
g = b("overview/shared/media/BiVideo"),
h = b("overview/shared/MediaTimer"),
c = b("defer/Deferred"),
f = b("assetLoader/AssetLoader");
function j(m) {
var k = document.getElementById("stillcontainer");
var l;
for (var n in m) {
if (!k.querySelector(".still_" + n)) {
l = document.createElement("img");
l.src = m[n];
l.alt = "";
l.className = "still still_" + n;
k.appendChild(l);
}
}
}
function i(m, l, k) {
this.containerElement = m;
this.config = l;
this.clips = k;
}
i.prototype.constructor = i;
i.prototype.initFlow = function(l) {
var w = new c();
var k;
var v = "json";
var q = "jpg";
var o = [l.flowKeyFrame, l.flowEndFrame];
var m = l.diffDir;
var r = l.flowPattern || "flow_###.";
var u = m + r + q;
var n = l.manifestFileName || "flow_manifest.";
var p = /^https?:\/\/[^\/]+\//i;
var t = l.manifest.replace(p, "/") + n + v;
if (l.stills) {
j(l.stills, l.stillsDir);
}
k = e(this.containerElement, o, u, t, {
superframes: false,
keyframeCache: false,
benchmark: false
});
k.frameRate = l.fps;
k.loop = false;
k.on("canplaythrough", function(x) {
w.resolve(x);
});
this.mediaElement = k;
return w.promise();
};
i.prototype.initVideo = function(k) {
if (k.stills) {
j(k.stills);
}
this.mediaElement = new d(this.containerElement, k.file, k.poster);
return this.mediaElement.promise();
};
i.prototype.initBiVideo = function(k) {
if (k.stills) {
j(k.stills);
}
this.mediaElement = new g(
this.containerElement,
k.file,
k.backwards,
k.poster,
k.startTime
);
return this.mediaElement.promise();
};
i.prototype.loadExperience = function(k) {
switch (k.type) {
case "bivideo":
return this.initBiVideo(k);
case "video":
return this.initVideo(k);
case "flow":
return this.initFlow(k);
return new c().reject();
}
};
i.prototype.load = function() {
var k = new c(),
l = this.config;
this.loadExperience(l[0]).then(
function() {
k.resolve();
},
function() {