• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • API Docs
    • Environments
    • Tutorials
  • Community
    • Gallery
    • Blog
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • Shifter »
    • Yogi »
    • YUI 2
    • YUI Doc »
    • YUI Test
    • YUI Website
    • YUI Compressor »
    • YUI Builder »
    • YUI PHP Loader
    • Grid Builder »
    • Skin Builder »
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • Yogi Documentation
  • Shifter Documentation
  • Developer Guide
  • Module Setup

Tag Cloud

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    Patch: 3.3.0 bubble target vs preventedFn (gallery-patch-330-event-preventedfn) on cdn

    Last Updated: 02/9/11
    + 0 -

    Luke Smith

    YUI Contributor

    See 19 more by this user.

    Created: 02/7/11
    Last CDN Push: 03/9/11
    Build Tag: gallery-2011.03.09-21-14
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.3.0
    Free for use.

    This patch adds missing logic in YUI 3.3.0's event system whereby preventing an event from a bubble target did not trigger the event's preventedFn.

    See the example snippet below for the case where the behavior fails without this patch.

    This patch module is only necessary for version 3.3.0.

    • Tags:
    • lsmith
    • event
    • bug
    • patch
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Apply the patch in the use() statement as long as version 3.3.0 is in use. Remove from the use() statement after upgrading to the subsequent version.

    Code Sample

    <script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2011.03.09-21-14'
    }).use('event-custom', 'gallery-patch-330-event-preventedfn', function(Y) {
     
        // Create two EventTargets (typically, these will be class instances that inherit from EventTarget
        var a = new Y.EventTarget({ emitFacade: true, prefix: 'a' }),
            b = new Y.EventTarget({ emitFacade: true, prefix: 'b', bubbles: true });
     
        // Events from b will bubble to a, allowing a.on('b:foo', fn)
        b.addTarget(a);
     
        // The child publishes an event with a preventedFn, so when e.preventDefault() is called from a
        // subscriber, this function should execute instead of the defaultFn
        b.publish('foo', {
            defaultFn: function () { Y.log('default'); },
            preventedFn: function () { Y.log('prevented'); }
        });
     
        // Set up event subscribers to every phase of the event lifecycle
        b.on('foo', function () { Y.log('b on foo'); });
        b.after('foo', function () { Y.log('b after foo'); });
        a.on('b:foo', function () { Y.log('a on foo'); });
        a.after('b:foo', function () { Y.log('a after foo'); });
     
        // If the event is not prevented, the following messages should be logged in order:
        // b on foo
        // a on foo
        // default
        // a after foo
        // b after foo
     
        // Preventing the event from a bubble target subscriber should trigger the preventedFn.
        // This is not happening in 3.3.0 without this patch
        a.on('b:foo', function (e) { e.preventDefault(); });
     
        b.fire('foo');
     
        // output before (notice no defaultFn, but also no preventedFn):
        // b on foo
        // a on foo
     
        // output with patch
        // b on foo
        // a on foo
        // prevented
     
    });

    © 2006-2013 Yahoo! Inc. All rights reserved.
    All code on this site is licensed under the BSD License unless stated otherwise.
    About This Site · Security Contact Info