function LinkeditorPanels(linkeditor) {
this.linkeditor = linkeditor;
this.sides = ['left', 'right'];
+ this.maxWidth = 70;
+ this.minWidth = 7;
+ this.thresholdToggle = 3;
}
LinkeditorPanels.prototype = {
init: function () {
-
var $this = this;
$.each(this.sides, function (k, side) {
var tool = $this.linkeditor.settings.get(side + '_tool');
var open = $this.linkeditor.settings.get(tool + '_open');
- console.log(open);
- var width = Math.min(70, Math.max(12, $this.linkeditor.settings.get(tool + '_width')));
+ var width = $this.normalizeWidth($this.linkeditor.settings.get(tool + '_width'));
var icon = $("#linkeditor-icon-" + tool);
- var panelContainer = $("#linkeditor-" + side + '-panel')
+ var panelContainer = $("#linkeditor-" + side + '-panel').data('tool', tool);
$("#linkeditor-" + side + '-icons').append(icon);
panelContainer.append($("#linkeditor-panel-" + tool));
panelContainer.attr('data-width', width);
});
this.linkeditor.resize.resize();
+ $(document).on('mousedown', ".linkeditor-sidebar .handle", function (e) {
+ $this.linkeditor.setMouseCoordinates(e);
+ $(this).addClass('dragging');
+ return false;
+ });
+
+ },
+
+ moveHandle: function () {
+ var $this = this;
+ $(".linkeditor-sidebar .handle.dragging").each(function () {
+ let cssWidth;
+ let sidebar = $(this).closest('.linkeditor-sidebar');
+ if (sidebar.data('side') === 'left') {
+ cssWidth = $this.linkeditor.mx - 49;
+ } else {
+ cssWidth = $this.linkeditor.resize.ww - 49 - $this.linkeditor.mx;
+ }
+ let panel = $(sidebar).find('.linkeditor-panel');
+ let relativeWidth = 100 * (cssWidth / $this.linkeditor.resize.ww);
+
+ let tool = panel.data('tool');
+ // Open/close when drag&drop
+ if (relativeWidth < $this.thresholdToggle) {
+ // Close
+ $this.setPanelState(tool, false);
+ } else {
+ $this.setPanelState(tool, true);
+ }
+
+ let width = $this.normalizeWidth(relativeWidth);
+ panel.data('width', width);
+ $this.linkeditor.settings.set(tool + '_width', width);
+ $this.linkeditor.resize.resize();
+ });
+ },
+
+ normalizeWidth: function (w) {
+ return Math.max(this.minWidth, Math.min(w, this.maxWidth));
+ },
+
+ mouseup: function () {
+ $(".linkeditor-sidebar .handle.dragging").removeClass('dragging');
},
resize: function (ww) {
$(this).css('width', w);
});
},
+
toggleLayers: function () {
this.togglePanel('layers');
},
this.togglePanel('form');
},
togglePanel: function (panel) {
+ this.setPanelState(panel, 'toggle');
+ },
+ setPanelState: function (panel, newState) {
let container = $("#linkeditor-panel-" + panel).closest('.linkeditor-panel');
- container.toggleClass('open');
+ var currentState = container.hasClass('open');
+ if (currentState === newState) {
+ return;
+ }
+ if (newState === 'toggle') {
+ newState = !currentState;
+ }
var icon = $("#linkeditor-icon-" + panel);
- var opened = container.hasClass('open');
- if (opened) {
+ if (newState) {
+ container.addClass('open');
icon.addClass('active');
} else {
+ container.removeClass('open');
icon.removeClass('active');
}
- this.linkeditor.settings.set(panel + '_open', opened);
+ this.linkeditor.settings.set(panel + '_open', newState);
this.linkeditor.resize.resize();
- }
+ },
};
module.exports = LinkeditorPanels;
data-tooltip="{{__('Liste des liens')}} (F7)"
data-key="f7"></a>
<a href="#" id="linkeditor-icon-form" data-icon="settings" data-action="panels.toggleForm"
- data-tooltip="{{__('Afficher le formulaire')}} (F8)"
+ data-tooltip="{{__('Paramètres du lien')}} (F8)"
data-key="f8"></a>
<div id="linkeditor-panel-layers">
</div>
<div id="linkeditor-panel-form">
</div>
</div>
- <aside id="linkeditor-left" class="linkeditor-sidebar">
+ <aside id="linkeditor-left" class="linkeditor-sidebar" data-side="left">
<nav id="linkeditor-left-icons">
</nav>
</div>
</div>
</div>
- <aside id="linkeditor-right" class="linkeditor-sidebar">
+ <aside id="linkeditor-right" class="linkeditor-sidebar" data-side="right">
<nav id="linkeditor-right-icons"></nav>
<div id="linkeditor-right-panel" class="linkeditor-panel"></div>
<div class="handle"></div>