How to use CustomEvent method in Karma

Best JavaScript code snippet using karma

Run Karma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

EventHelper.js

Source: EventHelper.js Github

copy
1Ext.define("Ext.irm.EventHelper",{
2    statics: {
3        //mouse events supported
4        mouseEvents: {
5            click:      1,
6            dblclick:   1,
7            mouseover:  1,
8            mouseout:   1,
9            mousedown:  1,
10            mouseup:    1,
11            mousemove:  1
12        },
13        //key events supported
14        keyEvents: {
15            keydown:    1,
16            keyup:      1,
17            keypress:   1
18        },
19        //HTML events supported
20        uiEvents  : {
21            blur:       1,
22            change:     1,
23            focus:      1,
24            resize:     1,
25            scroll:     1,
26            select:     1
27        },
28        //events that bubble by default
29        bubbleEvents : {
30            scroll:     1,
31            resize:     1,
32            reset:      1,
33            submit:     1,
34            change:     1,
35            select:     1,
36            error:      1,
37            abort:      1
38        }
39    }
40});
41
42
43Ext.apply(Ext.irm.EventHelper.bubbleEvents,Ext.irm.EventHelper.mouseEvents,Ext.irm.EventHelper.keyEvents);
44
45Ext.irm.EventHelper.simulateKeyEvent = function(target /*:HTMLElement*/, type /*:String*/,
46                             bubbles /*:Boolean*/,  cancelable /*:Boolean*/,
47                             view /*:Window*/,
48                             ctrlKey /*:Boolean*/,    altKey /*:Boolean*/,
49                             shiftKey /*:Boolean*/,   metaKey /*:Boolean*/,
50                             keyCode /*:int*/,        charCode /*:int*/) /*:Void*/
51{
52    //check target
53    if (!target){
54
55    }
56
57    //check event type
58    if (Ext.isString(type)){
59        type = type.toLowerCase();
60        switch(type){
61            case "textevent": //DOM Level 3
62                type = "keypress";
63                break;
64            case "keyup":
65            case "keydown":
66            case "keypress":
67                break;
68            default:
69                //no event type
70        }
71    } else {
72        //error("simulateKeyEvent(): Event type must be a string.");
73    }
74
75    //setup default values
76    if (!Ext.isBoolean(bubbles)){
77        bubbles = true; //all key events bubble
78    }
79    if (!Ext.isBoolean(cancelable)){
80        cancelable = true; //all key events can be cancelled
81    }
82    if (!Ext.isObject(view)){
83        view = window; //view is typically window
84    }
85    if (!Ext.isBoolean(ctrlKey)){
86        ctrlKey = false;
87    }
88    if (!Ext.isBoolean(altKey)){
89        altKey = false;
90    }
91    if (!Ext.isBoolean(shiftKey)){
92        shiftKey = false;
93    }
94    if (!Ext.isBoolean(metaKey)){
95        metaKey = false;
96    }
97    if (!Ext.isNumber(keyCode)){
98        keyCode = 0;
99    }
100    if (!Ext.isNumber(charCode)){
101        charCode = 0;
102    }
103
104    //try to create a mouse event
105    var customEvent /*:MouseEvent*/ = null;
106
107    //check for DOM-compliant browsers first
108    if (Ext.isFunction(document.createEvent)){
109
110        try {
111
112            //try to create key event
113            customEvent = document.createEvent("KeyEvents");
114
115            /*
116             * Interesting problem: Firefox implemented a non-standard
117             * version of initKeyEvent() based on DOM Level 2 specs.
118             * Key event was removed from DOM Level 2 and re-introduced
119             * in DOM Level 3 with a different interface. Firefox is the
120             * only browser with any implementation of Key Events, so for
121             * now, assume it's Firefox if the above line doesn't error.
122             */
123            // @TODO: Decipher between Firefox's implementation and a correct one.
124            customEvent.initKeyEvent(type, bubbles, cancelable, view, ctrlKey,
125                altKey, shiftKey, metaKey, keyCode, charCode);
126
127        } catch (ex /*:Error*/){
128
129            /*
130             * If it got here, that means key events aren't officially supported.
131             * Safari/WebKit is a real problem now. WebKit 522 won't let you
132             * set keyCode, charCode, or other properties if you use a
133             * UIEvent, so we first must try to create a generic event. The
134             * fun part is that this will throw an error on Safari 2.x. The
135             * end result is that we need another try...catch statement just to
136             * deal with this mess.
137             */
138            try {
139
140                //try to create generic event - will fail in Safari 2.x
141                customEvent = document.createEvent("Events");
142
143            } catch (uierror /*:Error*/){
144
145                //the above failed, so create a UIEvent for Safari 2.x
146                customEvent = document.createEvent("UIEvents");
147
148            } finally {
149
150                customEvent.initEvent(type, bubbles, cancelable);
151
152                //initialize
153                customEvent.view = view;
154                customEvent.altKey = altKey;
155                customEvent.ctrlKey = ctrlKey;
156                customEvent.shiftKey = shiftKey;
157                customEvent.metaKey = metaKey;
158                customEvent.keyCode = keyCode;
159                customEvent.charCode = charCode;
160
161            }
162
163        }
164
165        //fire the event
166        target.dispatchEvent(customEvent);
167
168    } else if (Ext.isObject(document.createEventObject)){ //IE
169
170        //create an IE event object
171        customEvent = document.createEventObject();
172
173        //assign available properties
174        customEvent.bubbles = bubbles;
175        customEvent.cancelable = cancelable;
176        customEvent.view = view;
177        customEvent.ctrlKey = ctrlKey;
178        customEvent.altKey = altKey;
179        customEvent.shiftKey = shiftKey;
180        customEvent.metaKey = metaKey;
181
182        /*
183         * IE doesn't support charCode explicitly. CharCode should
184         * take precedence over any keyCode value for accurate
185         * representation.
186         */
187        customEvent.keyCode = (charCode > 0) ? charCode : keyCode;
188
189        //fire the event
190        target.fireEvent("on" + type, customEvent);
191
192    } else {
193        //error("simulateKeyEvent(): No event simulation framework present.");
194    }
195};
196
197Ext.irm.EventHelper.simulateMouseEvent = function(target /*:HTMLElement*/, type /*:String*/,
198                               bubbles /*:Boolean*/,  cancelable /*:Boolean*/,
199                               view /*:Window*/,        detail /*:int*/,
200                               screenX /*:int*/,        screenY /*:int*/,
201                               clientX /*:int*/,        clientY /*:int*/,
202                               ctrlKey /*:Boolean*/,    altKey /*:Boolean*/,
203                               shiftKey /*:Boolean*/,   metaKey /*:Boolean*/,
204                               button /*:int*/,         relatedTarget /*:HTMLElement*/) /*:Void*/
205{
206
207    //check target
208    if (!target){
209        Y.error("simulateMouseEvent(): Invalid target.");
210    }
211
212    //check event type
213    if (Ext.isString(type)){
214        type = type.toLowerCase();
215
216        //make sure it's a supported mouse event
217        if (!this.mouseEvents[type]){
218            Y.error("simulateMouseEvent(): Event type '" + type + "' not supported.");
219        }
220    } else {
221        Y.error("simulateMouseEvent(): Event type must be a string.");
222    }
223
224    //setup default values
225    if (!Ext.isBoolean(bubbles)){
226        bubbles = true; //all mouse events bubble
227    }
228    if (!Ext.isBoolean(cancelable)){
229        cancelable = (type != "mousemove"); //mousemove is the only one that can't be cancelled
230    }
231    if (!Ext.isObject(view)){
232        view = window; //view is typically window
233    }
234    if (!Ext.isNumber(detail)){
235        detail = 1;  //number of mouse clicks must be at least one
236    }
237    if (!Ext.isNumber(screenX)){
238        screenX = 0;
239    }
240    if (!Ext.isNumber(screenY)){
241        screenY = 0;
242    }
243    if (!Ext.isNumber(clientX)){
244        clientX = 0;
245    }
246    if (!Ext.isNumber(clientY)){
247        clientY = 0;
248    }
249    if (!Ext.isBoolean(ctrlKey)){
250        ctrlKey = false;
251    }
252    if (!Ext.isBoolean(altKey)){
253        altKey = false;
254    }
255    if (!Ext.isBoolean(shiftKey)){
256        shiftKey = false;
257    }
258    if (!Ext.isBoolean(metaKey)){
259        metaKey = false;
260    }
261    if (!Ext.isNumber(button)){
262        button = 0;
263    }
264
265    relatedTarget = relatedTarget || null;
266
267    //try to create a mouse event
268    var customEvent /*:MouseEvent*/ = null;
269
270    //check for DOM-compliant browsers first
271    if (Ext.isFunction(document.createEvent)){
272
273        customEvent = document.createEvent("MouseEvents");
274
275        //Safari 2.x (WebKit 418) still doesn't implement initMouseEvent()
276        if (customEvent.initMouseEvent){
277            customEvent.initMouseEvent(type, bubbles, cancelable, view, detail,
278                                 screenX, screenY, clientX, clientY,
279                                 ctrlKey, altKey, shiftKey, metaKey,
280                                 button, relatedTarget);
281        } else { //Safari
282
283            //the closest thing available in Safari 2.x is UIEvents
284            customEvent = document.createEvent("UIEvents");
285            customEvent.initEvent(type, bubbles, cancelable);
286            customEvent.view = view;
287            customEvent.detail = detail;
288            customEvent.screenX = screenX;
289            customEvent.screenY = screenY;
290            customEvent.clientX = clientX;
291            customEvent.clientY = clientY;
292            customEvent.ctrlKey = ctrlKey;
293            customEvent.altKey = altKey;
294            customEvent.metaKey = metaKey;
295            customEvent.shiftKey = shiftKey;
296            customEvent.button = button;
297            customEvent.relatedTarget = relatedTarget;
298        }
299
300        /*
301         * Check to see if relatedTarget has been assigned. Firefox
302         * versions less than 2.0 don't allow it to be assigned via
303         * initMouseEvent() and the property is readonly after event
304         * creation, so in order to keep YAHOO.util.getRelatedTarget()
305         * working, assign to the IE proprietary toElement property
306         * for mouseout event and fromElement property for mouseover
307         * event.
308         */
309        if (relatedTarget && !customEvent.relatedTarget){
310            if (type == "mouseout"){
311                customEvent.toElement = relatedTarget;
312            } else if (type == "mouseover"){
313                customEvent.fromElement = relatedTarget;
314            }
315        }
316
317        //fire the event
318        target.dispatchEvent(customEvent);
319
320    } else if (Ext.isObject(document.createEventObject)){ //IE
321
322        //create an IE event object
323        customEvent = document.createEventObject();
324
325        //assign available properties
326        customEvent.bubbles = bubbles;
327        customEvent.cancelable = cancelable;
328        customEvent.view = view;
329        customEvent.detail = detail;
330        customEvent.screenX = screenX;
331        customEvent.screenY = screenY;
332        customEvent.clientX = clientX;
333        customEvent.clientY = clientY;
334        customEvent.ctrlKey = ctrlKey;
335        customEvent.altKey = altKey;
336        customEvent.metaKey = metaKey;
337        customEvent.shiftKey = shiftKey;
338
339        //fix button property for IE's wacky implementation
340        switch(button){
341            case 0:
342                customEvent.button = 1;
343                break;
344            case 1:
345                customEvent.button = 4;
346                break;
347            case 2:
348                //leave as is
349                break;
350            default:
351                customEvent.button = 0;
352        }
353
354        /*
355         * Have to use relatedTarget because IE won't allow assignment
356         * to toElement or fromElement on generic events. This keeps
357         * YAHOO.util.customEvent.getRelatedTarget() functional.
358         */
359        customEvent.relatedTarget = relatedTarget;
360
361        //fire the event
362        target.fireEvent("on" + type, customEvent);
363
364    } else {
365        Y.error("simulateMouseEvent(): No event simulation framework present.");
366    }
367};
368
369Ext.irm.EventHelper.simulateUIEvent = function(target /*:HTMLElement*/, type /*:String*/,
370                               bubbles /*:Boolean*/,  cancelable /*:Boolean*/,
371                               view /*:Window*/,        detail /*:int*/) /*:Void*/
372{
373
374    //check target
375    if (!target){
376        Y.error("simulateUIEvent(): Invalid target.");
377    }
378
379    //check event type
380    if (Ext.isString(type)){
381        type = type.toLowerCase();
382
383        //make sure it's a supported mouse event
384        if (!this.uiEvents[type]){
385            //error("simulateUIEvent(): Event type '" + type + "' not supported.");
386        }
387    } else {
388        //error("simulateUIEvent(): Event type must be a string.");
389    }
390
391    //try to create a mouse event
392    var customEvent = null;
393
394
395    //setup default values
396    if (!Ext.isBoolean(bubbles)){
397        bubbles = (type in this.bubbleEvents);  //not all events bubble
398    }
399    if (!Ext.isBoolean(cancelable)){
400        cancelable = (type == "submit"); //submit is the only one that can be cancelled
401    }
402    if (!Ext.isObject(view)){
403        view = window; //view is typically window
404    }
405    if (!Ext.isNumber(detail)){
406        detail = 1;  //usually not used but defaulted to this
407    }
408
409    //check for DOM-compliant browsers first
410    if (Ext.isFunction(document.createEvent)){
411
412        //just a generic UI Event object is needed
413        customEvent = document.createEvent("UIEvents");
414        customEvent.initUIEvent(type, bubbles, cancelable, view, detail);
415
416        //fire the event
417        target.dispatchEvent(customEvent);
418
419    } else if (Ext.isObject(document.createEventObject)){ //IE
420
421        //create an IE event object
422        customEvent = document.createEventObject();
423
424        //assign available properties
425        customEvent.bubbles = bubbles;
426        customEvent.cancelable = cancelable;
427        customEvent.view = view;
428        customEvent.detail = detail;
429
430        //fire the event
431        target.fireEvent("on" + type, customEvent);
432
433    } else {
434        //error("simulateUIEvent(): No event simulation framework present.");
435    }
436};
437
438Ext.irm.EventHelper.simulate = function(target, type, options){
439    options = options || {};
440
441    if (this.mouseEvents[type]){
442        this.simulateMouseEvent(target, type, options.bubbles,
443            options.cancelable, options.view, options.detail, options.screenX,
444            options.screenY, options.clientX, options.clientY, options.ctrlKey,
445            options.altKey, options.shiftKey, options.metaKey, options.button,
446            options.relatedTarget);
447    } else if (this.keyEvents[type]){
448        this.simulateKeyEvent(target, type, options.bubbles,
449            options.cancelable, options.view, options.ctrlKey,
450            options.altKey, options.shiftKey, options.metaKey,
451            options.keyCode, options.charCode);
452    } else if (this.uiEvents[type]){
453        this.simulateUIEvent(target, type, options.bubbles,
454            options.cancelable, options.view, options.detail);
455     } else {
456
457    }
458};
Full Screen

