10 examples of 'js trigger event' in JavaScript

Every line of 'js trigger event' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
82function trigger (el, eventName) {
83 var customEvent = new CustomEvent(eventName);
84 el.dispatchEvent(customEvent);
85}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

318function triggerAndReturn(context, eventName, data) {
319 //todo: Fire off some events
320 //var event = $.Event(eventName)
321 //$(context).trigger(event, data)
322 return true;//!event.defaultPrevented
323}
19trigger(s){
20 if(s) this.source = s
21
22 let source = this.source
23 if(!source) return
24
25 while(this.listeners.length){
26 let event = this.listeners.shift()
27 let { name, value } = event
28
29 if(typeof source[name] === 'function'){
30 source[name](...value)
31 }
32 }
33}
85_trigger(eventName, event) {
86 this._handlers.get(eventName).forEach((callback) => {
87 //clickThru has to be sync, if not will be block by the popupblocker
88 if (eventName === 'AdClickThru') {
89 callback(event);
90 } else {
91 setTimeout(() => {
92 if (this._handlers.get(eventName).length > 0) {
93 callback(event);
94 }
95 }, 0);
96 }
97 });
98}
312function trigger (eventName, event) {
313 if (hasUpdateFlag) return
314 appCacheNanny.trigger(eventName, event)
315}
85trigger(event, ...extraParameters) {
86 var eventCallbacks = this._eventCallbacks[event] || [];
87
88 // A callback can return a boolean value which will be logically compared to the other callbacks values before
89 // being returned by the trigger() method. This allows a callback to send a "signal" to the caller, like
90 // cancelling an action.
91 var returnValue = true;
92
93 eventCallbacks.forEach(eventCallback => {
94 // A callback must explicitly return false if it wants the trigger() method to return false, undefined will
95 // not work. This avoids crappy callbacks to mess up with the triggering system.
96 var value = eventCallback(...extraParameters);
97 value = value !== false ? true : false;
98
99 returnValue = returnValue && value; // Compare the result of the callback to the actual return value
100 });
101
102 return returnValue;
103}
23function triggerEvent(type, data) {
24 var event = new Event('flo_' + type);
25 event.data = data;
26 window.dispatchEvent(event);
27 return event;
28};
12function trigger(event) {
13 if (events[event]) {
14 events[event].apply(null, [].splice.call(arguments, 1, 1));
15 }
16}
6export function trigger(element: HTMLElement, eventType: string, eventArgs: any): void {
7 let evt;
8 if (doc.createEvent) {
9 evt = doc.createEvent("HTMLEvents");
10 evt.initEvent(eventType, true, true);
11 } else {
12 evt = doc.createEventObject();
13 evt.eventType = eventType;
14 }
15
16 evt.eventName = eventType;
17 ko.utils.extend(evt, eventArgs);
18
19 if (doc.createEvent) {
20 element.dispatchEvent(evt);
21 } else {
22 element.fireEvent("on" + evt.eventType, evt);
23 }
24}
237trigger(type) {
238 let evObj
239
240 if (document.createEvent) {
241 setTimeout(() => {
242 evObj = document.createEvent("MouseEvents")
243 evObj.initEvent(type, true, true)
244 this.$el.dispatchEvent(evObj)
245 }, 0)
246 } else {
247 setTimeout(() => {
248 if (document.createEventObject) {
249 evObj = document.createEventObject()
250 evObj.cancelBubble = true
251 this.$el.fireEvent("on" + type, evObj)
252 }
253 }, 0)
254 }
255}

Related snippets