I wrote my own code from a completely different direction before I saw
this.  That code adds new events to the standard code that do bubble.
It looks cleaner than what I did.  I added a 'wrapper' around the
standard code, with extra handling for the problem cases.  I also
added a descendant check that is not in the regular code (which I also
found after writing mine):

/* handle bubbling for blur and focus events, so that they can be used
with event delegation
 *
 * Usage: $(element).bubbleUp( eventName, selector, callback );
 */
Element.addMethods(
        {
                bubbleUp: function( element, eventName, selector, callback )
                {
                        var localEle = $(element);
                        if( arguments.length < 4 )
                        {
                                //With no selector, there is no Event 
delegation, and no special
handling needed
                                return localEle.on( eventName, selector );// 
selector is the
callback
                        }
                        if( eventName !== 'blur' && eventName !== 'focus' ) {
                                return localEle.on( eventName, selector, 
callback );
                        }//End if( eventName !== 'blur' && eventName !== 
'focus' ) {

                        if( localEle.addEventListener )
                        {
                                return localEle.addEventListener(
                                        eventName,
                                        function( triggerEvent )
                                        {
                                                var matchElement = 
triggerEvent.findElement( selector );
                                                // Documentation says 
findElement returns 'document' when no
match; symptoms says 'undefined' instead
                                                if( matchElement && 
matchElement.descendantOf( localEle ))
                                                {
                                                        callback.bind( this )( 
triggerEvent, matchElement );
                                                }
                                        },
                                        true
                                );
                        }
                        else // !( localEle.addEventListener )
                        {
                                return localEle.on(
                                        eventName === 
'focus'?'focusin':'focusout', // IE supports
[bubbling of] focusin and focusout
                                        selector, callback //Extension: use 
local function, and replace
event.type with blur or focus before calling callback ??
                                );
                        }//End else !( localEle.addEventListener )
                }//End bubbleUp: function
        }
);

On May 28, 2:28 am, Радослав Станков <rstan...@gmail.com> wrote:
> Hi, as I said in this ticket, you can use this 
> code:http://gist.github.com/162593
>
> for bubbling focus/blur. I have been using it for months and never
> have a single problem with this approach  :)

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to