1 Star 0 Fork 2

kaolasz / wrouter

forked from 云峰网络 / wrouter 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
wrouter0.11-min.js 3.28 KB
一键复制 编辑 原始数据 按行查看 历史
/*! wrouter v0.10 | (c) leiweicyz | www.51news.cc/license */
!function (a) { "use strict"; var b = function (a) { var c, d, e, f, b = this.configure(a); if (this.checkrouter()) $(function () { $("body").delegate("a", "click", function () { return b.load($(this).attr("href")) ? !1 : void 0 }) }), b.load(), c = function () { b.load() }, this.html5history ? window.onpopstate = c : window.onhashchange = c; else { d = location.hash, d && d.indexOf("#") > -1 && (e = d.indexOf("#"), d = d.substr(e + 1, d.length - e)); for (f in b.routers) d.match(b.routers[f].rule) && (location.href = d) } }; b.prototype.combine = function () { var b, a = ""; for (b in arguments) a += "/" + this.trim(arguments[b], arguments.length - 1 == b ? 1 : 0); return a }, b.prototype.trim = function (a, b, c) { return "number" == typeof b ? (c = b, b = "/") : c || (c = 0), b || (b = "/"), 0 != c && 1 != c || 0 != a.indexOf(b) || (a = a.substr(1, a.length - 1)), 0 != c && 2 != c || a.lastIndexOf(b) != a.length - b.length || (a = a.substr(0, a.length - b.length)), a }, b.prototype.checkrouter = function () { var a, b; return "onpopstate" in window ? !0 : "onhashchange" in window ? (a = navigator.userAgent, a.indexOf("compatible") > -1 && a.indexOf("MSIE") > -1 && -1 == a.indexOf("Opera") ? (b = new RegExp("MSIE (\\d+\\.\\d+);"), b.test(a), parseFloat(RegExp["$1"]) >= 8) : !0) : !1 }, b.prototype.configure = function (a) { var c, b = this; b.routers = a && a.routers || []; for (c in b.routers) "string" == typeof b.routers[c].rule && (b.routers[c].rule = new RegExp(b.routers[c].rule, "g")); return b.html5history = a && "boolean" == typeof a.html5history && !a.html5history ? a.html5history : void 0 !== window.history.pushState, b.root = a && a.root || "/", b.progress = a && a.progress || "#progress", b.onprogress = a && a.onprogress || function (a) { $(b.progress).css("width", 0).show().animate({ width: (0 == a.total ? 100 : 100 * (a.loaded / a.total)) + "%" }, function () { (0 == a.total || a.loaded == a.total) && $(b.progress).fadeOut(100) }) }, b }, b.prototype.getxhr = function () { return this.xhr ? this.xhr : (this.xhr = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"), this.xhr.onprogress = this.onprogress, this.xhr) }, b.prototype.ajax = function (a, b) { var c = this, d = c.getxhr(); return d.open("GET", a), d.setRequestHeader("WRouter", "1.0"), d.send(null), d.onreadystatechange = function () { 4 == d.readyState && 200 == d.status && b && b(d.responseText), 4 == d.readyState && 200 != d.status && c.error && c.error(d.readyState) }, c }, b.prototype.load = function (a) { var d, e, b = this, c = a ? !0 : !1; if (a = a || (b.html5history ? location.pathname + location.search : location.hash), !b.html5history || a != b.root) { if (d = a.indexOf("#"), d > -1 && (a = b.html5history ? a.substr(0, d) : a.substr(d + 1, a.length - d)), c && !b.html5history) return location.href = "#" + a, !0; for (e in b.routers) if (a.match(b.routers[e].rule)) return b.routers[e].title && (document.title = b.routers[e].title), b.ajax(a, function (a) { b.routers[e].container && $(b.routers[e].container).html(b.routers[e].action ? b.routers[e].action(a) : a), !b.routers[e].container && b.routers[e].action(a) }), c && window.history.pushState(null, null, a), !0 } }, a.wrouter = function (a) { return new b(a) } }(window);
1
https://gitee.com/kaolasz/wrouter.git
git@gitee.com:kaolasz/wrouter.git
kaolasz
wrouter
wrouter
master

搜索帮助