Guest User

Untitled

a guest
Oct 27th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var DOM = (function(defSearch, map, forEach, string, bool, array, toArray, reduce, uPush, contains, XHR, extend, iterable, ele, node, undefined) {
  2.   var args, global = this,
  3.       doc = global.document, find = defSearch;
  4.     DOM.searchEngine = function(func) {
  5.       find = func instanceof Function?func:defSearch;
  6.     };
  7.  
  8.     DOM.prototype.find = function(query) {
  9.       var input = find(query),
  10.           results = [];
  11.       $iterate(this, node, function(node) {
  12.         forEach(input, function(result) {
  13.           if(contains(node, result))
  14.              uPush(results, result);
  15.         });
  16.       }); return new DOM(results);
  17.     }; DOM.prototype.remove = function() {
  18.       $iterate(this, node, function(node) {
  19.         if(node.parentNode)
  20.            node.parentNode.removeChild(node);
  21.       }); return this;
  22.     }; DOM.prototype.append = function() {       var that  = this;
  23.       iterate(arguments, node, function(child) { var first = child.nodeType !== 11;
  24.         $iterate(that, node, function(parent) {
  25.           parent.appendChild(first?(first = false) || child:
  26.                                                       child.cloneNode(true));
  27.         });
  28.       }); return this;
  29.     }; DOM.prototype.clone = function(copyChildren) {
  30.       var results = [];
  31.       $iterate(this, node, function(node) {
  32.         results.push(node.cloneNode(copyChildren));
  33.       }); return new DOM(results);
  34.     }; DOM.prototype.each = function(callback) {
  35.       if(!(callback instanceof Function)) return this;
  36.       $iterate(this, null, function(item) {
  37.         callback(item);
  38.       }); return this;
  39.     };
  40.  
  41.     if(XHR) DOM.Ajax = function(opts) {
  42.       var xhr = XHR(), auth = opts && opts.auth;
  43.       if(opts.headers) for(var name in opts.headers)
  44.         xhr.setRequestHeader(name, opts.headers[name]);
  45.       xhr.open.apply(xhr, string(opts)?[ "GET", opts]:
  46.                          [opts.method || "GET",
  47.                           opts.address,
  48.                           opts.async || true,
  49.                           auth?opts.user:undefined,
  50.                           auth?opts.pass:undefined]);
  51.       return DOM.call(this, xhr);
  52.     }; DOM.Window = function(opts) {
  53.       if(!arguments.length) return DOM.call(this, global.open());
  54.       if(string(opts))  return DOM.call(this, global.open(opts));
  55.       var attr = new Array(3);
  56.           attr[2] = [];
  57.       for(var item in opts) {
  58.         switch(item) {
  59.           case "address": attr[0] = opts[item]; break;
  60.           case "name":    attr[1] = opts[item]; break;
  61.           default:        attr[2].push(
  62.             bool(opts[item])?item + "=" + (opts[item]?"yes":"no"):
  63.                              item + "=" +  opts[item]
  64.           );
  65.         }
  66.       } attr[2] = attr[2].join(",");
  67.       return DOM.call(this, Function.prototype.apply.call(global.open, global, attr));
  68.     }; DOM.Fragment = function() {
  69.       var frag = doc.createDocumentFragment();
  70.       iterate(arguments, node, function(element) {
  71.         frag.appendChild(element);
  72.       }); return DOM.call(this, frag);
  73.     };
  74.     (function() {
  75.       DOM.Element  = create(doc, doc.createElement );
  76.       DOM.Text     = create(doc, doc.createTextNode);
  77.  
  78.       function create(context, func) {
  79.         return function(name) {
  80.           name = arguments.length > 1?map(arguments, function(name) {
  81.             return func.call(context, name);
  82.           }):      func.call(context, name);
  83.           return    DOM.call(this,    name);
  84.         };
  85.       };
  86.     })(DOM);
  87.     if(DOM.Ajax) extend(DOM.Ajax,     DOM);
  88.                  extend(DOM.Window,   DOM);
  89.                  extend(DOM.Fragment, DOM);
  90.                  extend(DOM.Element,  DOM);
  91.                  extend(DOM.Text,     DOM);
  92.                                return(DOM);
  93.  
  94.   function $iterate($, filter, callback) {
  95.     if(! $.wrappee ) return;
  96.     if(  $.iterable)
  97.            iterate($.wrappee, filter, callback);
  98.     else if(!filter || filter($.wrappee))
  99.                      callback($.wrappee);
  100.   }; function iterate($, filter, callback) {
  101.     forEach($, function(item) {
  102.       if(!item) return;
  103.       if( item instanceof DOM) $iterate(item, filter, callback);
  104.       else if(iterable(item))   iterate(item, filter, callback);
  105.       else if(!filter || filter(        item))        callback(item);
  106.     });
  107.   }; function wrap(query, context) {
  108.     if(query instanceof DOM) {
  109.       this.wrappee  = query.wrappee;
  110.       this.iterable = query.iterable;
  111.     } else { var length;
  112.       this.wrappee = string(query)?find(query):
  113.                                  Object(query);
  114.       this.wrappee = array(  this.wrappee)?
  115.                  (!(length = this.wrappee.length)?null:
  116.                (length === 1?this.wrappee[0]:this.wrappee)):
  117.                              this.wrappee;
  118.       this.iterable = iterable(this.wrappee);
  119.     }
  120.   }; function DOM() {
  121.     if(!(this instanceof arguments.callee)) {
  122.       args = arguments;
  123.       return new arguments.callee;
  124.     } wrap.apply(this, args || arguments);
  125.               if(args) args = null;
  126.   };
  127. })(Sizzle,
  128.    Array.map,
  129.    Array.forEach,
  130.    String.isString,
  131.    Boolean.isBoolean,
  132.    Array.isArray,
  133.    Array.from,
  134.    Array.reduce,
  135.    Array.uPush,
  136. (function() {
  137.   var func = document.createElement("span").contains;
  138.   return func?function(x, y) {
  139.     return func.call(x, y);
  140.   }:function(x, y) {
  141.     return x.compareDocumentPosition(y) & 16;
  142.   }
  143. })(),
  144. (function() {
  145.   try {    new XMLHttpRequest; return function() {
  146.     return new XMLHttpRequest;
  147.   }} catch (e) {try{
  148.            new ActiveXObject("Msxml2.XMLHTTP"); return function() {
  149.     return new ActiveXObject("Msxml2.XMLHTTP");
  150.   }} catch (e) {try {
  151.            new ActiveXObject("Microsoft.XMLHTTP"); return function() {
  152.     return new ActiveXObject("Microsoft.XMLHTTP");
  153.   }}  catch (e) {}}}
  154. })(), function(func, obj) {
  155.   func.prototype = Object.create(obj.prototype);
  156.   func.prototype.constructor = func;
  157. }, function(obj) {
  158.   var length;
  159.   return !!(   obj instanceof Object &&
  160.    "length" in obj && (
  161.   !(length   = obj.length) ||
  162.     length - 1 in obj))
  163. }, function(obj) {
  164.   return    obj && "HTMLElement" in this?
  165.             obj instanceof HTMLElement:
  166.             obj.nodeType === 1;
  167. }, function(    obj) {
  168.   return        obj && "Node" in this?
  169.                 obj instanceof Node:
  170.   "nodeType" in obj;
  171. });
Add Comment
Please, Sign In to add comment