Add includeSnap option
This commit is contained in:
parent
5a3eaa2700
commit
ed88e631ab
|
@ -58,7 +58,8 @@ define([
|
||||||
thumbTemplate: '<div class="thumb" style="">' +
|
thumbTemplate: '<div class="thumb" style="">' +
|
||||||
'<div class="thumb-top"><div class="thumb-top-inner"></div></div>' +
|
'<div class="thumb-top"><div class="thumb-top-inner"></div></div>' +
|
||||||
'<div class="thumb-bottom"><div class="thumb-bottom-inner"></div></div>' +
|
'<div class="thumb-bottom"><div class="thumb-bottom-inner"></div></div>' +
|
||||||
'</div>'
|
'</div>',
|
||||||
|
includeSnap: true
|
||||||
},
|
},
|
||||||
|
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
|
|
@ -285,7 +285,8 @@ define([
|
||||||
minValue: 0,
|
minValue: 0,
|
||||||
maxValue: 100,
|
maxValue: 100,
|
||||||
values: [0, 100],
|
values: [0, 100],
|
||||||
thumbTemplate: '<div class="thumb" style=""></div>'
|
thumbTemplate: '<div class="thumb" style=""></div>',
|
||||||
|
includeSnap: false
|
||||||
},
|
},
|
||||||
|
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
@ -313,7 +314,6 @@ define([
|
||||||
me.maxValue = me.options.maxValue;
|
me.maxValue = me.options.maxValue;
|
||||||
me.delta = 100/(me.maxValue - me.minValue);
|
me.delta = 100/(me.maxValue - me.minValue);
|
||||||
me.thumbs = [];
|
me.thumbs = [];
|
||||||
|
|
||||||
if (me.options.el) {
|
if (me.options.el) {
|
||||||
me.render();
|
me.render();
|
||||||
}
|
}
|
||||||
|
@ -342,10 +342,37 @@ define([
|
||||||
el.find('.track-center').width(me.options.width - 14);
|
el.find('.track-center').width(me.options.width - 14);
|
||||||
el.width(me.options.width);
|
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) {
|
var onMouseUp = function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
|
if (me.options.includeSnap) resetPageX(e);
|
||||||
|
|
||||||
var index = e.data.index,
|
var index = e.data.index,
|
||||||
lastValue = me.thumbs[index].value,
|
lastValue = me.thumbs[index].value,
|
||||||
minValue = (index-1<0) ? 0 : me.thumbs[index-1].position,
|
minValue = (index-1<0) ? 0 : me.thumbs[index-1].position,
|
||||||
|
@ -387,6 +414,7 @@ define([
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
if (me.options.includeSnap) resetPageX(e);
|
||||||
|
|
||||||
var index = e.data.index,
|
var index = e.data.index,
|
||||||
lastValue = me.thumbs[index].value,
|
lastValue = me.thumbs[index].value,
|
||||||
|
@ -416,6 +444,7 @@ define([
|
||||||
|
|
||||||
var index = e.data.index,
|
var index = e.data.index,
|
||||||
thumb = me.thumbs[index].thumb;
|
thumb = me.thumbs[index].thumb;
|
||||||
|
setCenters(index);
|
||||||
|
|
||||||
me._dragstart = e.pageX*Common.Utils.zoom() - thumb.offset().left - thumb.width()/2;
|
me._dragstart = e.pageX*Common.Utils.zoom() - thumb.offset().left - thumb.width()/2;
|
||||||
me.setActiveThumb(index);
|
me.setActiveThumb(index);
|
||||||
|
@ -428,6 +457,7 @@ define([
|
||||||
$(document).on('mousemove', null, e.data, me.binding.onMouseMove);
|
$(document).on('mousemove', null, e.data, me.binding.onMouseMove);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var onTrackMouseUp = function (e) {
|
var onTrackMouseUp = function (e) {
|
||||||
if ( me.disabled || !_.isUndefined(me._dragstart) || me.thumbs.length > 9) return;
|
if ( me.disabled || !_.isUndefined(me._dragstart) || me.thumbs.length > 9) return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue