You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
839 lines
27 KiB
839 lines
27 KiB
7 years ago
|
/**
|
||
|
* Created by zcf on 2016/9/22.
|
||
7 years ago
|
*/
|
||
7 years ago
|
BI.SliderIconButton = BI.inherit(BI.Widget, {
|
||
7 years ago
|
_defaultConfig: function () {
|
||
7 years ago
|
return BI.extend(BI.SliderIconButton.superclass._defaultConfig.apply(this, arguments), {
|
||
7 years ago
|
baseCls: "bi-single-slider-button"
|
||
7 years ago
|
});
|
||
|
},
|
||
|
_init: function () {
|
||
7 years ago
|
BI.extend(BI.SliderIconButton.superclass._init.apply(this, arguments));
|
||
7 years ago
|
this.slider = BI.createWidget({
|
||
|
type: "bi.icon_button",
|
||
7 years ago
|
cls: "cursor-drag widget-slider-icon slider-button",
|
||
7 years ago
|
iconWidth: 14,
|
||
|
iconHeight: 14,
|
||
|
height: 14,
|
||
|
width: 14
|
||
|
});
|
||
|
BI.createWidget({
|
||
|
type: "bi.absolute",
|
||
|
element: this,
|
||
|
items: [{
|
||
|
el: this.slider,
|
||
|
top: 7,
|
||
|
left: -7
|
||
|
}],
|
||
|
width: 0,
|
||
|
height: 14
|
||
|
});
|
||
|
}
|
||
7 years ago
|
});
|
||
7 years ago
|
BI.shortcut("bi.single_slider_button", BI.SliderIconButton);/**
|
||
7 years ago
|
* Created by zcf on 2016/9/22.
|
||
7 years ago
|
*/
|
||
7 years ago
|
BI.SingleSlider = BI.inherit(BI.Widget, {
|
||
|
_constant: {
|
||
|
EDITOR_WIDTH: 90,
|
||
|
EDITOR_HEIGHT: 30,
|
||
|
HEIGHT: 28,
|
||
|
SLIDER_WIDTH_HALF: 15,
|
||
|
SLIDER_WIDTH: 30,
|
||
|
SLIDER_HEIGHT: 30,
|
||
|
TRACK_HEIGHT: 24
|
||
|
},
|
||
|
_defaultConfig: function () {
|
||
|
return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), {
|
||
7 years ago
|
baseCls: "bi-single-slider bi-slider-track",
|
||
7 years ago
|
digit: ""
|
||
7 years ago
|
});
|
||
|
},
|
||
|
_init: function () {
|
||
|
BI.SingleSlider.superclass._init.apply(this, arguments);
|
||
|
|
||
7 years ago
|
var self = this, o = this.options;
|
||
7 years ago
|
var digitExist = (o.digit === "") ? false : true;
|
||
7 years ago
|
var c = this._constant;
|
||
|
this.enable = false;
|
||
|
this.value = "";
|
||
|
|
||
|
this.grayTrack = BI.createWidget({
|
||
|
type: "bi.layout",
|
||
|
cls: "gray-track",
|
||
|
height: 6
|
||
|
});
|
||
|
this.blueTrack = BI.createWidget({
|
||
|
type: "bi.layout",
|
||
|
cls: "blue-track bi-high-light-background",
|
||
|
height: 6
|
||
|
});
|
||
|
this.track = this._createTrackWrapper();
|
||
|
|
||
|
this.slider = BI.createWidget({
|
||
7 years ago
|
type: "bi.single_slider_button"
|
||
7 years ago
|
});
|
||
|
this.slider.element.draggable({
|
||
|
axis: "x",
|
||
|
containment: this.grayTrack.element,
|
||
|
scroll: false,
|
||
|
drag: function (e, ui) {
|
||
|
var percent = (ui.position.left) * 100 / (self._getGrayTrackLength());
|
||
|
var significantPercent = BI.parseFloat(percent.toFixed(1));//直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。
|
||
|
self._setBlueTrack(significantPercent);
|
||
|
self._setLabelPosition(significantPercent);
|
||
|
var v = self._getValueByPercent(significantPercent);
|
||
7 years ago
|
v = digitExist ? v.toFixed(o.digit) : v;
|
||
7 years ago
|
self.label.setValue(v);
|
||
|
self.value = v;
|
||
7 years ago
|
self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
|
||
7 years ago
|
},
|
||
|
stop: function (e, ui) {
|
||
|
var percent = (ui.position.left) * 100 / (self._getGrayTrackLength());
|
||
|
var significantPercent = BI.parseFloat(percent.toFixed(1));
|
||
|
self._setSliderPosition(significantPercent);
|
||
|
self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
|
||
|
}
|
||
|
});
|
||
|
var sliderVertical = BI.createWidget({
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [this.slider]
|
||
|
}],
|
||
|
hgap: c.SLIDER_WIDTH_HALF,
|
||
|
height: c.SLIDER_HEIGHT
|
||
|
});
|
||
|
sliderVertical.element.click(function (e) {
|
||
|
if (self.enable) {
|
||
|
var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF;
|
||
|
var trackLength = self.track.element[0].scrollWidth;
|
||
|
var percent = 0;
|
||
|
if (offset < 0) {
|
||
|
percent = 0
|
||
|
}
|
||
|
if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) {
|
||
|
percent = offset * 100 / self._getGrayTrackLength();
|
||
|
}
|
||
|
if (offset > (trackLength - c.SLIDER_WIDTH)) {
|
||
|
percent = 100
|
||
|
}
|
||
|
var significantPercent = BI.parseFloat(percent.toFixed(1));
|
||
|
self._setAllPosition(significantPercent);
|
||
|
var v = self._getValueByPercent(significantPercent);
|
||
7 years ago
|
v = digitExist ? v.toFixed(o.digit) : v;
|
||
7 years ago
|
self.label.setValue(v);
|
||
|
self.value = v;
|
||
|
self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
|
||
|
}
|
||
|
});
|
||
|
this.label = BI.createWidget({
|
||
|
type: "bi.sign_editor",
|
||
7 years ago
|
cls: "slider-editor-button bi-border",
|
||
7 years ago
|
errorText: "",
|
||
|
height: c.HEIGHT,
|
||
7 years ago
|
width: c.EDITOR_WIDTH - 2,
|
||
7 years ago
|
allowBlank: false,
|
||
|
validationChecker: function (v) {
|
||
|
return self._checkValidation(v);
|
||
|
},
|
||
|
quitChecker: function (v) {
|
||
|
return self._checkValidation(v);
|
||
|
}
|
||
|
});
|
||
|
this.label.on(BI.SignEditor.EVENT_CONFIRM, function () {
|
||
7 years ago
|
var v = BI.parseFloat(this.getValue());
|
||
|
var percent = self._getPercentByValue(v);
|
||
7 years ago
|
var significantPercent = BI.parseFloat(percent.toFixed(1));
|
||
|
self._setAllPosition(significantPercent);
|
||
7 years ago
|
v = digitExist ? v.toFixed(o.digit) : v;
|
||
|
this.setValue(v);
|
||
|
self.value = v;
|
||
7 years ago
|
self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
|
||
|
});
|
||
|
this._setVisible(false);
|
||
|
BI.createWidget({
|
||
|
type: "bi.absolute",
|
||
|
element: this,
|
||
|
items: [{
|
||
|
el: {
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [{
|
||
|
el: this.track,
|
||
|
width: "100%",
|
||
|
height: c.TRACK_HEIGHT
|
||
|
}]
|
||
|
}],
|
||
|
hgap: 7,
|
||
|
height: c.TRACK_HEIGHT
|
||
|
},
|
||
|
top: 33,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}, {
|
||
|
el: sliderVertical,
|
||
|
top: 30,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}, {
|
||
|
el: {
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [this.label]
|
||
|
}],
|
||
|
rgap: c.EDITOR_WIDTH,
|
||
|
height: c.EDITOR_HEIGHT
|
||
|
},
|
||
|
top: 0,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}]
|
||
|
})
|
||
|
},
|
||
|
|
||
|
_createTrackWrapper: function () {
|
||
|
return BI.createWidget({
|
||
|
type: "bi.absolute",
|
||
|
items: [{
|
||
|
el: {
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [{
|
||
|
el: this.grayTrack,
|
||
|
top: 0,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}, {
|
||
|
el: this.blueTrack,
|
||
|
top: 0,
|
||
|
left: 0,
|
||
|
width: "0%"
|
||
|
}]
|
||
|
}],
|
||
|
hgap: 8,
|
||
|
height: 8
|
||
|
},
|
||
|
top: 8,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}]
|
||
|
})
|
||
|
},
|
||
|
|
||
|
_checkValidation: function (v) {
|
||
7 years ago
|
return BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)
|
||
7 years ago
|
},
|
||
|
|
||
|
_setBlueTrack: function (percent) {
|
||
|
this.blueTrack.element.css({"width": percent + "%"});
|
||
|
},
|
||
|
|
||
|
_setLabelPosition: function (percent) {
|
||
|
this.label.element.css({"left": percent + "%"});
|
||
|
},
|
||
|
|
||
|
_setSliderPosition: function (percent) {
|
||
|
this.slider.element.css({"left": percent + "%"});
|
||
|
},
|
||
|
|
||
|
_setAllPosition: function (percent) {
|
||
|
this._setSliderPosition(percent);
|
||
|
this._setLabelPosition(percent);
|
||
|
this._setBlueTrack(percent);
|
||
|
},
|
||
|
|
||
|
_setVisible: function (visible) {
|
||
|
this.slider.setVisible(visible);
|
||
|
this.label.setVisible(visible);
|
||
|
},
|
||
|
|
||
|
_getGrayTrackLength: function () {
|
||
|
return this.grayTrack.element[0].scrollWidth
|
||
|
},
|
||
|
|
||
|
_getValueByPercent: function (percent) {
|
||
|
var thousandth = BI.parseInt(percent * 10);
|
||
|
return (((this.max - this.min) * thousandth) / 1000 + this.min);
|
||
|
},
|
||
|
|
||
|
_getPercentByValue: function (v) {
|
||
|
return (v - this.min) * 100 / (this.max - this.min);
|
||
|
},
|
||
|
|
||
|
getValue: function () {
|
||
|
return this.value;
|
||
|
},
|
||
|
|
||
|
setValue: function (v) {
|
||
7 years ago
|
var o = this.options;
|
||
7 years ago
|
var digitExist = (o.digit === "") ? false : true;
|
||
7 years ago
|
var value = BI.parseFloat(v);
|
||
7 years ago
|
value = digitExist ? value.toFixed(o.digit) : value;
|
||
7 years ago
|
if ((!isNaN(value))) {
|
||
|
if (this._checkValidation(value)) {
|
||
|
this.value = value;
|
||
|
}
|
||
|
if (value > this.max) {
|
||
|
this.value = this.max;
|
||
|
}
|
||
|
if (value < this.min) {
|
||
|
this.value = this.min;
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
setMinAndMax: function (v) {
|
||
|
var minNumber = BI.parseFloat(v.min);
|
||
|
var maxNumber = BI.parseFloat(v.max);
|
||
|
if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) {
|
||
|
this.min = minNumber;
|
||
|
this.max = maxNumber;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
reset: function () {
|
||
|
this._setVisible(false);
|
||
|
this.enable = false;
|
||
|
this.value = "";
|
||
|
this.min = 0;
|
||
|
this.max = 0;
|
||
|
this._setBlueTrack(0);
|
||
|
},
|
||
|
|
||
|
populate: function () {
|
||
|
if (!isNaN(this.min) && !isNaN(this.max)) {
|
||
|
this._setVisible(true);
|
||
|
this.enable = true;
|
||
|
this.label.setErrorText(BI.i18nText("BI-Please_Enter") + this.min + "-" + this.max + BI.i18nText("BI-Basic_De") + BI.i18nText("BI-Basic_Number"));
|
||
|
if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) {
|
||
|
this.label.setValue(this.value);
|
||
|
this._setAllPosition(this._getPercentByValue(this.value));
|
||
|
} else {
|
||
|
this.label.setValue(this.max);
|
||
|
this._setAllPosition(100);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
7 years ago
|
});
|
||
7 years ago
|
BI.SingleSlider.EVENT_CHANGE = "EVENT_CHANGE";
|
||
|
BI.shortcut("bi.single_slider", BI.SingleSlider);/**
|
||
7 years ago
|
* Created by Urthur on 2017/9/12.
|
||
|
*/
|
||
|
BI.SingleSliderLabel = BI.inherit(BI.Widget, {
|
||
|
_constant: {
|
||
|
EDITOR_WIDTH: 90,
|
||
|
EDITOR_HEIGHT: 30,
|
||
|
HEIGHT: 28,
|
||
|
SLIDER_WIDTH_HALF: 15,
|
||
|
SLIDER_WIDTH: 30,
|
||
|
SLIDER_HEIGHT: 30,
|
||
|
TRACK_HEIGHT: 24
|
||
|
},
|
||
|
_defaultConfig: function () {
|
||
|
return BI.extend(BI.SingleSliderLabel.superclass._defaultConfig.apply(this, arguments), {
|
||
|
baseCls: "bi-single-slider bi-slider-track",
|
||
|
digit: "",
|
||
|
unit: ""
|
||
|
});
|
||
|
},
|
||
|
_init: function () {
|
||
|
BI.SingleSliderLabel.superclass._init.apply(this, arguments);
|
||
|
|
||
|
var self = this, o = this.options;
|
||
|
var digitExist = (o.digit === "") ? false : true;
|
||
|
var c = this._constant;
|
||
|
this.enable = false;
|
||
|
this.value = "";
|
||
|
|
||
|
this.grayTrack = BI.createWidget({
|
||
|
type: "bi.layout",
|
||
|
cls: "gray-track",
|
||
|
height: 6
|
||
|
});
|
||
|
this.blueTrack = BI.createWidget({
|
||
|
type: "bi.layout",
|
||
|
cls: "blue-track bi-high-light-background",
|
||
|
height: 6
|
||
|
});
|
||
|
this.track = this._createTrackWrapper();
|
||
|
|
||
|
this.slider = BI.createWidget({
|
||
|
type: "bi.single_slider_button"
|
||
|
});
|
||
|
this.slider.element.draggable({
|
||
|
axis: "x",
|
||
|
containment: this.grayTrack.element,
|
||
|
scroll: false,
|
||
|
drag: function (e, ui) {
|
||
|
var percent = (ui.position.left) * 100 / (self._getGrayTrackLength());
|
||
|
var significantPercent = BI.parseFloat(percent.toFixed(1));//直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。
|
||
|
self._setBlueTrack(significantPercent);
|
||
|
self._setLabelPosition(significantPercent);
|
||
|
var v = self._getValueByPercent(significantPercent);
|
||
|
v = digitExist ? v.toFixed(o.digit) : v;
|
||
|
self.label.setText(v + o.unit);
|
||
|
self.value = v;
|
||
|
self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE);
|
||
|
},
|
||
|
stop: function (e, ui) {
|
||
|
var percent = (ui.position.left) * 100 / (self._getGrayTrackLength());
|
||
|
var significantPercent = BI.parseFloat(percent.toFixed(1));
|
||
|
self._setSliderPosition(significantPercent);
|
||
|
self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE);
|
||
|
}
|
||
|
});
|
||
|
var sliderVertical = BI.createWidget({
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [this.slider]
|
||
|
}],
|
||
|
hgap: c.SLIDER_WIDTH_HALF,
|
||
|
height: c.SLIDER_HEIGHT
|
||
|
});
|
||
|
sliderVertical.element.click(function (e) {
|
||
|
if (self.enable) {
|
||
|
var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF;
|
||
|
var trackLength = self.track.element[0].scrollWidth;
|
||
|
var percent = 0;
|
||
|
if (offset < 0) {
|
||
|
percent = 0
|
||
|
}
|
||
|
if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) {
|
||
|
percent = offset * 100 / self._getGrayTrackLength();
|
||
|
}
|
||
|
if (offset > (trackLength - c.SLIDER_WIDTH)) {
|
||
|
percent = 100
|
||
|
}
|
||
|
var significantPercent = BI.parseFloat(percent.toFixed(1));
|
||
|
self._setAllPosition(significantPercent);
|
||
|
var v = self._getValueByPercent(significantPercent);
|
||
|
v = digitExist ? v.toFixed(o.digit) : v;
|
||
|
self.label.setText(v + o.unit);
|
||
|
self.value = v;
|
||
|
self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE);
|
||
|
}
|
||
|
});
|
||
|
this.label = BI.createWidget({
|
||
|
type: "bi.label",
|
||
|
height: c.HEIGHT,
|
||
|
width: c.EDITOR_WIDTH - 2
|
||
|
});
|
||
|
|
||
|
this._setVisible(false);
|
||
|
BI.createWidget({
|
||
|
type: "bi.absolute",
|
||
|
element: this,
|
||
|
items: [{
|
||
|
el: {
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [{
|
||
|
el: this.track,
|
||
|
width: "100%",
|
||
|
height: c.TRACK_HEIGHT
|
||
|
}]
|
||
|
}],
|
||
|
hgap: 7,
|
||
|
height: c.TRACK_HEIGHT
|
||
|
},
|
||
|
top: 33,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}, {
|
||
|
el: sliderVertical,
|
||
|
top: 30,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}, {
|
||
|
el: {
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [this.label]
|
||
|
}],
|
||
|
rgap: c.EDITOR_WIDTH,
|
||
|
height: c.EDITOR_HEIGHT
|
||
|
},
|
||
|
top: 10,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}]
|
||
|
})
|
||
|
},
|
||
|
|
||
|
_createTrackWrapper: function () {
|
||
|
return BI.createWidget({
|
||
|
type: "bi.absolute",
|
||
|
items: [{
|
||
|
el: {
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [{
|
||
|
el: this.grayTrack,
|
||
|
top: 0,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}, {
|
||
|
el: this.blueTrack,
|
||
|
top: 0,
|
||
|
left: 0,
|
||
|
width: "0%"
|
||
|
}]
|
||
|
}],
|
||
|
hgap: 8,
|
||
|
height: 8
|
||
|
},
|
||
|
top: 8,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}]
|
||
|
})
|
||
|
},
|
||
|
|
||
|
_checkValidation: function (v) {
|
||
|
return BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)
|
||
|
},
|
||
|
|
||
|
_setBlueTrack: function (percent) {
|
||
|
this.blueTrack.element.css({"width": percent + "%"});
|
||
|
},
|
||
|
|
||
|
_setLabelPosition: function (percent) {
|
||
|
this.label.element.css({"left": percent + "%"});
|
||
|
},
|
||
|
|
||
|
_setSliderPosition: function (percent) {
|
||
|
this.slider.element.css({"left": percent + "%"});
|
||
|
},
|
||
|
|
||
|
_setAllPosition: function (percent) {
|
||
|
this._setSliderPosition(percent);
|
||
|
this._setLabelPosition(percent);
|
||
|
this._setBlueTrack(percent);
|
||
|
},
|
||
|
|
||
|
_setVisible: function (visible) {
|
||
|
this.slider.setVisible(visible);
|
||
|
this.label.setVisible(visible);
|
||
|
},
|
||
|
|
||
|
_getGrayTrackLength: function () {
|
||
|
return this.grayTrack.element[0].scrollWidth
|
||
|
},
|
||
|
|
||
|
_getValueByPercent: function (percent) {
|
||
|
var thousandth = BI.parseInt(percent * 10);
|
||
|
return (((this.max - this.min) * thousandth) / 1000 + this.min);
|
||
|
},
|
||
|
|
||
|
_getPercentByValue: function (v) {
|
||
|
return (v - this.min) * 100 / (this.max - this.min);
|
||
|
},
|
||
|
|
||
|
getValue: function () {
|
||
|
return this.value;
|
||
|
},
|
||
|
|
||
|
setValue: function (v) {
|
||
|
var o = this.options;
|
||
|
var digitExist = (o.digit === "") ? false : true;
|
||
|
var value = BI.parseFloat(v);
|
||
|
value = digitExist ? value.toFixed(o.digit) : value;
|
||
|
if ((!isNaN(value))) {
|
||
|
if (this._checkValidation(value)) {
|
||
|
this.value = value;
|
||
|
}
|
||
|
if (value > this.max) {
|
||
|
this.value = this.max;
|
||
|
}
|
||
|
if (value < this.min) {
|
||
|
this.value = this.min;
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
setMinAndMax: function (v) {
|
||
|
var minNumber = BI.parseFloat(v.min);
|
||
|
var maxNumber = BI.parseFloat(v.max);
|
||
|
if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) {
|
||
|
this.min = minNumber;
|
||
|
this.max = maxNumber;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
reset: function () {
|
||
|
this._setVisible(false);
|
||
|
this.enable = false;
|
||
|
this.value = "";
|
||
|
this.min = 0;
|
||
|
this.max = 0;
|
||
|
this._setBlueTrack(0);
|
||
|
},
|
||
|
|
||
|
populate: function () {
|
||
|
var o = this.options;
|
||
|
if (!isNaN(this.min) && !isNaN(this.max)) {
|
||
|
this._setVisible(true);
|
||
|
this.enable = true;
|
||
|
if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) {
|
||
|
this.label.setValue(this.value + o.unit);
|
||
|
this._setAllPosition(this._getPercentByValue(this.value));
|
||
|
} else {
|
||
|
this.label.setValue(this.max + o.unit);
|
||
|
this._setAllPosition(100);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
BI.SingleSliderLabel.EVENT_CHANGE = "EVENT_CHANGE";
|
||
|
BI.shortcut("bi.single_slider_label", BI.SingleSliderLabel);/**
|
||
7 years ago
|
* normal single slider
|
||
|
* Created by Young on 2017/6/21.
|
||
7 years ago
|
*/
|
||
7 years ago
|
BI.SingleSliderNormal = BI.inherit(BI.Widget, {
|
||
|
|
||
|
_constant: {
|
||
|
EDITOR_WIDTH: 90,
|
||
|
EDITOR_HEIGHT: 30,
|
||
|
HEIGHT: 28,
|
||
|
SLIDER_WIDTH_HALF: 15,
|
||
|
SLIDER_WIDTH: 30,
|
||
|
SLIDER_HEIGHT: 30,
|
||
|
TRACK_HEIGHT: 24
|
||
|
},
|
||
|
|
||
|
props: {
|
||
|
baseCls: "bi-single-button bi-button-track",
|
||
|
minMax: {
|
||
|
min: 0,
|
||
|
max: 100
|
||
7 years ago
|
},
|
||
7 years ago
|
color: "#3f8ce8"
|
||
|
},
|
||
|
|
||
|
render: function () {
|
||
|
var self = this;
|
||
|
var c = this._constant;
|
||
|
var track = this._createTrack();
|
||
|
this.slider = BI.createWidget({
|
||
7 years ago
|
type: "bi.single_slider_button"
|
||
7 years ago
|
});
|
||
|
this.slider.element.draggable({
|
||
|
axis: "x",
|
||
|
containment: this.grayTrack.element,
|
||
|
scroll: false,
|
||
|
drag: function (e, ui) {
|
||
|
var percent = (ui.position.left) * 100 / (self._getGrayTrackLength());
|
||
|
var significantPercent = BI.parseFloat(percent.toFixed(1));//直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。
|
||
|
self._setBlueTrack(significantPercent);
|
||
|
var v = self._getValueByPercent(significantPercent);
|
||
|
self.value = v;
|
||
|
self.fireEvent(BI.SingleSliderNormal.EVENT_DRAG, v);
|
||
|
},
|
||
|
stop: function (e, ui) {
|
||
|
var percent = (ui.position.left) * 100 / (self._getGrayTrackLength());
|
||
|
var significantPercent = BI.parseFloat(percent.toFixed(1));
|
||
|
self._setSliderPosition(significantPercent);
|
||
|
self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
|
||
7 years ago
|
}
|
||
7 years ago
|
});
|
||
|
|
||
|
var sliderVertical = BI.createWidget({
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [this.slider]
|
||
|
}],
|
||
|
hgap: c.SLIDER_WIDTH_HALF,
|
||
|
height: c.SLIDER_HEIGHT
|
||
|
});
|
||
|
sliderVertical.element.click(function (e) {
|
||
|
if (self.enable) {
|
||
|
var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF;
|
||
|
var trackLength = self.track.element[0].scrollWidth;
|
||
|
var percent = 0;
|
||
|
if (offset < 0) {
|
||
|
percent = 0
|
||
7 years ago
|
}
|
||
7 years ago
|
if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) {
|
||
|
percent = offset * 100 / self._getGrayTrackLength();
|
||
7 years ago
|
}
|
||
7 years ago
|
if (offset > (trackLength - c.SLIDER_WIDTH)) {
|
||
|
percent = 100
|
||
7 years ago
|
}
|
||
7 years ago
|
var significantPercent = BI.parseFloat(percent.toFixed(1));
|
||
|
self._setAllPosition(significantPercent);
|
||
|
var v = self._getValueByPercent(significantPercent);
|
||
|
self.value = v;
|
||
|
self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
|
||
7 years ago
|
}
|
||
7 years ago
|
});
|
||
|
|
||
|
return {
|
||
|
type: "bi.absolute",
|
||
|
element: this,
|
||
|
items: [{
|
||
|
el: {
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [{
|
||
|
el: track,
|
||
|
width: "100%",
|
||
|
height: c.TRACK_HEIGHT
|
||
|
}]
|
||
|
}],
|
||
|
hgap: 7,
|
||
|
height: c.TRACK_HEIGHT
|
||
|
},
|
||
|
top: 3,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}, {
|
||
|
el: sliderVertical,
|
||
|
top: 0,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}]
|
||
|
}
|
||
|
},
|
||
|
|
||
|
_createTrack: function () {
|
||
|
var self = this;
|
||
|
var c = this._constant;
|
||
|
this.grayTrack = BI.createWidget({
|
||
|
type: "bi.layout",
|
||
|
cls: "gray-track",
|
||
|
height: 6
|
||
|
});
|
||
|
this.blueTrack = BI.createWidget({
|
||
|
type: "bi.layout",
|
||
|
cls: "blue-track",
|
||
|
height: 6
|
||
|
});
|
||
|
this.blueTrack.element.css({"background-color": this.options.color});
|
||
|
|
||
|
return {
|
||
|
type: "bi.absolute",
|
||
|
items: [{
|
||
|
el: {
|
||
|
type: "bi.vertical",
|
||
|
items: [{
|
||
|
type: "bi.absolute",
|
||
|
items: [{
|
||
|
el: this.grayTrack,
|
||
|
top: 0,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}, {
|
||
|
el: this.blueTrack,
|
||
|
top: 0,
|
||
|
left: 0,
|
||
|
width: "0%"
|
||
|
}]
|
||
|
}],
|
||
|
hgap: 8,
|
||
|
height: 8
|
||
|
},
|
||
|
top: 8,
|
||
|
left: 0,
|
||
|
width: "100%"
|
||
|
}],
|
||
|
ref: function (ref) {
|
||
|
self.track = ref;
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
|
},
|
||
|
|
||
|
_checkValidation: function (v) {
|
||
|
return !(BI.isNull(v) || v < this.min || v > this.max)
|
||
|
},
|
||
|
|
||
|
_setBlueTrack: function (percent) {
|
||
|
this.blueTrack.element.css({"width": percent + "%"});
|
||
|
},
|
||
|
|
||
|
_setSliderPosition: function (percent) {
|
||
|
this.slider.element.css({"left": percent + "%"});
|
||
|
},
|
||
|
|
||
|
_setAllPosition: function (percent) {
|
||
|
this._setSliderPosition(percent);
|
||
|
this._setBlueTrack(percent);
|
||
|
},
|
||
|
|
||
|
_setVisible: function (visible) {
|
||
|
this.slider.setVisible(visible);
|
||
|
},
|
||
|
|
||
|
_getGrayTrackLength: function () {
|
||
|
return this.grayTrack.element[0].scrollWidth
|
||
|
},
|
||
|
|
||
|
_getValueByPercent: function (percent) {
|
||
|
var thousandth = BI.parseInt(percent * 10);
|
||
|
return (((this.max - this.min) * thousandth) / 1000 + this.min);
|
||
|
},
|
||
|
|
||
|
_getPercentByValue: function (v) {
|
||
|
return (v - this.min) * 100 / (this.max - this.min);
|
||
|
},
|
||
|
|
||
|
getValue: function () {
|
||
|
return this.value;
|
||
|
},
|
||
|
|
||
|
setValue: function (v) {
|
||
|
var value = BI.parseFloat(v);
|
||
|
if ((!isNaN(value))) {
|
||
|
if (this._checkValidation(value)) {
|
||
|
this.value = value;
|
||
7 years ago
|
}
|
||
7 years ago
|
if (value > this.max) {
|
||
|
this.value = this.max;
|
||
7 years ago
|
}
|
||
7 years ago
|
if (value < this.min) {
|
||
|
this.value = this.min;
|
||
7 years ago
|
}
|
||
7 years ago
|
}
|
||
|
},
|
||
|
|
||
|
setMinAndMax: function (v) {
|
||
|
var minNumber = BI.parseFloat(v.min);
|
||
|
var maxNumber = BI.parseFloat(v.max);
|
||
|
if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) {
|
||
|
this.min = minNumber;
|
||
|
this.max = maxNumber;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
reset: function () {
|
||
|
this._setVisible(false);
|
||
|
this.enable = false;
|
||
|
this.value = "";
|
||
|
this.min = 0;
|
||
|
this.max = 0;
|
||
|
this._setBlueTrack(0);
|
||
|
},
|
||
|
|
||
|
populate: function () {
|
||
|
if (!isNaN(this.min) && !isNaN(this.max)) {
|
||
|
this._setVisible(true);
|
||
|
this.enable = true;
|
||
|
if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) {
|
||
|
this._setAllPosition(this._getPercentByValue(this.value));
|
||
7 years ago
|
} else {
|
||
7 years ago
|
this._setAllPosition(100);
|
||
7 years ago
|
}
|
||
|
}
|
||
7 years ago
|
}
|
||
|
});
|
||
|
BI.SingleSliderNormal.EVENT_DRAG = "EVENT_DRAG";
|
||
7 years ago
|
BI.shortcut("bi.single_slider_normal", BI.SingleSliderNormal);
|