Commit 3f4174f9 authored by catch's avatar catch

Revert "Issue #2830882 by tedbow, droplet, Adita, drpal, markcarver, Wim...

Revert "Issue #2830882 by tedbow, droplet, Adita, drpal, markcarver, Wim Leers, nod_: Introduce Drupal.offCanvas, mirrored after Drupal.dialog, to avoid Settings Tray using Drupal.Dialog in unintended ways"

This reverts commit 48339450.
parent 88d1f67e
......@@ -6,124 +6,106 @@
**/
(function ($, Drupal, debounce, displace) {
Drupal.offCanvas = {
minDisplaceWidth: 768,
var minDisplaceWidth = 768;
$mainCanvasWrapper: $('[data-off-canvas-main-canvas]'),
var edge = document.documentElement.dir === 'rtl' ? 'left' : 'right';
isOffCanvas: function isOffCanvas($element) {
return $element.is('#drupal-off-canvas');
},
beforeCreate: function beforeCreate(settings) {
$('body').addClass('js-tray-open');
settings.dialogClass += ' ui-dialog-off-canvas';
var $mainCanvasWrapper = $('[data-off-canvas-main-canvas]');
settings.position = {
my: 'left top',
at: Drupal.offCanvas.getEdge() + ' top',
of: window
};
settings.height = $(window).height();
},
beforeClose: function beforeClose() {
$('body').removeClass('js-tray-open');
function resetSize(event) {
var offsets = displace.offsets;
var $element = event.data.$element;
var $widget = $element.dialog('widget');
var $elementScroll = $element.scrollTop();
$(document).off('.off-canvas');
$(window).off('.off-canvas');
Drupal.offCanvas.$mainCanvasWrapper.css('padding-' + Drupal.offCanvas.getEdge(), 0);
},
afterCreate: function afterCreate($element, settings) {
var eventData = { settings: settings, $element: $element, offCanvasDialog: this };
var adjustedOptions = {
position: {
my: edge + ' top',
at: edge + ' top' + (offsets.top !== 0 ? '+' + offsets.top : ''),
of: window
}
};
$element.on('dialogresize.off-canvas', eventData, debounce(Drupal.offCanvas.bodyPadding, 100)).on('dialogContentResize.off-canvas', eventData, Drupal.offCanvas.handleDialogResize).on('dialogContentResize.off-canvas', eventData, debounce(Drupal.offCanvas.bodyPadding, 100)).trigger('dialogresize.off-canvas');
$widget.css({
position: 'fixed',
height: $(window).height() - (offsets.top + offsets.bottom) + 'px'
});
Drupal.offCanvas.getContainer($element).attr('data-offset-' + Drupal.offCanvas.getEdge(), '');
$element.dialog('option', adjustedOptions).trigger('dialogContentResize.off-canvas');
$(window).on('resize.off-canvas scroll.off-canvas', eventData, debounce(Drupal.offCanvas.resetSize, 100)).trigger('resize.off-canvas');
},
render: function render(settings) {
$('.ui-dialog-off-canvas, .ui-dialog-off-canvas .ui-dialog-titlebar').toggleClass('ui-dialog-empty-title', !settings.title);
},
handleDialogResize: function handleDialogResize(event) {
var $element = event.data.$element;
var $container = Drupal.offCanvas.getContainer($element);
$element.scrollTop($elementScroll);
}
var $offsets = $container.find('> :not(#drupal-off-canvas, .ui-resizable-handle)');
var offset = 0;
function handleDialogResize(event) {
var $element = event.data.$element;
var $widget = $element.dialog('widget');
$element.css({ height: 'auto' });
var modalHeight = $container.height();
var $offsets = $widget.find('> :not(#drupal-off-canvas, .ui-resizable-handle)');
var offset = 0;
var modalHeight = void 0;
$offsets.each(function ($offset) {
offset += $($offset).outerHeight();
});
$element.css({ height: 'auto' });
modalHeight = $widget.height();
$offsets.each(function () {
offset += $(this).outerHeight();
});
var scrollOffset = $element.outerHeight() - $element.height();
$element.height(modalHeight - offset - scrollOffset);
},
resetSize: function resetSize(event) {
var offsets = displace.offsets;
var $element = event.data.$element;
var container = Drupal.offCanvas.getContainer($element);
var topPosition = offsets.top !== 0 ? '+' + offsets.top : '';
var adjustedOptions = {
position: {
my: Drupal.offCanvas.getEdge() + ' top',
at: Drupal.offCanvas.getEdge() + ' top' + topPosition,
of: window
}
};
var scrollOffset = $element.outerHeight() - $element.height();
$element.height(modalHeight - offset - scrollOffset);
}
container.css({
position: 'fixed',
height: $(window).height() - (offsets.top + offsets.bottom) + 'px'
});
$element.dialog('option', adjustedOptions).trigger('dialogContentResize.off-canvas');
},
bodyPadding: function bodyPadding(event) {
if ($('body').outerWidth() < Drupal.offCanvas.minDisplaceWidth) {
return;
}
var $element = event.data.$element;
var $container = Drupal.offCanvas.getContainer($element);
var $mainCanvasWrapper = Drupal.offCanvas.$mainCanvasWrapper;
var width = $container.outerWidth();
var mainCanvasPadding = $mainCanvasWrapper.css('padding-' + Drupal.offCanvas.getEdge());
if (width !== mainCanvasPadding) {
$mainCanvasWrapper.css('padding-' + Drupal.offCanvas.getEdge(), width + 'px');
$container.attr('data-offset-' + Drupal.offCanvas.getEdge(), width);
displace();
}
},
getContainer: function getContainer($element) {
return $element.dialog('widget');
},
getEdge: function getEdge() {
return document.documentElement.dir === 'rtl' ? 'left' : 'right';
function bodyPadding(event) {
if ($('body').outerWidth() < minDisplaceWidth) {
return;
}
};
var $element = event.data.$element;
var $widget = $element.dialog('widget');
var width = $widget.outerWidth();
var mainCanvasPadding = $mainCanvasWrapper.css('padding-' + edge);
if (width !== mainCanvasPadding) {
$mainCanvasWrapper.css('padding-' + edge, width + 'px');
$widget.attr('data-offset-' + edge, width);
displace();
}
}
Drupal.behaviors.offCanvasEvents = {
attach: function attach() {
$(window).once('off-canvas').on({
'dialog:beforecreate': function dialogBeforecreate(event, dialog, $element, settings) {
if (Drupal.offCanvas.isOffCanvas($element)) {
Drupal.offCanvas.beforeCreate(settings);
'dialog:aftercreate': function dialogAftercreate(event, dialog, $element, settings) {
if ($element.is('#drupal-off-canvas')) {
var eventData = { settings: settings, $element: $element };
$('.ui-dialog-off-canvas, .ui-dialog-off-canvas .ui-dialog-titlebar').toggleClass('ui-dialog-empty-title', !settings.title);
$element.on('dialogresize.off-canvas', eventData, debounce(bodyPadding, 100)).on('dialogContentResize.off-canvas', eventData, handleDialogResize).on('dialogContentResize.off-canvas', eventData, debounce(bodyPadding, 100)).trigger('dialogresize.off-canvas');
$element.dialog('widget').attr('data-offset-' + edge, '');
$(window).on('resize.off-canvas scroll.off-canvas', eventData, debounce(resetSize, 100)).trigger('resize.off-canvas');
}
},
'dialog:aftercreate': function dialogAftercreate(event, dialog, $element, settings) {
if (Drupal.offCanvas.isOffCanvas($element)) {
Drupal.offCanvas.render(settings);
Drupal.offCanvas.afterCreate($element, settings);
'dialog:beforecreate': function dialogBeforecreate(event, dialog, $element, settings) {
if ($element.is('#drupal-off-canvas')) {
$('body').addClass('js-tray-open');
settings.position = {
my: 'left top',
at: edge + ' top',
of: window
};
settings.dialogClass += ' ui-dialog-off-canvas';
settings.height = $(window).height();
}
},
'dialog:beforeclose': function dialogBeforeclose(event, dialog, $element) {
if (Drupal.offCanvas.isOffCanvas($element)) {
Drupal.offCanvas.beforeClose(event, dialog, $element);
if ($element.is('#drupal-off-canvas')) {
$('body').removeClass('js-tray-open');
$(document).off('.off-canvas');
$(window).off('.off-canvas');
$mainCanvasWrapper.css('padding-' + edge, 0);
}
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment