forked from NxtChg/pieces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjslib.min.js
1 lines (1 loc) · 2.27 KB
/
jslib.min.js
1
function defined(t){return void 0!==t&&null!==t}var js={};js.$=function(t){return document.getElementById(t)},js.is_array=function(t){return t&&t.constructor===Array},js.cb=function(t,n){return function(){return n.apply(t,arguments)}},js.count=function(t){var n=0;if(defined(t.length))return t.length;for(var e in t)t.hasOwnProperty(e)&&n++;return n},js.clone=function(t){if(null===t||"object"!=typeof t)return t;for(var n=arguments,e=new t.constructor,o=0;o<n.length;o++)for(var r in n[o])n[o].hasOwnProperty(r)&&(e[r]=js.clone(n[o][r]));return e},js.encode_utf8=function(t){return unescape(encodeURIComponent(t))},js.decode_utf8=function(t){return decodeURIComponent(escape(t))},js.round=function(t,n,e){var o=t<0,r=Math.pow(10,n),i=Math.abs(t)*r;return i=e?Math.floor(i):Math.round(i),(o?-i:i)/r},js.round_sig=function(t,n){return js.round(t,n-Math.floor(Math.log10(Math.abs(t)))-1)},String.prototype.trim=String.prototype.trim||function(){return this.replace(/(^\s+)|(\s+$)/g,"")},window.escape=window.escape||function(t){return t.replace(/[^\w@\*\-\+\.\/]/g,function(t){return t="000"+t.charCodeAt(0).toString(16).toUpperCase(),t.length<6?"%"+t.slice(-2):"%u"+t.slice(-4)})},window.unescape=window.unescape||function(t){return t.replace(/%u([\da-f]{4})|%([\da-f]{2})/gi,function(t,n,e){return String.fromCharCode(parseInt(n||e,16))})},Math.log2=Math.log2||function(t){return Math.log(t)*Math.LOG2E},Math.log10=Math.log10||function(t){return Math.log(t)*Math.LOG10E},js.get_cookie=function(t){for(var n=document.cookie.split(";"),e=0;e<n.length;e++){for(var o=n[e],r=-1;o.charCodeAt(++r)<33;);if(o.indexOf(t+"=",r)==r)return decodeURIComponent(o.substr(r+t.length+1))}},js.set_cookie=function(t,n,e,o){var r=encodeURIComponent,i=r(n);if(e){var u=new Date;u.setDate(u.getDate()+e),i+="; expires="+u.toUTCString()}o&&(i+="; path="+o),document.cookie=r(t)+"="+i},js.check_cookies=function(){var t="testcookie";if(js.set_cookie(t,1),navigator.cookieEnabled&&js.get_cookie(t))return js.set_cookie(t,"",-1),!0},js.debounce=function(t,n){return function(){clearTimeout(this.timer);var e=this,o=arguments;this.timer=setTimeout(function(){t.apply(e,o)},n)}},js.throttle=function(t,n,e){return function(){if(!this.timer){var o=this,r=arguments;e&&t.apply(o,r),this.timer=setTimeout(function(){o.timer=null,t.apply(o,r)},n)}}};