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

Issue 41: Adding option showScale (or data-slider-showscale) to show min and max slider #44

Open
wants to merge 1 commit 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
18 changes: 18 additions & 0 deletions css/simple-slider-volume.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@
background: -webkit-linear-gradient(top, #c5c5c5, #a2a2a2);
background: linear-gradient(top, #c5c5c5, #a2a2a2);
}

.slider-volume > .scale {
width: 100%;
color: #888;
font-size: small;
}

.slider-volume > .scale > .min-scale {
float: left;
font-weight: bold;
color: #622;
}

.slider-volume > .scale > .max-scale {
float: right;
font-weight: bold;
color: #262;
}
13 changes: 13 additions & 0 deletions css/simple-slider.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,16 @@
border-color: #496805;
}

.slider > .scale {
width: 100%;
color: #888;
font-size: small;
}

.slider > .scale > .min-scale {
float: left;
}

.slider > .scale > .max-scale {
float: right;
}
1 change: 1 addition & 0 deletions css/simple-slider.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ <h1>jQuery Simple Slider Examples</h1>
<h2>Basic Example</h2>
<input type="text" data-slider="true">

<h2>Basic Example (with Scale) </h2>
<input type="text" data-slider="true" data-slider-showScale="true">

<h2>Basic Example (Themed)</h2>
<input type="text" data-slider="true" data-slider-theme="volume">

<h2>Basic Example (Themed with Scale)</h2>
<input type="text" data-slider="true" data-slider-theme="volume" data-slider-showScale="true">

<h2>Predefined Value</h2>
<input type="text" value="0.2" data-slider="true">

Expand All @@ -41,6 +47,9 @@ <h2>Steps</h2>
<h2>Range</h2>
<input type="text" data-slider="true" data-slider-range="10,1000">

<h2>Range (with Scale)</h2>
<input type="text" data-slider="true" data-slider-range="10,1000" data-slider-showScale="true">

<h2>Range &amp; Steps</h2>
<input type="text" data-slider="true" data-slider-range="100,500" data-slider-step="100">

Expand Down
27 changes: 26 additions & 1 deletion js/simple-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
jQuery Simple Slider

Copyright (c) 2012 James Smith (http://loopj.com)
Copyright (c) 2013 Erik J. Nedwidek (http://github.com/nedwidek)

Licensed under the MIT license (http://mit-license.org/)
*/
Expand All @@ -23,7 +24,8 @@ var __slice = [].slice,
classPrefix: null,
classSuffix: null,
theme: null,
highlight: false
highlight: false,
showScale: false
};
this.settings = $.extend({}, this.defaultOptions, options);
if (this.settings.theme) {
Expand Down Expand Up @@ -106,6 +108,20 @@ var __slice = [].slice,
}
this.setSliderPositionFromValue(this.value);
ratio = this.valueToRatio(this.value);
if (this.settings.showScale) {
this.scale = this.createDivElement("scale");
this.minScale = this.createSpanElement("min-scale", this.scale);
this.maxScale = this.createSpanElement("max-scale", this.scale);

range = this.getRange();

this.minScale.html(range.min);
this.maxScale.html(range.max);

this.scale.css('marginTop', function(index, currentValue) {
return (parseInt(currentValue, 10) + this.previousSibling.offsetHeight / 2) + 'px';
});
}
this.input.trigger("slider:ready", {
value: this.value,
ratio: ratio,
Expand All @@ -125,6 +141,12 @@ var __slice = [].slice,
return item;
};

SimpleSlider.prototype.createSpanElement = function(classname, parent) {
var item;
item = $("<span>").addClass(classname).appendTo(parent);
return item;
};

SimpleSlider.prototype.setRatio = function(ratio) {
var value;
ratio = Math.min(1, ratio);
Expand Down Expand Up @@ -357,6 +379,9 @@ var __slice = [].slice,
if ($el.data("slider-animate") != null) {
settings.animate = $el.data("slider-animate");
}
if ($el.data("slider-showscale") != null) {
settings.showScale = $el.data("slider-showscale");
}
return $el.simpleSlider(settings);
});
});
Expand Down
12 changes: 1 addition & 11 deletions js/simple-slider.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.