Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#14065 closed enhancement (fixed)

Add support for defaultPrevented property to older browsers

Reported by: Thomas Bachem Owned by: Kris Zyp
Priority: high Milestone: 1.8
Component: Events Version: 1.6.1
Keywords: Cc:
Blocked By: Blocking:

Description

The standardized "defaultPrevented" property on events is supported by recent versions of Gecko (https://developer.mozilla.org/en/DOM/event.defaultPrevented), Safari (http://developer.apple.com/library/safari/#documentation/UserExperience/Reference/SafariEventClassRef/SafariEvent.html), Opera and maybe others as well, but it would be nice if Dojo could fall back to an own implementation via its _fixEvent() workaround.

We are currently using the following Dojo hack for that:

// Extend Dojo to always provide a defaultPrevented property on events
var dojoEventListener = dojo._event_listener;

// We need to override this method so that it calls _fixEvent(),
// see also the very end of Dojo's _base/event.js 
dojoEventListener._fixCallback = function(name, fp){
	var f = dojoEventListener._fixEvent;
	return function(e){ return fp.call(this, f(e, this)); };
};

// Extend Dojo's internally used _fixEvent() method to always
// add the standardized defaultPrevented property
// (https://developer.mozilla.org/en/DOM/event.defaultPrevented)
var originalFixEvent = dojoEventListener._fixEvent;
dojoEventListener._fixEvent = function(evt, sender) {
	var fixedEvt = originalFixEvent(evt, sender);
	
	var originalPreventDefault = fixedEvt.preventDefault;
	fixedEvt.preventDefault = function() {
		fixedEvt.defaultPrevented = true;
		originalPreventDefault.apply(this, arguments);
	};
	
	return fixedEvt;
};

Change History (2)

comment:1 Changed 8 years ago by Kris Zyp

Resolution: fixed
Status: newclosed

In [27491]:

Add defaultPrevented for IE DOM events, fixes #14065 !strict

comment:2 Changed 8 years ago by bill

Milestone: tbd1.8
Note: See TracTickets for help on using tickets.