Mercurial > hg > isophonics-drupal-site
comparison core/modules/block/js/block.js @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 1fec387a4317 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 /** | |
2 * DO NOT EDIT THIS FILE. | |
3 * See the following change record for more information, | |
4 * https://www.drupal.org/node/2815083 | |
5 * @preserve | |
6 **/ | |
7 | |
8 (function ($, window, Drupal) { | |
9 Drupal.behaviors.blockSettingsSummary = { | |
10 attach: function attach() { | |
11 if (typeof $.fn.drupalSetSummary === 'undefined') { | |
12 return; | |
13 } | |
14 | |
15 function checkboxesSummary(context) { | |
16 var vals = []; | |
17 var $checkboxes = $(context).find('input[type="checkbox"]:checked + label'); | |
18 var il = $checkboxes.length; | |
19 for (var i = 0; i < il; i++) { | |
20 vals.push($($checkboxes[i]).html()); | |
21 } | |
22 if (!vals.length) { | |
23 vals.push(Drupal.t('Not restricted')); | |
24 } | |
25 return vals.join(', '); | |
26 } | |
27 | |
28 $('[data-drupal-selector="edit-visibility-node-type"], [data-drupal-selector="edit-visibility-language"], [data-drupal-selector="edit-visibility-user-role"]').drupalSetSummary(checkboxesSummary); | |
29 | |
30 $('[data-drupal-selector="edit-visibility-request-path"]').drupalSetSummary(function (context) { | |
31 var $pages = $(context).find('textarea[name="visibility[request_path][pages]"]'); | |
32 if (!$pages.val()) { | |
33 return Drupal.t('Not restricted'); | |
34 } | |
35 | |
36 return Drupal.t('Restricted to certain pages'); | |
37 }); | |
38 } | |
39 }; | |
40 | |
41 Drupal.behaviors.blockDrag = { | |
42 attach: function attach(context, settings) { | |
43 if (typeof Drupal.tableDrag === 'undefined' || typeof Drupal.tableDrag.blocks === 'undefined') { | |
44 return; | |
45 } | |
46 | |
47 function checkEmptyRegions(table, rowObject) { | |
48 table.find('tr.region-message').each(function () { | |
49 var $this = $(this); | |
50 | |
51 if ($this.prev('tr').get(0) === rowObject.element) { | |
52 if (rowObject.method !== 'keyboard' || rowObject.direction === 'down') { | |
53 rowObject.swap('after', this); | |
54 } | |
55 } | |
56 | |
57 if ($this.next('tr').is(':not(.draggable)') || $this.next('tr').length === 0) { | |
58 $this.removeClass('region-populated').addClass('region-empty'); | |
59 } else if ($this.is('.region-empty')) { | |
60 $this.removeClass('region-empty').addClass('region-populated'); | |
61 } | |
62 }); | |
63 } | |
64 | |
65 function updateLastPlaced(table, rowObject) { | |
66 table.find('.color-success').removeClass('color-success'); | |
67 | |
68 var $rowObject = $(rowObject); | |
69 if (!$rowObject.is('.drag-previous')) { | |
70 table.find('.drag-previous').removeClass('drag-previous'); | |
71 $rowObject.addClass('drag-previous'); | |
72 } | |
73 } | |
74 | |
75 function updateBlockWeights(table, region) { | |
76 var weight = -Math.round(table.find('.draggable').length / 2); | |
77 | |
78 table.find('.region-' + region + '-message').nextUntil('.region-title').find('select.block-weight').val(function () { | |
79 return ++weight; | |
80 }); | |
81 } | |
82 | |
83 var table = $('#blocks'); | |
84 | |
85 var tableDrag = Drupal.tableDrag.blocks; | |
86 | |
87 tableDrag.row.prototype.onSwap = function (swappedRow) { | |
88 checkEmptyRegions(table, this); | |
89 updateLastPlaced(table, this); | |
90 }; | |
91 | |
92 tableDrag.onDrop = function () { | |
93 var dragObject = this; | |
94 var $rowElement = $(dragObject.rowObject.element); | |
95 | |
96 var regionRow = $rowElement.prevAll('tr.region-message').get(0); | |
97 var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2'); | |
98 var regionField = $rowElement.find('select.block-region-select'); | |
99 | |
100 if (regionField.find('option[value=' + regionName + ']').length === 0) { | |
101 window.alert(Drupal.t('The block cannot be placed in this region.')); | |
102 | |
103 regionField.trigger('change'); | |
104 } | |
105 | |
106 if (!regionField.is('.block-region-' + regionName)) { | |
107 var weightField = $rowElement.find('select.block-weight'); | |
108 var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/, '$2'); | |
109 regionField.removeClass('block-region-' + oldRegionName).addClass('block-region-' + regionName); | |
110 weightField.removeClass('block-weight-' + oldRegionName).addClass('block-weight-' + regionName); | |
111 regionField.val(regionName); | |
112 } | |
113 | |
114 updateBlockWeights(table, regionName); | |
115 }; | |
116 | |
117 $(context).find('select.block-region-select').once('block-region-select').on('change', function (event) { | |
118 var row = $(this).closest('tr'); | |
119 var select = $(this); | |
120 | |
121 tableDrag.rowObject = new tableDrag.row(row[0]); | |
122 var region_message = table.find('.region-' + select[0].value + '-message'); | |
123 var region_items = region_message.nextUntil('.region-message, .region-title'); | |
124 if (region_items.length) { | |
125 region_items.last().after(row); | |
126 } else { | |
127 region_message.after(row); | |
128 } | |
129 updateBlockWeights(table, select[0].value); | |
130 | |
131 checkEmptyRegions(table, tableDrag.rowObject); | |
132 | |
133 updateLastPlaced(table, row); | |
134 | |
135 if (!tableDrag.changed) { | |
136 $(Drupal.theme('tableDragChangedWarning')).insertBefore(tableDrag.table).hide().fadeIn('slow'); | |
137 tableDrag.changed = true; | |
138 } | |
139 | |
140 select.trigger('blur'); | |
141 }); | |
142 } | |
143 }; | |
144 })(jQuery, window, Drupal); |