Passed
Pull Request — master (#258)
by Dominik
05:19
created

lib/Customizer/Range/control.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 30
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 18
dl 0
loc 30
rs 10
c 0
b 0
f 0
mnd 2
bc 2
fnc 3
bpm 0.6666
cpm 1.6666
noi 0
1
/* globals wp */
2
import $ from 'jquery'
3
4
wp.customize.controlConstructor['flynt-range'] = wp.customize.Control.extend({
5
  ready: function () {
6
    const control = this
7
8
    this.container.on('change', '.flynt-range', function () {
9
      const $el = $(this)
10
      const max = parseInt($el.attr('max'), 10)
11
      const min = parseInt($el.attr('min'), 10)
12
      let value = parseInt($el.val(), 10)
13
14
      if (min > value) {
15
        value = min
16
      }
17
18
      if (max < value) {
19
        value = max
20
      }
21
22
      control.setting.set(value)
23
    })
24
25
    this.container.on('click', '.flynt-range-reset', function () {
26
      const $el = $(this)
27
      const value = $el.data('default')
28
      control.setting.set(value)
29
    })
30
  }
31
})
32