-
Notifications
You must be signed in to change notification settings - Fork 11
/
phonebook.min.js
1 lines (1 loc) · 1.3 KB
/
phonebook.min.js
1
!function(e,t){if(typeof module!="undefined")module.exports=t();else if(typeof define=="function"&&typeof define.amd=="object")define(t);else this[e]=t()}("Phonebook",function(){function e(e){this.url=e.url||"";this.options=e.options||{};this.data=e.data||{};this.parent=e.parent||null}e.prototype={define:function(e){var t=e.name;var n=e.url;var r=e.type;var i=e.data;var s=e.options;var o;if(o=!this[t]){this[t]=function(e,t){return this.request(r,n,jQuery.extend(i,e),jQuery.extend(s,t))}}return o},request:function(e,t,n,r){n=n||{};r=r||{};return jQuery.ajax(jQuery.extend(this.buildHash("options",r),{url:this.getURL()+t,type:e,data:this.buildHash("data",n)}))},getURL:function(){var e="";if(this.parent){e=this.parent.getURL()}return(e+this.url).replace(/[\/]+/gi,"/")},buildHash:function(e,t){var n=this[e];if(typeof t=="function"){t=t.bind(t)()}if(this.parent){n=this.parent.buildHash(e,n)}return jQuery.extend({},n,t)},addChapter:function(t){var n;var r=t.name;if(n=!this[r]){this[r]=e.open(jQuery.extend(t,{parent:this}))}return n},get:function(e,t,n){return this.request("GET",e,t,n)},post:function(e,t,n){return this.request("POST",e,t,n)},put:function(e,t,n){return this.request("PUT",e,t,n)},destroy:function(e,t,n){return this.request("DELETE",e,t,n)}};e.open=function(t){return new e(t)};e.version="1.0";return e})