1
0
Fork 0
mirror of synced 2024-07-04 14:10:33 +12:00
appwrite/public/scripts/litespeed.js

1 line
14 KiB
JavaScript
Raw Normal View History

2019-05-09 18:54:39 +12:00
"use strict";var container=function(){var e=[],t={context:"",of:""},r=function(t,r,n,o){if("string"!=typeof t)throw new Error("var name must be of type string");if("function"!=typeof r&&"object"!=typeof r)throw new Error('var object "'+t+'" must be of type function or object');if("boolean"!=typeof n)throw new Error('var singelton "'+t+'" must be of type boolean');return o&&window.localStorage.setItem(t,JSON.stringify(r)),e[t]={name:t,object:r,singleton:n,instance:null},this},n={},o=function(t){var r=void 0!==e[t]?e[t]:null;if(null===r){if(n[t])return n[t];var o=window.localStorage.getItem(t);return o?(o=JSON.parse(o),n[t]=o,o):null}if(null===r.instance){var a="function"==typeof r.object?this.resolve(r.object):r.object;return r.singleton&&(r.instance=a),a}return r.instance},a=function(e){var t=this,r=/^function\s*[^\(]*\(\s*([^\)]*)\)/m,n=e.toString(),o=n.match(r)[1].split(",");return e.apply(e,o.map(function(e){return t.get(e.trim())}))},i=function(e){function t(){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}(function(e,r){e=e.replace(t.of,t.context).split(".");for(var n=this.get(e.shift());e.length>1;){if(void 0==n)return null;n=n[e.shift()]}if(void 0!==r)return n[e.shift()]=r;if(void 0==n)return null;var o=e.shift();return void 0==o?n:n[o]}),s=function(){return t},l=function(e,r){return t={context:e,of:r},this},c={set:r,get:o,resolve:a,path:i,setScope:l,getScope:s};return r("container",c,!0),c}();container.set("http",function(e){var t=[],r=[],n=function(t,r,n){var o,a=e.createElement("a"),i=/(?:\?|&amp;|&)+([^=]+)(?:=([^&]*))*/g,s=[];for(a.href=t,r=encodeURIComponent(r);o=i.exec(a.search);)r!=o[1]&&s.push(o[1]+(o[2]?"="+o[2]:""));return s.push(r+(n?"="+encodeURIComponent(n):"")),a.search=s.join("&"),a.href},o=function(o,a,i,s,l){var c;if(-1==["GET","POST","PUT","DELETE","TRACE","HEAD","OPTIONS","CONNECT","PATCH"].indexOf(o))throw new Error("var method must contain a valid HTTP method name");if("string"!=typeof a)throw new Error("var url must be of type string");if("object"!=typeof i)throw new Error("var headers must be of type object");if("string"!=typeof a)throw new Error("var url must be of type string");for(c=0;c<t.length;c++)a=n(a,t[c].key,t[c].value);return new Promise(function(t,n){var u=new XMLHttpRequest;for(u.open(o,a,!0),u.setRequestHeader("Ajax","1"),c=0;c<r.length;c++)u.setRequestHeader(r[c].key,r[c].value);for(var p in i)i.hasOwnProperty(p)&&u.setRequestHeader(p,i[p]);u.onload=function(){4==u.readyState&&200==u.status?t(u.response):(e.dispatchEvent(new CustomEvent("http-"+o.toLowerCase()+"-"+u.status)),n(new Error(u.statusText)))},l&&(u.addEventListener("progress",l),u.upload.addEventListener("progress",l,!1)),u.onerror=function(){n(new Error("Network Error"))},u.send(s)})};return{get:function(e){return o("GET",e,{},"")},post:function(e,t,r){return o("POST",e,t,r)},put:function(e,t,r){return o("PUT",e,t,r)},"delete":function(e){return o("DELETE",e,{},"")},addGlobalParam:function(e,r){t.push({key:e,value:r})},addGlobalHeader:function(e,t){r.push({key:e,value:t})}}},!0),container.set("cookie",function(e){function t(t){var r="; "+e.cookie,n=r.split("; "+t+"=");return 2==n.length?n.pop().split(";").shift():void 0}function r(t,r,n){var o=new Date;o.setTime(o.getTime()+24*n*60*60*1e3);var a="expires="+o.toUTCString();e.cookie=t+"="+r+";"+a+";path=/"}return{get:t,set:r}},!0),String.prototype.replaceAll=function(e,t){var r=this;return r.replace(new RegExp(e,"g"),t)},Object.path=function(e,t,r){for(t=t.split(".");t.length>1;){if(void 0==e)return null;e=e[t.shift()]}return void 0!==r?e[t.shift()]=r:void 0==e?null:e[t.shift()]},Array.prototype.includes||(Array.prototype.includes=function(e){if(null==this)throw new TypeError("Array.prototype.includes called on null or undefined");var t=Object(this),r=parseInt(t.length,10)||0;if(0===r)return!1;var n,o=parseInt(arguments[1],10)||0;o>=0?n=o:(n=r+o,0>n&&(n=0));for(var a;r>n;){if(a=t[n],e===a||e!==e&&a!==a)return!0;n++}return!1}),container.set("view",function(e,t){var r={},n=function(e,t,r,n,o){(!t.$lsStop||o)&&(r.set("element",t,!0),