@leapdev/gui 0.2.241 → 0.2.242

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.
@@ -50,8 +50,6 @@
50
50
 
51
51
  //LEAP Help Centre JS for Components generated via Chrome Extension
52
52
  (function () {
53
- const topicsTabAccordion = {};
54
-
55
53
  const getClosestParent = function (elem, selector) {
56
54
  if (!Element.prototype.matches) {
57
55
  Element.prototype.matches =
@@ -105,18 +103,156 @@
105
103
  };
106
104
 
107
105
  // #@desktop:accordion-2;sub-accordion-1@parent-accordion-1
106
+ // Set default tab via URL hash parameters or device type if present on tabs
108
107
  const urlHash = {
108
+ topicsTabAccordion: {},
109
+ articleTabsInit: false,
110
+ articleAccordionInit: false,
111
+ deviceType: getDeviceType(),
109
112
  list: window.location.hash,
110
113
  init: function () {
111
- this.openedTopics = window.location.hash.substring(1).split('@').splice(1);
114
+ urlHash.openedTopics = window.location.hash.substring(1).split('@').splice(1);
115
+
116
+ ready('.sf-tabs', function () {
117
+ if (!urlHash.articleTabsInit) {
118
+
119
+ const toggleTabs = (params) => {
120
+ // Remove existing active CSS classes
121
+ const currentTabContentID = params.tabNav.querySelector('.sf-tab-item.active').firstElementChild.id.substring(7);
122
+ params.tabNav.querySelector('.sf-tab-item.active').classList.remove('active');
123
+ document.getElementById(currentTabContentID).classList.remove('in');
124
+
125
+ //Update tab according to device with active and in css class
126
+ params.targetTabLink.parentNode.classList.add('active');
127
+ document.getElementById(params.targetTabLink.id.substring(7)).classList.add('in');
128
+ };
129
+
130
+ document.querySelectorAll('.sf-tabs').forEach(tab => {
131
+ tab.querySelectorAll('.sf-tab-item-link').forEach(tabitem => {
132
+ const tabItemText = tabitem.textContent.toLowerCase().replace(/\s/g, '');
133
+
134
+ const _closestParent = urlHash.closestParent(tabitem);
135
+
136
+ urlHash.topicsTabAccordion[tabitem.id] = {
137
+ text: tabItemText,
138
+ isMainParent: _closestParent.flag,
139
+ parentLabel: _closestParent.parentLabel,
140
+ directParentID: _closestParent.directParentID
141
+ };
142
+
143
+ // If URL hash is not present, we locate the name of the device tab
144
+ const sfTabNav = tabitem.parentNode.parentNode;
145
+ if (tabItemText === urlHash.deviceType && urlHash.list === '') {
146
+ if (sfTabNav.querySelector('.sf-tab-item.active').classList.contains('active')) {
147
+ toggleTabs({
148
+ targetTabLink: tabitem,
149
+ tabNav: sfTabNav
150
+ });
151
+ }
152
+ }
153
+
154
+ if (urlHash.list !== '' && urlHash.list.search(tabItemText) > -1) {
155
+ Object.keys(urlHash.topicsTabAccordion).forEach(key => {
156
+ if (tabItemText == urlHash.topicsTabAccordion[key].text) {
157
+ toggleTabs({
158
+ targetTabLink: tabitem,
159
+ tabNav: sfTabNav
160
+ });
161
+ }
162
+ });
163
+ }
164
+ });
165
+ });
166
+
167
+ urlHash.articleTabsInit = true;
168
+ console.log(urlHash.topicsTabAccordion);
169
+ }
170
+ });
171
+
172
+ ready('.sf-accordion', function () {
173
+ if (!urlHash.articleAccordionInit) {
174
+ const urlHashList = window.location.hash;
175
+ document.querySelectorAll('.sf-accordion-toggle').forEach(accordionToggle => {
176
+ const accordionText = accordionToggle
177
+ .querySelector('.sf-accordion-text')
178
+ .textContent.split(' ').join('-').toLowerCase();
179
+
180
+ const _closestParent = urlHash.closestParent(accordionToggle);
181
+
182
+ urlHash.topicsTabAccordion[accordionToggle.id] = {
183
+ text: accordionText,
184
+ isMainParent: _closestParent.flag,
185
+ parentLabel: _closestParent.parentLabel
186
+ };
187
+
188
+ if (urlHashList !== '' && urlHash.list.split(':')[1] === accordionText) {
189
+ Object.keys(urlHash.topicsTabAccordion).forEach(key => {
190
+ if (accordionText == urlHash.topicsTabAccordion[key].text) {
191
+ document.getElementById(key).classList.add('in');
192
+
193
+ const hasAccordionParent = getClosestParent(accordionToggle, '.sf-accordion-content');
194
+ if (hasAccordionParent !== null) {
195
+ document.getElementById(`target_${hasAccordionParent.id}`).classList.add('in');
196
+ }
197
+ return;
198
+ }
199
+ });
200
+ }
201
+ });
202
+
203
+ urlHash.articleAccordionInit = true;
204
+ }
205
+ });
206
+
207
+ if (window.location.pathname.includes('/article')) {
208
+ urlHash.observe();
209
+ }
210
+ },
211
+ observe: function () {
212
+ const previousState = window.history.state;
213
+ let t = setInterval(function () {
214
+ if (previousState !== window.history.state) {
215
+ previousState = window.history.state;
216
+ clearInterval(t);
217
+ urlHash.reset();
218
+ }
219
+ }, 100);
220
+ },
221
+ closestParent: function (child) {
222
+ const tabContent = getClosestParent(child, '.sf-tab-content');
223
+ const accordionContent = getClosestParent(child, '.sf-accordion-content');
224
+ const parentLabel = () => {
225
+ if (tabContent !== null) {
226
+ return document.getElementById(`target_${tabContent.id}`).textContent;
227
+ }
228
+ else if (accordionContent !== null) {
229
+ return document.getElementById(`target_${accordionContent.id}`).querySelector('.sf-accordion-text').textContent;
230
+ }
231
+ else {
232
+ return '';
233
+ }
234
+ };
235
+ // console.log(tabContent, accordionContent);
236
+ return {
237
+ parentLabel: parentLabel().split(' ').join('-').toLowerCase(),
238
+ flag: tabContent !== null || accordionContent !== null ? false : true,
239
+ directParentID: 'test'
240
+ };
112
241
  },
113
242
  setItem: function (id) {
114
- const childText = topicsTabAccordion[id].isMainParent ? '' : (':' + topicsTabAccordion[id].text);
115
- const parentText = topicsTabAccordion[id].isMainParent ? topicsTabAccordion[id].text : topicsTabAccordion[id].parentLabel;
243
+ const childText = urlHash.topicsTabAccordion[id].isMainParent ? '' : (':' + urlHash.topicsTabAccordion[id].text);
244
+ const parentText = urlHash.topicsTabAccordion[id].isMainParent ? urlHash.topicsTabAccordion[id].text : urlHash.topicsTabAccordion[id].parentLabel;
116
245
  return `@${parentText}${childText}`;
246
+ },
247
+ reset: function () {
248
+ urlHash.topicsTabAccordion = {};
249
+ urlHash.articleTabsInit = false;
250
+ urlHash.articleAccordionInit = false;
251
+ urlHash.init();
117
252
  }
118
253
  };
119
254
 
255
+ urlHash.init();
120
256
  // Tab and Accordion Toggling
121
257
  document.addEventListener('click', function (event) {
122
258
  const
@@ -157,121 +293,10 @@
157
293
  className.value.indexOf('sf-tab-item-link') !== -1 ||
158
294
  className.value.indexOf('sf-accordion-toggle') !== -1
159
295
  ) {
296
+ // console.log(urlHash.topicsTabAccordion);
160
297
  window.location.hash = urlHash.setItem(targetElem.id);
161
298
  }
162
299
 
163
300
  return false;
164
301
  }, false);
165
-
166
- // Set default tab via URL hash parameters or device type if present on tabs
167
- let articleTabsInit = false;
168
- let articleAccordionInit = false;
169
-
170
- urlHash.init();
171
-
172
- const closestParent = (child) => {
173
- const tabContent = getClosestParent(child, '.sf-tab-content');
174
- const accordionContent = getClosestParent(child, '.sf-accordion-content');
175
- const parentLabel = () => {
176
- if (tabContent !== null) {
177
- return document.getElementById(`target_${tabContent.id}`).textContent;
178
- }
179
- else if (accordionContent !== null) {
180
- return document.getElementById(`target_${accordionContent.id}`).querySelector('.sf-accordion-text').textContent;
181
- }
182
- else {
183
- return '';
184
- }
185
- };
186
- return {
187
- parentLabel: parentLabel().split(' ').join('-').toLowerCase(),
188
- flag: tabContent !== null || accordionContent !== null ? false : true
189
- };
190
- };
191
-
192
- ready('.sf-tabs', function () {
193
- if (!articleTabsInit) {
194
-
195
- const toggleTabs = (params) => {
196
- // Remove existing active CSS classes
197
- const currentTabContentID = params.tabNav.querySelector('.sf-tab-item.active').firstElementChild.id.substring(7);
198
- params.tabNav.querySelector('.sf-tab-item.active').classList.remove('active');
199
- document.getElementById(currentTabContentID).classList.remove('in');
200
-
201
- //Update tab according to device with active and in css class
202
- params.targetTabLink.parentNode.classList.add('active');
203
- document.getElementById(params.targetTabLink.id.substring(7)).classList.add('in');
204
- };
205
-
206
- document.querySelectorAll('.sf-tabs').forEach(tab => {
207
- const deviceType = getDeviceType();
208
- tab.querySelectorAll('.sf-tab-item-link').forEach(tabitem => {
209
- const tabItemText = tabitem.textContent.toLowerCase().replace(/\s/g, '');
210
-
211
- const _closestParent = closestParent(tabitem);
212
-
213
- topicsTabAccordion[tabitem.id] = {
214
- text: tabItemText,
215
- isMainParent: _closestParent.flag,
216
- parentLabel: _closestParent.parentLabel
217
- };
218
-
219
- // If URL hash is not present, we locate the name of the device tab
220
- const sfTabNav = tabitem.parentNode.parentNode;
221
- if (tabItemText === deviceType && urlHash.list === '') {
222
- if (sfTabNav.querySelector('.sf-tab-item.active').classList.contains('active')) {
223
- toggleTabs({
224
- targetTabLink: tabitem,
225
- tabNav: sfTabNav
226
- });
227
- }
228
- }
229
-
230
- if (urlHash.list !== '' && urlHash.list.search(tabItemText) > -1) {
231
- Object.keys(topicsTabAccordion).forEach(key => {
232
- if (tabItemText == topicsTabAccordion[key].text) {
233
- toggleTabs({
234
- targetTabLink: tabitem,
235
- tabNav: sfTabNav
236
- });
237
- }
238
- });
239
- }
240
- });
241
- });
242
-
243
- articleTabsInit = true;
244
- console.log(topicsTabAccordion);
245
- }
246
- });
247
-
248
- ready('.sf-accordion', function () {
249
- if (!articleAccordionInit) {
250
- const urlHashList = window.location.hash;
251
- document.querySelectorAll('.sf-accordion-toggle').forEach(accordionToggle => {
252
- const accordionText = accordionToggle
253
- .querySelector('.sf-accordion-text')
254
- .textContent.split(' ').join('-').toLowerCase();
255
-
256
- const _closestParent = closestParent(accordionToggle);
257
-
258
- topicsTabAccordion[accordionToggle.id] = {
259
- text: accordionText,
260
- isMainParent: _closestParent.flag,
261
- parentLabel: _closestParent.parentLabel
262
- };
263
-
264
- if (urlHashList !== '' && urlHash.list.search(accordionText) > -1) {
265
- Object.keys(topicsTabAccordion).forEach(key => {
266
- if (accordionText == topicsTabAccordion[key].text) {
267
- document.getElementById(key).classList.add('in');
268
- return;
269
- }
270
- });
271
- }
272
- });
273
-
274
- articleAccordionInit = true;
275
- }
276
- });
277
302
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapdev/gui",
3
- "version": "0.2.241",
3
+ "version": "0.2.242",
4
4
  "description": "LEAP GUI",
5
5
  "author": "LEAP Dev",
6
6
  "license": "ISC",