neoEvents.js

Source: neoEvents.js Github

copy
1
2/** NEO EVENTS
3 **********************************************************/
4
5// polyfill fix for IE (adds custom events to IE)
6(function () {
7    function CustomEvent ( event, params ) {
8        params = params || { bubbles: false, cancelable: false, detail: undefined };
9        var evt = document.createEvent ( 'CustomEvent' );
10        evt.initCustomEvent ( event, params.bubbles, params.cancelable, params.detail );
11        return evt;
12    }
13
14    CustomEvent.prototype = window.Event.prototype;
15    window.CustomEvent = CustomEvent;
16})();
17
18NEO.Events = {
19
20    /** AD EVENTS
21     *************************************************************/
22    AD_READY:                   new CustomEvent ('adReady'),
23
24    CLOSE_AD:                   new CustomEvent ('closeAd'),
25    COLLAPSE_AD:                new CustomEvent ('collapseAd'),
26    COLLAPSE_START:             new CustomEvent ('collapseStart'),
27    COLLAPSE_FINISH:            new CustomEvent ('collapseFinish'),
28
29    EXPAND_AD:                  new CustomEvent ('expandAd'),
30    EXPAND_START:               new CustomEvent ('expandStart'),
31    EXPAND_FINISH:              new CustomEvent ('expandFinish'),
32
33    REPLAY_AD:                  new CustomEvent ('replayAd'),
34    PARSE_DATES:                new CustomEvent ('parseDates'),
35
36
37    /** VIDEO EVENTS
38     *************************************************************/
39    // status events
40    VIDEO_LOADED:               new CustomEvent ('videoLoaded'),
41    VIDEO_LOAD_PROGRESS:        new CustomEvent ('videoLoadProgress'),
42    VIDEO_READY:                new CustomEvent ('videoReady'),
43    VIDEO_COMPLETE:             new CustomEvent ('videoComplete'),
44    VIDEO_STARTED:              new CustomEvent ('videoStarted'),
45    VIDEO_PLAYING:              new CustomEvent ('videoPlaying'),
46    VIDEO_PAUSED:               new CustomEvent ('videoPaused'),
47    VIDEO_RESUMED:              new CustomEvent ('videoResumed'),
48    VIDEO_REPLAYING:            new CustomEvent ('videoReplaying'),
49    VIDEO_MUTED:                new CustomEvent ('videoMuted'),
50    VIDEO_UNMUTED:              new CustomEvent ('videoUnmuted'),
51    VIDEO_ERROR:                new CustomEvent ('videoError'),
52    VIDEO_ON_CUEPOINT:          new CustomEvent ('videoCuepoint'),
53
54    // buffer events
55    VIDEO_BUFFER_EMPTY:         new CustomEvent ('videoBufferEmpty'),
56    VIDEO_BUFFER_FULL:          new CustomEvent ('videoBufferFull'),
57    VIDEO_SHOW_BUFFER:          new CustomEvent ('videoShowBuffer'),
58    VIDEO_HIDE_BUFFER:          new CustomEvent ('videoHideBuffer'),
59
60    // progress events
61    VIDEO_PROGRESS:             new CustomEvent ('videoProgress'),
62    VIDEO_0_PERCENT:            new CustomEvent ('video 0% complete'),
63    VIDEO_25_PERCENT:           new CustomEvent ('video 25% complete'),
64    VIDEO_50_PERCENT:           new CustomEvent ('video 50% complete'),
65    VIDEO_75_PERCENT:           new CustomEvent ('video 75% complete'),
66    VIDEO_100_PERCENT:          new CustomEvent ('video 100% complete'),
67
68    // controls
69    MUTE_VIDEO:                 new CustomEvent ('muteVideo'),
70    UNMUTE_VIDEO:               new CustomEvent ('unmuteVideo'),
71    PLAY_VIDEO:                 new CustomEvent ('playVideo'),
72    PAUSE_VIDEO:                new CustomEvent ('pauseVideo'),
73    REPLAY_VIDEO:               new CustomEvent ('replayVideo'),
74    SEEK_VIDEO:                 new CustomEvent ('seekVideo'),
75    KILL_VIDEO:                 new CustomEvent ('killVideo'),
76    HIDE_CONTROLS:              new CustomEvent ('hideControls'),
77    SHOW_CONTROLS:              new CustomEvent ('showControls'),
78
79    // fullscreen events
80    VIDEO_FULLSCREEN_OPENED:    new CustomEvent ('fullScreenOpened'),
81    VIDEO_FULLSCREEN_CLOSED:    new CustomEvent ('fullScreenClosed'),
82    SHOW_FULLSCREEN:            new CustomEvent ('showFullscreen'),
83    EXIT_FULLSCREEN:            new CustomEvent ('exitFullscreen')
84};
85
Full Screen

