2015-08-18 00:00:26 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Block admin behaviors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function ($, Drupal) {
|
|
|
|
|
2015-10-22 04:44:50 +00:00
|
|
|
'use strict';
|
2015-08-18 00:00:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters the block list by a text input search string.
|
|
|
|
*
|
2015-09-04 20:20:09 +00:00
|
|
|
* 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`
|
2015-08-18 00:00:26 +00:00
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
2015-09-04 20:20:09 +00:00
|
|
|
*
|
|
|
|
* @prop {Drupal~behaviorAttach} attach
|
|
|
|
* Attaches the behavior for the block filtering.
|
2015-08-18 00:00:26 +00:00
|
|
|
*/
|
|
|
|
Drupal.behaviors.blockFilterByText = {
|
|
|
|
attach: function (context, settings) {
|
|
|
|
var $input = $('input.block-filter-text').once('block-filter-text');
|
2015-08-27 19:03:05 +00:00
|
|
|
var $table = $($input.attr('data-element'));
|
|
|
|
var $filter_rows;
|
2015-08-18 00:00:26 +00:00
|
|
|
|
2015-09-04 20:20:09 +00:00
|
|
|
/**
|
|
|
|
* Filters the block list.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e
|
|
|
|
* The jQuery event for the keyup event that triggered the filter.
|
|
|
|
*/
|
2015-08-18 00:00:26 +00:00
|
|
|
function filterBlockList(e) {
|
|
|
|
var query = $(e.target).val().toLowerCase();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows or hides the block entry based on the query.
|
|
|
|
*
|
2015-09-04 20:20:09 +00:00
|
|
|
* @param {number} index
|
|
|
|
* The index in the loop, as provided by `jQuery.each`
|
|
|
|
* @param {HTMLElement} label
|
|
|
|
* The label of the block.
|
2015-08-18 00:00:26 +00:00
|
|
|
*/
|
2015-08-27 19:03:05 +00:00
|
|
|
function toggleBlockEntry(index, label) {
|
|
|
|
var $label = $(label);
|
|
|
|
var $row = $label.parent().parent();
|
|
|
|
var textMatch = $label.text().toLowerCase().indexOf(query) !== -1;
|
|
|
|
$row.toggle(textMatch);
|
2015-08-18 00:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Filter if the length of the query is at least 2 characters.
|
|
|
|
if (query.length >= 2) {
|
2015-08-27 19:03:05 +00:00
|
|
|
$filter_rows.each(toggleBlockEntry);
|
2015-08-18 00:00:26 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-08-27 19:03:05 +00:00
|
|
|
$filter_rows.each(function (index) {
|
|
|
|
$(this).parent().parent().show();
|
|
|
|
});
|
2015-08-18 00:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-27 19:03:05 +00:00
|
|
|
if ($table.length) {
|
|
|
|
$filter_rows = $table.find('div.block-filter-text-source');
|
2015-08-18 00:00:26 +00:00
|
|
|
$input.on('keyup', filterBlockList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Highlights the block that was just placed into the block listing.
|
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
2015-09-04 20:20:09 +00:00
|
|
|
*
|
|
|
|
* @prop {Drupal~behaviorAttach} attach
|
|
|
|
* Attaches the behavior for the block placement highlighting.
|
2015-08-18 00:00:26 +00:00
|
|
|
*/
|
|
|
|
Drupal.behaviors.blockHighlightPlacement = {
|
|
|
|
attach: function (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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}(jQuery, Drupal));
|