Skip to content

Instantly share code, notes, and snippets.

@annulen
Created November 10, 2011 11:02
Show Gist options
  • Save annulen/1354608 to your computer and use it in GitHub Desktop.
Save annulen/1354608 to your computer and use it in GitHub Desktop.
Daria.nop = function () {}, Daria.contextHelpPages = {}, Daria.checkHttps = function (a) {
a = a || Daria.nop;
var b = window,
c = b.location,
d = document;
if (c.protocol == "https:") b.httpsOk = !0, a();
else if ("httpsOk" in b) a();
else {
var e = d.createElement("script");
e.src = "https://" + c.host + "/neo2/js/https.js";
try {
d.getElementsByTagName("head")[0].appendChild(e), setTimeout(function () {
b.httpsOk || Daria.ErrorLog.send({
errorType: "HTTPS"
}), a()
}, 3e3)
} catch (f) {
a()
}
}
};
var globalEval;
window.execScript ? globalEval = function (a) {
window.execScript(a)
} : globalEval = function (a) {
window.eval(a)
}, Daria.ErrorLog = {
send: function (a) {
var b = [],
c = "/monitoring.txt?";
b.push("login=" + encodeURIComponent(Daria.login)), b.push("loc=" + encodeURIComponent(window.location.toString())), b.push("cv=" + Daria.Config.version), b.push("sv=" + Daria.Config.actualVersion), b.push("lcl=" + Daria.locale);
for (var d in a) a.hasOwnProperty(d) && b.push(d + "=" + encodeURIComponent(a[d]));
window.DariaAfterLoad && b.push("afterload=true"), c += b.join("&"), (new Image).src = c
},
sendException: function (a, b, c) {
c = c || {};
var d = "",
e = "";
b && (e = b.stack, b.message ? d = b.message : b.toString && (d = b.toString())), c.errorType = a, c.msg = d, c.stack = e, this.send(c)
}
}, function (a) {
function i(a) {
var b = 0,
c = e[a],
d = c ? c.length : 0;
if (!d) return;
console.groupCollapsed("handlers.jsx " + a);
for (; b < d; b++) console.log.apply(console, c[b]);
console.groupEnd(), delete e[a]
}
var b = {},
c = ["groupCollapsed", "groupEnd", "log"],
d = a.yatester && "console" in window && "log" in window.console && "groupCollapsed" in window.console && !window.opera,
e = {};
for (var f = 0, g = c.length; f < g; f++) {
var h = c[f];
b[h] = d ?
function (a) {
return function (b) {
switch (a) {
case "groupEnd":
i(b);
break;
case "log":
e[b] || (e[b] = []), e[b].push(Array.prototype.slice.call(arguments, 1))
}
}
}(h) : a.nop
}
a.DebugTimers = b, a.DebugTimers.enabled = d
}(Daria), function (a) {
var b;
try {
b = localStorage.getItem ? localStorage : null
} catch (c) {}
if (!b) {
a.LS = null;
return
}
a.LS = {
setItem: function (a, c) {
try {
return b.setItem(a, c), !0
} catch (d) {}
},
getItem: function (a) {
try {
return b.getItem(a)
} catch (c) {}
return null
},
clear: function () {
try {
return b.clear(), !0
} catch (a) {}
},
removeItem: function (a) {
try {
return b.removeItem(a), !0
} catch (c) {}
},
length: function () {
try {
return b.length
} catch (a) {}
return 0
},
key: function (a) {
try {
return b.key(a)
} catch (c) {}
return ""
}
}
}(Daria), function (a, b) {
var c = a.location,
d = 0,
e = /^(\w+ is undefined|syntax error|Script error|Синтаксическая ошибка|Expected |Предполагается наличие |uncaught exception|Error loading script|Незавершенная строковая константа)/;
b.errorRefresh = function () {
b.checkHttps(function () {
b.LS && b.LS.clear(), a.httpsOk && c.protocol != "https:" ? a.location = String(c.href).replace(/^http:/, "https:") : !b.nocache && !b.Config.dev && (a.location = "?nocache")
})
}, a.onerror = function (c, f, g) {
c && typeof c != "string" && c.type && c.target && (f = c.target.src, c = "Error loading script");
if (c && (c.indexOf("file://") > -1 || c.indexOf("chrome://") > -1)) return;
if (f && (f.indexOf("js/https.js") > -1 || f.indexOf("awaps.yandex.ru") > -1 || f.indexOf("mc.yandex.ru") > -1 || /^chrome\//.test(f))) return;
d++, !a.DariaAfterLoad && d < 2 && c && e.test(c) && (f && f.indexOf("yandex") ? b.errorRefresh() : f || setTimeout(function () {
a.DariaAfterLoad || b.errorRefresh()
}, 1e4)), b.ErrorLog.send({
errorType: "JSError",
id: d,
msg: c,
url: f,
line: g
})
}, a.console && console.log("Любишь заглядывать в консоль? А может и js умеешь писать? http://company.yandex.ru/job/vacancies/interface_dev_mail.xml")
}(window, Daria), function (a, b, c) {
function v(a, b, c) {
typeof a == "string" && (a = [a]);
for (var e = 0, f = a.length; e < f; e++) {
var g = a[e],
h = d.getModule(g);
if (h.status < b || c) h.status = b;
var i = h.modules;
for (var j = 0, k = i.length; j < k; j++) {
var l = i[j];
g != l && v(l, b, c)
}
}
}
function x(a, b) {
b = b || {};
var c = a.split(e),
g = b.project = c.shift(),
h = c.pop(),
i = c.shift() || g,
j, k;
switch (h) {
case "js":
j = "{mail-static}/hubs/" + g + "/_" + i + ".{locale}." + h, k = [g + f, "locale"];
break;
case "xsl":
j = "{xsl-static}/hubs/" + g + "/_" + i + ".{locale}." + h, k = [g + f, "locale"];
break;
case "css":
b.url = j = b.url || "{mail-static}/hubs/" + g + "/" + i + "/_{mail-scheme}{msie-suffix}." + h, k = [g + f, "mail-scheme", "msie-suffix"];
if (o["msie-suffix"] && j.indexOf("{msie-suffix}") > -1) {
b.url = b.url.replace("{msie-suffix}", "");
var l = {};
l[a.replace(/\.css$/, ".ie-css")] = {
url: j,
guards: b.guards
}, d.addModules(l)
}
break;
case "ie-css":
j = "{mail-static}/hubs/" + g + "/" + i + "/_{mail-scheme}{msie-suffix}.css", k = [g + f, "mail-scheme", "msie-suffix"]
}
b.url = b.url || j, b.guards = k.concat(b.guards || []);
var m = [],
n = i.split("_");
for (var p = 0, q = n.length; p < q; p++) {
var s = n[p];
X(s) ? m.push("jane" + e + h) : m.push(g + e + s + e + h)
}
return b.modules = m, b._modules = A(m), b.requests = [], U(a, b) ? b._weight = -100 : b._weight = m.length, b.status = r, b
}
function y(a, b) {
b = b || u;
var c = [];
for (var e = 0, f = a.length; e < f; e++) {
var g = a[e],
h = d.getModule(g);
h.status <= b && c.push(g)
}
return c
}
function A(a) {
var b = {};
for (var c = 0, d = a.length; c < d; c++) b[a[c]] = 1;
return b
}
function B(a) {
var b = {},
c = [];
for (var d = 0, e = a.length; d < e; d++) {
var f = a[d];
b[f] || (c.push(f), b[f] = 1)
}
return c
}
function D(a) {
for (var b in a) return !1;
return !0
}
function E(a) {
function p(a) {
var c = [];
for (var d = 0, f = e; d < f; d++) c.push(b[d][a[d]]);
return B(c)
}
function q(a) {
if (a < e) for (var b = 0, f = c[a]; b < f; b++) o[a] = b, q(a + 1);
else {
var g = p(o),
h = 0,
i = 0;
for (var b = 0, f = g.length; b < f; b++) h += d.getModule(g[b])._weight, i++;
if (h < m || h === m && i < l) m = h, l = i, n = C.call(o)
}
}
var b = [],
c = [],
e = a.length;
for (var f = 0; f < e; f++) {
var g = [],
h = a[f];
for (var i in j) {
var k = d.getModule(i);
k._modules[h] && k.url && g.push(i)
}
b.push(g), c.push(g.length)
}
var l = Number.POSITIVE_INFINITY,
m = Number.POSITIVE_INFINITY,
n, o = [];
return q(0), p(n)
}
function F(a) {
var b = d.getModule(a),
c = b.modules;
v(c, s);
var e = J(b.url);
P(e, a, function (a) {
if (a === !1) return;
v(c, t), b.data = a;
for (var e = 0, f = c.length; e < f; e++) {
var g = c[e],
h = d.getModule(g).requests;
for (var i = 0, j = h.length; i < j; i++) {
var k = h[i],
l = k.wait;
delete l[g], D(l) && k.callback()
}
}
})
}
function I(a) {
a = y(a, t), a = E(a), a.sort(T);
var b = [];
for (var c = 0, e = a.length; c < e; c++) {
var f = a[c],
g = d.getModule(f);
if (g.status < u && g.data) {
var h = W(f);
H[h] && (H[h](f, g.data), g.data = null, b.push(f))
}
}
v(b, u)
}
function J(a) {
return typeof a == "function" && (a = a()), a = a.replace(/(?:{(.*?)})/g, function (a, b) {
return o[b] || ""
}), a
}
function M(a) {
if (!m) return;
if (a) {
var b = [],
c = a + ".",
d = c.length;
for (var e = 0, f = m.length(); e < f; e++) {
var g = m.key(e);
g.substr(0, d) == c && b.push(g)
}
for (e = 0, f = b.length; e < f; e++) try {
m.removeItem(b[e])
} catch (h) {
m.clear();
break
}
} else m.clear()
}
function N(a) {
var b = "_guardsValue";
if (!a[b]) {
var c = a.guards || [],
d = [];
for (var e = 0, f = c.length; e < f; e++) {
var g = c[e];
d.push(g + "=" + o[g])
}
a[b] = d.join("+") + "@"
}
return a[b]
}
function P(a, b, e, f) {
if (b) {
var g;
if (m) if (g = U(b)) {
e(g);
return
}
}
var h = W(a);
if (!q() && O[h]) h == "js" && z && z.blockJSLoad ? (v(b, r, !0), e(!1)) : O[h](a, function () {
e()
});
else {
var i = /^\/\//.test(a) ? L() : K();
if (i) {
i.open(f ? "POST" : "GET", a, !0);
var j = function () {
i.onreadystatechange = c.nop;
try {
i.onload = i.onerror = i.onprogress = c.nop
} catch (a) {}
j = k = null;
var d = i.responseText;
b && V(b, d), e(d)
},
k = function () {
i.onreadystatechange = c.nop;
try {
i.onload = i.onerror = i.onprogress = c.nop
} catch (f) {}
j = k = null;
try {
i.abort()
} catch (f) {}
S();
if (b) {
a = J(d.getModule(b).url), b in l ? l[b]++ : l[b] = 1;
if (l[b] < 3) P(a, b, e);
else {
m && m.clear();
try {
var g = i ? i.status : ""
} catch (f) {}
c.ErrorLog.send({
errorType: "loadfailed",
moduleid: b,
status: g
})
}
}
};
"onreadystatechange" in i ? i.onreadystatechange = function () {
if (i.readyState < 4) return;
i.status == 200 && i.responseText ? j && j() : k && k()
} : i.onload = j;
try {
i.onerror = k, i.onprogress = function () {}
} catch (n) {}
if (f) {
i.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var o = [];
for (var p in f) o.push(encodeURIComponent(p) + "=" + encodeURIComponent(f[p]));
i.send(o.join("&"))
} else i.send(null)
}
}
}
function Q(a) {
if (!m) return;
var b = a + f,
c = m.getItem(b),
e = d.getProjectVersion(a);
(!c || e != c) && M(a), m.setItem(b, e)
}
function R() {
if (!m) return;
m.getItem(g) != h && m.clear(), m.setItem(g, h)
}
function S() {
b.cookie = "fail_xdr=1;max-age=604800", o["xsl-static"] = k, p = !1, c.ErrorLog.send({
errorType: "XDR"
});
for (var a in i) i[a].onXDRFail && i[a].onXDRFail();
S = c.nop
}
function T(a, b) {
var c = X(a),
d = X(b);
return !c && d ? 1 : c && !d ? -1 : 0
}
function U(a, b) {
b = b || d.getModule(a);
if (!m || !b) return "";
var c = N(b),
e = c.length,
f = m.getItem(a);
return f && f.substr(0, e) == c ? f.substr(e) : (f && m.removeItem(a), "")
}
function V(a, b) {
var c = d.getModule(a);
return m && c && m.setItem(a, N(c) + b)
}
function W(a) {
return a.split(".").slice(-1)[0]
}
function X(a) {
return a.indexOf("jane") > -1
}
var d = c.Services = {},
e = ".",
f = e + "version",
g = "jane-storage-version",
h = "3",
i = {},
j = {},
k = "/neo2/" + c.Config.version + c.staticSuffix,
l = {},
m = c.LS;
R();
var n = b.getElementById("handlers-data");
d.hData = [{
data: n ? n.text.replace(/^\/\//gm, "") : null,
params: {},
handlers: ["account-information", "settings"]
}];
var o = d.Params = {
locale: c.locale,
"mail-static": c.Config.staticRoot + c.staticSuffix,
"xsl-static": k,
"mail-scheme": c.themeId
},
p = a.location.search.indexOf("fail_xdr=1") == -1 && !/fail_xdr=1(;|$)/.test(b.cookie) && !! (a.XDomainRequest || a.XMLHttpRequest && "withCredentials" in new XMLHttpRequest),
q = d.XDRSupport = function () {
return p
};
q() && (o["xsl-static"] = o["mail-static"]), function () {
var a = navigator.userAgent.toLowerCase();
o["msie-suffix"] = "";
if (a.indexOf("webkit") > -1) o.webkit = !0;
else if (a.indexOf("opera") > -1) o.opera = !0;
else {
var c = /(msie) ([\w.]+)/.exec(a);
if (c) {
var d = parseInt(c[2], 10);
if (d < 8 || b.documentMode && b.documentMode < 8) o["msie-suffix"] = ".ie.ie"
}
}
}();
var r = 0,
s = 1,
t = 2,
u = 3,
w = {};
d.getXSL = function (a) {
return i[a] && i[a].XSLT
}, d.getProject = function (a) {
return i[a]
}, d.getModule = function (a) {
var b = j[a];
return b || (b = j[a] = x(a)), b
}, d.addProjects = function (a) {
for (var b in a) {
c.Config.XSL.services[b] = "";
var d = a[b];
i[b] = d, o[b + f] = d.version, Q(b)
}
}, d.getProjectVersion = function (a) {
return d.getProject(a).version
}, d.getProjectByMid = function (a) {
return j[a].project
}, d.addModules = function (a) {
for (var b in a) j[b] = x(b, a[b])
};
var z = {
blockJSLoad: !0,
n: 0,
modules: [],
donePart: function () {
this.n--, this.n || z.done()
},
done: function () {
if (!c.XOk) return;
var a = d.hData,
b = [];
delete d.hData, c.DebugTimers.groupCollapsed(0);
for (var e = 0, f = a.length; e < f; e++) try {
var g = a[e];
b = b.concat(g.handlers);
if (!g.data) continue;
var h = new c.XML(g.data),
i = g.handlers,
j = g.params;
delete j._handlers;
var k = {};
for (var l = 0, m = i.length; l < m; l++) {
var n = i[l];
k[n] = c.$H(n).getKey(j)
}
h.nodes && c.Handler.parseResponse(h.nodes, [{
handlers: k,
params: j
}], {}, 0, !0) === !1 && c.ErrorLog.send({
xmlData: g && g.data && g.data.length < 5e3 ? g.data : "",
handlers: i,
params: j
})
} catch (o) {
c.ErrorLog.sendException("PrefetchDataException", o, {
xmlData: g && g.data && g.data.length < 5e3 ? g.data : "",
handlers: i,
params: j
})
}
c.DebugTimers.groupEnd(0), $(function () {
c.init(b, g ? g.params : null)
}), z = null
}
};
d.bootstrap = function () {
if (c.isFatalError) return;
var b = a.location.hash || "#inbox",
e = d.url2pid(b),
f = d.pid2Modules(e, b);
z.modules = f.modules, z.n = 1;
var g = f.data;
if (g && g.handlers) {
var h = c.handlersPrefix + "/handlers.jsx",
i = g.params || {};
g.params._handlers = g.handlers.join(","), z.n++, P(h, null, function (a) {
d.hData.push({
data: a,
params: i,
handlers: g.handlers
}), z.donePart()
}, g.params)
}
d.loadModules(f.modules)
}, d.pid2Modules = function (a, b) {
var e = this.getProject(a),
f = {
handlers: ["settings-color-schemes", "user-settings", "settings-color-schemes-text", "informer-news", "lenta-counter", "db-ro-status", "collectors", "collector-settings", "folders"],
params: {
"color-scheme": c.themeId,
"region-code": c.Config.XSL["region-code"],
_locale: c.locale
}
},
g;
typeof e.prefetch == "function" && (g = e.prefetch(b, f));
var h = B([].concat(d.require, e.require || [], g || []));
if (o["msie-suffix"]) {
var i = [];
for (var j = 0, k = h.length; j < k; j++) {
var l = h[j];
W(l) == "css" && i.push(l.replace(/\.css$/, ".ie-css"))
}
h = h.concat(i)
}
return {
modules: h,
data: f
}
}, d.postBootstrap = function () {
if (c.isFatalError) return;
z.blockJSLoad = !1, a.errTimeoutLimit = setTimeout(function () {
c.LS && c.LS.clear(), c.ErrorLog.send({
errorType: "VeryLongLoading"
})
}, 6e4), a.pleaseWaitTimer = setTimeout(function () {
$("#app-loading1").css("display", "none").removeClass("g-hidden").fadeIn(1e3)
}, 900), a.longLoadTimer = setTimeout(function () {
$("#app-loading2").css("display", "none").removeClass("g-hidden").fadeIn(1e3)
}, 2e4), d.runModules(z.modules, function () {
z.donePart()
})
}, d.require = ["jane.js", "jane.xsl", "jane.css"], d.url2pid = function (a) {
var b = this.url2pid.callbacks;
for (var c = 0; c < b.length; c++) {
var d = b[c](a);
if (d) return d
}
return "mail"
}, d.url2pid.callbacks = [], d.addProjects({
jane: {
version: c.Config.version_full
}
}), d.addModules({
"jane.js": null,
"jane.xsl": null,
"jane.css": null
});
var C = Array.prototype.slice;
d.loadModules = function (a, b) {
b = b || c.nop;
var e = {
callback: b,
wait: {},
load: []
};
a.sort(T);
for (var f = 0, g = a.length; f < g; f++) {
var h = a[f],
i = d.getModule(h),
j = i.status;
j < s && e.load.push(h), j < t && (e.wait[h] = 1, i.requests.push(e))
}
if (D(e.wait)) b();
else {
a = E(e.load);
for (var f = 0, g = a.length; f < g; f++) F(a[f])
}
};
var G = function () {
var a = b.getElementsByTagName("head")[0],
c = b.getElementById("handlers-data");
return function (b) {
a.insertBefore(b, c)
}
}(),
H = {
js: function (a, b) {
globalEval(b)
},
css: function (a, c) {
var d = b.createElement("style");
d.setAttribute("type", "text/css"), d.setAttribute("id", "css-" + a), G(d), d.styleSheet ? d.styleSheet.cssText = c : d.appendChild(b.createTextNode(c))
},
xsl: function (a, b) {
if (c.XSLT) {
var e = d.getProjectByMid(a),
f = i[e].XSLT;
o.webkit && (b = b.replace('method="xml"', 'method="html"').replace(/<br\/>/g, '<xsl:value-of select="\'&lt;br/&gt;\'" disable-output-escaping="yes"/>'));
if (f) {
var g = new c.XSLT(b),
h = g.nodes,
j = f.nodes.cloneNode(!0);
while (m = j.lastChild) h.insertBefore(m, h.firstChild);
g._onload(), f = g
} else {
f = new c.XSLT(b);
var k = d.getModule(a);
if (k.modules.length > 1 && k._modules["jane.xsl"]) i.jane.XSLT = new c.XSLT(b.replace(/<xsl:template name="i18n-convert">(.*)<\/xsl:stylesheet>/, "")), f._onload();
else if (e != "jane") {
var l = i.jane.XSLT.nodes.cloneNode(!0),
m, n = f.nodes;
while (m = l.lastChild) n.insertBefore(m, n.firstChild);
f._onload()
}
}
f.isValid() ? i[e].XSLT = f : (c.isFatalError = !0, c.ErrorLog.send({
errorType: "xsl_load_fail",
mid: a
}), c.errorRefresh())
}
}
};
H["ie-css"] = H.css, d.runModules = function (a, b) {
var c = y(a, t),
e = [];
for (var f = 0, g = c.length; f < g; f++) {
var h = c[f];
X(h) && W(h) == "js" && d.getModule(h).status == t && e.push(h)
}
e.length && I(e), d.loadModules(y(a, s), function () {
I(a), b()
})
};
var K;
a.XMLHttpRequest ? K = function () {
return new a.XMLHttpRequest
} : K = function () {
try {
return new a.ActiveXObject("Microsoft.XMLHTTP")
} catch (b) {}
};
var L = K;
a.XDomainRequest && (L = function () {
return new a.XDomainRequest
});
var O = {
css: function (a, c) {
var d = b.createElement("link");
d.setAttribute("type", "text/css"), d.setAttribute("rel", "stylesheet"), d.setAttribute("href", a), o["msie-suffix"] ? d.onreadystatechange = function () {
/loaded|complete/.test(d.readyState) && c()
} : o.opera ? d.onload = c : "onreadystatechange" in d ? d.onreadystatechange = function () {
/loaded|complete/.test(d.readyState) && c()
} : function e() {
d && d.sheet ? c() : setTimeout(e, 20)
}(), G(d)
},
js: function (c, d) {
if (a.Jane || X(c)) {
var e = b.createElement("script");
e.setAttribute("type", "text/javascript"), e.setAttribute("charset", "utf-8"), e.setAttribute("src", c), G(e);
var f = !1;
e.onload = e.onreadystatechange = function () {
var b = this.readyState;
!f && (!b || b == "loaded" || b == "complete") && (f = !0, d(), e.onload = e.onreadystatechange = null, a.setTimeout(function () {
for (var a in w) {
var b = w[a];
delete w[a], O.js(a, b)
}
}, 1))
}
} else w[c] = d
}
};
d.get = P
}(window, document, Daria), Daria.Services.addProjects({
webchat: {
version: Daria.webchatVersion
}
}), Daria.Services.addModules({
"webchat.roster.js": {
url: Daria.Config.webchatStaticPath + "/_webchat-mail-neo2." + Daria.locale + "." + (Daria.IS_CORP ? "production-yt." : "") + "js"
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment