From 9616b1a2358c47d20e877f49238c00eecb0eda37 Mon Sep 17 00:00:00 2001 From: Julia Svinareva <julia.svinaryova@onlyoffice.com> Date: Mon, 9 Dec 2019 15:51:49 +0300 Subject: [PATCH] [SSE] Fix bug 43275 --- apps/common/main/lib/component/TabBar.js | 185 +---------------------- 1 file changed, 3 insertions(+), 182 deletions(-) diff --git a/apps/common/main/lib/component/TabBar.js b/apps/common/main/lib/component/TabBar.js index 44e58de0b..9b77da678 100644 --- a/apps/common/main/lib/component/TabBar.js +++ b/apps/common/main/lib/component/TabBar.js @@ -123,183 +123,6 @@ define([ } }, - setAbsTabs: function () { - var me = this, tab = null, length = this.bounds.length; - - for (var i = 0; i < length; ++i) { - tab = me.bar.tabs[i].$el; - tab.css('position', 'absolute'); - tab.css('left', (me.bounds[i].left - me.tabBarLeft - this.scrollLeft) + 'px'); - - if (tab.hasClass('active')) { - tab.css('top', '1px'); - } else { - tab.css('top', '0px'); - } - } - }, - - updatePositions: function () { - this.drag.place = undefined; - - var i, tabBound, center, place = -1, next = -this.scrollLeft, - tabsCount = this.bounds.length, - dragBound = this.drag.tab.$el.get(0).getBoundingClientRect(); - - if (this.drag.moveX - this.drag.mouseX > 0) { - for (i = tabsCount - 1; i >= 0; --i) { - tabBound = this.bounds[i]; - center = (tabBound.right + tabBound.left) * 0.5; - if (dragBound.left < center && center < dragBound.right) { - place = i; - break; - } - } - - if (-1 === place) { - for (i = tabsCount - 1; i >= 0; --i) { - tabBound = dragBound; - center = (tabBound.right + tabBound.left) * 0.5; - if (this.bounds[i].left < center && center < this.bounds[i].right) { - place = i; - break; - } - } - } - - } else { - for (i = 0; i < tabsCount; ++i) { - tabBound = this.bounds[i]; - center = (tabBound.right + tabBound.left) * 0.5; - if (dragBound.left < center && center < dragBound.right) { - place = i; - break; - } - } - - if (-1 === place) { - for (i = 0; i < tabsCount; ++i) { - tabBound = dragBound; - center = (tabBound.right + tabBound.left) * 0.5; - if (this.bounds[i].left < center && center < this.bounds[i].right) { - place = i; - break; - } - } - } - } - - if (-1 !== place) { - - this.drag.place = place; - - for (i = 0; i < tabsCount; ++i) { - if (i === place) { - if (place < this.drag.index) { - next += this.drag.tabWidth; - } - } - - if (place > this.drag.index) { - if (i === place + 1) { - next += this.drag.tabWidth; - } - } - - if (i !== this.drag.index) { - this.bar.tabs[i].$el.css('left', next + 'px'); - } else { - if (this.drag.index === place) { - next += this.drag.tabWidth; - } - - continue; - } - - next += this.bounds[i].width; - } - } - }, - - setHook: function(e, bar, tab) { - var me = this; - - function dragComplete() { - if (!_.isUndefined(me.drag)) { - me.drag.tab.removeClass('dragged'); - me.drag.tab.$el.css('z-index', ''); - me.bar.dragging = false; - var tab = null; - for (var i = me.bar.tabs.length - 1; i >= 0; --i) { - tab = me.bar.tabs[i].$el; - if (tab) { - tab.css('top', ''); - tab.css('position', ''); - tab.css('left', ''); - } - } - - if (!_.isUndefined(me.drag.place)) { - me.bar.trigger('tab:move', me.drag.index, me.drag.place); - me.bar.$bar.scrollLeft(me.scrollLeft); - me.bar.scrollX = undefined; - } else { - me.bar.trigger('tab:move', me.drag.index); - me.bar.$bar.scrollLeft(me.scrollLeft); - me.bar.scrollX = undefined; - } - - me.drag = undefined; - } - } - - function dragMove (e) { - if (!_.isUndefined(me.drag)) { - me.drag.moveX = e.clientX*Common.Utils.zoom(); - var leftPos = Math.max(me.drag.moveX - me.drag.anchorX - me.tabBarLeft - me.scrollLeft, 0); - leftPos = Math.min(leftPos, me.tabBarRight - me.tabBarLeft - me.drag.tabWidth - me.scrollLeft); - - me.drag.tab.$el.css('left', leftPos + 'px'); - me.drag.tab.$el.css('z-index','100'); - - me.updatePositions(); - } - } - - function dragDropText (e) { // disable firefox drag&drop - e.preventDefault(); - } - - if (!_.isUndefined(bar) && !_.isUndefined(tab) && bar.tabs.length > 1) { - tab.addClass('dragged'); - - var index = bar.tabs.indexOf(tab), - _clientX = e.clientX*Common.Utils.zoom(); - me.bar = bar; - me.drag = {tab: tab, index: index}; - bar.dragging = true; - - this.calculateBounds(); - this.setAbsTabs(); - - me.drag.moveX = _clientX; - me.drag.mouseX = _clientX; - me.drag.anchorX = _clientX - this.bounds[index].left; - me.drag.tabWidth = this.bounds[index].width; - - document.addEventListener('dragstart',dragDropText); - - $(document).on('mousemove.tabbar', dragMove); - $(document).on('mouseup.tabbar', function (e) { - dragComplete(e); - $(document).off('mouseup.tabbar'); - $(document).off('mousemove.tabbar'); - - document.removeEventListener('dragstart',dragDropText); - }); - } - }, - setHookTabs: function (e, bar, tabs) { var me = this; function dragComplete() { @@ -410,11 +233,9 @@ define([ mousedown: $.proxy(function (e) { if (this.bar.options.draggable && !_.isUndefined(dragHelper) && (3 !== e.which)) { if (!tab.isLockTheDrag) { - if (this.bar.selectTabs.length > 1) { - dragHelper.setHookTabs(e, this.bar, this.bar.selectTabs); - } else { - dragHelper.setHook(e, this.bar, tab); - } + if (!e.ctrlKey && !e.metaKey && !e.shiftKey) + tab.changeState(); + dragHelper.setHookTabs(e, this.bar, this.bar.selectTabs); } } }, this)