summaryrefslogtreecommitdiff
path: root/modules/profile/profile.js
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-10-29 10:01:28 +0000
committerDries Buytaert <dries@buytaert.net>2008-10-29 10:01:28 +0000
commit5371104a2d10889c532bb5d345fa6d71c0a897d1 (patch)
treebbef382cea55823195e0cb7469074b743913bc74 /modules/profile/profile.js
parent068febde425f4521d61f863ffaca76da65916449 (diff)
downloadbrdo-5371104a2d10889c532bb5d345fa6d71c0a897d1.tar.gz
brdo-5371104a2d10889c532bb5d345fa6d71c0a897d1.tar.bz2
- Patch #316225 by sun et al: allow behaviors to detach from AHAH/AJAX.
Diffstat (limited to 'modules/profile/profile.js')
-rw-r--r--modules/profile/profile.js78
1 files changed, 40 insertions, 38 deletions
diff --git a/modules/profile/profile.js b/modules/profile/profile.js
index 2d84d27e0..d14be4b7d 100644
--- a/modules/profile/profile.js
+++ b/modules/profile/profile.js
@@ -7,48 +7,50 @@
* objects initialized in that behavior to update the row. It shows and hides
* a warning message when removing the last field from a profile category.
*/
-Drupal.behaviors.profileDrag = function(context) {
- var table = $('#profile-fields');
- var tableDrag = Drupal.tableDrag['profile-fields']; // Get the profile tableDrag object.
+Drupal.behaviors.profileDrag = {
+ attach: function(context) {
+ var table = $('#profile-fields');
+ var tableDrag = Drupal.tableDrag['profile-fields']; // Get the profile tableDrag object.
- // Add a handler for when a row is swapped, update empty categories.
- tableDrag.row.prototype.onSwap = function(swappedRow) {
- var rowObject = this;
- $('tr.category-message', table).each(function() {
- // If the dragged row is in this category, but above the message row, swap it down one space.
- if ($(this).prev('tr').get(0) == rowObject.element) {
- // Prevent a recursion problem when using the keyboard to move rows up.
- if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
- rowObject.swap('after', this);
+ // Add a handler for when a row is swapped, update empty categories.
+ tableDrag.row.prototype.onSwap = function(swappedRow) {
+ var rowObject = this;
+ $('tr.category-message', table).each(function() {
+ // If the dragged row is in this category, but above the message row, swap it down one space.
+ if ($(this).prev('tr').get(0) == rowObject.element) {
+ // Prevent a recursion problem when using the keyboard to move rows up.
+ if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
+ rowObject.swap('after', this);
+ }
}
- }
- // This category has become empty
- if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) {
- $(this).removeClass('category-populated').addClass('category-empty');
- }
- // This category has become populated.
- else if ($(this).is('.category-empty')) {
- $(this).removeClass('category-empty').addClass('category-populated');
- }
- });
- };
+ // This category has become empty
+ if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) {
+ $(this).removeClass('category-populated').addClass('category-empty');
+ }
+ // This category has become populated.
+ else if ($(this).is('.category-empty')) {
+ $(this).removeClass('category-empty').addClass('category-populated');
+ }
+ });
+ };
- // Add a handler so when a row is dropped, update fields dropped into new categories.
- tableDrag.onDrop = function() {
- dragObject = this;
- if ($(dragObject.rowObject.element).prev('tr').is('.category-message')) {
- var categoryRow = $(dragObject.rowObject.element).prev('tr').get(0);
- var categoryNum = categoryRow.className.replace(/([^ ]+[ ]+)*category-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
- var categoryField = $('select.profile-category', dragObject.rowObject.element);
- var weightField = $('select.profile-weight', dragObject.rowObject.element);
- var oldcategoryNum = weightField[0].className.replace(/([^ ]+[ ]+)*profile-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
+ // Add a handler so when a row is dropped, update fields dropped into new categories.
+ tableDrag.onDrop = function() {
+ dragObject = this;
+ if ($(dragObject.rowObject.element).prev('tr').is('.category-message')) {
+ var categoryRow = $(dragObject.rowObject.element).prev('tr').get(0);
+ var categoryNum = categoryRow.className.replace(/([^ ]+[ ]+)*category-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
+ var categoryField = $('select.profile-category', dragObject.rowObject.element);
+ var weightField = $('select.profile-weight', dragObject.rowObject.element);
+ var oldcategoryNum = weightField[0].className.replace(/([^ ]+[ ]+)*profile-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
- if (!categoryField.is('.profile-category-'+ categoryNum)) {
- categoryField.removeClass('profile-category-' + oldcategoryNum).addClass('profile-category-' + categoryNum);
- weightField.removeClass('profile-weight-' + oldcategoryNum).addClass('profile-weight-' + categoryNum);
+ if (!categoryField.is('.profile-category-'+ categoryNum)) {
+ categoryField.removeClass('profile-category-' + oldcategoryNum).addClass('profile-category-' + categoryNum);
+ weightField.removeClass('profile-weight-' + oldcategoryNum).addClass('profile-weight-' + categoryNum);
- categoryField.val(categoryField[0].options[categoryNum].value);
+ categoryField.val(categoryField[0].options[categoryNum].value);
+ }
}
- }
- };
+ };
+ }
};