Skip to content
This repository was archived by the owner on May 25, 2019. It is now read-only.

Commit 44953c3

Browse files
committed
Merge pull request #67 from tony0918/master
Added tick marks support for horizontal slider bar.
2 parents ce9cd12 + e746693 commit 44953c3

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

demo/css/slider.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.ui-slider-tick {
2+
position: absolute;
3+
background-color: #aaa;
4+
width: 2px;
5+
height: 8px;
6+
top: 16px;
7+
}

demo/demo.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
66
<title>AngularUI - Slider demo</title>
77
<base href=".."></base>
8-
<link rel="stylesheet" href="bower_components/jquery-ui/themes/smoothness/jquery-ui.css">
8+
<link rel="stylesheet" href="bower_components/jquery-ui/themes/smoothness/jquery-ui.css">
9+
<link rel="stylesheet" href="demo/css/slider.css">
910
<style>
1011
body {
1112
padding: 2em;
@@ -188,10 +189,16 @@ <h1>AngularUI Slider demo</h1>
188189
</pre>
189190
</div>
190191
</li>
192+
<li>
193+
<div class="sliderExample"><a name="ex13"></a>
194+
<strong>Slider with tick marks. Support horizontal slider bar so far. 'tick' and 'step' attributes are required.</strong>
195+
<div ui-slider data-min="0" data-max="20" data-step="5" data-tick ng-model="demoVals.sliderExample13"></div>
196+
</div>
197+
</li>
191198
</ol>
192-
<script type="text/javascript" src="bower_components/jquery/jquery.min.js"></script>
193-
<script type="text/javascript" src="bower_components/jquery-ui/ui/minified/jquery-ui.min.js"></script>
194-
<script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
199+
<script type="text/javascript" src="bower_components/jquery/dist/jquery.min.js"></script>
200+
<script type="text/javascript" src="bower_components/jquery-ui/ui/minified/jquery-ui.min.js"></script>
201+
<script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
195202
<script type="text/javascript" src="src/slider.js"></script>
196203
<script>
197204
var app = angular.module('sliderDemoApp', ['ui.slider']);

src/slider.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ angular.module('ui.slider', []).value('uiSliderConfig',{}).directive('uiSlider',
55
uiSliderConfig = uiSliderConfig || {};
66
return {
77
require: 'ngModel',
8-
compile: function () {
9-
return function (scope, elm, attrs, ngModel) {
8+
compile: function() {
9+
var preLink = function (scope, elm, attrs, ngModel) {
1010

1111
function parseNumber(n, decimals) {
1212
return (decimals) ? parseFloat(n) : parseInt(n, 10);
@@ -135,6 +135,30 @@ angular.module('ui.slider', []).value('uiSliderConfig',{}).directive('uiSlider',
135135
destroy();
136136
});
137137
};
138+
139+
var postLink = function (scope, element, attrs, ngModel) {
140+
// Add tick marks if 'tick' and 'step' attributes have been setted on element.
141+
// Support horizontal slider bar so far. 'tick' and 'step' attributes are required.
142+
var options = angular.extend({}, scope.$eval(attrs.uiSlider));
143+
var properties = ['max', 'step', 'tick'];
144+
angular.forEach(properties, function(property) {
145+
if (angular.isDefined(attrs[property])) {
146+
options[property] = attrs[property];
147+
}
148+
});
149+
if (angular.isDefined(options['tick']) && angular.isDefined(options['step'])) {
150+
var total = parseInt(parseInt(options['max'])/parseInt(options['step']));
151+
for (var i = total; i >= 0; i--) {
152+
var left = ((i / total) * 100) + '%';
153+
$("<div/>").addClass("ui-slider-tick").appendTo(element).css({left: left});
154+
};
155+
}
156+
}
157+
158+
return {
159+
pre: preLink,
160+
post: postLink
161+
};
138162
}
139163
};
140164
}]);

0 commit comments

Comments
 (0)