diff --git a/core/modules/outside_in/js/outside_in.js b/core/modules/outside_in/js/outside_in.js index 3ecb151..30e2a3b 100644 --- a/core/modules/outside_in/js/outside_in.js +++ b/core/modules/outside_in/js/outside_in.js @@ -13,6 +13,7 @@ $('.outside-in-editable a, .outside-in-editable button') .not('div.contextual a, div.contextual button') .toggleClass('js-outsidein-edit-mode'); + $('.outside-in-editable').toggleClass('focus'); }); // Bind an event listener to the .outside-in-editable div @@ -40,6 +41,42 @@ }); /** + * Add Ajax behaviours to links added by contextual links + * + * @todo Fix contextual links to work with use-ajax links. + * @see https://www.drupal.org/node/2764931 + * + * @param {jQuery.Event} event + * The `drupalContextualLinkAdded` event. + * @param {object} data + * An object containing the data relevant to the event. + * + * @listens event:drupalContextualLinkAdded + */ + $(document).on('drupalContextualLinkAdded', function (event, data) { + // Bind Ajax behaviors to all items showing the class. + data.$el.find('.use-ajax').once('ajax').each(function () { + // Below is copied directly from ajax.js to keep behavior the same. + var element_settings = {}; + // Clicked links look better with the throbber than the progress bar. + element_settings.progress = {type: 'throbber'}; + + // For anchor tags, these will go to the target of the anchor rather + // than the usual location. + var href = $(this).attr('href'); + if (href) { + element_settings.url = href; + element_settings.event = 'click'; + } + element_settings.dialogType = $(this).data('dialog-type'); + element_settings.dialog = $(this).data('dialog-options'); + element_settings.base = $(this).attr('id'); + element_settings.element = this; + Drupal.ajax(element_settings); + }); + }); + + /** * Attaches contextual's edit toolbar tab behavior. * * @type {Drupal~behavior}