UNPKG

@progress/kendo-ui

Version:

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

1 lines 6.87 kB
module.exports=function(n){var r={};function i(t){if(r[t])return r[t].exports;var e=r[t]={exports:{},id:t,loaded:!1};return n[t].call(e.exports,e,e.exports,i),e.loaded=!0,e.exports}return i.m=n,i.c=r,i.p="",i(0)}({0:function(t,e,n){t.exports=n(1417)},3:function(t,e){t.exports=function(){throw Error("define cannot be used indirect")}},1051:function(t,e){t.exports=require("./kendo.core")},1417:function(t,e,n){var r;n(3),n=[n(1051)],void 0===(e="function"==typeof(r=function(){var t={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:false},r=window.kendo.jQuery,n=void 0,e=window.kendo,s="change",l="back",p="same",d=e.support,a=window.location,o=window.history,g=50,b=e.support.browser.msie,v=/^#*/,u=window.document;function c(t,e){if(!e)return t;if(t+"/"===e)t=e;var n=new RegExp("^"+e,"i");if(!n.test(t))t=e+"/"+t;return a.protocol+"//"+(a.host+"/"+t).replace(/\/\/+/g,"/")}function w(t){return t?"#!":"#"}function k(t){var e=a.href;if(t==="#!"&&e.indexOf("#")>-1&&e.indexOf("#!")<0)return null;return e.split(t)[1]||""}function i(t,e){if(e.indexOf(t)===0)return e.substr(t.length).replace(/\/\//g,"/");else return e}var x=e.Class.extend({back:function(){if(b)setTimeout(function(){o.back()});else o.back()},forward:function(){if(b)setTimeout(function(){o.forward()});else o.forward()},length:function(){return o.length},replaceLocation:function(t){a.replace(t)}}),m=x.extend({init:function(t){this.root=t},navigate:function(t){o.pushState({},u.title,c(t,this.root))},replace:function(t){o.replaceState({},u.title,c(t,this.root))},normalize:function(t){return i(this.root,t)},current:function(){var t=a.pathname;if(a.search)t+=a.search;return i(this.root,t)},change:function(t){r(window).bind("popstate.kendo",t)},stop:function(){r(window).unbind("popstate.kendo")},normalizeCurrent:function(t){var e,n=t.root,r=a.pathname,i=k(w(t.hashBang));if(n===r+"/")e=n;if(n===r&&i)e=c(i.replace(v,""),n);if(e)o.pushState({},u.title,e)}});function y(t){return t.replace(/^(#)?/,"#")}function _(t){return t.replace(/^(#(!)?)?/,"#!")}var C=x.extend({init:function(t){this._id=e.guid();this.prefix=w(t);this.fix=t?_:y},navigate:function(t){a.hash=this.fix(t)},replace:function(t){this.replaceLocation(this.fix(t))},normalize:function(t){if(t.indexOf(this.prefix)<0)return t;else return t.split(this.prefix)[1]},change:function(t){if(d.hashChange)r(window).on("hashchange."+this._id,t);else this._interval=setInterval(t,g)},stop:function(){r(window).off("hashchange."+this._id);clearInterval(this._interval)},current:function(){return k(this.prefix)},normalizeCurrent:function(t){var e=a.pathname,n=t.root;if(t.pushState&&n!==e){this.replaceLocation(n+this.prefix+i(n,e));return true}return false}}),S=e.Observable.extend({start:function(t){t=t||{};this.bind([s,l,p],t);if(this._started)return;this._started=true;t.root=t.root||"/";var e=this.createAdapter(t),n;if(e.normalizeCurrent(t))return;n=e.current();r.extend(this,{adapter:e,root:t.root,historyLength:e.length(),current:n,locations:[n]});e.change(this._checkUrl.bind(this))},createAdapter:function(t){return d.pushState&&t.pushState?new m(t.root):new C(t.hashBang)},stop:function(){if(!this._started)return;this.adapter.stop();this.unbind(s);this._started=false},change:function(t){this.bind(s,t)},replace:function(e,t){this._navigate(e,t,function(t){t.replace(e);this.locations[this.locations.length-1]=this.current})},navigate:function(e,t){if(e==="#:back"){this.backCalled=true;this.adapter.back();return}this._navigate(e,t,function(t){t.navigate(e);this.locations.push(this.current)})},_navigate:function(t,e,n){var r=this.adapter;t=r.normalize(t);if(this.current===t||this.current===decodeURIComponent(t)){this.trigger(p);return}if(!e)if(this.trigger(s,{url:t,decode:false}))return;this.current=t;n.call(this,r);this.historyLength=r.length()},_checkUrl:function(){var t=this.adapter,e=t.current(),n=t.length(),r=this.historyLength===n,i=e===this.locations[this.locations.length-2]&&r,a=this.backCalled,o=this.current;if(e===null||this.current===e||this.current===decodeURIComponent(e))return true;this.historyLength=n;this.backCalled=false;this.current=e;if(i&&this.trigger("back",{url:o,to:e})){t.forward();this.current=o;return}if(this.trigger(s,{url:e,backButtonPressed:!a})){if(i)t.forward();else{t.back();this.historyLength--}this.current=o;return}if(i)this.locations.pop();else this.locations.push(e)}}),h=(e.History=S,e.History.HistoryAdapter=x,e.History.HashAdapter=C,e.History.PushStateAdapter=m,e.absoluteURL=c,e.history=new S,window.kendo),f=h.history,P=h.Observable,B="init",R="routeMissing",L="change",z="back",H="same",O=/\((.*?)\)/g,U=/(\(\?)?:\w+/g,A=/\*\w+/g,I=/[\-{}\[\]+?.,\\\^$|#\s]/g;function D(t,e){return e?t:"([^/]+)"}function E(t,e){return new RegExp("^"+t.replace(I,"\\$&").replace(O,"(?:$1)?").replace(U,D).replace(A,"(.*?)")+"$",e?"i":"")}function Q(t){return t.replace(/(\?.*)|(#.*)/g,"")}var T=h.Class.extend({init:function(t,e,n){if(!(t instanceof RegExp))t=E(t,n);this.route=t;this._callback=e},callback:function(t,e,n){var r,i=0,a,o=h.parseQueryStringParams(t);o._back=e;t=Q(t);r=this.route.exec(t).slice(1);a=r.length;if(n)for(;i<a;i++)if(typeof r[i]!=="undefined")r[i]=decodeURIComponent(r[i]);r.push(o);this._callback.apply(null,r)},worksWith:function(t,e,n){if(this.route.test(Q(t))){this.callback(t,e,n);return true}else return false}}),W=P.extend({init:function(t){if(!t)t={};P.fn.init.call(this);this.routes=[];this.pushState=t.pushState;this.hashBang=t.hashBang;this.root=t.root;this.ignoreCase=t.ignoreCase!==false;this.bind([B,R,L,H,z],t)},destroy:function(){f.unbind(L,this._urlChangedProxy);f.unbind(H,this._sameProxy);f.unbind(z,this._backProxy);this.unbind()},start:function(){var e=this,t=function(){e._same()},n=function(t){e._back(t)},r=function(t){e._urlChanged(t)};f.start({same:t,change:r,back:n,pushState:e.pushState,hashBang:e.hashBang,root:e.root});var i={url:f.current||"/",preventDefault:$.noop};if(!e.trigger(B,i))e._urlChanged(i);this._urlChangedProxy=r;this._backProxy=n},route:function(t,e){this.routes.push(new T(t,e,this.ignoreCase))},navigate:function(t,e){h.history.navigate(t,e)},replace:function(t,e){h.history.replace(t,e)},_back:function(t){if(this.trigger(z,{url:t.url,to:t.to}))t.preventDefault()},_same:function(){this.trigger(H)},_urlChanged:function(t){var e=t.url;var n=!!t.decode;var r=t.backButtonPressed;if(!e)e="/";if(this.trigger(L,{url:t.url,params:h.parseQueryStringParams(t.url),backButtonPressed:r})){t.preventDefault();return}var i=0,a=this.routes,o,s=a.length;for(;i<s;i++){o=a[i];if(o.worksWith(e,r,n))return}if(this.trigger(R,{url:e,params:h.parseQueryStringParams(e),backButtonPressed:r}))t.preventDefault()}});return h.Router=W,window.kendo})?r.apply(e,n):r)||(t.exports=e)}});