forked from bendc/sprint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsprint.min.js
1 lines (1 loc) · 16.5 KB
/
sprint.min.js
1
(function(){"use strict";var t,e,n,i,r=window.document,o=function(t,e){for(var n=z(e),i=Object.keys(t),r=i.length,o=0;o<r;++o)for(var s=i[o],h=t[s],f=h.length,u=0;u<f;++u)n.on(s,h[u])},s=(t=["animation-iteration-count","column-count","flex-grow","flex-shrink","font-weight","line-height","opacity","order","orphans","widows","z-index"],function(e,n){if(g(e,t))return n;var i=b(n)?n:n.toString();return n&&!/\D/.test(i)&&(i+="px"),i}),h=function(t,e,n){return function(i){z(i.target).closest(e,n).size()&&t.apply(i.target,arguments)}},f={afterbegin:function(t){this.insertBefore(t,this.firstChild)},afterend:function(t){var e=this.parentElement;e&&e.insertBefore(t,this.nextSibling)},beforebegin:function(t){var e=this.parentElement;e&&e.insertBefore(t,this)},beforeend:function(t){this.appendChild(t)}},u=function(t,e){if(!(t.nodeType>1)){(h=l(t))&&o(h,e);for(var n,i=k("*",t),r=i.length,s=0;s<r;++s){var h;(h=l(i[s]))&&(n||(n=k("*",e)),o(h,n[s]))}}},a=function(t,e,n,i,r){var o=[],s=this;return this.each(function(){for(var h=t?this.parentElement:this;h&&(!r||r!==h)&&(i&&!s.is(i,h)||(o.push(h),!n))&&!e;)h=h.parentElement}),z(C(o))},c=function(t){return M(t)[0]},l=function(t){return t.sprintEventListeners},p=function(t,e){return Object.keys(l(t)).filter(function(t){return M(e).every(function(e){return g(e,M(t))})})},v=function(t,e,n){if(void 0===n){var i=t.get(0);if(!i||i.nodeType>1&&9!==i.nodeType)return;var o=e[0].toUpperCase()+e.substring(1);return i===r?Math.max(i.body["scroll"+o]||0,i.body["offset"+o]||0,x["scroll"+o]||0,x["offset"+o]||0):i===window?window["inner"+o]:i.getBoundingClientRect()[e]}var h=m(n),f=h?"":s(e,n);return t.each(function(t){this===r||this===window||this.nodeType>1||(h&&(f=s(e,n.call(this,t,z(this)[e]()))),this.style[e]=f)})},d=function(t,e){var n=e.length,i=e,o=n;if(n>1&&t.indexOf("after")>-1)for(i=[],o=n;o--;)i.push(e[o]);for(o=0;o<n;++o){var s=i[o],h=typeof s;if("string"===h||"number"===h)this.each(function(){this.insertAdjacentHTML(t,s)});else{if("function"!==h){var a=s instanceof H,c=[],l=a?s.get():Array.isArray(s)?j(s,!0,!0):s.nodeType?[s]:O(s),p=l.length;if(this.each(function(e){for(var n=r.createDocumentFragment(),i=0;i<p;++i){var o,s=l[i];e?(o=s.cloneNode(!0),u(s,o)):o=s,n.appendChild(o),c.push(o)}f[t].call(this,n)}),a&&(s.dom=c,s.length=c.length),o<n-1)continue;return c}this.each(function(e){var n=s.call(this,e,this.innerHTML);d.call(z(this),t,[n])})}}},g=function(t,e){for(var n=e.length;n--;)if(e[n]===t)return!0;return!1},y=function(t){return/\./.test(t)},m=function(t){return"function"==typeof t},b=function(t){return"string"==typeof t},T=function(t,e,n){return void 0===e?"add"===t?this:this.removeAttr("class"):(b(e)&&(i=!0,r=e.trim().split(" "),o=r.length),this.each(function(s,h){if(!(this.nodeType>1)){if(!i){var f=e.call(h,s,h.className);if(!f)return;r=f.trim().split(" "),o=r.length}for(var u=0;u<o;++u){var a=r[u];a&&(void 0===n?h.classList[t](a):h.classList.toggle(a,n))}}}));var i,r,o},w=(function(){for(var t=["mozMatchesSelector","webkitMatchesSelector","msMatchesSelector","matches"],e=t.length;e--;){var n=t[e];if(Element.prototype[n])return n}})(),C=function(t){for(var e=[],n=0,i=t.length,r=0;r<i;++r){for(var o=t[r],s=!1,h=0;h<n;++h)if(o===e[h]){s=!0;break}s||(e[n++]=o)}return e},E=(e=function(t,e,n){return function(i){n&&n!==i||(t.removeEventListener(e,i),y(e)&&!(function(t,e,n){return!(Object.keys(l(t)).filter(function(t){return c(e)===c(t)}).map(function(e){return l(t)[e]}).reduce(function(t,e){return t.concat(e)}).filter(function(t){return t===n}).length<2)})(t,e,i)&&t.removeEventListener(c(e),i))}},function(t,n){return function(i){l(t)[i].forEach(e(t,i,n)),l(t)[i]=(function(t,e){return t.filter(function(t){return e&&e!==t})})(l(t)[i],n)}}),x=r.documentElement,j=function(t,e,n){for(var i=t.length,o=i;o--;)if(!t[o]&&0!==t[o]||e&&t[o]instanceof H||n&&(b(t[o])||"number"==typeof t[o])){for(var s=[],h=0;h<i;++h){var f=t[h];if(f||0===f)if(e&&f instanceof H)for(var u=0;u<f.length;++u)s.push(f.get(u));else{var a=typeof f;!n||"string"!==a&&"number"!==a?s.push(f):s.push(r.createTextNode(f))}}return s}return t},A=function(t,e,i){if(!n){var o=x.scrollTop;x.scrollTop=o+1;var s=x.scrollTop;x.scrollTop=o,n=s>o?x:r.body}if(void 0===i){var h=t.get(0);if(!h)return;return h!==window&&h!==r||(h=n),h[e]}return t.each(function(){var t=this;t!==window&&t!==r||(t=n),t[e]=i})},L=function(t,e,n,i){var r=[],o=e+"ElementSibling";return t.each(function(){for(var e=this;(e=e[o])&&(!i||!t.is(i,e));)n&&!t.is(n,e)||r.push(e)}),z(C(r))},S=function(t,e,n){var i=e+"ElementSibling";return t.map(function(){var e=this[i];if(e&&(!n||t.is(n,e)))return e},!1)},k=function(t,e){if(e=e||r,/^[\#.]?[\w-]+$/.test(t)){var n=t[0];if("."===n)return O(e.getElementsByClassName(t.slice(1)));if("#"===n){var i=void 0!==e.getElementById?e.getElementById(t.slice(1)):e.querySelector(t);return i?[i]:[]}return"body"===t?[r.body]:"head"===t?[r.head]:O(e.getElementsByTagName(t))}return O(e.querySelectorAll(t))},M=function(t){return j(t.split("."))},O=function(t){for(var e=[],n=t.length;n--;)e[n]=t[n];return e},B=(i=function(t,e){var n=z(t).clone(!0).get(0),i=n;if(n&&!(this.nodeType>1)){for(;i.firstChild;)i=i.firstChild;if("inner"===e){for(;this.firstChild;)i.appendChild(this.firstChild);this.appendChild(n)}else{var r="all"===e?this.get(0):this,o=r.parentNode,s=r.nextSibling;"all"===e?this.each(function(){i.appendChild(this)}):i.appendChild(r),o.insertBefore(n,s)}}},function(t,e){return"function"==typeof t?this.each(function(n){z(this)["inner"===e?"wrapInner":"wrap"](t.call(this,n))}):"all"===e?i.call(this,t,e):this.each(function(){i.call(this,t,e)}),this}),N={legend:{intro:"<fieldset>",outro:"</fieldset>"},area:{intro:"<map>",outro:"</map>"},param:{intro:"<object>",outro:"</object>"},thead:{intro:"<table>",outro:"</table>"},tr:{intro:"<table><tbody>",outro:"</tbody></table>"},col:{intro:"<table><tbody></tbody><colgroup>",outro:"</colgroup></table>"},td:{intro:"<table><tbody><tr>",outro:"</tr></tbody></table>"}};["tbody","tfoot","colgroup","caption"].forEach(function(t){N[t]=N.thead}),N.th=N.td;var H=function(t,e){if(b(t))"<"===t[0]?this.dom=[(function(t){var e=r.createElement("div"),n=/[\w:-]+/.exec(t)[0],i=N[n],o=t.trim();i&&(o=i.intro+o+i.outro),e.insertAdjacentHTML("afterbegin",o);var s=e.lastChild;if(i)for(var h=i.outro.match(/</g).length;h--;)s=s.lastChild;return e.textContent="",s})(t)]:this.dom=e&&e instanceof H?e.find(t).get():k(t,e);else if(Array.isArray(t))this.dom=j(t);else if(t instanceof NodeList||t instanceof HTMLCollection)this.dom=O(t);else{if(t instanceof H)return t;if("function"==typeof t)return this.ready(t);this.dom=t?[t]:[]}this.length=this.dom.length};H.prototype={add:function(t){for(var e=this.get(),n=z(t),i=n.get(),r=0;r<n.length;++r)e.push(i[r]);return z(C(e))},addClass:function(t){return T.call(this,"add",t)},after:function(){return d.call(this,"afterend",arguments),this},append:function(){return d.call(this,"beforeend",arguments),this},appendTo:function(t){return z(d.call(z(t),"beforeend",[this]))},attr:function(t,e){var n=typeof e,i="function"===n;if("string"===n||"number"===n||i)return this.each(function(n){this.nodeType>1||this.setAttribute(t,i?e.call(this,n,this.getAttribute(t)):e)});if("object"===n){var r=Object.keys(t),o=r.length;return this.each(function(){if(!(this.nodeType>1))for(var e=0;e<o;++e){var n=r[e];this.setAttribute(n,t[n])}})}var s=this.get(0);if(s&&!(s.nodeType>1)){var h=s.getAttribute(t);if(null!==h)return h||t}},before:function(){return d.call(this,"beforebegin",arguments),this},children:function(t){var e=[],n=this;return this.each(function(){if(!(this.nodeType>1))for(var i=this.children,r=i.length,o=0;o<r;++o){var s=i[o];t&&!n.is(t,s)||e.push(s)}}),z(e)},clone:function(t){return this.map(function(){if(this){var e=this.cloneNode(!0);return t&&u(this,e),e}},!1)},closest:function(t,e){return a.call(this,!1,!1,!0,t,e)},css:function(t,e){var n=typeof e,i="string"===n;if(i||"number"===n){var r=i&&/=/.test(e);if(r)var o=parseInt(e[0]+e.slice(2));return this.each(function(){if(!(this.nodeType>1)){if(r)var n=parseInt(getComputedStyle(this).getPropertyValue(t))+o;this.style[t]=s(t,r?n:e)}})}if("function"===n)return this.each(function(n){if(!(this.nodeType>1)){var i=getComputedStyle(this).getPropertyValue(t);this.style[t]=e.call(this,n,i)}});if("string"==typeof t){if(!(h=this.get(0))||h.nodeType>1)return;return getComputedStyle(h).getPropertyValue(t)}if(Array.isArray(t)){var h;if(!(h=this.get(0))||h.nodeType>1)return;for(var f={},u=getComputedStyle(h),a=t.length,c=0;c<a;++c){var l=t[c];f[l]=u.getPropertyValue(l)}return f}var p=Object.keys(t),v=p.length;return this.each(function(){if(!(this.nodeType>1))for(var e=0;e<v;++e){var n=p[e];this.style[n]=s(n,t[n])}})},detach:function(){return this.map(function(){var t=this.parentElement;if(t)return t.removeChild(this),this},!1)},each:function(t){for(var e=this.dom,n=this.length,i=0;i<n;++i){var r=e[i];if(!1===t.call(r,i,r))break}return this},empty:function(){return this.each(function(){this.innerHTML=""})},eq:function(t){return z(this.get(t))},filter:function(t){var e=m(t),n=this;return this.map(function(i){if(!(this.nodeType>1||!e&&!n.is(t,this)||e&&!t.call(this,i,this)))return this},!1)},find:function(t){if("string"==typeof t){var e=[];return this.each(function(){if(!(this.nodeType>1))for(var n=k(t,this),i=n.length,r=0;r<i;++r)e.push(n[r])}),z(C(e))}for(var n=t.nodeType?[t]:t.get(),i=n.length,r=[],o=0,s=0;s<this.length;++s){var h=this.get(s);if(!(h.nodeType>1))for(var f=0;f<i;++f){var u=n[f];if(h.contains(u)&&(r[o++]=u,!(o<i)))return z(r)}}return z(r)},first:function(){return this.eq(0)},get:function(t){return void 0===t?this.dom:(t<0&&(t+=this.length),this.dom[t])},has:function(t){if("string"==typeof t)return this.map(function(){if(!(this.nodeType>1)&&k(t,this)[0])return this},!1);for(var e=[],n=this.length;n--;){var i=this.get(n);if(i.contains(t)){e.push(i);break}}return z(e)},hasClass:function(t){for(var e=this.length;e--;){var n=this.get(e);if(n.nodeType>1)return;if(n.classList.contains(t))return!0}return!1},height:function(t){return v(this,"height",t)},html:function(t){if(void 0===t){var e=this.get(0);if(!e)return;return e.innerHTML}return m(t)?this.each(function(e){var n=t.call(this,e,this.innerHTML);z(this).html(n)}):this.each(function(){this.innerHTML=t})},index:function(t){if(this.length){var e,n;t?"string"==typeof t?(e=this.get(0),n=z(t)):(e=t instanceof H?t.get(0):t,n=this):(e=this.get(0),n=this.first().parent().children());for(var i=n.get(),r=i.length;r--;)if(i[r]===e)return r;return-1}},insertAfter:function(t){return z(t).after(this),this},insertBefore:function(t){return z(t).before(this),this},is:function(t,e){var n=e?[e]:this.get(),i=n.length,r=typeof t;if("string"===r){for(var o=0;o<i;++o){var s=n[o];if(!(s.nodeType>1)&&s[w](t))return!0}return!1}if("object"===r){var h,f=(h=t instanceof H?t.get():t.length?t:[t]).length;for(o=0;o<i;++o)for(var u=0;u<f;++u)if(n[o]===h[u])return!0;return!1}if("function"===r){for(o=0;o<i;++o)if(t.call(this,o,this))return!0;return!1}},last:function(){return this.eq(-1)},map:function(t,e){void 0===e&&(e=!0);for(var n=this.get(),i=this.length,r=[],o=0;o<i;++o){var s=n[o],h=t.call(s,o,s);if(e&&Array.isArray(h))for(var f=h.length,u=0;u<f;++u)r.push(h[u]);else r.push(h)}return z(r)},next:function(t){return S(this,"next",t)},nextAll:function(t){return L(this,"next",t)},nextUntil:function(t,e){return L(this,"next",e,t)},not:function(t){var e=m(t),n=this;return this.map(function(i){if(e){if(t.call(this,i,this))return}else if(n.is(t,this))return;return this},!1)},off:function(t,e){return"object"==typeof t?(Object.keys(t).forEach(function(e){this.off(e,t[e])},this),this):(t&&(t=t.trim().split(" ")),this.each(function(){var n,i;l(this)&&(t?t.forEach((n=this,i=e,function(t){p(n,t).forEach(E(n,i))})):Object.keys(l(this)).forEach(E(this)))}))},offset:function(t){if(!t){var e=this.get(0);if(!e||e.nodeType>1)return;var n=e.getBoundingClientRect();return{top:n.top+window.pageYOffset,left:n.left+window.pageXOffset}}return"object"==typeof t?this.each(function(){if(!(this.nodeType>1)){var e=z(this);"static"===e.css("position")?e.css("position","relative"):e.css({top:0,left:0});var n=e.offset();e.css({top:t.top-n.top+"px",left:t.left-n.left+"px"})}}):m(t)?this.each(function(e){var n=z(this),i=t.call(this,e,n.offset());n.offset(i)}):void 0},offsetParent:function(){var t=[];return this.each(function(){if(!(this.nodeType>1)){for(var e=this;e!=x;){e=e.parentNode;var n=getComputedStyle(e).getPropertyValue("position");if(!n)break;if("static"!==n)return void t.push(e)}t.push(x)}}),z(t)},on:function(t,e,n,i){if("string"!=typeof e&&(n=e,e=null),n){var r=null!=e;r&&(n=h(n,e));var o=t.trim().split(" ");return this.each(function(){r&&(n=h(n,e,this)),l(this)||(this.sprintEventListeners={}),o.forEach(function(t){var e=l(this)[t];e||(e=[]),e.push(n),this.addEventListener(t,n,i),y(t)&&this.addEventListener(c(t),n,i)},this)})}return Object.keys(t).forEach(function(e){this.on(e,t[e])},this),this},parent:function(t){return a.call(this,!0,!0,!1,t)},parents:function(t){return a.call(this,!0,!1,!1,t)},position:function(){var t=this.offset(),e=this.parent().offset();if(t)return{top:t.top-e.top,left:t.left-e.left}},prop:function(t,e){if("object"==typeof t){var n=Object.keys(t),i=n.length;return this.each(function(){for(var e=0;e<i;++e){var r=n[e];this[r]=t[r]}})}if(void 0===e){var r=this.get(0);if(!r)return;return r[t]}var o=m(e);return this.each(function(n){this[t]=o?e.call(this,n,this[t]):e})},prepend:function(){return d.call(this,"afterbegin",arguments),this},prependTo:function(t){return z(d.call(z(t),"afterbegin",[this]))},prev:function(t){return S(this,"previous",t)},prevAll:function(t){return L(this,"previous",t)},prevUntil:function(t,e){return L(this,"previous",e,t)},ready:function(t){return this.dom=[r],this.length=1,this.on("DOMContentLoaded",t)},remove:function(t){var e=this;return this.each(function(){var n=this.parentElement;n&&(t&&!e.is(t,this)||n.removeChild(this))})},removeAttr:function(t){if(t){var e=t.trim().split(" "),n=e.length;this.each(function(){if(!(this.nodeType>1))for(var t=0;t<n;++t)this.removeAttribute(e[t])})}return this},removeClass:function(t){return T.call(this,"remove",t)},removeProp:function(t){return this.each(function(){this[t]=void 0})},replaceAll:function(t){return z(t).replaceWith(this),this},replaceWith:function(t){return m(t)?this.each(function(e){z(this).replaceWith(t.call(this,e,this))}):this.before(t).remove()},scrollLeft:function(t){return A(this,"scrollLeft",t)},scrollTop:function(t){return A(this,"scrollTop",t)},siblings:function(t){var e=[],n=this;return this.each(function(i,r){z(this).parent().children().each(function(){this===r||t&&!n.is(t,this)||e.push(this)})}),z(e)},size:function(){return this.length},slice:function(t,e){var n=this.get(),i=[],r=t>=0?t:t+this.length,o=this.length;for(e<0?o+=e:e>=0&&(o=e>this.length?this.length:e);r<o;++r)i.push(n[r]);return z(i)},text:function(t){if(void 0===t){var e=[];return this.each(function(){e.push(this.textContent)}),e.join("")}var n=m(t);return this.each(function(e){this.textContent=n?t.call(this,e,this.textContent):t})},toggleClass:function(t,e){return T.call(this,"toggle",t,e)},trigger:function(t){if(!window.CustomEvent||"function"!=typeof window.CustomEvent){var e=function(t,e){var n;return e=e||{bubbles:!1,cancelable:!1,detail:void 0},(n=r.createEvent("CustomEvent")).initCustomEvent(t,e.bubbles,e.cancelable,e.detail),n};e.prototype=window.Event.prototype,window.CustomEvent=e}return this.each(function(){p(this,t).forEach(function(t){this.dispatchEvent(new e(t,{bubbles:!0,cancelable:!0}))},this)})},unwrap:function(){return this.parent().each(function(){this!==r.body&&this!==x&&z(this).replaceWith(this.childNodes)}),this},val:function(t){if(void 0===t){var e=this.get(0);if(!e)return;if(e.multiple){var n=[];return this.first().children(":checked").each(function(){n.push(this.value)}),n}return e.value}if(Array.isArray(t)){var i=this;return this.each(function(){this.multiple?i.children().each(function(){this.selected=g(this.value,t)}):this.checked=g(this.value,t)})}return m(t)?this.each(function(e){z(this).val(t.call(this,e,this.value))}):this.each(function(){this.value=t})},width:function(t){return v(this,"width",t)},wrap:function(t){return B.call(this,t)},wrapAll:function(t){return B.call(this,t,"all")},wrapInner:function(t){return B.call(this,t,"inner")}};for(var P=["blur","focus","resize","scroll","click","change","select","submit","ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],I=0;I<P.length;++I){var q=P[I];H.prototype[q]=function(t){return this.on(q,t)}}var z=function(t,e){return new H(t,e)};z.fn=H.prototype,"function"==typeof define&&define.amd?define(function(){return z}):"undefined"!=typeof module&&module.exports?module.exports=z:(this.Sprint=z,void 0===this.$&&(this.$=z),void 0===this.jQuery&&(this.jQuery=z))}).call(this);