@themarioga/grid-editor 9.2.6 → 9.3.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 +38 -0
- package/README.md +68 -5
- package/dist/grideditor.bundle.min.js +2 -2
- package/dist/grideditor.css +267 -0
- package/dist/grideditor.d.ts +88 -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 +102 -0
- package/dist/locales/grideditor.es.js +102 -0
- package/dist/locales/grideditor.es.min.js +1 -1
- package/dist/locales/grideditor.es.min.js.map +2 -2
- package/dist/plugins/grideditor.navbar.esm.js +2084 -0
- package/dist/plugins/grideditor.navbar.js +2085 -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 +1978 -0
- package/dist/plugins/grideditor.sidenav.js +1979 -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 +103 -1
- package/docs/plugins.md +23 -4
- package/example/containers.html +59 -2
- package/example/index.html +1 -1
- package/example/playground.html +2 -0
- package/package.json +1 -1
- package/src/js/grideditor.js +36 -4
- package/src/js/locales/grideditor.es.js +102 -0
- package/src/js/nav/browse.js +51 -0
- package/src/js/nav/canvas.js +170 -0
- package/src/js/nav/convert.js +175 -0
- package/src/js/nav/drawers.js +258 -0
- package/src/js/nav/feature.js +94 -0
- package/src/js/nav/locale.js +128 -0
- package/src/js/nav/markup.js +121 -0
- package/src/js/nav/panels.js +443 -0
- package/src/js/nav/pieces.js +207 -0
- package/src/js/plugins/grideditor.navbar.js +454 -0
- package/src/js/plugins/grideditor.sidenav.js +349 -0
- package/src/less/grideditor.less +199 -0
- package/types/grideditor.d.ts +88 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navbars for grid-editor.
|
|
3
|
+
*
|
|
4
|
+
* A container plugin: load this file after the editor and the toolbar offers
|
|
5
|
+
* a Bootstrap 5.3 navbar - a brand, lists of links, dropdowns, texts and free
|
|
6
|
+
* zones of rows and columns - that folds into a collapse or an offcanvas
|
|
7
|
+
* below its breakpoint. It is edited in place: every piece has a drawer,
|
|
8
|
+
* its text is renamed where it stands, and its options are in the settings
|
|
9
|
+
* panel.
|
|
10
|
+
*
|
|
11
|
+
* <script src="dist/grideditor.min.js"></script>
|
|
12
|
+
* <script src="dist/plugins/grideditor.navbar.min.js"></script>
|
|
13
|
+
*
|
|
14
|
+
* Nothing of Bootstrap's javascript reaches the canvas while editing: the
|
|
15
|
+
* toggler, the dropdowns and the offcanvas are shown open, and the preview
|
|
16
|
+
* button gives them back. `getHtml` is a navbar that works on the page with
|
|
17
|
+
* Bootstrap's javascript.
|
|
18
|
+
*
|
|
19
|
+
* new GridEditor('#myGrid', { navbar: { expand: 'md', browse: function(done, field) { … } } });
|
|
20
|
+
* ge.createContainer('navbar', { brand: 'ACME', collapse: 'offcanvas' });
|
|
21
|
+
*/
|
|
22
|
+
import { GridEditor } from '../grideditor.js';
|
|
23
|
+
import * as dom from '../dom.js';
|
|
24
|
+
import { EN, BACKGROUND_CHOICES, POSITION_CHOICES } from '../nav/locale.js';
|
|
25
|
+
import * as pieces from '../nav/pieces.js';
|
|
26
|
+
import * as markup from '../nav/markup.js';
|
|
27
|
+
import { registerNav } from '../nav/feature.js';
|
|
28
|
+
import { containerBase } from '../nav/canvas.js';
|
|
29
|
+
import { fieldRow, selectControl, checkControl, sectionsOf } from '../nav/panels.js';
|
|
30
|
+
|
|
31
|
+
Object.assign(GridEditor.locales.en, EN, { 'container.add_navbar': 'Navbar' });
|
|
32
|
+
|
|
33
|
+
registerNav();
|
|
34
|
+
|
|
35
|
+
var LAYOUT_ATTR = 'data-ge-navbar-layout';
|
|
36
|
+
|
|
37
|
+
var BACKGROUNDS = BACKGROUND_CHOICES.map(function(each) { return each.value; });
|
|
38
|
+
var POSITIONS = POSITION_CHOICES.map(function(each) { return each.value; });
|
|
39
|
+
|
|
40
|
+
/** What a navbar made new has when neither the call nor the setting says. */
|
|
41
|
+
var DEFAULTS = {
|
|
42
|
+
expand: 'lg',
|
|
43
|
+
collapse: 'collapse',
|
|
44
|
+
offcanvas_placement: 'end',
|
|
45
|
+
bg: 'body-tertiary',
|
|
46
|
+
theme: null,
|
|
47
|
+
position: null,
|
|
48
|
+
width: 'fluid',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
GridEditor.containers.navbar = function(ge) {
|
|
52
|
+
var base = containerBase(ge, 'navbar');
|
|
53
|
+
var baseMark = base.mark;
|
|
54
|
+
var baseUnmark = base.unmark;
|
|
55
|
+
var BREAKPOINTS = ge.breakpoints.filter(function(key) { return key !== 'xs'; });
|
|
56
|
+
var sections = sectionsOf();
|
|
57
|
+
|
|
58
|
+
var VALUES = {
|
|
59
|
+
expand: [false, true].concat(BREAKPOINTS),
|
|
60
|
+
collapse: ['collapse', 'offcanvas', false],
|
|
61
|
+
offcanvas_placement: ['start', 'end'],
|
|
62
|
+
bg: [null].concat(BACKGROUNDS),
|
|
63
|
+
theme: [null, 'light', 'dark'],
|
|
64
|
+
position: [null].concat(POSITIONS),
|
|
65
|
+
width: ['fluid', 'fixed'].concat(BREAKPOINTS),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A value for a new navbar: the option, or the navbar setting, or the
|
|
70
|
+
* default. One the option does not take is warned about and the default
|
|
71
|
+
* used.
|
|
72
|
+
*/
|
|
73
|
+
function chosen(options, key) {
|
|
74
|
+
var setting = ge.settings.navbar || {};
|
|
75
|
+
var value = options[key] !== undefined ? options[key] : setting[key];
|
|
76
|
+
|
|
77
|
+
if (value === undefined) { return DEFAULTS[key]; }
|
|
78
|
+
if (VALUES[key].indexOf(value) !== -1) { return value; }
|
|
79
|
+
|
|
80
|
+
ge.warn('navbar: ' + JSON.stringify(value) + ' is not a ' + key + ', which takes ' +
|
|
81
|
+
JSON.stringify(VALUES[key]) + ': ' + JSON.stringify(DEFAULTS[key]) + ' is used');
|
|
82
|
+
return DEFAULTS[key];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The brand a new navbar has: its own text, or none with `false`. */
|
|
86
|
+
function brandOf(options) {
|
|
87
|
+
var brand = options.brand;
|
|
88
|
+
|
|
89
|
+
if (brand === undefined) { return ge.t('container.navbar_brand'); }
|
|
90
|
+
if (brand === false || (typeof brand === 'string' && brand !== '')) { return brand; }
|
|
91
|
+
|
|
92
|
+
ge.warn('navbar: ' + JSON.stringify(brand) + ' is not a brand, which takes a text or false: ' +
|
|
93
|
+
JSON.stringify(ge.t('container.navbar_brand')) + ' is used');
|
|
94
|
+
return ge.t('container.navbar_brand');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function navOf(container) { return pieces.navOf(container); }
|
|
98
|
+
|
|
99
|
+
function infix(value) { return value === true ? '' : '-' + value; }
|
|
100
|
+
|
|
101
|
+
/** What a navbar's classes and attributes say it is. */
|
|
102
|
+
function read(container) {
|
|
103
|
+
var nav = navOf(container);
|
|
104
|
+
var wrap = pieces.wrapOf(container);
|
|
105
|
+
var expand = false;
|
|
106
|
+
var width = 'fluid';
|
|
107
|
+
var offcanvas = pieces.offcanvasOf(container);
|
|
108
|
+
|
|
109
|
+
Array.prototype.forEach.call(nav.classList, function(name) {
|
|
110
|
+
if (name === 'navbar-expand') { expand = true; }
|
|
111
|
+
if (/^navbar-expand-/.test(name) && BREAKPOINTS.indexOf(name.slice(14)) !== -1) { expand = name.slice(14); }
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
Array.prototype.forEach.call(wrap.classList, function(name) {
|
|
115
|
+
if (name === 'container') { width = 'fixed'; }
|
|
116
|
+
if (/^container-/.test(name) && name !== 'container-fluid') { width = name.slice(10); }
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
var bg = BACKGROUNDS.filter(function(name) { return dom.hasClass(nav, 'bg-' + name); })[0];
|
|
120
|
+
var position = POSITIONS.filter(function(name) { return dom.hasClass(container, name); })[0];
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
brand: !!dom.child(wrap, '.navbar-brand'),
|
|
124
|
+
expand: expand,
|
|
125
|
+
collapse: dom.child(wrap, '.navbar-collapse') ? 'collapse' : offcanvas ? 'offcanvas' : false,
|
|
126
|
+
offcanvas_placement: offcanvas && dom.hasClass(offcanvas, 'offcanvas-start') ? 'start' : (offcanvas ? 'end' : null),
|
|
127
|
+
bg: bg === undefined ? null : bg,
|
|
128
|
+
theme: nav.getAttribute('data-bs-theme') || null,
|
|
129
|
+
position: position === undefined ? null : position,
|
|
130
|
+
width: width,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function togglerOf(container) {
|
|
135
|
+
return dom.child(pieces.wrapOf(container), '.navbar-toggler');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function makeToggler(id, offcanvas) {
|
|
139
|
+
var toggler = dom.element('button', {
|
|
140
|
+
'class': 'navbar-toggler',
|
|
141
|
+
type: 'button',
|
|
142
|
+
'data-bs-toggle': offcanvas ? 'offcanvas' : 'collapse',
|
|
143
|
+
'data-bs-target': '#' + id,
|
|
144
|
+
'aria-controls': id,
|
|
145
|
+
'aria-expanded': 'false',
|
|
146
|
+
'aria-label': ge.t('container.navbar_toggle'),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
toggler.appendChild(dom.element('span', { 'class': 'navbar-toggler-icon' }));
|
|
150
|
+
|
|
151
|
+
return toggler;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function makeOffcanvas(id, placement) {
|
|
155
|
+
var panel = dom.element('div', {
|
|
156
|
+
'class': 'offcanvas offcanvas-' + placement,
|
|
157
|
+
tabindex: '-1',
|
|
158
|
+
id: id,
|
|
159
|
+
'aria-labelledby': id + '-label',
|
|
160
|
+
});
|
|
161
|
+
var header = panel.appendChild(dom.element('div', { 'class': 'offcanvas-header' }));
|
|
162
|
+
|
|
163
|
+
header.appendChild(dom.element('h5', { 'class': 'offcanvas-title', id: id + '-label' },
|
|
164
|
+
ge.t('container.navbar_offcanvas_title')));
|
|
165
|
+
header.appendChild(dom.element('button', {
|
|
166
|
+
type: 'button',
|
|
167
|
+
'class': 'btn-close',
|
|
168
|
+
'data-bs-dismiss': 'offcanvas',
|
|
169
|
+
'aria-label': ge.t('container.nav_close'),
|
|
170
|
+
}));
|
|
171
|
+
panel.appendChild(dom.element('div', { 'class': 'offcanvas-body' }));
|
|
172
|
+
|
|
173
|
+
return panel;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Everything that was in the part that folds, in the same order and
|
|
178
|
+
* untouched, goes into the new one: the pieces, and whatever else the
|
|
179
|
+
* host put there. The id is kept when there was one, so going to another
|
|
180
|
+
* way of folding and back leaves the markup as it was.
|
|
181
|
+
*/
|
|
182
|
+
function setCollapse(container, to, placement, mark) {
|
|
183
|
+
var wrap = pieces.wrapOf(container);
|
|
184
|
+
var from = read(container).collapse;
|
|
185
|
+
if (from === to) { return; }
|
|
186
|
+
|
|
187
|
+
var area = pieces.areaOf(container);
|
|
188
|
+
var toggler = togglerOf(container);
|
|
189
|
+
var old = area === wrap ? null : (dom.child(wrap, '.navbar-collapse') || dom.child(wrap, '.offcanvas'));
|
|
190
|
+
var id = old && old.id ? old.id : ge.containerId('navbar');
|
|
191
|
+
var kids = dom.children(area).filter(function(node) {
|
|
192
|
+
return !dom.is(node, '.navbar-brand, .navbar-toggler') && !(area === wrap && node === old);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (toggler) { toggler.remove(); }
|
|
196
|
+
if (old) { old.remove(); }
|
|
197
|
+
|
|
198
|
+
var brand = dom.child(wrap, '.navbar-brand');
|
|
199
|
+
var after = brand ? brand.nextSibling : wrap.firstChild;
|
|
200
|
+
var target = wrap;
|
|
201
|
+
|
|
202
|
+
if (to !== false) {
|
|
203
|
+
var panel = to === 'collapse'
|
|
204
|
+
? dom.element('div', { 'class': 'collapse navbar-collapse', id: id })
|
|
205
|
+
: makeOffcanvas(id, placement);
|
|
206
|
+
|
|
207
|
+
wrap.insertBefore(makeToggler(id, to === 'offcanvas'), after);
|
|
208
|
+
wrap.appendChild(panel);
|
|
209
|
+
target = to === 'collapse' ? panel : dom.child(panel, '.offcanvas-body');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
kids.forEach(function(node) { target.appendChild(node); });
|
|
213
|
+
|
|
214
|
+
if (mark) {
|
|
215
|
+
baseMark(container);
|
|
216
|
+
// The lists the pieces are sorted in are the new part's
|
|
217
|
+
ge.reinit();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function setBrand(container, on) {
|
|
222
|
+
var wrap = pieces.wrapOf(container);
|
|
223
|
+
var brand = dom.child(wrap, '.navbar-brand');
|
|
224
|
+
|
|
225
|
+
if (!on) {
|
|
226
|
+
if (brand) { brand.remove(); }
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (brand) { return; }
|
|
230
|
+
|
|
231
|
+
wrap.insertBefore(dom.element('a', { 'class': 'navbar-brand', href: '#' }, ge.t('container.navbar_brand')), wrap.firstChild);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function write(container, key, value, options) {
|
|
235
|
+
var nav = navOf(container);
|
|
236
|
+
var wrap = pieces.wrapOf(container);
|
|
237
|
+
|
|
238
|
+
if (key === 'expand') {
|
|
239
|
+
Array.prototype.filter.call(nav.classList, function(name) { return /^navbar-expand/.test(name); })
|
|
240
|
+
.forEach(function(name) { nav.classList.remove(name); });
|
|
241
|
+
if (value !== false) { dom.addClass(nav, 'navbar-expand' + (value === true ? '' : infix(value))); }
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (key === 'bg') {
|
|
245
|
+
Array.prototype.filter.call(nav.classList, function(name) { return /^bg-/.test(name); })
|
|
246
|
+
.forEach(function(name) { nav.classList.remove(name); });
|
|
247
|
+
if (value !== null) { dom.addClass(nav, 'bg-' + value); }
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (key === 'theme') {
|
|
251
|
+
if (value === null) { nav.removeAttribute('data-bs-theme'); } else { nav.setAttribute('data-bs-theme', value); }
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (key === 'position') {
|
|
255
|
+
dom.removeClass(container, POSITIONS.join(' '));
|
|
256
|
+
if (value !== null) { dom.addClass(container, value); }
|
|
257
|
+
dom.dropEmptyClass(container);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (key === 'width') {
|
|
261
|
+
Array.prototype.filter.call(wrap.classList, function(name) { return /^container(-|$)/.test(name); })
|
|
262
|
+
.forEach(function(name) { wrap.classList.remove(name); });
|
|
263
|
+
dom.addClass(wrap, value === 'fluid' ? 'container-fluid' : value === 'fixed' ? 'container' : 'container-' + value);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (key === 'offcanvas_placement') {
|
|
267
|
+
var offcanvas = pieces.offcanvasOf(container);
|
|
268
|
+
|
|
269
|
+
if (offcanvas) {
|
|
270
|
+
dom.removeClass(offcanvas, 'offcanvas-start offcanvas-end');
|
|
271
|
+
dom.addClass(offcanvas, 'offcanvas-' + value);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (key === 'collapse') {
|
|
276
|
+
setCollapse(container, value, (options && options.placement) || placementOf(), !!(options && options.mark));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (key === 'brand') { setBrand(container, value); }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** The side a navbar that folds into an offcanvas gets: the setting's, or the end. */
|
|
283
|
+
function placementOf() {
|
|
284
|
+
var setting = (ge.settings.navbar || {}).offcanvas_placement;
|
|
285
|
+
|
|
286
|
+
return VALUES.offcanvas_placement.indexOf(setting) !== -1 ? setting : DEFAULTS.offcanvas_placement;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** The expand a view lays the navbar out as: null in the all view, which is what the window gives. */
|
|
290
|
+
function layoutHere(container) {
|
|
291
|
+
if (ge.view() === 'all') { return null; }
|
|
292
|
+
|
|
293
|
+
var expand = read(container).expand;
|
|
294
|
+
if (expand === true) { return 'expanded'; }
|
|
295
|
+
if (expand === false) { return 'collapsed'; }
|
|
296
|
+
|
|
297
|
+
return ge.breakpoints.indexOf(ge.view()) >= ge.breakpoints.indexOf(expand) ? 'expanded' : 'collapsed';
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* A breakpoint view narrows the canvas, not the window, and Bootstrap's
|
|
302
|
+
* classes answer to the window: so the view says how the navbar is laid
|
|
303
|
+
* out, and the stylesheet paints it that way.
|
|
304
|
+
*/
|
|
305
|
+
function markLayout(container) {
|
|
306
|
+
var layout = layoutHere(container);
|
|
307
|
+
|
|
308
|
+
if (layout) {
|
|
309
|
+
container.setAttribute(LAYOUT_ATTR, layout);
|
|
310
|
+
} else {
|
|
311
|
+
container.removeAttribute(LAYOUT_ATTR);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** The Navbar section of a navbar's settings panel. */
|
|
316
|
+
function createSection(container) {
|
|
317
|
+
var body = dom.element('div', { 'class': 'ge-nav-options' });
|
|
318
|
+
var fields = {};
|
|
319
|
+
|
|
320
|
+
function change(key, value) {
|
|
321
|
+
write(container, key, value, { mark: true });
|
|
322
|
+
markLayout(container);
|
|
323
|
+
sections.render();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function select(name, label, choices, onChange) {
|
|
327
|
+
var field = selectControl(choices, onChange);
|
|
328
|
+
|
|
329
|
+
fields[name] = field.control;
|
|
330
|
+
body.appendChild(fieldRow(name, label, field.control, field.id));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
var brand = checkControl(ge.t('container.nav_brand_show'), function(on) {
|
|
334
|
+
write(container, 'brand', on);
|
|
335
|
+
baseMark(container);
|
|
336
|
+
sections.render();
|
|
337
|
+
});
|
|
338
|
+
brand.box.setAttribute('data-ge-nav-option', 'brand');
|
|
339
|
+
body.appendChild(brand.box);
|
|
340
|
+
|
|
341
|
+
select('expand', ge.t('container.navbar_expand'), [
|
|
342
|
+
{ value: 'false', label: ge.t('container.navbar_expand_never') },
|
|
343
|
+
{ value: 'true', label: ge.t('container.navbar_expand_always') },
|
|
344
|
+
].concat(BREAKPOINTS.map(function(key) {
|
|
345
|
+
return { value: key, label: ge.t('container.navbar_expand_from', { breakpoint: key }) };
|
|
346
|
+
})), function(value) { change('expand', value === 'true' ? true : value === 'false' ? false : value); });
|
|
347
|
+
|
|
348
|
+
select('collapse', ge.t('container.navbar_collapse'), [
|
|
349
|
+
{ value: 'none', label: ge.t('container.navbar_collapse_none') },
|
|
350
|
+
{ value: 'collapse', label: ge.t('container.navbar_collapse_collapse') },
|
|
351
|
+
{ value: 'offcanvas', label: ge.t('container.navbar_collapse_offcanvas') },
|
|
352
|
+
], function(value) { change('collapse', value === 'none' ? false : value); });
|
|
353
|
+
|
|
354
|
+
select('offcanvas_placement', ge.t('container.navbar_offcanvas_placement'), [
|
|
355
|
+
{ value: 'start', label: ge.t('container.nav_start') },
|
|
356
|
+
{ value: 'end', label: ge.t('container.nav_end') },
|
|
357
|
+
], function(value) { change('offcanvas_placement', value); });
|
|
358
|
+
|
|
359
|
+
select('bg', ge.t('container.nav_bg'), [{ value: 'none', label: ge.t('container.nav_bg_none') }].concat(
|
|
360
|
+
BACKGROUND_CHOICES.map(function(each) { return { value: each.value, label: ge.t(each.labelKey) }; })
|
|
361
|
+
), function(value) { change('bg', value === 'none' ? null : value); });
|
|
362
|
+
|
|
363
|
+
select('theme', ge.t('container.nav_theme'), [
|
|
364
|
+
{ value: 'auto', label: ge.t('container.nav_theme_auto') },
|
|
365
|
+
{ value: 'light', label: ge.t('container.nav_theme_light') },
|
|
366
|
+
{ value: 'dark', label: ge.t('container.nav_theme_dark') },
|
|
367
|
+
], function(value) { change('theme', value === 'auto' ? null : value); });
|
|
368
|
+
|
|
369
|
+
select('position', ge.t('container.navbar_position'), [
|
|
370
|
+
{ value: 'none', label: ge.t('container.navbar_position_none') },
|
|
371
|
+
].concat(POSITION_CHOICES.map(function(each) {
|
|
372
|
+
return { value: each.value, label: ge.t(each.labelKey) };
|
|
373
|
+
})), function(value) { change('position', value === 'none' ? null : value); });
|
|
374
|
+
|
|
375
|
+
select('width', ge.t('container.navbar_width'), [
|
|
376
|
+
{ value: 'fluid', label: ge.t('container.navbar_width_fluid') },
|
|
377
|
+
{ value: 'fixed', label: ge.t('container.navbar_width_fixed') },
|
|
378
|
+
].concat(BREAKPOINTS.map(function(key) {
|
|
379
|
+
return { value: key, label: ge.t('container.navbar_width_from', { breakpoint: key }) };
|
|
380
|
+
})), function(value) { change('width', value); });
|
|
381
|
+
|
|
382
|
+
function render() {
|
|
383
|
+
var values = read(container);
|
|
384
|
+
|
|
385
|
+
brand.input.checked = values.brand;
|
|
386
|
+
fields.expand.value = String(values.expand);
|
|
387
|
+
fields.collapse.value = values.collapse === false ? 'none' : values.collapse;
|
|
388
|
+
fields.offcanvas_placement.value = values.offcanvas_placement || placementOf();
|
|
389
|
+
fields.offcanvas_placement.disabled = values.collapse !== 'offcanvas';
|
|
390
|
+
fields.bg.value = values.bg === null ? 'none' : values.bg;
|
|
391
|
+
fields.theme.value = values.theme === null ? 'auto' : values.theme;
|
|
392
|
+
fields.position.value = values.position === null ? 'none' : values.position;
|
|
393
|
+
fields.width.value = values.width;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
render();
|
|
397
|
+
sections.add({ node: container, element: body, render: render });
|
|
398
|
+
|
|
399
|
+
return body;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return Object.assign(base, {
|
|
403
|
+
labelKey: 'container.add_navbar',
|
|
404
|
+
|
|
405
|
+
create: function(options) {
|
|
406
|
+
options = options || {};
|
|
407
|
+
|
|
408
|
+
var container = dom.element('div', { 'data-ge-container': 'navbar' });
|
|
409
|
+
var nav = container.appendChild(dom.element('nav', { 'class': 'navbar' }));
|
|
410
|
+
var wrap = nav.appendChild(dom.element('div', { 'class': 'container-fluid' }));
|
|
411
|
+
|
|
412
|
+
var brand = brandOf(options);
|
|
413
|
+
if (brand !== false) { wrap.appendChild(dom.element('a', { 'class': 'navbar-brand', href: '#' }, brand)); }
|
|
414
|
+
|
|
415
|
+
var list = wrap.appendChild(markup.list(ge, 'navbar', true, 2));
|
|
416
|
+
list.appendChild(markup.dropdown(ge));
|
|
417
|
+
|
|
418
|
+
['expand', 'bg', 'theme', 'position', 'width'].forEach(function(key) {
|
|
419
|
+
write(container, key, chosen(options, key));
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
var collapse = chosen(options, 'collapse');
|
|
423
|
+
var placement = chosen(options, 'offcanvas_placement');
|
|
424
|
+
|
|
425
|
+
write(container, 'collapse', collapse, { placement: placement });
|
|
426
|
+
|
|
427
|
+
return container;
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
mark: function(container) {
|
|
431
|
+
baseMark(container);
|
|
432
|
+
markLayout(container);
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
unmark: function(container) {
|
|
436
|
+
baseUnmark(container);
|
|
437
|
+
container.removeAttribute(LAYOUT_ATTR);
|
|
438
|
+
},
|
|
439
|
+
|
|
440
|
+
panelSection: function(node, kind) {
|
|
441
|
+
if (kind !== 'navbar' || !navOf(node)) { return null; }
|
|
442
|
+
|
|
443
|
+
return { labelKey: 'container.navbar_section', body: createSection(node) };
|
|
444
|
+
},
|
|
445
|
+
|
|
446
|
+
// After a view change or a change of classes: the layout marks and the sections follow
|
|
447
|
+
onRefresh: function(scope) {
|
|
448
|
+
dom.selfAndAll(scope, '[data-ge-container="navbar"]').forEach(markLayout);
|
|
449
|
+
sections.render(scope);
|
|
450
|
+
},
|
|
451
|
+
|
|
452
|
+
onDeinit: function() { sections.clear(); },
|
|
453
|
+
});
|
|
454
|
+
};
|