Skip to main content

Bug Tracker

Side navigation

#13619 closed feature (duplicate)

Opened March 17, 2013 12:18PM UTC

Closed March 18, 2013 04:35PM UTC

Adding a event to the begging of event stack

Reported by: ben@lupimedia.com Owned by: ben@lupimedia.com
Priority: undecided Milestone: None
Component: unfiled Version: 2.0b2
Keywords: Cc:
Blocked by: Blocking:
Description

being able to bind events that get placed at the beginning of the event stack.

i made a quick mod to the events to get the desired behaviour, and might be good to put in.

example 1 :: normal event order

var t = $('<div/>');

t.on('test', function(){console.log('FIRST');});

t.on('test', function(e){ e.stopImmediatePropagation(); console.log('last');});

t.trigger('test');

FIRST

last

example 2 :: adding a event before the others

var t = $('<div/>');

t.on('test', function(){console.log('FIRST');});

t.on('~test', function(e){ e.stopImmediatePropagation(); console.log('last');});

t.trigger('test');

last

code:

in events:add

after:

type = ( selector ? special.delegateType : special.bindType ) || type;

insert:

var placeFirst = type[0] === '~';

if(placeFirst){

type = type.substr(1);

}

replace:

handlers.push( handleObj );

with:

if(placeFirst){

handlers.unshift( handleObj );

}else{

handlers.push( handleObj );

}

Attachments (0)
Change History (2)

Changed March 18, 2013 04:18PM UTC by timmywil comment:1

owner: → ben@lupimedia.com
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/. Open the link and click to "Fork" (in the top menu) to get started.

Changed March 18, 2013 04:35PM UTC by timmywil comment:2

resolution: → duplicate
status: pendingclosed

Duplicate of #7548.Sorry, I didn't read this closely. I just saw the pasted code and asked for a test case. However, this is not something that will be added to core.