| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 2 /** 3 * Add functionality to the profile drag and drop table. 4 * 5 * This behavior is dependent on the tableDrag behavior, since it uses the 6 * objects initialized in that behavior to update the row. It shows and hides 7 * a warning message when removing the last field from a profile category. 8 */ 9 Drupal.behaviors.profileDrag = function(context) { 10 var table = $('#profile-fields'); 11 var tableDrag = Drupal.tableDrag['profile-fields']; // Get the profile tableDrag object. 12 13 // Add a handler for when a row is swapped, update empty categories. 14 tableDrag.row.prototype.onSwap = function(swappedRow) { 15 var rowObject = this; 16 $('tr.category-message', table).each(function() { 17 // If the dragged row is in this category, but above the message row, swap it down one space. 18 if ($(this).prev('tr').get(0) == rowObject.element) { 19 // Prevent a recursion problem when using the keyboard to move rows up. 20 if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) { 21 rowObject.swap('after', this); 22 } 23 } 24 // This category has become empty 25 if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').size() == 0) { 26 $(this).removeClass('category-populated').addClass('category-empty'); 27 } 28 // This category has become populated. 29 else if ($(this).is('.category-empty')) { 30 $(this).removeClass('category-empty').addClass('category-populated'); 31 } 32 }); 33 }; 34 35 // Add a handler so when a row is dropped, update fields dropped into new categories. 36 tableDrag.onDrop = function() { 37 dragObject = this; 38 if ($(dragObject.rowObject.element).prev('tr').is('.category-message')) { 39 var categoryRow = $(dragObject.rowObject.element).prev('tr').get(0); 40 var categoryNum = categoryRow.className.replace(/([^ ]+[ ]+)*category-([^ ]+)-message([ ]+[^ ]+)*/, '$2'); 41 var categoryField = $('select.profile-category', dragObject.rowObject.element); 42 var weightField = $('select.profile-weight', dragObject.rowObject.element); 43 var oldcategoryNum = weightField[0].className.replace(/([^ ]+[ ]+)*profile-weight-([^ ]+)([ ]+[^ ]+)*/, '$2'); 44 45 if (!categoryField.is('.profile-category-'+ categoryNum)) { 46 categoryField.removeClass('profile-category-' + oldcategoryNum).addClass('profile-category-' + categoryNum); 47 weightField.removeClass('profile-weight-' + oldcategoryNum).addClass('profile-weight-' + categoryNum); 48 49 categoryField.val(categoryField[0].options[categoryNum].value); 50 } 51 } 52 }; 53 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |