2016-01-31 23:27:14 +01:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2016-01-31 23:27:14 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
RED.tray = (function() {
|
|
|
|
|
|
|
|
var stack = [];
|
2016-05-06 18:19:32 +02:00
|
|
|
var editorStack = $("#editor-stack");
|
2016-06-04 01:42:08 +02:00
|
|
|
var openingTray = false;
|
2016-01-31 23:27:14 +01:00
|
|
|
|
|
|
|
function resize() {
|
|
|
|
|
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
function showTray(options) {
|
|
|
|
var el = $('<div class="editor-tray"></div>');
|
2016-05-03 16:45:29 +02:00
|
|
|
var header = $('<div class="editor-tray-header"></div>').appendTo(el);
|
2016-05-06 18:19:32 +02:00
|
|
|
var bodyWrapper = $('<div class="editor-tray-body-wrapper"></div>').appendTo(el);
|
|
|
|
var body = $('<div class="editor-tray-body"></div>').appendTo(bodyWrapper);
|
2016-02-28 00:13:19 +01:00
|
|
|
var footer = $('<div class="editor-tray-footer"></div>').appendTo(el);
|
2016-04-14 03:07:49 +02:00
|
|
|
var resizer = $('<div class="editor-tray-resize-handle"></div>').appendTo(el);
|
2016-05-03 16:45:29 +02:00
|
|
|
// var growButton = $('<a class="editor-tray-resize-button" style="cursor: w-resize;"><i class="fa fa-angle-left"></i></a>').appendTo(resizer);
|
|
|
|
// var shrinkButton = $('<a class="editor-tray-resize-button" style="cursor: e-resize;"><i style="margin-left: 1px;" class="fa fa-angle-right"></i></a>').appendTo(resizer);
|
|
|
|
if (options.title) {
|
2017-10-25 16:26:24 +02:00
|
|
|
var titles = stack.map(function(e) { return e.options.title });
|
|
|
|
titles.push(options.title);
|
|
|
|
var title = '<ul class="editor-tray-breadcrumbs"><li>'+titles.join("</li><li>")+'</li></ul>';
|
|
|
|
|
|
|
|
$('<div class="editor-tray-titlebar">'+title+'</div>').appendTo(header);
|
2016-05-03 16:45:29 +02:00
|
|
|
}
|
2017-08-03 10:58:25 +02:00
|
|
|
if (options.width === Infinity) {
|
|
|
|
options.maximized = true;
|
|
|
|
resizer.addClass('editor-tray-resize-maximised');
|
|
|
|
}
|
2016-05-03 16:45:29 +02:00
|
|
|
var buttonBar = $('<div class="editor-tray-toolbar"></div>').appendTo(header);
|
2016-05-31 14:24:56 +02:00
|
|
|
var primaryButton;
|
2016-02-28 00:13:19 +01:00
|
|
|
if (options.buttons) {
|
|
|
|
for (var i=0;i<options.buttons.length;i++) {
|
|
|
|
var button = options.buttons[i];
|
2016-06-20 15:25:11 +02:00
|
|
|
var b = $('<button>').button().appendTo(buttonBar);
|
2016-02-28 00:13:19 +01:00
|
|
|
if (button.id) {
|
|
|
|
b.attr('id',button.id);
|
|
|
|
}
|
|
|
|
if (button.text) {
|
2016-05-03 16:45:29 +02:00
|
|
|
b.html(button.text);
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
|
|
|
if (button.click) {
|
2016-06-01 00:20:25 +02:00
|
|
|
b.click((function(action) {
|
|
|
|
return function(evt) {
|
|
|
|
if (!$(this).hasClass('disabled')) {
|
|
|
|
action(evt);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})(button.click));
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
|
|
|
if (button.class) {
|
|
|
|
b.addClass(button.class);
|
2016-05-31 14:24:56 +02:00
|
|
|
if (button.class === "primary") {
|
|
|
|
primaryButton = button;
|
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-06 18:19:32 +02:00
|
|
|
el.appendTo(editorStack);
|
2016-02-28 00:13:19 +01:00
|
|
|
var tray = {
|
|
|
|
tray: el,
|
|
|
|
header: header,
|
|
|
|
body: body,
|
|
|
|
footer: footer,
|
2016-05-31 14:24:56 +02:00
|
|
|
options: options,
|
|
|
|
primaryButton: primaryButton
|
2016-02-28 00:13:19 +01:00
|
|
|
};
|
2016-05-03 16:45:29 +02:00
|
|
|
stack.push(tray);
|
|
|
|
|
2017-08-03 10:58:25 +02:00
|
|
|
if (!options.maximized) {
|
|
|
|
el.draggable({
|
2016-04-14 03:07:49 +02:00
|
|
|
handle: resizer,
|
|
|
|
axis: "x",
|
|
|
|
start:function(event,ui) {
|
|
|
|
el.width('auto');
|
|
|
|
},
|
|
|
|
drag: function(event,ui) {
|
2016-05-06 18:19:32 +02:00
|
|
|
var absolutePosition = editorStack.position().left+ui.position.left
|
|
|
|
if (absolutePosition < 7) {
|
|
|
|
ui.position.left += 7-absolutePosition;
|
|
|
|
} else if (ui.position.left > -tray.preferredWidth-1) {
|
|
|
|
ui.position.left = -Math.min(editorStack.position().left-7,tray.preferredWidth-1);
|
2016-05-19 12:16:10 +02:00
|
|
|
}
|
|
|
|
if (tray.options.resize) {
|
2016-04-14 03:07:49 +02:00
|
|
|
setTimeout(function() {
|
|
|
|
tray.options.resize({width: -ui.position.left});
|
|
|
|
},0);
|
|
|
|
}
|
2016-04-18 17:41:58 +02:00
|
|
|
tray.width = -ui.position.left;
|
2016-04-14 03:07:49 +02:00
|
|
|
},
|
|
|
|
stop:function(event,ui) {
|
|
|
|
el.width(-ui.position.left);
|
|
|
|
el.css({left:''});
|
|
|
|
if (tray.options.resize) {
|
|
|
|
tray.options.resize({width: -ui.position.left});
|
|
|
|
}
|
2016-04-18 17:41:58 +02:00
|
|
|
tray.width = -ui.position.left;
|
2016-04-14 03:07:49 +02:00
|
|
|
}
|
|
|
|
});
|
2017-08-03 10:58:25 +02:00
|
|
|
}
|
2016-04-14 03:07:49 +02:00
|
|
|
|
2017-02-16 22:41:20 +01:00
|
|
|
function finishBuild() {
|
|
|
|
$("#header-shade").show();
|
|
|
|
$("#editor-shade").show();
|
|
|
|
$("#palette-shade").show();
|
|
|
|
$(".sidebar-shade").show();
|
|
|
|
tray.preferredWidth = Math.max(el.width(),500);
|
2017-10-09 13:10:00 +02:00
|
|
|
if (!options.maximized) {
|
|
|
|
body.css({"minWidth":tray.preferredWidth-40});
|
|
|
|
}
|
2017-02-16 22:41:20 +01:00
|
|
|
if (options.width) {
|
|
|
|
if (options.width > $("#editor-stack").position().left-8) {
|
|
|
|
options.width = $("#editor-stack").position().left-8;
|
|
|
|
}
|
|
|
|
el.width(options.width);
|
|
|
|
} else {
|
|
|
|
el.width(tray.preferredWidth);
|
2016-04-18 22:22:45 +02:00
|
|
|
}
|
2016-05-06 18:19:32 +02:00
|
|
|
|
2017-02-16 22:41:20 +01:00
|
|
|
tray.width = el.width();
|
|
|
|
if (tray.width > $("#editor-stack").position().left-8) {
|
|
|
|
tray.width = Math.max(0/*tray.preferredWidth*/,$("#editor-stack").position().left-8);
|
|
|
|
el.width(tray.width);
|
|
|
|
}
|
2016-05-06 18:19:32 +02:00
|
|
|
|
2017-02-16 22:41:20 +01:00
|
|
|
// tray.body.parent().width(Math.min($("#editor-stack").position().left-8,tray.width));
|
2016-05-06 18:19:32 +02:00
|
|
|
|
2017-02-16 22:41:20 +01:00
|
|
|
el.css({
|
|
|
|
right: -(el.width()+10)+"px",
|
|
|
|
transition: "right 0.25s ease"
|
|
|
|
});
|
|
|
|
$("#workspace").scrollLeft(0);
|
|
|
|
handleWindowResize();
|
|
|
|
openingTray = true;
|
2016-03-24 00:22:36 +01:00
|
|
|
setTimeout(function() {
|
2016-06-04 01:42:08 +02:00
|
|
|
setTimeout(function() {
|
2017-02-16 22:41:20 +01:00
|
|
|
if (!options.width) {
|
|
|
|
el.width(Math.min(tray.preferredWidth,$("#editor-stack").position().left-8));
|
|
|
|
}
|
|
|
|
if (options.resize) {
|
|
|
|
options.resize({width:el.width()});
|
|
|
|
}
|
|
|
|
if (options.show) {
|
|
|
|
options.show();
|
|
|
|
}
|
|
|
|
setTimeout(function() {
|
|
|
|
// Delay resetting the flag, so we don't close prematurely
|
|
|
|
openingTray = false;
|
|
|
|
},200);
|
|
|
|
body.find(":focusable:first").focus();
|
2016-04-18 17:41:58 +02:00
|
|
|
|
2017-02-16 22:41:20 +01:00
|
|
|
},150);
|
|
|
|
el.css({right:0});
|
|
|
|
},0);
|
|
|
|
}
|
|
|
|
if (options.open) {
|
|
|
|
if (options.open.length === 1) {
|
|
|
|
options.open(el);
|
|
|
|
finishBuild();
|
|
|
|
} else {
|
|
|
|
options.open(el,finishBuild);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
finishBuild();
|
|
|
|
}
|
2016-02-28 00:13:19 +01:00
|
|
|
}
|
|
|
|
|
2016-04-18 17:41:58 +02:00
|
|
|
function handleWindowResize() {
|
|
|
|
if (stack.length > 0) {
|
|
|
|
var tray = stack[stack.length-1];
|
|
|
|
var trayHeight = tray.tray.height()-tray.header.outerHeight()-tray.footer.outerHeight();
|
2017-01-30 00:01:31 +01:00
|
|
|
tray.body.height(trayHeight);
|
2017-08-03 10:58:25 +02:00
|
|
|
if (tray.options.maximized || tray.width > $("#editor-stack").position().left-8) {
|
2016-05-06 18:19:32 +02:00
|
|
|
tray.width = $("#editor-stack").position().left-8;
|
|
|
|
tray.tray.width(tray.width);
|
|
|
|
// tray.body.parent().width(tray.width);
|
|
|
|
} else if (tray.width < tray.preferredWidth) {
|
|
|
|
tray.width = Math.min($("#editor-stack").position().left-8,tray.preferredWidth);
|
2016-04-18 17:41:58 +02:00
|
|
|
tray.tray.width(tray.width);
|
2016-05-06 18:19:32 +02:00
|
|
|
// tray.body.parent().width(tray.width);
|
2016-04-18 17:41:58 +02:00
|
|
|
}
|
|
|
|
if (tray.options.resize) {
|
2017-01-30 00:01:31 +01:00
|
|
|
tray.options.resize({width:tray.width, height:trayHeight});
|
2016-04-18 17:41:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
|
2016-04-18 17:41:58 +02:00
|
|
|
return {
|
|
|
|
init: function init() {
|
|
|
|
$(window).resize(handleWindowResize);
|
|
|
|
RED.events.on("sidebar:resize",handleWindowResize);
|
2016-05-31 14:24:56 +02:00
|
|
|
$("#editor-shade").click(function() {
|
2016-06-04 01:42:08 +02:00
|
|
|
if (!openingTray) {
|
|
|
|
var tray = stack[stack.length-1];
|
|
|
|
if (tray && tray.primaryButton) {
|
|
|
|
tray.primaryButton.click();
|
|
|
|
}
|
2016-05-31 14:24:56 +02:00
|
|
|
}
|
|
|
|
});
|
2016-01-31 23:27:14 +01:00
|
|
|
},
|
|
|
|
show: function show(options) {
|
2017-08-20 23:59:51 +02:00
|
|
|
if (stack.length > 0 && !options.overlay) {
|
2016-01-31 23:27:14 +01:00
|
|
|
var oldTray = stack[stack.length-1];
|
2018-01-25 14:50:35 +01:00
|
|
|
if (options.width === "inherit") {
|
|
|
|
options.width = oldTray.tray.width();
|
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
oldTray.tray.css({
|
|
|
|
right: -(oldTray.tray.width()+10)+"px"
|
|
|
|
});
|
|
|
|
setTimeout(function() {
|
|
|
|
oldTray.tray.detach();
|
2016-02-28 00:13:19 +01:00
|
|
|
showTray(options);
|
2016-05-21 23:11:10 +02:00
|
|
|
},250)
|
2016-02-28 00:13:19 +01:00
|
|
|
} else {
|
2016-06-01 00:19:43 +02:00
|
|
|
RED.events.emit("editor:open");
|
2016-02-28 00:13:19 +01:00
|
|
|
showTray(options);
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
2016-03-21 23:51:48 +01:00
|
|
|
close: function close(done) {
|
2016-01-31 23:27:14 +01:00
|
|
|
if (stack.length > 0) {
|
|
|
|
var tray = stack.pop();
|
|
|
|
tray.tray.css({
|
|
|
|
right: -(tray.tray.width()+10)+"px"
|
|
|
|
});
|
|
|
|
setTimeout(function() {
|
|
|
|
if (tray.options.close) {
|
|
|
|
tray.options.close();
|
|
|
|
}
|
|
|
|
tray.tray.remove();
|
|
|
|
if (stack.length > 0) {
|
|
|
|
var oldTray = stack[stack.length-1];
|
2017-08-20 23:59:51 +02:00
|
|
|
if (!oldTray.options.overlay) {
|
|
|
|
oldTray.tray.appendTo("#editor-stack");
|
|
|
|
setTimeout(function() {
|
|
|
|
handleWindowResize();
|
|
|
|
oldTray.tray.css({right:0});
|
|
|
|
if (oldTray.options.show) {
|
|
|
|
oldTray.options.show();
|
|
|
|
}
|
|
|
|
},0);
|
|
|
|
} else {
|
2016-04-18 17:41:58 +02:00
|
|
|
handleWindowResize();
|
2016-03-21 23:51:48 +01:00
|
|
|
if (oldTray.options.show) {
|
|
|
|
oldTray.options.show();
|
|
|
|
}
|
2017-08-20 23:59:51 +02:00
|
|
|
}
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
2016-03-21 23:51:48 +01:00
|
|
|
if (done) {
|
|
|
|
done();
|
|
|
|
}
|
2016-06-01 00:19:43 +02:00
|
|
|
if (stack.length === 0) {
|
|
|
|
$("#header-shade").hide();
|
|
|
|
$("#editor-shade").hide();
|
2016-08-04 17:49:36 +02:00
|
|
|
$("#palette-shade").hide();
|
2016-06-01 00:19:43 +02:00
|
|
|
$(".sidebar-shade").hide();
|
|
|
|
RED.events.emit("editor:close");
|
|
|
|
RED.view.focus();
|
|
|
|
}
|
2016-05-21 23:11:10 +02:00
|
|
|
},250)
|
2016-01-31 23:27:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|