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
103 lines (86 loc) · 2.58 KB
/
pause.js
File metadata and controls
103 lines (86 loc) · 2.58 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
steal('jquery/event/default').then(function($){
var current,
rnamespaces = /\.(.*)$/,
returnFalse = function(){return false},
returnTrue = function(){return true};
$.Event.prototype.isPaused = returnFalse
/**
* @function jQuery.Event.prototype.pause
* @parent jQuery.event.pause
*
* `event.paused()` 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
* @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 = jQuery.event.special[ handleObj.origType ],
origHandle = origType && origType.handle;
if(!origType){
jQuery.event.special[ handleObj.origType ] = {};
}
jQuery.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 jQuery.event.special[ handleObj.origType ];
} else {
jQuery.event.special[ handleObj.origType ].handle = origHandle;
}
}
}
delete this.pausedState;
// reset stuff
this.isPaused = this.isImmediatePropagationStopped = returnFalse;
// re-run dispatch
//$.event.dispatch.call(currentTarget, this)
// with the events removed, dispatch
if(!this.isPropagationStopped()){
// fire the event again, no events will get fired until
// same currentTarget / handler
$.event.trigger(this, [], this.target);
}
};
/*var oldDispatch = $.event.dispatch;
$.event.dispatch = function(){
}*/
// we need to finish handling
// and then trigger on next element ...
// can we fake the target ?
});