UNPKG

microbejs

Version:

microbe.js - A modular JS library for DOM manipulation, and more

2 lines 11.6 kB
/*! Microbe v0.5.2 | (c) 2014-2016 Sociomantic Labs | http://m.icro.be/license */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.µ=e()}}(function(){return function e(t,n,o){function r(u,s){if(!n[u]){if(!t[u]){var c="function"==typeof require&&require;if(!s&&c)return c(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var a=n[u]={exports:{}};t[u][0].call(a.exports,function(e){var n=t[u][1][e];return r(n?n:e)},a,a.exports,e,t,n,o)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<o.length;u++)r(o[u]);return r}({1:[function(e,t,n){"use strict";var o="[object MicrobeRoot]",r=e("./version")+"-tool",i={core:{}};e("./modules/tools")(i),e("./modules/pageStyles")(i),e("./modules/http")(i),Object.defineProperty(i,"version",{get:function(){return r}}),Object.defineProperty(i,"type",{get:function(){return o}}),t.exports=i},{"./modules/http":9,"./modules/pageStyles":10,"./modules/tools":11,"./version":13}],2:[function(e,t,n){(function(e){function n(){for(;r.next;){r=r.next;var e=r.task;r.task=void 0;var t=r.domain;t&&(r.domain=void 0,t.enter());try{e()}catch(o){if(c)throw t&&t.exit(),setTimeout(n,0),t&&t.enter(),o;setTimeout(function(){throw o},0)}t&&t.exit()}u=!1}function o(t){i=i.next={task:t,domain:c&&e.domain,next:null},u||(u=!0,s())}var r={task:void 0,next:null},i=r,u=!1,s=void 0,c=!1;if("undefined"!=typeof e&&e.nextTick)c=!0,s=function(){e.nextTick(n)};else if("function"==typeof setImmediate)s="undefined"!=typeof window?setImmediate.bind(window,n):function(){setImmediate(n)};else if("undefined"!=typeof MessageChannel){var f=new MessageChannel;f.port1.onmessage=n,s=function(){f.port2.postMessage(0)}}else s=function(){setTimeout(n,0)};t.exports=o}).call(this,e("_process"))},{_process:3}],3:[function(e,t,n){function o(){}var r=t.exports={};r.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),n.length>0)){var o=n.shift();o()}},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=o,r.addListener=o,r.once=o,r.off=o,r.removeListener=o,r.removeAllListeners=o,r.emit=o,r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")}},{}],4:[function(e,t,n){"use strict";t.exports=e("./lib/core.js"),e("./lib/done.js"),e("./lib/es6-extensions.js"),e("./lib/node-extensions.js")},{"./lib/core.js":5,"./lib/done.js":6,"./lib/es6-extensions.js":7,"./lib/node-extensions.js":8}],5:[function(e,t,n){"use strict";function o(e){function t(e){return null===c?void a.push(e):void u(function(){var t=c?e.onFulfilled:e.onRejected;if(null===t)return void(c?e.resolve:e.reject)(f);var n;try{n=t(f)}catch(o){return void e.reject(o)}e.resolve(n)})}function n(e){try{if(e===l)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var t=e.then;if("function"==typeof t)return void i(t.bind(e),n,o)}c=!0,f=e,s()}catch(r){o(r)}}function o(e){c=!1,f=e,s()}function s(){for(var e=0,n=a.length;n>e;e++)t(a[e]);a=null}if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");var c=null,f=null,a=[],l=this;this.then=function(e,n){return new l.constructor(function(o,i){t(new r(e,n,o,i))})},i(e,n,o)}function r(e,t,n,o){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.resolve=n,this.reject=o}function i(e,t,n){var o=!1;try{e(function(e){o||(o=!0,t(e))},function(e){o||(o=!0,n(e))})}catch(r){if(o)return;o=!0,n(r)}}var u=e("asap");t.exports=o},{asap:2}],6:[function(e,t,n){"use strict";var o=e("./core.js"),r=e("asap");t.exports=o,o.prototype.done=function(e,t){var n=arguments.length?this.then.apply(this,arguments):this;n.then(null,function(e){r(function(){throw e})})}},{"./core.js":5,asap:2}],7:[function(e,t,n){"use strict";function o(e){this.then=function(t){return"function"!=typeof t?this:new r(function(n,o){i(function(){try{n(t(e))}catch(r){o(r)}})})}}var r=e("./core.js"),i=e("asap");t.exports=r,o.prototype=r.prototype;var u=new o(!0),s=new o(!1),c=new o(null),f=new o(void 0),a=new o(0),l=new o("");r.resolve=function(e){if(e instanceof r)return e;if(null===e)return c;if(void 0===e)return f;if(e===!0)return u;if(e===!1)return s;if(0===e)return a;if(""===e)return l;if("object"==typeof e||"function"==typeof e)try{var t=e.then;if("function"==typeof t)return new r(t.bind(e))}catch(n){return new r(function(e,t){t(n)})}return new o(e)},r.all=function(e){var t=Array.prototype.slice.call(e);return new r(function(e,n){function o(i,u){try{if(u&&("object"==typeof u||"function"==typeof u)){var s=u.then;if("function"==typeof s)return void s.call(u,function(e){o(i,e)},n)}t[i]=u,0===--r&&e(t)}catch(c){n(c)}}if(0===t.length)return e([]);for(var r=t.length,i=0;i<t.length;i++)o(i,t[i])})},r.reject=function(e){return new r(function(t,n){n(e)})},r.race=function(e){return new r(function(t,n){e.forEach(function(e){r.resolve(e).then(t,n)})})},r.prototype["catch"]=function(e){return this.then(null,e)}},{"./core.js":5,asap:2}],8:[function(e,t,n){"use strict";var o=e("./core.js"),r=e("asap");t.exports=o,o.denodeify=function(e,t){return t=t||1/0,function(){var n=this,r=Array.prototype.slice.call(arguments);return new o(function(o,i){for(;r.length&&r.length>t;)r.pop();r.push(function(e,t){e?i(e):o(t)});var u=e.apply(n,r);!u||"object"!=typeof u&&"function"!=typeof u||"function"!=typeof u.then||o(u)})}},o.nodeify=function(e){return function(){var t=Array.prototype.slice.call(arguments),n="function"==typeof t[t.length-1]?t.pop():null,i=this;try{return e.apply(this,arguments).nodeify(n,i)}catch(u){if(null===n||"undefined"==typeof n)return new o(function(e,t){t(u)});r(function(){n.call(i,u)})}}},o.prototype.nodeify=function(e,t){return"function"!=typeof e?this:void this.then(function(n){r(function(){e.call(t,null,n)})},function(n){r(function(){e.call(t,n)})})}},{"./core.js":5,asap:2}],9:[function(e,t,n){t.exports=function(t){"use strict";var n=e("promise");t.http=function(e){var t,o,r,i,u,s,c,f;if(!e)return new Error("No parameters given");if("string"==typeof e&&(e={url:e}),t=new XMLHttpRequest,o=e.method||"GET",r=e.url,i=JSON.stringify(e.data)||null,u=e.user||"",s=e.password||"",c=e.headers||null,f="boolean"==typeof e.async?e.async:!0,t.onreadystatechange=function(){return 4===t.readyState?t:void 0},t.open(o,r,f,u,s),"POST"===o&&t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c)for(var a in c)t.setRequestHeader(a,c[a]);if(f)return new n(function(e,n){t.onerror=function(){n(new Error("Network error!"))},t.send(i),t.onload=function(){200===t.status?e(t.response):n(new Error(t.status))}});var l=function(e){var t={then:function(n){return 200===e.status&&n(e.responseText),t},"catch":function(n){return 200!==e.status&&n({status:e.status,statusText:e.statusText}),t}};return t};return t.send(i),t.onloadend=function(){return t.onreadystatechange(),l(t)},t.onloadend()},t.http.get=function(e){return this({url:e,method:"GET"})},t.http.post=function(e,t){return this({url:e,data:t,method:"POST"})}}},{promise:4}],10:[function(e,t,n){t.exports=function(e){"use strict";e.insertStyle=function(t,n,o){var r=t.replace(/ /g,"-"),i=o?r+o.replace(/[\s:\/\[\]\(\)]+/g,"-"):r;o=o||"none";var u,s,c=function(){var e=document.createElement("style");return e.className="microbe--inserted--style__"+i,o&&"none"!==o&&e.setAttribute("media",o),document.head.appendChild(e),e},f=e.__customCSSRules[r];if(f&&f[o]){u=f[o].el;var a=f[o].obj;for(s in n)a[s]=n[s];n=a}else u=c();var l=t+"{";for(s in n)l+=s+" : "+n[s]+";";return l+="}",u.innerHTML=l,e.__customCSSRules[r]=e.__customCSSRules[r]||{},e.__customCSSRules[r][o]={el:u,obj:n},u},e.__customCSSRules={},e.removeStyle=function(t,n,o){o||"string"!=typeof n||"all"===n||(o=n,n=null),o=o||"none";var r=function(n,o){n.parentNode.removeChild(n),delete e.__customCSSRules[t][o]},i=e.__customCSSRules[t];if(!i)return!1;if("all"===n)for(var u in i)r(i[u].el,u);else{if(i=i[o],!i)return!1;if(e.isArray(n)&&!e.isEmpty(n)){for(var s=0,c=n.length;c>s;s++)i.obj[n[s]]&&delete i.obj[n[s]];e.isEmpty(i.obj)?r(i.el,o):e.insertStyle(t,i.obj,o)}else r(i.el,o)}return!0},e.removeStyles=function(t){return e.removeStyle(t,"all")}}},{}],11:[function(e,t,n){t.exports=function(t){"use strict";window.Promise=window.Promise||e("promise");var n=e("./types");t.capitalize=function(e){var n=t.isArray(e);e=n?e:[e];for(var o,r=[],i=0,u=e.length;u>i;i++){o=e[i].split(" ");for(var s=0,c=o.length;c>s;s++)o[s]=o[s][0].toUpperCase()+o[s].slice(1);r.push(o.join(" "))}return n?r:r[0]},t.capitalise=t.capitalize,t.debounce=function(e,t,n){var o;return function(){var r=this,i=arguments,u=function(){o=null,n||e.apply(r,i)},s=n&&!o;clearTimeout(o),o=setTimeout(u,t),s&&e.apply(r,i)}},t.extend=function(){var e=t.isObject,n=t.isArray,o=arguments[0]||{},r=1,i=arguments.length,u=!1;"boolean"==typeof o&&(u=o,o=arguments[r]||{},r++),"object"==typeof o||t.isFunction(o)||(o={}),r===i&&(o=this,r--);for(var s,c,f,a,l,p;i>r;r++)if(s=arguments[r],null!==s&&void 0!==s)for(c in s)f=o[c],a=s[c],o!==a&&(u&&a&&(e(a)||(l=n(a)))?(l?(l=!1,p=f&&n(f)?f:[]):p=f&&e(f)?f:{},o[c]=t.extend(u,p,a)):void 0!==a&&(o[c]=a));return o},t.core.extend=t.extend,t.identity=function(e){return e},t.isArray=Array.isArray,t.isEmpty=function(e){var t;for(t in e)return!1;return!0},t.isFunction=function(e){return"function"===t.type(e)},t.isObject=function(e){return"object"===t.type(e)&&!e.nodeType&&!t.isWindow(e)},t.isUndefined=function(e,t){return t&&"object"!=typeof t?!0:t?!(e in t):void 0===e},t.isWindow=function(e){return null!==e&&e===e.window},t.merge=function(e,t,n){"boolean"==typeof t&&(n=t,t=null),t||(t=e,e=this);var o=e.length;if("number"==typeof o){for(var r=0,i=t.length;i>r;r++)n&&-1!==e.indexOf(t[r])||(e[o++]=t[r]);e.length=o}return e},t.core.merge=t.merge,t.noop=function(){},t.once=function(e,t){var n;return function(){return e&&(n=e.apply(t||this,arguments),e=null),n}},t.poll=function(e,t,n,o,r){var i=Number(new Date)+(o||2e3);r=r||100,function u(){if(e())try{t()}catch(o){throw"No argument given for success function"}else if(Number(new Date)<i)setTimeout(u,r);else try{n(new Error("timed out for "+e+": "+arguments))}catch(o){throw"No argument given for error function."}}()},t.toArray=function(e){return Array.prototype.slice.call(e||this)},t.core.toArray=t.toArray,t.type=function(e){if(null===e)return e+"";var t=n[Object.prototype.toString.call(e)];return t=t?t:n[e.toString()],t=t||typeof e,"object"===t&&e instanceof Promise&&(t="promise"),t},t.xyzzy=t.noop}},{"./types":12,promise:4}],12:[function(e,t,n){"use strict";t.exports={"[object Number]":"number","[object String]":"string","[object Function]":"function","[object Array]":"array","[object Date]":"date","[object RegExp]":"regExp","[object Error]":"error","[object Promise]":"promise","[object Microbe]":"microbe"}},{}],13:[function(e,t,n){t.exports="0.5.2"},{}]},{},[1])(1)});