@leapdev/gui 0.2.240 → 0.2.241

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.
@@ -48,19 +48,11 @@
48
48
  win.ready = ready;
49
49
  })(this);
50
50
 
51
+ //LEAP Help Centre JS for Components generated via Chrome Extension
51
52
  (function () {
52
- var getChildren = function (n, skipMe) {
53
- var r = [];
54
- for (; n; n = n.nextSibling)
55
- if (n.nodeType == 1 && n != skipMe) r.push(n);
56
- return r;
57
- };
58
-
59
- var getSiblings = function (n) {
60
- return getChildren(n.parentNode.firstChild, n);
61
- };
53
+ const topicsTabAccordion = {};
62
54
 
63
- var getClosestParent = function (elem, selector) {
55
+ const getClosestParent = function (elem, selector) {
64
56
  if (!Element.prototype.matches) {
65
57
  Element.prototype.matches =
66
58
  Element.prototype.matchesSelector ||
@@ -83,15 +75,18 @@
83
75
  return null;
84
76
  };
85
77
 
86
- // For Version 1 the order of Hash appendages is Tab -> Accordion -> Subaccordion
87
- var appendHash = function (str) {
88
- window.location.hash = (() => {
89
- const lowercasedStr = str.toLowerCase();
90
- return lowercasedStr.split(' ').join('-');
91
- })();
78
+ const getChildren = function (n, skipMe) {
79
+ let r = [];
80
+ for (; n; n = n.nextSibling)
81
+ if (n.nodeType == 1 && n != skipMe) r.push(n);
82
+ return r;
83
+ };
84
+
85
+ const getSiblings = function (n) {
86
+ return getChildren(n.parentNode.firstChild, n);
92
87
  };
93
88
 
94
- var getDeviceType = function () {
89
+ const getDeviceType = function () {
95
90
  const ua = navigator.userAgent;
96
91
  const isiOS = () => {
97
92
  return /iPad|iPhone/.test(ua) || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
@@ -109,18 +104,28 @@
109
104
  return;
110
105
  };
111
106
 
112
- var getURLHashList = function () {
113
- return window.location.hash !== '' ? window.location.hash.substring(1).split('#') : undefined;
107
+ // #@desktop:accordion-2;sub-accordion-1@parent-accordion-1
108
+ const urlHash = {
109
+ list: window.location.hash,
110
+ init: function () {
111
+ this.openedTopics = window.location.hash.substring(1).split('@').splice(1);
112
+ },
113
+ setItem: function (id) {
114
+ const childText = topicsTabAccordion[id].isMainParent ? '' : (':' + topicsTabAccordion[id].text);
115
+ const parentText = topicsTabAccordion[id].isMainParent ? topicsTabAccordion[id].text : topicsTabAccordion[id].parentLabel;
116
+ return `@${parentText}${childText}`;
117
+ }
114
118
  };
115
119
 
120
+ // Tab and Accordion Toggling
116
121
  document.addEventListener('click', function (event) {
117
- var
122
+ const
118
123
  targetElem = event.target,
119
124
  className = targetElem.classList;
120
125
 
121
126
  if (className.value.indexOf('sf-tab-item-link') !== -1) {
122
127
  event.preventDefault();
123
- var targetID,
128
+ let targetID,
124
129
  activeTabBtn,
125
130
  targetTab,
126
131
  targetTabSiblings,
@@ -136,8 +141,6 @@
136
141
  activeTabBtn.classList.add('active');
137
142
  targetTab.classList.add('in');
138
143
 
139
- appendHash(targetElem.textContent);
140
-
141
144
  activeBtnTabSiblings.forEach(function (element) {
142
145
  if (element.classList.value.indexOf('active') !== -1) element.classList.remove('active');
143
146
  });
@@ -147,58 +150,128 @@
147
150
  }
148
151
 
149
152
  if (className.value.indexOf('sf-accordion-toggle') !== -1) {
150
- appendHash(targetElem.querySelector('.sf-accordion-text').textContent);
151
- className.value.indexOf('in') == -1 ?
152
- className.add('in') : className.remove('in');
153
+ className.value.indexOf('in') == -1 ? className.add('in') : className.remove('in');
154
+ }
155
+
156
+ if (
157
+ className.value.indexOf('sf-tab-item-link') !== -1 ||
158
+ className.value.indexOf('sf-accordion-toggle') !== -1
159
+ ) {
160
+ window.location.hash = urlHash.setItem(targetElem.id);
153
161
  }
154
162
 
155
163
  return false;
156
164
  }, false);
157
165
 
158
- const openParent = (childElement) => {
159
- const closestTab = getClosestParent(childElement, '.sf-tab-content');
160
- const closestAccordion = getClosestParent(childElement, '.sf-accordion-content');
166
+ // Set default tab via URL hash parameters or device type if present on tabs
167
+ let articleTabsInit = false;
168
+ let articleAccordionInit = false;
161
169
 
162
- if (closestTab !== null) {
163
- document.getElementById(`target_${closestTab.id}`).click();
164
- }
165
- if (closestAccordion !== null) {
166
- document.getElementById(`target_${closestAccordion.id}`).click();
167
- }
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
+ };
168
190
  };
169
191
 
170
- // Set default tab via URL hash or device type if present on tabs
171
192
  ready('.sf-tabs', function () {
172
- const urlHashList = getURLHashList();
173
- document.querySelectorAll('.sf-tabs').forEach(tab => {
174
- const deviceType = getDeviceType();
175
- tab.querySelectorAll('.sf-tab-item-link').forEach(tabitem => {
176
- console.log(tabitem);
177
- const tabItemText = tabitem.textContent.toLowerCase().replace(/\s/g, '');
178
- console.log(tabItemText, deviceType, typeof (urlHashList));
179
-
180
- if (tabItemText === deviceType && typeof (urlHashList) === 'undefined') {
181
- tabitem.click();
182
- }
183
- else if (typeof (urlHashList) !== 'undefined' && urlHashList.includes(tabItemText)) {
184
- openParent(tabitem);
185
- tabitem.click();
186
- }
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
+ });
187
241
  });
188
- });
242
+
243
+ articleTabsInit = true;
244
+ console.log(topicsTabAccordion);
245
+ }
189
246
  });
190
247
 
191
248
  ready('.sf-accordion', function () {
192
- const urlHashList = getURLHashList();
193
- document.querySelectorAll('.sf-accordion-toggle').forEach(accordionToggle => {
194
- const accordionText = accordionToggle
195
- .querySelector('.sf-accordion-text')
196
- .textContent.split(' ').join('-').toLowerCase();
197
-
198
- if (typeof (urlHashList) !== 'undefined' && urlHashList.includes(accordionText)) {
199
- openParent(accordionToggle);
200
- accordionToggle.click();
201
- }
202
- });
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
+ }
203
276
  });
204
277
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapdev/gui",
3
- "version": "0.2.240",
3
+ "version": "0.2.241",
4
4
  "description": "LEAP GUI",
5
5
  "author": "LEAP Dev",
6
6
  "license": "ISC",