diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-04-11 22:19:46 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-04-11 22:19:46 +0000 |
commit | e888f0061cb7ca2f07b38ad4ff09da99faa75580 (patch) | |
tree | b1ffa36ead61e0061e99fdb4c33a8ea823eb4af5 /misc/form.js | |
parent | f278da9e50815f279ce4c7bda993f5d21b43efa3 (diff) | |
download | brdo-e888f0061cb7ca2f07b38ad4ff09da99faa75580.tar.gz brdo-e888f0061cb7ca2f07b38ad4ff09da99faa75580.tar.bz2 |
#323112 by dmitrig01, kkaefer, quicksketch, frando and many many more: Now presenting... Vertical Tabs. Fantastic new UI improvement for node forms and hopefully more in the future.
Diffstat (limited to 'misc/form.js')
-rw-r--r-- | misc/form.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/misc/form.js b/misc/form.js index 4451e40d9..b54582391 100644 --- a/misc/form.js +++ b/misc/form.js @@ -1,6 +1,63 @@ // $Id$ (function($) { +/** + * Retrieves the summary for the first element. + */ +$.fn.getSummary = function() { + var callback = this.data('summaryCallback'); + return (this[0] && callback) ? $.trim(callback(this[0])) : ''; +}; + +/** + * Sets the summary for all matched elements. + * + * @param callback + * Either a function that will be called each time the summary is + * retrieved or a string (which is returned each time). + */ +$.fn.setSummary = function(callback) { + var that = this; + + // To facilitate things, the callback should always be a function. If it's + // not, we wrap it into an anonymous function which just returns the value. + if (typeof callback != 'function') { + var val = callback; + callback = function() { return val; }; + } + + return this + .data('summaryCallback', callback) + // To prevent duplicate events, the handlers are first removed and then + // (re-)added. + .unbind('formUpdated.summary') + .bind('formUpdated.summary', function() { + that.trigger('summaryUpdated'); + }) + // The actual summaryUpdated handler doesn't fire when the callback is + // changed, so we have to do this manually. + .trigger('summaryUpdated'); +}; + +/** + * Sends a 'formUpdated' event each time a form element is modified. + */ +Drupal.behaviors.formUpdated = { + attach: function(context) { + // These events are namespaced so that we can remove them later. + var events = 'change.formUpdated click.formUpdated blur.formUpdated keyup.formUpdated'; + $(context) + // Since context could be an input element itself, it's added back to + // the jQuery object and filtered again. + .find(':input').andSelf().filter(':input') + // To prevent duplicate events, the handlers are first removed and then + // (re-)added. + .unbind(events).bind(events, function() { + $(this).trigger('formUpdated'); + }); + } +}; + Drupal.behaviors.multiselectSelector = { attach: function(context, settings) { // Automatically selects the right radio button in a multiselect control. |