TiddlyWiki.org

Ticket #413 (closed enhancement: fixed)

Opened 10 months ago

Last modified 10 months ago

Refactor event bubbling code

Reported by: SaqImtiaz Assigned to: SaqImtiaz
Priority: minor Milestone: 2.3
Component: core Version:
Severity: undefined Keywords:
Cc:

Description

It is suggested to create a function called stopEvent:

function stopEvent(ev){
	var e = ev? ev : window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
	return false;	
}	

This function would allow us to replace all instances of code like:

	e.cancelBubble = true;
	if(e.stopPropagation) e.stopPropagation();

with

stopEvent(e);

I've tested this on FF2, IE6 and IE7 and it works well.

Including the line var e = ev? ev : window.event; and returning false means that you can assign this function directly as the onclick or ondblclick for any DOM element where all click events should be prevented from bubbling.

document.getElementById("dontAllowDoubleClick").ondblclick = stopEvent;

Attachments

Ticket413.patch (466 bytes) - added by SaqImtiaz on 12/11/07 17:57:11.

Change History

12/11/07 17:57:11 changed by SaqImtiaz

  • attachment Ticket413.patch added.

12/11/07 17:57:19 changed by SaqImtiaz

  • status changed from new to assigned.

12/11/07 17:57:25 changed by SaqImtiaz

  • type changed from defect to enhancement.

26/11/07 10:24:27 changed by JeremyRuston

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in changeset:2969