Chris@0: /** Chris@0: * DO NOT EDIT THIS FILE. Chris@0: * See the following change record for more information, Chris@0: * https://www.drupal.org/node/2815083 Chris@0: * @preserve Chris@0: **/ Chris@0: Chris@0: (function ($, window, Drupal) { Chris@0: Drupal.behaviors.blockSettingsSummary = { Chris@0: attach: function attach() { Chris@0: if (typeof $.fn.drupalSetSummary === 'undefined') { Chris@0: return; Chris@0: } Chris@0: Chris@0: function checkboxesSummary(context) { Chris@0: var vals = []; Chris@0: var $checkboxes = $(context).find('input[type="checkbox"]:checked + label'); Chris@0: var il = $checkboxes.length; Chris@0: for (var i = 0; i < il; i++) { Chris@0: vals.push($($checkboxes[i]).html()); Chris@0: } Chris@0: if (!vals.length) { Chris@0: vals.push(Drupal.t('Not restricted')); Chris@0: } Chris@0: return vals.join(', '); Chris@0: } Chris@0: Chris@0: $('[data-drupal-selector="edit-visibility-node-type"], [data-drupal-selector="edit-visibility-language"], [data-drupal-selector="edit-visibility-user-role"]').drupalSetSummary(checkboxesSummary); Chris@0: Chris@0: $('[data-drupal-selector="edit-visibility-request-path"]').drupalSetSummary(function (context) { Chris@0: var $pages = $(context).find('textarea[name="visibility[request_path][pages]"]'); Chris@0: if (!$pages.val()) { Chris@0: return Drupal.t('Not restricted'); Chris@0: } Chris@0: Chris@0: return Drupal.t('Restricted to certain pages'); Chris@0: }); Chris@0: } Chris@0: }; Chris@0: Chris@0: Drupal.behaviors.blockDrag = { Chris@0: attach: function attach(context, settings) { Chris@0: if (typeof Drupal.tableDrag === 'undefined' || typeof Drupal.tableDrag.blocks === 'undefined') { Chris@0: return; Chris@0: } Chris@0: Chris@0: function checkEmptyRegions(table, rowObject) { Chris@0: table.find('tr.region-message').each(function () { Chris@0: var $this = $(this); Chris@0: Chris@0: if ($this.prev('tr').get(0) === rowObject.element) { Chris@0: if (rowObject.method !== 'keyboard' || rowObject.direction === 'down') { Chris@0: rowObject.swap('after', this); Chris@0: } Chris@0: } Chris@0: Chris@0: if ($this.next('tr').is(':not(.draggable)') || $this.next('tr').length === 0) { Chris@0: $this.removeClass('region-populated').addClass('region-empty'); Chris@0: } else if ($this.is('.region-empty')) { Chris@0: $this.removeClass('region-empty').addClass('region-populated'); Chris@0: } Chris@0: }); Chris@0: } Chris@0: Chris@0: function updateLastPlaced(table, rowObject) { Chris@0: table.find('.color-success').removeClass('color-success'); Chris@0: Chris@0: var $rowObject = $(rowObject); Chris@0: if (!$rowObject.is('.drag-previous')) { Chris@0: table.find('.drag-previous').removeClass('drag-previous'); Chris@0: $rowObject.addClass('drag-previous'); Chris@0: } Chris@0: } Chris@0: Chris@0: function updateBlockWeights(table, region) { Chris@0: var weight = -Math.round(table.find('.draggable').length / 2); Chris@0: Chris@0: table.find('.region-' + region + '-message').nextUntil('.region-title').find('select.block-weight').val(function () { Chris@0: return ++weight; Chris@0: }); Chris@0: } Chris@0: Chris@0: var table = $('#blocks'); Chris@0: Chris@0: var tableDrag = Drupal.tableDrag.blocks; Chris@0: Chris@0: tableDrag.row.prototype.onSwap = function (swappedRow) { Chris@0: checkEmptyRegions(table, this); Chris@0: updateLastPlaced(table, this); Chris@0: }; Chris@0: Chris@0: tableDrag.onDrop = function () { Chris@0: var dragObject = this; Chris@0: var $rowElement = $(dragObject.rowObject.element); Chris@0: Chris@0: var regionRow = $rowElement.prevAll('tr.region-message').get(0); Chris@0: var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2'); Chris@0: var regionField = $rowElement.find('select.block-region-select'); Chris@0: Chris@0: if (regionField.find('option[value=' + regionName + ']').length === 0) { Chris@0: window.alert(Drupal.t('The block cannot be placed in this region.')); Chris@0: Chris@0: regionField.trigger('change'); Chris@0: } Chris@0: Chris@0: if (!regionField.is('.block-region-' + regionName)) { Chris@0: var weightField = $rowElement.find('select.block-weight'); Chris@0: var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/, '$2'); Chris@0: regionField.removeClass('block-region-' + oldRegionName).addClass('block-region-' + regionName); Chris@0: weightField.removeClass('block-weight-' + oldRegionName).addClass('block-weight-' + regionName); Chris@0: regionField.val(regionName); Chris@0: } Chris@0: Chris@0: updateBlockWeights(table, regionName); Chris@0: }; Chris@0: Chris@0: $(context).find('select.block-region-select').once('block-region-select').on('change', function (event) { Chris@0: var row = $(this).closest('tr'); Chris@0: var select = $(this); Chris@0: Chris@0: tableDrag.rowObject = new tableDrag.row(row[0]); Chris@14: var regionMessage = table.find('.region-' + select[0].value + '-message'); Chris@14: var regionItems = regionMessage.nextUntil('.region-message, .region-title'); Chris@14: if (regionItems.length) { Chris@14: regionItems.last().after(row); Chris@0: } else { Chris@14: regionMessage.after(row); Chris@0: } Chris@0: updateBlockWeights(table, select[0].value); Chris@0: Chris@0: checkEmptyRegions(table, tableDrag.rowObject); Chris@0: Chris@0: updateLastPlaced(table, row); Chris@0: Chris@0: if (!tableDrag.changed) { Chris@0: $(Drupal.theme('tableDragChangedWarning')).insertBefore(tableDrag.table).hide().fadeIn('slow'); Chris@0: tableDrag.changed = true; Chris@0: } Chris@0: Chris@0: select.trigger('blur'); Chris@0: }); Chris@0: } Chris@0: }; Chris@0: })(jQuery, window, Drupal);