Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.fn.DelayedKey = function(fn, iKeyDelay, sKeyEvent) {
- var iTimeoutId,
- oEventData;
- if (!$.isFunction(fn)) {
- oEventData = arguments[0];
- fn = arguments[1];
- iKeyDelay = arguments[2];
- sKeyEvent = arguments[3];
- }
- if (!iKeyDelay || 0 > iKeyDelay) {
- iKeyDelay = 500;
- }
- if (!sKeyEvent || !this[sKeyEvent]) {
- sKeyEvent = 'keydown';
- }
- function fnExecCallback() {
- clearTimeout(iTimeoutId);
- fn.apply(this, arguments);
- }
- function fnDelayCallback() {
- var that = this,
- args = arguments;
- clearTimeout(iTimeoutId);
- iTimeoutId = setTimeout(function() {
- fnExecCallback.apply(that, args);
- }, iKeyDelay);
- }
- if (oEventData) {
- this.change(oEventData, fnExecCallback);
- this[sKeyEvent](oEventData, fnDelayCallback);
- }
- else {
- this.change(fnExecCallback);
- this[sKeyEvent](fnDelayCallback);
- }
- return this;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement