-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpega_yui_event.js
2421 lines (2139 loc) · 82.1 KB
/
pega_yui_event.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.5.1
*/
/**
* The CustomEvent class lets you define events for your application
* that can be subscribed to by one or more independent component.
*
* @param {String} type The type of event, which is passed to the callback
* when the event fires
* @param {Object} oScope The context the event will fire from. "this" will
* refer to this object in the callback. Default value:
* the window object. The listener can override this.
* @param {boolean} silent pass true to prevent the event from writing to
* the debugsystem
* @param {int} signature the signature that the custom event subscriber
* will receive. YAHOO.util.CustomEvent.LIST or
* pega.util.CustomEvent.FLAT. The default is
* pega.util.CustomEvent.LIST.
* @namespace YAHOO.util
* @class CustomEvent
* @constructor
*/
/*
TASK-20675 -- Added by goras.
This is to fix focus in event firing in case of Mozilla.Please don't remove unless this file is upgraded to YUI 2.8 version.
*/
pega.util.CustomEvent = function(type, oScope, silent, signature) {
/**
* The type of event, returned to subscribers when the event fires
* @property type
* @type string
*/
this.type = type;
/**
* The scope the the event will fire from by default. Defaults to the window
* obj
* @property scope
* @type object
*/
this.scope = oScope || window;
/**
* By default all custom events are logged in the debug build, set silent
* to true to disable debug outpu for this event.
* @property silent
* @type boolean
*/
this.silent = silent;
/**
* Custom events support two styles of arguments provided to the event
* subscribers.
* <ul>
* <li>pega.util.CustomEvent.LIST:
* <ul>
* <li>param1: event name</li>
* <li>param2: array of arguments sent to fire</li>
* <li>param3: <optional> a custom object supplied by the subscriber</li>
* </ul>
* </li>
* <li>pega.util.CustomEvent.FLAT
* <ul>
* <li>param1: the first argument passed to fire. If you need to
* pass multiple parameters, use and array or object literal</li>
* <li>param2: <optional> a custom object supplied by the subscriber</li>
* </ul>
* </li>
* </ul>
* @property signature
* @type int
*/
this.signature = signature || pega.util.CustomEvent.LIST;
/**
* The subscribers to this event
* @property subscribers
* @type Subscriber[]
*/
this.subscribers = [];
if (!this.silent) {
}
var onsubscribeType = "_YUICEOnSubscribe";
// Only add subscribe events for events that are not generated by
// CustomEvent
if (type !== onsubscribeType) {
/**
* Custom events provide a custom event that fires whenever there is
* a new subscriber to the event. This provides an opportunity to
* handle the case where there is a non-repeating event that has
* already fired has a new subscriber.
*
* @event subscribeEvent
* @type pega.util.CustomEvent
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event
* fires
* @param {boolean|Object} override If true, the obj passed in becomes
* the execution scope of the listener.
* if an object, that object becomes the
* the execution scope.
*/
this.subscribeEvent =
new pega.util.CustomEvent(onsubscribeType, this, true);
}
/**
* In order to make it possible to execute the rest of the subscriber
* stack when one thows an exception, the subscribers exceptions are
* caught. The most recent exception is stored in this property
* @property lastError
* @type Error
*/
this.lastError = null;
};
/**
* Subscriber listener sigature constant. The LIST type returns three
* parameters: the event type, the array of args passed to fire, and
* the optional custom object
* @property pega.util.CustomEvent.LIST
* @static
* @type int
*/
pega.util.CustomEvent.LIST = 0;
/**
* Subscriber listener sigature constant. The FLAT type returns two
* parameters: the first argument passed to fire and the optional
* custom object
* @property pega.util.CustomEvent.FLAT
* @static
* @type int
*/
pega.util.CustomEvent.FLAT = 1;
pega.util.CustomEvent.prototype = {
/**
* Subscribes the caller to this event
* @method subscribe
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event
* fires
* @param {boolean|Object} override If true, the obj passed in becomes
* the execution scope of the listener.
* if an object, that object becomes the
* the execution scope.
*/
subscribe: function(fn, obj, override) {
if (!fn) {
throw new Error("Invalid callback for subscriber to '" + this.type + "'");
}
if (this.subscribeEvent) {
this.subscribeEvent.fire(fn, obj, override);
}
this.subscribers.push( new pega.util.Subscriber(fn, obj, override) );
},
/**
* Unsubscribes subscribers.
* @method unsubscribe
* @param {Function} fn The subscribed function to remove, if not supplied
* all will be removed
* @param {Object} obj The custom object passed to subscribe. This is
* optional, but if supplied will be used to
* disambiguate multiple listeners that are the same
* (e.g., you subscribe many object using a function
* that lives on the prototype)
* @return {boolean} True if the subscriber was found and detached.
*/
unsubscribe: function(fn, obj) {
if (!fn) {
return this.unsubscribeAll();
}
var found = false;
for (var i=0, len=this.subscribers.length; i<len; ++i) {
var s = this.subscribers[i];
if (s && s.contains(fn, obj)) {
this._delete(i);
found = true;
}
}
return found;
},
/**
* Notifies the subscribers. The callback functions will be executed
* from the scope specified when the event was created, and with the
* following parameters:
* <ul>
* <li>The type of event</li>
* <li>All of the arguments fire() was executed with as an array</li>
* <li>The custom object (if any) that was passed into the subscribe()
* method</li>
* </ul>
* @method fire
* @param {Object*} arguments an arbitrary set of parameters to pass to
* the handler.
* @return {boolean} false if one of the subscribers returned false,
* true otherwise
*/
fire: function() {
var len=this.subscribers.length;
if (!len && this.silent) {
return true;
}
var args=[].slice.call(arguments, 0), ret=true, i, rebuild=false;
if (!this.silent) {
}
// make a copy of the subscribers so that there are
// no index problems if one subscriber removes another.
var subs = this.subscribers.slice();
for (i=0; i<len; ++i) {
var s = subs[i];
if (!s) {
rebuild=true;
} else {
if (!this.silent) {
}
var scope = s.getScope(this.scope);
if (this.signature == pega.util.CustomEvent.FLAT) {
var param = null;
if (args.length > 0) {
param = args[0];
}
try {
ret = s.fn.call(scope, param, s.obj);
} catch(e) {
this.lastError = e;
}
} else {
try {
ret = s.fn.call(scope, this.type, args, s.obj);
} catch(ex) {
this.lastError = ex;
}
}
if (false === ret) {
if (!this.silent) {
}
//break;
return false;
}
}
}
// if (rebuild) {
// var newlist=this.,subs=this.subscribers;
// for (i=0,len=subs.length; i<len; i=i+1) {
// // this wasn't doing anything before
// newlist.push(subs[i]);
// }
// this.subscribers=newlist;
// }
return true;
},
/**
* Removes all listeners
* @method unsubscribeAll
* @return {int} The number of listeners unsubscribed
*/
unsubscribeAll: function() {
for (var i=this.subscribers.length-1; i>-1; i--) {
this._delete(i);
}
this.subscribers=[];
return i;
},
/**
* @method _delete
* @private
*/
_delete: function(index) {
var s = this.subscribers[index];
if (s) {
delete s.fn;
delete s.obj;
}
// this.subscribers[index]=null;
this.subscribers.splice(index, 1);
},
/**
* @method toString
*/
toString: function() {
return "CustomEvent: " + "'" + this.type + "', " +
"scope: " + this.scope;
}
};
/////////////////////////////////////////////////////////////////////
/**
* Stores the subscriber information to be used when the event fires.
* @param {Function} fn The function to execute
* @param {Object} obj An object to be passed along when the event fires
* @param {boolean} override If true, the obj passed in becomes the execution
* scope of the listener
* @class Subscriber
* @constructor
*/
pega.util.Subscriber = function(fn, obj, override) {
/**
* The callback that will be execute when the event fires
* @property fn
* @type function
*/
this.fn = fn;
/**
* An optional custom object that will passed to the callback when
* the event fires
* @property obj
* @type object
*/
this.obj = pega.lang.isUndefined(obj) ? null : obj;
/**
* The default execution scope for the event listener is defined when the
* event is created (usually the object which contains the event).
* By setting override to true, the execution scope becomes the custom
* object passed in by the subscriber. If override is an object, that
* object becomes the scope.
* @property override
* @type boolean|object
*/
this.override = override;
};
/**
* Returns the execution scope for this listener. If override was set to true
* the custom obj will be the scope. If override is an object, that is the
* scope, otherwise the default scope will be used.
* @method getScope
* @param {Object} defaultScope the scope to use if this listener does not
* override it.
*/
pega.util.Subscriber.prototype.getScope = function(defaultScope) {
if (this.override) {
if (this.override === true) {
return this.obj;
} else {
return this.override;
}
}
return defaultScope;
};
/**
* Returns true if the fn and obj match this objects properties.
* Used by the unsubscribe method to match the right subscriber.
*
* @method contains
* @param {Function} fn the function to execute
* @param {Object} obj an object to be passed along when the event fires
* @return {boolean} true if the supplied arguments match this
* subscriber's signature.
*/
pega.util.Subscriber.prototype.contains = function(fn, obj) {
if (obj) {
return (this.fn == fn && this.obj == obj);
} else {
return (this.fn == fn);
}
};
/**
* @method toString
*/
pega.util.Subscriber.prototype.toString = function() {
return "Subscriber { obj: " + this.obj +
", override: " + (this.override || "no") + " }";
};
/**
* The Event Utility provides utilities for managing DOM Events and tools
* for building event systems
*
* @module event
* @title Event Utility
* @namespace pega.util
* @requires pega
*/
// The first instance of Event will win if it is loaded more than once.
// @TODO this needs to be changed so that only the state data that needs to
// be preserved is kept, while methods are overwritten/added as needed.
// This means that the module pattern can't be used.
if (!pega.util.Event) {
/**
* The event utility provides functions to add and remove event listeners,
* event cleansing. It also tries to automatically remove listeners it
* registers during the unload event.
*
* @class Event
* @static
*/
pega.util.Event = function() {
/**
* True after the onload event has fired
* @property loadComplete
* @type boolean
* @static
* @private
*/
var loadComplete = false;
/**
* Cache of wrapped listeners
* @property listeners
* @type array
* @static
* @private
*/
var listeners = [];
/**
* User-defined unload function that will be fired before all events
* are detached
* @property unloadListeners
* @type array
* @static
* @private
*/
var unloadListeners = [];
/**
* Cache of DOM0 event handlers to work around issues with DOM2 events
* in Safari
* @property legacyEvents
* @static
* @private
*/
var legacyEvents = [];
/**
* Listener stack for DOM0 events
* @property legacyHandlers
* @static
* @private
*/
var legacyHandlers = [];
/**
* The number of times to poll after window.onload. This number is
* increased if additional late-bound handlers are requested after
* the page load.
* @property retryCount
* @static
* @private
*/
var retryCount = 0;
/**
* onAvailable listeners
* @property onAvailStack
* @static
* @private
*/
var onAvailStack = [];
/**
* Lookup table for legacy events
* @property legacyMap
* @static
* @private
*/
var legacyMap = [];
/**
* Counter for auto id generation
* @property counter
* @static
* @private
*/
var counter = 0;
/**
* Normalized keycodes for webkit/safari
* @property webkitKeymap
* @type {int: int}
* @private
* @static
* @final
*/
var webkitKeymap = {
63232: 38, // up
63233: 40, // down
63234: 37, // left
63235: 39, // right
63276: 33, // page up
63277: 34, // page down
25: 9 // SHIFT-TAB (Safari provides a different key code in
// this case, even though the shiftKey modifier is set)
};
return {
/**
* The number of times we should look for elements that are not
* in the DOM at the time the event is requested after the document
* has been loaded. The default is 2000@amp;20 ms, so it will poll
* for 40 seconds or until all outstanding handlers are bound
* (whichever comes first).
* @property POLL_RETRYS
* @type int
* @static
* @final
*/
POLL_RETRYS: 2000,
/**
* The poll interval in milliseconds
* @property POLL_INTERVAL
* @type int
* @static
* @final
*/
POLL_INTERVAL: 20,
/**
* Element to bind, int constant
* @property EL
* @type int
* @static
* @final
*/
EL: 0,
/**
* Type of event, int constant
* @property TYPE
* @type int
* @static
* @final
*/
TYPE: 1,
/**
* Function to execute, int constant
* @property FN
* @type int
* @static
* @final
*/
FN: 2,
/**
* Function wrapped for scope correction and cleanup, int constant
* @property WFN
* @type int
* @static
* @final
*/
WFN: 3,
/**
* Object passed in by the user that will be returned as a
* parameter to the callback, int constant. Specific to
* unload listeners
* @property OBJ
* @type int
* @static
* @final
*/
UNLOAD_OBJ: 3,
/**
* Adjusted scope, either the element we are registering the event
* on or the custom object passed in by the listener, int constant
* @property ADJ_SCOPE
* @type int
* @static
* @final
*/
ADJ_SCOPE: 4,
/**
* The original obj passed into addListener
* @property OBJ
* @type int
* @static
* @final
*/
OBJ: 5,
/**
* The original scope parameter passed into addListener
* @property OVERRIDE
* @type int
* @static
* @final
*/
OVERRIDE: 6,
/**
* addListener/removeListener can throw errors in unexpected scenarios.
* These errors are suppressed, the method returns false, and this property
* is set
* @property lastError
* @static
* @type Error
*/
lastError: null,
/**
* Safari detection
* @property isSafari
* @private
* @static
* @deprecated use pega.env.ua.webkit
*/
isSafari: pega.env.ua.webkit,
/**
* webkit version
* @property webkit
* @type string
* @private
* @static
* @deprecated use pega.env.ua.webkit
*/
webkit: pega.env.ua.webkit,
/**
* IE detection
* @property isIE
* @private
* @static
* @deprecated use pega.env.ua.ie
*/
isIE: pega.env.ua.ie,
/**
* IE Edge detection
* @property isEdge
* @private
* @static
*/
isEdge: /Edge/.test(navigator.userAgent) ? true : false,
/**
* poll handle
* @property _interval
* @static
* @private
*/
_interval: null,
/**
* document readystate poll handle
* @property _dri
* @static
* @private
*/
_dri: null,
/**
* True when the document is initially usable
* @property DOMReady
* @type boolean
* @static
*/
DOMReady: false,
/**
* @method startInterval
* @static
* @private
*/
startInterval: function() {
if (!this._interval) {
var self = this;
var callback = function() { self._tryPreloadAttach(); };
this._interval = setInterval(callback, this.POLL_INTERVAL);
}
},
/**
* Executes the supplied callback when the item with the supplied
* id is found. This is meant to be used to execute behavior as
* soon as possible as the page loads. If you use this after the
* initial page load it will poll for a fixed time for the element.
* The number of times it will poll and the frequency are
* configurable. By default it will poll for 10 seconds.
*
* <p>The callback is executed with a single parameter:
* the custom object parameter, if provided.</p>
*
* @method onAvailable
*
* @param {string||string[]} p_id the id of the element, or an array
* of ids to look for.
* @param {function} p_fn what to execute when the element is found.
* @param {object} p_obj an optional object to be passed back as
* a parameter to p_fn.
* @param {boolean|object} p_override If set to true, p_fn will execute
* in the scope of p_obj, if set to an object it
* will execute in the scope of that object
* @param checkContent {boolean} check child node readiness (onContentReady)
* @static
*/
onAvailable: function(p_id, p_fn, p_obj, p_override, checkContent) {
var a = (pega.lang.isString(p_id)) ? [p_id] : p_id;
for (var i=0; i<a.length; i=i+1) {
onAvailStack.push({id: a[i],
fn: p_fn,
obj: p_obj,
override: p_override,
checkReady: checkContent });
}
retryCount = this.POLL_RETRYS;
this.startInterval();
},
/**
* Works the same way as onAvailable, but additionally checks the
* state of sibling elements to determine if the content of the
* available element is safe to modify.
*
* <p>The callback is executed with a single parameter:
* the custom object parameter, if provided.</p>
*
* @method onContentReady
*
* @param {string} p_id the id of the element to look for.
* @param {function} p_fn what to execute when the element is ready.
* @param {object} p_obj an optional object to be passed back as
* a parameter to p_fn.
* @param {boolean|object} p_override If set to true, p_fn will execute
* in the scope of p_obj. If an object, p_fn will
* exectute in the scope of that object
*
* @static
*/
onContentReady: function(p_id, p_fn, p_obj, p_override) {
this.onAvailable(p_id, p_fn, p_obj, p_override, true);
},
/**
* Executes the supplied callback when the DOM is first usable. This
* will execute immediately if called after the DOMReady event has
* fired. @todo the DOMContentReady event does not fire when the
* script is dynamically injected into the page. This means the
* DOMReady custom event will never fire in FireFox or Opera when the
* library is injected. It _will_ fire in Safari, and the IE
* implementation would allow for us to fire it if the defered script
* is not available. We want this to behave the same in all browsers.
* Is there a way to identify when the script has been injected
* instead of included inline? Is there a way to know whether the
* window onload event has fired without having had a listener attached
* to it when it did so?
*
* <p>The callback is a CustomEvent, so the signature is:</p>
* <p>type <string>, args <array>, customobject <object></p>
* <p>For DOMReady events, there are no fire argments, so the
* signature is:</p>
* <p>"DOMReady", [], obj</p>
*
*
* @method onDOMReady
*
* @param {function} p_fn what to execute when the element is found.
* @param {object} p_obj an optional object to be passed back as
* a parameter to p_fn.
* @param {boolean|object} p_scope If set to true, p_fn will execute
* in the scope of p_obj, if set to an object it
* will execute in the scope of that object
*
* @static
*/
onDOMReady: function(p_fn, p_obj, p_override) {
if (this.DOMReady) {
setTimeout(function() {
var s = window;
if (p_override) {
if (p_override === true) {
s = p_obj;
} else {
s = p_override;
}
}
p_fn.call(s, "DOMReady", [], p_obj);
}, 0);
} else {
this.DOMReadyEvent.subscribe(p_fn, p_obj, p_override);
}
},
/* 07/01/2011 GUJAS1 BUG-46147 - Added helper method to obtain listeners array length.
This value is passed back as removeListener's third parameter to bypass costly lookup.
*/
/**
* Returns the length of the listeners array.
*
* @method getListenerArrayLength
*
* @return {Number} -1 if listeners array is not found,
* Length of the listeners array if it is found.
* @static
*/
getListenerArrayLength: function(){
if (typeof listeners === "object" && typeof listeners.length == "number"){
return listeners.length;
}
},
/**
* Appends an event handler
*
* @method addListener
*
* @param {String|HTMLElement|Array|NodeList} el An id, an element
* reference, or a collection of ids and/or elements to assign the
* listener to.
* @param {String} sType The type of event to append
* @param {Function} fn The method the event invokes
* @param {Object} obj An arbitrary object that will be
* passed as a parameter to the handler
* @param {Boolean|object} override If true, the obj passed in becomes
* the execution scope of the listener. If an
* object, this object becomes the execution
* scope.
* @return {Boolean} True if the action was successful or defered,
* false if one or more of the elements
* could not have the listener attached,
* or if the operation throws an exception.
* @static
*/
addListener: function(el, sType, fn, obj, override) {
if (!fn || !fn.call) {
return false;
}
// The el argument can be an array of elements or element ids.
if ( this._isValidCollection(el)) {
var ok = true;
for (var i=0,len=el.length; i<len; ++i) {
ok = this.on(el[i],
sType,
fn,
obj,
override) && ok;
}
return ok;
} else if (pega.lang.isString(el)) {
var oEl = this.getEl(el);
// If the el argument is a string, we assume it is
// actually the id of the element. If the page is loaded
// we convert el to the actual element, otherwise we
// defer attaching the event until onload event fires
// check to see if we need to delay hooking up the event
// until after the page loads.
if (oEl) {
el = oEl;
} else {
// defer adding the event until the element is available
this.onAvailable(el, function() {
pega.util.Event.on(el, sType, fn, obj, override);
});
return true;
}
}
// Element should be an html element or an array if we get
// here.
if (!el) {
return false;
}
// we need to make sure we fire registered unload events
// prior to automatically unhooking them. So we hang on to
// these instead of attaching them to the window and fire the
// handles explicitly during our one unload event.
if ("unload" == sType && obj !== this) {
unloadListeners[unloadListeners.length] =
[el, sType, fn, obj, override];
return true;
}
// if the user chooses to override the scope, we use the custom
// object passed in, otherwise the executing scope will be the
// HTML element that the event is registered on
var scope = el;
if (override) {
if (override === true) {
scope = obj;
} else {
scope = override;
}
}
// wrap the function so we can return the obj object when
// the event fires;
var wrappedFn = function(e) {
return fn.call(scope, pega.util.Event.getEvent(e, el),
obj);
};
var li = [el, sType, fn, wrappedFn, scope, obj, override];
var index = listeners.length;
// cache the listener so we can try to automatically unload
listeners[index] = li;
if (this.useLegacyEvent(el, sType)) {
var legacyIndex = this.getLegacyIndex(el, sType);
// Add a new dom0 wrapper if one is not detected for this
// element
if ( legacyIndex == -1 ||
el != legacyEvents[legacyIndex][0] ) {
legacyIndex = legacyEvents.length;
legacyMap[el.id + sType] = legacyIndex;
// cache the signature for the DOM0 event, and
// include the existing handler for the event, if any
legacyEvents[legacyIndex] =
[el, sType, el["on" + sType]];
legacyHandlers[legacyIndex] = [];
el["on" + sType] =
function(e) {
pega.util.Event.fireLegacyEvent(
pega.util.Event.getEvent(e), legacyIndex);
};
}
// add a reference to the wrapped listener to our custom
// stack of events
//legacyHandlers[legacyIndex].push(index);
legacyHandlers[legacyIndex].push(li);
} else {
try {
// Providing for bubblable focus and blur in Firefox by using the capturing option
if(!pega.env.ua.ie)
{
if(sType=="focusin")
sType="focus";
else if(sType=="focusout")
sType="blur";
}
/* TASK-20675 BEGIN */
var capture = ((sType == "focus" || sType == "blur") && !pega.env.ua.ie) ? true : false;
this._simpleAdd(el, sType, wrappedFn, capture);
/* TASK-20675 END */
} catch(ex) {
// handle an error trying to attach an event. If it fails
// we need to clean up the cache