Henning Snater has uploaded a new change for review.
https://gerrit.wikimedia.org/r/54643
Change subject: Optimized jquery.eachchange performance
......................................................................
Optimized jquery.eachchange performance
Change-Id: I0af2c258e685631469e16ad9641b88cffc206d52
---
M DataTypes/resources/jquery/jquery.eachchange.js
1 file changed, 29 insertions(+), 25 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues
refs/changes/43/54643/1
diff --git a/DataTypes/resources/jquery/jquery.eachchange.js
b/DataTypes/resources/jquery/jquery.eachchange.js
index ecdbd2b..5ff6315 100644
--- a/DataTypes/resources/jquery/jquery.eachchange.js
+++ b/DataTypes/resources/jquery/jquery.eachchange.js
@@ -12,11 +12,37 @@
* @example $( 'input' ).eachchange( function( event, oldValue ) { ... } );
*
* @dependency jquery.client
- *
- * @TODO: Take care of context related changes via mouse (paste, drag, delete)
and DOM
*/
( function( $, undefined ) {
'use strict';
+
+ /**
+ * Returns a string to be used for detecting any instant changes of an
input box. In general, this
+ * should be just 'input' in recent browsers.
+ *
+ * @return {string} events
+ */
+ $.getInputEvent = function() {
+ // IE (at least <= version 9) does not trigger input event when
pressing backspace
+ // (version <= 8 does not support input event at all anyway)
+ if ( $.client.profile().name === 'msie' &&
$.client.profile().versionNumber >= 9 ) {
+ return 'input keyup';
+ }
+
+ var fallbackEvents = 'keyup keydown blur cut paste mousedown
mouseup mouseout',
+ $input = $( '<input/>' ),
+ supported = 'oninput' in $input[0];
+
+ $input.remove();
+
+ return ( supported ) ? 'input' : fallbackEvents;
+ };
+
+ /**
+ * String containing all the events needed to detect any change of the
input of an element.
+ * @type {string}
+ */
+ var inputEvents = $.getInputEvent();
$.fn.eachchange = function( fn ) {
var monitoredInputs = $();
@@ -35,7 +61,7 @@
var oldVal = input.val(); // old val to compare new one
with
input
- .on( $.getInputEvent(), function( e ) {
+ .on( inputEvents, function( e ) {
/*
* NOTE: we use 'keyup' here as well, so when
holding backspace the thing still gets
* triggered. Also, for some reason in
some browsers 'keydown' isn't triggered
@@ -70,28 +96,6 @@
} );
return this; // return jQuery object
- };
-
- /**
- * Returns a string to be used for detecting any instant changes of an
input box. In general, this
- * should be just 'input' in recent browsers.
- *
- * @return {String} events
- */
- $.getInputEvent = function() {
- var fallbackEvents = 'keyup keydown blur cut paste mousedown
mouseup mouseout';
-
- // IE (at least <= version 9) does not trigger input event when
pressing backspace
- // (version <= 8 does not support input event at all anyway)
- if ( $.client.profile().name === 'msie' &&
$.client.profile().versionNumber >= 9 ) {
- return 'input keyup';
- }
-
- var $input = $( '<input/>' );
- var supported = 'oninput' in $input[0];
- $input.remove();
-
- return ( supported ) ? 'input' : fallbackEvents;
};
}( jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/54643
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0af2c258e685631469e16ad9641b88cffc206d52
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Henning Snater <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits