forked from bitovi/jquerypp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpause.js
More file actions
88 lines (78 loc) · 2.31 KB
/
pause.js
File metadata and controls
88 lines (78 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
steal('jquery', 'jquerypp/event/default', function($) {
var current,
rnamespaces = /\.(.*)$/,
returnFalse = function(){return false},
returnTrue = function(){return true};
$.Event.prototype.isPaused = returnFalse
/**
* @function jQuery.Event.prototype.pause pause
* @parent jQuery.event.pause
*
* `event.pause()` pauses an event (to be resumed later):
*
* $('.tab').on('show', function(ev) {
* ev.pause();
* // Resume the event after 1 second
* setTimeout(function() {
* ev.resume();
* }, 1000);
* });
*/
$.Event.prototype.pause = function(){
// stop the event from continuing temporarily
// keep the current state of the event ...
this.pausedState = {
isDefaultPrevented : this.isDefaultPrevented() ?
returnTrue : returnFalse,
isPropagationStopped : this.isPropagationStopped() ?
returnTrue : returnFalse
};
this.stopImmediatePropagation();
this.preventDefault();
this.isPaused = returnTrue;
};
/**
* @function jQuery.Event.prototype.resume resume
* @parent jQuery.event.pause
*
* `event.resume()` resumes a paused event:
*
* $('.tab').on('show', function(ev) {
* ev.pause();
* // Resume the event after 1 second
* setTimeout(function() {
* ev.resume();
* }, 1000);
* });
*/
$.Event.prototype.resume = function(){
// temporarily remove all event handlers of this type
var handleObj = this.handleObj,
currentTarget = this.currentTarget;
// temporarily overwrite special handle
var origType = $.event.special[ handleObj.origType ],
origHandle = origType && origType.handle;
if(!origType){
$.event.special[ handleObj.origType ] = {};
}
$.event.special[ handleObj.origType ].handle = function(ev){
// remove this once we have passed the handleObj
if(ev.handleObj === handleObj && ev.currentTarget === currentTarget){
if(!origType){
delete $.event.special[ handleObj.origType ];
} else {
$.event.special[ handleObj.origType ].handle = origHandle;
}
}
}
delete this.pausedState;
// reset stuff
this.isPaused = this.isImmediatePropagationStopped = returnFalse;
if(!this.isPropagationStopped()){
// fire the event again, no events will get fired until
// same currentTarget / handler
$.event.trigger(this, [], this.target);
}
};
return $;
});