Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
117
web/core/modules/block/js/block.admin.es6.js
Normal file
117
web/core/modules/block/js/block.admin.es6.js
Normal file
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
* @file
|
||||
* Block admin behaviors.
|
||||
*/
|
||||
|
||||
(function($, Drupal, debounce) {
|
||||
/**
|
||||
* Filters the block list by a text input search string.
|
||||
*
|
||||
* The text input will have the selector `input.block-filter-text`.
|
||||
*
|
||||
* The target element to do searching in will be in the selector
|
||||
* `input.block-filter-text[data-element]`
|
||||
*
|
||||
* The text source where the text should be found will have the selector
|
||||
* `.block-filter-text-source`
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the behavior for the block filtering.
|
||||
*/
|
||||
Drupal.behaviors.blockFilterByText = {
|
||||
attach(context, settings) {
|
||||
const $input = $('input.block-filter-text').once('block-filter-text');
|
||||
const $table = $($input.attr('data-element'));
|
||||
let $filterRows;
|
||||
|
||||
/**
|
||||
* Filters the block list.
|
||||
*
|
||||
* @param {jQuery.Event} e
|
||||
* The jQuery event for the keyup event that triggered the filter.
|
||||
*/
|
||||
function filterBlockList(e) {
|
||||
const query = $(e.target)
|
||||
.val()
|
||||
.toLowerCase();
|
||||
|
||||
/**
|
||||
* Shows or hides the block entry based on the query.
|
||||
*
|
||||
* @param {number} index
|
||||
* The index in the loop, as provided by `jQuery.each`
|
||||
* @param {HTMLElement} label
|
||||
* The label of the block.
|
||||
*/
|
||||
function toggleBlockEntry(index, label) {
|
||||
const $label = $(label);
|
||||
const $row = $label.parent().parent();
|
||||
const textMatch =
|
||||
$label
|
||||
.text()
|
||||
.toLowerCase()
|
||||
.indexOf(query) !== -1;
|
||||
$row.toggle(textMatch);
|
||||
}
|
||||
|
||||
// Filter if the length of the query is at least 2 characters.
|
||||
if (query.length >= 2) {
|
||||
$filterRows.each(toggleBlockEntry);
|
||||
Drupal.announce(
|
||||
Drupal.formatPlural(
|
||||
$table.find('tr:visible').length - 1,
|
||||
'1 block is available in the modified list.',
|
||||
'@count blocks are available in the modified list.',
|
||||
),
|
||||
);
|
||||
} else {
|
||||
$filterRows.each(function(index) {
|
||||
$(this)
|
||||
.parent()
|
||||
.parent()
|
||||
.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if ($table.length) {
|
||||
$filterRows = $table.find('div.block-filter-text-source');
|
||||
$input.on('keyup', debounce(filterBlockList, 200));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Highlights the block that was just placed into the block listing.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the behavior for the block placement highlighting.
|
||||
*/
|
||||
Drupal.behaviors.blockHighlightPlacement = {
|
||||
attach(context, settings) {
|
||||
if (settings.blockPlacement) {
|
||||
$(context)
|
||||
.find('[data-drupal-selector="edit-blocks"]')
|
||||
.once('block-highlight')
|
||||
.each(function() {
|
||||
const $container = $(this);
|
||||
// Just scrolling the document.body will not work in Firefox. The html
|
||||
// element is needed as well.
|
||||
$('html, body').animate(
|
||||
{
|
||||
scrollTop:
|
||||
$('.js-block-placed').offset().top -
|
||||
$container.offset().top +
|
||||
$container.scrollTop(),
|
||||
},
|
||||
500,
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
})(jQuery, Drupal, Drupal.debounce);
|
|
@ -1,51 +1,20 @@
|
|||
/**
|
||||
* @file
|
||||
* Block admin behaviors.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Filters the block list by a text input search string.
|
||||
*
|
||||
* The text input will have the selector `input.block-filter-text`.
|
||||
*
|
||||
* The target element to do searching in will be in the selector
|
||||
* `input.block-filter-text[data-element]`
|
||||
*
|
||||
* The text source where the text should be found will have the selector
|
||||
* `.block-filter-text-source`
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the behavior for the block filtering.
|
||||
*/
|
||||
(function ($, Drupal, debounce) {
|
||||
Drupal.behaviors.blockFilterByText = {
|
||||
attach: function (context, settings) {
|
||||
attach: function attach(context, settings) {
|
||||
var $input = $('input.block-filter-text').once('block-filter-text');
|
||||
var $table = $($input.attr('data-element'));
|
||||
var $filter_rows;
|
||||
var $filterRows = void 0;
|
||||
|
||||
/**
|
||||
* Filters the block list.
|
||||
*
|
||||
* @param {jQuery.Event} e
|
||||
* The jQuery event for the keyup event that triggered the filter.
|
||||
*/
|
||||
function filterBlockList(e) {
|
||||
var query = $(e.target).val().toLowerCase();
|
||||
|
||||
/**
|
||||
* Shows or hides the block entry based on the query.
|
||||
*
|
||||
* @param {number} index
|
||||
* The index in the loop, as provided by `jQuery.each`
|
||||
* @param {HTMLElement} label
|
||||
* The label of the block.
|
||||
*/
|
||||
function toggleBlockEntry(index, label) {
|
||||
var $label = $(label);
|
||||
var $row = $label.parent().parent();
|
||||
|
@ -53,39 +22,29 @@
|
|||
$row.toggle(textMatch);
|
||||
}
|
||||
|
||||
// Filter if the length of the query is at least 2 characters.
|
||||
if (query.length >= 2) {
|
||||
$filter_rows.each(toggleBlockEntry);
|
||||
}
|
||||
else {
|
||||
$filter_rows.each(function (index) {
|
||||
$filterRows.each(toggleBlockEntry);
|
||||
Drupal.announce(Drupal.formatPlural($table.find('tr:visible').length - 1, '1 block is available in the modified list.', '@count blocks are available in the modified list.'));
|
||||
} else {
|
||||
$filterRows.each(function (index) {
|
||||
$(this).parent().parent().show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if ($table.length) {
|
||||
$filter_rows = $table.find('div.block-filter-text-source');
|
||||
$input.on('keyup', filterBlockList);
|
||||
$filterRows = $table.find('div.block-filter-text-source');
|
||||
$input.on('keyup', debounce(filterBlockList, 200));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Highlights the block that was just placed into the block listing.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the behavior for the block placement highlighting.
|
||||
*/
|
||||
Drupal.behaviors.blockHighlightPlacement = {
|
||||
attach: function (context, settings) {
|
||||
attach: function attach(context, settings) {
|
||||
if (settings.blockPlacement) {
|
||||
$(context).find('[data-drupal-selector="edit-blocks"]').once('block-highlight').each(function () {
|
||||
var $container = $(this);
|
||||
// Just scrolling the document.body will not work in Firefox. The html
|
||||
// element is needed as well.
|
||||
|
||||
$('html, body').animate({
|
||||
scrollTop: $('.js-block-placed').offset().top - $container.offset().top + $container.scrollTop()
|
||||
}, 500);
|
||||
|
@ -93,5 +52,4 @@
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
}(jQuery, Drupal));
|
||||
})(jQuery, Drupal, Drupal.debounce);
|
262
web/core/modules/block/js/block.es6.js
Normal file
262
web/core/modules/block/js/block.es6.js
Normal file
|
@ -0,0 +1,262 @@
|
|||
/**
|
||||
* @file
|
||||
* Block behaviors.
|
||||
*/
|
||||
|
||||
(function($, window, Drupal) {
|
||||
/**
|
||||
* Provide the summary information for the block settings vertical tabs.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the behavior for the block settings summaries.
|
||||
*/
|
||||
Drupal.behaviors.blockSettingsSummary = {
|
||||
attach() {
|
||||
// The drupalSetSummary method required for this behavior is not available
|
||||
// on the Blocks administration page, so we need to make sure this
|
||||
// behavior is processed only if drupalSetSummary is defined.
|
||||
if (typeof $.fn.drupalSetSummary === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a summary for checkboxes in the provided context.
|
||||
*
|
||||
* @param {HTMLDocument|HTMLElement} context
|
||||
* A context where one would find checkboxes to summarize.
|
||||
*
|
||||
* @return {string}
|
||||
* A string with the summary.
|
||||
*/
|
||||
function checkboxesSummary(context) {
|
||||
const vals = [];
|
||||
const $checkboxes = $(context).find(
|
||||
'input[type="checkbox"]:checked + label',
|
||||
);
|
||||
const il = $checkboxes.length;
|
||||
for (let i = 0; i < il; i++) {
|
||||
vals.push($($checkboxes[i]).html());
|
||||
}
|
||||
if (!vals.length) {
|
||||
vals.push(Drupal.t('Not restricted'));
|
||||
}
|
||||
return vals.join(', ');
|
||||
}
|
||||
|
||||
$(
|
||||
'[data-drupal-selector="edit-visibility-node-type"], [data-drupal-selector="edit-visibility-language"], [data-drupal-selector="edit-visibility-user-role"]',
|
||||
).drupalSetSummary(checkboxesSummary);
|
||||
|
||||
$(
|
||||
'[data-drupal-selector="edit-visibility-request-path"]',
|
||||
).drupalSetSummary(context => {
|
||||
const $pages = $(context).find(
|
||||
'textarea[name="visibility[request_path][pages]"]',
|
||||
);
|
||||
if (!$pages.val()) {
|
||||
return Drupal.t('Not restricted');
|
||||
}
|
||||
|
||||
return Drupal.t('Restricted to certain pages');
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Move a block in the blocks table between regions via select list.
|
||||
*
|
||||
* This behavior is dependent on the tableDrag behavior, since it uses the
|
||||
* objects initialized in that behavior to update the row.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the tableDrag behaviour for blocks in block administration.
|
||||
*/
|
||||
Drupal.behaviors.blockDrag = {
|
||||
attach(context, settings) {
|
||||
// tableDrag is required and we should be on the blocks admin page.
|
||||
if (
|
||||
typeof Drupal.tableDrag === 'undefined' ||
|
||||
typeof Drupal.tableDrag.blocks === 'undefined'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check empty regions and toggle classes based on this.
|
||||
*
|
||||
* @param {jQuery} table
|
||||
* The jQuery object representing the table to inspect.
|
||||
* @param {jQuery} rowObject
|
||||
* The jQuery object representing the table row.
|
||||
*/
|
||||
function checkEmptyRegions(table, rowObject) {
|
||||
table.find('tr.region-message').each(function() {
|
||||
const $this = $(this);
|
||||
// If the dragged row is in this region, but above the message row,
|
||||
// swap it down one space.
|
||||
if ($this.prev('tr').get(0) === rowObject.element) {
|
||||
// Prevent a recursion problem when using the keyboard to move rows
|
||||
// up.
|
||||
if (
|
||||
rowObject.method !== 'keyboard' ||
|
||||
rowObject.direction === 'down'
|
||||
) {
|
||||
rowObject.swap('after', this);
|
||||
}
|
||||
}
|
||||
// This region has become empty.
|
||||
if (
|
||||
$this.next('tr').is(':not(.draggable)') ||
|
||||
$this.next('tr').length === 0
|
||||
) {
|
||||
$this.removeClass('region-populated').addClass('region-empty');
|
||||
}
|
||||
// This region has become populated.
|
||||
else if ($this.is('.region-empty')) {
|
||||
$this.removeClass('region-empty').addClass('region-populated');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to update the last placed row with the correct classes.
|
||||
*
|
||||
* @param {jQuery} table
|
||||
* The jQuery object representing the table to inspect.
|
||||
* @param {jQuery} rowObject
|
||||
* The jQuery object representing the table row.
|
||||
*/
|
||||
function updateLastPlaced(table, rowObject) {
|
||||
// Remove the color-success class from new block if applicable.
|
||||
table.find('.color-success').removeClass('color-success');
|
||||
|
||||
const $rowObject = $(rowObject);
|
||||
if (!$rowObject.is('.drag-previous')) {
|
||||
table.find('.drag-previous').removeClass('drag-previous');
|
||||
$rowObject.addClass('drag-previous');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update block weights in the given region.
|
||||
*
|
||||
* @param {jQuery} table
|
||||
* Table with draggable items.
|
||||
* @param {string} region
|
||||
* Machine name of region containing blocks to update.
|
||||
*/
|
||||
function updateBlockWeights(table, region) {
|
||||
// Calculate minimum weight.
|
||||
let weight = -Math.round(table.find('.draggable').length / 2);
|
||||
// Update the block weights.
|
||||
table
|
||||
.find(`.region-${region}-message`)
|
||||
.nextUntil('.region-title')
|
||||
.find('select.block-weight')
|
||||
.val(
|
||||
// Increment the weight before assigning it to prevent using the
|
||||
// absolute minimum available weight. This way we always have an
|
||||
// unused upper and lower bound, which makes manually setting the
|
||||
// weights easier for users who prefer to do it that way.
|
||||
() => ++weight,
|
||||
);
|
||||
}
|
||||
|
||||
const table = $('#blocks');
|
||||
// Get the blocks tableDrag object.
|
||||
const tableDrag = Drupal.tableDrag.blocks;
|
||||
// Add a handler for when a row is swapped, update empty regions.
|
||||
tableDrag.row.prototype.onSwap = function(swappedRow) {
|
||||
checkEmptyRegions(table, this);
|
||||
updateLastPlaced(table, this);
|
||||
};
|
||||
|
||||
// Add a handler so when a row is dropped, update fields dropped into
|
||||
// new regions.
|
||||
tableDrag.onDrop = function() {
|
||||
const dragObject = this;
|
||||
const $rowElement = $(dragObject.rowObject.element);
|
||||
// Use "region-message" row instead of "region" row because
|
||||
// "region-{region_name}-message" is less prone to regexp match errors.
|
||||
const regionRow = $rowElement.prevAll('tr.region-message').get(0);
|
||||
const regionName = regionRow.className.replace(
|
||||
/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/,
|
||||
'$2',
|
||||
);
|
||||
const regionField = $rowElement.find('select.block-region-select');
|
||||
// Check whether the newly picked region is available for this block.
|
||||
if (regionField.find(`option[value=${regionName}]`).length === 0) {
|
||||
// If not, alert the user and keep the block in its old region
|
||||
// setting.
|
||||
window.alert(Drupal.t('The block cannot be placed in this region.'));
|
||||
// Simulate that there was a selected element change, so the row is
|
||||
// put back to from where the user tried to drag it.
|
||||
regionField.trigger('change');
|
||||
}
|
||||
|
||||
// Update region and weight fields if the region has been changed.
|
||||
if (!regionField.is(`.block-region-${regionName}`)) {
|
||||
const weightField = $rowElement.find('select.block-weight');
|
||||
const oldRegionName = weightField[0].className.replace(
|
||||
/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/,
|
||||
'$2',
|
||||
);
|
||||
regionField
|
||||
.removeClass(`block-region-${oldRegionName}`)
|
||||
.addClass(`block-region-${regionName}`);
|
||||
weightField
|
||||
.removeClass(`block-weight-${oldRegionName}`)
|
||||
.addClass(`block-weight-${regionName}`);
|
||||
regionField.val(regionName);
|
||||
}
|
||||
|
||||
updateBlockWeights(table, regionName);
|
||||
};
|
||||
|
||||
// Add the behavior to each region select list.
|
||||
$(context)
|
||||
.find('select.block-region-select')
|
||||
.once('block-region-select')
|
||||
.on('change', function(event) {
|
||||
// Make our new row and select field.
|
||||
const row = $(this).closest('tr');
|
||||
const select = $(this);
|
||||
// Find the correct region and insert the row as the last in the
|
||||
// region.
|
||||
tableDrag.rowObject = new tableDrag.row(row[0]);
|
||||
const regionMessage = table.find(
|
||||
`.region-${select[0].value}-message`,
|
||||
);
|
||||
const regionItems = regionMessage.nextUntil(
|
||||
'.region-message, .region-title',
|
||||
);
|
||||
if (regionItems.length) {
|
||||
regionItems.last().after(row);
|
||||
}
|
||||
// We found that regionMessage is the last row.
|
||||
else {
|
||||
regionMessage.after(row);
|
||||
}
|
||||
updateBlockWeights(table, select[0].value);
|
||||
// Modify empty regions with added or removed fields.
|
||||
checkEmptyRegions(table, tableDrag.rowObject);
|
||||
// Update last placed block indication.
|
||||
updateLastPlaced(table, row);
|
||||
// Show unsaved changes warning.
|
||||
if (!tableDrag.changed) {
|
||||
$(Drupal.theme('tableDragChangedWarning'))
|
||||
.insertBefore(tableDrag.table)
|
||||
.hide()
|
||||
.fadeIn('slow');
|
||||
tableDrag.changed = true;
|
||||
}
|
||||
// Remove focus from selectbox.
|
||||
select.trigger('blur');
|
||||
});
|
||||
},
|
||||
};
|
||||
})(jQuery, window, Drupal);
|
|
@ -1,38 +1,17 @@
|
|||
/**
|
||||
* @file
|
||||
* Block behaviors.
|
||||
*/
|
||||
* DO NOT EDIT THIS FILE.
|
||||
* See the following change record for more information,
|
||||
* https://www.drupal.org/node/2815083
|
||||
* @preserve
|
||||
**/
|
||||
|
||||
(function ($, window, Drupal) {
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Provide the summary information for the block settings vertical tabs.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the behavior for the block settings summaries.
|
||||
*/
|
||||
Drupal.behaviors.blockSettingsSummary = {
|
||||
attach: function () {
|
||||
// The drupalSetSummary method required for this behavior is not available
|
||||
// on the Blocks administration page, so we need to make sure this
|
||||
// behavior is processed only if drupalSetSummary is defined.
|
||||
attach: function attach() {
|
||||
if (typeof $.fn.drupalSetSummary === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a summary for checkboxes in the provided context.
|
||||
*
|
||||
* @param {HTMLDocument|HTMLElement} context
|
||||
* A context where one would find checkboxes to summarize.
|
||||
*
|
||||
* @return {string}
|
||||
* A string with the summary.
|
||||
*/
|
||||
function checkboxesSummary(context) {
|
||||
var vals = [];
|
||||
var $checkboxes = $(context).find('input[type="checkbox"]:checked + label');
|
||||
|
@ -53,72 +32,37 @@
|
|||
if (!$pages.val()) {
|
||||
return Drupal.t('Not restricted');
|
||||
}
|
||||
else {
|
||||
return Drupal.t('Restricted to certain pages');
|
||||
}
|
||||
|
||||
return Drupal.t('Restricted to certain pages');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Move a block in the blocks table between regions via select list.
|
||||
*
|
||||
* This behavior is dependent on the tableDrag behavior, since it uses the
|
||||
* objects initialized in that behavior to update the row.
|
||||
*
|
||||
* @type {Drupal~behavior}
|
||||
*
|
||||
* @prop {Drupal~behaviorAttach} attach
|
||||
* Attaches the tableDrag behaviour for blocks in block administration.
|
||||
*/
|
||||
Drupal.behaviors.blockDrag = {
|
||||
attach: function (context, settings) {
|
||||
// tableDrag is required and we should be on the blocks admin page.
|
||||
attach: function attach(context, settings) {
|
||||
if (typeof Drupal.tableDrag === 'undefined' || typeof Drupal.tableDrag.blocks === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to check empty regions and toggle classes based on this.
|
||||
*
|
||||
* @param {jQuery} table
|
||||
* The jQuery object representing the table to inspect.
|
||||
* @param {jQuery} rowObject
|
||||
* The jQuery object representing the table row.
|
||||
*/
|
||||
function checkEmptyRegions(table, rowObject) {
|
||||
table.find('tr.region-message').each(function () {
|
||||
var $this = $(this);
|
||||
// If the dragged row is in this region, but above the message row,
|
||||
// swap it down one space.
|
||||
|
||||
if ($this.prev('tr').get(0) === rowObject.element) {
|
||||
// Prevent a recursion problem when using the keyboard to move rows
|
||||
// up.
|
||||
if ((rowObject.method !== 'keyboard' || rowObject.direction === 'down')) {
|
||||
if (rowObject.method !== 'keyboard' || rowObject.direction === 'down') {
|
||||
rowObject.swap('after', this);
|
||||
}
|
||||
}
|
||||
// This region has become empty.
|
||||
|
||||
if ($this.next('tr').is(':not(.draggable)') || $this.next('tr').length === 0) {
|
||||
$this.removeClass('region-populated').addClass('region-empty');
|
||||
}
|
||||
// This region has become populated.
|
||||
else if ($this.is('.region-empty')) {
|
||||
$this.removeClass('region-empty').addClass('region-populated');
|
||||
}
|
||||
} else if ($this.is('.region-empty')) {
|
||||
$this.removeClass('region-empty').addClass('region-populated');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to update the last placed row with the correct classes.
|
||||
*
|
||||
* @param {jQuery} table
|
||||
* The jQuery object representing the table to inspect.
|
||||
* @param {jQuery} rowObject
|
||||
* The jQuery object representing the table row.
|
||||
*/
|
||||
function updateLastPlaced(table, rowObject) {
|
||||
// Remove the color-success class from new block if applicable.
|
||||
table.find('.color-success').removeClass('color-success');
|
||||
|
||||
var $rowObject = $(rowObject);
|
||||
|
@ -128,58 +72,37 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update block weights in the given region.
|
||||
*
|
||||
* @param {jQuery} table
|
||||
* Table with draggable items.
|
||||
* @param {string} region
|
||||
* Machine name of region containing blocks to update.
|
||||
*/
|
||||
function updateBlockWeights(table, region) {
|
||||
// Calculate minimum weight.
|
||||
var weight = -Math.round(table.find('.draggable').length / 2);
|
||||
// Update the block weights.
|
||||
table.find('.region-' + region + '-message').nextUntil('.region-title')
|
||||
.find('select.block-weight').val(function () {
|
||||
// Increment the weight before assigning it to prevent using the
|
||||
// absolute minimum available weight. This way we always have an
|
||||
// unused upper and lower bound, which makes manually setting the
|
||||
// weights easier for users who prefer to do it that way.
|
||||
return ++weight;
|
||||
});
|
||||
|
||||
table.find('.region-' + region + '-message').nextUntil('.region-title').find('select.block-weight').val(function () {
|
||||
return ++weight;
|
||||
});
|
||||
}
|
||||
|
||||
var table = $('#blocks');
|
||||
// Get the blocks tableDrag object.
|
||||
|
||||
var tableDrag = Drupal.tableDrag.blocks;
|
||||
// Add a handler for when a row is swapped, update empty regions.
|
||||
|
||||
tableDrag.row.prototype.onSwap = function (swappedRow) {
|
||||
checkEmptyRegions(table, this);
|
||||
updateLastPlaced(table, this);
|
||||
};
|
||||
|
||||
// Add a handler so when a row is dropped, update fields dropped into
|
||||
// new regions.
|
||||
tableDrag.onDrop = function () {
|
||||
var dragObject = this;
|
||||
var $rowElement = $(dragObject.rowObject.element);
|
||||
// Use "region-message" row instead of "region" row because
|
||||
// "region-{region_name}-message" is less prone to regexp match errors.
|
||||
|
||||
var regionRow = $rowElement.prevAll('tr.region-message').get(0);
|
||||
var regionName = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
|
||||
var regionField = $rowElement.find('select.block-region-select');
|
||||
// Check whether the newly picked region is available for this block.
|
||||
|
||||
if (regionField.find('option[value=' + regionName + ']').length === 0) {
|
||||
// If not, alert the user and keep the block in its old region
|
||||
// setting.
|
||||
window.alert(Drupal.t('The block cannot be placed in this region.'));
|
||||
// Simulate that there was a selected element change, so the row is
|
||||
// put back to from where the user tried to drag it.
|
||||
|
||||
regionField.trigger('change');
|
||||
}
|
||||
|
||||
// Update region and weight fields if the region has been changed.
|
||||
if (!regionField.is('.block-region-' + regionName)) {
|
||||
var weightField = $rowElement.find('select.block-weight');
|
||||
var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
|
||||
|
@ -191,38 +114,31 @@
|
|||
updateBlockWeights(table, regionName);
|
||||
};
|
||||
|
||||
// Add the behavior to each region select list.
|
||||
$(context).find('select.block-region-select').once('block-region-select')
|
||||
.on('change', function (event) {
|
||||
// Make our new row and select field.
|
||||
var row = $(this).closest('tr');
|
||||
var select = $(this);
|
||||
// Find the correct region and insert the row as the last in the
|
||||
// region.
|
||||
tableDrag.rowObject = new tableDrag.row(row[0]);
|
||||
var region_message = table.find('.region-' + select[0].value + '-message');
|
||||
var region_items = region_message.nextUntil('.region-message, .region-title');
|
||||
if (region_items.length) {
|
||||
region_items.last().after(row);
|
||||
$(context).find('select.block-region-select').once('block-region-select').on('change', function (event) {
|
||||
var row = $(this).closest('tr');
|
||||
var select = $(this);
|
||||
|
||||
tableDrag.rowObject = new tableDrag.row(row[0]);
|
||||
var regionMessage = table.find('.region-' + select[0].value + '-message');
|
||||
var regionItems = regionMessage.nextUntil('.region-message, .region-title');
|
||||
if (regionItems.length) {
|
||||
regionItems.last().after(row);
|
||||
} else {
|
||||
regionMessage.after(row);
|
||||
}
|
||||
// We found that region_message is the last row.
|
||||
else {
|
||||
region_message.after(row);
|
||||
}
|
||||
updateBlockWeights(table, select[0].value);
|
||||
// Modify empty regions with added or removed fields.
|
||||
checkEmptyRegions(table, tableDrag.rowObject);
|
||||
// Update last placed block indication.
|
||||
updateLastPlaced(table, row);
|
||||
// Show unsaved changes warning.
|
||||
if (!tableDrag.changed) {
|
||||
$(Drupal.theme('tableDragChangedWarning')).insertBefore(tableDrag.table).hide().fadeIn('slow');
|
||||
tableDrag.changed = true;
|
||||
}
|
||||
// Remove focus from selectbox.
|
||||
select.trigger('blur');
|
||||
});
|
||||
updateBlockWeights(table, select[0].value);
|
||||
|
||||
checkEmptyRegions(table, tableDrag.rowObject);
|
||||
|
||||
updateLastPlaced(table, row);
|
||||
|
||||
if (!tableDrag.changed) {
|
||||
$(Drupal.theme('tableDragChangedWarning')).insertBefore(tableDrag.table).hide().fadeIn('slow');
|
||||
tableDrag.changed = true;
|
||||
}
|
||||
|
||||
select.trigger('blur');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery, window, Drupal);
|
||||
})(jQuery, window, Drupal);
|
Reference in a new issue