Skip to content

Commit 5a10982

Browse files
committed
Implement own debounce function for compatibility with Gravity Forms
1 parent f0c9ead commit 5a10982

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

lib/class-option-number.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,27 @@ public static function createSliderScript() {
121121
}
122122
} ).disableSelection();
123123
} );
124-
$( '.tf-number input[type=number]' ).on( 'keyup', _.debounce( function() {
124+
125+
// Returns a function, that, as long as it continues to be invoked, will not
126+
// be triggered. The function will be called after it stops being called for
127+
// N milliseconds. If `immediate` is passed, trigger the function on the
128+
// leading edge, instead of the trailing.
129+
function debounce(func, wait, immediate) {
130+
var timeout;
131+
return function() {
132+
var context = this, args = arguments;
133+
var later = function() {
134+
timeout = null;
135+
if (!immediate) func.apply(context, args);
136+
};
137+
var callNow = immediate && !timeout;
138+
clearTimeout(timeout);
139+
timeout = setTimeout(later, wait);
140+
if (callNow) func.apply(context, args);
141+
};
142+
};
143+
144+
$( '.tf-number input[type=number]' ).on( 'keyup', debounce( function() {
125145
if ( $( this ).prev().slider( 'value' ).toString() !== $( this ).val().toString() ) {
126146
$( this ).prev().slider( 'value', $( this ).val() );
127147
}

0 commit comments

Comments
 (0)