From 0c660d8477247ee0a469f616d25ebee7f9716ca7 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Tue, 12 Jun 2012 10:39:50 +0900 Subject: [PATCH] Issue #1574512 by nod_: Selectors clean-up: block. --- core/modules/block/block.js | 56 +++++++++++++------------------------ 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/core/modules/block/block.js b/core/modules/block/block.js index e20001714e52..ba433a5ffd6e 100644 --- a/core/modules/block/block.js +++ b/core/modules/block/block.js @@ -6,7 +6,7 @@ * Provide the summary information for the block settings vertical tabs. */ Drupal.behaviors.blockSettingsSummary = { - attach: function (context) { + 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. @@ -14,51 +14,33 @@ Drupal.behaviors.blockSettingsSummary = { return; } - var $context = $(context); - $context.find('fieldset#edit-path').drupalSetSummary(function (context) { - if (!$(context).find('textarea[name="pages"]').val()) { - return Drupal.t('Not restricted'); - } - else { - return Drupal.t('Restricted to certain pages'); - } - }); - - $context.find('fieldset#edit-node-type').drupalSetSummary(function (context) { + function checkboxesSummary (context) { var vals = []; - $(context).find('input[type="checkbox"]:checked').each(function () { - vals.push($.trim($(this).next('label').text())); - }); - if (!vals.length) { - vals.push(Drupal.t('Not restricted')); + var $checkboxes = $(context).find('input[type="checkbox"]:checked + label'); + for (var i = 0, il = $checkboxes.length; i < il; i += 1) { + vals.push($($checkboxes[i]).text()); } - return vals.join(', '); - }); - - $context.find('fieldset#edit-language').drupalSetSummary(function (context) { - var vals = []; - $(context).find('input[type="checkbox"]:checked').each(function () { - vals.push($.trim($(this).next('label').text())); - }); if (!vals.length) { vals.push(Drupal.t('Not restricted')); } - return vals.join(', '); - }); + return $.map(vals, $.trim).join(', '); + } + $('#edit-node-type').drupalSetSummary(checkboxesSummary); + $('#edit-language').drupalSetSummary(checkboxesSummary); + $('#edit-role').drupalSetSummary(checkboxesSummary); - $context.find('fieldset#edit-role').drupalSetSummary(function (context) { - var vals = []; - $(context).find('input[type="checkbox"]:checked').each(function () { - vals.push($.trim($(this).next('label').text())); - }); - if (!vals.length) { - vals.push(Drupal.t('Not restricted')); + $('#edit-path').drupalSetSummary(function (context) { + var $pages = $(context).find('textarea[name="pages"]'); + if (!$pages.val()) { + return Drupal.t('Not restricted'); + } + else { + return Drupal.t('Restricted to certain pages'); } - return vals.join(', '); }); - $context.find('fieldset#edit-user').drupalSetSummary(function (context) { + $('#edit-user').drupalSetSummary(function (context) { var $radio = $(context).find('input[name="custom"]:checked'); if ($radio.val() == 0) { return Drupal.t('Not customizable'); @@ -83,7 +65,7 @@ Drupal.behaviors.blockDrag = { return; } - var table = $('table#blocks'); + var table = $('#blocks'); var tableDrag = Drupal.tableDrag.blocks; // Get the blocks tableDrag object. // Add a handler for when a row is swapped, update empty regions. -- GitLab