Skip to content

Instantly share code, notes, and snippets.

@theterg
Created March 31, 2014 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theterg/9893688 to your computer and use it in GitHub Desktop.
Save theterg/9893688 to your computer and use it in GitHub Desktop.
Nike Plus Javascript SDK unminified
/*! Nike+ Javascript SDK - v2.0.0 - Build 67 - 2014-03-24 */
var NIKEPLUS = NIKEPLUS || {};
! function (a) {
"use strict";
var b = {};
b.config = {};
var c;
/**
* @license
* Q - v1.0
* https://github.com/kriskowal/q
*
* Copyright 2009-2012 Kris Kowal under the terms of the MIT
* license found at http://github.com/kriskowal/q/raw/master/LICENSE
*
* With parts by Tyler Close
* Copyright 2007-2009 Tyler Close under the terms of the MIT X license found
* at http://www.opensource.org/licenses/mit-license.html
* Forked at ref_send.js version: 2009-05-11
*
* With parts by Mark Miller
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
! function (a) {
if ("function" == typeof bootstrap) bootstrap("promise", a);
else if ("object" == typeof exports) module.exports = a();
else if ("function" == typeof define && define.amd) define(a);
else if ("undefined" != typeof ses) {
if (!ses.ok()) return;
ses.makeQ = a
} else c = a()
}(function () {
function a(a) {
return function () {
return X.apply(a, arguments)
}
}
function b(a) {
return a === Object(a)
}
function c(a) {
return "[object StopIteration]" === db(a) || a instanceof T
}
function d(a, b) {
if (Q && b.stack && "object" == typeof a && null !== a && a.stack && -1 === a.stack.indexOf(fb)) {
for (var c = [], d = b; d; d = d.source) d.stack && c.unshift(d.stack);
c.unshift(a.stack);
var f = c.join("\n" + fb + "\n");
a.stack = e(f)
}
}
function e(a) {
for (var b = a.split("\n"), c = [], d = 0; d < b.length; ++d) {
var e = b[d];
h(e) || f(e) || !e || c.push(e)
}
return c.join("\n")
}
function f(a) {
return -1 !== a.indexOf("(module.js:") || -1 !== a.indexOf("(node.js:")
}
function g(a) {
var b = /at .+ \((.+):(\d+):(?:\d+)\)$/.exec(a);
if (b) return [b[1], Number(b[2])];
var c = /at ([^ ]+):(\d+):(?:\d+)$/.exec(a);
if (c) return [c[1], Number(c[2])];
var d = /.*@(.+):(\d+)$/.exec(a);
return d ? [d[1], Number(d[2])] : void 0
}
function h(a) {
var b = g(a);
if (!b) return !1;
var c = b[0],
d = b[1];
return c === S && d >= U && kb >= d
}
function i() {
if (Q) try {
throw new Error
} catch (a) {
var b = a.stack.split("\n"),
c = b[0].indexOf("@") > 0 ? b[1] : b[2],
d = g(c);
if (!d) return;
return S = d[0], d[1]
}
}
function j(a, b, c) {
return function () {
return "undefined" != typeof console && "function" == typeof console.warn && console.warn(b + " is deprecated, use " + c + " instead.", new Error("").stack), a.apply(a, arguments)
}
}
function k(a) {
return r(a) ? a : s(a) ? D(a) : C(a)
}
function l() {
function a(a) {
b = a, f.source = a, Z(c, function (b, c) {
W(function () {
a.promiseDispatch.apply(a, c)
})
}, void 0), c = void 0, d = void 0
}
var b, c = [],
d = [],
e = ab(l.prototype),
f = ab(o.prototype);
if (f.promiseDispatch = function (a, e, f) {
var g = Y(arguments);
c ? (c.push(g), "when" === e && f[1] && d.push(f[1])) : W(function () {
b.promiseDispatch.apply(b, g)
})
}, f.valueOf = function () {
if (c) return f;
var a = q(b);
return r(a) && (b = a), a
}, f.inspect = function () {
return b ? b.inspect() : {
state: "pending"
}
}, k.longStackSupport && Q) try {
throw new Error
} catch (g) {
f.stack = g.stack.substring(g.stack.indexOf("\n") + 1)
}
return e.promise = f, e.resolve = function (c) {
b || a(k(c))
}, e.fulfill = function (c) {
b || a(C(c))
}, e.reject = function (c) {
b || a(B(c))
}, e.notify = function (a) {
b || Z(d, function (b, c) {
W(function () {
c(a)
})
}, void 0)
}, e
}
function m(a) {
if ("function" != typeof a) throw new TypeError("resolver must be a function.");
var b = l();
try {
a(b.resolve, b.reject, b.notify)
} catch (c) {
b.reject(c)
}
return b.promise
}
function n(a) {
return m(function (b, c) {
for (var d = 0, e = a.length; e > d; d++) k(a[d]).then(b, c)
})
}
function o(a, b, c) {
void 0 === b && (b = function (a) {
return B(new Error("Promise does not support operation: " + a))
}), void 0 === c && (c = function () {
return {
state: "unknown"
}
});
var d = ab(o.prototype);
if (d.promiseDispatch = function (c, e, f) {
var g;
try {
g = a[e] ? a[e].apply(d, f) : b.call(d, e, f)
} catch (h) {
g = B(h)
}
c && c(g)
}, d.inspect = c, c) {
var e = c();
"rejected" === e.state && (d.exception = e.reason), d.valueOf = function () {
var a = c();
return "pending" === a.state || "rejected" === a.state ? d : a.value
}
}
return d
}
function p(a, b, c, d) {
return k(a).then(b, c, d)
}
function q(a) {
if (r(a)) {
var b = a.inspect();
if ("fulfilled" === b.state) return b.value
}
return a
}
function r(a) {
return b(a) && "function" == typeof a.promiseDispatch && "function" == typeof a.inspect
}
function s(a) {
return b(a) && "function" == typeof a.then
}
function t(a) {
return r(a) && "pending" === a.inspect().state
}
function u(a) {
return !r(a) || "fulfilled" === a.inspect().state
}
function v(a) {
return r(a) && "rejected" === a.inspect().state
}
function w() {
!ib && "undefined" != typeof window && window.console && console.warn("[Q] Unhandled rejection reasons (should be empty):", gb), ib = !0
}
function x() {
for (var a = 0; a < gb.length; a++) {
var b = gb[a];
console.warn("Unhandled rejection reason:", b)
}
}
function y() {
gb.length = 0, hb.length = 0, ib = !1, jb || (jb = !0, "undefined" != typeof process && process.on && process.on("exit", x))
}
function z(a, b) {
jb && (hb.push(a), gb.push(b && "undefined" != typeof b.stack ? b.stack : "(no stack) " + b), w())
}
function A(a) {
if (jb) {
var b = $(hb, a); - 1 !== b && (hb.splice(b, 1), gb.splice(b, 1))
}
}
function B(a) {
var b = o({
when: function (b) {
return b && A(this), b ? b(a) : this
}
}, function () {
return this
}, function () {
return {
state: "rejected",
reason: a
}
});
return z(b, a), b
}
function C(a) {
return o({
when: function () {
return a
},
get: function (b) {
return a[b]
},
set: function (b, c) {
a[b] = c
},
"delete": function (b) {
delete a[b]
},
post: function (b, c) {
return null === b || void 0 === b ? a.apply(void 0, c) : a[b].apply(a, c)
},
apply: function (b, c) {
return a.apply(b, c)
},
keys: function () {
return cb(a)
}
}, void 0, function () {
return {
state: "fulfilled",
value: a
}
})
}
function D(a) {
var b = l();
return W(function () {
try {
a.then(b.resolve, b.reject, b.notify)
} catch (c) {
b.reject(c)
}
}), b.promise
}
function E(a) {
return o({
isDef: function () {}
}, function (b, c) {
return K(a, b, c)
}, function () {
return k(a).inspect()
})
}
function F(a, b, c) {
return k(a).spread(b, c)
}
function G(a) {
return function () {
function b(a, b) {
var g;
if (eb) {
try {
g = d[a](b)
} catch (h) {
return B(h)
}
return g.done ? g.value : p(g.value, e, f)
}
try {
g = d[a](b)
} catch (h) {
return c(h) ? h.value : B(h)
}
return p(g, e, f)
}
var d = a.apply(this, arguments),
e = b.bind(b, "next"),
f = b.bind(b, "throw");
return e()
}
}
function H(a) {
k.done(k.async(a)())
}
function I(a) {
throw new T(a)
}
function J(a) {
return function () {
return F([this, L(arguments)], function (b, c) {
return a.apply(b, c)
})
}
}
function K(a, b, c) {
return k(a).dispatch(b, c)
}
function L(a) {
return p(a, function (a) {
var b = 0,
c = l();
return Z(a, function (d, e, f) {
var g;
r(e) && "fulfilled" === (g = e.inspect()).state ? a[f] = g.value : (++b, p(e, function (d) {
a[f] = d, 0 === --b && c.resolve(a)
}, c.reject, function (a) {
c.notify({
index: f,
value: a
})
}))
}, void 0), 0 === b && c.resolve(a), c.promise
})
}
function M(a) {
return p(a, function (a) {
return a = _(a, k), p(L(_(a, function (a) {
return p(a, V, V)
})), function () {
return a
})
})
}
function N(a) {
return k(a).allSettled()
}
function O(a, b) {
return k(a).then(void 0, void 0, b)
}
function P(a, b) {
return k(a).nodeify(b)
}
var Q = !1;
try {
throw new Error
} catch (R) {
Q = !! R.stack
}
var S, T, U = i(),
V = function () {}, W = function () {
function a() {
for (; b.next;) {
b = b.next;
var c = b.task;
b.task = void 0;
var e = b.domain;
e && (b.domain = void 0, e.enter());
try {
c()
} catch (g) {
if (f) throw e && e.exit(), setTimeout(a, 0), e && e.enter(), g;
setTimeout(function () {
throw g
}, 0)
}
e && e.exit()
}
d = !1
}
var b = {
task: void 0,
next: null
}, c = b,
d = !1,
e = void 0,
f = !1;
if (W = function (a) {
c = c.next = {
task: a,
domain: f && process.domain,
next: null
}, d || (d = !0, e())
}, "undefined" != typeof process && process.nextTick) f = !0, e = function () {
process.nextTick(a)
};
else if ("function" == typeof setImmediate) e = "undefined" != typeof window ? setImmediate.bind(window, a) : function () {
setImmediate(a)
};
else if ("undefined" != typeof MessageChannel) {
var g = new MessageChannel;
g.port1.onmessage = function () {
e = h, g.port1.onmessage = a, a()
};
var h = function () {
g.port2.postMessage(0)
};
e = function () {
setTimeout(a, 0), h()
}
} else e = function () {
setTimeout(a, 0)
};
return W
}(),
X = Function.call,
Y = a(Array.prototype.slice),
Z = a(Array.prototype.reduce || function (a, b) {
var c = 0,
d = this.length;
if (1 === arguments.length)
for (;;) {
if (c in this) {
b = this[c++];
break
}
if (++c >= d) throw new TypeError
}
for (; d > c; c++) c in this && (b = a(b, this[c], c));
return b
}),
$ = a(Array.prototype.indexOf || function (a) {
for (var b = 0; b < this.length; b++)
if (this[b] === a) return b;
return -1
}),
_ = a(Array.prototype.map || function (a, b) {
var c = this,
d = [];
return Z(c, function (e, f, g) {
d.push(a.call(b, f, g, c))
}, void 0), d
}),
ab = Object.create || function (a) {
function b() {}
return b.prototype = a, new b
}, bb = a(Object.prototype.hasOwnProperty),
cb = Object.keys || function (a) {
var b = [];
for (var c in a) bb(a, c) && b.push(c);
return b
}, db = a(Object.prototype.toString);
T = "undefined" != typeof ReturnValue ? ReturnValue : function (a) {
this.value = a
};
var eb;
try {
new Function("(function* (){ yield 1; })"), eb = !0
} catch (R) {
eb = !1
}
var fb = "From previous event:";
k.resolve = k, k.nextTick = W, k.longStackSupport = !1, k.defer = l, l.prototype.makeNodeResolver = function () {
var a = this;
return function (b, c) {
b ? a.reject(b) : a.resolve(arguments.length > 2 ? Y(arguments, 1) : c)
}
}, k.promise = m, k.passByCopy = function (a) {
return a
}, o.prototype.passByCopy = function () {
return this
}, k.join = function (a, b) {
return k(a).join(b)
}, o.prototype.join = function (a) {
return k([this, a]).spread(function (a, b) {
if (a === b) return a;
throw new Error("Can't join: not the same: " + a + " " + b)
})
}, k.race = n, o.prototype.race = function () {
return this.then(k.race)
}, k.makePromise = o, o.prototype.toString = function () {
return "[object Promise]"
}, o.prototype.then = function (a, b, c) {
function e(b) {
try {
return "function" == typeof a ? a(b) : b
} catch (c) {
return B(c)
}
}
function f(a) {
if ("function" == typeof b) {
d(a, h);
try {
return b(a)
} catch (c) {
return B(c)
}
}
return B(a)
}
function g(a) {
return "function" == typeof c ? c(a) : a
}
var h = this,
i = l(),
j = !1;
return W(function () {
h.promiseDispatch(function (a) {
j || (j = !0, i.resolve(e(a)))
}, "when", [
function (a) {
j || (j = !0, i.resolve(f(a)))
}
])
}), h.promiseDispatch(void 0, "when", [void 0,
function (a) {
var b, c = !1;
try {
b = g(a)
} catch (d) {
if (c = !0, !k.onerror) throw d;
k.onerror(d)
}
c || i.notify(b)
}
]), i.promise
}, k.when = p, o.prototype.thenResolve = function (a) {
return this.then(function () {
return a
})
}, k.thenResolve = function (a, b) {
return k(a).thenResolve(b)
}, o.prototype.thenReject = function (a) {
return this.then(function () {
throw a
})
}, k.thenReject = function (a, b) {
return k(a).thenReject(b)
}, k.nearer = q, k.isPromise = r, k.isPromiseAlike = s, k.isPending = t, o.prototype.isPending = function () {
return "pending" === this.inspect().state
}, k.isFulfilled = u, o.prototype.isFulfilled = function () {
return "fulfilled" === this.inspect().state
}, k.isRejected = v, o.prototype.isRejected = function () {
return "rejected" === this.inspect().state
};
var gb = [],
hb = [],
ib = !1,
jb = !0;
k.resetUnhandledRejections = y, k.getUnhandledReasons = function () {
return gb.slice()
}, k.stopUnhandledRejectionTracking = function () {
y(), "undefined" != typeof process && process.on && process.removeListener("exit", x), jb = !1
}, y(), k.reject = B, k.fulfill = C, k.master = E, k.spread = F, o.prototype.spread = function (a, b) {
return this.all().then(function (b) {
return a.apply(void 0, b)
}, b)
}, k.async = G, k.spawn = H, k["return"] = I, k.promised = J, k.dispatch = K, o.prototype.dispatch = function (a, b) {
var c = this,
d = l();
return W(function () {
c.promiseDispatch(d.resolve, a, b)
}), d.promise
}, k.get = function (a, b) {
return k(a).dispatch("get", [b])
}, o.prototype.get = function (a) {
return this.dispatch("get", [a])
}, k.set = function (a, b, c) {
return k(a).dispatch("set", [b, c])
}, o.prototype.set = function (a, b) {
return this.dispatch("set", [a, b])
}, k.del = k["delete"] = function (a, b) {
return k(a).dispatch("delete", [b])
}, o.prototype.del = o.prototype["delete"] = function (a) {
return this.dispatch("delete", [a])
}, k.mapply = k.post = function (a, b, c) {
return k(a).dispatch("post", [b, c])
}, o.prototype.mapply = o.prototype.post = function (a, b) {
return this.dispatch("post", [a, b])
}, k.send = k.mcall = k.invoke = function (a, b) {
return k(a).dispatch("post", [b, Y(arguments, 2)])
}, o.prototype.send = o.prototype.mcall = o.prototype.invoke = function (a) {
return this.dispatch("post", [a, Y(arguments, 1)])
}, k.fapply = function (a, b) {
return k(a).dispatch("apply", [void 0, b])
}, o.prototype.fapply = function (a) {
return this.dispatch("apply", [void 0, a])
}, k["try"] = k.fcall = function (a) {
return k(a).dispatch("apply", [void 0, Y(arguments, 1)])
}, o.prototype.fcall = function () {
return this.dispatch("apply", [void 0, Y(arguments)])
}, k.fbind = function (a) {
var b = k(a),
c = Y(arguments, 1);
return function () {
return b.dispatch("apply", [this, c.concat(Y(arguments))])
}
}, o.prototype.fbind = function () {
var a = this,
b = Y(arguments);
return function () {
return a.dispatch("apply", [this, b.concat(Y(arguments))])
}
}, k.keys = function (a) {
return k(a).dispatch("keys", [])
}, o.prototype.keys = function () {
return this.dispatch("keys", [])
}, k.all = L, o.prototype.all = function () {
return L(this)
}, k.allResolved = j(M, "allResolved", "allSettled"), o.prototype.allResolved = function () {
return M(this)
}, k.allSettled = N, o.prototype.allSettled = function () {
return this.then(function (a) {
return L(_(a, function (a) {
function b() {
return a.inspect()
}
return a = k(a), a.then(b, b)
}))
})
}, k.fail = k["catch"] = function (a, b) {
return k(a).then(void 0, b)
}, o.prototype.fail = o.prototype["catch"] = function (a) {
return this.then(void 0, a)
}, k.progress = O, o.prototype.progress = function (a) {
return this.then(void 0, void 0, a)
}, k.fin = k["finally"] = function (a, b) {
return k(a)["finally"](b)
}, o.prototype.fin = o.prototype["finally"] = function (a) {
return a = k(a), this.then(function (b) {
return a.fcall().then(function () {
return b
})
}, function (b) {
return a.fcall().then(function () {
throw b
})
})
}, k.done = function (a, b, c, d) {
return k(a).done(b, c, d)
}, o.prototype.done = function (a, b, c) {
var e = function (a) {
W(function () {
if (d(a, f), !k.onerror) throw a;
k.onerror(a)
})
}, f = a || b || c ? this.then(a, b, c) : this;
"object" == typeof process && process && process.domain && (e = process.domain.bind(e)), f.then(void 0, e)
}, k.timeout = function (a, b, c) {
return k(a).timeout(b, c)
}, o.prototype.timeout = function (a, b) {
var c = l(),
d = setTimeout(function () {
c.reject(new Error(b || "Timed out after " + a + " ms"))
}, a);
return this.then(function (a) {
clearTimeout(d), c.resolve(a)
}, function (a) {
clearTimeout(d), c.reject(a)
}, c.notify), c.promise
}, k.delay = function (a, b) {
return void 0 === b && (b = a, a = void 0), k(a).delay(b)
}, o.prototype.delay = function (a) {
return this.then(function (b) {
var c = l();
return setTimeout(function () {
c.resolve(b)
}, a), c.promise
})
}, k.nfapply = function (a, b) {
return k(a).nfapply(b)
}, o.prototype.nfapply = function (a) {
var b = l(),
c = Y(a);
return c.push(b.makeNodeResolver()), this.fapply(c).fail(b.reject), b.promise
}, k.nfcall = function (a) {
var b = Y(arguments, 1);
return k(a).nfapply(b)
}, o.prototype.nfcall = function () {
var a = Y(arguments),
b = l();
return a.push(b.makeNodeResolver()), this.fapply(a).fail(b.reject), b.promise
}, k.nfbind = k.denodeify = function (a) {
var b = Y(arguments, 1);
return function () {
var c = b.concat(Y(arguments)),
d = l();
return c.push(d.makeNodeResolver()), k(a).fapply(c).fail(d.reject), d.promise
}
}, o.prototype.nfbind = o.prototype.denodeify = function () {
var a = Y(arguments);
return a.unshift(this), k.denodeify.apply(void 0, a)
}, k.nbind = function (a, b) {
var c = Y(arguments, 2);
return function () {
function d() {
return a.apply(b, arguments)
}
var e = c.concat(Y(arguments)),
f = l();
return e.push(f.makeNodeResolver()), k(d).fapply(e).fail(f.reject), f.promise
}
}, o.prototype.nbind = function () {
var a = Y(arguments, 0);
return a.unshift(this), k.nbind.apply(void 0, a)
}, k.nmapply = k.npost = function (a, b, c) {
return k(a).npost(b, c)
}, o.prototype.nmapply = o.prototype.npost = function (a, b) {
var c = Y(b || []),
d = l();
return c.push(d.makeNodeResolver()), this.dispatch("post", [a, c]).fail(d.reject), d.promise
}, k.nsend = k.nmcall = k.ninvoke = function (a, b) {
var c = Y(arguments, 2),
d = l();
return c.push(d.makeNodeResolver()), k(a).dispatch("post", [b, c]).fail(d.reject), d.promise
}, o.prototype.nsend = o.prototype.nmcall = o.prototype.ninvoke = function (a) {
var b = Y(arguments, 1),
c = l();
return b.push(c.makeNodeResolver()), this.dispatch("post", [a, b]).fail(c.reject), c.promise
}, k.nodeify = P, o.prototype.nodeify = function (a) {
return a ? void this.then(function (b) {
W(function () {
a(null, b)
})
}, function (b) {
W(function () {
a(b)
})
}) : this
};
var kb = i();
return k
}), c.stopUnhandledRejectionTracking(), b.utils = function () {
function a(a) {
return x.hasOwnProperty(a) ? x[a] : x.unknown
}
function d(a, b) {
var c = !1,
d = a || navigator.appName,
e = b || navigator.userAgent,
f = new RegExp("MSIE ([0-9]{1,}[\\.0-9]{0,})");
return "Microsoft Internet Explorer" === d && null !== f.exec(e) && (c = parseFloat(RegExp.$1)), c
}
function e(a) {
return "[object Date]" === Object.prototype.toString.call(a) || a instanceof Date
}
function f(a) {
return "[object Array]" === Object.prototype.toString.call(a)
}
function g(a) {
return !!a && "[object Object]" === Object.prototype.toString.call(a)
}
function h(a, b) {
return l(a, b) > -1
}
function i(a, b, c) {
return a ? void("object" == typeof window.attachEvent ? a.attachEvent("on" + b, c) : a.addEventListener(b, c, !1)) : !1
}
function j(a, b, c) {
"object" == typeof window.detachEvent ? a.detachEvent("on" + b, c) : a.removeEventListener(b, c, !1)
}
function k(a, b, c) {
var d, e, f = c ? b : b.slice(0),
g = /\{\}/;
return f.length ? (e = f.shift(), d = a.replace(g, e), k(d, f, !0)) : a
}
function l(a, b, c) {
var d, e = 0;
if (!a) return -1;
if (d = a.length, Array.prototype.indexOf && a.indexOf === Array.prototype.indexOf) return a.indexOf(b, c);
for ("number" == typeof c && (e = 0 > c ? Math.max(0, d + c) : c); d > e; e++)
if (a[e] === b) return e;
return -1
}
function m(a, b) {
var c;
if (g(a))
for (var d in a)
if (a.hasOwnProperty(d) && (c = b.call(a[d], d, a[d]), c === !1)) break;
if (f(a))
for (var e = 0, h = a.length; h > e && (c = b.call(a[e], e, a[e]), c !== !1); e++);
return a
}
function n(a, b) {
var d, e = !1,
f = c.defer();
if (document.getElementById(a)) return f.reject(new Error("iFrame with that ID already exists.")), f.promise;
if (y) {
var g = "",
h = document.createElement("div");
g += "<iframe ", g += 'name="' + a + '" ', g += 'id="' + a + '" ', g += 'src="' + b + '" ', g += 'style="display: none;"></iframe>', h.innerHTML = g, document.body && document.body.appendChild(h), d = document.getElementById(a)
} else d = document.createElement("iframe"), d.setAttribute("name", a), d.id = a, d.setAttribute("src", b), d.style.display = "none", document.body && document.body.appendChild(d);
return i(d, "load", function () {
e = !0, f.resolve(d)
}), o(function () {
return e
}, 100, 20).then(function () {}, function () {
f.reject()
}), f.promise
}
function o(a, b, d) {
function e() {
if (g++, g > d) return h.reject(), !1;
var c = a();
c ? (clearTimeout(f), h.resolve(c)) : f = setTimeout(e, b)
}
var f, g = 0,
h = c.defer();
return e(), h.promise
}
function p(a) {
for (var b = "", c = 0, d = "abcdefghijklmnopqrstuvwxyz0123456789".split(""), e = d.length; a > c;) b += d[Math.floor(Math.random() * e)], c++;
return b
}
function q(a) {
var c = a || window.location.search || "",
d = c.replace("?", "");
return b.utils.deserialize(d)
}
function r(a, c) {
return b.utils.getQueryParams(c)[a]
}
function s(a) {
var c = a || window.location.hash || "",
d = c.replace("#", "");
return b.utils.deserialize(d)
}
function t(a, c) {
return b.utils.getHashParams(c)[a]
}
function u(a) {
if ("string" != typeof a) throw new Error("Deserialize only accepts string arguments");
var c = a.split("&"),
d = {};
return b.utils.each(c, function (a, b) {
var c = b.split("="),
e = c.length > 0 ? decodeURIComponent(c[0]) : "",
f = c.length > 1 ? decodeURIComponent(c[1]) : "";
d[e] = f
}), d
}
function v(a) {
var c, d = "";
if ("string" == typeof a) d = a;
else if (b.utils.isObject(a)) {
for (c in a)!a.hasOwnProperty(c) || "string" != typeof a[c] && "number" != typeof a[c] || (d += "&" + encodeURIComponent(c) + "=" + encodeURIComponent(a[c]));
d.length && (d = d.substring(1))
}
return d.length ? d : null
}
function w(a, c) {
var d = b.utils.serialize(c),
e = a.indexOf("?") > -1 ? "&" : "?";
return d ? a + e + d : a
}
var x = {
noToken: {
requestId: "sdk",
errors: [{
code: 1001,
message: "There is no access token"
}]
},
expiredToken: {
requestId: "sdk",
errors: [{
code: 1002,
message: "The access token expired"
}]
},
timeout: {
requestId: "sdk",
errors: [{
code: 1010,
message: "Cross domain communications timed out"
}]
},
unknown: {
requestId: "sdk",
errors: [{
code: 1099,
message: "undefined error"
}]
}
}, y = d();
return {
getErrorObject: a,
isDate: e,
isArray: f,
isObject: g,
inArray: h,
addListener: i,
removeListener: j,
each: m,
buildUrl: w,
indexOf: l,
replaceTokensInTextFromArray: k,
isIE: function () {
return y
},
createIFrame: n,
generateRandomString: p,
pollCondition: o,
getQueryParams: q,
getQueryParam: r,
getHashParams: s,
getHashParam: t,
deserialize: u,
serialize: v
}
}(), b.logging = function () {
function a() {
if (window.console && window.console.log) {
var a = Array.prototype.slice.call(arguments),
c = b.utils.inArray(n, a[0]) && console[a[0]] ? a[0] : "log",
d = a;
(b.utils.inArray(n, c) || "debug" === a[0]) && (d = d.slice(1)), d = 1 === d.length ? d[0] : d, console[c](d)
}
}
function c(a) {
var b = {};
if (!a.length) throw {
name: "InvalidArgumentError",
message: "An invalid argument was passed."
};
if ("string" != typeof a[0]) throw {
name: "InvalidArgumentError",
message: "An invalid argument was passed."
};
return b.message = a.shift(), b.values = a, b
}
function d(a, c) {
if ("string" != typeof a || "string" != typeof c) throw {
name: "InvalidArgumentError",
message: "An invalid argument was passed."
};
switch (o.push({
level: a,
message: c
}), a) {
case "error":
b.logging.consoleLog(a, a + " - " + c);
break;
case "warn":
b.logging.consoleLog(a, a + " - " + c);
break;
case "info":
m && b.logging.consoleLog(a, a + " - " + c);
break;
case "debug":
m && b.logging.consoleLog(a, a + " - " + c)
}
}
function e() {
var a = c(Array.prototype.slice.call(arguments)),
d = b.utils.replaceTokensInTextFromArray(a.message, a.values);
b.logging.log("error", d)
}
function f() {
var a = c(Array.prototype.slice.call(arguments)),
d = b.utils.replaceTokensInTextFromArray(a.message, a.values);
b.logging.log("warn", d)
}
function g() {
var a = c(Array.prototype.slice.call(arguments)),
d = b.utils.replaceTokensInTextFromArray(a.message, a.values);
b.logging.log("info", d)
}
function h() {
var a = c(Array.prototype.slice.call(arguments)),
d = b.utils.replaceTokensInTextFromArray(a.message, a.values);
b.logging.log("debug", d)
}
function i() {
return o.slice(0)
}
function j() {
o = []
}
function k(a) {
m = a
}
function l() {
return m
}
var m = !1,
n = ["error", "warn", "info"],
o = [];
return {
log: d,
consoleLog: a,
error: e,
warn: f,
info: g,
debug: h,
getHistory: i,
clearHistory: j,
setDebug: k,
getDebug: l,
parseLogArguments: c
}
}(), b.storage = function () {
function a() {
var a = "nike";
try {
return localStorage.setItem(a, a), localStorage.removeItem(a), !0
} catch (b) {
return !1
}
}
function c() {
b.logging.error("This browser does not support local storage.")
}
function d(a, b) {
i = "", a && (i += a + "_"), b && (i += b + "_")
}
function e(a, b) {
return h ? window.localStorage.setItem(i + a, b) : void c()
}
function f(a) {
return h ? window.localStorage.getItem(i + a) : void c()
}
function g(a) {
return h ? window.localStorage.removeItem(i + a) : void c()
}
var h = a(),
i = "";
return {
setSitePrefix: d,
set: e,
remove: g,
get: f
}
}(), b.xhr = function () {
function a() {
if (window.ActiveXObject) try {
return new window.ActiveXObject("Microsoft.XMLHTTP")
} catch (a) {} else try {
return new window.XMLHttpRequest
} catch (a) {}
}
function d(d) {
d = d && b.utils.isObject(d) ? d : {};
var e = c.defer(),
f = d.url,
g = d.method || "GET",
h = !/^(?:GET|HEAD)$/.test(g),
i = d.data && b.utils.isObject(d.data) ? d.data : {}, j = d.headers && b.utils.isObject(d.headers) ? d.headers : {}, k = "boolean" == typeof d.cache ? d.cache : !0,
l = a();
return l ? (h || (k || (i._ = (new Date).getTime()), f = b.utils.buildUrl(f, i)), l.open(g, f, !0), b.utils.each(j, function (a, b) {
l.setRequestHeader(a, b)
}), "POST" !== g.toUpperCase() || j["Content-Type"] || l.setRequestHeader("Content-Type", "application/json; charset=UTF-8"), l.onreadystatechange = function () {
4 === l.readyState && (/^2\d\d$/.test(l.status) || 304 === l.status ? e.resolve(JSON.parse(l.responseText)) : e.reject(JSON.parse(l.responseText)), l.onreadystatechange = function () {})
}, l.send(h && b.utils.serialize(i) || null), e.promise) : void b.logging.error("This browser does not support XMLHttpRequest.")
}
return {
send: d
}
}(), b.session = function () {
function a(a) {
if (b.utils.isObject(a)) {
if (a.data.access_token && !a.data.expires_in) return void b.logging.error("Can not provide an access token without an expires_in property.");
if (a.data.access_token && a.data.expires_in && isNaN(a.data.expires_in)) return void b.logging.error("Can not provide an access token with a non numeric expires_in property.");
if (a.data.access_token && a.data.expires_in && parseInt(a.data.expires_in, 10) > 10800) return void b.logging.error("Can not provide an access token with an expires_in value greater than 10800 seconds.");
var c, d = {};
return b.utils.each(g, function (e, f) {
var g = a.data[f];
g ? ("expires_in" === f && (g = parseInt(g, 10), c = g > 10800 ? 10800 : g, b.storage.set("token_expires", 1e3 * parseInt(c, 10) + (new Date).getTime())), b.storage.set(f, g)) : b.storage.set(f, ""), d[f] = b.storage.get(f)
}), a.data.state && (d.state = a.data.state), d
}
}
function c() {
var a, c = {}, d = b.session.validateToken();
switch (c.status = d, d) {
case "validToken":
c.authData = {}, b.utils.each(g, function (d, e) {
a = b.storage.get(e), a && ("expires_in" === e ? c.authData.expires_in = parseInt(b.session.resetExpiresTime() / 1e3, 10) : c.authData[e] = a)
})
}
return c
}
function d() {
if ("validToken" !== b.session.validateToken()) return !1;
var a, c = parseInt(b.storage.get("token_expires"), 10),
d = (new Date).getTime();
return c ? (a = c - d, b.storage.set("expires_in", a), a) : !1
}
function e() {
var a = b.storage.get("access_token"),
c = b.storage.get("token_expires"),
d = (new Date).getTime();
return a ? d > parseInt(c, 10) ? (b.session.clear(), "expiredToken") : "validToken" : "noToken"
}
function f() {
b.utils.each(g, function (a, c) {
b.storage.remove(c)
}), b.storage.remove("token_expires")
}
var g = ["access_token", "expires_in", "profile_img_url", "token_type", "user_id"];
return {
setupAuth: a,
clear: f,
getAuthData: c,
resetExpiresTime: d,
validateToken: e
}
}(), b.events = function () {
function a() {
this.listeners = {}
}
return a.prototype = {
addListener: function (a, c) {
if ("function" != typeof c) return void b.logging.warn("You did not provide a callback to subscribe to {}.", a);
var d = this.listeners;
"undefined" == typeof d[a] && (d[a] = []), d[a].push(c)
},
removeListener: function (a, c) {
var d = this.listeners;
if ("undefined" === d[a] || !b.utils.isArray(d[a])) return b.logging.warn("There are no listeners registered for {}.", a), this;
if ("undefined" != typeof c) {
var e = b.utils.indexOf(d[a], c);
e > -1 && d[a].splice(e, 1)
} else delete this.listeners[a];
return this
},
getListeners: function (a) {
return this.listeners[a] || []
},
trigger: function (a, c) {
var d = this.listeners[a] || [],
e = this;
b.utils.each(d, function (a, b) {
"function" == typeof b && b.apply(e, c || [])
})
}
}, {
Events: a
}
}(), b.internalEvents = new b.events.Events, b.externalEvents = new b.events.Events, b.auth = function () {
function a(a) {
var c, d = a || document.getElementsByTagName("body")[0] || document.createElement("div"),
e = document.createElement("img");
e.setAttribute("src", "https://www.nike.com/profile/assets/oauth/img/nikeoauth.png"), e.setAttribute("id", "nikeoauth-button"), e.style.cursor = "pointer", b.init.getConfig("oauthPopup") ? (d.appendChild(e), b.utils.addListener(e, "click", b.auth.launch)) : (c = document.createElement("a"), c.setAttribute("href", b.auth.getOauthUrl()), c.appendChild(e), d.appendChild(c))
}
function c() {
var a = {
client_id: b.init.getConfig("client_id"),
response_type: b.init.getConfig("response_type")
};
return b.init.getConfig("redirect_uri") && (a.redirect_uri = b.init.getConfig("redirect_uri")), b.init.getConfig("state") && (a.state = b.init.getConfig("state")), b.init.getConfig("locale") && (a.locale = b.init.getConfig("locale")), b.utils.buildUrl(b.init.getConfig("oauthEndpoint"), a)
}
function d() {
var a = b.utils.getHashParams();
return a && a.error && a.errorDescription && "token" === b.init.getConfig("response_type") ? "error" : a && a.access_token && "token" === b.init.getConfig("response_type") ? "success" : null
}
function e() {
var a = b.auth.getOauthUrl(),
c = window.open(a, "nikeoauth", "status=1,width=664,height=750,scrollbars=1");
return c
}
function f() {
b.xdcomms.send({
action: "logout"
})
}
function g(a) {
a = "function" == typeof a ? a : function () {}, b.xdcomms.send({
action: "getAuthData",
callback: a
})
}
function h(a, c) {
c = "function" == typeof c ? c : function () {}, b.xdcomms.send({
action: "setupAuth",
data: a,
callback: c
})
}
function i() {
var a = b.utils.getHashParams();
b.xdcomms.send({
action: "setupAuth",
data: a,
callback: b.init.getConfig("authSuccess")
})
}
function j() {
var a = b.utils.getHashParams();
b.init.getConfig("authError")(a)
}
function k(a) {
switch (a) {
case "noToken":
b.externalEvents.trigger("auth.noToken", [{
reason: "no token"
}]);
break;
case "expiredToken":
b.externalEvents.trigger("auth.expiredToken"), b.externalEvents.trigger("auth.noToken", [{
reason: "expired token"
}])
}
}
return {
launch: e,
login: a,
logout: f,
getOauthRedirect: d,
getOauthUrl: c,
getAuthData: g,
setAuthData: h,
finishSuccessfulAuth: i,
finishErrorAuth: j,
fireNoTokenEvents: k
}
}(), b.xdcomms = function () {
function a(a, c) {
r = a, "sender" === a && (b.utils.addListener(window, "message", b.xdcomms.senderMessageHandler), t = c, t || b.logging.error("Cross domain communications are not set up correctly.")), "receiver" === a && b.utils.addListener(window, "message", b.xdcomms.receiverMessageHandler)
}
function d() {
return r
}
function e(a) {
return 0 === a.indexOf(u)
}
function f(a) {
return JSON.parse(a.replace(u, ""))
}
function g(a, b, c) {
var d = {
action: a,
messageId: b,
data: c
};
return u + JSON.stringify(d)
}
function h(a) {
var c, d, e = a.messageId || b.utils.generateRandomString(40);
c = b.utils.isObject(a.data) ? a.data : {}, c.clientIdPrefix = b.init.getConfig("client_id"), c.sitePrefix = b.init.getConfig("sitePrefix"), d = b.xdcomms.createMessage(a.action, e, c), b.xdcomms.establishCommunications().then(function () {
b.xdcomms.postMessage(t.contentWindow, d, b.init.getConfig("xdCommDomain")), b.utils.pollCondition(function () {
return b.xdcomms.getResponse(e)
}, 100, 200).then(function (b) {
b.apiError ? (delete b.apiError, "function" == typeof a.error && a.error(b)) : "function" == typeof a.callback && a.callback(b)
}, function () {
"function" == typeof a.error && a.error(b.utils.getErrorObject("timeout"))
})
}, function () {
b.logging.error("SDK communication failed.")
})
}
function i(a) {
var c = a.data;
e(c) && (c = f(c), c && b.xdcomms.processMessageResponse(c).then(function (a) {
b.xdcomms.setResponse(c.messageId, a)
}, function () {}))
}
function j(a) {
var d = c.defer();
switch (a.action) {
case "apiCall":
d.resolve(a.data), b.externalEvents.trigger("api.response", [a.data]);
break;
case "apiCall_error":
b.externalEvents.trigger("api.error", [a.data]), a.data.error && b.auth.fireNoTokenEvents(a.data.error), a.data.apiError = !0, d.resolve(a.data);
break;
case "setupSDK":
b.xdcomms.setSDKReady(), d.resolve(a);
break;
case "setupAuth":
d.resolve(a.data);
break;
case "logout":
b.externalEvents.trigger("auth.logout"), d.resolve(a);
break;
case "getAuthData":
b.auth.fireNoTokenEvents(a.data.status), d.resolve(a.data);
break;
default:
d.reject(new Error("unrecognized action"))
}
return d.promise
}
function k(a) {
var c = a.data,
d = b.utils.isIE();
e(c) && (c = f(c), c && b.xdcomms.processReceivedMessage(c).then(function (c) {
var e = b.xdcomms.createMessage(c.action, c.messageId, c.data);
d && 9 > d ? b.xdcomms.postMessage(window.parent, e, "*") : b.xdcomms.postMessage(a.source, e, a.origin)
}, function (c) {
var e = b.xdcomms.createMessage(c.action + "_error", c.messageId, c.data);
d && 9 > d ? b.xdcomms.postMessage(window.parent, e, "*") : b.xdcomms.postMessage(a.source, e, a.origin)
}))
}
function l(a) {
var d = c.defer(),
e = {
action: a.action,
messageId: a.messageId
};
switch (a.data && (a.data.clientIdPrefix || a.data.sitePrefix) && b.storage.setSitePrefix(a.data.sitePrefix, a.data.clientIdPrefix), a.action) {
case "apiCall":
b.api.request(a.data).then(function (a) {
e.data = a, d.resolve(e)
}, function (a) {
e.data = a, d.reject(e)
});
break;
case "setupSDK":
b.logging.setDebug(a.data.debug), d.resolve(a);
break;
case "setupAuth":
e.data = b.session.setupAuth(a), d.resolve(e);
break;
case "logout":
e.data = b.session.clear(), d.resolve(e);
break;
case "getAuthData":
e.data = b.session.getAuthData(), d.resolve(e);
break;
default:
d.reject(new Error("unrecognized action"))
}
return d.promise
}
function m(a, b, c) {
window.setTimeout(function () {
a.postMessage(b, c)
}, 0)
}
function n() {
return b.utils.pollCondition(function () {
if (s) return s;
if (t) {
var a = b.utils.generateRandomString(40),
c = g("setupSDK", a, {
debug: b.init.getConfig("debug")
});
b.xdcomms.postMessage(t.contentWindow, c, b.init.getConfig("xdCommDomain"))
}
return s
}, 100, 20)
}
function o(a) {
"dev" === b.environment && "undefined" != typeof a ? s = a : s || (s = !0)
}
function p(a) {
return v[a]
}
function q(a, b) {
v[a] = b
}
var r, s, t, u = "NIKEPLUSJSSDK:",
v = {};
return {
setSDKReady: o,
getResponse: p,
setResponse: q,
setCommRole: a,
getCommRole: d,
send: h,
senderMessageHandler: i,
receiverMessageHandler: k,
validateMessage: e,
createMessage: g,
parseMessage: f,
processMessageResponse: j,
processReceivedMessage: l,
postMessage: m,
establishCommunications: n
}
}(), b.api = function () {
function a(a, c) {
var d, e, f, g = ["method", "cache"];
c = b.utils.isObject(c) ? c : {}, f = b.utils.isObject(c.data) ? c.data : {}, f.endpoint = a, b.utils.each(g, function (a, b) {
"undefined" != typeof c[b] && (f[b] = c[b])
}), e = "function" == typeof c.success ? c.success : function () {}, d = "function" == typeof c.error ? c.error : function () {}, b.xdcomms.send({
action: "apiCall",
data: f,
callback: e,
error: d
})
}
function d(a) {
var d = a.endpoint,
e = ["clientIdPrefix", "endpoint", "method", "sitePrefix", "cache", "access_token"],
f = a.method || "GET",
g = "boolean" == typeof a.cache ? a.cache : !0,
h = c.defer(),
i = b.session.validateToken();
switch (i) {
case "noToken":
h.reject(b.utils.getErrorObject("noToken"));
break;
case "expiredToken":
h.reject(b.utils.getErrorObject("expiredToken"));
break;
case "validToken":
b.utils.each(e, function (b, c) {
"undefined" != typeof a[c] && delete a[c]
}), a.access_token = b.storage.get("access_token"), b.xhr.send({
url: d,
cache: g,
data: a,
method: f,
headers: {
Accept: "application/json"
}
}).then(h.resolve, h.reject)
}
return h.promise
}
return {
request: d,
api: a
}
}(), b.sdkinit = function () {
function a() {
b.xdcomms.setCommRole("receiver")
}
return {
handleDOMReady: a
}
}(), b.init = function () {
function a(a) {
var c = a || {}, d = !0;
return b.environment = c.environment && "dev" === c.environment ? "dev" : "prod", c.mode && "receiver" === c.mode ? void b.sdkinit.handleDOMReady() : (b.utils.each(i, function (a, e) {
j[a] = e.devOnlyChange ? "dev" === b.environment && c[a] ? c[a] : e.value : c[a] || e.value, "" === j[a] && e.required && (b.logging.error("Please enter a value for the {} setting.", a), d = !1), e.type && typeof j[a] !== e.type && b.logging.warn("The {} setting has a type of {}, but it should be a {}.", a, typeof j[a], e.type)
}), void(d && (b.logging.setDebug(j.debug), b.utils.createIFrame("nike_jssdk_xdm", j.sdkFrameUrl).then(function (a) {
j.commIFrameLoaded = !0, h = a, b.xdcomms.setCommRole("sender", h)
}), b.logging.debug("API Init has succeeded with the following config: {}", JSON.stringify(j)))))
}
function c() {
"undefined" != typeof window.nikeplusSDKAsyncInit && setTimeout(function () {
window.nikeplusSDKAsyncInit();
var a = b.auth.getOauthRedirect();
switch (a) {
case "success":
b.auth.finishSuccessfulAuth();
break;
case "error":
b.auth.finishErrorAuth()
}
}, 0)
}
function d(a) {
return j[a]
}
function e(a, b) {
j[a] = b
}
function f() {
b.utils.removeListener(document, "DOMContentLoaded", f), b.utils.removeListener(window, "load", f), c()
}
function g() {
"complete" === document.readyState ? c() : (b.utils.addListener(document, "DOMContentLoaded", f), b.utils.addListener(window, "load", f))
}
var h, i = {
sitePrefix: {
value: ""
},
client_id: {
value: "",
required: !0
},
locale: {
value: "en_US",
required: !0
},
oauthEndpoint: {
value: "https://api.nike.com/oauth/2.0/authorize",
devOnlyChange: !0
},
sdkFrameUrl: {
value: "https://api.nike.com/nikeplus/js/v2/iframe.html",
devOnlyChange: !0
},
xdCommDomain: {
value: "https://api.nike.com",
devOnlyChange: !0
},
debug: {
value: !1,
type: "boolean",
devOnlyChange: !0
},
oauthPopup: {
value: !1
},
state: {
value: ""
},
response_type: {
value: "token"
},
redirect_uri: {
value: "",
required: !0
},
authSuccess: {
value: function () {},
type: "function"
},
authError: {
value: function () {},
type: "function"
}
}, j = {};
return {
init: a,
getConfig: d,
setConfig: e,
handleDOMReady: g
}
}(), b.init.handleDOMReady(), a.api = function (a, c) {
b.api.api(a, c)
}, a.login = function (a) {
b.auth.login(a)
}, a.logout = function () {
b.auth.logout()
}, a.getAuthData = function (a) {
b.auth.getAuthData(a)
}, a.setAuthData = function (a, c) {
b.auth.setAuthData(a, c)
}, a.events = {
subscribe: function (a, c) {
b.externalEvents.addListener(a, c)
},
unsubscribe: function (a, c) {
b.externalEvents.removeListener(a, c)
}
}, a.init = function (a) {
b.init.init(a)
}
}(NIKEPLUS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment