UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

3 lines (2 loc) 6.59 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("kendo.core.js")):"function"==typeof define&&define.amd?define(["exports","kendo.core.min"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).kendo=t.kendo||{},t.kendo._globals=t.kendo._globals||{},t.kendo._globals.Router={}))}(this,(function(t){!function(t){var e=window.kendo,n="change",i="same",r=e.support,o=window.location,a=window.history,s=e.support.browser.msie,h=/^#*/,c=window.document;function u(t,e){return e?(t+"/"===e&&(t=e),new RegExp("^"+e,"i").test(t)||(t=e+"/"+t),o.protocol+"//"+(o.host+"/"+t).replace(/\/\/+/g,"/")):t}function l(t){return t?"#!":"#"}function d(t){var e=o.href;return"#!"===t&&e.indexOf("#")>-1&&e.indexOf("#!")<0?null:e.split(t)[1]||""}function f(t,e){return 0===e.indexOf(t)?e.substr(t.length).replace(/\/\//g,"/"):e}var p=e.Class.extend({back:function(){s?setTimeout((function(){a.back()})):a.back()},forward:function(){s?setTimeout((function(){a.forward()})):a.forward()},length:function(){return a.length},replaceLocation:function(t){o.replace(t)}}),g=p.extend({init:function(t){this.root=t},navigate:function(t){a.pushState({},c.title,u(t,this.root))},replace:function(t){a.replaceState({},c.title,u(t,this.root))},normalize:function(t){return f(this.root,t)},current:function(){var t=o.pathname;return o.search&&(t+=o.search),f(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,i=o.pathname,r=d(l(t.hashBang));n===i+"/"&&(e=n),n===i&&r&&(e=u(r.replace(h,""),n)),e&&a.pushState({},c.title,e)}});function b(t){return t.replace(/^(#)?/,"#")}function k(t){return t.replace(/^(#(!)?)?/,"#!")}var v=p.extend({init:function(t){this._id=e.guid(),this.prefix=l(t),this.fix=t?k:b},navigate:function(t){o.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){r.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 d(this.prefix)},normalizeCurrent:function(t){var e=o.pathname,n=t.root;return!(!t.pushState||n===e)&&(this.replaceLocation(n+this.prefix+f(n,e)),!0)}}),w=e.Observable.extend({start:function(e){if(e=e||{},this.bind([n,"back",i],e),!this._started){this._started=!0,e.root=e.root||"/";var r,o=this.createAdapter(e);o.normalizeCurrent(e)||(r=o.current(),t.extend(this,{adapter:o,root:e.root,historyLength:o.length(),current:r,locations:[r]}),o.change(this._checkUrl.bind(this)))}},createAdapter:function(t){return r.pushState&&t.pushState?new g(t.root):new v(t.hashBang)},stop:function(){this._started&&(this.adapter.stop(),this.unbind(n),this._started=!1)},change:function(t){this.bind(n,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,r){var o=this.adapter;t=o.normalize(t),this.current!==t&&this.current!==decodeURIComponent(t)?!e&&this.trigger(n,{url:t,decode:!1})||(this.current=t,r.call(this,o),this.historyLength=o.length()):this.trigger(i)},_checkUrl:function(){var t=this.adapter,e=t.current(),i=t.length(),r=this.historyLength===i,o=e===this.locations[this.locations.length-2]&&r,a=this.backCalled,s=this.current;return null===e||this.current===e||this.current===decodeURIComponent(e)||(this.historyLength=i,this.backCalled=!1,this.current=e,o&&this.trigger("back",{url:s,to:e})?(t.forward(),void(this.current=s)):this.trigger(n,{url:e,backButtonPressed:!a})?(o?t.forward():(t.back(),this.historyLength--),void(this.current=s)):void(o?this.locations.pop():this.locations.push(e)))}});e.History=w,e.History.HistoryAdapter=p,e.History.HashAdapter=v,e.History.PushStateAdapter=g,e.absoluteURL=u,e.history=new w}(window.kendo.jQuery);var e=kendo;!function(){var t=window.kendo,e=t.history,n=t.Observable,i="init",r="routeMissing",o="change",a="back",s="same",h=/\((.*?)\)/g,c=/(\(\?)?:\w+/g,u=/\*\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(c,d).replace(u,"(.*?)")+"$",e?"i":"")}(t,n)),this.route=t,this._callback=e},callback:function(e,n,i){var r,o,a=0,s=t.parseQueryStringParams(e);if(s._back=n,e=f(e),o=(r=this.route.exec(e).slice(1)).length,i)for(;a<o;a++)void 0!==r[a]&&(r[a]=decodeURIComponent(r[a]));r.push(s),this._callback.apply(null,r)},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([i,r,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)},r=function(e){t._urlChanged(e)};e.start({same:function(){t._same()},change:r,back:n,pushState:t.pushState,hashBang:t.hashBang,root:t.root});var o={url:e.current||"/",preventDefault:$.noop};t.trigger(i,o)||t._urlChanged(o),this._urlChangedProxy=r,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,i=!!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,c=h.length;s<c;s++)if(h[s].worksWith(n,a,i))return;this.trigger(r,{url:n,params:t.parseQueryStringParams(n),backButtonPressed:a})&&e.preventDefault()}}});t.Router=g}(),t.__meta__={id:"router",name:"Router",category:"framework",description:"The Router class is responsible for tracking the application state and navigating between the application states.",depends:["core"],hidden:!1},t.default=e,Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=kendo.router.min.js.map