diff --git a/core/modules/views_ui/js/views_ui.listing.js b/core/modules/views_ui/js/views_ui.listing.js index 1dc807a..2296c81 100644 --- a/core/modules/views_ui/js/views_ui.listing.js +++ b/core/modules/views_ui/js/views_ui.listing.js @@ -51,4 +51,45 @@ } }; + + // When a view is enabled, this variable will hold it's machine name. It is + // used in the behavior to focus on the first dropbutton link of this view's + // row. + var enabledView = ''; + + /** + * Handles focus after Ajax update. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Listen to disable events on views listing page to keep focus in context. + */ + Drupal.behaviors.viewsEnableFocus = { + attach: function (context) { + + function focusRow(index, row) { + var $row = $(row); + var $source = $row.find('.views-ui-view-machine-name .views-table-filter-text-source'); + var textMatch = $source.text().indexOf(enabledView) !== -1; + if (textMatch) { + $row.find('.dropbutton a').eq(0).trigger('focus'); + } + } + + // Enable a view, keep the machine name around so that the next round of + // Drupal.behaviorAttach() focuses it. + $(context).find('tr.views-ui-list-disabled li.enable .use-ajax').on('click', function () { + // Store the machine name of the view to focus after ajax update. + enabledView = $(this).closest('tr').find('.views-ui-view-machine-name .views-table-filter-text-source').text(); + }); + + // A view has been enabled, focus the first dropbutton link. + if (enabledView && enabledView !== '') { + $('tr.views-ui-list-enabled').each(focusRow); + enabledView = ''; + } + } + }; + }(jQuery, Drupal));