diff --git a/core/modules/outside_in/js/off-canvas.iframe.js b/core/modules/outside_in/js/off-canvas.iframe.js new file mode 100644 index 0000000..30a6067 --- /dev/null +++ b/core/modules/outside_in/js/off-canvas.iframe.js @@ -0,0 +1,33 @@ +/** + * @file + * Drupal's off_canvas_iframe library. + */ + +(function ($, Drupal) { + 'use strict'; + + /** + * Ensure that links in the iframe use the correct renderer. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + * Append the correct _wrapper_format for links in the iframe. + */ + Drupal.behaviors.offCanvasIFrameLinks = { + attach: function (context) { + var $context = $(context); + // Update href for all links not targeting the "_parent". + $context.find('a[target!="_parent"]').each(function () { + $(this).attr('href', $(this).attr('href') + '?_wrapper_format=drupal_dialog_offcanvas'); + }); + $context.find('[data-dialog-renderer="offcanvas"]').each(function () { + $(this).removeAttr('data-dialog-renderer'); + $(this).removeAttr('data-dialog-type'); + + }); + + // @todo What should happen with off-canvas + } + }; +})(jQuery, Drupal); diff --git a/core/modules/outside_in/js/offcanvas.js b/core/modules/outside_in/js/offcanvas.js index 8cda69d..7b5749d 100644 --- a/core/modules/outside_in/js/offcanvas.js +++ b/core/modules/outside_in/js/offcanvas.js @@ -144,4 +144,73 @@ } }); + /** + * Add the Off-canvas wrapper format to the path. + * + * @param {string} path + * The path. + * @return {string} + * The appended path. + */ + function addFormatWrapper(path) { + if (path.includes('?')) { + path += '&'; + } + else { + path += '?'; + } + return path + '_wrapper_format=drupal_dialog_offcanvas'; + } + + /** + * Open off-canvas links in an iframe dialog. + * + * @type {Drupal~behavior} + * + * @prop {Drupal~behaviorAttach} attach + */ + Drupal.behaviors.offCanvasLinks = { + attach: function (context) { + if ($('.off-canvas-iframe').length) { + // Already in off-canvas iframe do not open any links in the nested + // iframe. + // @see \Drupal\outside_in\Render\MainContent\OffCanvasRender::renderResponse + return; + } + + $(context).find('[data-dialog-renderer="offcanvas"]').on('click', function (event) { + event.preventDefault(); + + var path = addFormatWrapper($(event.currentTarget).attr('href')); + if (!$('#drupal-offcanvas').length) { + $('