@leapdev/gui 0.2.239 → 0.2.240

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,3 +1,53 @@
1
+ // Mutation Observer for Accordion and Tabs
2
+ //https://gist.github.com/matthewmorrone/da487467501e8b815430
3
+ (function (win) {
4
+ 'use strict';
5
+
6
+ var listeners = [],
7
+ doc = win.document,
8
+ MutationObserver = win.MutationObserver || win.WebKitMutationObserver,
9
+ observer;
10
+
11
+ function ready(selector, fn) {
12
+ // Store the selector and callback to be monitored
13
+ listeners.push({
14
+ selector: selector,
15
+ fn: fn
16
+ });
17
+ if (!observer) {
18
+ // Watch for changes in the document
19
+ observer = new MutationObserver(check);
20
+ observer.observe(doc.documentElement, {
21
+ childList: true,
22
+ subtree: true
23
+ });
24
+ }
25
+ // Check if the element is currently in the DOM
26
+ check();
27
+ }
28
+
29
+ function check() {
30
+ // Check the DOM for elements matching a stored selector
31
+ for (var i = 0, len = listeners.length, listener, elements; i < len; i++) {
32
+ listener = listeners[i];
33
+ // Query for elements matching the specified selector
34
+ elements = doc.querySelectorAll(listener.selector);
35
+ for (var j = 0, jLen = elements.length, element; j < jLen; j++) {
36
+ element = elements[j];
37
+ // Make sure the callback isn't invoked with the
38
+ // same element more than once
39
+ if (!element.ready) {
40
+ element.ready = true;
41
+ // Invoke the callback with the element
42
+ listener.fn.call(element, element);
43
+ }
44
+ }
45
+ }
46
+ }
47
+ // Expose `ready`
48
+ win.ready = ready;
49
+ })(this);
50
+
1
51
  (function () {
2
52
  var getChildren = function (n, skipMe) {
3
53
  var r = [];
@@ -59,6 +109,10 @@
59
109
  return;
60
110
  };
61
111
 
112
+ var getURLHashList = function () {
113
+ return window.location.hash !== '' ? window.location.hash.substring(1).split('#') : undefined;
114
+ };
115
+
62
116
  document.addEventListener('click', function (event) {
63
117
  var
64
118
  targetElem = event.target,
@@ -101,53 +155,50 @@
101
155
  return false;
102
156
  }, false);
103
157
 
104
- // Set default tab via URL hash or device type if present on tabs
105
- document.addEventListener('DOMContentLoaded', function () {
106
- const tabs = document.querySelectorAll('.sf-tabs');
107
- const accordion = document.querySelectorAll('.sf-accordion-toggle');
108
- const urlHashList = window.location.hash !== '' ? window.location.hash.substring(1).split('#') : undefined;
109
-
110
- const openParent = (childElement) => {
111
- const closestTab = getClosestParent(childElement, '.sf-tab-content');
112
- const closestAccordion = getClosestParent(childElement, '.sf-accordion-content');
113
-
114
- if (closestTab !== null) {
115
- document.getElementById(`target_${closestTab.id}`).click();
116
- }
117
- if (closestAccordion !== null) {
118
- document.getElementById(`target_${closestAccordion.id}`).click();
119
- }
120
- };
158
+ const openParent = (childElement) => {
159
+ const closestTab = getClosestParent(childElement, '.sf-tab-content');
160
+ const closestAccordion = getClosestParent(childElement, '.sf-accordion-content');
121
161
 
122
- if (tabs.length !== 0) {
123
- tabs.forEach(tab => {
124
- const deviceType = getDeviceType();
125
- tab.querySelectorAll('.sf-tab-item-link').forEach(tabitem => {
126
- const tabItemText = tabitem.textContent.toLowerCase().replace(/\s/g, '');
127
-
128
- if (tabItemText === deviceType && typeof (urlHashList) === 'undefined') {
129
- tabitem.click();
130
- }
131
- else if (typeof (urlHashList) !== 'undefined' && urlHashList.includes(tabItemText)) {
132
- openParent(tabitem);
133
- tabitem.click();
134
- }
135
- });
136
- });
162
+ if (closestTab !== null) {
163
+ document.getElementById(`target_${closestTab.id}`).click();
137
164
  }
165
+ if (closestAccordion !== null) {
166
+ document.getElementById(`target_${closestAccordion.id}`).click();
167
+ }
168
+ };
138
169
 
139
- if (accordion.length !== 0) {
140
- accordion.forEach(accordionToggle => {
141
- const accordionText = accordionToggle
142
- .querySelector('.sf-accordion-text')
143
- .textContent.split(' ').join('-').toLowerCase();
144
-
145
- if (typeof (urlHashList) !== 'undefined' && urlHashList.includes(accordionText)) {
146
- openParent(accordionToggle);
147
- accordionToggle.click();
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();
148
186
  }
149
187
  });
150
- }
188
+ });
151
189
  });
152
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
+ });
153
204
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leapdev/gui",
3
- "version": "0.2.239",
3
+ "version": "0.2.240",
4
4
  "description": "LEAP GUI",
5
5
  "author": "LEAP Dev",
6
6
  "license": "ISC",