Skip to content

Instantly share code, notes, and snippets.

@franklinjavier
Created June 11, 2015 15:23
Show Gist options
  • Select an option

  • Save franklinjavier/262f71e53779128e5535 to your computer and use it in GitHub Desktop.

Select an option

Save franklinjavier/262f71e53779128e5535 to your computer and use it in GitHub Desktop.
jQuery source viewer - You might not need jquery
// Showing `jQuery.each` from 1.7.2
function (object, callback, args) {
var name, i = 0,
length = object.length,
isObj = length === undefined || jQuery.isFunction(object);
if (args) {
if (isObj) {
for (name in object) {
if (callback.apply(object[name], args) === false) {
break;
}
}
} else {
for (; i < length;) {
if (callback.apply(object[i++], args) === false) {
break;
}
}
}
// A special, fast, case for the most common use of each
} else {
if (isObj) {
for (name in object) {
if (callback.call(object[name], name, object[name]) === false) {
break;
}
}
} else {
for (; i < length;) {
if (callback.call(object[i], i, object[i++]) === false) {
break;
}
}
}
}
return object;
}
// Showing `jQuery.fn.html` from 1.7.2
function (value) {
return jQuery.access(this, function (value) {
var elem = this[0] || {},
i = 0,
l = this.length;
if (value === undefined) {
return elem.nodeType === 1 ? elem.innerHTML.replace(rinlinejQuery, "") : null;
}
if (typeof value === "string" && !rnoInnerhtml.test(value) && (jQuery.support.leadingWhitespace || !rleadingWhitespace.test(value)) && !wrapMap[(rtagName.exec(value) || ["", ""])[1].toLowerCase()]) {
value = value.replace(rxhtmlTag, "<$1></$2>");
try {
for (; i < l; i++) {
// Remove element nodes and prevent memory leaks
elem = this[i] || {};
if (elem.nodeType === 1) {
jQuery.cleanData(elem.getElementsByTagName("*"));
elem.innerHTML = value;
}
}
elem = 0;
// If using innerHTML throws an exception, use the fallback method
} catch(e) {}
}
if (elem) {
this.empty().append(value);
}
},
null, value, arguments.length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment