Skip to content

Instantly share code, notes, and snippets.

@sbdchd
Created Jul 15, 2022
Embed
What would you like to do?
flickr js stuff
(() => {
var e,
r = Object.defineProperty,
t =
((e = function (e) {
if ("undefined" != typeof require)
return require.apply(this, arguments);
throw new Error('Dynamic require of "' + e + '" is not supported');
}),
"undefined" != typeof require
? require
: "undefined" != typeof Proxy
? new Proxy(e, {
get: (e, r) => ("undefined" != typeof require ? require : e)[r],
})
: e),
n = (e, r) => () => (r || e((r = { exports: {} }).exports, r), r.exports),
i = (e, t, n) => (
((e, t, n) => {
t in e
? r(e, t, {
enumerable: !0,
configurable: !0,
writable: !0,
value: n,
})
: (e[t] = n);
})(e, "symbol" != typeof t ? t + "" : t, n),
n
),
o = n((e, r) => {
r.exports = window.YUI_config.flickr;
}),
a = n((e, r) => {
r.exports = function () {
return function (e, r, t) {
var n;
for (n in e.params) e.params[n] = e.params[n][0];
t();
};
};
}),
s = n((e, r) => {
var n = t("hermes-core/type-validator");
r.exports = function (e) {
return function (r, t, i) {
var o = r.params[e];
if (!o || "string" != typeof o) return i();
n.nsid(o) || (r.params[e] = String(o).toLowerCase()), i();
};
};
}),
c = n((e, r) => {
r.exports = function () {
return function (e, r, t) {
e.params instanceof Array && e.params.shift(), t();
};
};
}),
u = n((e, r) => {
r.exports = function (e) {
return function (r, t, n) {
"object" == typeof r.appContext
? ((r.appContext.routeConfig = e), n())
: n(new Error("appContext is undefined"));
};
};
}),
l = n((e, r) => {
o(), t("hermes-core/flog")("bounce-route");
r.exports = function (e, r) {
return function (e, r, t) {
t();
};
};
}),
d = n((e, r) => {
r.exports = function () {
return function (e, r, t) {
t();
};
};
}),
p = n((e, r) => {
var n = t("hermes-core/flog")("flickr-router");
r.exports = function (e, r, t) {
var i,
o = this;
return t.redirect
? ((window.location = t.redirect), Promise.resolve())
: ((document.title = t.title),
o.onRender(),
e.appContext
.getView(t.view, t.params, t.layout)
.then(function (r) {
return (
o.onViewLoaded(),
(i = r)._params &&
(i._params.keyEventScope = i.name + i._yuid),
e.appContext
.getKeyboardManager()
.setCurrentKeyEventScope(i.name + i._yuid),
i.set("isRootView", !0),
i.initialize()
);
})
.then(function () {
var r, n;
o.onViewInitialized(),
(n = (n = (n = (r =
document.querySelector("html")).className.trim()).replace(
/html-[\S]+-view/,
"html-" + t.view
)).replace(/[\S]+-layout/, t.layout + "-layout")),
(r.className = n),
e.transactionId === o.currentTransactionId &&
o.app.showView(i, null, {
render: !0,
callback: function (r) {
o.onFinished(),
"popstate" !== e.src && window.scroll(0, 0);
},
});
})
.catch(function (e) {
throw (n.error("Render had an error", { err: e }), e);
}));
};
}),
f = n((e, r) => {
r.exports = (e) => Promise.resolve(null);
}),
g = n((e, r) => {
var n = t("hermes-core/flog")("flickr-router"),
g = t("hermes-core/fletrics"),
w = o(),
h = a(),
m = s(),
v = c(),
y = u(),
C = l(),
b = d(),
S = p(),
k = f();
r.exports = class {
constructor(e, r, t = {}) {
i(this, "render", S),
(this.app = e),
this.setupRoutes(r),
(this.onRender = t.onRender || function () {}),
(this.onViewLoaded = t.onViewLoaded || function () {}),
(this.onViewInitialized = t.onViewInitialized || function () {}),
(this.onFinished = t.onFinished || function () {});
}
setupRoutes(e) {
var r, t, n, i, o;
for (n in e.patterns)
this.registerParam(n, new RegExp(e.patterns[n]));
for (r = 0; r < e.routes.length; r++)
if ((i = e.routes[r]).path instanceof Array)
for (t = 0; t < i.path.length; t++) {
for (n in ((o = {}), i)) "path" !== n && (o[n] = i[n]);
(o.path = i.path[t]), this.registerRoute(o);
}
else this.registerRoute(i);
}
registerParam(e, r) {
this.app.param(e, r);
}
registerRoute(e) {
var r = this;
this.route(e, [
function (e, r, t) {
"appContext" in window
? (e.appContext = window.appContext)
: window.beaconError &&
window.beaconError(
"[flickr-router] No appcontext.",
window.location.href
),
t();
},
h(),
m("nsid_or_path_alias"),
v(),
y(e),
C(e, r),
b(e),
function (e, r, t) {
Object.assign(e, w.request), t();
},
function (t, n, i) {
r._processRequest(e, t, n, i);
},
]);
}
route(e, r) {
var t = [];
return (
t.push(e.path), (t = t.concat(r)), this.app.route.apply(this.app, t)
);
}
_processRequest(e, r, t, n) {
var i = this;
(r.transactionId = Date.now() + "" + Math.random()),
(this.currentTransactionId = r.transactionId),
(r.appContext.startTime = Date.now()),
r.appContext
.getRoute(e.module)
.then(function (e) {
var n;
return (
(i.executingRoute = e),
(n = {
id: r.id,
isInsecureGod: r.isInsecureGod,
cookies: r.cookies,
headers: r.headers,
params: r.params,
url: r.url.toString(),
path: r.path,
query: r.query,
buckets: r.buckets,
lang: r.lang,
geo: r.geo,
probableUser: r.probableUser,
UA: r.UA,
hasSessionCookie: r.hasSessionCookie,
body: r.body,
isInRebootGroups: r.isInRebootGroups,
}),
r.isGod && (n.isGod = r.isGod),
(r.routeTimingStart = Date.now()),
Promise.all([k(r), e.run(n, t)])
);
})
.then(function (e) {
if (e.length >= 2) {
e[0];
r.appContext.initialView = e[1].view;
}
return i._renderView(e, r, t, n);
})
.catch(function (e) {
return i._throwError.call(i, e, r, t, n);
});
}
_renderView(e, r, t, i) {
var o,
a = e.length > 0 ? e[0] : null,
s = e.length > 1 ? e[1] : null,
c = { nsid: !0, ispro: !0, segments: !0 };
if (!s) throw new Error("Invalid viewConfig");
if (((s.params = s.params || {}), a)) {
if (
(a.signedIn && a.user && a.user.username
? n.info("user is signed in", {
nsid: a.user.nsid,
username: a.user.username._content,
segments: a.user.segments,
})
: n.info("user is signed out"),
a.signedIn && a.user)
)
for (o in a.user) void 0 === c[o] && delete a.user[o];
(a.isInsecureGod = r.isInsecureGod), (r.appContext.auth = a);
}
return (
s &&
void 0 !== s.params &&
(s.params.isOwner =
r.appContext.getViewer().signedIn &&
r.appContext.getViewer().nsid === s.params.nsid),
s.redirect ||
((s.params.UA = r.UA),
(s.params.isMobile = r.UA.isMobileBrowser),
(s.layout = s.layout || w.rendering.default_layout),
(s.title = (function (e) {
let r = "Flickr";
return (
"string" == typeof e && (e = e.trim()) && (r = e + " | " + r),
r
);
})(s.title)),
(r.appContext.routeTiming = Date.now() - r.routeTimingStart)),
this.render(r, t, s)
);
}
_throwError(e, r, t, i) {
var o,
a = r && r.UA && (r.UA.isBot || r.UA.isSharingBot),
s = a ? g.getBotString() : "",
c = this;
if (!t.headersSent) {
if (e.is404)
return (
(o = c.executingRoute.display404Error(r, e)), c.render(r, t, o)
);
if (
r &&
r.appContext &&
e &&
e.message &&
e.message.indexOf(
"Not enough storage is available to complete this operation"
) > -1
)
return r.appContext.mitigateClientPanda(
"common.IE_STORAGE_ISSUE"
);
if (
r &&
r.appContext &&
e &&
(e.moduleLoadingError ||
e.message.indexOf(
"Loading failed: Failed to load https://combo.staticflickr.com/zz/combo?"
) > -1)
)
return (
window.beaconError &&
window.beaconError(
"[flickr-router] Module loading Issue:" + e.message,
window.location.href,
e
),
r.appContext.mitigateClientPanda("common.MODULES_BLOCKED")
);
try {
if (
(g.increment("hermes.page.failures" + s),
n.error("Reboot page failure", { err: e, req: r }),
e.fatal
? e.timeout || e.clientTimeout
? (g.increment("hermes.api.timeouts" + s),
n.error("Unexpected error", {
err: e,
metric: "api.timeouts" + s,
}))
: "Site Auth Failed" === e.message
? (g.increment("hermes.siteauth.failures"),
(e.type = "SiteAuth"),
(e.redirect = !0))
: "Session Failed" === e.message
? (g.increment("hermes.sessioncookie.failures"),
(e.type = "SiteAuth"),
(e.redirect = !0))
: (g.increment("hermes.api.other" + s),
n.error("Unexpected error", {
err: e,
metric: "api.other" + s,
}))
: (g.increment("hermes.page.failures.other" + s),
n.error("Unexpected error", {
err: e,
metric: "page.failures.other",
isBot: a,
}),
window.beaconError &&
window.beaconError(
"[flickr-router] Unexpected page failure:" +
e.message +
" UA:" +
((navigator && navigator.userAgent) || "").toString(),
window.location.href,
e
)),
window.beaconError && (!e.redirect || "SiteAuth" !== e.type))
) {
e.panda = !0;
r && r.UA && " unsupported:" + r.UA.isUnsupportedBrowser + " ",
window.beaconError(
"[flickr-router] " + e.message,
window.location.href,
e
);
}
} catch (r) {
var u = r;
void 0 === c.executingRoute && (u = e), n.info({ err: e });
try {
window.beaconError &&
((e.panda = !0),
window.beaconError(
"[flickr-router] _throwError failed: " + e.message,
window.location.href,
e
),
u !== e &&
window.beaconError(u.message, window.location.href, u));
} catch (e) {
n.info("Failed trying to beacon client error", { err: e });
}
}
return (
(o = c.executingRoute.display500Error(r, e)), c.render(r, t, o)
);
}
n.info("server render called but headers have already been sent", {
timeout: r.timeout,
});
}
};
});
YUI.add(
"client-app",
function (e, r) {
let n = g();
var i,
o,
a = t("hermes-core/flog")(r),
s = !1,
c = e.config.flickr.clientNavEnabled,
u = !1;
function l() {
c = !1;
}
function d(r) {
var t,
n,
i = window.location,
o = window.history,
a = !1;
if (
i.search &&
o.replaceState &&
((t = e.QueryString.parse(i.search.replace("?", ""))),
r.forEach(function (e) {
e in t && (delete t[e], (a = !0));
}),
a)
) {
n = e.QueryString.stringify(t);
try {
o.replaceState({}, "", i.pathname + (n ? "?" + n : ""));
} catch (e) {}
}
}
function p(e, r) {
return new r.Promise(function (t, n) {
r.use(e, function (e, r) {
r && "success" in r
? r.success
? t(e)
: n(r.msg)
: n("Y.use: no status provided");
});
});
}
function f(r) {
var t,
n,
o,
a,
s = [],
c = [
"flickr.photos.addView",
"flickr.groups.updateViewDate",
"flickr.photos.getPhotos",
"flickr.people.addView",
"flickr.photosets.addView",
];
if ((i.getViewCounter().flushQueue(), i.uploadIsInProgress()))
a = this.intlMessage({ intlName: "client-app.UPLOAD_IN_PROGRESS" });
else {
for (t in i.writeAPICallsMadeOnThisPage)
(n = i.writeAPICallsMadeOnThisPage[t]).completed || s.push(n);
s.length &&
(s.every(function (e) {
return -1 !== c.indexOf(e.methodName);
}) ||
(e.config.flickr.requestConfig &&
e.config.flickr.requestConfig.auth &&
e.config.flickr.requestConfig.auth.isInsecureGod
? ((o = s
.map(function (e) {
return e.methodName;
})
.join(", ")),
(a =
this.intlMessage({
intlName: "client-app.SAVING_LAST_ACTIONS",
}) +
" In progress API Methods: " +
o))
: (a = this.intlMessage({
intlName: "client-app.SAVING_LAST_ACTIONS",
}))));
}
return (
e.Storage.Instance.clear(),
a && ((r || window.event).returnValue = a),
a
);
}
function w(r) {
if (!c) return (window.location = r.url), void r.halt();
i.setClientSideRouted(!0),
i.setPreviousLocation(),
i.updateModelRefetchState(
r.url,
r.originEvent &&
r.originEvent.currentTarget &&
r.originEvent.currentTarget.hasClass("do-not-evict")
),
i.clearWriteAPICallCache(),
i.setGPCredentials(null),
e.fire("loader:start"),
i.adManager.isEnabled() &&
i.adManager.currentlyShowingAd &&
i.adManager.adIsUnloading(),
i.adManager.destroyAdUnitsOnPage(),
i.getKeyboardManager().resetCurrentKeyEventScope(),
e.Object.each(i.modelRegistries, function (e, r) {
e.hasWeakSubscribers && e.removeWeakSubscribers();
}),
(s = !0);
}
function h() {
e.UA.chrome > 0 &&
(window.scrollTo(window.scrollX, window.scrollY + 1),
window.scrollTo(window.scrollX, window.scrollY - 1));
}
function m(r) {
e.Object.each(i.modelRegistries, function (e, r) {
e.hasWeakSubscribers && e.removeWeakSubscribers();
}),
e.fire("close-dialogs"),
"popstate" === r.src && h(),
"popstate" === r.src &&
!o.hasRoute(o.getPath()) &&
!e.Object.isEmpty(r.newVal) &&
o.navigate(o.getPath()),
i.getViewCounter().flushQueue({ resetDuplicateTracking: !0 }),
s || i.updateModelRefetchState(),
(s = !1);
}
function v(e) {
o.set("previousView", e.prevVal);
}
function y(r) {
var t = this.get("activeView");
if (
(void 0 === t.getViewDataFromHistory("referrer") &&
t.setViewDataOnHistory("referrer", i.getPreviousURL()),
i.dataLayer.updateDataLayer(),
e.Snowplough && e.Snowplough.sendPageView(t),
e.DeferImages.update(),
i.adManager.setAdCouldBeShown(!1),
e.config.win.onappclientnav)
)
try {
e.config.win.onappclientnav();
} catch (e) {}
e.Accessibility.manageFocusOutlines(t),
void 0 !== window._sift &&
window._sift.push &&
window._sift.push(["_trackPageview"]),
u && i.requiresCookieConsent && C(),
window.addEventListener("message", function (e) {
"flickr:CMPframed" === e.data &&
((u = !0), i.requiresCookieConsent && C());
}),
i.trustarcConsentManager &&
(i.trustarcConsentManager.reset(), i.trustarcConsentManager.load());
}
function C() {
window.__tcfapi &&
window.__tcfapi("ping", 2, function (r) {
r.cmpLoaded ||
(a.info("CMP Loaded value is false"),
e.Snowplough &&
e.Snowplough.sendStructuredEvent({
category: "cookie_consent",
action: "consent_issue",
label: "cmpLoaded undefined",
}));
});
}
function b(r) {
return new e.Promise(function (t, n) {
var s = setTimeout(function () {
n(new Error("Initial View Timeout"));
}, 12e3);
(r.params.appContext = i),
o.showContent(
e.one("#content > .view"),
{ view: { name: r.name, config: r.params } },
function (r) {
e.one("body").removeClass("dark-loader"),
r._params && (r._params.keyEventScope = r.name + r._yuid),
r.setViewDataOnHistory("referrer", document.referrer),
r.set("isRootView", !0),
i.dataLayer.updateDataLayer(),
r
.initialize()
.then(function () {
e.Snowplough &&
(e.Snowplough.setUserId(),
e.Snowplough.sendPageView(r)),
i
.getKeyboardManager()
.setCurrentKeyEventScope(r.name + r._yuid),
h(),
e.DeferImages.init(),
e.Accessibility.manageFocusOutlines(r),
d(["campaignID", "linkID"]),
(function () {
if (
e.config.flickr.requestConfig &&
e.config.flickr.requestConfig.auth &&
e.config.flickr.requestConfig.auth.isInsecureGod
) {
var r = e.all("[data-view-signature]");
r.size() &&
a.warn(
"View signature mismatches detected! A view likely modified the `params` object directly.",
{ views: r.getDOMNodes() }
);
}
})(),
clearTimeout(s),
t();
})
.then(null, function (e) {
throw (
(a.error(
"There was a problem initializing or activating the view.",
{ err: e }
),
n(),
e)
);
}),
u && i.requiresCookieConsent && C(),
window.addEventListener("message", function (e) {
"flickr:CMPframed" === e.data &&
((u = !0), i.requiresCookieConsent && C());
});
}
),
o.before("navigate", w),
o.before("activeViewChange", v),
e.on("history:change", m),
o.after("activeViewChange", y);
});
}
function S(r, t, a, s) {
var c = {};
return (
e.Views && e.Views[r] && (c[r] = { type: e.Views[r], preserve: !1 }),
(o = new e.App({
serverRouting: !0,
viewContainer: "#content",
container: "#content",
linkSelector: ":not(.server-only-link):not([target=_blank])",
scrollToTop: !1,
views: c,
})),
new n(o, e.config.flickr.routes, {
onRender: function () {
e.fire("loader:progress");
},
onViewLoaded: function () {
e.fire("loader:progress");
},
onViewInitialized: function () {
e.fire("loader:progress");
},
onFinished: function () {
e.fire("loader:finish");
},
}),
(s.auth = t),
(s.flapp = o),
(i = (function (r) {
return (window.appContext = new e.AppContext(r)), window.appContext;
})(s)),
(i.routeTiming = s.routeTiming),
(i.routeConfig = s.routeConfig),
e.mix(e.Node.DOM_EVENTS, {
transitionend: !0,
webkitTransitionEnd: !0,
}),
(t && t.user && t.user.ispro) || e.use("prbd"),
e.ClientTransport.authorize(i),
(window.snowplough = e.Snowplough),
window.addEventListener("unload", function (r) {
e.ClientTransport.unloading = !0;
}),
window.addEventListener("load", function (r) {
e.ClientTransport.unloading = !1;
}),
i.adManager.detectAdBlocker(),
i.trustarcConsentManager && i.trustarcConsentManager.load(),
i.modelImportExport.importAll(a)
);
}
(e.ClientApp = {
init: function (r) {
if (void 0 === r)
return e.Promise.reject({
message: "Invalid config object supplied, was undefined.",
});
var t,
n,
o = r.initialView,
a = r.modelExport,
s = r.auth,
c = this;
return (
s || l(),
(t = s && r.auth.signedIn ? r.auth.csrf : null),
(e.config.flickr.csrf.token = t),
(e.config.flickr.requestConfig = { auth: s }),
(r.params.routeTiming = r.routeTiming),
(r.params.routeConfig = r.routeConfig),
d(e.config.flickr.routing_params),
window.location.search &&
window.location.search.match(/yc=/) &&
((n = e.QueryString.parse(
window.location.search.replace("?", "")
)),
(e.config.flickr.ycParam = n.yc)),
(e.transportFactory = function (r, t) {
return new e.ClientTransport(t);
}),
p(o.name, e)
.then(function () {
return S(o.name, s, a, r.params);
})
.then(function () {
return b(o);
})
.then(function () {
(function () {
var r = e.one("link#rollup-css");
r
? r.get("sheet")
? ((i.isCSSLoaded = !0), e.fire("css-loaded"))
: r.once("load", function () {
(i.isCSSLoaded = !0), e.fire("css-loaded");
})
: ((i.isCSSLoaded = !0), e.fire("css-loaded"));
})(),
e.AnchorRepositioner.jumpTo(),
e.config.win.addEventListener("beforeunload", f.bind(c));
})
.then(e.config.win.onappinit)
);
},
beforeUnload: f,
beforeNavigate: w,
_loadInitialView: p,
langBundles: ["client-app"],
disableClientNav: l,
getScrollSection: function r(t, n, i) {
var o = e.one(document.elementFromPoint(n, i)),
a = o.ancestor("[data-scroll-section]", !0);
if (a) return a.getAttribute("data-scroll-section");
var s,
c = o.ancestor(".view", !0);
if (c) {
if (
(s = c.getAttribute("class").match(/[\S]+-view/)[0]) === t.name &&
n === window.innerWidth / 2
) {
var u = r(t, n / 2, i);
return u !== t.name ? u : r(t, n + n / 2, i);
}
return s;
}
},
}),
(e.rapidTracker = { beacon: function () {} }),
e.mix(e.ClientApp, e.Localizable);
},
"0.0.1",
{
requires: [
"hermes-core",
"app-base",
"app-content",
"router",
"app-context",
"client-transport",
"handlebars-helpers",
"loader-bar",
"murmurhash",
"node",
"site-key",
"flickr-promise",
"global-events",
"querystring-parse-simple",
"querystring-stringify-simple",
"storage-helper",
"keyboard-manager",
"dom",
"overflow-helper",
"defer-images",
"accessibility",
"anchor-repositioner",
"atics",
"snowplough",
],
affinity: "client",
langBundles: ["client-app"],
}
);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment