Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In JavaScript, what is event.isTrigger?

I came across this in some JS code I was working on:

if ( typeof( e.isTrigger ) == 'undefined' ) { // do some stuff             } 

This seems to be part of jQuery. As far as I can see it tells you if an event originated with the user or automatically.

Is this right? And given that it's not documented, is there a way of finding such things out without going behind the curtain of the jQuery API?

like image 938
djb Avatar asked May 22 '12 14:05

djb


2 Answers

In jQuery 1.7.2 (unminified) line 3148 contains event.isTrigger = true; nested within the trigger function. So yes, you are correct - this is only flagged when you use .trigger() and is used internally to determine how to handle events.

like image 176
Snuffleupagus Avatar answered Sep 24 '22 00:09

Snuffleupagus


If you look at jQuery github project, inside trigger.js file line 49 (link here) you can find how isTrigger gets calculated.

enter image description here

If you add a trigger in your JavaScript and debug through, You can see how the breakpoint reaches this codeline (checked in jQuery-2.1.3.js for this SO question)

like image 22
Nipuna Avatar answered Sep 23 '22 00:09

Nipuna