@themarioga/grid-editor 9.2.6 → 9.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -0
- package/README.md +109 -5
- package/dist/grideditor.bundle.min.js +2 -2
- package/dist/grideditor.css +329 -0
- package/dist/grideditor.d.ts +125 -0
- package/dist/grideditor.esm.js +27 -5
- package/dist/grideditor.js +27 -5
- package/dist/grideditor.min.css +1 -1
- package/dist/grideditor.min.css.map +1 -1
- package/dist/grideditor.min.js +1 -1
- package/dist/grideditor.min.js.map +3 -3
- package/dist/locales/grideditor.es.esm.js +125 -0
- package/dist/locales/grideditor.es.js +125 -0
- package/dist/locales/grideditor.es.min.js +1 -1
- package/dist/locales/grideditor.es.min.js.map +2 -2
- package/dist/plugins/grideditor.dropdown.esm.js +2231 -0
- package/dist/plugins/grideditor.dropdown.js +2232 -0
- package/dist/plugins/grideditor.dropdown.min.js +1 -0
- package/dist/plugins/grideditor.dropdown.min.js.map +7 -0
- package/dist/plugins/grideditor.navbar.esm.js +2188 -0
- package/dist/plugins/grideditor.navbar.js +2189 -0
- package/dist/plugins/grideditor.navbar.min.js +1 -0
- package/dist/plugins/grideditor.navbar.min.js.map +7 -0
- package/dist/plugins/grideditor.sidenav.esm.js +2082 -0
- package/dist/plugins/grideditor.sidenav.js +2083 -0
- package/dist/plugins/grideditor.sidenav.min.js +1 -0
- package/dist/plugins/grideditor.sidenav.min.js.map +7 -0
- package/docs/events.md +5 -1
- package/docs/locale-keys.md +126 -1
- package/docs/plugins.md +24 -4
- package/example/containers.html +93 -2
- package/example/index.html +1 -1
- package/example/playground.html +3 -0
- package/package.json +1 -1
- package/src/js/grideditor.js +36 -4
- package/src/js/locales/grideditor.es.js +125 -0
- package/src/js/nav/browse.js +51 -0
- package/src/js/nav/canvas.js +170 -0
- package/src/js/nav/convert.js +179 -0
- package/src/js/nav/drawers.js +290 -0
- package/src/js/nav/dropdown.js +253 -0
- package/src/js/nav/feature.js +113 -0
- package/src/js/nav/locale.js +128 -0
- package/src/js/nav/markup.js +121 -0
- package/src/js/nav/panels.js +454 -0
- package/src/js/nav/pieces.js +253 -0
- package/src/js/plugins/grideditor.dropdown.js +335 -0
- package/src/js/plugins/grideditor.navbar.js +454 -0
- package/src/js/plugins/grideditor.sidenav.js +349 -0
- package/src/less/grideditor.less +231 -0
- package/types/grideditor.d.ts +125 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fields of the settings panel: the builders the two plugins share, and
|
|
3
|
+
* the section each piece has.
|
|
4
|
+
*/
|
|
5
|
+
import * as dom from '../dom.js';
|
|
6
|
+
import * as pieces from './pieces.js';
|
|
7
|
+
import * as convert from './convert.js';
|
|
8
|
+
import { browseButton } from './browse.js';
|
|
9
|
+
import { editInPlace } from './drawers.js';
|
|
10
|
+
|
|
11
|
+
var counter = 0;
|
|
12
|
+
|
|
13
|
+
/** The title of a piece's section, which is also what the panel calls the piece. */
|
|
14
|
+
export var SECTION_KEYS = {
|
|
15
|
+
'nav-list': { labelKey: 'container.nav_list_section' },
|
|
16
|
+
'nav-link': { labelKey: 'container.nav_link_section' },
|
|
17
|
+
'nav-dropdown': { labelKey: 'container.nav_dropdown_section' },
|
|
18
|
+
'nav-menu-item': { labelKey: 'container.nav_menu_item_section' },
|
|
19
|
+
'nav-text': { labelKey: 'container.nav_text_section' },
|
|
20
|
+
'nav-zone': { labelKey: 'container.nav_zone_section' },
|
|
21
|
+
'nav-brand': { labelKey: 'container.nav_brand_section' },
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function nextId() {
|
|
25
|
+
return 'ge-nav-option-' + (++counter);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A field: its label, its control and a name tests and styles can find it by. */
|
|
29
|
+
export function fieldRow(name, label, control, id) {
|
|
30
|
+
var box = dom.element('div', { 'class': 'ge-nav-option mb-2', 'data-ge-nav-option': name });
|
|
31
|
+
|
|
32
|
+
if (label) { box.appendChild(dom.element('label', { 'class': 'form-label', 'for': id }, label)); }
|
|
33
|
+
box.appendChild(control);
|
|
34
|
+
|
|
35
|
+
return box;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A select over `choices`, each { value, label }. */
|
|
39
|
+
export function selectControl(choices, onChange) {
|
|
40
|
+
var id = nextId();
|
|
41
|
+
var control = dom.element('select', { 'class': 'form-select form-select-sm', id: id });
|
|
42
|
+
|
|
43
|
+
choices.forEach(function(each) { control.appendChild(dom.element('option', { value: each.value }, each.label)); });
|
|
44
|
+
control.addEventListener('change', function() { onChange(control.value); });
|
|
45
|
+
|
|
46
|
+
return { id: id, control: control };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A checkbox; `box` is what goes in the panel. */
|
|
50
|
+
export function checkControl(label, onChange) {
|
|
51
|
+
var id = nextId();
|
|
52
|
+
var box = dom.element('div', { 'class': 'form-check ge-nav-option mb-2' });
|
|
53
|
+
var input = box.appendChild(dom.element('input', { 'class': 'form-check-input', type: 'checkbox', id: id }));
|
|
54
|
+
|
|
55
|
+
box.appendChild(dom.element('label', { 'class': 'form-check-label', 'for': id }, label));
|
|
56
|
+
input.addEventListener('change', function() { onChange(input.checked); });
|
|
57
|
+
|
|
58
|
+
return { box: box, input: input };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A text field that writes as it is typed in and when it is left. */
|
|
62
|
+
export function textControl(onChange) {
|
|
63
|
+
var id = nextId();
|
|
64
|
+
var control = dom.element('input', { 'class': 'form-control form-control-sm', type: 'text', id: id });
|
|
65
|
+
|
|
66
|
+
['input', 'change'].forEach(function(name) {
|
|
67
|
+
control.addEventListener(name, function() { onChange(control.value); });
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return { id: id, control: control };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A field marked as wrong, or not. */
|
|
74
|
+
export function markInvalid(control, invalid) {
|
|
75
|
+
dom.toggleClass(control, 'is-invalid', invalid);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A list of the sections open, to fill again when the markup changes. */
|
|
79
|
+
export function sectionsOf() {
|
|
80
|
+
var kept = [];
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
add: function(entry) {
|
|
84
|
+
kept = kept.filter(function(each) { return each.element.isConnected; });
|
|
85
|
+
kept.push(entry);
|
|
86
|
+
},
|
|
87
|
+
render: function(scope) {
|
|
88
|
+
kept = kept.filter(function(each) { return each.element.isConnected; });
|
|
89
|
+
kept.forEach(function(each) {
|
|
90
|
+
if (!scope || each.node === scope || scope.contains(each.node)) { each.render(); }
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
clear: function() { kept = []; },
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Clear what marks a link active, and give it to one. */
|
|
98
|
+
export function setActive(container, anchor, on) {
|
|
99
|
+
var clear = function(each) {
|
|
100
|
+
dom.removeClass(each, 'active');
|
|
101
|
+
each.removeAttribute('aria-current');
|
|
102
|
+
dom.dropEmptyClass(each);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
if (!on) {
|
|
106
|
+
clear(anchor);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
dom.all(container, 'a.nav-link, a.dropdown-item').filter(function(each) {
|
|
111
|
+
return pieces.isOwn(container, each);
|
|
112
|
+
}).forEach(clear);
|
|
113
|
+
|
|
114
|
+
dom.addClass(anchor, 'active');
|
|
115
|
+
anchor.setAttribute('aria-current', 'page');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function alignOf(node) {
|
|
119
|
+
return dom.hasClass(node, 'ms-auto') ? 'end' : dom.hasClass(node, 'mx-auto') ? 'center' : 'after';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function settingsOf(ge, container) {
|
|
123
|
+
return ge.settings[pieces.typeOf(container)] || {};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A URL field, with the host's file browser beside it when it gave one. `context`
|
|
128
|
+
* says the editor is gone, and `kept` is the list of sections to fill again.
|
|
129
|
+
*/
|
|
130
|
+
export function urlFieldFor(ge, context, kept, container, node, property, name, label, read, write, browseNode) {
|
|
131
|
+
var field = textControl(write);
|
|
132
|
+
var holder = dom.element('div', { 'class': 'input-group input-group-sm' });
|
|
133
|
+
|
|
134
|
+
holder.appendChild(field.control);
|
|
135
|
+
|
|
136
|
+
var button = browseButton(ge, context, settingsOf(ge, container).browse, browseNode || node, property, read, function(url) {
|
|
137
|
+
write(url);
|
|
138
|
+
kept.render();
|
|
139
|
+
});
|
|
140
|
+
if (button) { holder.appendChild(button); }
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
row: fieldRow(name, label, holder, field.id),
|
|
144
|
+
render: function() { field.control.value = read(); },
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function linkFieldsFor(ge, context, kept, container, node, anchor, fields) {
|
|
149
|
+
fields.push(urlFieldFor(ge, context, kept, container, node, 'href', 'href', ge.t('container.nav_href'),
|
|
150
|
+
function() { return anchor.getAttribute('href') || ''; },
|
|
151
|
+
function(value) { anchor.setAttribute('href', value); }, anchor));
|
|
152
|
+
|
|
153
|
+
var active = checkControl(ge.t('container.nav_active'), function(on) {
|
|
154
|
+
setActive(container, anchor, on);
|
|
155
|
+
kept.render();
|
|
156
|
+
});
|
|
157
|
+
var disabled = checkControl(ge.t('container.nav_disabled'), function(on) {
|
|
158
|
+
dom.toggleClass(anchor, 'disabled', on);
|
|
159
|
+
if (on) {
|
|
160
|
+
anchor.setAttribute('aria-disabled', 'true');
|
|
161
|
+
} else {
|
|
162
|
+
anchor.removeAttribute('aria-disabled');
|
|
163
|
+
dom.dropEmptyClass(anchor);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
var tab = checkControl(ge.t('container.nav_new_tab'), function(on) {
|
|
167
|
+
if (on) {
|
|
168
|
+
anchor.setAttribute('target', '_blank');
|
|
169
|
+
anchor.setAttribute('rel', 'noopener');
|
|
170
|
+
} else {
|
|
171
|
+
anchor.removeAttribute('target');
|
|
172
|
+
anchor.removeAttribute('rel');
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
active.box.setAttribute('data-ge-nav-option', 'active');
|
|
177
|
+
disabled.box.setAttribute('data-ge-nav-option', 'disabled');
|
|
178
|
+
tab.box.setAttribute('data-ge-nav-option', 'new_tab');
|
|
179
|
+
|
|
180
|
+
fields.push({ row: active.box, render: function() { active.input.checked = dom.hasClass(anchor, 'active'); } });
|
|
181
|
+
fields.push({ row: disabled.box, render: function() { disabled.input.checked = dom.hasClass(anchor, 'disabled'); } });
|
|
182
|
+
fields.push({ row: tab.box, render: function() { tab.input.checked = anchor.getAttribute('target') === '_blank'; } });
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The panels of the pieces of a navbar and a sidenav, for one editor. */
|
|
186
|
+
export function createPanels(ge, loaded) {
|
|
187
|
+
var kept = sectionsOf();
|
|
188
|
+
var context = { destroyed: false };
|
|
189
|
+
|
|
190
|
+
function urlField(container, node, property, name, label, read, write, browseNode) {
|
|
191
|
+
return urlFieldFor(ge, context, kept, container, node, property, name, label, read, write, browseNode);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function linkFields(container, node, anchor, fields) {
|
|
195
|
+
linkFieldsFor(ge, context, kept, container, node, anchor, fields);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function dropdownFields(container, node, fields) {
|
|
199
|
+
var type = pieces.typeOf(container);
|
|
200
|
+
|
|
201
|
+
if (type === 'sidenav') {
|
|
202
|
+
var kind = selectControl([
|
|
203
|
+
{ value: 'collapse', label: ge.t('container.nav_submenu_type_collapse') },
|
|
204
|
+
{ value: 'dropdown', label: ge.t('container.nav_submenu_type_dropdown') },
|
|
205
|
+
], function(value) {
|
|
206
|
+
if (value === 'collapse') { convert.toSubmenu(ge, node); } else { convert.toDropdown(ge, node); }
|
|
207
|
+
kept.render();
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
fields.push({
|
|
211
|
+
row: fieldRow('submenu_type', ge.t('container.nav_submenu_type'), kind.control, kind.id),
|
|
212
|
+
render: function() { kind.control.value = pieces.isSubmenu(node) ? 'collapse' : 'dropdown'; },
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
var end = checkControl(ge.t('container.nav_menu_end'), function(on) {
|
|
217
|
+
var menu = pieces.menuOf(node);
|
|
218
|
+
if (!menu) { return; }
|
|
219
|
+
|
|
220
|
+
dom.toggleClass(menu, 'dropdown-menu-end', on);
|
|
221
|
+
dom.dropEmptyClass(menu);
|
|
222
|
+
});
|
|
223
|
+
end.box.setAttribute('data-ge-nav-option', 'menu_end');
|
|
224
|
+
fields.push({
|
|
225
|
+
row: end.box,
|
|
226
|
+
render: function() {
|
|
227
|
+
var menu = pieces.menuOf(node);
|
|
228
|
+
|
|
229
|
+
end.input.checked = dom.hasClass(menu, 'dropdown-menu-end');
|
|
230
|
+
end.input.disabled = pieces.isSubmenu(node);
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
if (type !== 'sidenav') { return; }
|
|
235
|
+
|
|
236
|
+
var open = checkControl(ge.t('container.nav_submenu_open'), function(on) {
|
|
237
|
+
var collapse = dom.child(node, '.collapse');
|
|
238
|
+
var toggle = dom.child(node, 'a');
|
|
239
|
+
if (!collapse) { return; }
|
|
240
|
+
|
|
241
|
+
dom.toggleClass(collapse, 'show', on);
|
|
242
|
+
toggle.setAttribute('aria-expanded', on ? 'true' : 'false');
|
|
243
|
+
});
|
|
244
|
+
open.box.setAttribute('data-ge-nav-option', 'submenu_open');
|
|
245
|
+
fields.push({
|
|
246
|
+
row: open.box,
|
|
247
|
+
render: function() {
|
|
248
|
+
var collapse = dom.child(node, '.collapse');
|
|
249
|
+
|
|
250
|
+
open.input.checked = dom.hasClass(collapse, 'show');
|
|
251
|
+
open.input.disabled = !pieces.isSubmenu(node);
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function alignmentField(node, fields) {
|
|
257
|
+
var align = selectControl([
|
|
258
|
+
{ value: 'after', label: ge.t('container.nav_align_after') },
|
|
259
|
+
{ value: 'end', label: ge.t('container.nav_align_end') },
|
|
260
|
+
{ value: 'center', label: ge.t('container.nav_align_center') },
|
|
261
|
+
], function(value) {
|
|
262
|
+
dom.removeClass(node, 'ms-auto mx-auto');
|
|
263
|
+
if (value === 'end') { dom.addClass(node, 'ms-auto'); }
|
|
264
|
+
if (value === 'center') { dom.addClass(node, 'mx-auto'); }
|
|
265
|
+
dom.dropEmptyClass(node);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
fields.push({
|
|
269
|
+
row: fieldRow('align', ge.t('container.nav_align'), align.control, align.id),
|
|
270
|
+
render: function() { align.control.value = alignOf(node); },
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function scrollFields(node, fields) {
|
|
275
|
+
var height = textControl(function(value) {
|
|
276
|
+
if (!dom.hasClass(node, 'navbar-nav-scroll')) { return; }
|
|
277
|
+
|
|
278
|
+
var valid = value.trim() !== '' && window.CSS && CSS.supports('height', value.trim());
|
|
279
|
+
|
|
280
|
+
markInvalid(height.control, !valid);
|
|
281
|
+
if (valid) { ge.setHostStyle(node, '--bs-scroll-height', value.trim()); }
|
|
282
|
+
});
|
|
283
|
+
var scroll = checkControl(ge.t('container.nav_scroll'), function(on) {
|
|
284
|
+
if (on) {
|
|
285
|
+
var typed = height.control.value.trim();
|
|
286
|
+
var wanted = typed && CSS.supports('height', typed) ? typed : '75vh';
|
|
287
|
+
|
|
288
|
+
dom.addClass(node, 'navbar-nav-scroll');
|
|
289
|
+
ge.setHostStyle(node, '--bs-scroll-height', wanted);
|
|
290
|
+
} else {
|
|
291
|
+
dom.removeClass(node, 'navbar-nav-scroll');
|
|
292
|
+
dom.dropEmptyClass(node);
|
|
293
|
+
ge.setHostStyle(node, '--bs-scroll-height', '');
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
markInvalid(height.control, false);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
scroll.box.setAttribute('data-ge-nav-option', 'scroll');
|
|
300
|
+
fields.push({ row: scroll.box, render: function() { scroll.input.checked = dom.hasClass(node, 'navbar-nav-scroll'); } });
|
|
301
|
+
fields.push({
|
|
302
|
+
row: fieldRow('scroll_height', ge.t('container.nav_scroll_height'), height.control, height.id),
|
|
303
|
+
render: function() {
|
|
304
|
+
var shown = ge.hostStyle(node, '--bs-scroll-height').value;
|
|
305
|
+
|
|
306
|
+
height.control.value = shown || '75vh';
|
|
307
|
+
height.control.disabled = !dom.hasClass(node, 'navbar-nav-scroll');
|
|
308
|
+
markInvalid(height.control, false);
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function bottomField(node, fields) {
|
|
314
|
+
var bottom = checkControl(ge.t('container.nav_bottom'), function(on) {
|
|
315
|
+
dom.toggleClass(node, 'mt-auto', on);
|
|
316
|
+
dom.dropEmptyClass(node);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
bottom.box.setAttribute('data-ge-nav-option', 'bottom');
|
|
320
|
+
fields.push({ row: bottom.box, render: function() { bottom.input.checked = dom.hasClass(node, 'mt-auto'); } });
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function brandFields(container, node, fields) {
|
|
324
|
+
var imageOf = function() { return dom.child(node, 'img'); };
|
|
325
|
+
|
|
326
|
+
fields.push(urlField(container, node, 'href', 'href', ge.t('container.nav_href'),
|
|
327
|
+
function() { return node.getAttribute('href') || ''; },
|
|
328
|
+
function(value) { node.setAttribute('href', value); }));
|
|
329
|
+
|
|
330
|
+
fields.push(urlField(container, node, 'src', 'image', ge.t('container.nav_brand_image'),
|
|
331
|
+
function() { var img = imageOf(); return img ? img.getAttribute('src') || '' : ''; },
|
|
332
|
+
function(value) { setImage(value); },
|
|
333
|
+
function() { return imageOf() || node; }));
|
|
334
|
+
|
|
335
|
+
var alt = textControl(function(value) {
|
|
336
|
+
var img = imageOf();
|
|
337
|
+
if (img) { img.setAttribute('alt', value); }
|
|
338
|
+
});
|
|
339
|
+
fields.push({
|
|
340
|
+
row: fieldRow('alt', ge.t('container.nav_brand_alt'), alt.control, alt.id),
|
|
341
|
+
render: function() {
|
|
342
|
+
var img = imageOf();
|
|
343
|
+
|
|
344
|
+
alt.control.value = img ? img.getAttribute('alt') || '' : '';
|
|
345
|
+
alt.control.disabled = !img;
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
var height = textControl(function(value) {
|
|
350
|
+
var img = imageOf();
|
|
351
|
+
var valid = /^\d+$/.test(value.trim()) && parseInt(value, 10) >= 1;
|
|
352
|
+
|
|
353
|
+
markInvalid(height.control, !valid);
|
|
354
|
+
if (valid && img) { img.setAttribute('height', String(parseInt(value, 10))); }
|
|
355
|
+
});
|
|
356
|
+
fields.push({
|
|
357
|
+
row: fieldRow('image_height', ge.t('container.nav_brand_height'), height.control, height.id),
|
|
358
|
+
render: function() {
|
|
359
|
+
var img = imageOf();
|
|
360
|
+
|
|
361
|
+
height.control.value = img ? img.getAttribute('height') || '30' : '30';
|
|
362
|
+
height.control.disabled = !img;
|
|
363
|
+
markInvalid(height.control, false);
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
function setImage(url) {
|
|
368
|
+
var img = imageOf();
|
|
369
|
+
|
|
370
|
+
if (url === '') {
|
|
371
|
+
if (img) { img.remove(); }
|
|
372
|
+
if (!node.textContent.trim().replace(/\s+/g, '')) {
|
|
373
|
+
node.appendChild(document.createTextNode(ge.t(pieces.defaultLabelKey(node, 'nav-brand', container))));
|
|
374
|
+
editInPlace(ge, node, function() { return ge.t(pieces.defaultLabelKey(node, 'nav-brand', container)); });
|
|
375
|
+
}
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (img) {
|
|
380
|
+
img.setAttribute('src', url);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
var first = dom.children(node).filter(function(each) { return !dom.hasClass(each, 'ge-tools-drawer'); })[0] || null;
|
|
385
|
+
|
|
386
|
+
node.insertBefore(dom.element('img', { src: url, alt: '', height: '30' }), first || node.firstChild);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** The fields of a piece, or an empty list for a piece with none. */
|
|
391
|
+
function fieldsOf(container, node, kind) {
|
|
392
|
+
var type = pieces.typeOf(container);
|
|
393
|
+
var fields = [];
|
|
394
|
+
|
|
395
|
+
if (kind === 'nav-link') { linkFields(container, node, pieces.anchorOf(node), fields); }
|
|
396
|
+
if (kind === 'nav-dropdown') { dropdownFields(container, node, fields); }
|
|
397
|
+
|
|
398
|
+
if (kind === 'nav-menu-item' && pieces.itemType(node) === 'link') {
|
|
399
|
+
linkFields(container, node, pieces.anchorOf(node), fields);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (kind === 'nav-list') {
|
|
403
|
+
if (type === 'navbar') {
|
|
404
|
+
alignmentField(node, fields);
|
|
405
|
+
scrollFields(node, fields);
|
|
406
|
+
} else {
|
|
407
|
+
bottomField(node, fields);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (kind === 'nav-text' || kind === 'nav-zone') {
|
|
412
|
+
if (type === 'navbar') { alignmentField(node, fields); } else { bottomField(node, fields); }
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (kind === 'nav-brand') { brandFields(container, node, fields); }
|
|
416
|
+
|
|
417
|
+
return fields;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return {
|
|
421
|
+
context: context,
|
|
422
|
+
|
|
423
|
+
/** The section of a piece's settings panel, or null for a piece with nothing to set. */
|
|
424
|
+
pieceSection: function(node, kind) {
|
|
425
|
+
if (pieces.KINDS.indexOf(kind) === -1) { return null; }
|
|
426
|
+
|
|
427
|
+
var container = pieces.ownerOf(node, loaded);
|
|
428
|
+
if (!container) { return null; }
|
|
429
|
+
|
|
430
|
+
var fields = fieldsOf(container, node, kind);
|
|
431
|
+
if (!fields.length) { return null; }
|
|
432
|
+
|
|
433
|
+
var body = dom.element('div', { 'class': 'ge-nav-options' });
|
|
434
|
+
|
|
435
|
+
fields.forEach(function(each) { body.appendChild(each.row); });
|
|
436
|
+
|
|
437
|
+
var render = function() { fields.forEach(function(each) { each.render(); }); };
|
|
438
|
+
|
|
439
|
+
render();
|
|
440
|
+
kept.add({ node: node, element: body, render: render });
|
|
441
|
+
|
|
442
|
+
return { labelKey: SECTION_KEYS[kind].labelKey, body: body };
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
/** Every section open, filled again from the markup. */
|
|
446
|
+
refresh: function() { kept.render(); },
|
|
447
|
+
|
|
448
|
+
onRefresh: function(scope) { kept.render(scope); },
|
|
449
|
+
|
|
450
|
+
onDeinit: function() { kept.clear(); },
|
|
451
|
+
|
|
452
|
+
onDestroy: function() { context.destroyed = true; },
|
|
453
|
+
};
|
|
454
|
+
}
|