From 7178c63e1098c273360861a461e09289e56da9b4 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 20 Sep 2019 12:58:03 +0100 Subject: [PATCH] Fix tab access on touch screens --- .../editor-client/src/js/ui/common/tabs.js | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/common/tabs.js b/packages/node_modules/@node-red/editor-client/src/js/ui/common/tabs.js index 288334c06..0d371e56f 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/common/tabs.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/common/tabs.js @@ -19,6 +19,9 @@ RED.tabs = (function() { var defaultTabIcon = "fa fa-lemon-o"; + var dragActive = false; + var dblClickTime; + var dblClickArmed = false; function createTabs(options) { var tabs = {}; @@ -201,7 +204,16 @@ RED.tabs = (function() { } function onTabClick(evt) { - evt.preventDefault(); + if (dragActive) { + return + } + if (dblClickTime && Date.now()-dblClickTime < 400) { + dblClickTime = 0; + dblClickArmed = true; + return onTabDblClick.call(this,evt); + } + dblClickTime = Date.now(); + var currentTab = ul.find("li.red-ui-tab.active"); var thisTab = $(this).parent(); var fireSelectionChanged = false; @@ -267,7 +279,6 @@ RED.tabs = (function() { if (fireSelectionChanged) { selectionChanged(); } - return false; } function updateScroll() { @@ -289,7 +300,6 @@ RED.tabs = (function() { } function onTabDblClick(evt) { evt.preventDefault(); - evt.stopPropagation(); if (evt.metaKey || evt.shiftKey) { return; } @@ -418,7 +428,11 @@ RED.tabs = (function() { } - ul.find("li.red-ui-tab a").on("click",onTabClick).on("dblclick",onTabDblClick); + ul.find("li.red-ui-tab a") + .on("mouseup",onTabClick) + .on("click", function(evt) {evt.preventDefault(); }) + .on("dblclick", function(evt) {evt.stopPropagation(); evt.preventDefault(); }) + setTimeout(function() { updateTabWidths(); },0); @@ -524,8 +538,9 @@ RED.tabs = (function() { RED.popover.tooltip($(pinnedLink), tab.name, tab.action); } - link.on("click",onTabClick); - link.on("dblclick",onTabDblClick); + link.on("mouseup",onTabClick); + link.on("click", function(evt) { evt.preventDefault(); }) + link.on("dblclick", function(evt) { evt.stopPropagation(); evt.preventDefault(); }) if (tab.closeable) { @@ -560,6 +575,8 @@ RED.tabs = (function() { axis:"x", distance: 20, start: function(event,ui) { + if (dblClickArmed) { dblClickArmed = false; return false } + dragActive = true; originalTabOrder = []; tabElements = []; ul.children().each(function(i) { @@ -615,6 +632,7 @@ RED.tabs = (function() { } }, stop: function(event,ui) { + dragActive = false; ul.children().css({position:"relative",left:"",transition:""}); if (!li.hasClass('active')) { li.css({zIndex:""});