domma-js 0.7.2-alpha → 0.7.5-alpha

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.
@@ -1,112 +1,111 @@
1
1
  /**
2
2
  * Domma Kickstart Application
3
3
  *
4
- * This file initializes your Domma project based on domma.config.json.
5
- * Customize the config file to change navbar, footer, theme, and features.
4
+ * This file initialises your Domma project based on domma.config.json.
5
+ * Customise the config file to change navbar, footer, theme, and features.
6
6
  */
7
7
 
8
- (async function () {
8
+ $(() => {
9
9
  // Load configuration
10
- const response = await fetch('./domma.config.json');
11
- const config = await response.json();
12
-
13
- // Initialize theme
14
- if (config.theme) {
15
- Domma.theme.init({
16
- theme: config.theme.default || 'charcoal-dark',
17
- persist: config.theme.persist !== false,
18
- autoDetect: config.theme.autoDetect === true
19
- });
20
-
21
- // Add theme selector if enabled
22
- if (config.theme.selector) {
23
- addThemeSelector();
24
- }
25
- }
26
-
27
- // Initialize navbar
28
- if (config.navbar) {
29
- Domma.elements.navbar('#main-navbar', {
30
- brand: config.navbar.brand,
31
- items: config.navbar.items,
32
- variant: config.navbar.variant || 'dark',
33
- position: config.navbar.position || 'sticky',
34
- collapsible: config.navbar.collapsible !== false
35
- });
36
- }
37
-
38
- // Initialize footer
39
- if (config.footer) {
40
- const footer = document.querySelector('.page-footer');
41
- if (footer) {
42
- const footerContent = document.createElement('div');
43
- footerContent.className = 'footer-content';
44
-
45
- const copyright = document.createElement('p');
46
- copyright.textContent = config.footer.copyright;
47
- footerContent.appendChild(copyright);
48
-
49
- const nav = document.createElement('nav');
50
- nav.className = 'footer-nav';
51
- config.footer.links.forEach(link => {
52
- const a = document.createElement('a');
53
- a.href = link.url;
54
- a.textContent = link.text;
55
- nav.appendChild(a);
10
+ Domma.http.get('./domma.config.json').then(config => {
11
+ // Initialise theme
12
+ if (config.theme) {
13
+ Domma.theme.init({
14
+ theme: config.theme.default || 'charcoal-dark',
15
+ persist: config.theme.persist !== false,
16
+ autoDetect: config.theme.autoDetect === true
56
17
  });
57
- footerContent.appendChild(nav);
58
18
 
59
- footer.appendChild(footerContent);
19
+ // Add theme selector if enabled
20
+ if (config.theme.selector) {
21
+ addThemeSelector();
22
+ }
60
23
  }
61
- }
62
24
 
63
- // Initialize features
64
- if (config.features) {
65
- // Icon scanning
66
- if (config.features.icons) {
67
- Domma.icons.scan();
25
+ // Initialise navbar
26
+ if (config.navbar) {
27
+ Domma.elements.navbar('#main-navbar', {
28
+ brand: config.navbar.brand,
29
+ items: config.navbar.items,
30
+ variant: config.navbar.variant || 'dark',
31
+ position: config.navbar.position || 'sticky',
32
+ collapsible: config.navbar.collapsible !== false
33
+ });
68
34
  }
69
35
 
70
- // Back to top button
71
- if (config.features.backToTop) {
72
- Domma.elements.backToTop({
73
- scrollThreshold: 300,
74
- position: 'bottom-right'
75
- });
36
+ // Initialise footer
37
+ if (config.footer) {
38
+ const $footer = $('.page-footer');
39
+ if ($footer.length) {
40
+ const $footerContent = $('<div class="footer-content"></div>');
41
+
42
+ const $copyright = $('<p></p>').text(config.footer.copyright);
43
+ $footerContent.append($copyright);
44
+
45
+ const $nav = $('<nav class="footer-nav"></nav>');
46
+ _.each(config.footer.links, link => {
47
+ const $link = $('<a></a>')
48
+ .attr('href', link.url)
49
+ .text(link.text);
50
+ $nav.append($link);
51
+ });
52
+ $footerContent.append($nav);
53
+
54
+ $footer.append($footerContent);
55
+ }
76
56
  }
77
57
 
78
- // Smooth scroll
79
- if (config.features.smoothScroll) {
80
- document.querySelectorAll('a[href^="#"]').forEach(anchor => {
81
- anchor.addEventListener('click', function (e) {
58
+ // Initialise features
59
+ if (config.features) {
60
+ // Icon scanning
61
+ if (config.features.icons) {
62
+ Domma.icons.scan();
63
+ }
64
+
65
+ // Back to top button
66
+ if (config.features.backToTop) {
67
+ Domma.elements.backToTop({
68
+ scrollThreshold: 300,
69
+ position: 'bottom-right'
70
+ });
71
+ }
72
+
73
+ // Smooth scroll
74
+ if (config.features.smoothScroll) {
75
+ $('a[href^="#"]').on('click', function (e) {
82
76
  e.preventDefault();
83
- const target = document.querySelector(this.getAttribute('href'));
84
- if (target) {
85
- target.scrollIntoView({behavior: 'smooth'});
77
+ const targetId = $(this).attr('href');
78
+ const $target = $(targetId);
79
+
80
+ if ($target.length) {
81
+ $target[0].scrollIntoView({behavior: 'smooth'});
86
82
  }
87
83
  });
88
- });
89
- }
84
+ }
90
85
 
91
- // Code copy buttons
92
- if (config.features.codeCopy) {
93
- document.querySelectorAll('pre code').forEach(block => {
94
- const button = document.createElement('button');
95
- button.textContent = 'Copy';
96
- button.className = 'btn btn-sm code-copy-btn';
97
- button.onclick = () => {
98
- navigator.clipboard.writeText(block.textContent);
99
- button.textContent = 'Copied!';
100
- setTimeout(() => button.textContent = 'Copy', 2000);
101
- };
102
- block.parentElement.style.position = 'relative';
103
- block.parentElement.insertBefore(button, block);
104
- });
86
+ // Code copy buttons
87
+ if (config.features.codeCopy) {
88
+ $('pre code').each((codeBlock) => {
89
+ const $code = $(codeBlock);
90
+ const $pre = $code.parent();
91
+
92
+ const $button = $('<button class="btn btn-sm code-copy-btn">Copy</button>');
93
+
94
+ $button.on('click', () => {
95
+ _.copyToClipboard($code.text());
96
+ $button.text('Copied!');
97
+ setTimeout(() => $button.text('Copy'), 2000);
98
+ });
99
+
100
+ $pre.css('position', 'relative');
101
+ $pre.prepend($button);
102
+ });
103
+ }
105
104
  }
106
- }
107
105
 
108
- console.log(`✓ Domma initialized with theme: ${config.theme.default}`);
109
- })();
106
+ console.log(`✓ Domma initialised with theme: ${config.theme.default}`);
107
+ });
108
+ });
110
109
 
111
110
  /**
112
111
  * Add floating theme selector
@@ -115,28 +114,25 @@ function addThemeSelector() {
115
114
  const themes = Domma.theme.listThemes();
116
115
  const currentTheme = Domma.theme.get();
117
116
 
118
- const selector = document.createElement('div');
119
- selector.className = 'theme-selector';
117
+ const $selector = $('<div class="theme-selector"></div>');
118
+ const $select = $('<select id="theme-select" class="form-select"></select>');
120
119
 
121
- const select = document.createElement('select');
122
- select.id = 'theme-select';
123
- select.className = 'form-select';
120
+ _.each(themes, theme => {
121
+ const $option = $('<option></option>')
122
+ .attr('value', theme)
123
+ .text(theme);
124
124
 
125
- themes.forEach(theme => {
126
- const option = document.createElement('option');
127
- option.value = theme;
128
- option.textContent = theme;
129
125
  if (theme === currentTheme) {
130
- option.selected = true;
126
+ $option.attr('selected', 'selected');
131
127
  }
132
- select.appendChild(option);
128
+
129
+ $select.append($option);
133
130
  });
134
131
 
135
- selector.appendChild(select);
132
+ $selector.append($select);
136
133
 
137
134
  // Add styles
138
- const style = document.createElement('style');
139
- style.textContent = `
135
+ const $style = $(`<style>
140
136
  .theme-selector {
141
137
  position: fixed;
142
138
  bottom: 80px;
@@ -150,12 +146,13 @@ function addThemeSelector() {
150
146
  .theme-selector select {
151
147
  min-width: 150px;
152
148
  }
153
- `;
154
- document.head.appendChild(style);
155
- document.body.appendChild(selector);
149
+ </style>`);
150
+
151
+ $('head').append($style);
152
+ $('body').append($selector);
156
153
 
157
154
  // Handle theme changes
158
- select.addEventListener('change', (e) => {
159
- Domma.theme.set(e.target.value);
155
+ $select.on('change', (e) => {
156
+ Domma.theme.set($(e.target).val());
160
157
  });
161
158
  }