Created
September 12, 2012 19:28
-
-
Save kodi/3709296 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var EarPods360 = AC.Class({ | |
initialize: function (g, i, h, j, l, k) { | |
if (AC.Environment.Feature.supportsCanvas()) { | |
this._element = $(g); | |
this._captions = null; | |
this._showOnScroll = new AC.ShowOnScroll(this._element); | |
this._showOnScroll.setDelegate(this); | |
this._flow = null; | |
this._fps = j; | |
this._scrubRotateDistance = l; | |
this._scrubbable = true; | |
this._scrubDirection = k; | |
AC.Synthesize.synthesize(this); | |
this.setup(i, h) | |
} | |
}, | |
setup: function (g, f) { | |
if (AC.Detector.isiPad()) { | |
if (typeof AC.Detector.isiPadWithGyro() !== "boolean") { | |
var e = this; | |
window.setTimeout(function () { | |
e.setup.apply(e, [g, f]) | |
}, 20) | |
} else { | |
if (AC.Detector.isiPadWithGyro() === true) { | |
this.__setup(g, f) | |
} else { | |
this.setScrubbable(false); | |
this.__setup(g, f) | |
} | |
} | |
} else { | |
if (AC.Detector.isMobile() && window.devicePixelRatio < 1.5) { | |
this.setScrubbable(false); | |
this.__setup(g, f) | |
} else { | |
if (window.navigator && window.navigator.userAgent && window.navigator.userAgent.match(/android/i)) { | |
return | |
} else { | |
var h = AC.Detector.macOSVersion(); | |
if (h && h < 10.7 && h > 10) { | |
this.setScrubbable(false) | |
} else { | |
this.setScrubbable(!window.devicePixelRatio || window.devicePixelRatio < 1.5) | |
} | |
this.__setup(g, f) | |
} | |
} | |
} | |
}, | |
__setup: function (d, e) { | |
this.__hideableElements = []; | |
this.__setupCaptions(AC.Element.selectAll(".caption", this.element()), e); | |
var f = (typeof window.ontouchstart === "undefined" || !this.captions()) ? true : false; | |
this.setFlow(new AC.Flow.VR(this.element(), d, { | |
scrubDirection: this.scrubDirection(), | |
scrubbable: this.scrubbable(), | |
scrubRotateDistance: this.scrubRotateDistance(), | |
autoplay: false, | |
throwable: f, | |
maxThrowDuration: 1, | |
fps: this.fps() | |
})); | |
this.flow().setDelegate(this); | |
AC.Element.addClassName(this.element(), "enhanced"); | |
this.__insertCaptions() | |
}, | |
__setupCaptions: function (e, f) { | |
var h; | |
var g; | |
if (e.length > 0) { | |
this.setCaptions({}) | |
} | |
for (h = 0; h < e.length; h += 1) { | |
if (!isNaN(f[e[h].id])) { | |
g = f[e[h].id]; | |
if (typeof this.captions()[g] === "undefined") { | |
this.captions()[g] = [] | |
} | |
this.captions()[g].push(e[h]); | |
AC.Element.setStyle(e[h], "opacity:0"); | |
e[h].parentNode.removeChild(e[h]) | |
} | |
} | |
}, | |
__insertCaptions: function () { | |
if (!this.captions()) { | |
return false | |
} | |
var c; | |
var d; | |
for (c in this.captions()) { | |
if (this.captions().hasOwnProperty(c) && Array.isArray(this.captions()[c])) { | |
for (d = 0; | |
d < this.captions()[c].length; d += 1) { | |
this.element().appendChild(this.captions()[c][d]); | |
this.__hideableElements.push(this.captions()[c][d]) | |
} | |
} | |
} | |
}, | |
__playToCaption: function () { | |
if (this.__throwDirection) { | |
if (this.scrubbable()) { | |
this.flow().options().scrubbable = false | |
} | |
var h; | |
var i; | |
var l; | |
var m = this.flow().flow().forwards().currentFrame(); | |
var n = this.flow().flow().forwards().framecount() - 1; | |
var k; | |
var j; | |
for (k in this.captions()) { | |
if (this.captions().hasOwnProperty(k)) { | |
k = parseInt(k, 10); | |
j = (k - m) * this.__throwDirection; | |
if (j < 0) { | |
if (this.__throwDirection < 0) { | |
j = m + n - k | |
} else { | |
j = n - m + k | |
} | |
} | |
if (!h || (i && j < i)) { | |
h = k; | |
i = j | |
} | |
} | |
} | |
if (typeof h !== "undefined") { | |
this.flow().play({ | |
direction: this.__throwDirection, | |
toFrame: h, | |
fps: 100, | |
continuous: false | |
}) | |
} | |
} | |
}, | |
scrolledIntoView: function () { | |
if (!this.__hasInteracted && !this.__hasPlayed) { | |
var b = this; | |
window.setTimeout(function () { | |
b.flow().play.call(b.flow()) | |
}, 20); | |
this.__hasPlayed = true | |
} | |
}, | |
visitorEngaged: function () { | |
this.showOnScroll().stopObserving(); | |
this.analytics("engaged") | |
}, | |
onDidPlay: function () { | |
var b = this.flow().flow().forwards().currentFrame(); | |
if (this.__hasInteracted && this.captions() && typeof this.captions()[b] !== "undefined") { | |
if (this.scrubbable()) { | |
this.flow().options().scrubbable = true | |
} | |
this.captions()[b].forEach(function (a) { | |
AC.Element.setStyle(a, "opacity:1") | |
}) | |
} | |
}, | |
onScrubStart: function () { | |
this.analytics("interacted"); | |
this.__hasInteracted = true; | |
if (this.__hideableElements) { | |
this.__hideableElements.forEach(function (b) { | |
AC.Element.setStyle(b, "opacity:0") | |
}) | |
} | |
}, | |
onScrubMove: function (b) { | |
if (!this.captions()) { | |
return false | |
} | |
}, | |
onScrubEnd: function () { | |
if (!this.captions()) { | |
return false | |
} | |
var b = this.flow().__scrubHistory ? this.flow().__scrubHistory.slice(0) : []; | |
if (b.length > 1) { | |
if (b[1] === 0 && b[2]) { | |
b[1] = b[2] | |
} | |
this.__throwDirection = (b[0] - b[1]) > 0 ? this.flow().options().scrubDirection : this.flow().options().scrubDirection * -1 | |
} else { | |
this.__throwDirection = 0 | |
} | |
if (this.flow().options().throwable === false) { | |
this.__playToCaption() | |
} | |
}, | |
onDidThrowStep: function (d) { | |
if (!this.captions()) { | |
return false | |
} | |
if (this.__throwDirection) { | |
d = d.slice(0); | |
var c; | |
if (d.length > 1) { | |
c = (d[0] - d[1]) * this.__throwDirection * -1; | |
if (c < 0) { | |
c = Infinity | |
} | |
} else { | |
c = 0 | |
} | |
if (c <= 5) { | |
this.__playToCaption() | |
} | |
} | |
}, | |
analytics: function (c) { | |
if (typeof this.__didTrack === "undefined") { | |
this.__didTrack = [] | |
} | |
if (this.__didTrack.indexOf(c) < 0) { | |
this.__didTrack.push(c); | |
var d = { | |
prop3: (AC.Tracking.pageName() + " - " + this.element().id + " - " + c) | |
}; | |
AC.Tracking.trackClick(d, this, "o", d.prop3) | |
} | |
} | |
}); | |
var earPods360; | |
Event.onDOMReady(function () { | |
var h = "/v/iphone/shared/earpods-360/a/sequence/"; | |
var i = 18; | |
var g = { | |
"earpod-caption-primary": 65, | |
"earpod-caption-front": 65, | |
"earpod-caption-rear": 166, | |
"earpod-caption-bass": 166 | |
}; | |
var f = 2000; | |
var j = -1; | |
if (typeof window.ontouchstart !== "undefined") { | |
h = "/v/iphone/shared/earpods-360/a/sequence_half/"; | |
i = 9; | |
g = { | |
"earpod-caption-primary": 32, | |
"earpod-caption-front": 32, | |
"earpod-caption-rear": 83, | |
"earpod-caption-bass": 83 | |
}; | |
f = 1000 | |
} else { | |
if (window.devicePixelRatio >= 1.5) { | |
h = "/v/iphone/shared/earpods-360/a/sequence_2x/" | |
} | |
} | |
earPods360 = new EarPods360("animation-earpods", h, g, i, f, j) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment