Include to favorites
Log in Logout Register
Start Login Contact Help Photos What's new
Avanced Search
FAQ
RESULTS IN: TEXT IMAGES
 

Hello, Guest
Login  Register
Online: 108 visitors

Blogging (2)
Business (1)
Educational (2)
Gadgets (1)
Games (8)
High Tech News (1)
Internet (1)
PC (2)
PDA (0)
Science (1)
Shopping (6)
Software (1)
Wireless (1)


Browse by date

<< May 2012 >>
MonTueWedThrFriSatSun
123456
78910111213
14151617181920
21222324252627
28293031




Recent searches

Popular searches

Hot this month

Weblogs Archive


GADGETS AND GAMES DIRECTORY :: > Software Register Weblog >  Software Tech Weblogs - WEEKLYBITS.COM GADGETS AND GAMES DIRECTORY
Yahoo User Interface Blog
generated by http://wordpress.org/?v=3.0.4  en Blogger
SEND A FRIEND
Suscribing to  please login first
User: Login

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications.
News and Articles about Designing and Developing with Yahoo! Libraries.Visit Yahoo! User Interface Blog
Address URLhttp://www.yuiblog.com/blog    Registered: 26-Apr-2008
Ads:

Send to email
Visit In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading in DevelopmentYUI 3 GalleryDOM eventsevent bindingYUI 3
By Caridy Patino
el 23-Jun-2010

This article introduces my Event Binder module, recently released in the YUI 3 Gallery.

YUI 3 is getting good traction in the developer community, with significant adoption of the latest 3.1.1 release and a huge infusion of new, innovative projects in the YUI 3 Gallery. Many developers are getting their heads around the on-demand nature of YUI 3 and starting to leverage those capabilities in their designs. This approach has big advantages, but it also can present some challenges.

One of these challenges is to catch user interactions early. Even as the browser starts rendering the page, we want the user to be able to start interacting with page elements. In many cases, those interactions might happen before the JavaScript initialization process (including the attachment of event listeners) has completed.

In many cases you can streamline your initialization code by setting only your event listeners and then adding the logic for loading the pieces that you need for every user interaction. Recently, engineers at Facebook talked about a similar approach to improve the loading process ? see the interview from Rey Bango at JSConf. Here is an example of how this technique might work in YUI 3:

 <script src="http://yui.yahooapis.com/combo?3.1.1/build/yui/yui-min.js&

	3.1.1/build/oop/oop-min.js&3.1.1/build/event-custom/event-custom-base-min.js&
	3.1.1/build/event/event-base-min.js&3.1.1/build/dom/dom-base-min.js&
	3.1.1/build/dom/selector-native-min.js&3.1.1/build/dom/selector-css2-min.js&
	3.1.1/build/node/node-base-min.js"></script>

YUI().use('event-base', function(Y) {
    // wait until the user focuses on an input element to start loading assets
    Y.on("click", function(e) {

      Y.use ('anim', 'io', function() {
          // load a remote content and display it using an animation here
      });

      e.halt(); // stop the propagation
    }, "#demo");
});

This introduces some complexity in your code because listeners not only have to deal with the user interaction but also with some loading logic. Another downside to this approach is that you still have to load some JavaScript code at the top (in this case YUI seed, the Event Utility, and some dependencies) in order to define at least the listener and the loading logic to catch early actions. So, let?s consider this as two separate use-cases:

  • Capturing early user interactions
  • Facilitating the on-demand nature of some user interactions

To address these needs I’ve created a new module for YUI 3. My main focus has been to create a component that works without affecting your application logic. This new module is called "gallery-event-binder" and is now available through the YUI Loader.

Capturing early user interactions

The main goal of this feature is to guarantee that user interactions are queuing until event listeners are initialized.

Let?s see an event binder example:

YUI({
    //Last Gallery Build of this module
    gallery: 'gallery-2010.06.07-17-52'
}).use('gallery-event-binder', 'event', function(Y) {

    Y.on('click', function(e) {

        // do your stuff here
        e.halt(); // stop the event propagation if you want...

    }, '#demo');

    // flush early user interactions
    Y.EventBinder.flush('click');

});

In this example, YUI Loader will try to load the gallery-event-binder and event modules on-demand, and once they’re both ready along with their dependencies, the code within the callback function (third argument) will be executed. During execution, a listener is set for an element with id=demo. The trick here is that once Y.EventBinder.flush('click') gets called, the system will flush some of the click events that might have happened before this initialization code gets executed.

The configuration

This technique requires some extra configuration, specifically the definition of YUI_config as a global variable to tweak the YUI execution. Don’t worry, it’s very simple. Let’s see an example in details:

YUI_config = {
    // standard YUI_config configuration
    combine: true,
    filter: 'min',

    // event binder configuration starts here
    eventbinder: {
        // Event handler to store events that you want to redispatch.
        fn: function(e) {
            var binder = YUI_config.eventbinder,
                filter = /yui3-event-binder/,
                container = (e.target || e.srcElement),
                info = {
                    target: container,
                    type : e.type
                };

            // look for an element with the class yui3-event-binder
            while (container && !filter.test(container.className)) {
                container = container.parentNode;
            }

            if (container) {
                (binder.q = binder.q || []).push(info);

                // prevent the default browser action for this event
                if (e.preventDefault) {
                    e.preventDefault();
                }
                return (e.returnValue = false);
            }
        },
        // interface to listen for specific events
        listenFor: function(type) {
            var d = document;
            // Before the library loads, we have to deal with browser inconsistencies
            if (d.addEventListener) {
                d.addEventListener(type, this.fn, false);
            } else {
                d.attachEvent('on' + type, this.fn);
            }

            return this;
        }
    }
};
// add events to the monitoring process
YUI_config.eventbinder.listenFor('click');

This code should be included at the very top of the page. It will be just a few bites once you minify this configuration object. I recommend using a cacheable (external) file for production and including it in the head section in your pages. You can read more about YUI_config and the different configurations that you can tweak through this object in the official API documentation.

You can modify this configuration to suit you best, and define events that you care about as well. In the above example, we added ‘click’ to the monitoring list (last line). You can add multiple events to the monitoring list using chaining:

YUI_config.eventbinder.listenFor('click').listenFor('keyup').listenFor('mouseover');

How does this feature work?

Once the configuration (i.e., YUI_config) logic is executed, along with the call to YUI_config.eventbinder.listenFor, a listener for a specific event type will be defined. Only events that bubble up will be monitored as the listener will be defined for the document element. When a user interaction is caught at this level, it will be analyzed, specifically checking if the target element or any of its ancestors has classname yui3-event-binder. If so, the event will be added to a queue and the default behavior for that event will be prevented. This technique provides an easy way to monitor specific types of interaction in specific areas of the page.

When this code is executed, listeners for events of the specified type or types are added to the document, so when those events occur and bubble up (this only monitors events that bubble), they will be stopped and their information stored in a processing queue. Later, in your use() callback when your initialization is finished, simply call Y.EventBinder.flush to redispatch all the stored click events as if they happened just then?courtesy of the event-simulate module.

Facilitating the on-demand nature of some user interactions

The main goal of this feature is to help developers to define loading logic based on user interactions.

Here?s another event binder example:

YUI({
  modules: {
    'my-custom-module': {
      fullpath: './my-custom-module.js'
    }
  }
}).use('gallery-event-binder', 'node', function(Y) {

  // set a listener for '#demo a' and rely on 'my-custom-module'
  // to handle that particular event.
  Y.EventBinder.on('click', 'my-custom-module', '#demo a');

  // set a delegate listener for all the anchors in a list and rely
  // on 'my-custom-module' and 'my-another-module' to handle those particular events
  Y.EventBinder.delegate('click', ['my-another-module'], '#mylist', 'li a');

});

