-
Notifications
You must be signed in to change notification settings - Fork 84
/
preview.js
101 lines (92 loc) · 2.46 KB
/
preview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import './style.css'
try {
require('../e2e-tests/node_modules/cypress-storybook/react');
} catch (ex) {
console.log(ex);
}
import '@wordpress/components/build-style/style.css'
import '@icon/dashicons/dashicons.css'
import {FONTS} from '../stories/utils/values'
import {BuildersData} from "./dummy-data";
window.NeveReactCustomize = {}
window.nvComponents = {}
window.NeveReactCustomize.HFG = BuildersData
const wpObject = {
customize: {
bind: (event, callback) => {
},
previewedDevice: (device) => {
const wrap = document.querySelector('.mock-customize');
if (wrap.classList.contains(`preview-${device}`)) {
return false;
}
wrap.classList.remove('preview-desktop', 'preview-mobile', 'preview-tablet')
wrap.classList.add(`preview-${device}`);
},
section: (slug) => ({
focus: () => console.log(`Focusing Section ${slug}.`),
expanded: (value) => console.log(`Set Expanded for ${slug} to ${value}.`),
params: {
title: `Title: ${slug}`,
}
}),
state: (slug) => ({
get: () => {
return 'title_tagline'
},
bind: (a) => {
console.log('State Bounded and returns:', a());
},
unbind: (a) => {
console.log('State Unbounded and returns:', a());
}
}),
previewer: {
bind: (e) => {
console.log('Event Bound:', e);
},
send: (e) => {
console.log(e)
},
refresh: () => {
console.log('REFRESH PREVIEW');
}
},
control: (slug, callback) => {
if (callback) {
callback(window.wp.customize.control(slug))
}
if (slug.indexOf('_columns_layout') > -1) {
return {
setting: {
value: 'left-third',
get: () => window.wp.customize.control(slug).setting.value,
set: (value) => {
},
bind: (value) => window.wp.customize.control(slug).setting.value
}
}
}
if (slug.indexOf('_columns_number') > -1) {
return {
setting: {
value: 2,
get: () => window.wp.customize.control(slug).setting.value,
set: (value) => {
},
bind: (value) => window.wp.customize.control(slug).setting.value
}
}
}
}
}
};
window.wp = wpObject;
const head = document.querySelector('#nv-google-fonts');
const families = FONTS.Google.join('|');
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('id', 'google-fonts-css');
link.setAttribute('href', `https://fonts.googleapis.com/css?family=${families}&text=Abc&display=swap&ver=2.9.5`);
link.setAttribute('media', 'all');
head.appendChild(link)