mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Build: Add the ability to remove global exposure.
Ref #14016 Conflicts: build/tasks/build.js src/core.js
This commit is contained in:
parent
0e89df5b6d
commit
1d3b60044b
@ -84,6 +84,7 @@ Some example modules that can be excluded are:
|
|||||||
- **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods.
|
- **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods.
|
||||||
- **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods.
|
- **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods.
|
||||||
- **exports/amd**: Exclude the AMD definition.
|
- **exports/amd**: Exclude the AMD definition.
|
||||||
|
- **exports/global**: Exclude the attachment of global jQuery variables ($ and jQuery) to the window.
|
||||||
- **core/ready**: Exclude the ready module if you place your scripts at the end of the body. Any ready callbacks bound with `jQuery()` will simply be called immediately. However, `jQuery(document).ready()` will not be a function and `.on("ready", ...)` or similar will not be triggered.
|
- **core/ready**: Exclude the ready module if you place your scripts at the end of the body. Any ready callbacks bound with `jQuery()` will simply be called immediately. However, `jQuery(document).ready()` will not be a function and `.on("ready", ...)` or similar will not be triggered.
|
||||||
- **deferred**: Exclude jQuery.Deferred. This also removes jQuery.Callbacks. *Note* that modules that depend on jQuery.Deferred(AJAX, effects, core/ready) will not be removed and will still expect jQuery.Deferred to be there. Include your own jQuery.Deferred implementation or exclude those modules as well (`grunt custom:-deferred,-ajax,-effects,-core/ready`).
|
- **deferred**: Exclude jQuery.Deferred. This also removes jQuery.Callbacks. *Note* that modules that depend on jQuery.Deferred(AJAX, effects, core/ready) will not be removed and will still expect jQuery.Deferred to be there. Include your own jQuery.Deferred implementation or exclude those modules as well (`grunt custom:-deferred,-ajax,-effects,-core/ready`).
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ module.exports = function( grunt ) {
|
|||||||
"build",
|
"build",
|
||||||
"Concatenate source, remove sub AMD definitions, (include/exclude modules with +/- flags), embed date/version",
|
"Concatenate source, remove sub AMD definitions, (include/exclude modules with +/- flags), embed date/version",
|
||||||
function() {
|
function() {
|
||||||
var flag,
|
var flag, index,
|
||||||
done = this.async(),
|
done = this.async(),
|
||||||
flags = this.flags,
|
flags = this.flags,
|
||||||
optIn = flags[ "*" ],
|
optIn = flags[ "*" ],
|
||||||
@ -186,6 +186,13 @@ module.exports = function( grunt ) {
|
|||||||
excluder( flag );
|
excluder( flag );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace exports/global with a noop noConflict
|
||||||
|
if ( (index = excluded.indexOf( "exports/global" )) > -1 ) {
|
||||||
|
config.rawText[ "exports/global" ] = "define(['../core']," +
|
||||||
|
"function( jQuery ) {\njQuery.noConflict = function() {};\n});";
|
||||||
|
excluded.splice( index, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
grunt.verbose.writeflags( excluded, "Excluded" );
|
grunt.verbose.writeflags( excluded, "Excluded" );
|
||||||
grunt.verbose.writeflags( included, "Included" );
|
grunt.verbose.writeflags( included, "Included" );
|
||||||
|
|
||||||
|
18
src/core.js
18
src/core.js
@ -12,12 +12,6 @@ define([
|
|||||||
], function( deletedIds, slice, concat, push, indexOf, class2type, toString, hasOwn, trim, support ) {
|
], function( deletedIds, slice, concat, push, indexOf, class2type, toString, hasOwn, trim, support ) {
|
||||||
|
|
||||||
var
|
var
|
||||||
// Map over jQuery in case of overwrite
|
|
||||||
_jQuery = window.jQuery,
|
|
||||||
|
|
||||||
// Map over the $ in case of overwrite
|
|
||||||
_$ = window.$,
|
|
||||||
|
|
||||||
version = "@VERSION",
|
version = "@VERSION",
|
||||||
|
|
||||||
// Define a local copy of jQuery
|
// Define a local copy of jQuery
|
||||||
@ -202,18 +196,6 @@ jQuery.extend({
|
|||||||
|
|
||||||
noop: function() {},
|
noop: function() {},
|
||||||
|
|
||||||
noConflict: function( deep ) {
|
|
||||||
if ( window.$ === jQuery ) {
|
|
||||||
window.$ = _$;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( deep && window.jQuery === jQuery ) {
|
|
||||||
window.jQuery = _jQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
return jQuery;
|
|
||||||
},
|
|
||||||
|
|
||||||
// See test/unit/core.js for details concerning isFunction.
|
// See test/unit/core.js for details concerning isFunction.
|
||||||
// Since version 1.3, DOM methods and functions like alert
|
// Since version 1.3, DOM methods and functions like alert
|
||||||
// aren't supported. They return false on IE (#2968).
|
// aren't supported. They return false on IE (#2968).
|
||||||
|
29
src/exports/global.js
Normal file
29
src/exports/global.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
define([
|
||||||
|
"../core"
|
||||||
|
], function( jQuery ) {
|
||||||
|
|
||||||
|
var
|
||||||
|
// Map over jQuery in case of overwrite
|
||||||
|
_jQuery = window.jQuery,
|
||||||
|
|
||||||
|
// Map over the $ in case of overwrite
|
||||||
|
_$ = window.$;
|
||||||
|
|
||||||
|
jQuery.noConflict = function( deep ) {
|
||||||
|
if ( window.$ === jQuery ) {
|
||||||
|
window.$ = _$;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( deep && window.jQuery === jQuery ) {
|
||||||
|
window.jQuery = _jQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
return jQuery;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Expose jQuery and $ identifiers, even in
|
||||||
|
// AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
|
||||||
|
// and CommonJS for browser emulators (#13566)
|
||||||
|
window.jQuery = window.$ = jQuery;
|
||||||
|
|
||||||
|
});
|
8
src/jquery.js
vendored
8
src/jquery.js
vendored
@ -28,12 +28,10 @@ define([
|
|||||||
"./offset",
|
"./offset",
|
||||||
"./dimensions",
|
"./dimensions",
|
||||||
"./deprecated",
|
"./deprecated",
|
||||||
"./exports/amd"
|
"./exports/amd",
|
||||||
|
"./exports/global"
|
||||||
], function( jQuery ) {
|
], function( jQuery ) {
|
||||||
|
|
||||||
// Expose jQuery and $ identifiers, even in
|
return jQuery;
|
||||||
// AMD (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
|
|
||||||
// and CommonJS for browser emulators (#13566)
|
|
||||||
return (window.jQuery = window.$ = jQuery);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user