@@ -6,17 +6,19 @@ angular.module('nouislider', []).directive('slider', function () {
66 start : '@' ,
77 step : '@' ,
88 end : '@' ,
9+ callback : '@' ,
910 ngModel : '=' ,
1011 ngFrom : '=' ,
1112 ngTo : '='
1213 } ,
1314 link : function ( scope , element , attrs ) {
14- var fromParsed , parsedValue , slider , toParsed ;
15+ var callback , config , fromParsed , parsedValue , slider , toParsed ;
1516 slider = $ ( element ) ;
17+ callback = scope . callback ? scope . callback : 'slide' ;
1618 if ( scope . ngFrom != null && scope . ngTo != null ) {
1719 fromParsed = null ;
1820 toParsed = null ;
19- slider . noUiSlider ( {
21+ config = {
2022 range : [
2123 scope . start ,
2224 scope . end
@@ -26,22 +28,23 @@ angular.module('nouislider', []).directive('slider', function () {
2628 scope . ngTo || scope . end
2729 ] ,
2830 step : scope . step || 1 ,
29- connect : true ,
30- slide : function ( ) {
31- var from , to , _ref ;
32- _ref = slider . val ( ) , from = _ref [ 0 ] , to = _ref [ 1 ] ;
33- fromParsed = parseFloat ( from ) ;
34- toParsed = parseFloat ( to ) ;
35- scope . values = [
36- fromParsed ,
37- toParsed
38- ] ;
39- return scope . $apply ( function ( ) {
40- scope . ngFrom = fromParsed ;
41- return scope . ngTo = toParsed ;
42- } ) ;
43- }
44- } ) ;
31+ connect : true
32+ } ;
33+ config [ callback ] = function ( ) {
34+ var from , to , _ref ;
35+ _ref = slider . val ( ) , from = _ref [ 0 ] , to = _ref [ 1 ] ;
36+ fromParsed = parseFloat ( from ) ;
37+ toParsed = parseFloat ( to ) ;
38+ scope . values = [
39+ fromParsed ,
40+ toParsed
41+ ] ;
42+ return scope . $apply ( function ( ) {
43+ scope . ngFrom = fromParsed ;
44+ return scope . ngTo = toParsed ;
45+ } ) ;
46+ } ;
47+ slider . noUiSlider ( config ) ;
4548 scope . $watch ( 'ngFrom' , function ( newVal , oldVal ) {
4649 if ( newVal !== fromParsed ) {
4750 return slider . val ( [
@@ -60,21 +63,22 @@ angular.module('nouislider', []).directive('slider', function () {
6063 } ) ;
6164 } else {
6265 parsedValue = null ;
63- slider . noUiSlider ( {
66+ config = {
6467 range : [
6568 scope . start ,
6669 scope . end
6770 ] ,
6871 start : scope . ngModel || scope . start ,
6972 step : scope . step || 1 ,
70- handles : 1 ,
71- slide : function ( ) {
72- parsedValue = slider . val ( ) ;
73- return scope . $apply ( function ( ) {
74- return scope . ngModel = parseFloat ( parsedValue ) ;
75- } ) ;
76- }
77- } ) ;
73+ handles : 1
74+ } ;
75+ config [ callback ] = function ( ) {
76+ parsedValue = slider . val ( ) ;
77+ return scope . $apply ( function ( ) {
78+ return scope . ngModel = parseFloat ( parsedValue ) ;
79+ } ) ;
80+ } ;
81+ slider . noUiSlider ( config ) ;
7882 return scope . $watch ( 'ngModel' , function ( newVal , oldVal ) {
7983 if ( newVal !== parsedValue ) {
8084 return slider . val ( newVal ) ;
0 commit comments