Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support draw scales with not equal spaces. #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions js/jquery.slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,22 @@
if( this.settings.scale && this.settings.scale.length > 0 ){
var str = "";
var s = this.settings.scale;
var prc = Math.round((100/(s.length-1))*10)/10;
for( var i=0; i < s.length; i++ ){
str += '<span style="left: ' + i*prc + '%">' + ( s[i] != '|' ? '<ins>' + s[i] + '</ins>' : '' ) + '</span>';
};
return str;
if (! (s[0] instanceof Object))
{
var prc = Math.round((100/(s.length-1))*10)/10;
for( var i=0; i < s.length; i++ ){
str += '<span style="left: ' + i*prc + '%">' + ( s[i] != '|' ? '<ins>' + s[i] + '</ins>' : '' ) + '</span>';
};
return str;
}
else
{
for( var i=0; i < s.length; i++ ){
var prc = Math.round(100 * (((s[i].position - this.settings.from) / this.settings.interval *10) / 10));
str += '<span style="left: ' + prc + '%">' + ( s[i].label != '|' ? '<ins>' + s[i].label + '</ins>' : '' ) + '</span>';
};
return str;
}
} else return "";

return "";
Expand Down Expand Up @@ -635,30 +646,37 @@
function jSliderPointer(){
Draggable.apply( this, arguments );
}

jSliderPointer.prototype = new Draggable();

jSliderPointer.prototype.oninit = function( ptr, id, _constructor ){
this.uid = id;
this.parent = _constructor;
this.value = {};
this.settings = this.parent.settings;
};

jSliderPointer.prototype.onmousedown = function(evt){
if (this.parent.inputNode.attr("disabled"))
return;
this._parent = {
offset: this.parent.domNode.offset(),
width: this.parent.domNode.width()
};
this.ptr.addDependClass("hover");
this.setIndexOver();
};

jSliderPointer.prototype.onmousemove = function( evt, x ){
if (this.parent.inputNode.attr("disabled"))
return;
var coords = this._getPageCoords( evt );
this._set( this.calc( coords.x ) );
};

jSliderPointer.prototype.onmouseup = function( evt ){
if (this.parent.inputNode.attr("disabled"))
return;
if( this.parent.settings.callback && $.isFunction(this.parent.settings.callback) )
this.parent.settings.callback.call( this.parent, this.parent.getValue() );

Expand Down
16 changes: 15 additions & 1 deletion tests/zero_value.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</script>

<div class="layout-slider" style="width: 100%">
Slider <span style="display: inline-block; width: 400px; padding: 0 5px;"><input id="Slider2" type="slider" name="price" value="-0.5;0.5" /></span> in string
Slider <span style="display: inline-block; width: 400px; padding: 0 5px;"><input id="Slider2" type="slider" name="price" value="-0.5;0.5"/></span> in string
</div>
<script type="text/javascript" charset="utf-8">
jQuery("#Slider2").slider({
Expand All @@ -59,6 +59,20 @@
});
</script>

<div class="layout-slider" style="width: 100%">
Slider <span style="display: inline-block; width: 400px; padding: 0 5px;"><input id="Slider3" type="slider" name="price" value="50" disabled/></span> in string
</div>
<script type="text/javascript" charset="utf-8">
jQuery("#Slider3").slider({
from: -50,
to: 200,
step: 5,
dimension: '%',
skin: 'plastic',
scale: [{label: '-50', position: -50}, {label: '0', position: 0}, {label: '120', position: 120}, {label: '200', position: 200}]
});
</script>

</div>
</body>
</html>