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

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • FAQ
  • Developer FAQ
  • Developer Guide
  • Module Setup

Tag Cloud

ericf yql io node datatable caridy davglass foxxtrot apipkin satyam solmsted model plugin jafl form liferay async animation table widget event nzakas greghinch css lsmith

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.

    Data Storage (gallery-data-storage) on cdn

    Last Updated: 03/27/10
    + -1 -

    Andrew Bialecki

    YUI Contributor

    See 2 more by this user.

    Created: 03/14/10
    Last CDN Push: 03/16/10
    Build Tag: gallery-2010.03.16-20
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.0.0
    Free for use.

    UPDATE: Deprecated: See the Node module and class which now support everything you need natively.

    Sometimes it's useful to store arbitrary data with a particular node or object. If your class uses the Attribute utility, you're in luck and you're job is done. However, the Node class doesn't (yet) use the Attribute utility, so this port of the jQuery data storage API allows you to associate data with a particular Node instance. In fact, you're not limited to a Y.Node instances -- any object will do.

    For Y.Node and Y.NodeList instances, two methods -- data() and removeData() -- are added to their prototypes and chainable so you can easily store and retrieve data you want to associate with those elements.

    Documentation


    See http://projects.sophomoredev.com/yui-gallery-data-storage/ for quick documentation. It's pretty straightforward.
    • Tags:
    • storage
    • bialecki
    • data
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Here's a quick snippet of what you can do with the data storage module covering use with Node instances, NodeList instances and arbitrary JavaScript objects.

    Code Sample

    <script src="http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js"></script>
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2010.03.16-20'
    }).use('gallery-data-storage', function(Y) {
     
        // Use it with a single element...
     
        var foo = Y.one("#foo").data("bar", "baz");
     
        foo.data(); // { bar: "baz" }
        foo.data("bar"); // "baz"
     
        foo.removeData();
        foo.data("bar") // undefined
     
     
        // Use it with a list of elements...
     
        var lis = Y.all("li").data("type", "you are a li"),
            first = lis.item(0).data("type", "you're the leader li");
     
        first.data(); // { type: "you're the leader li" }
        lis.item(1).data("type"); // "you are a li"
     
     
        // Use it with any old object...
        var obj = {},
            DS = Y.DataStorage;
     
        DS.data(obj, "favoriteTeam", "redSox");
        DS.data(obj, "favoriteColor", "orange");
     
        DS.data(obj); // { favoriteTeam: "redSox", favoriteColor: "orange" }
     
        DS.removeData(obj, "favoriteTeam");
     
        DS.data(obj, "favoriteColor"); // "orange"
    });

    Forum Posts

    No forum posts for this module.

    © 2006-2011 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