MCPcopy
hub / github.com/angular-ui/ui-router / eventHandler

Function eventHandler

test/angular/1.4/angular.js:3332–3375  ·  view source on GitHub ↗
(event, type)

Source from the content-addressed store, hash-verified

3330
3331function createEventHandler(element, events) {
3332 var eventHandler = function(event, type) {
3333 // jQuery specific api
3334 event.isDefaultPrevented = function() {
3335 return event.defaultPrevented;
3336 };
3337
3338 var eventFns = events[type || event.type];
3339 var eventFnsLength = eventFns ? eventFns.length : 0;
3340
3341 if (!eventFnsLength) return;
3342
3343 if (isUndefined(event.immediatePropagationStopped)) {
3344 var originalStopImmediatePropagation = event.stopImmediatePropagation;
3345 event.stopImmediatePropagation = function() {
3346 event.immediatePropagationStopped = true;
3347
3348 if (event.stopPropagation) {
3349 event.stopPropagation();
3350 }
3351
3352 if (originalStopImmediatePropagation) {
3353 originalStopImmediatePropagation.call(event);
3354 }
3355 };
3356 }
3357
3358 event.isImmediatePropagationStopped = function() {
3359 return event.immediatePropagationStopped === true;
3360 };
3361
3362 // Some events have special handlers that wrap the real handler
3363 var handlerWrapper = eventFns.specialHandlerWrapper || defaultHandlerWrapper;
3364
3365 // Copy event handlers in case event handlers array is modified during execution.
3366 if ((eventFnsLength > 1)) {
3367 eventFns = shallowCopy(eventFns);
3368 }
3369
3370 for (var i = 0; i < eventFnsLength; i++) {
3371 if (!event.isImmediatePropagationStopped()) {
3372 handlerWrapper(element, event, eventFns[i]);
3373 }
3374 }
3375 };
3376
3377 // TODO: this is a hack for angularMocks/clearDataCache that makes it possible to deregister all
3378 // events on `element`

Callers

nothing calls this directly

Calls 2

isUndefinedFunction · 0.70
shallowCopyFunction · 0.70

Tested by

no test coverage detected