﻿/*
* jQuery Address Plugin v1.0
* http://www.asual.com/jquery/address/
*
* Copyright (c) 2009 Rostislav Hristov
* Dual licensed under the MIT and GPL licenses.
* http://docs.jquery.com/License
*
* Date: 2009-04-28 16:54:00 +0300 (Tue, 28 Apr 2009)
* Revision: 399
*/
(function(a) { a.address = (function() { var c = function(i) { a(this).trigger(a.extend(a.Event(i), (function() { var af = { value: this.value(), path: this.path(), pathNames: this.pathNames(), parameterNames: this.parameterNames(), parameters: {}, queryString: this.queryString() }; for (var ae = 0, p = af.parameterNames.length; ae < p; ae++) { af.parameters[af.parameterNames[ae]] = this.parameter(af.parameterNames[ae]) } return af }).call(this))) }; var U = function() { c.call(a.address, "init") }; var n = function() { c.call(a.address, "change") }; var O = function() { var i = T.href.indexOf("#"); return i != -1 ? ac(o(T.href.substr(i + 1))) : "" }; var g = function() { try { top.document; return top } catch (i) { return window } }; var E = function(p, i) { if (B.strict) { p = i ? (p.substr(0, 1) != "/" ? "/" + p : p) : (p == "" ? "/" : p) } return p }; var q = function(i, p) { return (h && T.protocol == "file:") ? (p ? P.replace(/\?/, "%3F") : P.replace(/%253F/, "?")) : i }; var ad = function(ag) { for (var ae = 0, p = ag.childNodes.length, af; ae < p; ae++) { if (ag.childNodes[ae].src) { k = String(ag.childNodes[ae].src) } if (af = ad(ag.childNodes[ae])) { return af } } }; var W = function() { if (!s) { var p = O(); var i = !(P == p); if (t && r < 523) { if (D != X.length) { D = X.length; if (typeof z[D - 1] != F) { P = z[D - 1] } S() } } else { if (h && i) { if (r < 7) { T.reload() } else { G.value(p) } } else { if (i) { P = p; S() } } } } }; var S = function() { n(); m(v, 10) }; var v = function() { var p = (T.pathname + (/\/$/.test(T.pathname) ? "" : "/") + C.value()).replace(/\/\//, "/").replace(/^\/$/, ""); var i = window[B.tracker]; if (typeof i == f) { i(p) } else { if (typeof pageTracker != F && typeof pageTracker._trackPageview == f) { pageTracker._trackPageview(p) } else { if (typeof urchinTracker == f) { urchinTracker(p) } } } }; var e = function() { var i = w.contentWindow.document; i.open(); i.write("<html><head><title>" + aa.title + "</title><script>var " + x + ' = "' + O() + '";<\/script></head></html>'); i.close() }; var M = function() { if (!R) { R = true; a("a").attr("xref", function() { return a(this).attr("href") }); if (h && r < 8) { aa.body.innerHTML = '<iframe id="' + x + '" src="javascript:false;" width="0" height="0"></iframe>' + aa.body.innerHTML; w = aa.getElementById(x); m(function() { a(w).bind("load", function() { var i = w.contentWindow; var p = i.location.href; P = (typeof i[x] != F ? i[x] : ""); if (P != O()) { S(); T.hash = q(P, true) } }); if (typeof w.contentWindow[x] == F) { e() } }, 50) } else { if (t) { if (r < 418) { a(aa.body).append('<form id="' + x + '" style="position:absolute;top:-9999px;" method="get"></form>'); I = aa.getElementById(x) } if (typeof T[x] == F) { T[x] = {} } if (typeof T[x][T.pathname] != F) { z = T[x][T.pathname].split(",") } } } m(function() { U(); n(); v() }, 1); if (h && r >= 8) { aa.body.onhashchange = W } else { u(W, 50) } a("a").attr("href", function() { return a(this).attr("xref") }).removeAttr("xref"); a("a[rel*=address:]").address() } }; var C = { baseURL: function() { var i = T.href; if (i.indexOf("#") != -1) { i = i.substr(0, i.indexOf("#")) } if (i.substr(i.length - 1) == "/") { i = i.substr(0, i.length - 1) } return i }, strict: function() { return B.strict }, history: function() { return B.history }, tracker: function() { return B.tracker }, title: function() { return aa.title }, value: function() { if (!Z) { return null } return o(E(q(P, false), false)) }, path: function() { var i = this.value(); return (i.indexOf("?") != -1) ? i.split("?")[0] : i }, pathNames: function() { var p = this.path(); var i = p.split("/"); if (p.substr(0, 1) == "/" || p.length == 0) { i.splice(0, 1) } if (p.substr(p.length - 1, 1) == "/") { i.splice(i.length - 1, 1) } return i }, queryString: function() { var p = this.value(); var i = p.indexOf("?"); return (i != -1 && i < p.length) ? p.substr(i + 1) : "" }, parameter: function(aj) { var ag = this.value(); var ae = ag.indexOf("?"); if (ae != -1) { ag = ag.substr(ae + 1); var ai = ag.split("&"); var ah, af = ai.length; while (af--) { ah = ai[af].split("="); if (ah[0] == aj) { return ah[1] } } } }, parameterNames: function() { var af = this.value(); var p = af.indexOf("?"); var ag = []; if (p != -1) { af = af.substr(p + 1); if (af != "" && af.indexOf("=") != -1) { var ah = af.split("&"); var ae = 0; while (ae < ah.length) { ag.push(ah[ae].split("=")[0]); ae++ } } } return ag } }; var G = { strict: function(i) { B.strict = i }, history: function(i) { B.history = i }, tracker: function(i) { B.tracker = i }, title: function(i) { m(function() { H = aa.title = i; if (J && w && w.contentWindow && w.contentWindow.document) { w.contentWindow.document.title = i; J = false } if (!L && Y) { T.replace(T.href.indexOf("#") != -1 ? T.href : T.href + "#") } L = false }, 50) }, value: function(ae) { ae = ac(o(E(ae, true))); if (ae == "/") { ae = "" } if (P == ae) { return } L = true; P = ae; s = true; S(); z[X.length] = P; if (t) { if (B.history) { T[x][T.pathname] = z.toString(); D = X.length + 1; if (r < 418) { if (T.search == "") { I.action = "#" + P; I.submit() } } else { if (r < 523 || P == "") { var i = aa.createEvent("MouseEvents"); i.initEvent("click", true, true); var p = aa.createElement("a"); p.href = "#" + P; p.dispatchEvent(i) } else { T.hash = "#" + P } } } else { T.replace("#" + P) } } else { if (P != O()) { if (B.history) { T.hash = "#" + q(P, true) } else { T.replace("#" + P) } } } if ((h && r < 8) && B.history) { m(e, 50) } if (t) { m(function() { s = false }, 1) } else { s = false } } }; var x = "jQueryAddress", f = "function", F = "undefined", A = a.browser, r = parseFloat(a.browser.version), Y = A.mozilla, h = A.msie, K = A.opera, t = A.safari, Z = false, N = g(), aa = N.document, X = N.history, T = N.location, u = setInterval, m = setTimeout, o = decodeURI, ac = encodeURI, ab = navigator.userAgent, w, I, k, H = aa.title, D = X.length, s = false, R = false, L = true, J = true, z = [], y = {}, P = O(), j = {}, B = { history: true, strict: true }; if (h) { r = parseFloat(ab.substr(ab.indexOf("MSIE") + 4)) } Z = (Y && r >= 1) || (h && r >= 6) || (K && r >= 9.5) || (t && r >= 312); if (Z) { for (var V = 1; V < D; V++) { z.push("") } z.push(O()); if (h && T.hash != O()) { T.hash = "#" + q(O(), true) } if (K) { history.navigationMode = "compatible" } ad(document); var b = k.indexOf("?"); if (k && b > -1) { var l, d = k.substr(b + 1).split("&"); for (var V = 0, Q; Q = d[V]; V++) { l = Q.split("="); if (/^(history|strict)$/.test(l[0])) { B[l[0]] = (isNaN(l[1]) ? /^(true|yes)$/i.test(l[1]) : (parseInt(l[1]) != 0)) } if (/^tracker$/.test(l[0])) { B[l[0]] = l[1] } } } a(M) } else { if ((!Z && T.href.indexOf("#") != -1) || (t && r < 418 && T.href.indexOf("#") != -1 && T.search != "")) { aa.open(); aa.write('<html><head><meta http-equiv="refresh" content="0;url=' + T.href.substr(0, T.href.indexOf("#")) + '" /></head></html>'); aa.close() } else { v() } } a.each(("init,change").split(","), function(ae, p) { j[p] = function(af, i) { a(a.address).bind(p, i || af, i && af); return this } }); a.each(("baseURL,strict,history,tracker,title,value").split(","), function(ae, p) { j[p] = function(i) { if (typeof i != "undefined") { if (Z) { G[p](i) } return a.address } else { return C[p]() } } }); a.each(("path,pathNames,queryString,parameter,parameterNames").split(","), function(ae, p) { j[p] = function(i) { return C[p](i) } }); return j })(); a.fn.address = function(b) { a(this).click(function() { var c = b ? b.call(this) : /address:/.test(a(this).attr("rel")) ? a(this).attr("rel").split("address:")[1].split(" ")[0] : a(this).attr("href").replace(/^#/, ""); a.address.value(c); return false }) } } (jQuery));