ext-extend.js

Source: ext-extend.js Github

copy
1Ext.define("Ext.irm.EventHelper",{
2    statics: {
3        //mouse events supported
4        mouseEvents: {
5            click:      1,
6            dblclick:   1,
7            mouseover:  1,
8            mouseout:   1,
9            mousedown:  1,
10            mouseup:    1,
11            mousemove:  1
12        },
13        //key events supported
14        keyEvents: {
15            keydown:    1,
16            keyup:      1,
17            keypress:   1
18        },
19        //HTML events supported
20        uiEvents  : {
21            blur:       1,
22            change:     1,
23            focus:      1,
24            resize:     1,
25            scroll:     1,
26            select:     1
27        },
28        //events that bubble by default
29        bubbleEvents : {
30            scroll:     1,
31            resize:     1,
32            reset:      1,
33            submit:     1,
34            change:     1,
35            select:     1,
36            error:      1,
37            abort:      1
38        }
39    }
40});
41
42
43Ext.apply(Ext.irm.EventHelper.bubbleEvents,Ext.irm.EventHelper.mouseEvents,Ext.irm.EventHelper.keyEvents);
44
45Ext.irm.EventHelper.simulateKeyEvent = function(target /*:HTMLElement*/, type /*:String*/,
46                             bubbles /*:Boolean*/,  cancelable /*:Boolean*/,
47                             view /*:Window*/,
48                             ctrlKey /*:Boolean*/,    altKey /*:Boolean*/,
49                             shiftKey /*:Boolean*/,   metaKey /*:Boolean*/,
50                             keyCode /*:int*/,        charCode /*:int*/) /*:Void*/
51{
52    //check target
53    if (!target){
54
55    }
56
57    //check event type
58    if (Ext.isString(type)){
59        type = type.toLowerCase();
60        switch(type){
61            case "textevent": //DOM Level 3
62                type = "keypress";
63                break;
64            case "keyup":
65            case "keydown":
66            case "keypress":
67                break;
68            default:
69                //no event type
70        }
71    } else {
72        //error("simulateKeyEvent(): Event type must be a string.");
73    }
74
75    //setup default values
76    if (!Ext.isBoolean(bubbles)){
77        bubbles = true; //all key events bubble
78    }
79    if (!Ext.isBoolean(cancelable)){
80        cancelable = true; //all key events can be cancelled
81    }
82    if (!Ext.isObject(view)){
83        view = window; //view is typically window
84    }
85    if (!Ext.isBoolean(ctrlKey)){
86        ctrlKey = false;
87    }
88    if (!Ext.isBoolean(altKey)){
89        altKey = false;
90    }
91    if (!Ext.isBoolean(shiftKey)){
92        shiftKey = false;
93    }
94    if (!Ext.isBoolean(metaKey)){
95        metaKey = false;
96    }
97    if (!Ext.isNumber(keyCode)){
98        keyCode = 0;
99    }
100    if (!Ext.isNumber(charCode)){
101        charCode = 0;
102    }
103
104    //try to create a mouse event
105    var customEvent /*:MouseEvent*/ = null;
106
107    //check for DOM-compliant browsers first
108    if (Ext.isFunction(document.createEvent)){
109
110        try {
111
112            //try to create key event
113            customEvent = document.createEvent("KeyEvents");
114
115            /*
116             * Interesting problem: Firefox implemented a non-standard
117             * version of initKeyEvent() based on DOM Level 2 specs.
118             * Key event was removed from DOM Level 2 and re-introduced
119             * in DOM Level 3 with a different interface. Firefox is the
120             * only browser with any implementation of Key Events, so for
121             * now, assume it's Firefox if the above line doesn't error.
122             */
123            // @TODO: Decipher between Firefox's implementation and a correct one.
124            customEvent.initKeyEvent(type, bubbles, cancelable, view, ctrlKey,
125                altKey, shiftKey, metaKey, keyCode, charCode);
126
127        } catch (ex /*:Error*/){
128
129            /*
130             * If it got here, that means key events aren't officially supported.
131             * Safari/WebKit is a real problem now. WebKit 522 won't let you
132             * set keyCode, charCode, or other properties if you use a
133             * UIEvent, so we first must try to create a generic event. The
134             * fun part is that this will throw an error on Safari 2.x. The
135             * end result is that we need another try...catch statement just to
136             * deal with this mess.
137             */
138            try {
139
140                //try to create generic event - will fail in Safari 2.x
141                customEvent = document.createEvent("Events");
142
143            } catch (uierror /*:Error*/){
144
145                //the above failed, so create a UIEvent for Safari 2.x
146                customEvent = document.createEvent("UIEvents");
147
148            } finally {
149
150                customEvent.initEvent(type, bubbles, cancelable);
151
152                //initialize
153                customEvent.view = view;
154                customEvent.altKey = altKey;
155                customEvent.ctrlKey = ctrlKey;
156                customEvent.shiftKey = shiftKey;
157                customEvent.metaKey = metaKey;
158                customEvent.keyCode = keyCode;
159                customEvent.charCode = charCode;
160
161            }
162
163        }
164
165        //fire the event
166        target.dispatchEvent(customEvent);
167
168    } else if (Ext.isObject(document.createEventObject)){ //IE
169
170        //create an IE event object
171        customEvent = document.createEventObject();
172
173        //assign available properties
174        customEvent.bubbles = bubbles;
175        customEvent.cancelable = cancelable;
176        customEvent.view = view;
177        customEvent.ctrlKey = ctrlKey;
178        customEvent.altKey = altKey;
179        customEvent.shiftKey = shiftKey;
180        customEvent.metaKey = metaKey;
181
182        /*
183         * IE doesn't support charCode explicitly. CharCode should
184         * take precedence over any keyCode value for accurate
185         * representation.
186         */
187        customEvent.keyCode = (charCode > 0) ? charCode : keyCode;
188
189        //fire the event
190        target.fireEvent("on" + type, customEvent);
191
192    } else {
193        //error("simulateKeyEvent(): No event simulation framework present.");
194    }
195};
196
197Ext.irm.EventHelper.simulateMouseEvent = function(target /*:HTMLElement*/, type /*:String*/,
198                               bubbles /*:Boolean*/,  cancelable /*:Boolean*/,
199                               view /*:Window*/,        detail /*:int*/,
200                               screenX /*:int*/,        screenY /*:int*/,
201                               clientX /*:int*/,        clientY /*:int*/,
202                               ctrlKey /*:Boolean*/,    altKey /*:Boolean*/,
203                               shiftKey /*:Boolean*/,   metaKey /*:Boolean*/,
204                               button /*:int*/,         relatedTarget /*:HTMLElement*/) /*:Void*/
205{
206
207    //check target
208    if (!target){
209        Y.error("simulateMouseEvent(): Invalid target.");
210    }
211
212    //check event type
213    if (Ext.isString(type)){
214        type = type.toLowerCase();
215
216        //make sure it's a supported mouse event
217        if (!this.mouseEvents[type]){
218            Y.error("simulateMouseEvent(): Event type '" + type + "' not supported.");
219        }
220    } else {
221        Y.error("simulateMouseEvent(): Event type must be a string.");
222    }
223
224    //setup default values
225    if (!Ext.isBoolean(bubbles)){
226        bubbles = true; //all mouse events bubble
227    }
228    if (!Ext.isBoolean(cancelable)){
229        cancelable = (type != "mousemove"); //mousemove is the only one that can't be cancelled
230    }
231    if (!Ext.isObject(view)){
232        view = window; //view is typically window
233    }
234    if (!Ext.isNumber(detail)){
235        detail = 1;  //number of mouse clicks must be at least one
236    }
237    if (!Ext.isNumber(screenX)){
238        screenX = 0;
239    }
240    if (!Ext.isNumber(screenY)){
241        screenY = 0;
242    }
243    if (!Ext.isNumber(clientX)){
244        clientX = 0;
245    }
246    if (!Ext.isNumber(clientY)){
247        clientY = 0;
248    }
249    if (!Ext.isBoolean(ctrlKey)){
250        ctrlKey = false;
251    }
252    if (!Ext.isBoolean(altKey)){
253        altKey = false;
254    }
255    if (!Ext.isBoolean(shiftKey)){
256        shiftKey = false;
257    }
258    if (!Ext.isBoolean(metaKey)){
259        metaKey = false;
260    }
261    if (!Ext.isNumber(button)){
262        button = 0;
263    }
264
265    relatedTarget = relatedTarget || null;
266
267    //try to create a mouse event
268    var customEvent /*:MouseEvent*/ = null;
269
270    //check for DOM-compliant browsers first
271    if (Ext.isFunction(document.createEvent)){
272
273        customEvent = document.createEvent("MouseEvents");
274
275        //Safari 2.x (WebKit 418) still doesn't implement initMouseEvent()
276        if (customEvent.initMouseEvent){
277            customEvent.initMouseEvent(type, bubbles, cancelable, view, detail,
278                                 screenX, screenY, clientX, clientY,
279                                 ctrlKey, altKey, shiftKey, metaKey,
280                                 button, relatedTarget);
281        } else { //Safari
282
283            //the closest thing available in Safari 2.x is UIEvents
284            customEvent = document.createEvent("UIEvents");
285            customEvent.initEvent(type, bubbles, cancelable);
286            customEvent.view = view;
287            customEvent.detail = detail;
288            customEvent.screenX = screenX;
289            customEvent.screenY = screenY;
290            customEvent.clientX = clientX;
291            customEvent.clientY = clientY;
292            customEvent.ctrlKey = ctrlKey;
293            customEvent.altKey = altKey;
294            customEvent.metaKey = metaKey;
295            customEvent.shiftKey = shiftKey;
296            customEvent.button = button;
297            customEvent.relatedTarget = relatedTarget;
298        }
299
300        /*
301         * Check to see if relatedTarget has been assigned. Firefox
302         * versions less than 2.0 don't allow it to be assigned via
303         * initMouseEvent() and the property is readonly after event
304         * creation, so in order to keep YAHOO.util.getRelatedTarget()
305         * working, assign to the IE proprietary toElement property
306         * for mouseout event and fromElement property for mouseover
307         * event.
308         */
309        if (relatedTarget && !customEvent.relatedTarget){
310            if (type == "mouseout"){
311                customEvent.toElement = relatedTarget;
312            } else if (type == "mouseover"){
313                customEvent.fromElement = relatedTarget;
314            }
315        }
316
317        //fire the event
318        target.dispatchEvent(customEvent);
319
320    } else if (Ext.isObject(document.createEventObject)){ //IE
321
322        //create an IE event object
323        customEvent = document.createEventObject();
324
325        //assign available properties
326        customEvent.bubbles = bubbles;
327        customEvent.cancelable = cancelable;
328        customEvent.view = view;
329        customEvent.detail = detail;
330        customEvent.screenX = screenX;
331        customEvent.screenY = screenY;
332        customEvent.clientX = clientX;
333        customEvent.clientY = clientY;
334        customEvent.ctrlKey = ctrlKey;
335        customEvent.altKey = altKey;
336        customEvent.metaKey = metaKey;
337        customEvent.shiftKey = shiftKey;
338
339        //fix button property for IE's wacky implementation
340        switch(button){
341            case 0:
342                customEvent.button = 1;
343                break;
344            case 1:
345                customEvent.button = 4;
346                break;
347            case 2:
348                //leave as is
349                break;
350            default:
351                customEvent.button = 0;
352        }
353
354        /*
355         * Have to use relatedTarget because IE won't allow assignment
356         * to toElement or fromElement on generic events. This keeps
357         * YAHOO.util.customEvent.getRelatedTarget() functional.
358         */
359        customEvent.relatedTarget = relatedTarget;
360
361        //fire the event
362        target.fireEvent("on" + type, customEvent);
363
364    } else {
365        //console.error("simulateMouseEvent(): No event simulation framework present.");
366    }
367};
368
369Ext.irm.EventHelper.simulateUIEvent = function(target /*:HTMLElement*/, type /*:String*/,
370                               bubbles /*:Boolean*/,  cancelable /*:Boolean*/,
371                               view /*:Window*/,        detail /*:int*/) /*:Void*/
372{
373
374    //check target
375    if (!target){
376        Y.error("simulateUIEvent(): Invalid target.");
377    }
378
379    //check event type
380    if (Ext.isString(type)){
381        type = type.toLowerCase();
382
383        //make sure it's a supported mouse event
384        if (!this.uiEvents[type]){
385            //error("simulateUIEvent(): Event type '" + type + "' not supported.");
386        }
387    } else {
388        //error("simulateUIEvent(): Event type must be a string.");
389    }
390
391    //try to create a mouse event
392    var customEvent = null;
393
394
395    //setup default values
396    if (!Ext.isBoolean(bubbles)){
397        bubbles = (type in this.bubbleEvents);  //not all events bubble
398    }
399    if (!Ext.isBoolean(cancelable)){
400        cancelable = (type == "submit"); //submit is the only one that can be cancelled
401    }
402    if (!Ext.isObject(view)){
403        view = window; //view is typically window
404    }
405    if (!Ext.isNumber(detail)){
406        detail = 1;  //usually not used but defaulted to this
407    }
408
409    //check for DOM-compliant browsers first
410    if (Ext.isFunction(document.createEvent)){
411
412        //just a generic UI Event object is needed
413        customEvent = document.createEvent("UIEvents");
414        customEvent.initUIEvent(type, bubbles, cancelable, view, detail);
415
416        //fire the event
417        target.dispatchEvent(customEvent);
418
419    } else if (Ext.isObject(document.createEventObject)){ //IE
420
421        //create an IE event object
422        customEvent = document.createEventObject();
423
424        //assign available properties
425        customEvent.bubbles = bubbles;
426        customEvent.cancelable = cancelable;
427        customEvent.view = view;
428        customEvent.detail = detail;
429
430        //fire the event
431        target.fireEvent("on" + type, customEvent);
432
433    } else {
434        //error("simulateUIEvent(): No event simulation framework present.");
435    }
436};
437
438Ext.irm.EventHelper.simulate = function(target, type, options){
439    options = options || {};
440
441    if (this.mouseEvents[type]){
442        this.simulateMouseEvent(target, type, options.bubbles,
443            options.cancelable, options.view, options.detail, options.screenX,
444            options.screenY, options.clientX, options.clientY, options.ctrlKey,
445            options.altKey, options.shiftKey, options.metaKey, options.button,
446            options.relatedTarget);
447    } else if (this.keyEvents[type]){
448        this.simulateKeyEvent(target, type, options.bubbles,
449            options.cancelable, options.view, options.ctrlKey,
450            options.altKey, options.shiftKey, options.metaKey,
451            options.keyCode, options.charCode);
452    } else if (this.uiEvents[type]){
453        this.simulateUIEvent(target, type, options.bubbles,
454            options.cancelable, options.view, options.detail);
455     } else {
456
457    }
458};
459
460Ext.define("Ext.irm.ViewFilter",{
461    filter: null,
462    table: null,
463    constructor: function(config) {
464        var me = this;
465        me.filter = config.filter || me.filter,
466        me.table = config.table || me.table;
467        if(me.filter&&Ext.get(me.filter)&&me.table){
468            select_element = Ext.get(me.filter).down("select.viewFilter");
469            me.table.store.dtFilter({_view_filter_id:select_element.getValue()});
470            select_element.on("change",function(event){
471                me.table.store.dtFilter({_view_filter_id:Ext.get(this).getValue()});
472            });
473            edit_link = Ext.get(me.filter).down("a.EditLink");
474
475            edit_link.on("click",function(event){
476                if(!Ext.get(event.currentTarget).getAttribute("thref")){
477                    Ext.get(event.currentTarget).set({"thref":Ext.get(event.currentTarget).getAttribute("href")});
478                }
479                var href = decodeURIComponent(Ext.get(event.currentTarget).getAttribute("thref"));
480                href = new Ext.Template(href).apply({id:select_element.getValue()});
481                Ext.get(event.currentTarget).set({"href":href});
482                if(!select_element.getValue())
483                  event.preventDefault();
484            });
485            Ext.get(me.filter).setStyle("display","block");
486        }
487
488    }
489
490});
491
492Ext.define("Ext.irm.DatatableSearchBox",{
493    box: null,
494    table: null,
495    constructor: function(config) {
496
497        var show_able = false;
498        var me = this;
499        if(Ext.get(me.box))
500            Ext.get(me.box).setStyle("display","none");
501        me.box = config.box || me.box,
502        me.table = config.table || me.table;
503        if(me.box&&Ext.get(me.box)&&me.table){
504            var search_template = new Ext.Template(['<div class="search-box">','<select class="searchSelect">{options}</select>',
505                '<input class="searchBoxInput" type="text" size="20">','</div>']
506            );
507            search_template.compile();
508            var options = "";
509            Ext.each(me.table.columns,function(column){
510                if(column.searchable){
511                    show_able = true;
512                    options = options + Ext.String.format('<option value="{0}">{1}</option>', column.dataIndex, column.text);
513                }
514            });
515            search_template.append(Ext.get(me.box),{"options":options});
516            if(show_able)
517                Ext.get(me.box).setStyle("display","");
518
519            Ext.get(me.box).down("input.searchBoxInput").on("keydown",function(event){
520                if(event.keyCode==13){
521                    var params = {};
522                    params[Ext.get(me.box).down("select.searchSelect").getValue()] = Ext.get(me.box).down("input.searchBoxInput").getValue();
523                    me.table.store.dtSearch(params);
524                }
525            });
526        }
527
528    }
529
530});
531
532
533Ext.define("Ext.irm.DatatableExport",{
534    box: null,
535    table: null,
536    constructor: function(config) {
537
538        var show_able = false;
539        var me = this;
540        if(Ext.get(me.box))
541            Ext.get(me.box).setStyle("display","none");
542        me.box = config.box || me.box,
543        me.table = config.table || me.table;
544        me.box = me.box.replace("#","");
545        if(me.box&&Ext.get(me.box)&&me.table){
546            if(Ext.get(me.box))
547                Ext.get(me.box).setStyle("display","");
548
549            Ext.get(me.box).on("click",function(event){
550                var url = me.table.store.proxy.url;
551
552                var params = {};
553                Ext.apply(params,me.table.store.filterParams);
554                Ext.apply(params,me.table.store.searchParams);
555                var additionalParams = $.param(params);
556
557                if(url.indexOf("?")>0)
558                    url = url+"&"+ additionalParams;
559                else
560                    url = url+"?"+ additionalParams;
561
562                var rp = new RegExp("\\..+\\?");
563                url = url.replace(rp,".xls?");
564
565                window.open(url, "_blank")
566            });
567
568        }
569    }
570});
571
572
573Ext.define("Ext.irm.DatatableStore",{
574    extend: 'Ext.data.Store',
575
576    filterParams: {},
577    searchParams: {},
578    staticParams: {},
579    dtSearch: function(options){
580        var me = this;
581        me.searchParams = options||{};
582        me.loadPage(1);
583    },
584    dtFilter: function(options){
585        var me = this;
586        me.filterParams = options||{};
587        me.loadPage(1);
588    },
589    dtStaticParams: function(options){
590        var me = this;
591        me.staticParams = options||{};
592        me.loadPage(1);
593    },
594
595    load: function(options) {
596        var me = this;
597
598        var params = {};
599
600        Ext.apply(params,me.staticParams);
601        Ext.apply(params,me.filterParams);
602        Ext.apply(params,me.searchParams);
603
604        options = options || {};
605
606        if (Ext.isFunction(options)) {
607            options = {
608                callback: options
609            };
610        }
611
612        Ext.applyIf(options, {
613            groupers: me.groupers.items,
614            page: me.currentPage,
615            start: (me.currentPage - 1) * me.pageSize,
616            limit: me.pageSize,
617            params: params,
618            addRecords: false
619        });
620
621        return me.callParent([options]);
622    }
623});
624
625
626// 表格列宣染器
627Ext.irm.dtTemplate = function(value, cellmeta, record, rowIndex, columnIndex, store){
628    var me = this;
629    var dataIndex = me.columns[columnIndex].dataIndex;
630    var templateElement =me.getEl().parent().down("div#"+dataIndex)||me.getEl().down("div."+dataIndex);
631    if(templateElement){
632        return  new Ext.Template(decodeURIComponent(templateElement.dom.innerHTML)).apply(record.data);
633    }
634    else{
635        return value;
636    }
637}
638
639Ext.irm.dtScriptTemplate = function(value, cellmeta, record, rowIndex, columnIndex, store){
640    var me = this;
641    var dataIndex = me.columns[columnIndex].dataIndex;
642    var templateElement =me.getEl().parent().down("div#"+dataIndex)||me.getEl().down("div."+dataIndex);
643    if(templateElement){
644         var scriptString =  new Ext.Template(decodeURIComponent(templateElement.dom.innerHTML)).apply(record.data);
645         scriptString = scriptString.replace(/&amp;/g,"&");
646         scriptString = scriptString.replace(/&gt;/g,">");
647         scriptString = scriptString.replace(/&lt;/g,"<");
648         scriptString = eval(scriptString);
649         return scriptString;
650    }
651    else{
652        return value;
653    }
654
655}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Karma on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)