diff --git a/apps/common/main/lib/component/MultiSliderGradient.js b/apps/common/main/lib/component/MultiSliderGradient.js index 28c2daf09..e488a41d8 100644 --- a/apps/common/main/lib/component/MultiSliderGradient.js +++ b/apps/common/main/lib/component/MultiSliderGradient.js @@ -58,7 +58,8 @@ define([ thumbTemplate: '
' + '
' + '
' + - '
' + '', + includeSnap: true }, disabled: false, diff --git a/apps/common/main/lib/component/Slider.js b/apps/common/main/lib/component/Slider.js index d142eed92..5b454f737 100644 --- a/apps/common/main/lib/component/Slider.js +++ b/apps/common/main/lib/component/Slider.js @@ -285,7 +285,8 @@ define([ minValue: 0, maxValue: 100, values: [0, 100], - thumbTemplate: '
' + thumbTemplate: '
', + includeSnap: false }, disabled: false, @@ -313,7 +314,6 @@ define([ me.maxValue = me.options.maxValue; me.delta = 100/(me.maxValue - me.minValue); me.thumbs = []; - if (me.options.el) { me.render(); } @@ -342,10 +342,37 @@ define([ el.find('.track-center').width(me.options.width - 14); el.width(me.options.width); + var centers = []; + var setCenters = function (index) { + if(!me.options.includeSnap) return; + centers = [50]; + var n=0; + _.each(me.thumbs, function (thumb, indexT) { + if (indexT != index) { + centers.push((thumb.position - n) / 2 + n); + n = thumb.position; + } + }); + if(n != 100) centers.push((100 - n) / 2 + n); + }; + + var resetPageX = function (e) { + var x; + _.each(centers, function (cnt){ + x=(0.01 * me.width * cnt + me.cmpEl.offset().left + me._dragstart)/Common.Utils.zoom(); + if((e.pageX <= x + 10) && (e.pageX >= x-10)) { + e.pageX = x; + return; + } + }); + }; + var onMouseUp = function (e) { e.preventDefault(); e.stopPropagation(); + if (me.options.includeSnap) resetPageX(e); + var index = e.data.index, lastValue = me.thumbs[index].value, minValue = (index-1<0) ? 0 : me.thumbs[index-1].position, @@ -387,6 +414,7 @@ define([ e.preventDefault(); e.stopPropagation(); + if (me.options.includeSnap) resetPageX(e); var index = e.data.index, lastValue = me.thumbs[index].value, @@ -416,6 +444,7 @@ define([ var index = e.data.index, thumb = me.thumbs[index].thumb; + setCenters(index); me._dragstart = e.pageX*Common.Utils.zoom() - thumb.offset().left - thumb.width()/2; me.setActiveThumb(index); @@ -428,6 +457,7 @@ define([ $(document).on('mousemove', null, e.data, me.binding.onMouseMove); }; + var onTrackMouseUp = function (e) { if ( me.disabled || !_.isUndefined(me._dragstart) || me.thumbs.length > 9) return;