Skip to content

Commit a055c8f

Browse files
committed
code refactoring
1 parent b537eb3 commit a055c8f

File tree

3 files changed

+65
-25
lines changed

3 files changed

+65
-25
lines changed

README.md

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,38 @@ $('.rslider__fox').RangeSliderFox({
7373
grid: true,
7474
gridSnap: false,
7575
gridNum: 40,
76+
onStart: (data) => {
77+
console.log(data.type);
78+
console.log(data.orientation);
79+
console.log(data.theme);
80+
console.log(data.min);
81+
console.log(data.max);
82+
console.log(data.from);
83+
console.log(data.to);
84+
console.log(data.step);
85+
console.log(data.keyStepOne);
86+
console.log(data.keyStepHold);
87+
console.log(data.bar);
88+
console.log(data.tipPrefix);
89+
console.log(data.tipPostfix);
90+
console.log(data.tipMinMax);
91+
console.log(data.tipFromTo);
92+
console.log(data.grid);
93+
console.log(data.gridSnap);
94+
console.log(data.gridNum);
95+
console.log(data.gridStep);
96+
console.log(data.gridRound);
97+
console.log(data.disabled);
98+
},
99+
onChange:(data) => {
100+
console.log(data);
101+
},
102+
onUpdate:(data) => {
103+
console.log(data);
104+
},
105+
onReset:(data) => {
106+
console.log(data);
107+
}
76108
})
77109
```
78110

@@ -87,6 +119,15 @@ max:600,
87119
from:350
88120
})
89121

122+
// unsubscribe from events
123+
124+
obj.update({
125+
onStart:null,
126+
onChange:null,
127+
onUpdate:null,
128+
onReset:null
129+
})
130+
90131
// This piece of code will change range values and set the dot on position 350.
91132

92133
obj.reset()
@@ -111,9 +152,9 @@ obj.destroy()
111152
| max | data-max | 10 (-n, n.n..) | number | Maximal value of the range |
112153
| to | data-to | 2 (-n, n.n..) | number | Second dot position |
113154
| from | data-from | 1 (-n, n.n..) | number | First dot position |
114-
| step | data-step | 0 (0-max) | number | Step of the dot mooving |
115-
| keyStepOne | data-key-step-one | 0(0-max) | number | Step of the dot mooving on keyboard key single pressing |
116-
| keyStepHold | data-key-step-hold | 0(0-max) | number | Step of the dot mooving on keyboard key holding |
155+
| step | data-step | 0 (max-mun) | number | Step of the dot mooving |
156+
| keyStepOne | data-key-step-one | 0 (max-mun) | number | Step of the dot mooving on keyboard key single pressing |
157+
| keyStepHold | data-key-step-hold | 0 (max-mun) | number | Step of the dot mooving on keyboard key holding |
117158
| bar | data-bar | false | boolean | Progrees-bar view (shown or hidden) |
118159
| tipPrefix | data-tip-prefix | '' (char…) | string | Prefix for hints (15 characters maximum) |
119160
| tipPostfix | data-tip-postfix | '' (char…) | string | Postfix for hints (15 characters maximum) |
@@ -125,14 +166,16 @@ obj.destroy()
125166
| gridStep | data-grid-step | 0 (n, n.n..) | number | Amount of steps in the interval |
126167
| gridRound | data-grid-round | 0 (n) | number | Fractional rounding |
127168
| disabled | data-disabled | false | boolean | Slider enabled or disabled |
128-
| onStart | - | (data) => data | Function | Call a callback function after the first start of the plugin and pass an object of current configuration data as an argument |
129-
| onChange | - | (data) => data | Function | Call a callback function after each user’s interaction with the slider and pass an object of current configuration data as an argument |
130-
| onUpdate | - | (data) => data | Function | Call a callback function after “update” method calling and pass an object of current configuration data as an argument |
131-
| onReset | - | (data) => data | Function | Call a callback function after “reset” method calling and pass an object of current configuration data as an argument |
169+
| onStart | - | null | Function | Call a callback function after the first start of the plugin and pass an object of current configuration data as an argument |
170+
| onChange | - | null | Function | Call a callback function after each user’s interaction with the slider and pass an object of current configuration data as an argument |
171+
| onUpdate | - | null | Function | Call a callback function after “update” method calling and pass an object of current configuration data as an argument |
172+
| onReset | - | null | Function | Call a callback function after “reset” method calling and pass an object of current configuration data as an argument |
132173

133174

134175
## Setup and Scripts ( build the project, start, testing, production)
135176

177+
* Node version v14.18.1
178+
136179
* Install dependencies:
137180
```
138181
npm i

