forked from bitovi/jquerypp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.js
More file actions
119 lines (99 loc) · 3.1 KB
/
default.js
File metadata and controls
119 lines (99 loc) · 3.1 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
steal('jquery/event').then(function($){
/**
* @function jQuery.fn.triggerAsync
* @parent jQuery.event.pause
* @plugin jquery/event/default
*
* `jQuery.fn.triggerAsync(type, [data], [success], [prevented]` triggers an event and calls success
* when the event has finished propagating through the DOM and no other handler
* called `event.preventDefault()` or returned `false`.
*
* $('#panel').triggerAsync('show', function() {
* $('#panel').show();
* });
*
* You can also provide a callback that gets called if `event.preventDefault()` was called on the event:
*
* $('panel').triggerAsync('show', function(){
* $('#panel').show();
* },function(){
* $('#other').addClass('error');
* });
*
* @param {String} type The type of event
* @param {Object} data The data for the event
* @param {Function} success a callback function which occurs upon success
* @param {Function} prevented a callback function which occurs if preventDefault was called
*/
$.fn.triggerAsync = function(type, data, success, prevented){
if(typeof data == 'function'){
success = data;
data = undefined;
}
if ( this[0] ) {
var event = $.Event( type ),
old = event.preventDefault;
event.preventDefault = function(){
old.apply(this, arguments);
prevented && prevented(this)
}
//event._success= success;
jQuery.event.trigger( {type: type, _success: success}, data, this[0] );
} else{
success.call(this);
}
return this;
}
/**
* @add jQuery.event.special
*/
//cache default types for performance
var types = {}, rnamespaces= /\.(.*)$/, $event = $.event;
/**
* @attribute default
* @parent specialevents
* @plugin jquery/event/default
* @download http://jmvcsite.heroku.com/pluginify?plugins[]=jquery/event/default/default.js
* @test jquery/event/default/qunit.html
*
*/
$event.special["default"] = {
add: function( handleObj ) {
//save the type
types[handleObj.namespace.replace(rnamespaces,"")] = true;
},
setup: function() {return true}
}
// overwrite trigger to allow default types
var oldTrigger = $event.trigger;
$event.trigger = function defaultTriggerer( event, data, elem, onlyHandlers){
// Event object or event type
var type = event.type || event,
namespaces = [],
// Caller can pass in an Event, Object, or just an event type string
event = typeof event === "object" ?
// jQuery.Event object
event[ jQuery.expando ] ? event :
// Object literal
new jQuery.Event( type, event ) :
// Just the event type (string)
new jQuery.Event( type );
//event._defaultActions = []; //set depth for possibly reused events
var res = oldTrigger.call($.event, event, data, elem, onlyHandlers);
if(!onlyHandlers && !event.isDefaultPrevented() && event.type.indexOf("default") !== 0){
oldTrigger("default."+event.type, data, elem)
if(event._success){
event._success(event)
}
}
// code for paused
if( event.isPaused && event.isPaused() ){
// set back original stuff
event.isDefaultPrevented =
event.pausedState.isDefaultPrevented;
event.isPropagationStopped =
event.pausedState.isPropagationStopped;
}
return res;
};
});