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