/** * Copyright (c) 2008, Nathan Bubna * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Simplifies the process of getting/setting values from/for the descendants * of any HTML element(s). This is a bit like form serialization except * that it can both get and set values for form fields, div/span elements, * or any such mix of nodes. Another way to look at it is as an HTML template * engine that is bi-directional and does not actually require a separate * template. Rather than replacing placeholders, it uses element attributes * to identify where values should be set or retrieved. * * To retrieve values, simply do: * * var values = $('.parent').values(); * * This will look amongst the descendants of the element(s) with class 'parent' * to find all elements with a 'name' attribute and then smartly * grabs the "value" for each of those elements. By "smartly", i mean that * it use $el.val() for input elements, $el.find('option:selected').text() * for select elements, and $el.text() for the rest, in other words, it grabs the * displayed values by default. It also trims whitespace when it uses text(). * Once each value is retrieved it is added to a hash object (think JSON) using * the value of the 'name' attribute as its key, and in the end, that hash * object is returned, giving you easy access to the values. * * If you pass in an object to this method, like: * * $('.parent').values({ foo: 'bar', answer: 42 }); * * it will reverse the process and set those values to the elements * with matching names. * * If you pass in a different HTML element(s), like: * * $('.parent').values($('form#foo')); * * then it will grab the values from