demo20230512/Scripts/kendo/2014.2.716/kendo.router.min.js
2023-05-12 10:20:28 +08:00

16 lines
6.4 KiB
JavaScript

/**
* Copyright 2014 Telerik AD
*
* 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(e,define){define(["./kendo.core.min"],e)}(function(){return function(e,t){function n(e,t){if(!t)return e;e+"/"===t&&(e=t);var n=RegExp("^"+t,"i");return n.test(e)||(e=t+"/"+e),h.protocol+"//"+(h.host+"/"+e).replace(/\/\/+/g,"/")}function r(e){return e?"#!":"#"}function i(e){var t=h.href;return"#!"===e&&t.indexOf("#")>-1&&t.indexOf("#!")<0?null:t.split(e)[1]||""}function o(e,t){return 0===t.indexOf(e)?t.substr(e.length).replace(/\/\//g,"/"):t}function a(e){return e.replace(/^(#)?/,"#")}function s(e){return e.replace(/^(#(!)?)?/,"#!")}var u=window.kendo,l="change",c="back",d="same",f=u.support,h=window.location,p=window.history,m=50,g=u.support.browser.msie,y=/^#*/,v=window.document,w=u.Class.extend({back:function(){g?setTimeout(function(){p.back()}):p.back()},forward:function(){g?setTimeout(function(){p.forward()}):p.forward()},length:function(){return p.length},replaceLocation:function(e){h.replace(e)}}),b=w.extend({init:function(e){this.root=e},navigate:function(e){p.pushState({},v.title,n(e,this.root))},replace:function(e){p.replaceState({},v.title,n(e,this.root))},normalize:function(e){return o(this.root,e)},current:function(){var e=h.pathname;return h.search&&(e+=h.search),o(this.root,e)},change:function(t){e(window).bind("popstate.kendo",t)},stop:function(){e(window).unbind("popstate.kendo")},normalizeCurrent:function(e){var t,o=e.root,a=h.pathname,s=i(r(e.hashBang));o===a+"/"&&(t=o),o===a&&s&&(t=n(s.replace(y,""),o)),t&&p.pushState({},v.title,t)}}),M=w.extend({init:function(e){this._id=u.guid(),this.prefix=r(e),this.fix=e?s:a},navigate:function(e){h.hash=this.fix(e)},replace:function(e){this.replaceLocation(this.fix(e))},normalize:function(e){return e.indexOf(this.prefix)<0?e:e.split(this.prefix)[1]},change:function(t){f.hashChange?e(window).on("hashchange."+this._id,t):this._interval=setInterval(t,m)},stop:function(){e(window).off("hashchange."+this._id),clearInterval(this._interval)},current:function(){return i(this.prefix)},normalizeCurrent:function(e){var t=h.pathname,n=e.root;return e.pushState&&n!==t?(this.replaceLocation(n+this.prefix+o(n,t)),!0):!1}}),S=u.Observable.extend({start:function(t){if(t=t||{},this.bind([l,c,d],t),!this._started){this._started=!0,t.root=t.root||"/";var n,r=this.createAdapter(t);r.normalizeCurrent(t)||(n=r.current(),e.extend(this,{adapter:r,root:t.root,historyLength:r.length(),current:n,locations:[n]}),r.change(e.proxy(this,"_checkUrl")))}},createAdapter:function(e){return f.pushState&&e.pushState?new b(e.root):new M(e.hashBang)},stop:function(){this._started&&(this.adapter.stop(),this.unbind(l),this._started=!1)},change:function(e){this.bind(l,e)},replace:function(e,t){this._navigate(e,t,function(t){t.replace(e),this.locations[this.locations-1]=this.current})},navigate:function(e,n){return"#:back"===e?(this.backCalled=!0,this.adapter.back(),t):(this._navigate(e,n,function(t){t.navigate(e),this.locations.push(this.current)}),t)},_navigate:function(e,n,r){var i=this.adapter;return e=i.normalize(e),this.current===e||this.current===decodeURIComponent(e)?(this.trigger(d),t):((n||!this.trigger(l,{url:e}))&&(this.current=e,r.call(this,i),this.historyLength=i.length()),t)},_checkUrl:function(){var e=this.adapter,n=e.current(),r=e.length(),i=this.historyLength===r,o=n===this.locations[this.locations.length-2]&&i,a=this.backCalled,s=this.current;return null===n||this.current===n||this.current===decodeURIComponent(n)?!0:(this.historyLength=r,this.backCalled=!1,this.current=n,o&&this.trigger("back",{url:s,to:n})?(e.forward(),this.current=s,t):this.trigger(l,{url:n,backButtonPressed:!a})?(o?e.forward():(e.back(),this.historyLength--),this.current=s,t):(o?this.locations.pop():this.locations.push(n),t))}});u.History=S,u.History.HistoryAdapter=w,u.History.HashAdapter=M,u.History.PushStateAdapter=b,u.absoluteURL=n,u.history=new S}(window.kendo.jQuery),function(){function e(e,t){return t?e:"([^/]+)"}function t(t){return RegExp("^"+t.replace(p,"\\$&").replace(d,"(?:$1)?").replace(f,e).replace(h,"(.*?)")+"$")}function n(e){return e.replace(/(\?.*)|(#.*)/g,"")}var r=window.kendo,i=r.history,o=r.Observable,a="init",s="routeMissing",u="change",l="back",c="same",d=/\((.*?)\)/g,f=/(\(\?)?:\w+/g,h=/\*\w+/g,p=/[\-{}\[\]+?.,\\\^$|#\s]/g,m=r.Class.extend({init:function(e,n){e instanceof RegExp||(e=t(e)),this.route=e,this._callback=n},callback:function(e){var t,i,o=0,a=r.parseQueryStringParams(e);for(e=n(e),t=this.route.exec(e).slice(1),i=t.length;i>o;o++)void 0!==t[o]&&(t[o]=decodeURIComponent(t[o]));t.push(a),this._callback.apply(null,t)},worksWith:function(e){return this.route.test(n(e))?(this.callback(e),!0):!1}}),g=o.extend({init:function(e){e||(e={}),o.fn.init.call(this),this.routes=[],this.pushState=e.pushState,this.hashBang=e.hashBang,this.root=e.root,this.bind([a,s,u,c],e)},destroy:function(){i.unbind(u,this._urlChangedProxy),i.unbind(c,this._sameProxy),i.unbind(l,this._backProxy),this.unbind()},start:function(){var e,t=this,n=function(){t._same()},r=function(e){t._back(e)},o=function(e){t._urlChanged(e)};i.start({same:n,change:o,back:r,pushState:t.pushState,hashBang:t.hashBang,root:t.root}),e={url:i.current||"/",preventDefault:$.noop},t.trigger(a,e)||t._urlChanged(e),this._urlChangedProxy=o,this._backProxy=r},route:function(e,t){this.routes.push(new m(e,t))},navigate:function(e,t){r.history.navigate(e,t)},replace:function(e,t){r.history.replace(e,t)},_back:function(e){this.trigger(l,{url:e.url,to:e.to})&&e.preventDefault()},_same:function(){this.trigger(c)},_urlChanged:function(e){var t,n,i,o,a=e.url;if(a||(a="/"),this.trigger(u,{url:e.url,params:r.parseQueryStringParams(e.url),backButtonPressed:e.backButtonPressed}))return void e.preventDefault();for(t=0,n=this.routes,o=n.length;o>t;t++)if(i=n[t],i.worksWith(a))return;this.trigger(s,{url:a,params:r.parseQueryStringParams(a),backButtonPressed:e.backButtonPressed})&&e.preventDefault()}});r.Router=g}(),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()});