MCPcopy Index your code
hub / github.com/devote/HTML5-History-API / dispatchEvent

Function dispatchEvent

history.js:781–813  ·  view source on GitHub ↗

* Wrapper for the methods 'dispatchEvent/fireEvent' in the context of the 'window' * * @param {Event|String} event Instance of Event or event type string if 'eventObject' used * @param {*} [eventObject] For Internet Explorer 8 required event object on this argument * @return {Boolean} If

(event, eventObject)

Source from the content-addressed store, hash-verified

779 * @return {Boolean} If 'preventDefault' was called the value is false, else the value is true.
780 */
781 function dispatchEvent(event, eventObject) {
782 var eventType = ('' + (typeof event === "string" ? event : event.type)).replace(/^on/, '');
783 var list = eventsList[eventType];
784 if (list) {
785 // need to understand that there is one object of Event
786 eventObject = typeof event === "string" ? eventObject : event;
787 if (eventObject.target == null) {
788 // need to override some of the properties of the Event object
789 for(var props = ['target', 'currentTarget', 'srcElement', 'type']; event = props.pop();) {
790 // use 'redefineProperty' to override the properties
791 eventObject = redefineProperty(eventObject, event, {
792 get: event === 'type' ? function() {
793 return eventType;
794 } : function() {
795 return global;
796 }
797 });
798 }
799 }
800 if (triggerEventsInWindowAttributes) {
801 // run function defined in the attributes 'onpopstate/onhashchange' in the 'window' context
802 ((eventType === 'popstate' ? global.onpopstate : global.onhashchange)
803 || emptyFunction).call(global, eventObject);
804 }
805 // run other functions that are in the list of handlers
806 for(var i = 0, len = list.length; i < len; i++) {
807 list[i].call(global, eventObject);
808 }
809 return true;
810 } else {
811 return dispatch(event, eventObject);
812 }
813 }
814
815 /**
816 * dispatch current state event

Callers 3

firePopStateFunction · 0.70
onHashChangeFunction · 0.70
onLoadFunction · 0.70

Calls 1

redefinePropertyFunction · 0.70

Tested by

no test coverage detected