1
|
|
|
/* globals wp, Option */ |
2
|
|
|
import $ from 'jquery' |
3
|
|
|
|
4
|
|
|
wp.customize.controlConstructor['flynt-typography'] = wp.customize.Control.extend({ |
5
|
|
|
ready: function () { |
6
|
|
|
const $family = this.container.find('.flynt-typography-family') |
7
|
|
|
const $variant = this.container.find('.flynt-typography-variant') |
8
|
|
|
let family = this.params.value.family |
9
|
|
|
let category = this.params.value.category |
10
|
|
|
|
11
|
|
|
$family.select2({ |
12
|
|
|
data: Object.values(this.params.fonts) |
13
|
|
|
}) |
14
|
|
|
|
15
|
|
|
$variant.select2() |
16
|
|
|
|
17
|
|
|
$family.val(this.params.font).trigger('change') |
18
|
|
|
|
19
|
|
|
const addOptions = function (options, selected = '') { |
20
|
|
|
$variant.empty() |
21
|
|
|
|
22
|
|
|
for (const option of options) { |
23
|
|
|
const isSelected = (selected === option) |
24
|
|
|
const newOption = new Option(option, option, isSelected, isSelected) |
25
|
|
|
$variant.append(newOption).trigger('change') |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$family.on('select2:select', (e) => { |
30
|
|
|
const data = e.params.data |
31
|
|
|
const variants = this.params.fonts[data.id].variants |
32
|
|
|
family = data.family |
33
|
|
|
category = data.category |
34
|
|
|
|
35
|
|
|
addOptions(variants) |
36
|
|
|
this.setting.set({ |
37
|
|
|
family: family, |
38
|
|
|
category: category, |
39
|
|
|
variant: variants[0] |
40
|
|
|
}) |
41
|
|
|
}) |
42
|
|
|
|
43
|
|
|
$variant.on('select2:select', (e) => { |
44
|
|
|
const data = e.params.data |
45
|
|
|
this.setting.set({ |
46
|
|
|
family: family, |
47
|
|
|
category: category, |
48
|
|
|
variant: data.id |
49
|
|
|
}) |
50
|
|
|
}) |
51
|
|
|
|
52
|
|
|
this.container.on('click', '.flynt-typography-reset', (e) => { |
53
|
|
|
const $el = $(e.currentTarget) |
54
|
|
|
const id = $el.data('key') |
55
|
|
|
const variants = this.params.fonts[id].variants |
56
|
|
|
const selected = this.params.default.variant |
57
|
|
|
|
58
|
|
|
addOptions(variants, selected) |
59
|
|
|
this.setting.set(this.params.default) |
60
|
|
|
$family.val(id).trigger('change') |
61
|
|
|
}) |
62
|
|
|
} |
63
|
|
|
}) |
64
|
|
|
|