/[drupal]/drupal/modules/profile/profile.js
ViewVC logotype

Contents of /drupal/modules/profile/profile.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download) (as text)
Mon Apr 27 20:19:37 2009 UTC (7 months ago) by webchick
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-7, DRUPAL-7-0-UNSTABLE-10, DRUPAL-7-0-UNSTABLE-8, DRUPAL-7-0-UNSTABLE-9, HEAD
Changes since 1.6: +6 -6 lines
File MIME type: text/javascript
#444402 follow-up by kkaefer: Fix autocomplete, enforce code style for anonymous JS functions.
1 // $Id: profile.js,v 1.6 2009/04/26 19:18:46 webchick Exp $
2 (function ($) {
3
4 /**
5 * Add functionality to the profile drag and drop table.
6 *
7 * This behavior is dependent on the tableDrag behavior, since it uses the
8 * objects initialized in that behavior to update the row. It shows and hides
9 * a warning message when removing the last field from a profile category.
10 */
11 Drupal.behaviors.profileDrag = {
12 attach: function (context, settings) {
13 var table = $('#profile-fields');
14 var tableDrag = Drupal.tableDrag['profile-fields']; // Get the profile tableDrag object.
15
16 // Add a handler for when a row is swapped, update empty categories.
17 tableDrag.row.prototype.onSwap = function (swappedRow) {
18 var rowObject = this;
19 $('tr.category-message', table).each(function () {
20 // If the dragged row is in this category, but above the message row, swap it down one space.
21 if ($(this).prev('tr').get(0) == rowObject.element) {
22 // Prevent a recursion problem when using the keyboard to move rows up.
23 if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
24 rowObject.swap('after', this);
25 }
26 }
27 // This category has become empty
28 if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) {
29 $(this).removeClass('category-populated').addClass('category-empty');
30 }
31 // This category has become populated.
32 else if ($(this).is('.category-empty')) {
33 $(this).removeClass('category-empty').addClass('category-populated');
34 }
35 });
36 };
37
38 // Add a handler so when a row is dropped, update fields dropped into new categories.
39 tableDrag.onDrop = function () {
40 dragObject = this;
41 if ($(dragObject.rowObject.element).prev('tr').is('.category-message')) {
42 var categoryRow = $(dragObject.rowObject.element).prev('tr').get(0);
43 var categoryNum = categoryRow.className.replace(/([^ ]+[ ]+)*category-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
44 var categoryField = $('select.profile-category', dragObject.rowObject.element);
45 var weightField = $('select.profile-weight', dragObject.rowObject.element);
46 var oldcategoryNum = weightField[0].className.replace(/([^ ]+[ ]+)*profile-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
47
48 if (!categoryField.is('.profile-category-' + categoryNum)) {
49 categoryField.removeClass('profile-category-' + oldcategoryNum).addClass('profile-category-' + categoryNum);
50 weightField.removeClass('profile-weight-' + oldcategoryNum).addClass('profile-weight-' + categoryNum);
51
52 categoryField.val(categoryField[0].options[categoryNum].value);
53 }
54 }
55 };
56 }
57 };
58
59 })(jQuery);

  ViewVC Help
Powered by ViewVC 1.1.2