From 4e71065321723ace41ca0727fdb1a0c775895076 Mon Sep 17 00:00:00 2001
From: Dries <dries@buytaert.net>
Date: Thu, 15 Aug 2013 10:29:30 -0500
Subject: [PATCH] Issue #2058321 by tim.plunkett, pameeela: Move the 'place
 block' UI into the block listing.

---
 core/modules/block/js/block.admin.js | 71 ++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 core/modules/block/js/block.admin.js

diff --git a/core/modules/block/js/block.admin.js b/core/modules/block/js/block.admin.js
new file mode 100644
index 000000000000..93d92295e873
--- /dev/null
+++ b/core/modules/block/js/block.admin.js
@@ -0,0 +1,71 @@
+(function ($, Drupal) {
+
+"use strict";
+
+/**
+ * Filters the block list by a text input search string.
+ *
+ * Text search input: input.block-filter-text
+ * Target element:    input.block-filter-text[data-element]
+ * Source text:       .block-filter-text-source
+ */
+Drupal.behaviors.blockFilterByText = {
+  attach: function (context, settings) {
+    var $input = $('input.block-filter-text').once('block-filter-text');
+    var $element = $($input.attr('data-element'));
+    var $blocks, $details;
+
+    /**
+     * Hides the <details> element for a category if it has no visible blocks.
+     */
+    function hideCategoryDetails(index, element) {
+      var $details = $(element);
+      $details.toggle($details.find('li:visible').length > 0);
+    }
+
+    /**
+     * Filters the block list.
+     */
+    function filterBlockList (e) {
+      var query = $(e.target).val().toLowerCase();
+
+      /**
+       * Shows or hides the block entry based on the query.
+       */
+      function showBlockEntry (index, block) {
+        var $block = $(block);
+        var $sources = $block.find('.block-filter-text-source');
+        var textMatch = $sources.text().toLowerCase().indexOf(query) !== -1;
+        $block.toggle(textMatch);
+      }
+
+      // Filter if the length of the query is at least 2 characters.
+      if (query.length >= 2) {
+        $blocks.each(showBlockEntry);
+
+        // Note that we first open all <details> to be able to use ':visible'.
+        // Mark the <details> elements that were closed before filtering, so
+        // they can be reclosed when filtering is removed.
+        $details.not('[open]').attr('data-drupal-block-state', 'forced-open');
+        // Hide the category <details> if they don't have any visible rows.
+        $details.attr('open', 'open').each(hideCategoryDetails);
+      }
+      else {
+        $blocks.show();
+        $details.show();
+        // Return <details> elements that had been closed before filtering
+        // to a closed state.
+        $details.filter('[data-drupal-block-state="forced-open"]').removeAttr('open data-drupal-block-state');
+      }
+    }
+
+    if ($element.length) {
+      $details = $element.find('details');
+      $blocks = $details.find('li');
+
+      $input.on('keyup', filterBlockList);
+    }
+  }
+};
+
+}(jQuery, Drupal));
-- 
GitLab