microbejs
Version:
microbe.js - A modular JS library for DOM manipulation, and more
2 lines • 13.9 kB
JavaScript
/*! Microbe v0.5.2 | (c) 2014-2016 Sociomantic Labs | http://m.icro.be/license */
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.µ=t()}}(function(){return function t(e,r,n){function i(c,u){if(!r[c]){if(!e[c]){var f="function"==typeof require&&require;if(!u&&f)return f(c,!0);if(o)return o(c,!0);var s=new Error("Cannot find module '"+c+"'");throw s.code="MODULE_NOT_FOUND",s}var a=r[c]={exports:{}};e[c][0].call(a.exports,function(t){var r=e[c][1][t];return i(r?r:t)},a,a.exports,t,e,r,n)}return r[c].exports}for(var o="function"==typeof require&&require,c=0;c<n.length;c++)i(n[c]);return i}({1:[function(t,e,r){"use strict";var n="[object Microbe]",i=t("./version")+"-selectorEngine",o=function(t,e,r){return new o.core.__init__(t,e,r)};t("./selectorEngine/init")(o,n,i),e.exports=o.core.constructor=o},{"./selectorEngine/init":4,"./version":7}],2:[function(t,e,r){"use strict";var n=function(){var t=arguments[0],e=arguments[1]>>0,r=Object(this),n=this.length>>0;if(0===n)return!1;for(e=e>=0?e:e+n,e=0>e?0:e;n>e;){if(t===r[e]||r[e]!==r[e]&&t!==t)return!0;e++}return!1};e.exports=function(t){t.core.every=Array.prototype.every,t.core.findIndex=Array.prototype.findIndex,t.core.each=Array.prototype.forEach,t.core.forEach=Array.prototype.forEach,t.core.includes=Array.prototype.includes?Array.prototype.includes:n,t.core.indexOf=Array.prototype.indexOf,t.core.lastIndexOf=Array.prototype.lastIndexOf,t.core.map=Array.prototype.map,t.core.pop=Array.prototype.pop,t.core.push=Array.prototype.push,t.core.reverse=Array.prototype.reverse,t.core.shift=Array.prototype.shift,t.core.slice=Array.prototype.slice,t.core.some=Array.prototype.some,t.core.sort=Array.prototype.sort,t.core.unshift=Array.prototype.unshift,t.core.splice=function(t,e){return this.constructor(Array.prototype.splice.call(this,t,e))}}},{}],3:[function(t,e,r){var n=function(t){return!!t};e.exports=function(t){"use strict";t.core.children=function(t){var e=this.constructor,r=function(r){return r=e(r.children),"string"==typeof t?r.filter(t):r};return this.map(r)},t.core.childrenFlat=function(t){var e=0,r=[],n=function(t){for(var n=t.children,i=n.length,o=0;i>o;o++)r[e]=n[o],e++};this.each(n);var i=this.constructor(r);return"string"==typeof t?i.filter(t):i},t.core.filter=function(e){var r,i,o,c=this;if(0===this.length)return this;if("function"==typeof e){for(var u=[],f=0,s=this.length;s>f;f++)u[f]=e.call(this[f],f)?this[f]:null;return u=u.filter(n),this.constructor(u)}var a=function(e,r,i){if(t.pseudo[e[0]])return t.pseudo[e[0]](r,e[1]);var c,u=[];if(c=0===i?e[0]:":"+e[0],""!==c){""!==e[1]&&(c+="("+e[1]+")");for(var f=0,s=r.length;s>f;f++)o=r[f],u[f]=t.matches(o,c)===!0?o:null;u=u.filter(n)}return new t(u)};if(e&&-1!==e.indexOf(":")){r=e.split(":"),i=[[r.splice(0,1).toString(),""]];for(var l,h=0,p=r.length;p>h;h++)l=r[h],-1!==l.indexOf("(")?(l=l.split("("),l[1]=l[1].replace(")","")):l=[l,""],i.push(l)}else{if(!e)return this;i=[[e,""]]}for(var d=0,v=i.length;v>d;d++){if(0===c.length)return c;""!==i[d][0]&&(c=a(i[d],c,d))}return c},t.core.find=function(e){var r=e[0];if(" "===r&&(e=e.trim(),r=e[0]),">"===r)return e=e.slice(1).trim(),this.childrenFlat().filter(e);if("~"===r)return e=e.slice(1).trim(),this.siblingsFlat().filter(e);if("!"===r)return this.parent();if("+"===r){e=e.slice(1).trim();for(var i,o=[],c=this.children(),u=0,f=c.length;f>u;u++)i=c[u][0],o[u]=i?i:null;return o.filter(n),new t(o).filter(e)}if(-1!==e.indexOf(":"))return this.constructor(e,this);for(var s=new t(e),a=[],l=0,h=0,p=this.length;p>h;h++)for(var d=0,v=s.length;v>d;d++)t.contains(s[d],this[h])&&(a[l]=s[d],l++);return this.constructor(a)},t.core.first=function(){return 0!==this.length?this.constructor(this[0]):this.constructor([])},t.core.last=function(){var t=this.length;return 1===t?this:0!==t?this.constructor(this[t-1]):this.constructor([])},t.core.parent=function(){var t,e,r=function(t){return t.parentNode},n=new Array(this.length);for(t=0,e=this.length;e>t;t++)n[t]=r(this[t]);return this.constructor(n)},t.core.siblings=function(t){var e=this.constructor,r=function(r){for(var n=[],i=0,o=r.parentNode.firstElementChild;o;)if(o!==r&&(n[i]=o,i++),o=o.nextElementSibling,!o)return n=e(n),"string"==typeof t?n.filter(t):n};return this.map(r)},t.core.siblingsFlat=function(t){var e=0,r=[],n="+"===t||"~"===t,i=function(i){var o=i;for(o=n?i.nextElementSibling:i.parentNode.firstElementChild;o&&(o!==i&&-1===r.indexOf(o)&&(r[e]=o,e++),o=o.nextElementSibling,o&&"+"!==t););};this.each(i);var o=this.constructor(r);return"string"!=typeof t||n?o:o.filter(t)},t.core.toString=function(){return this.type}}},{}],4:[function(t,e,r){var n=Array.prototype.slice;e.exports=function(e,r,i){"use strict";function o(t,e){for(var r=0,n=t.length;n>r;r++)e[r]=t[r];return e.length=r,e}function c(t,e){for(var r=t.match(h),n="",i="",c="",u=0,f=r.length;f>u;u++){var s=r[u][0];switch(s){case"#":n+=r[u];break;case".":c+=r[u];break;default:i+=r[u]}}if("string"==typeof i&&(t=document.createElement(i),n&&(t.id=n.slice(1)),c))for(c=c.split("."),u=1,f=c.length;f>u;u++)t.classList.add(c[u]);return o([t],e)}function u(t,e){var r=document.createElement("div");r.innerHTML=t,t=n.call(r.children);for(var i=0,c=t.length;c>i;i++)r.removeChild(t[i]);return o(t,e)}function f(t){return-1!==t.indexOf(">>")&&(t=t.replace(/>>/g," ")),-1!==t.indexOf("!")&&(t=t.replace(/!/g,":parent")),t}function s(t,r){if("string"==typeof t&&-1===t.indexOf(":")&&-1===t.indexOf("!")&&-1===t.indexOf(" "))switch(t[0]){case"#":if(-1===t.indexOf(".")){var i=document.getElementById(t.slice(1));return null===i?o([],r):o([i],r)}break;case".":if(-1===t.indexOf("#")){var c=t.slice(1);if(-1===c.indexOf("."))return o(document.getElementsByClassName(c),r);c=c.split(".");for(var u,f,s=document.getElementsByClassName(c[0]),a=1,l=c.length;l>a;a++){u=n.call(document.getElementsByClassName(c[a]));for(var h=0,p=s.length;p>h;h++)f=s[h],-1===u.indexOf(f)&&(s[h]=null)}return o(s,r).filter(function(t){return null!==t})}break;default:if(t&&-1===t.indexOf("[")&&-1===t.indexOf("<")&&-1===t.indexOf("#")&&-1===t.indexOf("."))return o(document.getElementsByTagName(t),r)}else"function"==typeof t&&e&&"function"==typeof e.ready&&e.ready(t);return!1}e.core={get type(){return r},get isMicrobe(){return!0},get version(){return i}},Object.defineProperty(e,"version",{get:function(){return i}});var a,l,h=e.prototype.__selectorRegex=/(?:[\s]*\.([\w-_\.]+)|#([\w-_]+)|([^#\.:<][\w-_]*)|(<[\w-_#\.]+>)|:([^#\.<][\w-()_]*))/g,p=e.core.__init__=function(t,e,n){var i;if(!e&&(i=s(t,this)))return i;if("string"==typeof t&&(t=f(t)),"string"==typeof e&&(e=f(e)),t=t||"",e&&e.type===r){i=o([],this);for(var v,g=0,y=e.length;y>g;g++){v=new p(t,e[g]);for(var m=0,x=v.length;x>m;m++)-1===Array.prototype.indexOf.call(i,v[m])&&(i[i.length]=v[m],i.length++)}return i}var O,b;if(1===t.nodeType||(O=Array.isArray(t)||t.jquery)||t===window||t===document||(b="[object HTMLCollection]"===t.toString()))return O||b||(t=[t]),o(t,this);if(e=void 0===e?document:e,e!==document&&"string"==typeof e&&"string"==typeof t)return this.constructor(e).find(t);var A=e.nodeType;if(!t||"string"!=typeof t||1!==A&&9!==A)return o([],this);var w=t.match(h);if(w&&1===w.length&&":"!==w[0][0])switch(a=w[0][0],l=t.slice(1),a){case".":var _=(t||"").slice(1).split(".").length;if(1===_)return o(e.getElementsByClassName(l),this);break;case"#":var E=document.getElementById(l);return e.ownerDocument&&this.contains(E,e)?o([E],this):o([],this);case"<":return c(t.substring(1,t.length-1),this);default:return o(e.getElementsByTagName(t),this)}return this instanceof p?-1!==t.indexOf(":")&&d?d(this,t,e,o):-1!==t.indexOf("/")?u(t,this):o(e.querySelectorAll(t),this):new p(t,e,n)};e.core.__init__.prototype=e.core,t("./core")(e),t("./root")(e),t("./pseudo")(e),t("./array")(e);var d=e.pseudo}},{"./array":2,"./core":3,"./pseudo":5,"./root":6}],5:[function(t,e,r){e.exports=function(t){"use strict";function e(t,e,r){for(var n,i=[],o=0,c=0,u=t.length;u>c;c++)n=e(t[c],i,c),n&&(i[o]=n,o++);return r?i:t.constructor(i)}var r=function(e,r,n){if("odd"===r?r="2n":"even"===r&&(r="2n1"),-1===r.indexOf("n")){switch(n){case!0:case"last":return new t(e[e.length-parseInt(r)])}return new t(e[parseInt(r)-1])}r=r.split("n");var i,o=parseInt(r[0])||1,c=parseInt(r[1]);n!==!0&&"last"!==n||(i=e.length-parseInt(r[1]),c=i%o);for(var u,f=[],s=c||0,a=i||e.length;a>s;)u=e[s],u&&f.push(u),s+=o;return new t(f)},n=function(e,r,i,o){function c(t){for(var r,c=[],u=0,f=t.length;f>u;u++)if(0===u)c=n(e,t[u],i,o);else{r=n(e,t[u],i,o);for(var s=0,a=r.length;a>s;s++)-1===Array.prototype.indexOf.call(c,r[s])&&(c[c.length]=r[s],c.length++)}return c}function u(){var n=s(a),c=o(i.querySelectorAll(n[0]),e);n=n[1];for(var u,f,l=0,h=n.length;h>l;l++)u=n[l].split("("),f=u[1],f&&(f=f.slice(0,f.length-1)),u=u[0],t.pseudo[u]&&(c=t.pseudo[u](c,f,r));return c}function f(r){for(var n,c=t.pseudo(e,r[0],i,o),u=!1,f=1,s=r.length;s>f;f++)if(n=r[f].trim(),"~"===n[0]?(c=c.siblingsFlat("~"),u=!0):"+"===n[0]?(c=c.siblingsFlat("+"),u=!0):u?(c=c.filter(n),u=!1):(c=c.find(n),u=!1),0===c.length)return c;return c}function s(e){var r,n=e.split(":");e=n[0],n.splice(0,1);for(var i=0,o=n.length;o>i;i++)r=n[i].split("("),t.pseudo[r[0]]||(e+=":"+n[i],n.splice(i,1));return[e,n]}if(-1!==r.indexOf(",")){if(r=r.split(/,(?![a-zA-Z0-9-#.,\s]+\))/g),r.length>1)return c(r);r=r[0]}var a=r;if(":"===a[0]&&(a="*"+a),-1!==a.trim().indexOf(" ")){var l=function(t){return" "===t?!1:t},h=a.split(/((?:[A-Za-z0-9.#*\-_]+)?(?:\:[A-Za-z\-]+(?:\([\s\S]+\))?)?)?( )?/);if(h=h.filter(l),h.length>1)return f(h);a=h[0]}return u()};n["any-link"]=function(t){return t.filter("a")},n.blank=function(t){var r=function(t,e){var r=t.textContent;return-1===e.indexOf(t)&&/^\s*$/.test(r||t.value)?t:void 0};return e(t,r)},n.column=function(t,e){return t.filter("col").filter(e)},n.contains=function(t,r){r=r.toLowerCase();var n=function(t){var e=function(t){return document.all?t.innerText:t.textContent},n=e(t);return-1!==n.toLowerCase().indexOf(r)?t:void 0};return e(t,n)},n["default"]=function(t){t=t.filter("input, option");var r=function(t){return t.defaultChecked===!0?t:void 0};return e(t,r)},n.dir=function(t,r){var n=function(t){return getComputedStyle(t).direction===r?t:void 0};return e(t,n)},n.drop=function(t,e){if(t=t.filter("[dropzone]"),!e)return t;switch(e){case"active":return t.filter(":active");case"invalid":return t.filter();case"valid":return t.filter()}},n.even=function(t){var r=function(t,e,r){return(r+1)%2===0?t:void 0};return e(t,r)},n.first=function(t){return t.first()},n.gt=function(t,e){return t.splice(e,t.length)},n.has=function(t,r){var n=function(t){return t.querySelector(r)?t:void 0};return e(t,n)},n["in-range"]=function(t){t=t.filter("[max],[min]");var r=function(t){var e=t.getAttribute("min"),r=t.getAttribute("max"),n=parseInt(t.value);if(n)if(e&&r){if(n>e&&r>n)return t}else if(e&&n>e||r&&r>n)return t};return e(t,r)},n.lang=function(t,r){if(r){t=t.filter("[lang]"),r=r.replace("*","");var n=function(t){return-1!==t.getAttribute("lang").indexOf(r)?t:void 0};return e(t,n)}return t.constructor([])},n.last=function(t){return t.last()},n["local-link"]=function(t,r){t=t.filter("a");var n=document.location,i=function(t){var e=t.href,i=e.replace(n.protocol+"//","").replace(n.host,"");i="/"===i[0]?i.slice(1):i;var o=i.split("/").length-1;return/^https?:\/\//.test(i)||r&&parseInt(r)!==o?void 0:t};return e(t,i)},n.lt=function(t,e){return t.splice(0,e)},n.matches=function(t,e,r){var n=t.constructor,i=":matches("+e+")";e=e.split(","),r=r.replace(i,""),r="*"===r?"":r;for(var o=n(r+e[0].trim()),c=1,u=e.length;u>c;c++)o.merge(n(r+e[c].trim()),!0);return o},n.not=function(r,n,i,o){if(-1!==n.indexOf(",")){var c=r.constructor;n=n.split(",");for(var u=0,f=n.length;f>u;u++)r=this.not(r,n[u].trim(),i,!0);return c(r)}var s=function(e){return t.matches(e,n)?void 0:e};return e(r,s,o)},n["nth-column"]=function(t,e){return t=t.filter("col"),r(t,e)},n["nth-last-column"]=function(t,e){return t=t.filter("col"),r(t,e,!0)},n["nth-last-match"]=function(t,e){return r(t,e,!0)},n["nth-match"]=function(t,e){return r(t,e)},n.odd=function(t){var r=function(t,e,r){return(r+1)%2!==0?t:void 0};return e(t,r)},n.optional=function(t){return t.filter("input:not([required=required]), textfield:not([required=required]), [required=optional], [optional]")},n["out-of-range"]=function(t){t=t.filter("[max],[min]");var r=function(t){var e=t.getAttribute("min"),r=t.getAttribute("max"),n=parseInt(t.value);if(n)if(e&&r){if(e>n||n>r)return t}else if(e&&e>n||r&&n>r)return t};return e(t,r)},n.parent=function(t){t=t.parent();var r=function(t,e,r){return-1===e.indexOf(t)?t:void 0};return e(t,r)},n["read-only"]=function(t){return t.filter(":not(input,textfield,[contenteditable=false])")},n["read-write"]=function(t){return t.filter("input,textfield,[contenteditable=true]")},n.required=function(t){return t.filter("[required=required]")},n.root=function(t){return t.constructor(document.body.parentNode)},t.pseudo=n}},{}],6:[function(t,e,r){e.exports=function(t){"use strict";t.contains=function(t,e){for(var r=t.parentNode;r!==document&&r!==e;)r=r.parentNode||e.parentNode;return r!==document},t.matches=function(t,e){var r=this.matches.__matchesMethod,n="string"!=typeof t&&!!t.length&&"[object HTMLFormElement]"!==t.toString(),i=!(!Array.isArray(t)&&!n);i||n||(t=[t]),!r&&t[0]&&(t[0].matches?r=this.matches.__matchesMethod="matches":t[0].msMatchesSelector?r=this.matches.__matchesMethod="msMatchesSelector":t[0].mozMatchesSelector?r=this.matches.__matchesMethod="mozMatchesSelector":t[0].webkitMatchesSelector&&(r=this.matches.__matchesMethod="webkitMatchesSelector"));for(var o=[],c=0,u=t.length;u>c;c++)o.push(t[c][r](e));return i?o:o[0]}}},{}],7:[function(t,e,r){e.exports="0.5.2"},{}]},{},[1])(1)});