Skip to content

Instantly share code, notes, and snippets.

/* !
* Partial jQuery, extracted from
* jQuery JavaScript Library v1.7.2
*/
(function( window, undefined ) {
// Use the correct document accordingly with window argument (sandbox)
var document = window.document,
navigator = window.navigator;
... skip ....
@kswlee
kswlee / jQCoreSimple.js
Created June 27, 2012 14:57
Simplified jQuery Core
var jQuery = (function() {
// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
},
// A central reference to the root jQuery(document)
rootjQuery;
jQuery.fn = jQuery.prototype = {
// No chaining
$("#menu").fadeIn('fast');
$("#menu").addClass(".active");
$("#menu").css('marginRight', '10px');
// vs. with chaining
$("#menu").fadeIn('fast').addClass("active").css('marginRight', '10px');
// or
$("#menu").fadeIn('fast')
.addClass("active")
.css('marginRight', '10px');
function setup(items)
{
var divs = document.getElementsByTagName("div");
var images = document.getElementsByTagName("image");
var button = document.getElementsById("save-btn");
for (var i = 0; i < items.length; i++) {
process(items[i], div[i]);
}
function setup(items)
{
var doc = document;
var divs = doc.getElementsByTagName("div");
var images = doc.getElementsByTagName("image");
var button = doc.getElementsById("save-btn");
for (var i = 0; i < items.length; i++) {
process(items[i], div[i]);
}
@kswlee
kswlee / gist:3182106
Created July 26, 2012 13:46
jQuery ready funciton
//... skipped ...
ready: function( fn ) {
// Attach the listeners
jQuery.bindReady();
// Add the callback
readyList.add( fn );
return this;
},
@kswlee
kswlee / gist:3182301
Created July 26, 2012 14:18
jQuery init function (partial)
// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) ) {
return rootjQuery.ready( selector );
}
@kswlee
kswlee / gist:3182346
Created July 26, 2012 14:24
jQuery init function (partial)
init: function( selector, context, rootjQuery ) {
var match, elem, ret, doc;
// Handle $(""), $(null), or $(undefined)
if ( !selector ) {
return this;
}
// Handle $(DOMElement)
if ( selector.nodeType ) {
@kswlee
kswlee / gist:3182736
Created July 26, 2012 15:32
jQuery ready and bindReady
ready: function( fn ) {
// Attach the listeners
jQuery.bindReady();
// Add the callback
readyList.add( fn );
return this;
}