12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- (function ($) {
- Drupal.behaviors.profileDrag = {
- attach: function (context, settings) {
- var table = $('#profile-fields');
- var tableDrag = Drupal.tableDrag['profile-fields'];
-
- tableDrag.row.prototype.onSwap = function (swappedRow) {
- var rowObject = this;
- $('tr.category-message', table).each(function () {
-
- if ($(this).prev('tr').get(0) == rowObject.element) {
-
- if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {
- rowObject.swap('after', this);
- }
- }
-
- if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').length == 0) {
- $(this).removeClass('category-populated').addClass('category-empty');
- }
-
- else if ($(this).is('.category-empty')) {
- $(this).removeClass('category-empty').addClass('category-populated');
- }
- });
- };
-
- 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);
- categoryField.val(categoryField[0].options[categoryNum].value);
- }
- }
- };
- }
- };
- })(jQuery);
|