1+ import "./surveyjs_importer.js" ;
2+
3+ var widget = {
4+ name : "nouislider" ,
5+ isFit : function ( question ) { return question . getType ( ) === 'nouislider' ; } ,
6+ htmlTemplate : "<div></div>" ,
7+ activatedByChanged : function ( activatedBy ) {
8+ Survey . JsonObject . metaData . addClass ( "nouislider" , [ ] , null , "empty" ) ;
9+ Survey . JsonObject . metaData . addProperties ( "nouislider" , [ { name : "rangeMin:number" , default : 0 } , { name : "rangeMax:number" , default : 100 } ,
10+ { name : "defaultRangeMin:number" , default : 30 } , { name : "defaultRangeMax:number" , default : 70 } ] ) ;
11+ } ,
12+ afterRender : function ( question , el ) {
13+ var startValue = question . value ;
14+ if ( ! startValue || startValue . length != 2 ) {
15+ startValue = [ question . defaultRangeMin , question . defaultRangeMax ] ;
16+ }
17+ if ( startValue [ 0 ] < question . rangeMin ) startValue [ 0 ] = question . rangeMin ;
18+ if ( startValue [ 0 ] > question . rangeMax ) startValue [ 0 ] = question . rangeMax ;
19+ if ( startValue [ 1 ] < startValue [ 0 ] ) startValue [ 1 ] = startValue [ 0 ] ;
20+ if ( startValue [ 1 ] > question . rangeMax ) startValue [ 1 ] = question . rangeMax ;
21+ question . value = startValue ;
22+
23+ var slider = noUiSlider . create ( el , {
24+ start : startValue ,
25+ connect : true ,
26+ pips : {
27+ mode : 'steps' ,
28+ stepped : true ,
29+ density : 4
30+ } ,
31+ range : {
32+ 'min' : question . rangeMin ,
33+ 'max' : question . rangeMax
34+ }
35+ } ) ;
36+ slider . on ( 'set' , function ( ) {
37+ question . value = slider . get ( ) ;
38+ } ) ;
39+ var updateValueHandler = function ( ) {
40+ slider . set ( question . value ) ;
41+ } ;
42+ question . noUiSlider = slider ;
43+ question . valueChangedCallback = updateValueHandler ;
44+ } ,
45+ willUnmount : function ( question , el ) {
46+ question . noUiSlider . destroy ( ) ;
47+ question . noUiSlider = null ;
48+ }
49+ }
50+
51+ Survey . CustomWidgetCollection . Instance . addCustomWidget ( widget , "customtype" ) ;
0 commit comments