dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
icons.js
Go to the documentation of this file.
1(function ($) {
2
3 if (!window.dbx) return;
4 const dbx = window.dbx;
5
6 function init(el, cfg) {
7
8 // --------------------------------------------
9 // Sprite laden (einmal global)
10 // --------------------------------------------
11 if (!window._dbxIconSpriteLoaded) {
12
13 const spritePath = dbx.config.rootPath + 'design/' + dbx.config.design + '/icons/sprite.svg';
14
15 dbx.log("icons → load sprite:", spritePath);
16
17 if (!dbx.ajax || typeof dbx.ajax.request !== 'function') {
18 dbx.error("icons → ajax.js not loaded");
19 return;
20 }
21
22 dbx.ajax.request({
23 url: spritePath,
24 method: 'GET',
25 mode: 'text',
26 timeout: 30000
27 })
28 .then(svg => {
29
30 const div = document.createElement('div');
31 div.style.display = 'none';
32 div.innerHTML = svg;
33
34 document.body.prepend(div);
35
36 window._dbxIconSpriteLoaded = true;
37
38 dbx.log("icons → sprite loaded");
39
40 renderIcons(el);
41 })
42 .catch(err => {
43 dbx.error("icons → sprite load failed:", err);
44 });
45
46 } else {
47 renderIcons(el);
48 }
49 }
50
51 function renderIcons(el) {
52
53 $(el).find('.dbx-icon').each(function () {
54
55 const icon = this.getAttribute('data-icon');
56 if (!icon) return;
57
58 const size = this.getAttribute('data-size');
59 const color = this.getAttribute('data-color');
60
61 // SVG erstellen
62 const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
63 svg.classList.add('dbx-icon');
64
65 // size (optional)
66 if (size) {
67 svg.classList.add('dbx-icon-' + size);
68 }
69
70 // color (optional)
71 if (color) {
72 svg.style.color = color;
73 }
74
75 // use
76 const use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
77 use.setAttribute('href', '#' + icon);
78
79 svg.appendChild(use);
80
81 // ersetzen
82 this.replaceWith(svg);
83 });
84 }
85
86 // --------------------------------------------
87 // FEATURE REGISTER (WICHTIG!)
88 // --------------------------------------------
89 dbx.feature.register("icons", {
90
91 scope: "element", // 🔥 FIX
92
93 css: [
94 ['css', 'design', 'c-icons.css']
95 ],
96
97 js: [
98 ['js', 'lib', 'ajax.js']
99 ],
100
101 init(el, cfg) {
102 init(el, cfg || {});
103 }
104
105 });
106
107})(jQuery);