@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,2085 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
// src/js/register.js
|
|
3
|
+
var GridEditor = window.GridEditor;
|
|
4
|
+
if (!GridEditor || typeof GridEditor.get !== "function") {
|
|
5
|
+
throw new Error("grid-editor: load grideditor.js (or grideditor.bundle.min.js) before its plugins, its locales and grideditor.jquery.js");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/js/dom.js
|
|
9
|
+
function all(root, selector) {
|
|
10
|
+
return root ? Array.prototype.slice.call(root.querySelectorAll(selector)) : [];
|
|
11
|
+
}
|
|
12
|
+
function one(root, selector) {
|
|
13
|
+
return root ? root.querySelector(selector) : null;
|
|
14
|
+
}
|
|
15
|
+
function selfAndAll(root, selector) {
|
|
16
|
+
if (!root) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
var found = all(root, selector);
|
|
20
|
+
if (root.nodeType === 1 && root.matches(selector)) {
|
|
21
|
+
found.unshift(root);
|
|
22
|
+
}
|
|
23
|
+
return found;
|
|
24
|
+
}
|
|
25
|
+
function children(node, selector) {
|
|
26
|
+
if (!node) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
return Array.prototype.filter.call(node.children, function(each) {
|
|
30
|
+
return !selector || each.matches(selector);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function child(node, selector) {
|
|
34
|
+
return children(node, selector)[0] || null;
|
|
35
|
+
}
|
|
36
|
+
function closest(node, selector, stopAt) {
|
|
37
|
+
var found = node && node.nodeType === 1 ? node.closest(selector) : null;
|
|
38
|
+
if (found && stopAt && found !== stopAt && !stopAt.contains(found)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return found;
|
|
42
|
+
}
|
|
43
|
+
function is(node, selector) {
|
|
44
|
+
return !!node && node.nodeType === 1 && node.matches(selector);
|
|
45
|
+
}
|
|
46
|
+
function element(tag, attributes, text2) {
|
|
47
|
+
var node = document.createElement(tag);
|
|
48
|
+
Object.keys(attributes || {}).forEach(function(name) {
|
|
49
|
+
var value = attributes[name];
|
|
50
|
+
if (value !== null && value !== void 0 && value !== false) {
|
|
51
|
+
node.setAttribute(name, value);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (text2 !== void 0 && text2 !== null) {
|
|
55
|
+
node.textContent = text2;
|
|
56
|
+
}
|
|
57
|
+
return node;
|
|
58
|
+
}
|
|
59
|
+
function addClass(node, names) {
|
|
60
|
+
split(names).forEach(function(name) {
|
|
61
|
+
node.classList.add(name);
|
|
62
|
+
});
|
|
63
|
+
return node;
|
|
64
|
+
}
|
|
65
|
+
function removeClass(node, names) {
|
|
66
|
+
split(names).forEach(function(name) {
|
|
67
|
+
node.classList.remove(name);
|
|
68
|
+
});
|
|
69
|
+
return node;
|
|
70
|
+
}
|
|
71
|
+
function toggleClass(node, names, state) {
|
|
72
|
+
split(names).forEach(function(name) {
|
|
73
|
+
if (state === void 0) {
|
|
74
|
+
node.classList.toggle(name);
|
|
75
|
+
} else {
|
|
76
|
+
node.classList.toggle(name, !!state);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return node;
|
|
80
|
+
}
|
|
81
|
+
function hasClass(node, name) {
|
|
82
|
+
return !!node && node.nodeType === 1 && node.classList.contains(name);
|
|
83
|
+
}
|
|
84
|
+
function split(names) {
|
|
85
|
+
return String(names || "").split(/\s+/).filter(Boolean);
|
|
86
|
+
}
|
|
87
|
+
function dropEmptyClass(node) {
|
|
88
|
+
if (!node.getAttribute("class")) {
|
|
89
|
+
node.removeAttribute("class");
|
|
90
|
+
}
|
|
91
|
+
return node;
|
|
92
|
+
}
|
|
93
|
+
function dropEmptyStyle(node) {
|
|
94
|
+
if (!node.getAttribute("style")) {
|
|
95
|
+
node.removeAttribute("style");
|
|
96
|
+
}
|
|
97
|
+
return node;
|
|
98
|
+
}
|
|
99
|
+
function attr(node, attributes) {
|
|
100
|
+
Object.keys(attributes).forEach(function(name) {
|
|
101
|
+
var value = attributes[name];
|
|
102
|
+
if (value === null || value === void 0) {
|
|
103
|
+
node.removeAttribute(name);
|
|
104
|
+
} else {
|
|
105
|
+
node.setAttribute(name, value);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return node;
|
|
109
|
+
}
|
|
110
|
+
function hide(node) {
|
|
111
|
+
node.style.display = "none";
|
|
112
|
+
return node;
|
|
113
|
+
}
|
|
114
|
+
function visible(node) {
|
|
115
|
+
return !!(node.offsetWidth || node.offsetHeight || node.getClientRects().length);
|
|
116
|
+
}
|
|
117
|
+
function delegate(root, types, selector, handler, options) {
|
|
118
|
+
var listener = function(event) {
|
|
119
|
+
var match = closest(event.target, selector, root);
|
|
120
|
+
if (match && root.contains(match)) {
|
|
121
|
+
return handler.call(match, event);
|
|
122
|
+
}
|
|
123
|
+
return void 0;
|
|
124
|
+
};
|
|
125
|
+
split(types).forEach(function(type) {
|
|
126
|
+
root.addEventListener(type, listener, options);
|
|
127
|
+
});
|
|
128
|
+
return listener;
|
|
129
|
+
}
|
|
130
|
+
var DEFAULT_DURATION = 400;
|
|
131
|
+
function animateAway(node, frames, duration, done) {
|
|
132
|
+
duration = duration === void 0 ? DEFAULT_DURATION : duration;
|
|
133
|
+
addClass(node, "ge-leaving");
|
|
134
|
+
var finish = function() {
|
|
135
|
+
removeClass(node, "ge-leaving");
|
|
136
|
+
dropEmptyClass(node);
|
|
137
|
+
hide(node);
|
|
138
|
+
if (done) {
|
|
139
|
+
done();
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
if (!visible(node) || !node.animate || duration <= 0) {
|
|
143
|
+
window.setTimeout(finish, 0);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
var animation = node.animate(frames(getComputedStyle(node)), {
|
|
147
|
+
duration,
|
|
148
|
+
easing: "ease-in-out"
|
|
149
|
+
});
|
|
150
|
+
var called = false;
|
|
151
|
+
var once = function() {
|
|
152
|
+
if (called) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
called = true;
|
|
156
|
+
finish();
|
|
157
|
+
};
|
|
158
|
+
animation.onfinish = once;
|
|
159
|
+
animation.oncancel = once;
|
|
160
|
+
}
|
|
161
|
+
function fadeOut(node, duration, done) {
|
|
162
|
+
animateAway(node, function(style) {
|
|
163
|
+
return [{ opacity: style.opacity }, { opacity: 0 }];
|
|
164
|
+
}, duration, done);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/js/nav/locale.js
|
|
168
|
+
var EN = {
|
|
169
|
+
"container.navbar_brand": "Brand",
|
|
170
|
+
"container.sidenav_brand": "Brand",
|
|
171
|
+
"container.nav_link": "Link",
|
|
172
|
+
"container.nav_dropdown": "Dropdown",
|
|
173
|
+
"container.nav_submenu": "Submenu",
|
|
174
|
+
"container.nav_menu_link": "Action",
|
|
175
|
+
"container.nav_menu_header": "Header",
|
|
176
|
+
"container.nav_text": "Text",
|
|
177
|
+
"container.navbar_toggle": "Toggle navigation",
|
|
178
|
+
"container.navbar_offcanvas_title": "Menu",
|
|
179
|
+
"container.sidenav_trigger": "Menu",
|
|
180
|
+
"tool.add_nav_piece": "Add\u2026",
|
|
181
|
+
"tool.add_nav_link": "Add link or dropdown",
|
|
182
|
+
"tool.add_nav_menu_item": "Add item",
|
|
183
|
+
"tool.fold_nav_menu": "Fold this menu while editing",
|
|
184
|
+
"confirm.delete_nav_piece": "Delete this and everything in it?",
|
|
185
|
+
"container.navbar_section": "Navbar",
|
|
186
|
+
"container.sidenav_section": "Sidebar",
|
|
187
|
+
"container.nav_brand_show": "Brand",
|
|
188
|
+
"container.nav_brand_image": "Image",
|
|
189
|
+
"container.nav_brand_alt": "Alt text",
|
|
190
|
+
"container.nav_brand_height": "Height (px)",
|
|
191
|
+
"container.navbar_expand": "Expand",
|
|
192
|
+
"container.navbar_expand_never": "Never",
|
|
193
|
+
"container.navbar_expand_always": "Always",
|
|
194
|
+
"container.navbar_expand_from": "From {breakpoint}",
|
|
195
|
+
"container.navbar_collapse": "Collapse",
|
|
196
|
+
"container.navbar_collapse_collapse": "Collapse",
|
|
197
|
+
"container.navbar_collapse_offcanvas": "Offcanvas",
|
|
198
|
+
"container.navbar_collapse_none": "Not collapsed",
|
|
199
|
+
"container.navbar_offcanvas_placement": "Side",
|
|
200
|
+
"container.nav_start": "Start",
|
|
201
|
+
"container.nav_end": "End",
|
|
202
|
+
"container.nav_bg": "Background",
|
|
203
|
+
"container.nav_bg_none": "None",
|
|
204
|
+
"container.nav_bg_body_tertiary": "Light grey",
|
|
205
|
+
"container.nav_bg_body": "Page",
|
|
206
|
+
"container.nav_bg_primary": "Primary",
|
|
207
|
+
"container.nav_bg_secondary": "Secondary",
|
|
208
|
+
"container.nav_bg_success": "Success",
|
|
209
|
+
"container.nav_bg_danger": "Danger",
|
|
210
|
+
"container.nav_bg_warning": "Warning",
|
|
211
|
+
"container.nav_bg_info": "Info",
|
|
212
|
+
"container.nav_bg_light": "Light",
|
|
213
|
+
"container.nav_bg_dark": "Dark",
|
|
214
|
+
"container.nav_theme": "Theme",
|
|
215
|
+
"container.nav_theme_auto": "Auto",
|
|
216
|
+
"container.nav_theme_light": "Light",
|
|
217
|
+
"container.nav_theme_dark": "Dark",
|
|
218
|
+
"container.navbar_position": "Position",
|
|
219
|
+
"container.navbar_position_none": "In the flow",
|
|
220
|
+
"container.navbar_position_fixed_top": "Fixed top",
|
|
221
|
+
"container.navbar_position_fixed_bottom": "Fixed bottom",
|
|
222
|
+
"container.navbar_position_sticky_top": "Sticky top",
|
|
223
|
+
"container.navbar_position_sticky_bottom": "Sticky bottom",
|
|
224
|
+
"container.navbar_width": "Inner width",
|
|
225
|
+
"container.navbar_width_fluid": "Full",
|
|
226
|
+
"container.navbar_width_fixed": "Fixed",
|
|
227
|
+
"container.navbar_width_from": "Full up to {breakpoint}",
|
|
228
|
+
"container.sidenav_width": "Width",
|
|
229
|
+
"container.sidenav_style": "Link style",
|
|
230
|
+
"container.sidenav_style_pills": "Pills",
|
|
231
|
+
"container.sidenav_style_plain": "Plain",
|
|
232
|
+
"container.sidenav_full_height": "Full height",
|
|
233
|
+
"container.sidenav_responsive": "Responsive",
|
|
234
|
+
"container.sidenav_responsive_never": "Always visible",
|
|
235
|
+
"container.sidenav_responsive_from": "Offcanvas below {breakpoint}",
|
|
236
|
+
"container.sidenav_offcanvas_title": "Menu",
|
|
237
|
+
"container.nav_close": "Close",
|
|
238
|
+
"container.nav_list_section": "List",
|
|
239
|
+
"container.nav_link_section": "Link",
|
|
240
|
+
"container.nav_dropdown_section": "Dropdown",
|
|
241
|
+
"container.nav_menu_item_section": "Item",
|
|
242
|
+
"container.nav_text_section": "Text",
|
|
243
|
+
"container.nav_zone_section": "Free zone",
|
|
244
|
+
"container.nav_brand_section": "Brand",
|
|
245
|
+
"container.nav_align": "Alignment",
|
|
246
|
+
"container.nav_align_after": "After the previous",
|
|
247
|
+
"container.nav_align_end": "At the end",
|
|
248
|
+
"container.nav_align_center": "Centered",
|
|
249
|
+
"container.nav_scroll": "Scroll",
|
|
250
|
+
"container.nav_scroll_height": "Height",
|
|
251
|
+
"container.nav_bottom": "At the bottom",
|
|
252
|
+
"container.nav_href": "URL",
|
|
253
|
+
"container.nav_active": "Active",
|
|
254
|
+
"container.nav_disabled": "Disabled",
|
|
255
|
+
"container.nav_new_tab": "New tab",
|
|
256
|
+
"container.nav_menu_end": "Menu on the right",
|
|
257
|
+
"container.nav_submenu_type": "Type",
|
|
258
|
+
"container.nav_submenu_type_collapse": "Collapsible",
|
|
259
|
+
"container.nav_submenu_type_dropdown": "Dropdown",
|
|
260
|
+
"container.nav_submenu_open": "Open on load",
|
|
261
|
+
"container.nav_menu_divider": "Divider",
|
|
262
|
+
"container.nav_zone": "Free zone",
|
|
263
|
+
"tool.add_nav_list": "Add list",
|
|
264
|
+
"tool.add_nav_text": "Add text",
|
|
265
|
+
"tool.add_nav_zone": "Add free zone",
|
|
266
|
+
"tool.unfold_nav_menu": "Unfold this menu",
|
|
267
|
+
"container.nav_browse": "Browse\u2026",
|
|
268
|
+
"tool.delete_nav_piece": "Delete"
|
|
269
|
+
};
|
|
270
|
+
var BACKGROUND_CHOICES = [
|
|
271
|
+
{ value: "body-tertiary", labelKey: "container.nav_bg_body_tertiary" },
|
|
272
|
+
{ value: "body", labelKey: "container.nav_bg_body" },
|
|
273
|
+
{ value: "primary", labelKey: "container.nav_bg_primary" },
|
|
274
|
+
{ value: "secondary", labelKey: "container.nav_bg_secondary" },
|
|
275
|
+
{ value: "success", labelKey: "container.nav_bg_success" },
|
|
276
|
+
{ value: "danger", labelKey: "container.nav_bg_danger" },
|
|
277
|
+
{ value: "warning", labelKey: "container.nav_bg_warning" },
|
|
278
|
+
{ value: "info", labelKey: "container.nav_bg_info" },
|
|
279
|
+
{ value: "light", labelKey: "container.nav_bg_light" },
|
|
280
|
+
{ value: "dark", labelKey: "container.nav_bg_dark" }
|
|
281
|
+
];
|
|
282
|
+
var POSITION_CHOICES = [
|
|
283
|
+
{ value: "fixed-top", labelKey: "container.navbar_position_fixed_top" },
|
|
284
|
+
{ value: "fixed-bottom", labelKey: "container.navbar_position_fixed_bottom" },
|
|
285
|
+
{ value: "sticky-top", labelKey: "container.navbar_position_sticky_top" },
|
|
286
|
+
{ value: "sticky-bottom", labelKey: "container.navbar_position_sticky_bottom" }
|
|
287
|
+
];
|
|
288
|
+
|
|
289
|
+
// src/js/nav/pieces.js
|
|
290
|
+
var TYPES = ["navbar", "sidenav"];
|
|
291
|
+
var WRAPS = ".container, .container-fluid, .container-sm, .container-md, .container-lg, .container-xl, .container-xxl";
|
|
292
|
+
var KINDS = ["nav-list", "nav-link", "nav-dropdown", "nav-menu-item", "nav-text", "nav-zone", "nav-brand"];
|
|
293
|
+
function typeOf(container) {
|
|
294
|
+
return container ? container.getAttribute("data-ge-container") : null;
|
|
295
|
+
}
|
|
296
|
+
function isZone(node) {
|
|
297
|
+
return is(node, '[data-ge-nav="zone"]');
|
|
298
|
+
}
|
|
299
|
+
function isSubmenu(node) {
|
|
300
|
+
return is(node, 'li[data-ge-nav="submenu"]');
|
|
301
|
+
}
|
|
302
|
+
function navOf(container) {
|
|
303
|
+
return child(container, "nav");
|
|
304
|
+
}
|
|
305
|
+
function wrapOf(container) {
|
|
306
|
+
var nav = navOf(container);
|
|
307
|
+
return nav ? child(nav, WRAPS) || nav : null;
|
|
308
|
+
}
|
|
309
|
+
function areaOf(container) {
|
|
310
|
+
var wrap = wrapOf(container);
|
|
311
|
+
if (!wrap) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
var collapse = child(wrap, ".navbar-collapse");
|
|
315
|
+
if (collapse) {
|
|
316
|
+
return collapse;
|
|
317
|
+
}
|
|
318
|
+
var offcanvas = child(wrap, ".offcanvas");
|
|
319
|
+
var body = offcanvas ? child(offcanvas, ".offcanvas-body") : null;
|
|
320
|
+
return body || wrap;
|
|
321
|
+
}
|
|
322
|
+
function offcanvasOf(container) {
|
|
323
|
+
var wrap = wrapOf(container);
|
|
324
|
+
return wrap ? child(wrap, ".offcanvas") : null;
|
|
325
|
+
}
|
|
326
|
+
function panelOf(container) {
|
|
327
|
+
return children(container).filter(function(node) {
|
|
328
|
+
return !hasClass(node, "ge-tools-drawer") && node.tagName !== "BUTTON";
|
|
329
|
+
})[0] || null;
|
|
330
|
+
}
|
|
331
|
+
function triggerOf(container) {
|
|
332
|
+
return child(container, "button");
|
|
333
|
+
}
|
|
334
|
+
function holderOf(container) {
|
|
335
|
+
return typeOf(container) === "sidenav" ? panelOf(container) : areaOf(container);
|
|
336
|
+
}
|
|
337
|
+
function ownerOf(node, loaded) {
|
|
338
|
+
var holder = node && node.parentElement ? node.parentElement.closest('[data-ge-container], [data-ge-nav="zone"]') : null;
|
|
339
|
+
if (!holder || isZone(holder)) {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
return loaded(typeOf(holder)) ? holder : null;
|
|
343
|
+
}
|
|
344
|
+
function isMenu(node) {
|
|
345
|
+
return is(node, ".dropdown-menu");
|
|
346
|
+
}
|
|
347
|
+
function menuOf(dropdown2) {
|
|
348
|
+
if (isSubmenu(dropdown2)) {
|
|
349
|
+
return one(dropdown2, ":scope > .collapse > ul");
|
|
350
|
+
}
|
|
351
|
+
return child(dropdown2, ".dropdown-menu");
|
|
352
|
+
}
|
|
353
|
+
function itemType(item) {
|
|
354
|
+
if (child(item, "hr")) {
|
|
355
|
+
return "divider";
|
|
356
|
+
}
|
|
357
|
+
if (child(item, "h6")) {
|
|
358
|
+
return "header";
|
|
359
|
+
}
|
|
360
|
+
if (child(item, "a")) {
|
|
361
|
+
return "link";
|
|
362
|
+
}
|
|
363
|
+
return "text";
|
|
364
|
+
}
|
|
365
|
+
function anchorOf(piece) {
|
|
366
|
+
return child(piece, "a");
|
|
367
|
+
}
|
|
368
|
+
function kindOf(node, loaded) {
|
|
369
|
+
var container = ownerOf(node, loaded);
|
|
370
|
+
if (!container) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
var type = typeOf(container);
|
|
374
|
+
var parent = node.parentElement;
|
|
375
|
+
var holder = holderOf(container);
|
|
376
|
+
if (parent === holder || type === "navbar" && parent === wrapOf(container) && is(node, ".navbar-brand")) {
|
|
377
|
+
if (isZone(node)) {
|
|
378
|
+
return "nav-zone";
|
|
379
|
+
}
|
|
380
|
+
if (type === "navbar") {
|
|
381
|
+
if (is(node, ".navbar-brand")) {
|
|
382
|
+
return "nav-brand";
|
|
383
|
+
}
|
|
384
|
+
if (is(node, "ul.navbar-nav")) {
|
|
385
|
+
return "nav-list";
|
|
386
|
+
}
|
|
387
|
+
if (is(node, ".navbar-text")) {
|
|
388
|
+
return "nav-text";
|
|
389
|
+
}
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
if (is(node, 'a[data-ge-nav="brand"]')) {
|
|
393
|
+
return "nav-brand";
|
|
394
|
+
}
|
|
395
|
+
if (is(node, "ul.nav")) {
|
|
396
|
+
return "nav-list";
|
|
397
|
+
}
|
|
398
|
+
if (is(node, '[data-ge-nav="text"]')) {
|
|
399
|
+
return "nav-text";
|
|
400
|
+
}
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
if (!is(node, "li") || !parent) {
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
if (is(parent, "ul") && parent.parentElement && kindOf(parent, loaded) === "nav-list") {
|
|
407
|
+
if (is(node, ".nav-item.dropdown") || type === "sidenav" && isSubmenu(node)) {
|
|
408
|
+
return "nav-dropdown";
|
|
409
|
+
}
|
|
410
|
+
if (is(node, ".nav-item") && child(node, "a.nav-link")) {
|
|
411
|
+
return "nav-link";
|
|
412
|
+
}
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
if (isMenu(parent) && is(parent.parentElement, "li.nav-item.dropdown") && kindOf(parent.parentElement, loaded) === "nav-dropdown") {
|
|
416
|
+
return "nav-menu-item";
|
|
417
|
+
}
|
|
418
|
+
if (type === "sidenav" && is(parent, "ul") && is(parent.parentElement, ".collapse") && isSubmenu(parent.parentElement.parentElement) && kindOf(parent.parentElement.parentElement, loaded) === "nav-dropdown") {
|
|
419
|
+
return "nav-menu-item";
|
|
420
|
+
}
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
function piecesOf(container, loaded) {
|
|
424
|
+
var found = [];
|
|
425
|
+
all(container, "*").forEach(function(node) {
|
|
426
|
+
if (ownerOf(node, loaded) !== container) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
var kind = kindOf(node, loaded);
|
|
430
|
+
if (kind) {
|
|
431
|
+
found.push({ node, kind });
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
return found;
|
|
435
|
+
}
|
|
436
|
+
function isOwn(container, node) {
|
|
437
|
+
var scope = node.parentElement ? node.parentElement.closest('[data-ge-container], [data-ge-nav="zone"]') : null;
|
|
438
|
+
return scope === container;
|
|
439
|
+
}
|
|
440
|
+
function togglesOf(container) {
|
|
441
|
+
return all(container, "[data-bs-toggle], [data-ge-bs-toggle], [data-bs-dismiss], [data-ge-bs-dismiss]").filter(function(node) {
|
|
442
|
+
return isOwn(container, node);
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
function defaultLabelKey(node, kind, container) {
|
|
446
|
+
var type = typeOf(container);
|
|
447
|
+
if (kind === "nav-link") {
|
|
448
|
+
return "container.nav_link";
|
|
449
|
+
}
|
|
450
|
+
if (kind === "nav-dropdown") {
|
|
451
|
+
return isSubmenu(node) ? "container.nav_submenu" : "container.nav_dropdown";
|
|
452
|
+
}
|
|
453
|
+
if (kind === "nav-text") {
|
|
454
|
+
return "container.nav_text";
|
|
455
|
+
}
|
|
456
|
+
if (kind === "nav-brand") {
|
|
457
|
+
return type === "sidenav" ? "container.sidenav_brand" : "container.navbar_brand";
|
|
458
|
+
}
|
|
459
|
+
var itemKind = itemType(node);
|
|
460
|
+
if (itemKind === "header") {
|
|
461
|
+
return "container.nav_menu_header";
|
|
462
|
+
}
|
|
463
|
+
if (itemKind === "text") {
|
|
464
|
+
return "container.nav_text";
|
|
465
|
+
}
|
|
466
|
+
return "container.nav_menu_link";
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// src/js/nav/markup.js
|
|
470
|
+
var MENU_CLASSES = {
|
|
471
|
+
link: "dropdown-item",
|
|
472
|
+
divider: "dropdown-divider",
|
|
473
|
+
header: "dropdown-header",
|
|
474
|
+
text: "dropdown-item-text"
|
|
475
|
+
};
|
|
476
|
+
var SUBMENU_CLASSES = {
|
|
477
|
+
link: "nav-link",
|
|
478
|
+
divider: "my-1",
|
|
479
|
+
header: "small text-body-secondary px-3 pt-2 mb-1",
|
|
480
|
+
text: "d-block small px-3 py-1"
|
|
481
|
+
};
|
|
482
|
+
var ITEM_TAGS = { link: "a", divider: "hr", header: "h6", text: "span" };
|
|
483
|
+
function menuItem(ge, type, context) {
|
|
484
|
+
var classes = context === "submenu" ? SUBMENU_CLASSES : MENU_CLASSES;
|
|
485
|
+
var item = element("li", type === "link" && context === "submenu" ? { "class": "nav-item" } : {});
|
|
486
|
+
var inner = element(ITEM_TAGS[type], { "class": classes[type] });
|
|
487
|
+
if (type === "link") {
|
|
488
|
+
inner.setAttribute("href", "#");
|
|
489
|
+
inner.textContent = ge.t("container.nav_menu_link");
|
|
490
|
+
} else if (type === "header") {
|
|
491
|
+
inner.textContent = ge.t("container.nav_menu_header");
|
|
492
|
+
} else if (type === "text") {
|
|
493
|
+
inner.textContent = ge.t("container.nav_text");
|
|
494
|
+
}
|
|
495
|
+
item.appendChild(inner);
|
|
496
|
+
return item;
|
|
497
|
+
}
|
|
498
|
+
function link(ge) {
|
|
499
|
+
var item = element("li", { "class": "nav-item" });
|
|
500
|
+
item.appendChild(element("a", { "class": "nav-link", href: "#" }, ge.t("container.nav_link")));
|
|
501
|
+
return item;
|
|
502
|
+
}
|
|
503
|
+
function dropdown(ge) {
|
|
504
|
+
var item = element("li", { "class": "nav-item dropdown" });
|
|
505
|
+
item.appendChild(element("a", {
|
|
506
|
+
"class": "nav-link dropdown-toggle",
|
|
507
|
+
href: "#",
|
|
508
|
+
role: "button",
|
|
509
|
+
"data-bs-toggle": "dropdown",
|
|
510
|
+
"aria-expanded": "false"
|
|
511
|
+
}, ge.t("container.nav_dropdown")));
|
|
512
|
+
var menu = item.appendChild(element("ul", { "class": "dropdown-menu" }));
|
|
513
|
+
menu.appendChild(menuItem(ge, "link", "menu"));
|
|
514
|
+
menu.appendChild(menuItem(ge, "link", "menu"));
|
|
515
|
+
return item;
|
|
516
|
+
}
|
|
517
|
+
function submenu(ge) {
|
|
518
|
+
var id = ge.containerId("nav");
|
|
519
|
+
var item = element("li", { "class": "nav-item", "data-ge-nav": "submenu" });
|
|
520
|
+
item.appendChild(element("a", {
|
|
521
|
+
"class": "nav-link dropdown-toggle",
|
|
522
|
+
href: "#" + id,
|
|
523
|
+
"data-bs-toggle": "collapse",
|
|
524
|
+
role: "button",
|
|
525
|
+
"aria-expanded": "false",
|
|
526
|
+
"aria-controls": id
|
|
527
|
+
}, ge.t("container.nav_submenu")));
|
|
528
|
+
var menu = item.appendChild(element("div", { "class": "collapse", id })).appendChild(element("ul", { "class": "nav flex-column ms-3" }));
|
|
529
|
+
menu.appendChild(menuItem(ge, "link", "submenu"));
|
|
530
|
+
menu.appendChild(menuItem(ge, "link", "submenu"));
|
|
531
|
+
return item;
|
|
532
|
+
}
|
|
533
|
+
function listClass(type, pills) {
|
|
534
|
+
return type === "sidenav" ? "nav" + (pills ? " nav-pills" : "") + " flex-column" : "navbar-nav";
|
|
535
|
+
}
|
|
536
|
+
function list(ge, type, pills, count) {
|
|
537
|
+
var ul = element("ul", { "class": listClass(type, pills) });
|
|
538
|
+
for (var i = 0; i < count; i++) {
|
|
539
|
+
ul.appendChild(link(ge));
|
|
540
|
+
}
|
|
541
|
+
return ul;
|
|
542
|
+
}
|
|
543
|
+
function text(ge, type) {
|
|
544
|
+
var label = ge.t("container.nav_text");
|
|
545
|
+
return type === "sidenav" ? element("div", { "class": "px-3 py-2", "data-ge-nav": "text" }, label) : element("span", { "class": "navbar-text" }, label);
|
|
546
|
+
}
|
|
547
|
+
function zone(ge) {
|
|
548
|
+
var node = element("div", { "class": "d-block", "data-ge-nav": "zone" });
|
|
549
|
+
node.appendChild(ge.defaultRegion());
|
|
550
|
+
return node;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/js/nav/convert.js
|
|
554
|
+
function setItemContext(item, context) {
|
|
555
|
+
var type = itemType(item);
|
|
556
|
+
var inner = child(item, ITEM_TAGS[type]);
|
|
557
|
+
var from = context === "submenu" ? MENU_CLASSES : SUBMENU_CLASSES;
|
|
558
|
+
var to = context === "submenu" ? SUBMENU_CLASSES : MENU_CLASSES;
|
|
559
|
+
if (!inner) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
var own = String(from[type]).split(" ");
|
|
563
|
+
var rest = Array.prototype.filter.call(inner.classList, function(name) {
|
|
564
|
+
return own.indexOf(name) === -1;
|
|
565
|
+
});
|
|
566
|
+
inner.className = [to[type]].concat(rest).join(" ");
|
|
567
|
+
if (type === "link") {
|
|
568
|
+
toggleClass(item, "nav-item", context === "submenu");
|
|
569
|
+
}
|
|
570
|
+
dropEmptyClass(item);
|
|
571
|
+
}
|
|
572
|
+
function apartAgain(ge, node) {
|
|
573
|
+
if (!ge.previewing()) {
|
|
574
|
+
ge.suspendToggles(node);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function setToggle(a, attributes) {
|
|
578
|
+
["data-bs-toggle", "data-ge-bs-toggle", "aria-controls", "aria-expanded", "role"].forEach(function(name) {
|
|
579
|
+
a.removeAttribute(name);
|
|
580
|
+
});
|
|
581
|
+
attr(a, attributes);
|
|
582
|
+
}
|
|
583
|
+
function toDropdown(ge, item) {
|
|
584
|
+
if (!isSubmenu(item)) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
var toggle = child(item, "a");
|
|
588
|
+
var collapse = child(item, ".collapse");
|
|
589
|
+
var menu = collapse ? child(collapse, "ul") : null;
|
|
590
|
+
item.removeAttribute("data-ge-nav");
|
|
591
|
+
addClass(item, "dropdown");
|
|
592
|
+
setToggle(toggle, { href: "#", role: "button", "data-bs-toggle": "dropdown", "aria-expanded": "false" });
|
|
593
|
+
if (menu) {
|
|
594
|
+
removeClass(menu, "nav flex-column ms-3");
|
|
595
|
+
addClass(menu, "dropdown-menu");
|
|
596
|
+
children(menu, "li").forEach(function(each) {
|
|
597
|
+
setItemContext(each, "menu");
|
|
598
|
+
});
|
|
599
|
+
item.insertBefore(menu, collapse);
|
|
600
|
+
collapse.remove();
|
|
601
|
+
}
|
|
602
|
+
apartAgain(ge, item);
|
|
603
|
+
}
|
|
604
|
+
function toSubmenu(ge, item) {
|
|
605
|
+
if (isSubmenu(item)) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
var id = ge.containerId("nav");
|
|
609
|
+
var toggle = child(item, "a");
|
|
610
|
+
var menu = child(item, ".dropdown-menu");
|
|
611
|
+
item.setAttribute("data-ge-nav", "submenu");
|
|
612
|
+
removeClass(item, "dropdown");
|
|
613
|
+
setToggle(toggle, { href: "#" + id, "data-bs-toggle": "collapse", role: "button", "aria-expanded": "false", "aria-controls": id });
|
|
614
|
+
if (menu) {
|
|
615
|
+
var collapse = element("div", { "class": "collapse", id });
|
|
616
|
+
removeClass(menu, "dropdown-menu dropdown-menu-end show");
|
|
617
|
+
addClass(menu, "nav flex-column ms-3");
|
|
618
|
+
menu.removeAttribute("data-bs-popper");
|
|
619
|
+
children(menu, "li").forEach(function(each) {
|
|
620
|
+
setItemContext(each, "submenu");
|
|
621
|
+
});
|
|
622
|
+
item.insertBefore(collapse, menu);
|
|
623
|
+
collapse.appendChild(menu);
|
|
624
|
+
}
|
|
625
|
+
apartAgain(ge, item);
|
|
626
|
+
}
|
|
627
|
+
function pillsIn(container, except) {
|
|
628
|
+
var lists = children(panelOf(container), "ul.nav").filter(function(each) {
|
|
629
|
+
return each !== except;
|
|
630
|
+
});
|
|
631
|
+
return !lists.length || hasClass(lists[0], "nav-pills");
|
|
632
|
+
}
|
|
633
|
+
function convertList(list2, toType, pills) {
|
|
634
|
+
removeClass(list2, "navbar-nav nav nav-pills flex-column");
|
|
635
|
+
addClass(list2, listClass(toType, pills));
|
|
636
|
+
if (toType === "sidenav") {
|
|
637
|
+
removeClass(list2, "navbar-nav-scroll");
|
|
638
|
+
list2.style.removeProperty("--bs-scroll-height");
|
|
639
|
+
dropEmptyStyle(list2);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
function textOf(node) {
|
|
643
|
+
var label = child(node, ".ge-pane-label");
|
|
644
|
+
if (label) {
|
|
645
|
+
return label.textContent;
|
|
646
|
+
}
|
|
647
|
+
return Array.prototype.filter.call(node.childNodes, function(each) {
|
|
648
|
+
return each.nodeType === 3;
|
|
649
|
+
}).map(function(each) {
|
|
650
|
+
return each.textContent;
|
|
651
|
+
}).join("");
|
|
652
|
+
}
|
|
653
|
+
function convertText(ge, node, toType) {
|
|
654
|
+
var made = text(ge, toType);
|
|
655
|
+
var own = Array.prototype.filter.call(node.classList, function(name) {
|
|
656
|
+
return !/^ge-/.test(name) && ["navbar-text", "px-3", "py-2"].indexOf(name) === -1;
|
|
657
|
+
});
|
|
658
|
+
made.textContent = textOf(node);
|
|
659
|
+
addClass(made, own.join(" "));
|
|
660
|
+
node.parentNode.replaceChild(made, node);
|
|
661
|
+
return made;
|
|
662
|
+
}
|
|
663
|
+
function dropped(ge, node, loaded) {
|
|
664
|
+
var parent = node.parentElement;
|
|
665
|
+
var container = ownerOf(node, loaded);
|
|
666
|
+
if (!parent || !container) {
|
|
667
|
+
return node;
|
|
668
|
+
}
|
|
669
|
+
var type = typeOf(container);
|
|
670
|
+
if (parent === holderOf(container)) {
|
|
671
|
+
if (is(node, "ul.navbar-nav, ul.nav")) {
|
|
672
|
+
convertList(node, type, pillsIn(container, node));
|
|
673
|
+
} else if (is(node, '.navbar-text, [data-ge-nav="text"]') && !is(node, type === "sidenav" ? '[data-ge-nav="text"]' : ".navbar-text")) {
|
|
674
|
+
node = convertText(ge, node, type);
|
|
675
|
+
}
|
|
676
|
+
removeClass(node, type === "sidenav" ? "ms-auto mx-auto" : "mt-auto");
|
|
677
|
+
dropEmptyClass(node);
|
|
678
|
+
return node;
|
|
679
|
+
}
|
|
680
|
+
if (is(parent, "ul") && kindOf(parent, loaded) === "nav-list") {
|
|
681
|
+
if (type === "navbar" && isSubmenu(node)) {
|
|
682
|
+
toDropdown(ge, node);
|
|
683
|
+
}
|
|
684
|
+
return node;
|
|
685
|
+
}
|
|
686
|
+
if (is(parent, ".dropdown-menu")) {
|
|
687
|
+
setItemContext(node, "menu");
|
|
688
|
+
} else if (is(parent, "ul") && is(parent.parentElement, ".collapse")) {
|
|
689
|
+
setItemContext(node, "submenu");
|
|
690
|
+
}
|
|
691
|
+
return node;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// src/js/nav/browse.js
|
|
695
|
+
function browseButton(ge, context, browse, node, property, current, apply) {
|
|
696
|
+
if (typeof browse !== "function") {
|
|
697
|
+
return null;
|
|
698
|
+
}
|
|
699
|
+
var button = element("button", {
|
|
700
|
+
type: "button",
|
|
701
|
+
"class": "btn btn-outline-secondary ge-nav-browse",
|
|
702
|
+
title: ge.t("container.nav_browse"),
|
|
703
|
+
"aria-label": ge.t("container.nav_browse")
|
|
704
|
+
});
|
|
705
|
+
button.appendChild(element("i", { "class": "bi bi-folder2-open", "aria-hidden": "true" }));
|
|
706
|
+
button.addEventListener("click", function() {
|
|
707
|
+
var answered = false;
|
|
708
|
+
var target = typeof node === "function" ? node() : node;
|
|
709
|
+
function answer(url) {
|
|
710
|
+
if (answered) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
answered = true;
|
|
714
|
+
if (url === null || url === void 0) {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
if (typeof url !== "string") {
|
|
718
|
+
ge.warn("navbar and sidenav browse gave " + typeof url + ", not a text: ignored");
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
if (url.trim() === "" || context.destroyed || !ge.canvas.contains(target)) {
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
apply(url.trim());
|
|
725
|
+
}
|
|
726
|
+
var result = browse(answer, { node: target, property, value: current() });
|
|
727
|
+
if (result && typeof result.then === "function") {
|
|
728
|
+
result.then(answer);
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
return button;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// src/js/nav/drawers.js
|
|
735
|
+
var wired = /* @__PURE__ */ new WeakSet();
|
|
736
|
+
var MARKS = /^ge-nav-/;
|
|
737
|
+
function labelOf(node) {
|
|
738
|
+
var existing = child(node, ".ge-pane-label");
|
|
739
|
+
if (existing) {
|
|
740
|
+
return existing;
|
|
741
|
+
}
|
|
742
|
+
var texts = Array.prototype.filter.call(node.childNodes, function(each) {
|
|
743
|
+
return each.nodeType === 3;
|
|
744
|
+
});
|
|
745
|
+
var content = texts.map(function(each) {
|
|
746
|
+
return each.textContent;
|
|
747
|
+
}).join("").trim();
|
|
748
|
+
if (!content) {
|
|
749
|
+
return null;
|
|
750
|
+
}
|
|
751
|
+
texts.forEach(function(each) {
|
|
752
|
+
each.remove();
|
|
753
|
+
});
|
|
754
|
+
return node.appendChild(element("span", { "class": "ge-pane-label" }, content));
|
|
755
|
+
}
|
|
756
|
+
function editInPlace(ge, node, fallback) {
|
|
757
|
+
var label = labelOf(node);
|
|
758
|
+
if (!label) {
|
|
759
|
+
return null;
|
|
760
|
+
}
|
|
761
|
+
ge.makeLabelEditable(label);
|
|
762
|
+
if (!wired.has(label)) {
|
|
763
|
+
wired.add(label);
|
|
764
|
+
label.addEventListener("blur", function() {
|
|
765
|
+
if (label.textContent.trim() === "") {
|
|
766
|
+
label.textContent = fallback();
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
return label;
|
|
771
|
+
}
|
|
772
|
+
function fallbackFor(ge, node, kind, container) {
|
|
773
|
+
return function() {
|
|
774
|
+
return ge.t(defaultLabelKey(node, kind, container));
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
function labelTarget(node, kind) {
|
|
778
|
+
if (kind === "nav-link" || kind === "nav-dropdown") {
|
|
779
|
+
return child(node, "a");
|
|
780
|
+
}
|
|
781
|
+
if (kind === "nav-menu-item") {
|
|
782
|
+
var type = itemType(node);
|
|
783
|
+
return type === "divider" ? null : child(node, ITEM_TAGS[type]);
|
|
784
|
+
}
|
|
785
|
+
return kind === "nav-text" || kind === "nav-brand" ? node : null;
|
|
786
|
+
}
|
|
787
|
+
function brandDrawer(ge, node) {
|
|
788
|
+
var drawer = element("div", { "class": "ge-tools-drawer ge-pane-drawer" });
|
|
789
|
+
node.insertBefore(drawer, node.firstChild);
|
|
790
|
+
ge.addSettingsTool(drawer, node, []);
|
|
791
|
+
}
|
|
792
|
+
function choice(label, choose, title) {
|
|
793
|
+
return { label, title: title || label, choose };
|
|
794
|
+
}
|
|
795
|
+
function pickerTool(ge, drawer, title, choices) {
|
|
796
|
+
var tool = one(drawer, ".ge-nav-add");
|
|
797
|
+
function open() {
|
|
798
|
+
ge.openPicker(tool, choices(), "ge-nav-picker");
|
|
799
|
+
}
|
|
800
|
+
if (!tool) {
|
|
801
|
+
tool = ge.createTool(drawer, title, "ge-nav-add", "bi bi-plus-circle", function(e) {
|
|
802
|
+
if (e) {
|
|
803
|
+
e.preventDefault();
|
|
804
|
+
}
|
|
805
|
+
if (ge.closePicker()) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
open();
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
ge.attachPicker(tool, open);
|
|
812
|
+
return tool;
|
|
813
|
+
}
|
|
814
|
+
function add(ge, node, kind, holder) {
|
|
815
|
+
return ge.place(node, kind, { appendTo: holder, source: "tool" });
|
|
816
|
+
}
|
|
817
|
+
function containerTools(ge, drawer, container) {
|
|
818
|
+
var type = typeOf(container);
|
|
819
|
+
pickerTool(ge, drawer, ge.t("tool.add_nav_piece"), function() {
|
|
820
|
+
var holder = holderOf(container);
|
|
821
|
+
return [
|
|
822
|
+
choice(ge.t("container.nav_list_section"), function() {
|
|
823
|
+
add(ge, list(ge, type, pillsIn(container), 1), "nav-list", holder);
|
|
824
|
+
}, ge.t("tool.add_nav_list")),
|
|
825
|
+
choice(ge.t("container.nav_text"), function() {
|
|
826
|
+
add(ge, text(ge, type), "nav-text", holder);
|
|
827
|
+
}, ge.t("tool.add_nav_text")),
|
|
828
|
+
choice(ge.t("container.nav_zone"), function() {
|
|
829
|
+
add(ge, zone(ge), "nav-zone", holder);
|
|
830
|
+
}, ge.t("tool.add_nav_zone"))
|
|
831
|
+
];
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
function addsOf(ge, node, kind, container) {
|
|
835
|
+
var type = typeOf(container);
|
|
836
|
+
if (kind === "nav-list") {
|
|
837
|
+
return {
|
|
838
|
+
title: ge.t("tool.add_nav_link"),
|
|
839
|
+
choices: function() {
|
|
840
|
+
return [
|
|
841
|
+
choice(ge.t("container.nav_link"), function() {
|
|
842
|
+
add(ge, link(ge), "nav-link", node);
|
|
843
|
+
}),
|
|
844
|
+
choice(ge.t(type === "sidenav" ? "container.nav_submenu" : "container.nav_dropdown"), function() {
|
|
845
|
+
add(ge, type === "sidenav" ? submenu(ge) : dropdown(ge), "nav-dropdown", node);
|
|
846
|
+
})
|
|
847
|
+
];
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
if (kind !== "nav-dropdown") {
|
|
852
|
+
return null;
|
|
853
|
+
}
|
|
854
|
+
var addItem = function(itemType2) {
|
|
855
|
+
add(ge, menuItem(ge, itemType2, isSubmenu(node) ? "submenu" : "menu"), "nav-menu-item", menuOf(node));
|
|
856
|
+
};
|
|
857
|
+
return {
|
|
858
|
+
title: ge.t("tool.add_nav_menu_item"),
|
|
859
|
+
choices: function() {
|
|
860
|
+
return [
|
|
861
|
+
choice(ge.t("container.nav_menu_link"), function() {
|
|
862
|
+
addItem("link");
|
|
863
|
+
}),
|
|
864
|
+
choice(ge.t("container.nav_menu_divider"), function() {
|
|
865
|
+
addItem("divider");
|
|
866
|
+
}),
|
|
867
|
+
choice(ge.t("container.nav_menu_header"), function() {
|
|
868
|
+
addItem("header");
|
|
869
|
+
}),
|
|
870
|
+
choice(ge.t("container.nav_text"), function() {
|
|
871
|
+
addItem("text");
|
|
872
|
+
})
|
|
873
|
+
];
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
function foldTool(ge, drawer, node) {
|
|
878
|
+
var tool = ge.createTool(drawer, ge.t("tool.fold_nav_menu"), "ge-nav-fold", "bi bi-chevron-bar-contract", function(e) {
|
|
879
|
+
if (e) {
|
|
880
|
+
e.preventDefault();
|
|
881
|
+
}
|
|
882
|
+
var folded = toggleClass(node, "ge-nav-folded").classList.contains("ge-nav-folded");
|
|
883
|
+
tool.setAttribute("title", folded ? ge.t("tool.unfold_nav_menu") : ge.t("tool.fold_nav_menu"));
|
|
884
|
+
});
|
|
885
|
+
return tool;
|
|
886
|
+
}
|
|
887
|
+
function markContainer(ge, container, loaded) {
|
|
888
|
+
var type = typeOf(container);
|
|
889
|
+
if (!ge.previewing()) {
|
|
890
|
+
togglesOf(container).forEach(function(node) {
|
|
891
|
+
ge.suspendToggles(node);
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
piecesOf(container, loaded).forEach(function(each) {
|
|
895
|
+
var node = each.node;
|
|
896
|
+
var kind = each.kind;
|
|
897
|
+
addClass(node, "ge-nav-piece ge-" + kind);
|
|
898
|
+
var labeled = labelTarget(node, kind);
|
|
899
|
+
if (labeled) {
|
|
900
|
+
editInPlace(ge, labeled, fallbackFor(ge, node, kind, container));
|
|
901
|
+
}
|
|
902
|
+
if (child(node, ".ge-tools-drawer")) {
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
if (kind === "nav-brand") {
|
|
906
|
+
brandDrawer(ge, node);
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
var drawer = ge.createPaneControls(node, kind, [], ge.t("confirm.delete_nav_piece"), function(removed) {
|
|
910
|
+
fadeOut(node, 200, removed);
|
|
911
|
+
}, { presets: [] });
|
|
912
|
+
var del = one(drawer, ".ge-delete-pane");
|
|
913
|
+
if (del) {
|
|
914
|
+
del.setAttribute("title", ge.t("tool.delete_nav_piece"));
|
|
915
|
+
del.setAttribute("aria-label", ge.t("tool.delete_nav_piece"));
|
|
916
|
+
}
|
|
917
|
+
var adds = addsOf(ge, node, kind, container);
|
|
918
|
+
if (adds) {
|
|
919
|
+
pickerTool(ge, drawer, adds.title, adds.choices);
|
|
920
|
+
}
|
|
921
|
+
if (kind === "nav-dropdown") {
|
|
922
|
+
foldTool(ge, drawer, node);
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
var offcanvas = type === "navbar" ? offcanvasOf(container) : panelOf(container);
|
|
926
|
+
var title = offcanvas ? one(offcanvas, ":scope > .offcanvas-header .offcanvas-title") : null;
|
|
927
|
+
if (title) {
|
|
928
|
+
editInPlace(ge, title, function() {
|
|
929
|
+
return ge.t(type === "navbar" ? "container.navbar_offcanvas_title" : "container.sidenav_offcanvas_title");
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
var trigger = type === "sidenav" ? triggerOf(container) : null;
|
|
933
|
+
if (trigger) {
|
|
934
|
+
editInPlace(ge, trigger, function() {
|
|
935
|
+
return ge.t("container.sidenav_trigger");
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
function unmarkContainer(ge, container) {
|
|
940
|
+
var own = function(node) {
|
|
941
|
+
return isOwn(container, node);
|
|
942
|
+
};
|
|
943
|
+
all(container, '[class*="ge-nav-"]').filter(own).forEach(function(node) {
|
|
944
|
+
Array.prototype.filter.call(node.classList, function(name) {
|
|
945
|
+
return MARKS.test(name);
|
|
946
|
+
}).forEach(function(name) {
|
|
947
|
+
node.classList.remove(name);
|
|
948
|
+
});
|
|
949
|
+
dropEmptyClass(node);
|
|
950
|
+
});
|
|
951
|
+
all(container, ".ge-pane-label").filter(own).forEach(function(label) {
|
|
952
|
+
ge.unwrapLabels(label.parentElement);
|
|
953
|
+
});
|
|
954
|
+
togglesOf(container).forEach(function(node) {
|
|
955
|
+
ge.resumeToggles(node);
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
function afterMove(ge, container, node, loaded) {
|
|
959
|
+
if (ownerOf(node, loaded) !== container) {
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
var moved = dropped(ge, node, loaded);
|
|
963
|
+
if (moved !== node) {
|
|
964
|
+
children(moved, ".ge-tools-drawer").forEach(function(drawer) {
|
|
965
|
+
drawer.remove();
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
markContainer(ge, container, loaded);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// src/js/nav/panels.js
|
|
972
|
+
var counter = 0;
|
|
973
|
+
var SECTION_KEYS = {
|
|
974
|
+
"nav-list": { labelKey: "container.nav_list_section" },
|
|
975
|
+
"nav-link": { labelKey: "container.nav_link_section" },
|
|
976
|
+
"nav-dropdown": { labelKey: "container.nav_dropdown_section" },
|
|
977
|
+
"nav-menu-item": { labelKey: "container.nav_menu_item_section" },
|
|
978
|
+
"nav-text": { labelKey: "container.nav_text_section" },
|
|
979
|
+
"nav-zone": { labelKey: "container.nav_zone_section" },
|
|
980
|
+
"nav-brand": { labelKey: "container.nav_brand_section" }
|
|
981
|
+
};
|
|
982
|
+
function nextId() {
|
|
983
|
+
return "ge-nav-option-" + ++counter;
|
|
984
|
+
}
|
|
985
|
+
function fieldRow(name, label, control, id) {
|
|
986
|
+
var box = element("div", { "class": "ge-nav-option mb-2", "data-ge-nav-option": name });
|
|
987
|
+
if (label) {
|
|
988
|
+
box.appendChild(element("label", { "class": "form-label", "for": id }, label));
|
|
989
|
+
}
|
|
990
|
+
box.appendChild(control);
|
|
991
|
+
return box;
|
|
992
|
+
}
|
|
993
|
+
function selectControl(choices, onChange) {
|
|
994
|
+
var id = nextId();
|
|
995
|
+
var control = element("select", { "class": "form-select form-select-sm", id });
|
|
996
|
+
choices.forEach(function(each) {
|
|
997
|
+
control.appendChild(element("option", { value: each.value }, each.label));
|
|
998
|
+
});
|
|
999
|
+
control.addEventListener("change", function() {
|
|
1000
|
+
onChange(control.value);
|
|
1001
|
+
});
|
|
1002
|
+
return { id, control };
|
|
1003
|
+
}
|
|
1004
|
+
function checkControl(label, onChange) {
|
|
1005
|
+
var id = nextId();
|
|
1006
|
+
var box = element("div", { "class": "form-check ge-nav-option mb-2" });
|
|
1007
|
+
var input = box.appendChild(element("input", { "class": "form-check-input", type: "checkbox", id }));
|
|
1008
|
+
box.appendChild(element("label", { "class": "form-check-label", "for": id }, label));
|
|
1009
|
+
input.addEventListener("change", function() {
|
|
1010
|
+
onChange(input.checked);
|
|
1011
|
+
});
|
|
1012
|
+
return { box, input };
|
|
1013
|
+
}
|
|
1014
|
+
function textControl(onChange) {
|
|
1015
|
+
var id = nextId();
|
|
1016
|
+
var control = element("input", { "class": "form-control form-control-sm", type: "text", id });
|
|
1017
|
+
["input", "change"].forEach(function(name) {
|
|
1018
|
+
control.addEventListener(name, function() {
|
|
1019
|
+
onChange(control.value);
|
|
1020
|
+
});
|
|
1021
|
+
});
|
|
1022
|
+
return { id, control };
|
|
1023
|
+
}
|
|
1024
|
+
function markInvalid(control, invalid) {
|
|
1025
|
+
toggleClass(control, "is-invalid", invalid);
|
|
1026
|
+
}
|
|
1027
|
+
function sectionsOf() {
|
|
1028
|
+
var kept = [];
|
|
1029
|
+
return {
|
|
1030
|
+
add: function(entry) {
|
|
1031
|
+
kept = kept.filter(function(each) {
|
|
1032
|
+
return each.element.isConnected;
|
|
1033
|
+
});
|
|
1034
|
+
kept.push(entry);
|
|
1035
|
+
},
|
|
1036
|
+
render: function(scope) {
|
|
1037
|
+
kept = kept.filter(function(each) {
|
|
1038
|
+
return each.element.isConnected;
|
|
1039
|
+
});
|
|
1040
|
+
kept.forEach(function(each) {
|
|
1041
|
+
if (!scope || each.node === scope || scope.contains(each.node)) {
|
|
1042
|
+
each.render();
|
|
1043
|
+
}
|
|
1044
|
+
});
|
|
1045
|
+
},
|
|
1046
|
+
clear: function() {
|
|
1047
|
+
kept = [];
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
function setActive(container, anchor, on) {
|
|
1052
|
+
var clear = function(each) {
|
|
1053
|
+
removeClass(each, "active");
|
|
1054
|
+
each.removeAttribute("aria-current");
|
|
1055
|
+
dropEmptyClass(each);
|
|
1056
|
+
};
|
|
1057
|
+
if (!on) {
|
|
1058
|
+
clear(anchor);
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
all(container, "a.nav-link, a.dropdown-item").filter(function(each) {
|
|
1062
|
+
return isOwn(container, each);
|
|
1063
|
+
}).forEach(clear);
|
|
1064
|
+
addClass(anchor, "active");
|
|
1065
|
+
anchor.setAttribute("aria-current", "page");
|
|
1066
|
+
}
|
|
1067
|
+
function alignOf(node) {
|
|
1068
|
+
return hasClass(node, "ms-auto") ? "end" : hasClass(node, "mx-auto") ? "center" : "after";
|
|
1069
|
+
}
|
|
1070
|
+
function createPanels(ge, loaded) {
|
|
1071
|
+
var kept = sectionsOf();
|
|
1072
|
+
var context = { destroyed: false };
|
|
1073
|
+
function settingsOf(container) {
|
|
1074
|
+
return ge.settings[typeOf(container)] || {};
|
|
1075
|
+
}
|
|
1076
|
+
function urlField(container, node, property, name, label, read, write, browseNode) {
|
|
1077
|
+
var field = textControl(write);
|
|
1078
|
+
var holder = element("div", { "class": "input-group input-group-sm" });
|
|
1079
|
+
holder.appendChild(field.control);
|
|
1080
|
+
var button = browseButton(ge, context, settingsOf(container).browse, browseNode || node, property, read, function(url) {
|
|
1081
|
+
write(url);
|
|
1082
|
+
kept.render();
|
|
1083
|
+
});
|
|
1084
|
+
if (button) {
|
|
1085
|
+
holder.appendChild(button);
|
|
1086
|
+
}
|
|
1087
|
+
return {
|
|
1088
|
+
row: fieldRow(name, label, holder, field.id),
|
|
1089
|
+
render: function() {
|
|
1090
|
+
field.control.value = read();
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1094
|
+
function linkFields(container, node, anchor, fields) {
|
|
1095
|
+
fields.push(urlField(
|
|
1096
|
+
container,
|
|
1097
|
+
node,
|
|
1098
|
+
"href",
|
|
1099
|
+
"href",
|
|
1100
|
+
ge.t("container.nav_href"),
|
|
1101
|
+
function() {
|
|
1102
|
+
return anchor.getAttribute("href") || "";
|
|
1103
|
+
},
|
|
1104
|
+
function(value) {
|
|
1105
|
+
anchor.setAttribute("href", value);
|
|
1106
|
+
},
|
|
1107
|
+
anchor
|
|
1108
|
+
));
|
|
1109
|
+
var active = checkControl(ge.t("container.nav_active"), function(on) {
|
|
1110
|
+
setActive(container, anchor, on);
|
|
1111
|
+
kept.render();
|
|
1112
|
+
});
|
|
1113
|
+
var disabled = checkControl(ge.t("container.nav_disabled"), function(on) {
|
|
1114
|
+
toggleClass(anchor, "disabled", on);
|
|
1115
|
+
if (on) {
|
|
1116
|
+
anchor.setAttribute("aria-disabled", "true");
|
|
1117
|
+
} else {
|
|
1118
|
+
anchor.removeAttribute("aria-disabled");
|
|
1119
|
+
dropEmptyClass(anchor);
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
var tab = checkControl(ge.t("container.nav_new_tab"), function(on) {
|
|
1123
|
+
if (on) {
|
|
1124
|
+
anchor.setAttribute("target", "_blank");
|
|
1125
|
+
anchor.setAttribute("rel", "noopener");
|
|
1126
|
+
} else {
|
|
1127
|
+
anchor.removeAttribute("target");
|
|
1128
|
+
anchor.removeAttribute("rel");
|
|
1129
|
+
}
|
|
1130
|
+
});
|
|
1131
|
+
active.box.setAttribute("data-ge-nav-option", "active");
|
|
1132
|
+
disabled.box.setAttribute("data-ge-nav-option", "disabled");
|
|
1133
|
+
tab.box.setAttribute("data-ge-nav-option", "new_tab");
|
|
1134
|
+
fields.push({ row: active.box, render: function() {
|
|
1135
|
+
active.input.checked = hasClass(anchor, "active");
|
|
1136
|
+
} });
|
|
1137
|
+
fields.push({ row: disabled.box, render: function() {
|
|
1138
|
+
disabled.input.checked = hasClass(anchor, "disabled");
|
|
1139
|
+
} });
|
|
1140
|
+
fields.push({ row: tab.box, render: function() {
|
|
1141
|
+
tab.input.checked = anchor.getAttribute("target") === "_blank";
|
|
1142
|
+
} });
|
|
1143
|
+
}
|
|
1144
|
+
function dropdownFields(container, node, fields) {
|
|
1145
|
+
var type = typeOf(container);
|
|
1146
|
+
if (type === "sidenav") {
|
|
1147
|
+
var kind = selectControl([
|
|
1148
|
+
{ value: "collapse", label: ge.t("container.nav_submenu_type_collapse") },
|
|
1149
|
+
{ value: "dropdown", label: ge.t("container.nav_submenu_type_dropdown") }
|
|
1150
|
+
], function(value) {
|
|
1151
|
+
if (value === "collapse") {
|
|
1152
|
+
toSubmenu(ge, node);
|
|
1153
|
+
} else {
|
|
1154
|
+
toDropdown(ge, node);
|
|
1155
|
+
}
|
|
1156
|
+
kept.render();
|
|
1157
|
+
});
|
|
1158
|
+
fields.push({
|
|
1159
|
+
row: fieldRow("submenu_type", ge.t("container.nav_submenu_type"), kind.control, kind.id),
|
|
1160
|
+
render: function() {
|
|
1161
|
+
kind.control.value = isSubmenu(node) ? "collapse" : "dropdown";
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
var end = checkControl(ge.t("container.nav_menu_end"), function(on) {
|
|
1166
|
+
var menu = menuOf(node);
|
|
1167
|
+
if (!menu) {
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
toggleClass(menu, "dropdown-menu-end", on);
|
|
1171
|
+
dropEmptyClass(menu);
|
|
1172
|
+
});
|
|
1173
|
+
end.box.setAttribute("data-ge-nav-option", "menu_end");
|
|
1174
|
+
fields.push({
|
|
1175
|
+
row: end.box,
|
|
1176
|
+
render: function() {
|
|
1177
|
+
var menu = menuOf(node);
|
|
1178
|
+
end.input.checked = hasClass(menu, "dropdown-menu-end");
|
|
1179
|
+
end.input.disabled = isSubmenu(node);
|
|
1180
|
+
}
|
|
1181
|
+
});
|
|
1182
|
+
if (type !== "sidenav") {
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
var open = checkControl(ge.t("container.nav_submenu_open"), function(on) {
|
|
1186
|
+
var collapse = child(node, ".collapse");
|
|
1187
|
+
var toggle = child(node, "a");
|
|
1188
|
+
if (!collapse) {
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
1191
|
+
toggleClass(collapse, "show", on);
|
|
1192
|
+
toggle.setAttribute("aria-expanded", on ? "true" : "false");
|
|
1193
|
+
});
|
|
1194
|
+
open.box.setAttribute("data-ge-nav-option", "submenu_open");
|
|
1195
|
+
fields.push({
|
|
1196
|
+
row: open.box,
|
|
1197
|
+
render: function() {
|
|
1198
|
+
var collapse = child(node, ".collapse");
|
|
1199
|
+
open.input.checked = hasClass(collapse, "show");
|
|
1200
|
+
open.input.disabled = !isSubmenu(node);
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
function alignmentField(node, fields) {
|
|
1205
|
+
var align = selectControl([
|
|
1206
|
+
{ value: "after", label: ge.t("container.nav_align_after") },
|
|
1207
|
+
{ value: "end", label: ge.t("container.nav_align_end") },
|
|
1208
|
+
{ value: "center", label: ge.t("container.nav_align_center") }
|
|
1209
|
+
], function(value) {
|
|
1210
|
+
removeClass(node, "ms-auto mx-auto");
|
|
1211
|
+
if (value === "end") {
|
|
1212
|
+
addClass(node, "ms-auto");
|
|
1213
|
+
}
|
|
1214
|
+
if (value === "center") {
|
|
1215
|
+
addClass(node, "mx-auto");
|
|
1216
|
+
}
|
|
1217
|
+
dropEmptyClass(node);
|
|
1218
|
+
});
|
|
1219
|
+
fields.push({
|
|
1220
|
+
row: fieldRow("align", ge.t("container.nav_align"), align.control, align.id),
|
|
1221
|
+
render: function() {
|
|
1222
|
+
align.control.value = alignOf(node);
|
|
1223
|
+
}
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
function scrollFields(node, fields) {
|
|
1227
|
+
var height = textControl(function(value) {
|
|
1228
|
+
if (!hasClass(node, "navbar-nav-scroll")) {
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
var valid = value.trim() !== "" && window.CSS && CSS.supports("height", value.trim());
|
|
1232
|
+
markInvalid(height.control, !valid);
|
|
1233
|
+
if (valid) {
|
|
1234
|
+
ge.setHostStyle(node, "--bs-scroll-height", value.trim());
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
var scroll = checkControl(ge.t("container.nav_scroll"), function(on) {
|
|
1238
|
+
if (on) {
|
|
1239
|
+
var typed = height.control.value.trim();
|
|
1240
|
+
var wanted = typed && CSS.supports("height", typed) ? typed : "75vh";
|
|
1241
|
+
addClass(node, "navbar-nav-scroll");
|
|
1242
|
+
ge.setHostStyle(node, "--bs-scroll-height", wanted);
|
|
1243
|
+
} else {
|
|
1244
|
+
removeClass(node, "navbar-nav-scroll");
|
|
1245
|
+
dropEmptyClass(node);
|
|
1246
|
+
ge.setHostStyle(node, "--bs-scroll-height", "");
|
|
1247
|
+
}
|
|
1248
|
+
markInvalid(height.control, false);
|
|
1249
|
+
});
|
|
1250
|
+
scroll.box.setAttribute("data-ge-nav-option", "scroll");
|
|
1251
|
+
fields.push({ row: scroll.box, render: function() {
|
|
1252
|
+
scroll.input.checked = hasClass(node, "navbar-nav-scroll");
|
|
1253
|
+
} });
|
|
1254
|
+
fields.push({
|
|
1255
|
+
row: fieldRow("scroll_height", ge.t("container.nav_scroll_height"), height.control, height.id),
|
|
1256
|
+
render: function() {
|
|
1257
|
+
var shown = ge.hostStyle(node, "--bs-scroll-height").value;
|
|
1258
|
+
height.control.value = shown || "75vh";
|
|
1259
|
+
height.control.disabled = !hasClass(node, "navbar-nav-scroll");
|
|
1260
|
+
markInvalid(height.control, false);
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
function bottomField(node, fields) {
|
|
1265
|
+
var bottom = checkControl(ge.t("container.nav_bottom"), function(on) {
|
|
1266
|
+
toggleClass(node, "mt-auto", on);
|
|
1267
|
+
dropEmptyClass(node);
|
|
1268
|
+
});
|
|
1269
|
+
bottom.box.setAttribute("data-ge-nav-option", "bottom");
|
|
1270
|
+
fields.push({ row: bottom.box, render: function() {
|
|
1271
|
+
bottom.input.checked = hasClass(node, "mt-auto");
|
|
1272
|
+
} });
|
|
1273
|
+
}
|
|
1274
|
+
function brandFields(container, node, fields) {
|
|
1275
|
+
var imageOf = function() {
|
|
1276
|
+
return child(node, "img");
|
|
1277
|
+
};
|
|
1278
|
+
fields.push(urlField(
|
|
1279
|
+
container,
|
|
1280
|
+
node,
|
|
1281
|
+
"href",
|
|
1282
|
+
"href",
|
|
1283
|
+
ge.t("container.nav_href"),
|
|
1284
|
+
function() {
|
|
1285
|
+
return node.getAttribute("href") || "";
|
|
1286
|
+
},
|
|
1287
|
+
function(value) {
|
|
1288
|
+
node.setAttribute("href", value);
|
|
1289
|
+
}
|
|
1290
|
+
));
|
|
1291
|
+
fields.push(urlField(
|
|
1292
|
+
container,
|
|
1293
|
+
node,
|
|
1294
|
+
"src",
|
|
1295
|
+
"image",
|
|
1296
|
+
ge.t("container.nav_brand_image"),
|
|
1297
|
+
function() {
|
|
1298
|
+
var img = imageOf();
|
|
1299
|
+
return img ? img.getAttribute("src") || "" : "";
|
|
1300
|
+
},
|
|
1301
|
+
function(value) {
|
|
1302
|
+
setImage(value);
|
|
1303
|
+
},
|
|
1304
|
+
function() {
|
|
1305
|
+
return imageOf() || node;
|
|
1306
|
+
}
|
|
1307
|
+
));
|
|
1308
|
+
var alt = textControl(function(value) {
|
|
1309
|
+
var img = imageOf();
|
|
1310
|
+
if (img) {
|
|
1311
|
+
img.setAttribute("alt", value);
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
fields.push({
|
|
1315
|
+
row: fieldRow("alt", ge.t("container.nav_brand_alt"), alt.control, alt.id),
|
|
1316
|
+
render: function() {
|
|
1317
|
+
var img = imageOf();
|
|
1318
|
+
alt.control.value = img ? img.getAttribute("alt") || "" : "";
|
|
1319
|
+
alt.control.disabled = !img;
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
var height = textControl(function(value) {
|
|
1323
|
+
var img = imageOf();
|
|
1324
|
+
var valid = /^\d+$/.test(value.trim()) && parseInt(value, 10) >= 1;
|
|
1325
|
+
markInvalid(height.control, !valid);
|
|
1326
|
+
if (valid && img) {
|
|
1327
|
+
img.setAttribute("height", String(parseInt(value, 10)));
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
fields.push({
|
|
1331
|
+
row: fieldRow("image_height", ge.t("container.nav_brand_height"), height.control, height.id),
|
|
1332
|
+
render: function() {
|
|
1333
|
+
var img = imageOf();
|
|
1334
|
+
height.control.value = img ? img.getAttribute("height") || "30" : "30";
|
|
1335
|
+
height.control.disabled = !img;
|
|
1336
|
+
markInvalid(height.control, false);
|
|
1337
|
+
}
|
|
1338
|
+
});
|
|
1339
|
+
function setImage(url) {
|
|
1340
|
+
var img = imageOf();
|
|
1341
|
+
if (url === "") {
|
|
1342
|
+
if (img) {
|
|
1343
|
+
img.remove();
|
|
1344
|
+
}
|
|
1345
|
+
if (!node.textContent.trim().replace(/\s+/g, "")) {
|
|
1346
|
+
node.appendChild(document.createTextNode(ge.t(defaultLabelKey(node, "nav-brand", container))));
|
|
1347
|
+
editInPlace(ge, node, function() {
|
|
1348
|
+
return ge.t(defaultLabelKey(node, "nav-brand", container));
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
if (img) {
|
|
1354
|
+
img.setAttribute("src", url);
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
var first = children(node).filter(function(each) {
|
|
1358
|
+
return !hasClass(each, "ge-tools-drawer");
|
|
1359
|
+
})[0] || null;
|
|
1360
|
+
node.insertBefore(element("img", { src: url, alt: "", height: "30" }), first || node.firstChild);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
function fieldsOf(container, node, kind) {
|
|
1364
|
+
var type = typeOf(container);
|
|
1365
|
+
var fields = [];
|
|
1366
|
+
if (kind === "nav-link") {
|
|
1367
|
+
linkFields(container, node, anchorOf(node), fields);
|
|
1368
|
+
}
|
|
1369
|
+
if (kind === "nav-dropdown") {
|
|
1370
|
+
dropdownFields(container, node, fields);
|
|
1371
|
+
}
|
|
1372
|
+
if (kind === "nav-menu-item" && itemType(node) === "link") {
|
|
1373
|
+
linkFields(container, node, anchorOf(node), fields);
|
|
1374
|
+
}
|
|
1375
|
+
if (kind === "nav-list") {
|
|
1376
|
+
if (type === "navbar") {
|
|
1377
|
+
alignmentField(node, fields);
|
|
1378
|
+
scrollFields(node, fields);
|
|
1379
|
+
} else {
|
|
1380
|
+
bottomField(node, fields);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
if (kind === "nav-text" || kind === "nav-zone") {
|
|
1384
|
+
if (type === "navbar") {
|
|
1385
|
+
alignmentField(node, fields);
|
|
1386
|
+
} else {
|
|
1387
|
+
bottomField(node, fields);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
if (kind === "nav-brand") {
|
|
1391
|
+
brandFields(container, node, fields);
|
|
1392
|
+
}
|
|
1393
|
+
return fields;
|
|
1394
|
+
}
|
|
1395
|
+
return {
|
|
1396
|
+
context,
|
|
1397
|
+
/** The section of a piece's settings panel, or null for a piece with nothing to set. */
|
|
1398
|
+
pieceSection: function(node, kind) {
|
|
1399
|
+
if (KINDS.indexOf(kind) === -1) {
|
|
1400
|
+
return null;
|
|
1401
|
+
}
|
|
1402
|
+
var container = ownerOf(node, loaded);
|
|
1403
|
+
if (!container) {
|
|
1404
|
+
return null;
|
|
1405
|
+
}
|
|
1406
|
+
var fields = fieldsOf(container, node, kind);
|
|
1407
|
+
if (!fields.length) {
|
|
1408
|
+
return null;
|
|
1409
|
+
}
|
|
1410
|
+
var body = element("div", { "class": "ge-nav-options" });
|
|
1411
|
+
fields.forEach(function(each) {
|
|
1412
|
+
body.appendChild(each.row);
|
|
1413
|
+
});
|
|
1414
|
+
var render = function() {
|
|
1415
|
+
fields.forEach(function(each) {
|
|
1416
|
+
each.render();
|
|
1417
|
+
});
|
|
1418
|
+
};
|
|
1419
|
+
render();
|
|
1420
|
+
kept.add({ node, element: body, render });
|
|
1421
|
+
return { labelKey: SECTION_KEYS[kind].labelKey, body };
|
|
1422
|
+
},
|
|
1423
|
+
/** Every section open, filled again from the markup. */
|
|
1424
|
+
refresh: function() {
|
|
1425
|
+
kept.render();
|
|
1426
|
+
},
|
|
1427
|
+
onRefresh: function(scope) {
|
|
1428
|
+
kept.render(scope);
|
|
1429
|
+
},
|
|
1430
|
+
onDeinit: function() {
|
|
1431
|
+
kept.clear();
|
|
1432
|
+
},
|
|
1433
|
+
onDestroy: function() {
|
|
1434
|
+
context.destroyed = true;
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
// src/js/nav/canvas.js
|
|
1440
|
+
function loadedFor(ge) {
|
|
1441
|
+
return function(type) {
|
|
1442
|
+
return TYPES.indexOf(type) !== -1 && !!GridEditor.containers[type] && (!ge.settings.plugins || ge.settings.plugins.indexOf(type) !== -1);
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
function guardLinks(ge, loaded) {
|
|
1446
|
+
var listening = null;
|
|
1447
|
+
return {
|
|
1448
|
+
start: function() {
|
|
1449
|
+
if (listening) {
|
|
1450
|
+
listening.abort();
|
|
1451
|
+
}
|
|
1452
|
+
listening = new AbortController();
|
|
1453
|
+
delegate(ge.canvas, "click", "a", function(e) {
|
|
1454
|
+
var holder = this.closest('[data-ge-container], [data-ge-nav="zone"]');
|
|
1455
|
+
if (holder && !isZone(holder) && loaded(typeOf(holder))) {
|
|
1456
|
+
e.preventDefault();
|
|
1457
|
+
}
|
|
1458
|
+
}, { signal: listening.signal });
|
|
1459
|
+
},
|
|
1460
|
+
stop: function() {
|
|
1461
|
+
if (listening) {
|
|
1462
|
+
listening.abort();
|
|
1463
|
+
}
|
|
1464
|
+
listening = null;
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
var STATE_ATTRIBUTES = ["class", "style", "aria-expanded", "aria-hidden", "aria-modal", "role", "data-bs-popper"];
|
|
1469
|
+
function stateOf(node) {
|
|
1470
|
+
var state = {};
|
|
1471
|
+
STATE_ATTRIBUTES.forEach(function(name) {
|
|
1472
|
+
state[name] = node.getAttribute(name);
|
|
1473
|
+
});
|
|
1474
|
+
return state;
|
|
1475
|
+
}
|
|
1476
|
+
function putState(node, state) {
|
|
1477
|
+
STATE_ATTRIBUTES.forEach(function(name) {
|
|
1478
|
+
node.getAttribute(name);
|
|
1479
|
+
if (state[name] === null) {
|
|
1480
|
+
node.removeAttribute(name);
|
|
1481
|
+
} else {
|
|
1482
|
+
node.setAttribute(name, state[name]);
|
|
1483
|
+
}
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
function isOffcanvas(node) {
|
|
1487
|
+
return Array.prototype.some.call(node.classList, function(name) {
|
|
1488
|
+
return name === "offcanvas" || /^offcanvas-(sm|md|lg|xl|xxl)$/.test(name);
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
function closer(node) {
|
|
1492
|
+
var bootstrap = window.bootstrap;
|
|
1493
|
+
if (!bootstrap) {
|
|
1494
|
+
return null;
|
|
1495
|
+
}
|
|
1496
|
+
var name = hasClass(node, "dropdown-menu") ? "Dropdown" : isOffcanvas(node) ? "Offcanvas" : "Collapse";
|
|
1497
|
+
var target = name === "Dropdown" ? node.previousElementSibling : node;
|
|
1498
|
+
var instance = target && bootstrap[name] && bootstrap[name].getInstance ? bootstrap[name].getInstance(target) : null;
|
|
1499
|
+
return instance ? { instance, target, event: "hidden.bs." + name.toLowerCase() } : null;
|
|
1500
|
+
}
|
|
1501
|
+
function previewFor(ge, type) {
|
|
1502
|
+
var found = /* @__PURE__ */ new Map();
|
|
1503
|
+
function containers() {
|
|
1504
|
+
return all(ge.canvas, '[data-ge-container="' + type + '"]');
|
|
1505
|
+
}
|
|
1506
|
+
return function(previewing) {
|
|
1507
|
+
if (previewing) {
|
|
1508
|
+
containers().forEach(function(container) {
|
|
1509
|
+
all(container, '.navbar-collapse, .collapse, .offcanvas, [class*="offcanvas-"], .dropdown-menu, [aria-expanded]').filter(function(node) {
|
|
1510
|
+
return isOwn(container, node);
|
|
1511
|
+
}).forEach(function(node) {
|
|
1512
|
+
if (!found.has(node)) {
|
|
1513
|
+
found.set(node, stateOf(node));
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
togglesOf(container).forEach(function(node) {
|
|
1517
|
+
ge.resumeToggles(node);
|
|
1518
|
+
});
|
|
1519
|
+
});
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
var left = Array.from(found.entries());
|
|
1523
|
+
var waiting = 0;
|
|
1524
|
+
var restored = false;
|
|
1525
|
+
var restoreAll = function() {
|
|
1526
|
+
if (restored) {
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
restored = true;
|
|
1530
|
+
left.forEach(function(entry) {
|
|
1531
|
+
putState(entry[0], entry[1]);
|
|
1532
|
+
});
|
|
1533
|
+
};
|
|
1534
|
+
left.forEach(function(entry) {
|
|
1535
|
+
var close = hasClass(entry[0], "show") ? closer(entry[0]) : null;
|
|
1536
|
+
if (!close) {
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
waiting++;
|
|
1540
|
+
close.target.addEventListener(close.event, function() {
|
|
1541
|
+
waiting--;
|
|
1542
|
+
if (!waiting) {
|
|
1543
|
+
restoreAll();
|
|
1544
|
+
}
|
|
1545
|
+
}, { once: true });
|
|
1546
|
+
close.instance.hide();
|
|
1547
|
+
});
|
|
1548
|
+
found = /* @__PURE__ */ new Map();
|
|
1549
|
+
if (waiting) {
|
|
1550
|
+
window.setTimeout(restoreAll, 1500);
|
|
1551
|
+
} else {
|
|
1552
|
+
restoreAll();
|
|
1553
|
+
}
|
|
1554
|
+
containers().forEach(function(container) {
|
|
1555
|
+
togglesOf(container).forEach(function(node) {
|
|
1556
|
+
ge.suspendToggles(node);
|
|
1557
|
+
});
|
|
1558
|
+
});
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
function containerBase(ge, type) {
|
|
1562
|
+
var loaded = loadedFor(ge);
|
|
1563
|
+
return {
|
|
1564
|
+
loaded,
|
|
1565
|
+
mark: function(container) {
|
|
1566
|
+
markContainer(ge, container, loaded);
|
|
1567
|
+
},
|
|
1568
|
+
unmark: function(container) {
|
|
1569
|
+
unmarkContainer(ge, container);
|
|
1570
|
+
},
|
|
1571
|
+
// The same on a copy of the canvas: unmark only touches markup
|
|
1572
|
+
cleanMarkup: function(root) {
|
|
1573
|
+
var definition = this;
|
|
1574
|
+
all(root, '[data-ge-container="' + type + '"]').forEach(function(container) {
|
|
1575
|
+
definition.unmark(container);
|
|
1576
|
+
});
|
|
1577
|
+
},
|
|
1578
|
+
tools: function(drawer, container) {
|
|
1579
|
+
containerTools(ge, drawer, container);
|
|
1580
|
+
},
|
|
1581
|
+
afterPaneMove: function(container, node) {
|
|
1582
|
+
afterMove(ge, container, node, loaded);
|
|
1583
|
+
},
|
|
1584
|
+
onPreviewChange: previewFor(ge, type)
|
|
1585
|
+
};
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
// src/js/nav/feature.js
|
|
1589
|
+
function holdsNav(node) {
|
|
1590
|
+
var selector = TYPES.map(function(type) {
|
|
1591
|
+
return '[data-ge-container="' + type + '"]';
|
|
1592
|
+
}).join(", ");
|
|
1593
|
+
return is(node, selector) || !!one(node, selector);
|
|
1594
|
+
}
|
|
1595
|
+
function registerNav() {
|
|
1596
|
+
if (GridEditor.features.nav) {
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
var factory = function(ge) {
|
|
1600
|
+
var loaded = loadedFor(ge);
|
|
1601
|
+
var panels = createPanels(ge, loaded);
|
|
1602
|
+
var guard = guardLinks(ge, loaded);
|
|
1603
|
+
return {
|
|
1604
|
+
kindOf: function(node) {
|
|
1605
|
+
return kindOf(node, loaded);
|
|
1606
|
+
},
|
|
1607
|
+
// A free zone is a list rows go in, as a section is
|
|
1608
|
+
regions: '[data-ge-nav="zone"]',
|
|
1609
|
+
/**
|
|
1610
|
+
* A zone takes rows and nothing else, and no navbar or sidenav
|
|
1611
|
+
* at any depth: not in it, not in a column of it, and not in a
|
|
1612
|
+
* row that holds one.
|
|
1613
|
+
*/
|
|
1614
|
+
accepts: function(region, node) {
|
|
1615
|
+
if (isZone(region) && !is(node, ".row")) {
|
|
1616
|
+
return false;
|
|
1617
|
+
}
|
|
1618
|
+
if (region.closest && region.closest('[data-ge-nav="zone"]') && holdsNav(node)) {
|
|
1619
|
+
return false;
|
|
1620
|
+
}
|
|
1621
|
+
return true;
|
|
1622
|
+
},
|
|
1623
|
+
panelSection: function(node, kind) {
|
|
1624
|
+
return panels.pieceSection(node, kind);
|
|
1625
|
+
},
|
|
1626
|
+
kindLabel: function(kind) {
|
|
1627
|
+
return SECTION_KEYS[kind] ? ge.t(SECTION_KEYS[kind].labelKey) : null;
|
|
1628
|
+
},
|
|
1629
|
+
// What moves: the lists, texts and zones of an area, the links and
|
|
1630
|
+
// dropdowns of a list, and the items of a menu, each among its own
|
|
1631
|
+
onSortable: function(sortable) {
|
|
1632
|
+
var holders = [];
|
|
1633
|
+
var lists = [];
|
|
1634
|
+
var menus = [];
|
|
1635
|
+
all(ge.canvas, "[data-ge-container]").forEach(function(container) {
|
|
1636
|
+
if (!loaded(typeOf(container))) {
|
|
1637
|
+
return;
|
|
1638
|
+
}
|
|
1639
|
+
var holder = holderOf(container);
|
|
1640
|
+
if (holder) {
|
|
1641
|
+
holders.push(holder);
|
|
1642
|
+
}
|
|
1643
|
+
piecesOf(container, loaded).forEach(function(each) {
|
|
1644
|
+
if (each.kind === "nav-list") {
|
|
1645
|
+
lists.push(each.node);
|
|
1646
|
+
}
|
|
1647
|
+
if (each.kind === "nav-dropdown") {
|
|
1648
|
+
menus.push(menuOf(each.node));
|
|
1649
|
+
}
|
|
1650
|
+
});
|
|
1651
|
+
});
|
|
1652
|
+
sortable(holders, { draggable: ".ge-nav-list, .ge-nav-text, .ge-nav-zone", group: "nav-block" });
|
|
1653
|
+
sortable(lists, { draggable: ".ge-nav-link, .ge-nav-dropdown", group: "nav-item" });
|
|
1654
|
+
sortable(menus.filter(Boolean), { draggable: ".ge-nav-menu-item", group: "nav-menu-item" });
|
|
1655
|
+
},
|
|
1656
|
+
onInit: function() {
|
|
1657
|
+
guard.start();
|
|
1658
|
+
},
|
|
1659
|
+
onDeinit: function() {
|
|
1660
|
+
guard.stop();
|
|
1661
|
+
panels.onDeinit();
|
|
1662
|
+
},
|
|
1663
|
+
// Nothing of the feature's is in the markup
|
|
1664
|
+
cleanMarkup: function() {
|
|
1665
|
+
},
|
|
1666
|
+
onRefresh: function(scope) {
|
|
1667
|
+
panels.onRefresh(scope);
|
|
1668
|
+
},
|
|
1669
|
+
onDestroy: function() {
|
|
1670
|
+
panels.onDestroy();
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
};
|
|
1674
|
+
factory.always = true;
|
|
1675
|
+
GridEditor.features.nav = factory;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
// src/js/plugins/grideditor.navbar.js
|
|
1679
|
+
Object.assign(GridEditor.locales.en, EN, { "container.add_navbar": "Navbar" });
|
|
1680
|
+
registerNav();
|
|
1681
|
+
var LAYOUT_ATTR = "data-ge-navbar-layout";
|
|
1682
|
+
var BACKGROUNDS = BACKGROUND_CHOICES.map(function(each) {
|
|
1683
|
+
return each.value;
|
|
1684
|
+
});
|
|
1685
|
+
var POSITIONS = POSITION_CHOICES.map(function(each) {
|
|
1686
|
+
return each.value;
|
|
1687
|
+
});
|
|
1688
|
+
var DEFAULTS = {
|
|
1689
|
+
expand: "lg",
|
|
1690
|
+
collapse: "collapse",
|
|
1691
|
+
offcanvas_placement: "end",
|
|
1692
|
+
bg: "body-tertiary",
|
|
1693
|
+
theme: null,
|
|
1694
|
+
position: null,
|
|
1695
|
+
width: "fluid"
|
|
1696
|
+
};
|
|
1697
|
+
GridEditor.containers.navbar = function(ge) {
|
|
1698
|
+
var base = containerBase(ge, "navbar");
|
|
1699
|
+
var baseMark = base.mark;
|
|
1700
|
+
var baseUnmark = base.unmark;
|
|
1701
|
+
var BREAKPOINTS = ge.breakpoints.filter(function(key) {
|
|
1702
|
+
return key !== "xs";
|
|
1703
|
+
});
|
|
1704
|
+
var sections = sectionsOf();
|
|
1705
|
+
var VALUES = {
|
|
1706
|
+
expand: [false, true].concat(BREAKPOINTS),
|
|
1707
|
+
collapse: ["collapse", "offcanvas", false],
|
|
1708
|
+
offcanvas_placement: ["start", "end"],
|
|
1709
|
+
bg: [null].concat(BACKGROUNDS),
|
|
1710
|
+
theme: [null, "light", "dark"],
|
|
1711
|
+
position: [null].concat(POSITIONS),
|
|
1712
|
+
width: ["fluid", "fixed"].concat(BREAKPOINTS)
|
|
1713
|
+
};
|
|
1714
|
+
function chosen(options, key) {
|
|
1715
|
+
var setting = ge.settings.navbar || {};
|
|
1716
|
+
var value = options[key] !== void 0 ? options[key] : setting[key];
|
|
1717
|
+
if (value === void 0) {
|
|
1718
|
+
return DEFAULTS[key];
|
|
1719
|
+
}
|
|
1720
|
+
if (VALUES[key].indexOf(value) !== -1) {
|
|
1721
|
+
return value;
|
|
1722
|
+
}
|
|
1723
|
+
ge.warn("navbar: " + JSON.stringify(value) + " is not a " + key + ", which takes " + JSON.stringify(VALUES[key]) + ": " + JSON.stringify(DEFAULTS[key]) + " is used");
|
|
1724
|
+
return DEFAULTS[key];
|
|
1725
|
+
}
|
|
1726
|
+
function brandOf(options) {
|
|
1727
|
+
var brand = options.brand;
|
|
1728
|
+
if (brand === void 0) {
|
|
1729
|
+
return ge.t("container.navbar_brand");
|
|
1730
|
+
}
|
|
1731
|
+
if (brand === false || typeof brand === "string" && brand !== "") {
|
|
1732
|
+
return brand;
|
|
1733
|
+
}
|
|
1734
|
+
ge.warn("navbar: " + JSON.stringify(brand) + " is not a brand, which takes a text or false: " + JSON.stringify(ge.t("container.navbar_brand")) + " is used");
|
|
1735
|
+
return ge.t("container.navbar_brand");
|
|
1736
|
+
}
|
|
1737
|
+
function navOf2(container) {
|
|
1738
|
+
return navOf(container);
|
|
1739
|
+
}
|
|
1740
|
+
function infix(value) {
|
|
1741
|
+
return value === true ? "" : "-" + value;
|
|
1742
|
+
}
|
|
1743
|
+
function read(container) {
|
|
1744
|
+
var nav = navOf2(container);
|
|
1745
|
+
var wrap = wrapOf(container);
|
|
1746
|
+
var expand = false;
|
|
1747
|
+
var width = "fluid";
|
|
1748
|
+
var offcanvas = offcanvasOf(container);
|
|
1749
|
+
Array.prototype.forEach.call(nav.classList, function(name) {
|
|
1750
|
+
if (name === "navbar-expand") {
|
|
1751
|
+
expand = true;
|
|
1752
|
+
}
|
|
1753
|
+
if (/^navbar-expand-/.test(name) && BREAKPOINTS.indexOf(name.slice(14)) !== -1) {
|
|
1754
|
+
expand = name.slice(14);
|
|
1755
|
+
}
|
|
1756
|
+
});
|
|
1757
|
+
Array.prototype.forEach.call(wrap.classList, function(name) {
|
|
1758
|
+
if (name === "container") {
|
|
1759
|
+
width = "fixed";
|
|
1760
|
+
}
|
|
1761
|
+
if (/^container-/.test(name) && name !== "container-fluid") {
|
|
1762
|
+
width = name.slice(10);
|
|
1763
|
+
}
|
|
1764
|
+
});
|
|
1765
|
+
var bg = BACKGROUNDS.filter(function(name) {
|
|
1766
|
+
return hasClass(nav, "bg-" + name);
|
|
1767
|
+
})[0];
|
|
1768
|
+
var position = POSITIONS.filter(function(name) {
|
|
1769
|
+
return hasClass(container, name);
|
|
1770
|
+
})[0];
|
|
1771
|
+
return {
|
|
1772
|
+
brand: !!child(wrap, ".navbar-brand"),
|
|
1773
|
+
expand,
|
|
1774
|
+
collapse: child(wrap, ".navbar-collapse") ? "collapse" : offcanvas ? "offcanvas" : false,
|
|
1775
|
+
offcanvas_placement: offcanvas && hasClass(offcanvas, "offcanvas-start") ? "start" : offcanvas ? "end" : null,
|
|
1776
|
+
bg: bg === void 0 ? null : bg,
|
|
1777
|
+
theme: nav.getAttribute("data-bs-theme") || null,
|
|
1778
|
+
position: position === void 0 ? null : position,
|
|
1779
|
+
width
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
function togglerOf(container) {
|
|
1783
|
+
return child(wrapOf(container), ".navbar-toggler");
|
|
1784
|
+
}
|
|
1785
|
+
function makeToggler(id, offcanvas) {
|
|
1786
|
+
var toggler = element("button", {
|
|
1787
|
+
"class": "navbar-toggler",
|
|
1788
|
+
type: "button",
|
|
1789
|
+
"data-bs-toggle": offcanvas ? "offcanvas" : "collapse",
|
|
1790
|
+
"data-bs-target": "#" + id,
|
|
1791
|
+
"aria-controls": id,
|
|
1792
|
+
"aria-expanded": "false",
|
|
1793
|
+
"aria-label": ge.t("container.navbar_toggle")
|
|
1794
|
+
});
|
|
1795
|
+
toggler.appendChild(element("span", { "class": "navbar-toggler-icon" }));
|
|
1796
|
+
return toggler;
|
|
1797
|
+
}
|
|
1798
|
+
function makeOffcanvas(id, placement) {
|
|
1799
|
+
var panel = element("div", {
|
|
1800
|
+
"class": "offcanvas offcanvas-" + placement,
|
|
1801
|
+
tabindex: "-1",
|
|
1802
|
+
id,
|
|
1803
|
+
"aria-labelledby": id + "-label"
|
|
1804
|
+
});
|
|
1805
|
+
var header = panel.appendChild(element("div", { "class": "offcanvas-header" }));
|
|
1806
|
+
header.appendChild(element(
|
|
1807
|
+
"h5",
|
|
1808
|
+
{ "class": "offcanvas-title", id: id + "-label" },
|
|
1809
|
+
ge.t("container.navbar_offcanvas_title")
|
|
1810
|
+
));
|
|
1811
|
+
header.appendChild(element("button", {
|
|
1812
|
+
type: "button",
|
|
1813
|
+
"class": "btn-close",
|
|
1814
|
+
"data-bs-dismiss": "offcanvas",
|
|
1815
|
+
"aria-label": ge.t("container.nav_close")
|
|
1816
|
+
}));
|
|
1817
|
+
panel.appendChild(element("div", { "class": "offcanvas-body" }));
|
|
1818
|
+
return panel;
|
|
1819
|
+
}
|
|
1820
|
+
function setCollapse(container, to, placement, mark) {
|
|
1821
|
+
var wrap = wrapOf(container);
|
|
1822
|
+
var from = read(container).collapse;
|
|
1823
|
+
if (from === to) {
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
var area = areaOf(container);
|
|
1827
|
+
var toggler = togglerOf(container);
|
|
1828
|
+
var old = area === wrap ? null : child(wrap, ".navbar-collapse") || child(wrap, ".offcanvas");
|
|
1829
|
+
var id = old && old.id ? old.id : ge.containerId("navbar");
|
|
1830
|
+
var kids = children(area).filter(function(node) {
|
|
1831
|
+
return !is(node, ".navbar-brand, .navbar-toggler") && !(area === wrap && node === old);
|
|
1832
|
+
});
|
|
1833
|
+
if (toggler) {
|
|
1834
|
+
toggler.remove();
|
|
1835
|
+
}
|
|
1836
|
+
if (old) {
|
|
1837
|
+
old.remove();
|
|
1838
|
+
}
|
|
1839
|
+
var brand = child(wrap, ".navbar-brand");
|
|
1840
|
+
var after = brand ? brand.nextSibling : wrap.firstChild;
|
|
1841
|
+
var target = wrap;
|
|
1842
|
+
if (to !== false) {
|
|
1843
|
+
var panel = to === "collapse" ? element("div", { "class": "collapse navbar-collapse", id }) : makeOffcanvas(id, placement);
|
|
1844
|
+
wrap.insertBefore(makeToggler(id, to === "offcanvas"), after);
|
|
1845
|
+
wrap.appendChild(panel);
|
|
1846
|
+
target = to === "collapse" ? panel : child(panel, ".offcanvas-body");
|
|
1847
|
+
}
|
|
1848
|
+
kids.forEach(function(node) {
|
|
1849
|
+
target.appendChild(node);
|
|
1850
|
+
});
|
|
1851
|
+
if (mark) {
|
|
1852
|
+
baseMark(container);
|
|
1853
|
+
ge.reinit();
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
function setBrand(container, on) {
|
|
1857
|
+
var wrap = wrapOf(container);
|
|
1858
|
+
var brand = child(wrap, ".navbar-brand");
|
|
1859
|
+
if (!on) {
|
|
1860
|
+
if (brand) {
|
|
1861
|
+
brand.remove();
|
|
1862
|
+
}
|
|
1863
|
+
return;
|
|
1864
|
+
}
|
|
1865
|
+
if (brand) {
|
|
1866
|
+
return;
|
|
1867
|
+
}
|
|
1868
|
+
wrap.insertBefore(element("a", { "class": "navbar-brand", href: "#" }, ge.t("container.navbar_brand")), wrap.firstChild);
|
|
1869
|
+
}
|
|
1870
|
+
function write(container, key, value, options) {
|
|
1871
|
+
var nav = navOf2(container);
|
|
1872
|
+
var wrap = wrapOf(container);
|
|
1873
|
+
if (key === "expand") {
|
|
1874
|
+
Array.prototype.filter.call(nav.classList, function(name) {
|
|
1875
|
+
return /^navbar-expand/.test(name);
|
|
1876
|
+
}).forEach(function(name) {
|
|
1877
|
+
nav.classList.remove(name);
|
|
1878
|
+
});
|
|
1879
|
+
if (value !== false) {
|
|
1880
|
+
addClass(nav, "navbar-expand" + (value === true ? "" : infix(value)));
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
if (key === "bg") {
|
|
1884
|
+
Array.prototype.filter.call(nav.classList, function(name) {
|
|
1885
|
+
return /^bg-/.test(name);
|
|
1886
|
+
}).forEach(function(name) {
|
|
1887
|
+
nav.classList.remove(name);
|
|
1888
|
+
});
|
|
1889
|
+
if (value !== null) {
|
|
1890
|
+
addClass(nav, "bg-" + value);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
if (key === "theme") {
|
|
1894
|
+
if (value === null) {
|
|
1895
|
+
nav.removeAttribute("data-bs-theme");
|
|
1896
|
+
} else {
|
|
1897
|
+
nav.setAttribute("data-bs-theme", value);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
if (key === "position") {
|
|
1901
|
+
removeClass(container, POSITIONS.join(" "));
|
|
1902
|
+
if (value !== null) {
|
|
1903
|
+
addClass(container, value);
|
|
1904
|
+
}
|
|
1905
|
+
dropEmptyClass(container);
|
|
1906
|
+
}
|
|
1907
|
+
if (key === "width") {
|
|
1908
|
+
Array.prototype.filter.call(wrap.classList, function(name) {
|
|
1909
|
+
return /^container(-|$)/.test(name);
|
|
1910
|
+
}).forEach(function(name) {
|
|
1911
|
+
wrap.classList.remove(name);
|
|
1912
|
+
});
|
|
1913
|
+
addClass(wrap, value === "fluid" ? "container-fluid" : value === "fixed" ? "container" : "container-" + value);
|
|
1914
|
+
}
|
|
1915
|
+
if (key === "offcanvas_placement") {
|
|
1916
|
+
var offcanvas = offcanvasOf(container);
|
|
1917
|
+
if (offcanvas) {
|
|
1918
|
+
removeClass(offcanvas, "offcanvas-start offcanvas-end");
|
|
1919
|
+
addClass(offcanvas, "offcanvas-" + value);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
if (key === "collapse") {
|
|
1923
|
+
setCollapse(container, value, options && options.placement || placementOf(), !!(options && options.mark));
|
|
1924
|
+
}
|
|
1925
|
+
if (key === "brand") {
|
|
1926
|
+
setBrand(container, value);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
function placementOf() {
|
|
1930
|
+
var setting = (ge.settings.navbar || {}).offcanvas_placement;
|
|
1931
|
+
return VALUES.offcanvas_placement.indexOf(setting) !== -1 ? setting : DEFAULTS.offcanvas_placement;
|
|
1932
|
+
}
|
|
1933
|
+
function layoutHere(container) {
|
|
1934
|
+
if (ge.view() === "all") {
|
|
1935
|
+
return null;
|
|
1936
|
+
}
|
|
1937
|
+
var expand = read(container).expand;
|
|
1938
|
+
if (expand === true) {
|
|
1939
|
+
return "expanded";
|
|
1940
|
+
}
|
|
1941
|
+
if (expand === false) {
|
|
1942
|
+
return "collapsed";
|
|
1943
|
+
}
|
|
1944
|
+
return ge.breakpoints.indexOf(ge.view()) >= ge.breakpoints.indexOf(expand) ? "expanded" : "collapsed";
|
|
1945
|
+
}
|
|
1946
|
+
function markLayout(container) {
|
|
1947
|
+
var layout = layoutHere(container);
|
|
1948
|
+
if (layout) {
|
|
1949
|
+
container.setAttribute(LAYOUT_ATTR, layout);
|
|
1950
|
+
} else {
|
|
1951
|
+
container.removeAttribute(LAYOUT_ATTR);
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
function createSection(container) {
|
|
1955
|
+
var body = element("div", { "class": "ge-nav-options" });
|
|
1956
|
+
var fields = {};
|
|
1957
|
+
function change(key, value) {
|
|
1958
|
+
write(container, key, value, { mark: true });
|
|
1959
|
+
markLayout(container);
|
|
1960
|
+
sections.render();
|
|
1961
|
+
}
|
|
1962
|
+
function select(name, label, choices, onChange) {
|
|
1963
|
+
var field = selectControl(choices, onChange);
|
|
1964
|
+
fields[name] = field.control;
|
|
1965
|
+
body.appendChild(fieldRow(name, label, field.control, field.id));
|
|
1966
|
+
}
|
|
1967
|
+
var brand = checkControl(ge.t("container.nav_brand_show"), function(on) {
|
|
1968
|
+
write(container, "brand", on);
|
|
1969
|
+
baseMark(container);
|
|
1970
|
+
sections.render();
|
|
1971
|
+
});
|
|
1972
|
+
brand.box.setAttribute("data-ge-nav-option", "brand");
|
|
1973
|
+
body.appendChild(brand.box);
|
|
1974
|
+
select("expand", ge.t("container.navbar_expand"), [
|
|
1975
|
+
{ value: "false", label: ge.t("container.navbar_expand_never") },
|
|
1976
|
+
{ value: "true", label: ge.t("container.navbar_expand_always") }
|
|
1977
|
+
].concat(BREAKPOINTS.map(function(key) {
|
|
1978
|
+
return { value: key, label: ge.t("container.navbar_expand_from", { breakpoint: key }) };
|
|
1979
|
+
})), function(value) {
|
|
1980
|
+
change("expand", value === "true" ? true : value === "false" ? false : value);
|
|
1981
|
+
});
|
|
1982
|
+
select("collapse", ge.t("container.navbar_collapse"), [
|
|
1983
|
+
{ value: "none", label: ge.t("container.navbar_collapse_none") },
|
|
1984
|
+
{ value: "collapse", label: ge.t("container.navbar_collapse_collapse") },
|
|
1985
|
+
{ value: "offcanvas", label: ge.t("container.navbar_collapse_offcanvas") }
|
|
1986
|
+
], function(value) {
|
|
1987
|
+
change("collapse", value === "none" ? false : value);
|
|
1988
|
+
});
|
|
1989
|
+
select("offcanvas_placement", ge.t("container.navbar_offcanvas_placement"), [
|
|
1990
|
+
{ value: "start", label: ge.t("container.nav_start") },
|
|
1991
|
+
{ value: "end", label: ge.t("container.nav_end") }
|
|
1992
|
+
], function(value) {
|
|
1993
|
+
change("offcanvas_placement", value);
|
|
1994
|
+
});
|
|
1995
|
+
select("bg", ge.t("container.nav_bg"), [{ value: "none", label: ge.t("container.nav_bg_none") }].concat(
|
|
1996
|
+
BACKGROUND_CHOICES.map(function(each) {
|
|
1997
|
+
return { value: each.value, label: ge.t(each.labelKey) };
|
|
1998
|
+
})
|
|
1999
|
+
), function(value) {
|
|
2000
|
+
change("bg", value === "none" ? null : value);
|
|
2001
|
+
});
|
|
2002
|
+
select("theme", ge.t("container.nav_theme"), [
|
|
2003
|
+
{ value: "auto", label: ge.t("container.nav_theme_auto") },
|
|
2004
|
+
{ value: "light", label: ge.t("container.nav_theme_light") },
|
|
2005
|
+
{ value: "dark", label: ge.t("container.nav_theme_dark") }
|
|
2006
|
+
], function(value) {
|
|
2007
|
+
change("theme", value === "auto" ? null : value);
|
|
2008
|
+
});
|
|
2009
|
+
select("position", ge.t("container.navbar_position"), [
|
|
2010
|
+
{ value: "none", label: ge.t("container.navbar_position_none") }
|
|
2011
|
+
].concat(POSITION_CHOICES.map(function(each) {
|
|
2012
|
+
return { value: each.value, label: ge.t(each.labelKey) };
|
|
2013
|
+
})), function(value) {
|
|
2014
|
+
change("position", value === "none" ? null : value);
|
|
2015
|
+
});
|
|
2016
|
+
select("width", ge.t("container.navbar_width"), [
|
|
2017
|
+
{ value: "fluid", label: ge.t("container.navbar_width_fluid") },
|
|
2018
|
+
{ value: "fixed", label: ge.t("container.navbar_width_fixed") }
|
|
2019
|
+
].concat(BREAKPOINTS.map(function(key) {
|
|
2020
|
+
return { value: key, label: ge.t("container.navbar_width_from", { breakpoint: key }) };
|
|
2021
|
+
})), function(value) {
|
|
2022
|
+
change("width", value);
|
|
2023
|
+
});
|
|
2024
|
+
function render() {
|
|
2025
|
+
var values = read(container);
|
|
2026
|
+
brand.input.checked = values.brand;
|
|
2027
|
+
fields.expand.value = String(values.expand);
|
|
2028
|
+
fields.collapse.value = values.collapse === false ? "none" : values.collapse;
|
|
2029
|
+
fields.offcanvas_placement.value = values.offcanvas_placement || placementOf();
|
|
2030
|
+
fields.offcanvas_placement.disabled = values.collapse !== "offcanvas";
|
|
2031
|
+
fields.bg.value = values.bg === null ? "none" : values.bg;
|
|
2032
|
+
fields.theme.value = values.theme === null ? "auto" : values.theme;
|
|
2033
|
+
fields.position.value = values.position === null ? "none" : values.position;
|
|
2034
|
+
fields.width.value = values.width;
|
|
2035
|
+
}
|
|
2036
|
+
render();
|
|
2037
|
+
sections.add({ node: container, element: body, render });
|
|
2038
|
+
return body;
|
|
2039
|
+
}
|
|
2040
|
+
return Object.assign(base, {
|
|
2041
|
+
labelKey: "container.add_navbar",
|
|
2042
|
+
create: function(options) {
|
|
2043
|
+
options = options || {};
|
|
2044
|
+
var container = element("div", { "data-ge-container": "navbar" });
|
|
2045
|
+
var nav = container.appendChild(element("nav", { "class": "navbar" }));
|
|
2046
|
+
var wrap = nav.appendChild(element("div", { "class": "container-fluid" }));
|
|
2047
|
+
var brand = brandOf(options);
|
|
2048
|
+
if (brand !== false) {
|
|
2049
|
+
wrap.appendChild(element("a", { "class": "navbar-brand", href: "#" }, brand));
|
|
2050
|
+
}
|
|
2051
|
+
var list2 = wrap.appendChild(list(ge, "navbar", true, 2));
|
|
2052
|
+
list2.appendChild(dropdown(ge));
|
|
2053
|
+
["expand", "bg", "theme", "position", "width"].forEach(function(key) {
|
|
2054
|
+
write(container, key, chosen(options, key));
|
|
2055
|
+
});
|
|
2056
|
+
var collapse = chosen(options, "collapse");
|
|
2057
|
+
var placement = chosen(options, "offcanvas_placement");
|
|
2058
|
+
write(container, "collapse", collapse, { placement });
|
|
2059
|
+
return container;
|
|
2060
|
+
},
|
|
2061
|
+
mark: function(container) {
|
|
2062
|
+
baseMark(container);
|
|
2063
|
+
markLayout(container);
|
|
2064
|
+
},
|
|
2065
|
+
unmark: function(container) {
|
|
2066
|
+
baseUnmark(container);
|
|
2067
|
+
container.removeAttribute(LAYOUT_ATTR);
|
|
2068
|
+
},
|
|
2069
|
+
panelSection: function(node, kind) {
|
|
2070
|
+
if (kind !== "navbar" || !navOf2(node)) {
|
|
2071
|
+
return null;
|
|
2072
|
+
}
|
|
2073
|
+
return { labelKey: "container.navbar_section", body: createSection(node) };
|
|
2074
|
+
},
|
|
2075
|
+
// After a view change or a change of classes: the layout marks and the sections follow
|
|
2076
|
+
onRefresh: function(scope) {
|
|
2077
|
+
selfAndAll(scope, '[data-ge-container="navbar"]').forEach(markLayout);
|
|
2078
|
+
sections.render(scope);
|
|
2079
|
+
},
|
|
2080
|
+
onDeinit: function() {
|
|
2081
|
+
sections.clear();
|
|
2082
|
+
}
|
|
2083
|
+
});
|
|
2084
|
+
};
|
|
2085
|
+
})();
|