@leapdev/gui 0.2.240 → 0.2.243

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,9 @@
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
- };
62
-
63
- var getClosestParent = function (elem, selector) {
53
+ const getClosestParent = function (elem, selector) {
64
54
  if (!Element.prototype.matches) {
65
55
  Element.prototype.matches =
66
56
  Element.prototype.matchesSelector ||
@@ -83,15 +73,18 @@
83
73
  return null;
84
74
  };
85
75
 
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
- })();
76
+ const getChildren = function (n, skipMe) {
77
+ let r = [];
78
+ for (; n; n = n.nextSibling)
79
+ if (n.nodeType == 1 && n != skipMe) r.push(n);
80
+ return r;
81
+ };
82
+
83
+ const getSiblings = function (n) {
84
+ return getChildren(n.parentNode.firstChild, n);
92
85
  };
93
86
 
94
- var getDeviceType = function () {
87
+ const getDeviceType = function () {
95
88
  const ua = navigator.userAgent;
96
89
  const isiOS = () => {
97
90
  return /iPad|iPhone/.test(ua) || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
@@ -109,18 +102,166 @@
109
102
  return;
110
103
  };
111
104
 
112
- var getURLHashList = function () {
113
- return window.location.hash !== '' ? window.location.hash.substring(1).split('#') : undefined;
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
107
+ const urlHash = {
108
+ topicsTabAccordion: {},
109
+ articleTabsInit: false,
110
+ articleAccordionInit: false,
111
+ deviceType: getDeviceType(),
112
+ list: window.location.hash,
113
+ init: function () {
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
+ let 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
+ };
241
+ },
242
+ setItem: function (id) {
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;
245
+ return `@${parentText}${childText}`;
246
+ },
247
+ reset: function () {
248
+ urlHash.topicsTabAccordion = {};
249
+ urlHash.articleTabsInit = false;
250
+ urlHash.articleAccordionInit = false;
251
+ urlHash.init();
252
+ }
114
253
  };
115
254
 
255
+ urlHash.init();
256
+ // Tab and Accordion Toggling
116
257
  document.addEventListener('click', function (event) {
117
- var
258
+ const
118
259
  targetElem = event.target,
119
260
  className = targetElem.classList;
120
261
 
121
262
  if (className.value.indexOf('sf-tab-item-link') !== -1) {
122
263
  event.preventDefault();
123
- var targetID,
264
+ let targetID,
124
265
  activeTabBtn,
125
266
  targetTab,
126
267
  targetTabSiblings,
@@ -136,8 +277,6 @@
136
277
  activeTabBtn.classList.add('active');
137
278
  targetTab.classList.add('in');
138
279
 
139
- appendHash(targetElem.textContent);
140
-
141
280
  activeBtnTabSiblings.forEach(function (element) {
142
281
  if (element.classList.value.indexOf('active') !== -1) element.classList.remove('active');
143
282
  });
@@ -147,58 +286,17 @@
147
286
  }
148
287
 
149
288
  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');
289
+ className.value.indexOf('in') == -1 ? className.add('in') : className.remove('in');
153
290
  }
154
291
 
155
- return false;
156
- }, false);
157
-
158
- const openParent = (childElement) => {
159
- const closestTab = getClosestParent(childElement, '.sf-tab-content');
160
- const closestAccordion = getClosestParent(childElement, '.sf-accordion-content');
161
-
162
- if (closestTab !== null) {
163
- document.getElementById(`target_${closestTab.id}`).click();
164
- }
165
- if (closestAccordion !== null) {
166
- document.getElementById(`target_${closestAccordion.id}`).click();
292
+ if (
293
+ className.value.indexOf('sf-tab-item-link') !== -1 ||
294
+ className.value.indexOf('sf-accordion-toggle') !== -1
295
+ ) {
296
+ // console.log(urlHash.topicsTabAccordion);
297
+ window.location.hash = urlHash.setItem(targetElem.id);
167
298
  }
168
- };
169
299
 
170
- // Set default tab via URL hash or device type if present on tabs
171
- 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
- }
187
- });
188
- });
189
- });
190
-
191
- 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
- });
203
- });
300
+ return false;
301
+ }, false);
204
302
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapdev/gui",
3
- "version": "0.2.240",
3
+ "version": "0.2.243",
4
4
  "description": "LEAP GUI",
5
5
  "author": "LEAP Dev",
6
6
  "license": "ISC",