From 7a3cf9c03cc34d5493383852f94d96fe4a3486ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?= Date: Tue, 21 Jan 2020 14:12:35 +0100 Subject: [PATCH] Ajax: Deprecate AJAX event aliases, inline event/alias into deprecated A new `src/deprecated` directory makes it possible to exclude some deprecated APIs from a custom build when their respective "parent" module is excluded without keeping that module outside of the `src/deprecated` directory or the `src/deprecated.js` file. Closes gh-4572 (cherry picked from 23d53928f383b0e7440bf4b08b7524e6af232fad) --- Gruntfile.js | 3 +- README.md | 7 ++- src/deprecated.js | 24 +--------- .../ajax-event-alias.js} | 2 +- src/deprecated/event.js | 48 +++++++++++++++++++ src/event/alias.js | 29 ----------- src/jquery.js | 1 - 7 files changed, 56 insertions(+), 58 deletions(-) rename src/{event/ajax.js => deprecated/ajax-event-alias.js} (81%) create mode 100644 src/deprecated/event.js delete mode 100644 src/event/alias.js diff --git a/Gruntfile.js b/Gruntfile.js index af76ce337..f3786d4eb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -58,7 +58,7 @@ module.exports = function( grunt ) { // Exclude specified modules if the module matching the key is removed removeWith: { - ajax: [ "manipulation/_evalUrl", "event/ajax" ], + ajax: [ "manipulation/_evalUrl", "deprecated/ajax-event-alias" ], callbacks: [ "deferred" ], css: [ "effects", "dimensions", "offset" ], "css/showHide": [ "effects" ], @@ -66,6 +66,7 @@ module.exports = function( grunt ) { remove: [ "ajax", "effects", "queue", "core/ready" ], include: [ "core/ready-no-deferred" ] }, + event: [ "deprecated/ajax-event-alias", "deprecated/event" ], sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ] } } diff --git a/README.md b/README.md index 531efc16f..fd6630eaa 100644 --- a/README.md +++ b/README.md @@ -90,10 +90,9 @@ Some example modules that can be excluded are: - **deprecated**: Methods documented as deprecated but not yet removed. - **dimensions**: The `.width()` and `.height()` methods, including `inner-` and `outer-` variations. - **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`. -- **event**: The `.on()` and `.off()` methods and all event functionality. Also removes `event/alias`. -- **event/alias**: All event attaching/triggering shorthands like `.click()` or `.mouseover()`. +- **event**: The `.on()` and `.off()` methods and all event functionality. - **event/focusin**: Cross-browser support for the focusin and focusout events. -- **event/trigger**: The `.trigger()` and `.triggerHandler()` methods. Used by **alias** and **focusin** modules. +- **event/trigger**: The `.trigger()` and `.triggerHandler()` methods. - **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods. - **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods. - **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. @@ -154,7 +153,7 @@ grunt custom:-css Exclude a bunch of modules: ```bash -grunt custom:-ajax,-css,-deprecated,-dimensions,-effects,-event/alias,-offset,-wrap +grunt custom:-ajax/jsonp,-css,-deprecated,-dimensions,-effects,-offset,-wrap ``` There is also a special alias to generate a build with the same configuration as the official jQuery Slim build is generated: diff --git a/src/deprecated.js b/src/deprecated.js index 141f99462..cc13c3c82 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -7,7 +7,8 @@ define( [ "./var/isWindow", "./var/slice", - "./event/alias" + "./deprecated/ajax-event-alias", + "./deprecated/event" ], function( jQuery, nodeName, camelCase, toType, isFunction, isWindow, slice ) { "use strict"; @@ -16,27 +17,6 @@ define( [ // Make sure we trim BOM and NBSP var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g; -jQuery.fn.extend( { - - bind: function( types, data, fn ) { - return this.on( types, null, data, fn ); - }, - unbind: function( types, fn ) { - return this.off( types, null, fn ); - }, - - delegate: function( selector, types, data, fn ) { - return this.on( types, selector, data, fn ); - }, - undelegate: function( selector, types, fn ) { - - // ( namespace ) or ( selector, types [, fn] ) - return arguments.length === 1 ? - this.off( selector, "**" ) : - this.off( types, selector || "**", fn ); - } -} ); - // Bind a function to a context, optionally partially applying any // arguments. // jQuery.proxy is deprecated to promote standards (specifically Function#bind) diff --git a/src/event/ajax.js b/src/deprecated/ajax-event-alias.js similarity index 81% rename from src/event/ajax.js rename to src/deprecated/ajax-event-alias.js index dd9c0ffe2..b96c0aa82 100644 --- a/src/event/ajax.js +++ b/src/deprecated/ajax-event-alias.js @@ -1,11 +1,11 @@ define( [ "../core", + "../ajax", "../event" ], function( jQuery ) { "use strict"; -// Attach a bunch of functions for handling common AJAX events jQuery.each( [ "ajaxStart", "ajaxStop", diff --git a/src/deprecated/event.js b/src/deprecated/event.js new file mode 100644 index 000000000..d2d26bc3e --- /dev/null +++ b/src/deprecated/event.js @@ -0,0 +1,48 @@ +define( [ + "../core", + + "../event", + "../event/trigger" +], function( jQuery ) { + +"use strict"; + +jQuery.fn.extend( { + + bind: function( types, data, fn ) { + return this.on( types, null, data, fn ); + }, + unbind: function( types, fn ) { + return this.off( types, null, fn ); + }, + + delegate: function( selector, types, data, fn ) { + return this.on( types, selector, data, fn ); + }, + undelegate: function( selector, types, fn ) { + + // ( namespace ) or ( selector, types [, fn] ) + return arguments.length === 1 ? + this.off( selector, "**" ) : + this.off( types, selector || "**", fn ); + }, + + hover: function( fnOver, fnOut ) { + return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); + } +} ); + +jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " + + "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + + "change select submit keydown keypress keyup contextmenu" ).split( " " ), + function( _i, name ) { + + // Handle event binding + jQuery.fn[ name ] = function( data, fn ) { + return arguments.length > 0 ? + this.on( name, null, data, fn ) : + this.trigger( name ); + }; + } ); + +} ); diff --git a/src/event/alias.js b/src/event/alias.js deleted file mode 100644 index 46bd1ae80..000000000 --- a/src/event/alias.js +++ /dev/null @@ -1,29 +0,0 @@ -define( [ - "../core", - - "../event", - "./trigger" -], function( jQuery ) { - -"use strict"; - -jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " + - "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " + - "change select submit keydown keypress keyup contextmenu" ).split( " " ), - function( _i, name ) { - - // Handle event binding - jQuery.fn[ name ] = function( data, fn ) { - return arguments.length > 0 ? - this.on( name, null, data, fn ) : - this.trigger( name ); - }; -} ); - -jQuery.fn.extend( { - hover: function( fnOver, fnOut ) { - return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver ); - } -} ); - -} ); diff --git a/src/jquery.js b/src/jquery.js index 0e026a6c1..61c4b2f0d 100644 --- a/src/jquery.js +++ b/src/jquery.js @@ -23,7 +23,6 @@ define( [ "./ajax/script", "./ajax/jsonp", "./ajax/load", - "./event/ajax", "./effects", "./effects/animatedSelector", "./offset", -- 2.39.5