diff --git a/apps/common/main/lib/component/MultiSliderGradient.js b/apps/common/main/lib/component/MultiSliderGradient.js index c738bb976..86290981b 100644 --- a/apps/common/main/lib/component/MultiSliderGradient.js +++ b/apps/common/main/lib/component/MultiSliderGradient.js @@ -150,6 +150,18 @@ define([ } style = Common.Utils.String.format('linear-gradient(to right, {0} {1}%, {2} {3}%)', this.colorValues[0], this.getValue(0), this.colorValues[1], this.getValue(1)); this.trackEl.css('background', style); + }, + + sortThumbs: function() { + var recalc_indexes = Common.UI.MultiSlider.prototype.sortThumbs.call(this), + new_colors = [], + me = this; + _.each (recalc_indexes, function(recalc_index) { + new_colors.push(me.colorValues[recalc_index]); + }); + this.colorValues = new_colors; + this.trigger('sortthumbs', me, recalc_indexes); + return recalc_indexes; } }); }); diff --git a/apps/common/main/lib/component/Slider.js b/apps/common/main/lib/component/Slider.js index 2d34c85e0..67a86d2d2 100644 --- a/apps/common/main/lib/component/Slider.js +++ b/apps/common/main/lib/component/Slider.js @@ -338,16 +338,21 @@ define([ e.preventDefault(); e.stopPropagation(); - var index = e.data, + var index = e.data.index, lastValue = me.thumbs[index].value, minValue = (index-1<0) ? 0 : me.thumbs[index-1].position, maxValue = (index+1 maxValue, + pos = Math.max(0, Math.min(100, position)), value = pos/me.delta + me.minValue; me.setThumbPosition(index, pos); me.thumbs[index].value = value; + if (need_sort) + me.sortThumbs(); + $(document).off('mouseup', onMouseUp); $(document).off('mousemove', onMouseMove); @@ -362,16 +367,21 @@ define([ e.preventDefault(); e.stopPropagation(); - var index = e.data, + var index = e.data.index, lastValue = me.thumbs[index].value, minValue = (index-1<0) ? 0 : me.thumbs[index-1].position, maxValue = (index+1 maxValue, + pos = Math.max(0, Math.min(100, position)), value = pos/me.delta + me.minValue; me.setThumbPosition(index, pos); me.thumbs[index].value = value; + if (need_sort) + me.sortThumbs(); + if (Math.abs(value-lastValue)>0.001) me.trigger('change', me, value, lastValue); }; @@ -379,7 +389,7 @@ define([ var onMouseDown = function (e) { if ( me.disabled ) return; - var index = e.data, + var index = e.data.index, thumb = me.thumbs[index].thumb; me._dragstart = e.pageX*Common.Utils.zoom() - thumb.offset().left - thumb.width()/2; @@ -389,8 +399,8 @@ define([ (index == idx) ? item.thumb.css('z-index', 500) : item.thumb.css('z-index', ''); }); - $(document).on('mouseup', null, index, onMouseUp); - $(document).on('mousemove', null, index, onMouseMove); + $(document).on('mouseup', null, e.data, onMouseUp); + $(document).on('mousemove', null, e.data, onMouseMove); }; var onTrackMouseDown = function (e) { @@ -441,7 +451,7 @@ define([ index: index }); me.setValue(index, me.options.values[index]); - thumb.on('mousedown', null, index, onMouseDown); + thumb.on('mousedown', null, me.thumbs[index], onMouseDown); }); me.setActiveThumb(0, true); @@ -489,6 +499,18 @@ define([ if (disabled !== this.disabled) this.cmpEl.toggleClass('disabled', disabled); this.disabled = disabled; + }, + + sortThumbs: function() { + this.thumbs.sort(function(a, b) { + return (a.position - b.position); + }); + var recalc_indexes = []; + _.each (this.thumbs, function(thumb, index) { + recalc_indexes.push(thumb.index); + thumb.index = index; + }); + return recalc_indexes; } }); }); diff --git a/apps/documenteditor/main/app/view/ShapeSettings.js b/apps/documenteditor/main/app/view/ShapeSettings.js index 2d131a7ad..d33dec7d0 100644 --- a/apps/documenteditor/main/app/view/ShapeSettings.js +++ b/apps/documenteditor/main/app/view/ShapeSettings.js @@ -1341,6 +1341,18 @@ define([ this.sldrGradient.on('thumbdblclick', function(cmp){ me.btnGradColor.cmpEl.find('button').dropdown('toggle'); }); + this.sldrGradient.on('sortthumbs', function(cmp, recalc_indexes){ + var colors = [], + currentIdx; + _.each (recalc_indexes, function(recalc_index, index) { + colors.push(me.GradColor.colors[recalc_index]); + if (me.GradColor.currentIdx == recalc_index) + currentIdx = index; + }); + me.OriginalFillType = null; + me.GradColor.colors = colors; + me.GradColor.currentIdx = currentIdx; + }); this.fillControls.push(this.sldrGradient); this.cmbBorderSize = new Common.UI.ComboBorderSizeEditable({ diff --git a/apps/documenteditor/main/app/view/TextArtSettings.js b/apps/documenteditor/main/app/view/TextArtSettings.js index 4a8259e87..479909abb 100644 --- a/apps/documenteditor/main/app/view/TextArtSettings.js +++ b/apps/documenteditor/main/app/view/TextArtSettings.js @@ -916,6 +916,18 @@ define([ this.sldrGradient.on('thumbdblclick', function(cmp){ me.btnGradColor.cmpEl.find('button').dropdown('toggle'); }); + this.sldrGradient.on('sortthumbs', function(cmp, recalc_indexes){ + var colors = [], + currentIdx; + _.each (recalc_indexes, function(recalc_index, index) { + colors.push(me.GradColor.colors[recalc_index]); + if (me.GradColor.currentIdx == recalc_index) + currentIdx = index; + }); + me.OriginalFillType = null; + me.GradColor.colors = colors; + me.GradColor.currentIdx = currentIdx; + }); this.lockedControls.push(this.sldrGradient); this.cmbBorderSize = new Common.UI.ComboBorderSizeEditable({