Here we use Y.EventBinder.on and Y.EventBinder.delegate to define some listeners. These two methods wrap Y.on and Y.delegate to drive loading logic through a user interaction. This lets us defer loading of specific functionality on a page until the user tries to use a particular feature.

In this case, when a user clicks on one of the elements, we load one or more custom YUI modules that implement all the features associated with that particular click. Once those modules become available (and new listeners are set), the binder will flush the event that was on hold during the loading process to preserve the state of the action.

This feature doesn’t require any initial configuration. Both of Event Binder’s features can be used at the same time to cover early and on-demand user-interactions. In this case, you need to define the configuration, then set the on-demand listeners, and finally flush the early events.

Here?s an end-to-end event binder example:

// configuration
YUI_config = { /* your custom event-binder configuration here */ };
YUI_config.eventbinder.listenFor('click')

// initialization
YUI({
  modules: {
    'my-custom-module': {
      fullpath: './my-custom-module.js'
    }
  }
}).use('gallery-event-binder', function(Y) {

  Y.EventBinder.delegate('click', ['my-custom-module'], '#doc', '.yui3-event-binder a');
  Y.EventBinder.flush('click');

});

A more advanced configuration

You can modify the fn function in your configuration to be more selective about which events to queue and you can store more information about the events. Additionally adds a yui3-waiting class to the click target which we style in CSS to display a loading spinner:

YUI_config = {
    // standard YUI_config configuration
    combine: true,
    filter: 'min',

    // event binder configuration starts here
    eventbinder: {
        // set of options that should be preserved for every event (all optional)
        eventProperties: [
            "ctrlKey", "altKey",
            "shiftKey", "metaKey",
            "keyCode", "charCode",
            "screenX", "screenY",
            "clientX", "clientY",
            "button",
            "relatedTarget"
        ],

        // listener callback function
        fn: function(e) {
            var binder = YUI_config.eventbinder,
                props = binder.eventProperties,
                filter = /yui3-event-binder/,
                target = (e.target || e.srcElement),
                container = target,
                info = {
                    target: target,
                    type : e.type
                },
                i;

            if (target.nodeType === 3) {
                // target is a text node, so use its parent element
                target = target.parentNode;
            }

            // look for an element with the class yui3-event-binder
            while (container && !filter.test(container.className)) {
                container = container.parentNode;
            }

            if (container) {
                target.className += ' yui3-waiting';

                // back up the event properties to simulate the event later on
                for (i = props.length - 1; i >= 0; --i) {
                    info[props[i]] = e[props[i]];
                }

                (binder.q = binder.q || []).push(info);

                // prevent the default browser action for this event
                if (e.preventDefault) {
                    e.preventDefault();
                }
                return (e.returnValue = false);
            }
        },

        listenFor: function(type) {
            var d = document;

            if (d.addEventListener) {
                d.addEventListener(type, this.fn, false);
            } else {
                d.attachEvent('on' + type, this.fn);
            }

            return this;
        }
    }
};
// add events to the monitoring process
YUI_config.eventbinder.listenFor('click');

Check out this event binder example to see this advanced configuration in action.

Conclusion:

For high performance web applications, it’s important for pages to load and become responsive quickly. To accomplish this, we have to rely on on-demand loading techniques. Once you start using them, it’s equally important to control user interactions that can happen before the corresponding code for an action become available.

Event Binder (gallery-event-binder) provides friendly APIs to deal with both use-cases without you having to change your application logic. It can be applied to any YUI 3 application without introducing extra complexity to your code.



Read 18 times

Suscribing to  please login first
In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading -  Tech Weblogs - WEEKLYBITS.COM  Blogger Is a collection of i

