-
Notifications
You must be signed in to change notification settings - Fork 2
/
easy.min.js
1 lines (1 loc) · 16.1 KB
/
easy.min.js
1
"use strict";(function(e,t){var n=function(){var n=e.$,r=function(e,t){return w(e)?$(document).ready(e):new r.fn.init(e,t)},i=Object.prototype.toString,s=Array.prototype.slice,o=Array.prototype.filter,u=HTMLElement.prototype.webkitMatchesSelector||HTMLElement.prototype.mozMatchesSelector,a=/^#([\w-]+)$/,f=/^\.([\w-]+)$/,l=/^([\w-]+)$/,c=/\s+/,h=/^\s*<(\w+)>/,p=/interactive|complete/,d={tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},v=document.createElement("div"),m=!1,g={},y={},b=function(e){return e===Object(e)},w=function(e){return i.call(e)==="[object Function]"},E=function(e,t){var n=e.length,r=e.length,i=0;if(!t)return;if(t.nodeType)e[n++]=t;else if(typeof t.length=="number")for(var s=t.length;i<s;i++)e[n++]=t[i];e.length=n;for(var o=r;o<n;o++)for(var u=0;u<r;u++)if(e[o]===e[u]){e.splice(o--,1),n--;break}return e},S=function(e,t){return!t||typeof t!="string"?e.nodeType?e:o.call(e,function(e){return e}):(t=t.trim(),e.nodeType===1?u.call(e,t)?e:null:typeof e.length=="number"?o.call(e,function(e){return e&&e.nodeType===1&&u.call(e,t.trim())}):null)},x=function(e){return v.innerHTML=e,s.call(v.childNodes,0).map(function(e){return v.removeChild(e)})},T=function(e){var t,n,r,i;if(r=e.length)for(n=0,r=e.length;n<r;n++)v.appendChild(e[n].cloneNode(!0));else e.nodeType&&v.appendChild(e.cloneNode(!0));return t=v.innerHTML,v.innerHTML="",t},N=function(e,t,n){var r;return typeof e!="string"?r=T(e):r=e,n.each(function(n,i){var s,o,u,a,f,l="insertBefore",c="appendChild",h=!1;if(!i&&typeof e!="string"){switch(t){case"afterend":a=n.parentNode,u=n.nextSibling,f=u?l:c;break;case"beforebegin":a=n.parentNode,u=n,f=l;break;case"afterbegin":a=n,u=n.firstChild,f=l,h=!0;break;case"beforeend":a=n,u=n,f=c}if("length"in e){h&&Array.prototype.reverse.apply(e);for(s=0,o=e.length;s<o;s++)a[f](e[s],u)}else e.nodeType&&a[f](e,u)}else n.insertAdjacentHTML(t,r)})},C=function(e,t){if("length"in e){for(var n=0;n<e.length;n++)if(t.call(e[n],e[n],n,e)===!1)return e}else for(var r in e)if(t.call(e[r],e[r],r,e)===!1)return e;return e},k=function(e){return e.replace(/([A-Z]+)/g,"-$1").toLowerCase()},L=function(e){return e.toLowerCase().replace(/-(\w)/g,function(e,t){return t.toUpperCase()})},A=function(t){var n,r;return y[t]||(n=document.createElement(t),document.body.appendChild(n),r=e.getComputedStyle(n).getPropertyValue("display"),y[t]=r==="none"?"block":r,n.parentNode.removeChild(n)),y[t]};r.prototype=r.fn={constructor:r,length:0,init:function(e,t){var n,i;return e?e.nodeType?(this[0]=e,this.length=1,this):e=="body"?(this[0]=document.body,this.length=1,this):typeof e=="string"?(e=e.trim(),h.test(e)?this.constructor(x(e)):(this.selector=e,(i=e.match(a))?(E(this,document.getElementById(i[1])),this):(t=t?r.isEasy(t)?t:this.constructor(t):this.constructor(document),t.find(e)))):"length"in e?E(this,e):this:this},find:function(e){var t=this.constructor(),n;if(typeof e=="string"){e=e.trim();if(n=e.match(a))E(t,document.getElementById(n[1]));else{var r="querySelectorAll";if(n=e.match(f))r="getElementsByClassName";else if(n=e.match(l))r="getElementsByTagName";this.each(function(i,s){E(t,i[r](n?n[1]:e))})}return t}},children:function(e){var t=this.constructor();return this.each(function(n,r){E(t,S(n.children,e))}),t},parent:function(e){var t=this.constructor();return this.each(function(n,r){E(t,S(n.parentNode,e))}),t},parents:function(e){var t=this.constructor(),n=[];return this.each(function(e,t){var r=e;while((r=r.parentNode)&&r!==document)n.indexOf(r)===-1&&n.push(r)}),E(t,S(n,e)),t},first:function(){var e=this[0];return b(e)?this.constructor(this[0]):e},last:function(){var e=this[this.length-1];return b(e)?this.constructor(e):e},eq:function(e){e=e<0?this.length+e:e;var t=this[e];return b?this.constructor(t):t},closest:function(e,t){var n=this[0];while(n&&!S(n,e))n!==document&&n!==t?n=n.parentNode:n=null;return this.constructor(n)},prev:function(e){var t=this.constructor();return E(t,S(this.pluck("previousElementSibling"),e)),t},next:function(e){var t=this.constructor();return E(t,S(this.pluck("nextElementSibling"),e)),t},siblings:function(e){var t=this.constructor();return this.each(function(n){E(t,S(s.call(n.parentNode.children).filter(function(e){return e!==n}),e))}),t},addClass:function(e){var t,n;return this.length&&e&&typeof e=="string"&&(t=e.split(c),m||(m=!!this[0].classList)?this.each(function(e){for(var n=0,r=t.length;n<r;n++)e.classList.add(t[n])}):this.each(function(r){if(r.nodeType===1)if(!r.className)r.className=e;else{n=" "+r.className+" ";for(var i=0,s=t.length;i<s;i++)~n.indexOf(" "+t[i]+" ")||(n+=t[i]+" ");r.className=n.trim()}})),this},removeClass:function(e){var n,r;if(this.length&&e&&typeof e=="string"||e===t)n=(e||"").trim().split(c),m||(m=!!this[0].classList)?this.each(function(t){if(e)for(var r=0,i=n.length;r<i;r++)t.classList.remove(n[r]);else t.className=""}):this.each(function(t){if(t.nodeType===1&&t.className)if(e){r=(" "+t.className+" ").replace(/[\r\n\t]/g," ");for(var i=0,s=n.length;i<s;i++)r=r.replace(" "+n[i]+" "," ");t.className=r.trim()}else t.className=""});return this},toggleClass:function(e){var t;if(this.length&&typeof e=="string"){t=e.trim().split(c);if(m||(m=!!this[0].classList))this.each(function(e){for(var n=0,r=t.length;n<r;n++)e.classList.toggle(t[n])});else for(var n=0,r=t.length;n<r;n++)this.hasClass(t[n])?this.removeClass(t[n]):this.addClass(t[n])}return this},hasClass:function(e){return typeof e=="string"&&this.length&&this[0].nodeType===1?m||(m=!!this[0].classList)?this[0].classList.contains(e):(g[e]||(g[e]=RegExp("(^|\\s)"+e+"($|\\s)"))).test(this[0].className):!1},access:function(e,n,r){var i=!0,s;if(r===t&&typeof n=="string")i=!1,this.length&&this[0].nodeType===1&&(s=e.call(this[0],this[0],n));else if(b(n))for(var o in n)this.access(e,o,n[o]);else this.each(function(t){e.call(t,t,n,r)});return i?this:s},attr:function(e,n){return this.access(function(e,n,r){return r===t?e.getAttribute(n):(e.setAttribute(n,r),e)},e,n)},removeAttr:function(e){return this.each(function(t){t.nodeType===1&&t.removeAttribute(e)}),this},prop:function(e,n){return e=d[e]||e,this.access(function(e,n,r){return r===t?e[n]:(e[n]=r,e)},e,n)},data:function(e,t){return this.attr("data-"+k(e),t)},empty:function(){return this.each(function(e){e.innerHTML=""})},remove:function(){return this.each(function(e){e.parentNode.removeChild(e)})},text:function(e){return this.access(function(e,n,r){return r===t?e[n]:(e[n]=r,e)},"textContent",e)},html:function(e){return this.access(function(e,n,i){return i===t?e[n]:(typeof i=="string"?e[n]=i:i.nodeType?(e.innerHTML="",e.appendChild(i)):r.isEasy(i)&&(e.innerHTML="",e.appendChild(i[0])),e)},"innerHTML",e)},after:function(e){return N(e,"afterend",this)},append:function(e){return N(e,"beforeend",this)},appendTo:function(e){return r.isEasy(e)?e.append(this):this.constructor(e).append(this),this},before:function(e){return N(e,"beforebegin",this)},prepend:function(e){return N(e,"afterbegin",this)},prependTo:function(e){return r.isEasy(e)?e.prepend(this):this.constructor(e).prepend(this),this},val:function(e){return this.access(function(e,n,i){return i===t?e.multiple?r(o.call(e,function(e){return e.selected})).pluck(n):e[n]:(e[n]=i,e)},"value",e)},css:function(n,r){return this.access(function(n,r,i){return i===t?n.style[L(r)]||e.getComputedStyle(n).getPropertyValue(k(r)):(i===""?n.style.removeProperty(k(r)):n.style.cssText+=";"+k(r)+":"+i+";",n)},n,r)},show:function(){return this.each(function(e){e.style.display=A(this.nodeName)})},hide:function(){return this.css("display","none")},ready:function(e){return p.test(document.readyState)?e():document.addEventListener("DOMContentLoaded",e,!1),this},add:function(e,t){return E(this,this.constructor(e,t))},get:function(e){return e===t?s.call(this):this[e]},pluck:function(e){return this.map(function(t){return t[e]})},each:function(e){return C.call(this,this,e),this},splice:[].splice,map:[].map},r.fn.init.prototype=r.fn;var O=r.extend=function(e,t){for(var n in t)e[n]=t[n];return e};return r.extend(r,{version:"0.1",isEasy:function(e){return e instanceof r},isObject:b,isFunction:w,isArray:Array.isArray||function(e){return i.call(e)==="[object Array]"},"default":function(e,t){for(var n in t)n in e||(e[n]=t[n]);return e},merge:E,each:C,escape:function(e){return(""+e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")},template:function(e){var t=/<%=([\s\S]+?)%>/g,n=/<%-([\s\S]+?)%>/g,r=/<%([\s\S]+?)%>/g,i=/(\r|\n|\t)/g,s="var __p='';__p+='"+e.replace(i,"").replace(t,"'+$1+'").replace(n,function(e,t){return"'+$.escape("+t+")+'"}).replace(r,function(e,t){return"';"+t+"__p+='"})+"';";return s="with(obj||{}){"+s+"} return __p;",new Function("obj",s)}}),r}();e.$=e.Easy=n,typeof define=="function"&&define("easy",[],function(e,t){return n})})(window),function($){function empty(){}function getDataType(e){return e&&(rhtml.test(e)?"html":rjson.test(e)?"json":rxml.test(e)?"xml":rscript.test(e)?"script":"text")}function serialize(e){return $.isObject(e)?$.param(e):e}function appendQuery(e,t){return(e+"&"+t).replace(/[&?]{1,2}/,"?")}var rhtml=/^text\/html/,rjson=/^application\/json/,rxml=/^(application|text)\/xml/,rscript=/^(application|text)\/script/,jsonpCallback=0;$.ajaxSettings={type:"GET",async:!0,before:empty,success:empty,error:empty,timeout:0},$.extend($,{ajax:function(url,options){var headers={},xhr=new XMLHttpRequest,deffered=new $.Deffered,timeout;xhr=deffered.promise(xhr),options=$.default(options||{},$.ajaxSettings);if(options.dataType==="jsonp")return this.jsonp(url,options);options.data&&(options.data=serialize(options.data)),options.data&&options.type.toUpperCase()==="GET"&&(url=appendQuery(url,options.data),delete options.data),xhr.onreadystatechange=function(){var dataType,error,result;if(xhr.readyState===4){clearTimeout(timeout);if(xhr.status>=200&&xhr.status<300||xhr.status==304){dataType=options.dataType||getDataType(xhr.getResponseHeader("content-type")),result=xhr.responseText;try{switch(dataType){case"json":result=/^\s*$/.test(xhr.responseText)?null:JSON.parse(xhr.responseText);break;case"xml":result=xhr.responseXML;break;case"script":(1,eval)(result)}}catch(e){error=e}error?(options.error&&options.error(xhr,"parser error",error),deffered.reject(xhr,"parser error",error)):(options.success&&options.success(result,xhr,options),deffered.resolve(result,error,options))}else options.error&&options.error(xhr,xhr.statusText),deffered.reject(xhr,xhr.statusText)}};if(options.contentType||options.data&&options.type.toUpperCase()!=="GET")headers["Content-Type"]=options.contentType||"application/x-www-form-urlencoded";headers=$.extend(headers,options.headers||{}),xhr.open(options.type.toUpperCase(),url,options.async);for(var key in headers)xhr.setRequestHeader(key,headers[key]);return options.before(xhr,options)===!1?(xhr.abort(),!1):(options.timeout>0&&(timeout=setTimeout(function(){xhr.onreadystatechange=empty,xhr.abort(),options.error&&options.error(xhr,"timeout"),deffered.reject(xhr,"timeout")},options.timeout)),xhr.send(options.data||null),xhr)},get:function(e,t,n){return n===undefined&&(n=t,t=null),this.ajax(e,{success:n,data:t})},post:function(e,t,n){return n===undefined&&(n=t,t=null),this.ajax(e,{type:"POST",success:n,data:t})},jsonp:function(e,t){var n=$.Deffered(),r=n.promise(),i="callback"+jsonpCallback++,s=document.createElement("script"),o;return r.abort=function(){s.parentNode.removeChild(s),i in window&&(window[i]=empty)},window[i]=function(e){t.success&&t.success(e),n.resolve(e),delete window[i]},s.src=e.replace(/=\?/,"="+i),t.timeout>0&&(o=setTimeout(function(){r.abort(),t.error&&t.error(r,"timeout"),n.reject(r,"timeout")},t.timeout)),t.error&&(s.onerror=function(){r.abort(),t.error(r,"error"),n.reject(r,"error")}),document.head.appendChild(s),r},param:function(e){var t=[];for(var n in e)if($.isArray(e[n]))for(var r=0;r<e[n].length;r++)t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n][r]));else t.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t.join("&").replace("%20","+")}})}(Easy),function(e){function t(e,t,n,r){var i,s=[];t=t/1e3+"s",i=" "+t+" "+n;for(var o in e)s.push(o+i);return s.join(",")+";"}var n={fast:200,slow:600},r={Webkit:"webkit",Moz:"",O:"o",ms:"MS"},i=document.createElement("div"),s,o;e.each(r,function(e,t){if(i.style[t+"Transition"]!==undefined)return s="-"+t.toLowerCase()+"-",o=e?e+"TransitionEnd":"transitionend",!1}),e.extend(e.fn,{animate:function(r,i,u,a){var f=this,l,c,h;i=n[i]||i,typeof i!="number"&&(a=u,u=i,i=400);if(e.isFunction(u)||u==undefined)a=u,u="ease";return l=t(r,i,u),r[s+"transition"]=l,h=function(e){typeof a=="function"&&e.done(function(e){a.call(this,e)}),c=function(t){e.resolveWith(f,t),f.unbind(o,c)},f.bind(o,c),setTimeout(function(){f.css(r)},0)},this.queue||(this.queue=e.Queue()),this.queue.add(h),this},fadeIn:function(e,t){return this.css({opacity:0}).show().animate({opacity:1},e,"linear",t)},fadeOut:function(e,t){var n=this;return this.animate({opacity:0},e,"linear",function(e){n.hide(),t.call(this,e)})}})}(Easy),function(e){var t=Array.prototype.slice,n=function(){function e(){}return function(t){return e.prototype=t,new e}}();e.extend(e,{Deffered:function(r){var i=!1,s=!1,o,u,a,f,l={then:function(e,t){return i?e&&e.apply(this,o):s?t&&t.apply(this,u):(e&&(a||(a=[])).push(e),t&&(f||(f=[])).push(t)),this},always:function(e){return this.then(e,e)},done:function(e){return this.then(e)},fail:function(e){return this.then(null,e)},isResolved:function(){return i},isRejected:function(){return s},promise:function(){return this}},c=n(l);return c.resolveWith=function(e){var n=t.call(arguments,1);!i&&!s&&(i=!0,o=n,a&&a.forEach(function(t){t.apply(e,o)}))},c.resolve=function(){var e=t.call(arguments,0);return e.unshift(this),c.resolveWith.apply(this,e)},c.rejectWith=function(e){var n=t.call(arguments,1);!s&&!i&&(s=!0,u=n,f&&f.forEach(function(t){t.apply(e,u)}))},c.reject=function(){var e=t.call(arguments,0);return e.unshift(this),c.rejectWith.apply(this,e)},c.promise=function(t){return e.isObject(t)?e.extend(t,l):l},r&&r.call(c,c),c},when:function(n){var r,i,s,o,u=arguments.length,a=Array(u);return u===1&&e.isFunction(n.promise)?n.promise:(s=function(e){return function(t){a.splice(e,1,t),u--,u||r.resolve.apply(r,a)}},o=function(){r.reject.apply(r,arguments)},i=t.call(arguments,0),i=i.map(function(t,n){var r=!t.promise,i=r?e.Deffered():t;return i.done(s(n)).fail(o),r&&i.resolve(t),i}),r=e.Deffered(),r.promise())},Queue:function(){function r(){var i;t.length?(i=e.Deffered(t.shift()),i.always(r)):n=!1}var t=[],n=!1;return{add:function(i){var s;t.push(i),n||(n=!0,s=e.Deffered(t.shift()),s.always(r))}}}})}(Easy),function(e){function s(e){return e._eid||(e._eid=n++)}function o(e,n,r,i){var o=s(e);return(t[o]||[]).filter(function(e){return e&&e.event==n&&(!i||i===e.selector)&&(!r||r===e||r===e.originalHandler)})}function u(e,n,r,i){var o=s(e);r.event=n,r.selector=i,(t[o]||(t[o]=[])).push(r),e.addEventListener(n,r)}function a(e,n,r,i){var u=t[s(e)];o(e,n,r,i).forEach(function(t){u.splice(u.indexOf(t),1),e.removeEventListener(t.event,t)})}function f(t){var n=e.extend({originalEvent:t},t);return i.forEach(function(e){n[e]=function(){return t[e].apply(t,arguments)}}),n}var t={},n=1,r={},i=["preventDefault","stopImmediatePropagation","stopPropagation"];r.click=r.mousedown=r.mouseup=r.mousemove="MouseEvents",e.Event=function(e,t){var n=document.createEvent(r[e]||"Events"),i=t?!!t.bubbles:!0;return n.initEvent(e,i,!0,null,null,null,null,null,null,null,null,null,null,null,null),n},e.extend(e.fn,{bind:function(e,t){return this.each(function(n){u(n,e,t)})},unbind:function(e,t){return this.each(function(n){a(n,e,t)})},trigger:function(t){var n=e.Event(t);return this.each(function(e){e.dispatchEvent(n)})},delegate:function(t,n,r){return this.each(function(i){var s=function(t){var s,o;if(o=e(t.target).closest(n,i)[0])return s=f(t),s.currentTarget=o,r.call(o,s)};s.originalHandler=r,u(i,t,s,n)})},undelegate:function(e,t,n){return this.each(function(r){a(r,e,n,t)})}}),["focusin","focusout","load","resize","scroll","unload","click","dblclick","mouseup","mousemove","mouseover","mouseout","change","select","keydown","keypress","keyup","error"].forEach(function(t){e.fn[t]=function(e){return this.bind(t,e)}})}(Easy)