forked from danielcrisp/angular-rangeslider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
258 lines (175 loc) · 11.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='https://fonts.googleapis.com/css?family=Architects+Daughter' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen" />
<link rel="stylesheet" type="text/css" href="stylesheets/pygment_trac.css" media="screen" />
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<title>AngularJS RangeSlider by danielcrisp</title>
</head>
<body>
<header>
<div class="inner">
<h1>AngularJS RangeSlider</h1>
<h2>Simple directive that creates a range slider for Angular, styled to match Bootstrap-styled form elements</h2>
<a href="https://github.com/danielcrisp/angular-rangeslider" class="button"><small>View project on</small>GitHub</a>
</div>
</header>
<div id="content-wrapper">
<div class="inner clearfix">
<section id="main-content">
<h1>
<a name="angular-rangeslider" class="anchor" href="#angular-rangeslider"><span class="octicon octicon-link"></span></a>AngularJS RangeSlider</h1>
<p><em>Current version: 0.0.10</em></p>
<p>Angular RangeSlider is a directive that creates an interactive slider that allows a user to change model values.</p>
<p>It has been styled to match form elements styled by <a href="http://twitter.github.io/bootstrap/">Twitter's Bootstrap CSS framework</a>.</p>
<h4>
<a name="requirements" class="anchor" href="#requirements"><span class="octicon octicon-link"></span></a>Requirements</h4>
<ul>
<li>Angular (v1.0.8+)</li>
<li>jQuery (v1.7+)</li>
</ul>
<h2>
<a name="quick-example" class="anchor" href="#quick-example"><span class="octicon octicon-link"></span></a>Demo</h2>
<p>Take a look at the <a href="demo/">live demo page</a></p>
<p>Or the <a href="demo/legacy.html">legacy Angular demo page</a></p>
<h2>
<a name="quick-example" class="anchor" href="#quick-example"><span class="octicon octicon-link"></span></a>Quick example</h2>
<p>A basic slider with a range of 0 to 100:</p>
<pre><code><div range-slider min="0" max="100" model-min="min" model-max="max"></div>
</code></pre>
<p>As the handles are moved the model values <code>min</code> and <code>max</code> will be updated in the parent controller.</p>
<p><img src="screenshots/slider.png" alt="Default example"></p>
<h2>
<a name="options" class="anchor" href="#options"><span class="octicon octicon-link"></span></a>Options</h2>
<p>Options are set as attributes on the <code><div range-slider></code></p>
<h3>
<a name="-two-way-bindings" class="anchor" href="#-two-way-bindings"><span class="octicon octicon-link"></span></a><code>=</code> two-way bindings</h3>
<p><code>min</code> - the minimum value the user can select (must be a number, can be a model property)</p>
<p><code>max</code> - the maximum value the user can select (must be a number, can be a model property)</p>
<p><code>model-min</code> - the model property for the min value, represents the position of the min handle</p>
<p><code>model-max</code> - the model property for the max value, represents the position of the max handle</p>
<p><code>disabled</code> - model property or boolean, disables the slider when <code>true</code></p>
<h3>
<a name="-attributes" class="anchor" href="#-attributes"><span class="octicon octicon-link"></span></a><code>@</code> attributes</h3>
<p><code>orientation</code> - slider orientation, default: 'horizontal' - options: 'horizontal' | 'vertical' | 'vertical left' | 'vertical right'</p>
<p><code>step</code> - amount to change the value by when moving a handle, default: 0</p>
<p><code>decimal-places</code> - the number of decimal places to round to, default: 0</p>
<p><code>filter</code> - a built-in filter to apply to the displayed values, for example <code>currency</code></p>
<p><code>filter-options</code> - options to pass to the filter</p>
<p><code>pin-handle</code> - disable/hide one handle, default: null - options: 'min' | 'max'</p>
<p><code>prevent-equal-min-max</code> - prevent the <code>min</code> and <code>max</code> values from being equal. The <code>step</code> value is used to set the minimum difference, otherwise a value of <code>1</code> is used.</p>
<h2>
<a name="some-more-examples" class="anchor" href="#some-more-examples"><span class="octicon octicon-link"></span></a>Some more examples</h2>
<h3>
<a name="using-model-properties" class="anchor" href="#using-model-properties"><span class="octicon octicon-link"></span></a>Using model properties</h3>
<p>The following properties are present in the scope:</p>
<pre><code>// set available range
$scope.minPrice = 100;
$scope.maxPrice = 999;
// default the user's values to the available range
$scope.userMinPrice = $scope.minPrice;
$scope.userMaxPrice = $scope.maxPrice;
</code></pre>
<p>So we can include the directive in the HTML like this:</p>
<pre><code><div range-slider min="minPrice" max="maxPrice" model-min="userMinPrice" model-max="userMaxPrice" step="5"></div>
</code></pre>
<p>As the user moves the min and max handles the <code>userMinPrice</code> and <code>userMaxPrice</code> will be updated in increments of <code>5</code> in real-time in the model.</p>
<h3>
<a name="using-filters" class="anchor" href="#using-filters"><span class="octicon octicon-link"></span></a>Using filters</h3>
<p>Continuing from the example above we can format the values displayed to the user as currency.</p>
<pre><code><div range-slider min="minPrice" max="maxPrice" model-min="userMinPrice" model-max="userMaxPrice" step="5" filter="currency"></div>
</code></pre>
<p>This will automatically be localised by Angular, but we can force it to be USD by passing this as an option:</p>
<pre><code><div range-slider min="minPrice" max="maxPrice" model-min="userMinPrice" model-max="userMaxPrice" step="5" filter="currency" filter-options="USD$"></div>
</code></pre>
<p><img src="screenshots/currency.png" alt="Currency example"></p>
<h3>
<a name="making-the-slider-vertical" class="anchor" href="#making-the-slider-vertical"><span class="octicon octicon-link"></span></a>Making the slider vertical</h3>
<p>Simply add one of the following values to the <code>orientation</code> attribute: 'vertical', 'vertical left' or 'vertical right'.</p>
<p>This will create a vertical slider that is centred in it's parent element:</p>
<pre><code><div range-slider min="0" max="100" model-min="min" model-max="max" orientation="vertical"></div>
</code></pre>
<p><img src="screenshots/vertical.png" alt="Vertical example"></p>
<p>To left-align the slider use 'vertical left':</p>
<pre><code><div range-slider min="0" max="100" model-min="min" model-max="max" orientation="vertical left"></div>
</code></pre>
<p>And to right-align the slider use 'vertical right':</p>
<pre><code><div range-slider min="0" max="100" model-min="min" model-max="max" orientation="vertical right"></div>
</code></pre>
<h3>
<a name="disabling-the-slider" class="anchor" href="#disabling-the-slider"><span class="octicon octicon-link"></span></a>Disabling the slider</h3>
<p>If you have a boolean property in your scope you can simply change this value to <code>true</code> to disable the slider:</p>
<pre><code>$scope.sliderDisabled = false;
</code></pre>
<p>And then specify the property using the disabled attribute:</p>
<pre><code><div range-slider min="0" max="100" model-min="min" model-max="max" disabled="sliderDisabled"></div>
// clicking this button will toggle the sliderDisabled value between true and false
<button ng-click="sliderDisabled=!sliderDisabled">Toggle slider disabled status</button>
</code></pre>
<p><img src="screenshots/disabled.png" alt="Disabled example"></p>
<h3>
<a name="pinning-a-handle" class="anchor" href="#pinning-a-handle"><span class="octicon octicon-link"></span></a>Pinning a handle</h3>
<p>If you would like only allow setting one value, effectively creating a single-value silder, set the pin-handle attribute to 'min' or 'max'. You may then omit the corresponding model-xxx property:</p>
<pre><code><div range-slider min="0" max="100" model-max="max" pin-handle="min></div>
</code></pre>
<p><img src="screenshots/pinned.png" alt="Pinned example"></p>
<h2>
<a name="to-do" class="anchor" href="#to-do"><span class="octicon octicon-link"></span></a>To Do</h2>
<ul>
<li>Remove full jQuery dependency</li>
<li>Make it work in older Angular versions</li>
<li>Add option to move values with handles</li>
<li>Improve behaviour when model values are not valid (e.g. min is greater than max)</li>
</ul><h2>
<a name="known-issues" class="anchor" href="#known-issues"><span class="octicon octicon-link"></span></a>Known Issues</h2>
<ul>
<li>The slider restricts the model value when editing outside the slider (e.g. in an ) but the only notification is made to the <code>console</code>
</li>
<li>The min slider handle disappears behind the max slider handle</li>
</ul><h2>
<a name="credits" class="anchor" href="#credits"><span class="octicon octicon-link"></span></a>Credits</h2>
<p>This was originally forked from <a href="http://refreshless.com/">Léon Gersen's</a> brilliant noUiSlider:</p>
<p><a href="https://github.com/leongersen/noUiSlider">https://github.com/leongersen/noUiSlider</a></p>
<h2>
<a name="licence" class="anchor" href="#licence"><span class="octicon octicon-link"></span></a>Licence</h2>
<p>This code is released under the <a href="http://opensource.org/licenses/MIT">MIT Licence</a></p>
<p>Copyright (c) 2013 Daniel Crisp</p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.</p>
</section>
<aside id="sidebar">
<a href="https://github.com/danielcrisp/angular-rangeslider/zipball/master" class="button">
<small>Download</small>
.zip file
</a>
<a href="https://github.com/danielcrisp/angular-rangeslider/tarball/master" class="button">
<small>Download</small>
.tar.gz file
</a>
<p class="repo-owner"><a href="https://github.com/danielcrisp/angular-rangeslider"></a> is maintained by <a href="https://github.com/danielcrisp">danielcrisp</a>.</p>
<p>This page was generated by <a href="https://pages.github.com">GitHub Pages</a> using the Architect theme by <a href="https://twitter.com/jasonlong">Jason Long</a>.</p>
</aside>
</div>
</div>
</body>
</html>