Photologs

Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
This article introduces my Event Binder module, recently released in the YUI 3 Gallery. YUI 3 is getting good traction in the developer community, with significant adoption of the latest 3.1.1 release and a huge infusion of new, innovative projects in the YUI 3 Gallery. Many developers are getting their heads around the on-demand nature of [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 23-Jun-2010 by Caridy Patino in DevelopmentYUI 3 GalleryDOM eventsevent bindingYUI 3
Read 18 times. More hits in More articles In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading Images about In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

YUI Theater ? Caridy Patiño Mayea: ?YUI 3 Loading Strategies: A Yahoo! Search Case Study? (51 min.)
Yahoo! frontend engineer Caridy Patiño Mayea speaks at YUIConf 2010 at Yahoo! HQ in Sunnyvale, CA. - YUI Theater ?  Caridy Patiño Mayea: ?YUI 3 Loading Strategies: A Yahoo! Search Case Study? (51 min.) A robust loading strategy is one of the most important elements of optimization for high traffic websites. YUI 3’s Loader is both powerful and elegant, and learning how to leverage it is a must for YUI developers. In this YUIConf 2010 session, Yahoo! frontend engineer and YUI contributor Caridy Patiño Mayea (@caridy) provides a technical [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 02-Dec-2010 by Eric Miraglia in YUI Theatercaridy patiño mayeaJS loading strategiesPerformanceyahooYahoo! Search
Read 12 times. More hits in More articles YUI Theater ?  Caridy Patiño Mayea: ?YUI 3 Loading Strategies: A Yahoo! Search Case Study? (51 min.) Images about YUI Theater ?  Caridy Patiño Mayea: ?YUI 3 Loading Strategies: A Yahoo! Search Case Study? (51 min.)
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

In the YUI 3 Gallery: The Carousel Module
About the authors: Gopal Venkatesan (@g13n) works for Yahoo! in Bangalore where is one of the deans of the frontend engineering community; Gopal has been the lead engineer on the YUI 2 Carousel project since the 2.6.0 release. He is also the author of the new YUI 3 Gallery Carousel module. Fabian Frank [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 13-Dec-2010 by Gopal Venkatesan and Fabian Fr in DevelopmentYUI 3 GallerycarouselYUI 3
Read 33 times. More hits in More articles In the YUI 3 Gallery: The Carousel Module Images about In the YUI 3 Gallery: The Carousel Module
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

In the YUI 3 Gallery: The Preload Module
A few weeks ago, Stoyan Stefanov (@stoyanstefanov) published the result of his research about preloading components in advance without executing them. This technique can help improve the performance of successive pages that make use of the cached resources. To leverage these results, we decided to port it to YUI 3 with a new module called "gallery-preload", [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 10-Jun-2010 by Caridy Patino in DevelopmentYUI 3 Gallery
Read 24 times. More hits in More articles In the YUI 3 Gallery: The Preload Module Images about In the YUI 3 Gallery: The Preload Module
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

In the YUI 3 Gallery: Matt Taylor?s RaphaelJS Module
Matt Taylor (@rhyolight, blog) works for Yahoo! on an internal browser-side JavaScript framework. He enjoys working with graphics, and he’s worked with drawings and animations before using Java2d libraries. Before moving to Silicon Valley to work for Yahoo!, Matt worked in the St. Louis area as a software contractor. He’s also worked extensively with Groovy [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 27-Sep-2010 by Matthew Taylor in DevelopmentYUI 3 Gallery
Read 13 times. More hits in More articles In the YUI 3 Gallery: Matt Taylor?s RaphaelJS Module Images about In the YUI 3 Gallery: Matt Taylor?s RaphaelJS Module
The Boy Genius Report Blogger

The gadgets and technology weblog
BGR

Apple to hold iOS 5 event in early April, report claims
A new report suggests Apple will unveil the next version of its mobile operating system at a media event early next month. German Apple enthusiast blog Macerkopf.de cites a trusted source in claiming that Apple will reveal iOS 5 and new MobileMe features in early April. The timing of the rumor is in line with Apple’s announcements in years past; Apple held its iOS 4 event last year on April [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 08-Mar-2011 by Zach Epstein in
Read 26 times. More hits in More articles Apple to hold iOS 5 event in early April, report claims Images about Apple to hold iOS 5 event in early April, report claims
Joystiq Blogger

Covers video game news from an independent, unbiased perspective
Joystiq Joystiq

Batman: Arkham City copies available early at Times Square TRU event
The Times Square Toys R Us location will hold an event on Monday, October 17, where 500 copies of Batman: Arkham City will be available a day early. The first 100 customers who pre-purchase a copy of the game thro [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 06-Oct-2011 by Alexander Sliwinski in
Read 5 times. More hits in More articles Batman: Arkham City copies available early at Times Square TRU event Images about Batman: Arkham City copies available early at Times Square TRU event
Joystiq Blogger

Covers video game news from an independent, unbiased perspective
Joystiq Joystiq

Get Zelda: Skyward Sword a day early at launch event, get Penny Arcade comic now
You won't have to go on a treasure hunt through dungeon-like NYC game stores to get a head start on The Legend of Zelda: Skyward Sword. If you're in the city, you'll be able to purchase the game a day early, and celebrate the launch with some fellow Triforce [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 15-Nov-2011 by JC Fletcher in
Read 5 times. More hits in More articles Get Zelda: Skyward Sword a day early at launch event, get Penny Arcade comic now Images about Get Zelda: Skyward Sword a day early at launch event, get Penny Arcade comic now
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

YUI 3.2.0 Released: SimpleYUI, Touch Event Support, Gestures, Transitions, CSS Grids, ScrollView, Uploader, and More
Intrinsic touch support in YUI 3.2.0 brings touch support to a wide range of YUI-powered interactions, including Drag and Drop and Slider. - YUI 3.2.0 Released: SimpleYUI, Touch Event Support, Gestures, Transitions, CSS Grids, ScrollView, Uploader, and More The YUI team is pleased to announce the GA release of YUI 3.2.0, a significant update to YUI’s JavaScript and CSS components. This release features a host of performance improvements and major new support for mobile devices with touch UIs. The Gesture module in YUI 3.2.0 brings touch support to a wide range of YUI-powered [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 07-Sep-2010 by Eric Miraglia in Development
Read 45 times. More hits in More articles YUI 3.2.0 Released: SimpleYUI, Touch Event Support, Gestures, Transitions, CSS Grids, ScrollView, Uploader, and More Images about YUI 3.2.0 Released: SimpleYUI, Touch Event Support, Gestures, Transitions, CSS Grids, ScrollView, Uploader, and More
Yahoo User Interface Blog Blogger

Is a collection of industrial-grade JavaScript utilities and widgets that enable you to efficiently get the most out of today’s powerful web applications. Yahoo! User Interface Blog News and Articles about Designing and Developing wiht Yahoo! Libraries.

YUI 3.2.0 Preview Release 1: Touch Event Support, Gestures, Transitions, CSS Grids, ScrollView, Uploader, and More
The YUI contributor’s team is pleased to announce the first developer preview of the upcoming YUI 3.2.0 release. This preview provides an opportunity for developers and implementers to help test the release for potential regressions and to provide feedback on new features and components. If you have an existing YUI implementation, please exercise [...] [..] Read complete article
Subscribe to In the YUI 3 Gallery: Caridy Patiño Mayea?s Event Binder Module Provides Support for Early Event Binding and Event-driven Module Loading
Published 26-Jul-2010 by Eric Miraglia in DevelopmentyuiYUI 3
Read 34 times. More hits in More articles YUI 3.2.0 Preview Release 1: Touch Event Support, Gestures, Transitions, CSS Grids, ScrollView, Uploader, and More Images about YUI 3.2.0 Preview Release 1: Touch Event Support, Gestures, Transitions, CSS Grids, ScrollView, Uploader, and More

Warning We are not responsible of information posted from external feeds. Use this website at your own risk. Notice: We will not be liable for any direct or indirect loss or damage arising under this disclaimer or in connection with our website, whether arising in tort, contract, or otherwise.


Your Site here Your Site here Your site here Your site here Your site here