Passed
Pull Request — master (#258)
by
unknown
04:59
created

assets/customizerControls.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 31
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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