src/components/header/header.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mixin header(options)
1111
header(class=className)
1212
div(class=classComp+'__wrapper')
1313
p(class=classComp+'__version') version: 1.0
14-
a(class=classComp+'__download' href='https://plugins.su/RangeSliderFox.zip') Download
14+
a(class=classComp+'__download' href='https://plugins.su/RangeSliderFox.zip') Download Zip
1515
a(class=classComp+'__github' href='https://github.com/coder1x/MetaLamp_four_task' target="_blank" rel="noopener noreferrer")
1616
svg(height='32' aria-hidden='true' viewBox='0 0 16 16' version='1.1' width='32' data-view-component='true' class='octicon octicon-mark-github v-align-middle')
1717
path(fill-rule='evenodd' d='M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z')

src/plugins/range-slider-fox/mvc/model/model.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,10 @@ class Model extends Observer {
650650

651651
this.onHandle = async () => {
652652

653-
const emptyFun = (data: RangeSliderOptions) => data;
654-
655-
this.onChange = options.onChange ?? emptyFun;
656-
this.onUpdate = options.onUpdate ?? emptyFun;
657-
this.onStart = options.onStart ?? emptyFun;
658-
this.onReset = options.onReset ?? emptyFun;
653+
this.onChange = options.onChange ?? null;
654+
this.onUpdate = options.onUpdate ?? null;
655+
this.onStart = options.onStart ?? null;
656+
this.onReset = options.onReset ?? null;
659657

660658
await this.update(options);
661659

@@ -798,15 +796,16 @@ class Model extends Observer {
798796
if (keyStepHold == null)
799797
keyStepHold = 0;
800798

801-
const validMaxMin = (val: number) => {
802-
if (val > this.max) return this.max;
803-
if (val < 0) return 0;
804-
return val;
799+
const validVal = (val: number) => {
800+
if (val <= this.getRange())
801+
return val;
802+
else
803+
return this.getRange();
805804
};
806805

807-
this.step = validMaxMin(+step);
808-
this.keyStepOne = validMaxMin(+keyStepOne);
809-
this.keyStepHold = validMaxMin(+keyStepHold);
806+
this.step = validVal(+step);
807+
this.keyStepOne = validVal(+keyStepOne);
808+
this.keyStepHold = validVal(+keyStepHold);
810809

811810
this.notifyOB({
812811
key: 'Step',
@@ -936,7 +935,7 @@ class Model extends Observer {
936935
let grid: boolean = options.grid;
937936
let gridNum: number = options.gridNum;
938937
let gridStep: number = options.gridStep;
939-
let gridRound: number = options.gridRound;
938+
let gridRound: number = Math.trunc(options.gridRound);
940939

941940
grid = Boolean(this.checkValue(grid, 'grid') ?? false);
942941
this.grid = Boolean(grid);
@@ -1045,11 +1044,9 @@ class Model extends Observer {
10451044
}
10461045
if (!fl) return false;
10471046

1048-
const emptyFun = (data: RangeSliderOptions) => data;
1049-
10501047
const checkData = (fun: Function) => {
10511048
if (fun === null) {
1052-
return emptyFun;
1049+
return null;
10531050
}
10541051
else if (typeof fun == 'function')
10551052
return fun;

0 commit comments

Comments
 (0)