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

Commit 69821d7

Browse files
committed
Added tick marks support for horizontal slider bar. Changed demo file to present a demo usage for the slider with tick marks. Fixed jquery include error when jquery lib updated to 2.x.
1 parent ce9cd12 commit 69821d7

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-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: 27 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,31 @@ angular.module('ui.slider', []).value('uiSliderConfig',{}).directive('uiSlider',
135135
destroy();
136136
});
137137
};
138+
139+
return {
140+
pre: preLink,
141+
post: postLink
142+
};
138143
}
139144
};
140145
}]);
146+
147+
function postLink(scope, element, attrs, ngModel) {
148+
// Add tick marks if 'tick' and 'step' attributes have been setted on element.
149+
// Support horizontal slider bar so far. 'tick' and 'step' attributes are required.
150+
var options = angular.extend({}, scope.$eval(attrs.uiSlider));
151+
var properties = ['max', 'step', 'tick'];
152+
angular.forEach(properties, function(property) {
153+
if (angular.isDefined(attrs[property])) {
154+
options[property] = attrs[property];
155+
}
156+
});
157+
if (angular.isDefined(options['tick']) && angular.isDefined(options['step'])) {
158+
var total = parseInt(parseInt(options['max'])/parseInt(options['step']));
159+
for (var i = total; i >= 0; i--) {
160+
console.log(i);
161+
var left = ((i / total) * 100) + '%';
162+
$("<div/>").addClass("ui-slider-tick").appendTo(element).css({left: left});
163+
};
164+
}
165+
}

0 commit comments

Comments
 (0)