diff --git a/core/modules/views_ui/js/views_ui.listing.js b/core/modules/views_ui/js/views_ui.listing.js index 1dc807a..46f54cd 100644 --- a/core/modules/views_ui/js/views_ui.listing.js +++ b/core/modules/views_ui/js/views_ui.listing.js @@ -51,4 +51,55 @@ } }; + + // When a view is enabled/disabled, 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 changedView = ''; + + // Hold the selector for changed view. + var viewSelector = ''; + + /** + * 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.viewsChangeFocus = { + attach: function (context) { + + function findChangedRow(index, row) { + var $row = $(row); + var $source = $row.find('.views-ui-view-machine-name .views-table-filter-text-source'); + if ($source.text().indexOf(changedView) !== -1) { + $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. + changedView = $(this).closest('tr').find('.views-ui-view-machine-name .views-table-filter-text-source').text(); + viewSelector = 'tr.views-ui-list-enabled'; + }); + + // Disable a view. + $(context).find('tr.views-ui-list-enabled li.disable .use-ajax').on('click', function () { + // Store the machine name of the view to focus after ajax update. + changedView = $(this).closest('tr').find('.views-ui-view-machine-name .views-table-filter-text-source').text(); + viewSelector = 'tr.views-ui-list-disabled'; + }); + + // A view has been enabled/disabled, focus the first dropbutton link. + if (changedView && changedView !== '') { + $(viewSelector).each(findChangedRow); + changedView = ''; + } + } + }; + }(jQuery, Drupal));