code linting and remove excessive new lines

This commit is contained in:
Steve-Mcl 2022-07-06 13:08:56 +01:00
parent 21d3261eec
commit 7216c6d62a
1 changed files with 31 additions and 50 deletions

View File

@ -1,4 +1,4 @@
RED.contextMenu = (function() {
RED.contextMenu = (function () {
let menu;
function createMenu() {
@ -15,10 +15,6 @@ RED.contextMenu = (function() {
// ],
// width: 200,
// })
}
function disposeMenu() {
@ -50,35 +46,35 @@ RED.contextMenu = (function() {
if (RED.view.snapGrid) {
const gridSize = RED.view.gridSize()
addX = gridSize*Math.floor(addX/gridSize)
addY = gridSize*Math.floor(addY/gridSize)
addX = gridSize * Math.floor(addX / gridSize)
addY = gridSize * Math.floor(addY / gridSize)
}
const menuItems = [
{ onselect: 'core:show-action-list', onpostselect: function() {} },
{ onselect: 'core:show-action-list', onpostselect: function () { } },
{
label: RED._("contextMenu.insert"),
options: [
{
label: RED._("contextMenu.node"),
onselect: function() {
onselect: function () {
RED.view.showQuickAddDialog({
position: [ addX, addY ],
position: [addX, addY],
touchTrigger: true,
splice: isSingleLink?selection.links[0]:undefined,
splice: isSingleLink ? selection.links[0] : undefined,
// spliceMultiple: isMultipleLinks
})
}
},
( hasSelection || hasLinks ) ? {
(hasSelection || hasLinks) ? {
label: RED._("contextMenu.junction"),
onselect: 'core:split-wires-with-junctions',
disabled: !hasLinks
} : {
label: RED._("contextMenu.junction"),
onselect: function() {
onselect: function () {
const nn = {
_def: {defaults:{}},
_def: { defaults: {} },
type: 'junction',
z: RED.workspaces.active(),
id: RED.nodes.id(),
@ -91,8 +87,8 @@ RED.contextMenu = (function() {
}
const historyEvent = {
dirty: RED.nodes.dirty(),
t:'add',
junctions:[nn]
t: 'add',
junctions: [nn]
}
RED.nodes.addJunction(nn);
RED.history.push(historyEvent);
@ -111,28 +107,13 @@ RED.contextMenu = (function() {
}
]
// menuItems.push(
// {
// label: (isSingleLink || isMultipleLinks)?'Insert into wire...':'Add node...',
// onselect: function() {
// RED.view.showQuickAddDialog({
// position: [ options.x - offset.left, options.y - offset.top ],
// touchTrigger: true,
// splice: isSingleLink?selection.links[0]:undefined,
// spliceMultiple: isMultipleLinks
// })
// }
// },
// )
// if (hasLinks && !hasSelection) {
// menuItems.push({ onselect: 'core:split-wires-with-junctions', label: 'Insert junction'})
// }
menuItems.push(
null,
{ onselect: 'core:undo', disabled: RED.history.list().length === 0 },
{ onselect: 'core:redo', disabled: RED.history.listRedo().length === 0 },
null,
{ onselect: 'core:cut-selection-to-internal-clipboard', label: RED._("keyboard.cutNode"), disabled: !hasSelection},
{ onselect: 'core:cut-selection-to-internal-clipboard', label: RED._("keyboard.cutNode"), disabled: !hasSelection },
{ onselect: 'core:copy-selection-to-internal-clipboard', label: RED._("keyboard.copyNode"), disabled: !hasSelection },
{ onselect: 'core:paste-from-internal-clipboard', label: RED._("keyboard.pasteNode"), disabled: !RED.view.clipboard() },
{ onselect: 'core:delete-selection', disabled: !canDelete },
@ -144,8 +125,8 @@ RED.contextMenu = (function() {
menuItems.push(
null,
isGroup ?
{ onselect: 'core:ungroup-selection', disabled: !isGroup }
: { onselect: 'core:group-selection', disabled: !hasSelection }
{ onselect: 'core:ungroup-selection', disabled: !isGroup }
: { onselect: 'core:group-selection', disabled: !hasSelection }
)
if (canRemoveFromGroup) {
menuItems.push({ onselect: 'core:remove-selection-from-group', label: RED._("menu.label.groupRemoveSelection") })
@ -154,16 +135,16 @@ RED.contextMenu = (function() {
}
menu = RED.menu.init({
direction: 'right',
onpreselect: function() {
onpreselect: function () {
disposeMenu()
},
onpostselect: function() {
onpostselect: function () {
RED.view.focus()
},
options: menuItems
});
menu.attr("id","red-ui-workspace-context-menu");
menu.attr("id", "red-ui-workspace-context-menu");
menu.css({
position: "absolute"
})
@ -174,18 +155,18 @@ RED.contextMenu = (function() {
var top = options.y
var left = options.x
if (top+menu.height()-$(document).scrollTop() > $(window).height()) {
top -= (top+menu.height())-$(window).height() + 22;
if (top + menu.height() - $(document).scrollTop() > $(window).height()) {
top -= (top + menu.height()) - $(window).height() + 22;
}
if (left+menu.width()-$(document).scrollLeft() > $(window).width()) {
left -= (left+menu.width())-$(window).width() + 18;
if (left + menu.width() - $(document).scrollLeft() > $(window).width()) {
left -= (left + menu.width()) - $(window).width() + 18;
}
menu.css({
top: top+"px",
left: left+"px"
top: top + "px",
left: left + "px"
})
$(".red-ui-menu.red-ui-menu-dropdown").hide();
$(document).on("mousedown.red-ui-workspace-context-menu", function(evt) {
$(document).on("mousedown.red-ui-workspace-context-menu", function (evt) {
if (menu && menu[0].contains(evt.target)) {
return
}
@ -198,11 +179,11 @@ RED.contextMenu = (function() {
}
// Allow escape key hook and other editor events to close context menu
RED.keyboard.add("red-ui-workspace-context-menu", "escape", function () { RED.contextMenu.hide() })
RED.events.on("editor:open",function() { RED.contextMenu.hide() });
RED.events.on("search:open",function() { RED.contextMenu.hide() });
RED.events.on("type-search:open",function() { RED.contextMenu.hide() });
RED.events.on("actionList:open",function() { RED.contextMenu.hide() });
RED.events.on("view:selection-changed",function() { RED.contextMenu.hide() });
RED.events.on("editor:open", function () { RED.contextMenu.hide() });
RED.events.on("search:open", function () { RED.contextMenu.hide() });
RED.events.on("type-search:open", function () { RED.contextMenu.hide() });
RED.events.on("actionList:open", function () { RED.contextMenu.hide() });
RED.events.on("view:selection-changed", function () { RED.contextMenu.hide() });
return {
show: show,
hide: disposeMenu