From bca576550249e9b79b1097669dff6d4ddd0d65cf Mon Sep 17 00:00:00 2001 From: jeresig Date: Wed, 8 Sep 2010 13:54:33 -0400 Subject: [PATCH 1/5] Make sure that jQuery works even when the individual modules are loaded separately AND jQuery.noConflict(true) is used. Fixes #7011. --- src/ajax.js | 4 ++++ src/attributes.js | 4 ++++ src/css.js | 4 ++++ src/data.js | 4 ++++ src/dimensions.js | 4 ++++ src/effects.js | 4 ++++ src/event.js | 4 ++++ src/manipulation.js | 6 +++++- src/offset.js | 4 ++++ src/queue.js | 4 ++++ src/support.js | 4 ++++ src/traversing.js | 4 ++++ test/unit/core.js | 3 ++- 13 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 2c4f13cb2..52a5a22cc 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + var jsc = jQuery.now(), rscript = //gi, rselectTextarea = /select|textarea/i, @@ -686,3 +688,5 @@ jQuery.extend( jQuery.ajax, { // For backwards compatibility jQuery.extend( jQuery.ajax ); + +})( jQuery ); diff --git a/src/attributes.js b/src/attributes.js index 719c368af..73b4cdf11 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + var rclass = /[\n\t]/g, rspace = /\s+/, rreturn = /\r/g, @@ -345,3 +347,5 @@ jQuery.extend({ return jQuery.style( elem, name, value ); } }); + +})( jQuery ); diff --git a/src/css.js b/src/css.js index cb65c0ba3..ae6853e9c 100644 --- a/src/css.js +++ b/src/css.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + // exclude the following css properties to add px var rexclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, ralpha = /alpha\([^)]*\)/, @@ -232,3 +234,5 @@ if ( jQuery.expr && jQuery.expr.filters ) { return !jQuery.expr.filters.hidden( elem ); }; } + +})( jQuery ); diff --git a/src/data.js b/src/data.js index d38d47d3c..5404c936c 100644 --- a/src/data.js +++ b/src/data.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + var windowData = {}; jQuery.extend({ @@ -165,3 +167,5 @@ jQuery.fn.extend({ }); } }); + +})( jQuery ); diff --git a/src/dimensions.js b/src/dimensions.js index aeaaa78ba..de10832d1 100644 --- a/src/dimensions.js +++ b/src/dimensions.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + // Create innerHeight, innerWidth, outerHeight and outerWidth methods jQuery.each([ "Height", "Width" ], function( i, name ) { @@ -55,3 +57,5 @@ jQuery.each([ "Height", "Width" ], function( i, name ) { }; }); + +})( jQuery ); diff --git a/src/effects.js b/src/effects.js index 40326e23d..65b9e0f97 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + var elemdisplay = {}, rfxtypes = /toggle|show|hide/, rfxnum = /^([+\-]=)?([\d+.\-]+)(.*)$/, @@ -480,3 +482,5 @@ if ( jQuery.expr && jQuery.expr.filters ) { }).length; }; } + +})( jQuery ); diff --git a/src/event.js b/src/event.js index 45f2202c5..f0b27de43 100644 --- a/src/event.js +++ b/src/event.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + var rnamespaces = /\.(.*)$/, fcleanup = function( nm ) { return nm.replace(/[^\w\s\.\|`]/g, function( ch ) { @@ -1109,3 +1111,5 @@ if ( window.attachEvent && !window.addEventListener ) { } }); } + +})( jQuery ); diff --git a/src/manipulation.js b/src/manipulation.js index cb898cc3c..3054eea1d 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, rleadingWhitespace = /^\s+/, rxhtmlTag = /(<([\w:]+)[^>]*?)\/>/g, @@ -599,4 +601,6 @@ function evalScript( i, elem ) { if ( elem.parentNode ) { elem.parentNode.removeChild( elem ); } -} \ No newline at end of file +} + +})( jQuery ); diff --git a/src/offset.js b/src/offset.js index 0ce4c1979..c38a7f216 100644 --- a/src/offset.js +++ b/src/offset.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + if ( "getBoundingClientRect" in document.documentElement ) { jQuery.fn.offset = function( options ) { var elem = this[0]; @@ -281,3 +283,5 @@ function getWindow( elem ) { elem.defaultView || elem.parentWindow : false; } + +})( jQuery ); diff --git a/src/queue.js b/src/queue.js index e52f37b85..11c658f5d 100644 --- a/src/queue.js +++ b/src/queue.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + jQuery.extend({ queue: function( elem, type, data ) { if ( !elem ) { @@ -88,3 +90,5 @@ jQuery.fn.extend({ return this.queue( type || "fx", [] ); } }); + +})( jQuery ); diff --git a/src/support.js b/src/support.js index cddd3dc3b..75e89dd0e 100644 --- a/src/support.js +++ b/src/support.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + (function() { jQuery.support = {}; @@ -146,3 +148,5 @@ jQuery.props = { usemap: "useMap", frameborder: "frameBorder" }; + +})( jQuery ); diff --git a/src/traversing.js b/src/traversing.js index fde7219bb..59110b096 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -1,3 +1,5 @@ +(function( jQuery ) { + var runtil = /Until$/, rparentsprev = /^(?:parents|prevUntil|prevAll)/, // Note: This RegExp should be improved, or likely pulled from Sizzle @@ -271,3 +273,5 @@ function winnow( elements, qualifier, keep ) { return (jQuery.inArray( elem, qualifier ) >= 0) === keep; }); } + +})( jQuery ); diff --git a/test/unit/core.js b/test/unit/core.js index 3ba16a486..811d13fb4 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -183,7 +183,7 @@ test("browser", function() { } test("noConflict", function() { - expect(6); + expect(7); var $$ = jQuery; @@ -196,6 +196,7 @@ test("noConflict", function() { equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" ); equals( jQuery, originaljQuery, "Make sure jQuery was reverted." ); equals( $, original$, "Make sure $ was reverted." ); + ok( $$("#main").html("test"), "Make sure that jQuery still works." ); jQuery = $$; }); From acb162a697e672b2b22e64a02e6278baafac5717 Mon Sep 17 00:00:00 2001 From: jeresig Date: Wed, 8 Sep 2010 18:13:35 -0400 Subject: [PATCH 2/5] Make sure that the removeEvent and buildFragment private functions are exposed (to help with access across modules). The final API for each of these is very much in flux and will likely change before the final release. Fixes #7011. --- src/core.js | 2 +- src/event.js | 4 ++-- src/manipulation.js | 8 ++++---- src/support.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core.js b/src/core.js index f5c27561b..65d32a39c 100644 --- a/src/core.js +++ b/src/core.js @@ -109,7 +109,7 @@ jQuery.fn = jQuery.prototype = { } } else { - ret = buildFragment( [ match[1] ], [ doc ] ); + ret = jQuery.buildFragment( [ match[1] ], [ doc ] ); selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes; } diff --git a/src/event.js b/src/event.js index f0b27de43..5e72aaaab 100644 --- a/src/event.js +++ b/src/event.js @@ -239,7 +239,7 @@ jQuery.event = { // remove generic event handler if no more handlers exist if ( eventType.length === 0 || pos != null && eventType.length === 1 ) { if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) { - removeEvent( elem, type, elemData.handle ); + jQuery.removeEvent( elem, type, elemData.handle ); } ret = null; @@ -527,7 +527,7 @@ jQuery.event = { } }; -var removeEvent = document.removeEventListener ? +jQuery.removeEvent = document.removeEventListener ? function( elem, type, handle ) { if ( elem.removeEventListener ) { elem.removeEventListener( type, handle, false ); diff --git a/src/manipulation.js b/src/manipulation.js index 3054eea1d..c3b8f6d0f 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -327,7 +327,7 @@ jQuery.fn.extend({ results = { fragment: parent }; } else { - results = buildFragment( args, this, scripts ); + results = jQuery.buildFragment( args, this, scripts ); } fragment = results.fragment; @@ -392,7 +392,7 @@ function cloneCopyEvent(orig, ret) { }); } -function buildFragment( args, nodes, scripts ) { +jQuery.buildFragment = function( args, nodes, scripts ) { var fragment, cacheable, cacheresults, doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document); @@ -422,7 +422,7 @@ function buildFragment( args, nodes, scripts ) { } return { fragment: fragment, cacheable: cacheable }; -} +}; jQuery.fragments = {}; @@ -569,7 +569,7 @@ jQuery.extend({ jQuery.event.remove( elem, type ); } else { - removeEvent( elem, type, data.handle ); + jQuery.removeEvent( elem, type, data.handle ); } } } diff --git a/src/support.js b/src/support.js index 75e89dd0e..febff1597 100644 --- a/src/support.js +++ b/src/support.js @@ -134,7 +134,7 @@ // release memory in IE root = script = div = all = a = null; -})(); +})( jQuery ); jQuery.props = { "for": "htmlFor", From 2663041924af36a26a30e60da5d97e2ab9fed5ec Mon Sep 17 00:00:00 2001 From: jeresig Date: Thu, 9 Sep 2010 08:23:10 -0400 Subject: [PATCH 3/5] Make sure that jQuery is being exposed outside of core (this will be stripped during the build process). Follow-up to #7011. --- src/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core.js b/src/core.js index 65d32a39c..d6ef236f4 100644 --- a/src/core.js +++ b/src/core.js @@ -1,4 +1,4 @@ -(function() { +var jQuery = (function() { // Define a local copy of jQuery var jQuery = function( selector, context ) { @@ -826,6 +826,6 @@ function doScrollCheck() { } // Expose jQuery to the global object -window.jQuery = window.$ = jQuery; +return window.jQuery = window.$ = jQuery; })(); From 82b35a4f2c11dc72178b78a1256b20d72b09708d Mon Sep 17 00:00:00 2001 From: jeresig Date: Thu, 9 Sep 2010 10:20:32 -0400 Subject: [PATCH 4/5] Removing extraneous argument. --- src/support.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/support.js b/src/support.js index febff1597..75e89dd0e 100644 --- a/src/support.js +++ b/src/support.js @@ -134,7 +134,7 @@ // release memory in IE root = script = div = all = a = null; -})( jQuery ); +})(); jQuery.props = { "for": "htmlFor", From 1ed405176bfac58f35c3027006e152a4725fd63b Mon Sep 17 00:00:00 2001 From: jeresig Date: Thu, 9 Sep 2010 10:34:21 -0400 Subject: [PATCH 5/5] Trim out the module wrappers during the build process. Follow-up to #7011. --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 0fff724c1..d11d4e1ff 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,8 @@ ${JQ}: selector ${MODULES} @@mkdir -p ${DIST_DIR} @@cat ${MODULES} | \ + sed 's/.function..jQuery...{//' | \ + sed 's/}...jQuery..;//' | \ sed 's/Date:./&'"${DATE}"'/' | \ ${VER} > ${JQ};