jdoms
Version:
jDoms is a fast, powerful, and zero-dependency JavaScript library for modern DOM manipulation, traversal, event handling, and more
1,913 lines (1,568 loc) • 94.8 kB
JavaScript
/*!
* jDoms JavaScript Library
* https://mamedul.gitlab.io/jdoms
*
* Licensed under the MIT license:
* https://opensource.org/licenses/MIT
*
* Project home:
* https://github.com/mamedul/jdoms
*
* Version: 1.1.1
*/
(function (global, factory) {
'use strict';
if (typeof module === "object" && typeof module.exports === "object") {
module.exports = global.document ?
factory(global, true) :
function (win) {
if (!win.document) {
throw new Error("jDoms requires a document which has a window");
}
return factory(win);
};
} else if (typeof define === 'function' && define.amd) {
define(factory);
factory(global);
} else {
factory(global);
}
if( typeof global !== "undefined" ){
global = typeof window !== "undefined" ? window : this || globalThis || self;
}
global.jDoms = factory(global);
}((typeof window !== "undefined" ? window : this || globalThis || self ), (function (window) {
'use strict';
var version = "1.1.1",
developer = "MAMEDUL ISLAM";
if(typeof document == 'undefined'){
var document = window.document;
}
console.log(window.document);
/* Important polyfills */
if(typeof String.prototype.trim !== 'function') {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
};
}
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun) {
var len = this.length >>> 0;
if (typeof fun != "function") {
throw new TypeError();
}
var res = [];
var thisP = arguments[1];
for (var i = 0; i < len; i++) {
if (i in this) {
var val = this[i];
if (fun.call(thisP, val, i, this)) {
res.push(val);
}
}
}
return res;
};
}
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
}
return -1;
};
}
/* Inside global functions */
var _isUndefined = function(variable){
return (typeof variable==="undefined");
};
var _isDefined = function(variable){
return (typeof variable!=="undefined");
};
var _isSet = function(variable){
return (typeof variable!=="undefined");
};
var _isString = function(variable){
return (typeof variable==="string");
};
var _isNumber = function(variable){
return (typeof variable==="number");
};
var _isInt = function(variable){
return (typeof variable==="number" && parseInt(variable)===variable );
};
var _isFinite = function(variable){
return isFinite(variable);
};
var _isInfinity = function(variable){
return (typeof variable==="number" && !isFinite(variable));
};
var _isBoolean = function(variable){
return (typeof variable==="boolean");
};
var _isBigInt = function(variable){
return (typeof variable==="bigint");
};
var _isFlatten = function(variable){
return (typeof variable==="string" || typeof variable==="number" || typeof variable==="boolean");
};
var _isEmpty = function(variable){
if( typeof variable==='undefined'||variable===""||variable===0||(_isArray(variable) && variable.length === 0)||_isPureObject(variable) && (Object.keys(variable).length === 0)||variable===false||variable===null||isNaN(variable)){ return true; }
return false;
};
var _isArray = function(variable){
if (typeof Array !== "undefined" && typeof Array.isArray === "function") {
return Array.isArray(variable);
}
try {
if (variable && variable.constructor && variable.constructor.name === "Array") {
return true;
}
return Object.prototype.toString.call(variable) === "[object Array]";
} catch(e){}
return false;
};
var _isFunction = function(variable){
return (typeof variable==="function");
};
var _isObject = function(variable){
return (typeof variable==="object");
};
var _isPureObject = function(variable){
return (typeof variable==="object" && typeof Object!="undefined" && variable===Object(variable) );
};
var _isSymbol = function(variable){
return (typeof variable==="symbol");
};
var _isjDoms = function(variable){
return ( (typeof variable==="function" && variable.name=="jDoms") || (typeof variable==="object" && typeof variable.constructor!="undefined" && typeof variable.constructor.name!="undefined" && variable.constructor.name=='jDoms') );
};
var _sizeOf = function(variable){
var _size = 0;
if(typeof variable=="boolean"||typeof variable=="function"||typeof variable=="symbol"){
_size = 1;
}else if(typeof variable=="bigint"){
if(typeof BigInt == "function" && typeof BigInt.valueOf == "function"){
_size = (""+BigInt(variable).valueOf()).length;
}else{
_size = (""+variable).length + 1;
}
}else if(typeof variable=="string"||typeof variable=="number"){
_size = (""+variable).length;
}else if(typeof variable=="object"){
if(typeof Object=="function" && typeof Object.keys=="function"){
_size = Object.keys(variable).length;
}
if(_size==0){
var key;
for (key in variable) {
if (_isSet(variable.hasOwnProperty) && variable.hasOwnProperty(key)){ _size++; }else{ continue; }
}
}
if(_size==0 && typeof variable.nodeName!="undefined" && typeof variable.nodeType!="undefined" && typeof variable.nodeValue!="undefined" ){
_size++;
}
}
return _size;
};
var _now = function(){
return (new Date()).getTime();
};
var _trim = function(str){
try{
if(_isString(str)){
if(str.trim){
return str.trim();
}else{
return str.replace(/^\s+|\s+$/gm,'');
}
}else if( _isArray(str) || _isObject(str) ){
for(var key in str ){
str[key] = _trim(str[key]);
}
return str;
}
}catch(err){}
return str;
};
var _unique = function (arr) {
if(_isArray(arr)){
arr = arr.filter(function (v, i, a) { return a.indexOf(v) === i; });
}else if(_isString(arr) ||_isNumber(arr)){
var new_str = "";
arr = "" + arr;
for(var i=0; i<arr.length; i++){
if(new_str.indexOf(arr[i])<0){ new_str+=arr[i]; }
}
return new_str;
}
return arr;
};
var _isUnique = function (arr) {
return _sizeOf( arr ) == _sizeOf( _unique(arr) );
};
var _merge = function (obj, nextObj) {
if (!_isPureObject(obj) || !_isPureObject(nextObj)) {
return _isPureObject(nextObj) ? JSON.parse(JSON.stringify(nextObj)) : nextObj;
}
for (var p in nextObj) {
if (!nextObj.hasOwnProperty || !nextObj.hasOwnProperty(p)) {
continue;
}
try {
if (_isPureObject(nextObj[p])) {
if (!_isPureObject(obj[p])) obj[p] = {};
obj[p] = _merge(obj[p], nextObj[p]);
} else {
obj[p] = nextObj[p];
}
} catch (e) {
obj[p] = nextObj[p];
}
}
return obj;
};
var _escape = function(str){
try{
return encodeURI(str);
}catch(err){}
return "";
};
var _unescape = function(str){
try{
return decodeURI(str);
}catch(err){}
return str;
};
var _encodeBase64 = function( rawStr ){
if(_isSet(btoa)){ return btoa(rawStr); }
var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var _utf8_encode = function (string) {
string = string.replace(/\r\n/g,"\n");
var utfText = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utfText += String.fromCharCode(c);
}else if((c > 127) && (c < 2048)) {
utfText += String.fromCharCode((c >> 6) | 192);
utfText += String.fromCharCode((c & 63) | 128);
}else {
utfText += String.fromCharCode((c >> 12) | 224);
utfText += String.fromCharCode(((c >> 6) & 63) | 128);
utfText += String.fromCharCode((c & 63) | 128);
}
}
return utfText;
};
var _encode = function (str) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
str = _utf8_encode(str);
while (i < str.length) {
chr1 = str.charCodeAt(i++);
chr2 = str.charCodeAt(i++);
chr3 = str.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
_keyStr.charAt(enc3) + _keyStr.charAt(enc4);
}
return output;
};
return _encode (rawStr);
};
var _decodeBase64 = function( encodedStr ){
if(_isSet(atob)){ return atob(encodedStr); }
var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var _utf8_decode = function (utfText) {
var string = "";
var i = 0;
var c = 0, c1 = 0, c2 = 0, c3 = 0;
while ( i < utfText.length ) {
c = utfText.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}else if((c > 191) && (c < 224)) {
c2 = utfText.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}else {
c2 = utfText.charCodeAt(i+1);
c3 = utfText.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
};
var _decode = function (str) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
str = str.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < str.length) {
enc1 = _keyStr.indexOf(str.charAt(i++));
enc2 = _keyStr.indexOf(str.charAt(i++));
enc3 = _keyStr.indexOf(str.charAt(i++));
enc4 = _keyStr.indexOf(str.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) { output = output + String.fromCharCode(chr2);}
if (enc4 != 64) { output = output + String.fromCharCode(chr3);}
}
output = _utf8_decode(output);
return output;
};
return _decode (encodedStr);
};
var _stringify = function() {
function e(e) {
return c.lastIndex = 0, c.test(e) ? '"' + e.replace(c, function(e) {
var n = f[e];
return _isString(n) ? n : "\\u" + ("0000" + e.charCodeAt(0).toString(16)).slice(-4);
}) + '"' : '"' + e + '"';
}
function n(e) {
var n = [];
for (var o in e){ n = n.concat(o); }
return n;
}
function o(n) {
var g = ['!doctype', 'br', 'hr', 'img', 'link', 'meta', 'input'];
var o = n.tagName.toLowerCase(),
t = "<" + o;
return n.attributes.length > 0 && (t += " "), t += Array.prototype.map.call(n.attributes, function(n) {
return "" === n.value ? n.name : n.name + "=" + e(n.value);
}).join(" "), t += g.indexOf(o)>-1? ">":">"+n.innerHTML+"</"+o+">";
}
function t(r, c) {
var f, u, d, p, g, m, h = a;
try {
if (g = c[r], g && "object" == typeof g && _isFunction(g.toJSON) && (g = g.toJSON(r)), g instanceof HTMLElement){ return o(g); }
if (g instanceof RegExp) { return String(g); }
if (g instanceof MimeType || g instanceof Plugin) { return Object.prototype.toString.call(g); }
switch (typeof g) {
case "string":
return e(g);
case "boolean":
case "null":
case "number":
case "undefined":
return String(g);
case "function":
case "object":
if (!g) return "null";
var y = s.indexOf(g) + 1;
if (y > 0) return "/**ref:" + y.toString(16) + "**/";
if (s.push(g), y = s.length, m = "/**id:" + y.toString(16) + "**/", _isFunction(g)) return m + " " + String(g);
if (a += l, p = [], "[object Array]" === Object.prototype.toString.apply(g)) {
for (d = g.length, f = 0; f < d; f += 1) p[f] = t(f, g) || "null";
return u = 0 === p.length ? "[]" : "[\n" + a + m + "\n" + a + p.join(",\n" + a) + "\n" + h + "]", a = h, u;
}
var q = n(g), k;
for(var x in q) {
if(_isSet(q.hasOwnProperty) && !q.hasOwnProperty(x)){continue;}
k = q[x];
u = t(k, g), u && p.push(e(k) + ": " + u);
}
return u = 0 === p.length ? "{}" : "{\n" + a + m + "\n" + a + p.join(",\n" + a) + "\n" + h + "}", a = h, u;
}
} catch (b) {
return "";
}
}
function r(e) {
if (_isString(e)) return e;
a = "", l = " ", s = [];
for (var n = t("", {
"": e
}), o = s.length; o;) new RegExp("/\\*\\*ref:" + o.toString(16) + "\\*\\*/").test(n) || (n = n.replace(new RegExp("[\r\n\t ]*/\\*\\*id:" + o.toString(16) + "\\*\\*/", "g"), "")), o--;
return s = null, n;
}
var a, l, s, c = /[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
f = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\" };
return { quote: e, getString: r };
}();
var _delay = function (callback, ms) {
var delay = (function () {
var timer = 0;
return function (callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms||0);
};
})();
return delay(callback, ms);
};
var _promise = function(resolve, reject){
var jDomsPromise = function (jDomsPromise) {
var that = this;
this.state = 'pending';
this.value = undefined;
this.consumers = [];
jDomsPromise(this.resolve.bind(this), this.reject.bind(this));
};
jDomsPromise.prototype.fulfill = function (value) {
if (this.state !== 'pending') return;
this.state = 'fulfilled';
this.value = value;
this.done();
};
jDomsPromise.prototype.reject = function (reason) {
if (this.state !== 'pending') return;
this.state = 'rejected';
this.value = reason;
this.done();
};
jDomsPromise.prototype.then = function(onFulfilled, onRejected ) {
var consumer = new jDomsPromise(function () {});
consumer.onFulfilled = _isFunction(onFulfilled)? onFulfilled : null;
consumer.onRejected = _isFunction(onRejected)? onRejected : null;
this.consumers = this.consumers.concat(consumer);
this.done();
return consumer;
};
jDomsPromise.prototype.done = function() {
var promise = this;
if (this.state === 'pending') return;
var callbackName = this.state == 'fulfilled' ? 'onFulfilled' : 'onRejected';
var resolver = this.state == 'fulfilled' ? 'resolve' : 'reject';
setTimeout(function() {
var pConsumers = promise.consumers.splice(0);
for( var key in pConsumers ) {
var consumer = pConsumers[key];
try {
var callback = consumer[callbackName];
if (callback) {
consumer.resolve(callback(promise.value));
} else {
consumer[resolver](promise.value);
}
} catch (e) {
consumer.reject(e);
}
}
}, 0);
};
jDomsPromise.prototype.resolve = function(x) {
var wasCalled, then;
if (this === x) {
throw new TypeError('Circular reference: promise value is promise itself');
}
if (x instanceof jDomsPromise) {
x.then(this.resolve.bind(this), this.reject.bind(this));
} else if (x === Object(x)) {
try {
then = x.then;
if (_isFunction(then)) {
then.call(x, function resolve(y) {
if (wasCalled) return;
wasCalled = true;
this.resolve(y);
}.bind(this), function reject(reasonY) {
if (wasCalled) return;
wasCalled = true;
this.reject(reasonY);
}.bind(this));
} else {
this.fulfill(x);
}
} catch(e) {
if (wasCalled) return;
this.reject(e);
}
} else {
this.fulfill(x);
}
};
return new jDomsPromise(resolve, reject);
};
var _dateParse = function(date){
return Date.parse(date);
};
var _urlParse = function (url) {
var loc= location||window.location;
var data = { hash: loc.hash||"", host: loc.host||"", hostname: loc.hostname||"", href: loc||"", origin: loc.origin||"", password: loc.password||"", pathname: loc.pathname||"", port: loc.port||"", protocol: loc.protocol||"", search: loc.search||"", username: loc.username||"" };
var a = document.createElement("a");
a.href = url;
data.hash = a.hash;
data.host = a.host;
data.hostname = a.hostname;
data.href = a.href;
data.origin = a.origin;
data.password = a.password;
data.pathname = a.pathname;
data.port = a.port;
data.protocol = a.protocol;
data.search = a.search;
data.username = a.username;
return data;
};
var _jsonParse = function (json_codes) {
var data = {};
if ( _isObject(JSON) && _isFunction(JSON.parse) ) {
try {
data = JSON.parse(json_codes);
} catch (err) {}
} else if (_isObject(Components) && _isFunction(Components.classes) && _isFunction(Components.interfaces)) {
try {
var nativeJSON = Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON);
data = nativeJSON.decode(json_codes);
} catch (err) {}
} else {
var jsonTrims = json_codes.replace(/^\s+/, "").replace(/\s+$/, "");
var new_data = (function (jsstring) {
var rvalidchars = /^[\],:{}\s]*$/,
rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g;
if (rvalidchars.test(jsonTrims.replace(rvalidescape, "@")
.replace(rvalidtokens, "]")
.replace(rvalidbraces, ""))) {
return (new Function("return " + jsonTrims))();
}
})();
data = !new_data ? data : new_data;
}
return data;
};
var _xmlParse = function(xml){
if (window.DOMParser) {
var parser = new DOMParser();
return parser.parseFromString(xml,"text/xml");
}
if(_isSet(ActiveXObject)){
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
return xmlDoc.loadXML(xml);
}
return {};
};
var _htmlParse = function(html){
if (typeof html !== 'string') return document.createDocumentFragment();
var trimmed = html.toLowerCase().replace(/^\s+|\s+$/gm,'');
if (trimmed.indexOf('<!doctype') === 0 && document.implementation && document.implementation.createHTMLDocument) {
var doc = document.implementation.createHTMLDocument("");
doc.documentElement.innerHTML = html;
return doc;
} else if ('content' in document.createElement('template')) {
var elm = document.createElement('template');
elm.innerHTML = html;
return elm.content;
} else {
var docFrag = document.createDocumentFragment();
var el = document.createElement('body');
el.innerHTML = html;
// Move child nodes into fragment safely
while (el.childNodes && el.childNodes.length > 0) {
docFrag.appendChild(el.childNodes[0]);
}
return docFrag;
}
};
var _ajax = function (ajx) {
ajx = ajx || {};
var xhr;
if (typeof XMLHttpRequest !== "undefined") {
xhr = new XMLHttpRequest();
} else if (typeof ActiveXObject !== "undefined") {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} else {
throw new Error("No XHR support");
}
if (ajx.xhr && ( _isObject(ajx.xhr) )) {
xhr = ajx.xhr;
}
var enctype = 'application';
if (_isString(ajx.enctype)) {
if (ajx.enctype === 'multipart/form-data') enctype = 'multipart';
else if (ajx.enctype === 'text/plain') enctype = 'text';
}
var url = '';
if (_isString(ajx.url)) {
url = ajx.url;
}
var method = 'GET';
if (_isString(ajx.method) && ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'OPTIONS', 'PATCH'].indexOf(ajx.method.toUpperCase()) > -1) {
method = ajx.method.toUpperCase();
}
var async = true;
if (_isBoolean(ajx.async)) {
async = ajx.async;
}
if (ajx.onBefore) {
try { ajx.onBefore(xhr); } catch(e){}
}
var data = null;
// If ajx.data is an object and not FormData, build proper payload
if (_isObject(ajx.data) && !(typeof FormData !== "undefined" && ajx.data instanceof FormData)) {
if (typeof FormData !== "undefined" && ajx.useFormData) {
data = new FormData();
for (var k in ajx.data) {
if (!ajx.data.hasOwnProperty || ajx.data.hasOwnProperty(k)) {
data.append(k, ajx.data[k]);
}
}
} else if (method === 'GET' || method === 'PUT') {
// append to URL
var parts = [];
for (var key in ajx.data) {
if (!ajx.data.hasOwnProperty || ajx.data.hasOwnProperty(key)) {
parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(ajx.data[key]));
}
}
if (parts.length) {
url += (url.indexOf('?') === -1 ? '?' : '&') + parts.join('&');
}
} else {
// urlencoded form body
var parts2 = [];
for (var kk in ajx.data) {
if (!ajx.data.hasOwnProperty || ajx.data.hasOwnProperty(kk)) {
parts2.push(encodeURIComponent(kk) + "=" + encodeURIComponent(ajx.data[kk]));
}
}
data = parts2.join('&');
}
} else if (_isString(ajx.data)) {
data = ajx.data;
if ((method === 'GET' || method === 'PUT') && data) {
url += (url.indexOf('?') === -1 ? '?' : '&') + (data[0] === '?' ? data.slice(1) : data);
data = null;
}
} else if (typeof FormData !== "undefined" && ajx.data instanceof FormData) {
data = ajx.data;
}
try {
xhr.withCredentials = (_urlParse(url).hostname || window.location.hostname) !== window.location.hostname;
} catch(e) {}
if (_isBoolean(ajx.credentials)) {
xhr.withCredentials = ajx.credentials;
}
if (_isString(ajx.type)) {
try { xhr.responseType = ajx.type; } catch(e){}
}
// OPEN with async flag
xhr.open(method, url, async);
if (method === 'POST' && !(data instanceof FormData)) {
try { xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); } catch(e){}
}
// Basic Auth header if provided
if ((_isString(ajx.username) || _isNumber(ajx.username) || _isString(ajx.password) || _isNumber(ajx.password))) {
var authType = _isString(ajx.authType) ? ajx.authType : "Basic";
var authLogin = "";
if (_isSet(ajx.username) && _isSet(ajx.password)) {
authLogin = _encodeBase64(ajx.username + ':' + ajx.password);
} else if (_isSet(ajx.username) && _isUndefined(ajx.password)) {
authLogin = _encodeBase64(String(ajx.username));
} else if (_isUndefined(ajx.username) && _isSet(ajx.password)) {
authLogin = _encodeBase64(String(ajx.password));
}
try { xhr.setRequestHeader("Authorization", authType + ' ' + authLogin); } catch(e){}
}
if (_isFlatten(ajx.cache)) {
try { xhr.setRequestHeader("Cache-Control", ajx.cache); } catch(e){}
}
if (_isObject(ajx.headers) || _isArray(ajx.headers)) {
for (var hk in ajx.headers) {
if (!ajx.headers.hasOwnProperty || ajx.headers.hasOwnProperty(hk)) {
try { xhr.setRequestHeader(hk, ajx.headers[hk]); } catch(e){}
}
}
}
if (ajx.timeout && (_isNumber(ajx.timeout) || _isString(ajx.timeout))) {
try { xhr.timeout = parseInt(ajx.timeout, 10); } catch(e){}
}
xhr.onreadystatechange = function () {
if (ajx.onReadyStateChange) { try { ajx.onReadyStateChange(xhr, this.readyState, this.status); } catch(e){} }
if (this.readyState === 0) {
if (ajx.onNotConnected) try { ajx.onNotConnected(xhr); } catch(e){}
} else if (this.readyState === 1) {
if (ajx.onConnected) try { ajx.onConnected(xhr); } catch(e){}
} else if (this.readyState === 2) {
if (ajx.onReceived) try { ajx.onReceived(xhr); } catch(e){}
} else if (this.readyState === 3) {
if (ajx.onLoading) try { ajx.onLoading(xhr); } catch(e){}
} else if (this.readyState === 4) {
if (ajx.onComplete) try { ajx.onComplete(xhr); } catch(e){}
if (this.status >= 200 && this.status < 300) {
if (ajx.onSuccess) try { ajx.onSuccess(xhr); } catch(e){}
} else {
if (ajx.onError) try { ajx.onError(xhr); } catch(e){}
}
}
};
xhr.onloadstart = function (ev) { if (ajx.onLoadStart) try { ajx.onLoadStart(ev); } catch(e){} };
xhr.onloadend = function (ev) { if (ajx.onLoadEnd) try { ajx.onLoadEnd(ev); } catch(e){} };
xhr.ontimeout = function (ev) { if (ajx.onTimeout) try { ajx.onTimeout(ev); } catch(e){} };
xhr.onload = function (ev) { if (ajx.onLoad) try { ajx.onLoad(ev); } catch(e){} };
xhr.onprogress = function (ev) { if (ajx.onProgress) try { ajx.onProgress(ev); } catch(e){} };
xhr.onabort = function (ev) { if (ajx.onAbort) try { ajx.onAbort(ev); } catch(e){} };
xhr.onerror = function (ev) { if (ajx.onError) try { ajx.onError(ev); } catch(e){} };
try {
xhr.send(data);
} catch(e) {
// if send fails and user provided onError
if (ajx.onError) try { ajx.onError(e); } catch(e){}
}
return xhr;
};
var _eventCallback = function(ev){
var _ev = { altKey: true, bubbles: true, cancelable: true, changedTouches: true, ctrlKey: true, detail: true, eventPhase: true, metaKey: true, pageX: true, pageY: true, shiftKey: true, view: true, "char": true, code: true, charCode: true, key: true, keyCode: true, button: true, buttons: true, clientX: true, clientY: true, offsetX: true, offsetY: true, pointerId: true, pointerType: true, screenX: true, screenY: true, targetTouches: true, touches: true, which: true };
var tempArray = jDoms(_eventCallback.that).doms(_eventCallback.selectors);
for (var q = 0; q < tempArray.length; q++) {
ev = ev||window.event;
var tgt = ev.target||ev.currentTarget||ev.srcElement;
if( tempArray[q] == tgt || jDoms(tempArray[q]).child(tgt).length>0 || ( (_isSet(tempArray[q].compareDocumentPosition)) && tempArray[q].compareDocumentPosition(tgt)==16 ) || ( (_isSet(tempArray[q].contains)) && tempArray[q].contains(tgt) ) ){
for( var ek in ev ){
if(_isSet(ev.hasOwnProperty) && !ev.hasOwnProperty(ek)){continue;}
_ev[ek] = ev[ek];
}
var tgt = ["target", "targetElement", "srcElement"];
for(var t=0; t<tgt.length; t++){
_ev[tgt[t]] = tempArray[q];
if(_isSet(Object.defineProperty)){
Object.defineProperty(_ev, tgt[t], {
writable: false,
value: tempArray[q]
});
}
}
_eventCallback.callback(_ev);
}
}
this.that = null;
this.selectors = null;
this.callback = null;
};
_eventCallback.type = null;
_eventCallback.that = null;
_eventCallback.selectors = null;
_eventCallback.callback = null;
/* Default prototype functions */
var functions = {
version: version,
length: function(){
return this.length || 0;
},
index: function (index) {
try{
return this[index];
}catch{
return undefined;
}
},
doms: function (selectors) {
var args = arguments || [];
selectors = selectors || args[0];
var context = args[1] || '';
var new_selectors = [];
if (this.length > 0) {
for (var k = 0; k < this.length; k++) {
var new_doms = jDoms(selectors, context, this[k]);
for (var x = 0; x < new_doms.length; x++) {
new_selectors = new_selectors.concat(new_doms[x]);
}
}
}
return jDoms(new_selectors);
},
find: function (selectors) {
var args = arguments;
var context = args[1] || '';
return this.doms(selectors, context);
},
search: function (selectors) {
var args = arguments;
var context = args[1] || '';
return this.doms(selectors, context);
},
index: function(index){
try{
return (this.length==0) ? this._[parseInt(index)] : this[parseInt(index)] ;
}catch(err){}
return null;
},
domIndex: function(index){
var item = [];
try{
item = this[parseInt(index)] ;
}catch(err){}
return jDoms( item );
},
key: function(key){
try{
if( _isSet(this._.hasOwnProperty) ){ return this._[key]; }
}catch(err){}
return null;
},
each: function (callback) {
for (var i = 0; i < this.length; i++) {
callback(this[i], i, this);
}
return this;
},
parent: function () {
var args = arguments || [];
var selectors = args[0];
var array1 = [];
var array2 = [];
for (var i = 0; i < this.length; i++) {
array1 = array1.concat(this[i].parentElement || this[i].parentNode);
if (_isSet(selectors)) {
var tempArray = jDoms(selectors, "", (this[i].ownerDocument || document));
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
}
}
if (_isSet(selectors)) {
if (array2.length > 1) {
array2 = array2.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
}
array1 = array1.filter(function (n) {
return array2.indexOf(n) !== -1;
});
}
array1 = _unique(array1);
return jDoms(array1);
},
closest: function (selectors) {
if (window.Element && !Element.prototype.closest) {
Element.prototype.closest = function (s) {
var matches = new jDoms.qsAll(selectors, "", (this.document || this.ownerDocument || document)),
i,
el = this;
do {
i = matches.length;
while (--i >= 0 && matches.item(i) !== el) {}
} while ((i < 0) && (el = (el.parentElement || el.parentNode)));
return el || [];
};
}
var array1 = [];
for (var i = 0; i < this.length; i++) {
if (_isSet(this[i].closest)) {
try{
var closestDoms = this[i].closest(selectors);
if(_isArray(closestDoms) || closestDoms instanceof NodeList){
for (var x = 0; x < closestDoms.length; x++) {
array1 = array1.concat(closestDoms[x]);
}
}else if(closestDoms){
array1 = array1.concat(closestDoms);
}
}catch{}
}
}
array1 = _unique( array1 );
return jDoms(array1);
},
child: function(){
var args = arguments || [];
var selectors = args[0];
var array1 = [];
var array2 = [];
var childList, n;
for (var i = 0; i < this.length; i++) {
if(_isSet(this[i].children)){
childList = this[i].children;
for (n = 0; n < childList.length; n++) {
array1 = array1.concat(childList[n]);
}
}else if(_isSet(this[i].childNodes)){
childList = this[i].childNodes;
for (n = 0; n < childList.length; n++) {
if ( childList[i].nodeName && childList[i].nodeType==Node.ELEMENT_NODE ) {
array1 = array1.concat(childList[n]);
}
}
}
array1 = array1.concat();
if (_isSet(selectors)) {
var tempArray = jDoms(selectors, "", (this[i].ownerDocument || document));
for (var nn = 0; nn < tempArray.length; nn++) {
array2 = array2.concat(tempArray[nn]);
}
}
}
if (_isSet(selectors)) {
if (array2.length > 1) {
array2 = array2.filter(function (v, p, a) {
return a.indexOf(v) === p;
});
}
array1 = array1.filter(function (p) {
return array2.indexOf(p) !== -1;
});
}
array1 = _unique( array1 );
return jDoms(array1);
},
children: function(){
var args = arguments || [];
var selectors = args[0];
return this.child(selectors);
},
match: function (selectors) {
var args = arguments || [];
selectors = selectors || args[0] || [];
var context = args[1] || '',
root = _isSet(args[2]) ? args[2] : document;
var array1 = [];
var array2 = [];
for (var i = 0; i < this.length; i++) {
array1 = array1.concat(this[i]);
}
var tempArray = jDoms(selectors, context, root);
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
if (_isSet(selectors)) {
if (array2.length > 1) {
array2 = array2.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
}
array1 = array1.filter(function (n) {
return array2.indexOf(n) !== -1;
});
}
array1 = _unique(array1);
return jDoms(array1);
},
matchTo: function (selectors) {
var args = arguments || [];
selectors = selectors || args[0] || [];
var context = args[1] || '',
root = _isSet(args[2]) ? args[2] : document;
var array1 = [];
var array2 = [];
for (var i = 0; i < this.length; i++) {
array1 = array1.concat(this[i]);
}
var tempArray = jDoms(selectors, context, root);
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
if (_isSet(selectors)) {
if (array2.length > 1) {
array2 = array2.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
}
array2 = array2.filter(function (n) {
return array1.indexOf(n) !== -1;
});
}
array2 = _unique(array2);
return jDoms(array2);
},
merge: function (selectors) {
var args = arguments || [];
selectors = selectors || args[0] || [];
var context = args[1] || '',
root = _isSet(args[2]) ? args[2] : document;
var array1 = [];
var array2 = [];
for (var i = 0; i < this.length; i++) {
array1 = array1.concat(this[i]);
}
var tempArray = jDoms(selectors, context, root);
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
if (_isSet(selectors)) {
for( var k=0; k<array2.length; k++){
if(array1.indexOf(array2[k])<0){
array1 = array1.concat(array2[k]);
}
}
}
array1 = _unique(array1);
return jDoms(array1);
},
unique: function(){
var array1 = [];
for (var i = 0; i < this.length; i++) {
array1 = array1.concat(this[i]);
}
array1 = _unique(array1);
return jDoms(array1);
},
not: function (selectors) {
var args = arguments || [];
selectors = selectors || args[0];
var context = args[1] || "",
root = _isSet(args[2]) ? args[2] : document;
var array1 = [];
var array2 = [];
for (var i = 0; i < this.length; i++) {
array1 = array1.concat(this[i]);
}
var tempArray = jDoms(selectors, context, root);
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
if (_isSet(selectors)) {
if (array2.length > 1) {
array2 = array2.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
}
array1 = array1.filter(function (n) {
return array2.indexOf(n) === -1;
});
}
array1 = _unique( array1 );
return jDoms(array1);
},
is: function (selectors) {
if (_isUndefined(this[0])) {
return false;
}
var array1 = [ this[0] ];
var array2 = [];
var tempArray = jDoms(this[0]).match(selectors);
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
array1 = array1.filter(function (n) {
return array2.indexOf(n) !== -1;
});
return array1.length > 0 ? true : false;
},
isSame: function (selectors) {
var args = arguments || [];
selectors = selectors || args[0] || [];
var context = args[1] || '',
root = _isSet(args[2]) ? args[2] : document;
var a = [];
var b = [];
for (var i = 0; i < this.length; i++) {
a = a.concat(this[i]);
}
var tempArray = jDoms(selectors, context, root);
for (var n = 0; n < tempArray.length; n++) {
b = b.concat(tempArray[n]);
}
a = jDoms.unique(a);
b = jDoms.unique(b);
if (a.length !== b.length){ return false; }
if (a === b) { return true; }
for (var k = 0; k < a.length; k++) {
if ( b.indexOf(a[k])==-1){ return false; }
}
return true;
},
isContains: function(selectors){
var args = arguments || [];
selectors = selectors || args[0];
var context = args[1] || '',
root = _isSet(args[2]) ? args[2] : document;
var first = this[0];
var second = jDoms(selectors, context, root)[0];
if(_isSet(first) && _isSet(second) && _isSet(first.contains) ){
return first.contains(second);
}
return false;
},
isContainsBy: function(selectors){
var args = arguments || [];
selectors = selectors || args[0];
var context = args[1] || '',
root = _isSet(args[2]) ? args[2] : document;
var second = this[0];
var first = jDoms(selectors, context, root)[0];
if(_isSet(first) && _isSet(second) && _isSet(first.contains) ){
return first.contains(second);
}
return false;
},
previous: function () {
var args = arguments || [];
var selectors = args[0];
var array1 = [];
var array2 = [];
for (var i = 0; i < this.length; i++) {
var previousSibling = this[i].previousSibling;
while (previousSibling && previousSibling.nodeType != 1) {
previousSibling = previousSibling.previousSibling;
}
array1 = array1.concat(previousSibling);
if (_isSet(selectors)) {
var tempArray = jDoms(selectors, "", (this[i].ownerDocument || document));
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
}
}
if (_isSet(selectors)) {
if (array2.length > 1) {
array2 = array2.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
}
array1 = array1.filter(function (n) {
return array2.indexOf(n) !== -1;
});
}
array1 = _unique(array1);
return jDoms(array1);
},
next: function () {
var args = arguments || [];
var selectors = args[0];
var array1 = [];
var array2 = [];
for (var i = 0; i < this.length; i++) {
var nextSibling = this[i].nextSibling;
while (nextSibling && nextSibling.nodeType != 1) {
nextSibling = nextSibling.nextSibling;
}
array1 = array1.concat(nextSibling);
if (_isSet(selectors)) {
var tempArray = jDoms(selectors, "", (this[i].ownerDocument || document));
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
}
}
if (_isSet(selectors)) {
if (array2.length > 1) {
array2 = array2.filter(function (v, p, a) {
return a.indexOf(v) === p;
});
}
array1 = array1.filter(function (p) {
return array2.indexOf(p) !== -1;
});
}
array1 = _unique(array1);
return jDoms(array1);
},
first: function () {
var array1 = this[0] ? [this[0]] : [];
if (!array1) {
return jDoms(array1);
}
var args = arguments || [];
var selectors = args[0];
var array2 = [];
if (_isSet(selectors)) {
var tempArray = jDoms(selectors, "", (array1[0].ownerDocument || document));
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
}
if (_isSet(selectors)) {
if (array2.length > 1) {
array2 = array2.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
}
array1 = array1.filter(function (n) {
return array2.indexOf(n) !== -1;
});
}
array1 = _unique(array1);
return jDoms(array1);
},
last: function () {
var array1 = this[this.length - 1] ? [this[this.length - 1]] : [];
if (!array1) {
return jDoms(array1);
}
var args = arguments || [];
var selectors = args[0];
var array2 = [];
if (_isSet(selectors)) {
var tempArray = jDoms(selectors, "", (array1[0].ownerDocument || document));
for (var n = 0; n < tempArray.length; n++) {
array2 = array2.concat(tempArray[n]);
}
}
if (_isSet(selectors)) {
if (array2.length > 1) {
array2 = array2.filter(function (v, i, a) {
return a.indexOf(v) === i;
});
}
array1 = array1.filter(function (n) {
return array2.indexOf(n) !== -1;
});
}
array1 = _unique(array1);
return jDoms(array1);
},
clone: function () {
var args = arguments;
var deep = (_isSet(args[0]) && args[0] === false) ? false : true;
for (var i = 0; i < this.length; i++) {
if (_isSet(this[i].cloneNode)) {
return jDoms(this[i].cloneNode(deep));
}
}
return this;
},
addEvent: function (evt) {
var args = arguments;
evt = evt || args[0] || "";
var selectors, callback, useCapture = false;
var evtArray = evt.split(" ");
if (_isSet(args[3])) {
selectors = args[1];
callback = args[2];
useCapture = (args[3] === true);
} else if (_isSet(args[2])) {
selectors = args[1];
callback = args[2];
} else if (_isSet(args[1])) {
callback = args[1];
}
if (!_isFunction(callback)) {
return this; // Cannot add an event without a callback
}
for (var i = 0; i < this.length; i++) {
var element = this[i];
// Initialize a place to store our handlers if it doesn't exist
if (!element._jDomsEvents) {
element._jDomsEvents = {};
}
for (var n = 0; n < evtArray.length; n++) {
var eventType = evtArray[n];
if (!eventType) continue;
var handler;
if (_isString(selectors)) {
// Delegated event
handler = function (e) {
var target = e.target;
// Traverse up the DOM from the event target
while (target && target !== this) {
// Check if the target matches the selector
if (jDoms(target).is(selectors)) {
// Call the original callback with the context of the matched element
callback.call(target, e);
}
target = target.parentNode;
}
};
} else {
// Direct event
handler = callback;
}
// Store the handler so we can remove it later
if (!element._jDomsEvents[eventType]) {
element._jDomsEvents[eventType] = [];
}
element._jDomsEvents[eventType].push({
originalCallback: callback,
handler: handler,
selectors: selectors || null
});
if (element.addEventListener) {
element.addEventListener(eventType, handler, useCapture);
} else if (element.attachEvent) {
element.attachEvent('on' + eventType, handler);
}
}
}
return this;
},
on: function (evt) {
var args = arguments;
evt = args[0];
var selectors = args[1],
callback = args[2],
useCapture = args[3];
return this.addEvent(evt, selectors, callback, useCapture);
},
removeEvent: function (evt) {
var args = arguments;
evt = evt || args[0] || "";
var selectors, callback, useCapture = false;
var evtArray = evt.split(" ");
if (_isSet(args[3])) {
selectors = args[1];
callback = args[2];
useCapture = (args[3] === true);
} else if (_isSet(args[2])) {
selectors = args[1];
callback = args[2];
} else if (_isSet(args[1])) {
callback = args[1];
}
for (var i = 0; i < this.length; i++) {
var element = this[i];
if (!element._jDomsEvents) continue;
for (var n = 0; n < evtArray.length; n++) {
var eventType = evtArray[n];
if (!eventType || !element._jDomsEvents[eventType]) continue;
// Find and remove the correct listener
var listeners = element._jDomsEvents[eventType];
for (var j = listeners.length - 1; j >= 0; j--) {
var listener = listeners[j];
var callbackMatches = !_isFunction(callback) || listener.originalCallback === callback;
var selectorMatches = !_isString(selectors) || listener.selectors === selectors;
if (callbackMatches && selectorMatches) {
if (element.removeEventListener) {
element.removeEventListener(eventType, listener.handler, useCapture);
} else if (element.detachEvent) {
element.detachEvent('on' + eventType, listener.handler);
}
// Remove from our stored listeners
listeners.splice(j, 1);
}
}
}
}
return this;
},
off: function (evt) {
var args = arguments;
evt = args[0];
var selectors = args[1],
callback = args[2],
useCapture = args[3];
return this.removeEvent(evt, selectors, callback, useCapture);
},
fireEvent: function (eventName) {
for (var i = 0; i < this.length; i++) {
var doc = document;
if (this[i].ownerDocument) {
doc = this[i].ownerDocument;
} else if (this[i].nodeType == 9) {
doc = this[i];
}
if (this[i].dispatchEvent) {
var eventClass = "";
switch (eventName) {
case "click":
case "mousedown":
case "mouseup":
eventClass = "MouseEvents";
break;
case "focus":
case "change":
case "blur":
case "select":
eventClass = "HTMLEvents";
break;
}
var event = doc.createEvent(eventClass);
var bubbles = eventName == "change" ? false : true;
if ( _isSet(event.initEvent) ) {
event.initEvent(eventName, bubbles, true);
}
event.synthetic = true;
this[i].dispatchEvent(event, true);
} else if (this[i].fireEvent && doc.createEventObject) {
var event = doc.createEventObject();
event.synthetic = true;
this[i].fireEvent("on" + eventName, event);
}
}
return this;
},
trigger: function (eventName) {
return this.fireEvent(eventName);
},
create: function(){
var array1 = [];
if(_isString(this._)){
var tags = this._.replace(/(?:\s*-\s*)+|\s{2,}/g, " ").split(" ");
var tag, tagName;
for( var i=0; i<tags.length; i++){
tag = null;
tagName = tags[i].replace(/[^A-Za-z]/gi,"");
if( _isString(this.__) ){
tag = document.createElementNS( this.__, tagName );
if( _isObject(this.___) ){
try{
for( var attrNameNS in this.___ ){
if( _isSet(this.__.hasOwnProperty) && !this.__.hasOwnProperty(attrNameNS) ){ continue; }
tag.setAttribute( attrNameNS, this.___[attrNameNS] );
}
}catch(err){}
}
}
if( _isObject(this.__) ){
try{
tag = document.createElement( tagName );
for( var attrName in this.__ ){
if( _isSet(this.__.hasOwnProperty) && !this.__.hasOwnProperty(attrName) ){ continue; }
tag.setAttribute( attrName, this.__[attrName] );
}
tag.innerHTML = this.___;
}catch(err){}
}
if(tag){
if(_isSet(arguments[0])){
var props = arguments[0];
if( _isObject(props) ){
try{
for( var propName in props ){
if( _isSet(props.hasOwnProperty) && !props.hasOwnProperty(propName) ){ continue; }
tag[propName] = props[propName];
}
}catch(err){}
}
}
array1 = array1.concat(tag);
}
}
}
return jDoms(array1);
},
createElement: function(){
return this.create( arguments[0] );
},
getHtml: function () {
var args = arguments || [];
for (var i = 0; i < this.length; i++) {
if (_isSet(args[0]) && args[0] === true) {
if (_isSet(this[i].outerHTML)) {
return this[i].outerHTML;
} else {
e.insertAdjacentHTML('beforeBegin', code);
var new_elem = e.previousSibling;
e.parentElement.removeChild(e);
var html = "";
if ((_isSet(this[i].nodeName) || _isSet(this[i].tagName)) && _isSet(this[i].attributes)) {
var endless = ['!doctype', 'br', 'hr', 'img', 'link', 'meta', 'input'];
var tag = this[i].nodeName || this[i].tagName;
tag = tag.toLowerCase();
var attrs = "";
for (var n = 0; n < this[i].attributes.length; n++) {
attrs += this[i].attributes[n].nodeName;
attrs += this[i].attributes[n].nodeValue.indexOf('"') > -1 ? "'" : '"';
attrs += this[i].attributes[n].nodeValue;
attrs += this[i].attributes[n].nodeValue.indexOf('"') > -1 ? "'" : '"';
}
html = _isSet(this[i].innerHTML)? this[i].innerHTML : "";
return "<" + tag + (attrs == "" ? "" : " " + attrs) + (endless.indexOf(tag) > -1 ? "/>" : ">" + html + "<" + tag + ">");
}
}
}
if (_isSet(this[i].innerHTML)) { return this[i].innerHTML; }
}
return "";
},
setHtml: function (html) {
var args = arguments || [];
for (var i = 0; i < this.length; i++) {
if (_isSet(args[1]) && args[1] === true) {
if (_isSet(this[i].outerHTML)) {
this[i].outerHTML = html;
} else {
this[i].insertAdjacentHTML('beforeBegin', code);
var parent = this[i].parentElement || this[i].parentNode;
parent.removeChild(this[i]);
}
} else if (_isSet(this[i].innerHTML)) {
this[i].innerHTML = html;
}
}
return this;
},
html: function () {
var args = arguments || [];
var set = _isSet(args[0]);
var outer = ((_isSet(args[1]) && args[1] === true) === true);
if (set) {
return this.setHtml(args[0], outer);
} else {
return this.getHtml(outer);
}
},
appendHtml: function (html) {
for (var i = 0; i < this.length; i++) {
try{
if( (_isObject(html) && _isNumber(html.length)) || _isArray(html) ){
for( var x=0; x<html.length; x++ ){
this[i].appendChild(html[x]);
}
}else if(_isSet(html.nodeType)){
this[i].appendChild(html);
}else{
var frag = document.createDocumentFragment();
var span = document.createElement("span");
span.innerHTML = html;
for (var n = 0; n < span.childNodes.length; n++) {
frag.appendChild(span.childNodes[n]);
}
this[i].appendChild(frag);
}
}catch(err){}
}
return this;
},
append: function (html){
return this.appendHtml(html);
},
prependHtml: function (html) {
for (var i = 0; i < this.length; i++) {
try{
if(_isObject(html)){
if(_isSet(html.hasOwnProperty)){
for(var k in html){
if(!html.hasOwnProperty(k)){continue;}
if (this[i].firstChild) {
this[i].insertBefore(html[k], this[i].firstChild);
} else {
this[i].appendChild(html[k]);
}
}
}else if(_isSet(html.nodeType)){
if (this[i].firstChild) {
this[i].insertBefore(html, this[i].firstChild);
} else {
this[i].appendChild(html);
}
}
}else{
var frag = document.createDocumentFragment();
var span = document.createElement("span");
span.innerHTML = html;
for (var n = 0; n < span.childNodes.length; n++) {
frag.appendChild(span.childNodes[n]);
}
if (this[i].firstChild) {
this[i].insertBefore(frag, this[i].firstChild);
} else {
this[i].appendChild(frag);
}
}
}catch(err){}
}
return this;
},
prepend: function (html){
return this.prependHtml(html);
},
appendHtmlTo: function (selectors) {
var args = arguments;
selectors = args[0] || selectors || [];
var context = args[1] || '',
root = _isSet(args[2]) ? args[2] : document;
var jDoms2 = jDoms(selectors, context, root);
return jDoms2.appendHtml(this);
},
appendTo: function (selectors){
var args = arguments;
s