-
Notifications
You must be signed in to change notification settings - Fork 2
/
pjax-router.min.js
1 lines (1 loc) · 2.71 KB
/
pjax-router.min.js
1
var Pjax=Pjax||{};!function(){Pjax.Config=function(){var t={matchBehaviour:"single"},e={matchBehaviour:function(e){if("single"!=e&&"all"!=e)throw new Error("Invalid value for router match behaviour. Available options are: single, all.");t.matchBehaviour=e}},n=function(e){return t[e]},r=function(n,r){if(e[n])e[n](r);else{if(!t[n])throw new Error("Setting ["+n+"] is not configurable.");t[n]=r}};return{get:n,set:r}}()}(),function(){Pjax.Eventer=function(t){var e=function(e,n){t(document).on(e,n)},n=function(t,e){return t(e)},r=function(t,e,r){for(var o=Pjax.Utility.determineHttpVerb(t,e),i=Pjax.Router.match(e.url,o,r),a=0;a<i.length;a++){var u={xhr:t,options:e,route:i[a]};return n(i[a].handler,u)}};return e("pjax:start",function(t,e,n){r(e,n,"before")}),e("pjax:end",function(t,e,n){r(e,n,"after")}),{listen:e}}()}(jQuery),function(){Pjax.Request=function(t,e){this.xhr=t,this.options=e,this.headers=t.headers,this.data=e.data,this.method=Pjax.Utility.determineHttpVerb(t,e),this.url=e.url}}(),function(){Pjax.Response=function(t,e){this.xhr=t,this.headers=t.headers,this.request=e,this.content=this.isJSON()?JSON.decode(t.response):t.response,this.isJSON=function(){return"json"==t.response},this.isHTML=function(){return!this.isJSON()}}}(),function(){Pjax.Route=function(t,e,n,r){if("string"!=typeof t)throw new Error("You must provide the pattern argument as a string when registering a new Route object.");if("string"!=typeof e)throw new Error("You must provide the method argument as a string when registering a new Route object.");if("function"!=typeof n)throw new Error("You must provide the handler argument as a function callback when registering a new Route object.");r=r||{when:"after"};var o=function(t){var e=t.replace(/:any/gi,"(.*)").replace(/:id/gi,"([0-9]+)").replace(/:alphanum/gi,"([a-z0-9\\-]+)").replace(/:alpha/gi,"([a-z\\-]+)").replace(/:(?=\/)+/gi,"([^/]+)"),n=e+"\\/?$";return new RegExp(n)},i=function(t,e,n){return n=n||"after",u.method==e&&u.options&&u.options.when==n?u.regex.test(t):!1},a=o(t),u={pattern:t,regex:a,method:e,handler:n,options:r,matches:i};return u}}(),function(){Pjax.Router=function(){var t=[],e=function(t,e,n){i(t,"get",e,n)},n=function(t,e,n){i(t,"post",e,n)},r=function(t,e,n){i(t,"delete",e,n)},o=function(t,e,n){i(t,"put",e,n)},i=function(e,n,r,o){t.push(Pjax.Route(e,n,r,o))},a=function(e,n,r){for(var o=[],i=0;i<t.length&&(!t[i].matches(e,n,r)||(o.push(t[i]),"single"!=Pjax.Config.get("matchBehaviour")));i++);return o},u=function(){t=[]},s=function(){return t};return{clear:u,get:e,post:n,put:o,del:r,"delete":r,match:a,getRoutes:s}}()}(),function(){Pjax.Utility=function(){var t=function(t,e){var n=e.type;return e.data&&e.data._method&&(n=e.data._method),n.toLowerCase()};return{determineHttpVerb:t}}()}();