root / drupal7 / modules / block / block.js @ 76597ebf
1 |
(function ($) { |
---|---|
2 |
|
3 |
/**
|
4 |
* Provide the summary information for the block settings vertical tabs.
|
5 |
*/
|
6 |
Drupal.behaviors.blockSettingsSummary = { |
7 |
attach: function (context) { |
8 |
// The drupalSetSummary method required for this behavior is not available
|
9 |
// on the Blocks administration page, so we need to make sure this
|
10 |
// behavior is processed only if drupalSetSummary is defined.
|
11 |
if (typeof jQuery.fn.drupalSetSummary == 'undefined') { |
12 |
return;
|
13 |
} |
14 |
|
15 |
$('fieldset#edit-path', context).drupalSetSummary(function (context) { |
16 |
if (!$('textarea[name="pages"]', context).val()) { |
17 |
return Drupal.t('Not restricted'); |
18 |
} |
19 |
else {
|
20 |
return Drupal.t('Restricted to certain pages'); |
21 |
} |
22 |
}); |
23 |
|
24 |
$('fieldset#edit-node-type', context).drupalSetSummary(function (context) { |
25 |
var vals = [];
|
26 |
$('input[type="checkbox"]:checked', context).each(function () { |
27 |
vals.push($.trim($(this).next('label').text())); |
28 |
}); |
29 |
if (!vals.length) {
|
30 |
vals.push(Drupal.t('Not restricted'));
|
31 |
} |
32 |
return vals.join(', '); |
33 |
}); |
34 |
|
35 |
$('fieldset#edit-role', context).drupalSetSummary(function (context) { |
36 |
var vals = [];
|
37 |
$('input[type="checkbox"]:checked', context).each(function () { |
38 |
vals.push($.trim($(this).next('label').text())); |
39 |
}); |
40 |
if (!vals.length) {
|
41 |
vals.push(Drupal.t('Not restricted'));
|
42 |
} |
43 |
return vals.join(', '); |
44 |
}); |
45 |
|
46 |
$('fieldset#edit-user', context).drupalSetSummary(function (context) { |
47 |
var $radio = $('input[name="custom"]:checked', context); |
48 |
if ($radio.val() == 0) { |
49 |
return Drupal.t('Not customizable'); |
50 |
} |
51 |
else {
|
52 |
return $radio.next('label').text(); |
53 |
} |
54 |
}); |
55 |
} |
56 |
}; |
57 |
|
58 |
/**
|
59 |
* Move a block in the blocks table from one region to another via select list.
|
60 |
*
|
61 |
* This behavior is dependent on the tableDrag behavior, since it uses the
|
62 |
* objects initialized in that behavior to update the row.
|
63 |
*/
|
64 |
Drupal.behaviors.blockDrag = { |
65 |
attach: function (context, settings) { |
66 |
// tableDrag is required and we should be on the blocks admin page.
|
67 |
if (typeof Drupal.tableDrag == 'undefined' || typeof Drupal.tableDrag.blocks == 'undefined') { |
68 |
return;
|
69 |
} |
70 |
|
71 |
var table = $('table#blocks'); |
72 |
var tableDrag = Drupal.tableDrag.blocks; // Get the blocks tableDrag object. |
73 |
|
74 |
// Add a handler for when a row is swapped, update empty regions.
|
75 |
tableDrag.row.prototype.onSwap = function (swappedRow) { |
76 |
checkEmptyRegions(table, this);
|
77 |
}; |
78 |
|
79 |
// A custom message for the blocks page specifically.
|
80 |
Drupal.theme.tableDragChangedWarning = function () { |
81 |
return '<div class="messages warning">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t('The changes to these blocks will not be saved until the <em>Save blocks</em> button is clicked.') + '</div>'; |
82 |
}; |
83 |
|
84 |
// Add a handler so when a row is dropped, update fields dropped into new regions.
|
85 |
tableDrag.onDrop = function () { |
86 |
dragObject = this;
|
87 |
// Use "region-message" row instead of "region" row because
|
88 |
// "region-{region_name}-message" is less prone to regexp match errors.
|
89 |
var regionRow = $(dragObject.rowObject.element).prevAll('tr.region-message').get(0); |
90 |
var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2'); |
91 |
var regionField = $('select.block-region-select', dragObject.rowObject.element); |
92 |
// Check whether the newly picked region is available for this block.
|
93 |
if ($('option[value=' + regionName + ']', regionField).length == 0) { |
94 |
// If not, alert the user and keep the block in its old region setting.
|
95 |
alert(Drupal.t('The block cannot be placed in this region.'));
|
96 |
// Simulate that there was a selected element change, so the row is put
|
97 |
// back to from where the user tried to drag it.
|
98 |
regionField.change(); |
99 |
} |
100 |
else if ($(dragObject.rowObject.element).prev('tr').is('.region-message')) { |
101 |
var weightField = $('select.block-weight', dragObject.rowObject.element); |
102 |
var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/, '$2'); |
103 |
|
104 |
if (!regionField.is('.block-region-' + regionName)) { |
105 |
regionField.removeClass('block-region-' + oldRegionName).addClass('block-region-' + regionName); |
106 |
weightField.removeClass('block-weight-' + oldRegionName).addClass('block-weight-' + regionName); |
107 |
regionField.val(regionName); |
108 |
} |
109 |
} |
110 |
}; |
111 |
|
112 |
// Add the behavior to each region select list.
|
113 |
$('select.block-region-select', context).once('block-region-select', function () { |
114 |
$(this).change(function (event) { |
115 |
// Make our new row and select field.
|
116 |
var row = $(this).closest('tr'); |
117 |
var select = $(this); |
118 |
tableDrag.rowObject = new tableDrag.row(row);
|
119 |
|
120 |
// Find the correct region and insert the row as the last in the region.
|
121 |
table.find('.region-' + select[0].value + '-message').nextUntil('.region-message').last().before(row); |
122 |
|
123 |
// Modify empty regions with added or removed fields.
|
124 |
checkEmptyRegions(table, row); |
125 |
// Remove focus from selectbox.
|
126 |
select.get(0).blur();
|
127 |
}); |
128 |
}); |
129 |
|
130 |
var checkEmptyRegions = function (table, rowObject) { |
131 |
$('tr.region-message', table).each(function () { |
132 |
// If the dragged row is in this region, but above the message row, swap it down one space.
|
133 |
if ($(this).prev('tr').get(0) == rowObject.element) { |
134 |
// Prevent a recursion problem when using the keyboard to move rows up.
|
135 |
if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) { |
136 |
rowObject.swap('after', this); |
137 |
} |
138 |
} |
139 |
// This region has become empty.
|
140 |
if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').length == 0) { |
141 |
$(this).removeClass('region-populated').addClass('region-empty'); |
142 |
} |
143 |
// This region has become populated.
|
144 |
else if ($(this).is('.region-empty')) { |
145 |
$(this).removeClass('region-empty').addClass('region-populated'); |
146 |
} |
147 |
}); |
148 |
}; |
149 |
} |
150 |
}; |
151 |
|
152 |
})(jQuery); |