[SSE] Fix bug 43275

This commit is contained in:
Julia Svinareva 2019-12-09 15:51:49 +03:00
parent 0279a891d1
commit 9616b1a235

View file

@ -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) { setHookTabs: function (e, bar, tabs) {
var me = this; var me = this;
function dragComplete() { function dragComplete() {
@ -410,11 +233,9 @@ define([
mousedown: $.proxy(function (e) { mousedown: $.proxy(function (e) {
if (this.bar.options.draggable && !_.isUndefined(dragHelper) && (3 !== e.which)) { if (this.bar.options.draggable && !_.isUndefined(dragHelper) && (3 !== e.which)) {
if (!tab.isLockTheDrag) { if (!tab.isLockTheDrag) {
if (this.bar.selectTabs.length > 1) { if (!e.ctrlKey && !e.metaKey && !e.shiftKey)
dragHelper.setHookTabs(e, this.bar, this.bar.selectTabs); tab.changeState();
} else { dragHelper.setHookTabs(e, this.bar, this.bar.selectTabs);
dragHelper.setHook(e, this.bar, tab);
}
} }
} }
}, this) }, this)