1 |
85ad3d82
|
Assos Assos
|
(function ($) {
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
Drupal.behaviors.shortcutDrag = {
|
10 |
|
|
attach: function (context, settings) {
|
11 |
|
|
if (Drupal.tableDrag) {
|
12 |
|
|
var table = $('table#shortcuts'),
|
13 |
|
|
visibleLength = 0,
|
14 |
|
|
slots = 0,
|
15 |
|
|
tableDrag = Drupal.tableDrag.shortcuts;
|
16 |
|
|
$('> tbody > tr, > tr', table)
|
17 |
|
|
.filter(':visible')
|
18 |
|
|
.filter(':odd').filter('.odd')
|
19 |
|
|
.removeClass('odd').addClass('even')
|
20 |
|
|
.end().end()
|
21 |
|
|
.filter(':even').filter('.even')
|
22 |
|
|
.removeClass('even').addClass('odd')
|
23 |
|
|
.end().end()
|
24 |
|
|
.end()
|
25 |
|
|
.filter('.shortcut-slot-empty').each(function(index) {
|
26 |
|
|
if ($(this).is(':visible')) {
|
27 |
|
|
visibleLength++;
|
28 |
|
|
}
|
29 |
|
|
slots++;
|
30 |
|
|
});
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
tableDrag.row.prototype.onSwap = function (swappedRow) {
|
34 |
|
|
var disabledIndex = $(table).find('tr').index($(table).find('tr.shortcut-status-disabled')) - slots - 2,
|
35 |
|
|
count = 0;
|
36 |
|
|
$(table).find('tr.shortcut-status-enabled').nextAll(':not(.shortcut-slot-empty)').each(function(index) {
|
37 |
|
|
if (index < disabledIndex) {
|
38 |
|
|
count++;
|
39 |
|
|
}
|
40 |
|
|
});
|
41 |
|
|
var total = slots - count;
|
42 |
|
|
if (total == -1) {
|
43 |
|
|
var disabled = $(table).find('tr.shortcut-status-disabled');
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
var changedRow = disabled.prevAll(':not(.shortcut-slot-empty)').not($(this.element)).get(0);
|
47 |
|
|
disabled.after(changedRow);
|
48 |
|
|
if ($(changedRow).hasClass('draggable')) {
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
var changedRowObject = new tableDrag.row(changedRow, 'mouse', false, 0, true);
|
54 |
|
|
changedRowObject.markChanged();
|
55 |
|
|
tableDrag.rowStatusChange(changedRowObject);
|
56 |
|
|
}
|
57 |
|
|
}
|
58 |
|
|
else if (total != visibleLength) {
|
59 |
|
|
if (total > visibleLength) {
|
60 |
|
|
|
61 |
|
|
$('.shortcut-slot-empty:hidden:last').show();
|
62 |
|
|
visibleLength++;
|
63 |
|
|
}
|
64 |
|
|
else {
|
65 |
|
|
|
66 |
|
|
$('.shortcut-slot-empty:visible:last').hide();
|
67 |
|
|
visibleLength--;
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
};
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
tableDrag.onDrop = function () {
|
74 |
|
|
tableDrag.rowStatusChange(this.rowObject);
|
75 |
|
|
return true;
|
76 |
|
|
};
|
77 |
|
|
|
78 |
|
|
tableDrag.rowStatusChange = function (rowObject) {
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
var statusRow = $(rowObject.element).prevAll('tr.shortcut-status').get(0);
|
82 |
|
|
var statusName = statusRow.className.replace(/([^ ]+[ ]+)*shortcut-status-([^ ]+)([ ]+[^ ]+)*/, '$2');
|
83 |
|
|
var statusField = $('select.shortcut-status-select', rowObject.element);
|
84 |
|
|
statusField.val(statusName);
|
85 |
|
|
};
|
86 |
|
|
|
87 |
|
|
tableDrag.restripeTable = function () {
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
$('> tbody > tr:visible, > tr:visible', this.table)
|
92 |
|
|
.filter(':odd').filter('.odd')
|
93 |
|
|
.removeClass('odd').addClass('even')
|
94 |
|
|
.end().end()
|
95 |
|
|
.filter(':even').filter('.even')
|
96 |
|
|
.removeClass('even').addClass('odd');
|
97 |
|
|
};
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
};
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
Drupal.behaviors.newSet = {
|
107 |
|
|
attach: function (context, settings) {
|
108 |
|
|
var selectDefault = function() {
|
109 |
|
|
$(this).closest('form').find('.form-item-set .form-type-radio:last input').attr('checked', 'checked');
|
110 |
|
|
};
|
111 |
|
|
$('div.form-item-new input').focus(selectDefault).keyup(selectDefault);
|
112 |
|
|
}
|
113 |
|
|
};
|
114 |
|
|
|
115 |
|
|
})(jQuery); |