musora-content-services 1.0.7 → 1.0.10

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +8 -1
  3. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  4. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  5. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  6. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  7. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  8. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  9. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  10. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  11. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  12. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  13. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  14. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  15. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  16. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  17. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  18. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  19. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  20. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  21. package/docs/global.html +1881 -1588
  22. package/docs/index.html +33 -10
  23. package/docs/index.js.html +304 -99
  24. package/docs/scripts/collapse.js +39 -0
  25. package/docs/scripts/commonNav.js +28 -0
  26. package/docs/scripts/nav.js +12 -0
  27. package/docs/scripts/polyfill.js +4 -0
  28. package/docs/scripts/search.js +99 -265
  29. package/docs/styles/jsdoc.css +776 -0
  30. package/docs/styles/prettify.css +80 -0
  31. package/jest.config.js +198 -0
  32. package/jsdoc.json +1 -1
  33. package/package.json +8 -5
  34. package/src/index.js +190 -49
  35. package/test/sanityQueryService.test.js +88 -0
@@ -0,0 +1,39 @@
1
+ function hideAllButCurrent(){
2
+ //by default all submenut items are hidden
3
+ //but we need to rehide them for search
4
+ document.querySelectorAll("nav > ul").forEach(function(parent) {
5
+ if (parent.className.indexOf("collapse_top") !== -1) {
6
+ parent.style.display = "none";
7
+ }
8
+ });
9
+ document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
10
+ parent.style.display = "none";
11
+ });
12
+ document.querySelectorAll("nav > h3").forEach(function(section) {
13
+ if (section.className.indexOf("collapsed_header") !== -1) {
14
+ section.addEventListener("click", function(){
15
+ if (section.nextSibling.style.display === "none") {
16
+ section.nextSibling.style.display = "block";
17
+ } else {
18
+ section.nextSibling.style.display = "none";
19
+ }
20
+ });
21
+ }
22
+ });
23
+
24
+ //only current page (if it exists) should be opened
25
+ var file = window.location.pathname.split("/").pop().replace(/\.html/, '');
26
+ document.querySelectorAll("nav > ul > li > a").forEach(function(parent) {
27
+ var href = parent.attributes.href.value.replace(/\.html/, '');
28
+ if (file === href) {
29
+ if (parent.parentNode.parentNode.className.indexOf("collapse_top") !== -1) {
30
+ parent.parentNode.parentNode.style.display = "block";
31
+ }
32
+ parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
33
+ elem.style.display = "block";
34
+ });
35
+ }
36
+ });
37
+ }
38
+
39
+ hideAllButCurrent();
@@ -0,0 +1,28 @@
1
+ if (typeof fetch === 'function') {
2
+ const init = () => {
3
+ if (typeof scrollToNavItem !== 'function') return false
4
+ scrollToNavItem()
5
+ // hideAllButCurrent not always loaded
6
+ if (typeof hideAllButCurrent === 'function') hideAllButCurrent()
7
+ return true
8
+ }
9
+ fetch('./nav.inc.html')
10
+ .then(response => response.ok ? response.text() : `${response.url} => ${response.status} ${response.statusText}`)
11
+ .then(body => {
12
+ document.querySelector('nav').innerHTML += body
13
+ // nav.js should be quicker to load than nav.inc.html, a fallback just in case
14
+ return init()
15
+ })
16
+ .then(done => {
17
+ if (done) return
18
+ let i = 0
19
+ ;(function waitUntilNavJs () {
20
+ if (init()) return
21
+ if (i++ < 100) return setTimeout(waitUntilNavJs, 300)
22
+ console.error(Error('nav.js not loaded after 30s waiting for it'))
23
+ })()
24
+ })
25
+ .catch(error => console.error(error))
26
+ } else {
27
+ console.error(Error('Browser too old to display commonNav (remove commonNav docdash option)'))
28
+ }
@@ -0,0 +1,12 @@
1
+ function scrollToNavItem() {
2
+ var path = window.location.href.split('/').pop().replace(/\.html/, '');
3
+ document.querySelectorAll('nav a').forEach(function(link) {
4
+ var href = link.attributes.href.value.replace(/\.html/, '');
5
+ if (path === href) {
6
+ link.scrollIntoView({block: 'center'});
7
+ return;
8
+ }
9
+ })
10
+ }
11
+
12
+ scrollToNavItem();
@@ -0,0 +1,4 @@
1
+ //IE Fix, src: https://www.reddit.com/r/programminghorror/comments/6abmcr/nodelist_lacks_foreach_in_internet_explorer/
2
+ if (typeof(NodeList.prototype.forEach)!==typeof(alert)){
3
+ NodeList.prototype.forEach=Array.prototype.forEach;
4
+ }
@@ -1,265 +1,99 @@
1
- /* global document */
2
-
3
- const searchId = 'LiBfqbJVcV';
4
- const searchHash = '#' + searchId;
5
- const searchContainer = document.querySelector('#PkfLWpAbet');
6
- const searchWrapper = document.querySelector('#iCxFxjkHbP');
7
- const searchCloseButton = document.querySelector('#VjLlGakifb');
8
- const searchInput = document.querySelector('#vpcKVYIppa');
9
- const resultBox = document.querySelector('#fWwVHRuDuN');
10
-
11
- function showResultText(text) {
12
- resultBox.innerHTML = `<span class="search-result-c-text">${text}</span>`;
13
- }
14
-
15
- function hideSearch() {
16
- // eslint-disable-next-line no-undef
17
- if (window.location.hash === searchHash) {
18
- // eslint-disable-next-line no-undef
19
- history.go(-1);
20
- }
21
-
22
- // eslint-disable-next-line no-undef
23
- window.onhashchange = null;
24
-
25
- if (searchContainer) {
26
- searchContainer.style.display = 'none';
27
- }
28
- }
29
-
30
- function listenCloseKey(event) {
31
- if (event.key === 'Escape') {
32
- hideSearch();
33
- // eslint-disable-next-line no-undef
34
- window.removeEventListener('keyup', listenCloseKey);
35
- }
36
- }
37
-
38
- function showSearch() {
39
- try {
40
- // Closing mobile menu before opening
41
- // search box.
42
- // It is defined in core.js
43
- // eslint-disable-next-line no-undef
44
- hideMobileMenu();
45
- } catch (error) {
46
- console.error(error);
47
- }
48
-
49
- // eslint-disable-next-line no-undef
50
- window.onhashchange = hideSearch;
51
-
52
- // eslint-disable-next-line no-undef
53
- if (window.location.hash !== searchHash) {
54
- // eslint-disable-next-line no-undef
55
- history.pushState(null, null, searchHash);
56
- }
57
-
58
- if (searchContainer) {
59
- searchContainer.style.display = 'flex';
60
- // eslint-disable-next-line no-undef
61
- window.addEventListener('keyup', listenCloseKey);
62
- }
63
-
64
- if (searchInput) {
65
- searchInput.focus();
66
- }
67
- }
68
-
69
- async function fetchAllData() {
70
- // eslint-disable-next-line no-undef
71
- const { hostname, protocol, port } = location;
72
-
73
- // eslint-disable-next-line no-undef
74
- const base = protocol + '//' + hostname + (port !== '' ? ':' + port : '') + baseURL;
75
- // eslint-disable-next-line no-undef
76
- const url = new URL('data/search.json', base);
77
- const result = await fetch(url);
78
- const { list } = await result.json();
79
-
80
- return list;
81
- }
82
-
83
- // eslint-disable-next-line no-unused-vars
84
- function onClickSearchItem(event) {
85
- const target = event.currentTarget;
86
-
87
- if (target) {
88
- const href = target.getAttribute('href') || '';
89
- let elementId = href.split('#')[1] || '';
90
- let element = document.getElementById(elementId);
91
-
92
- if (!element) {
93
- elementId = decodeURI(elementId);
94
- element = document.getElementById(elementId);
95
- }
96
-
97
- if (element) {
98
- setTimeout(function() {
99
- // eslint-disable-next-line no-undef
100
- bringElementIntoView(element); // defined in core.js
101
- }, 100);
102
- }
103
- }
104
- }
105
-
106
- function buildSearchResult(result) {
107
- let output = '';
108
- const removeHTMLTagsRegExp = /(<([^>]+)>)/ig;
109
-
110
- for (const res of result) {
111
- const { title = '', description = '' } = res.item;
112
-
113
- const _link = res.item.link.replace('<a href="', '').replace(/">.*/, '');
114
- const _title = title.replace(removeHTMLTagsRegExp, "");
115
- const _description = description.replace(removeHTMLTagsRegExp, "");
116
-
117
- output += `
118
- <a onclick="onClickSearchItem(event)" href="${_link}" class="search-result-item">
119
- <div class="search-result-item-title">${_title}</div>
120
- <div class="search-result-item-p">${_description || 'No description available.'}</div>
121
- </a>
122
- `;
123
- }
124
-
125
- return output;
126
- }
127
-
128
- function getSearchResult(list, keys, searchKey) {
129
- const defaultOptions = {
130
- shouldSort: true,
131
- threshold: 0.4,
132
- location: 0,
133
- distance: 100,
134
- maxPatternLength: 32,
135
- minMatchCharLength: 1,
136
- keys: keys
137
- };
138
-
139
- const options = { ...defaultOptions };
140
-
141
- // eslint-disable-next-line no-undef
142
- const searchIndex = Fuse.createIndex(options.keys, list);
143
-
144
- // eslint-disable-next-line no-undef
145
- const fuse = new Fuse(list, options, searchIndex);
146
-
147
- const result = fuse.search(searchKey);
148
-
149
- if (result.length > 20) {
150
- return result.slice(0, 20);
151
- }
152
-
153
- return result;
154
- }
155
-
156
- function debounce(func, wait, immediate) {
157
- let timeout;
158
-
159
- return function() {
160
- const args = arguments;
161
-
162
- clearTimeout(timeout);
163
- timeout = setTimeout(() => {
164
- timeout = null;
165
- if (!immediate) {
166
- // eslint-disable-next-line consistent-this, no-invalid-this
167
- func.apply(this, args);
168
- }
169
- }, wait);
170
-
171
- if (immediate && !timeout) {
172
- // eslint-disable-next-line consistent-this, no-invalid-this
173
- func.apply(this, args);
174
- }
175
- };
176
- }
177
-
178
- let searchData;
179
-
180
- async function search(event) {
181
- const value = event.target.value;
182
- const keys = ['title', 'description'];
183
-
184
- if (!resultBox) {
185
- console.error('Search result container not found');
186
-
187
- return;
188
- }
189
-
190
- if (!value) {
191
- showResultText('Type anything to view search result');
192
-
193
- return;
194
- }
195
-
196
- if (!searchData) {
197
- showResultText('Loading...');
198
-
199
- try {
200
- // eslint-disable-next-line require-atomic-updates
201
- searchData = await fetchAllData();
202
- } catch (e) {
203
- console.log(e);
204
- showResultText('Failed to load result.');
205
-
206
- return;
207
- }
208
- }
209
-
210
- const result = getSearchResult(searchData, keys, value);
211
-
212
- if (!result.length) {
213
- showResultText('No result found! Try some different combination.');
214
-
215
- return;
216
- }
217
-
218
- // eslint-disable-next-line require-atomic-updates
219
- resultBox.innerHTML = buildSearchResult(result);
220
- }
221
-
222
- function onDomContentLoaded() {
223
- const searchButton = document.querySelectorAll('.search-button');
224
- const debouncedSearch = debounce(search, 300);
225
-
226
- if (searchCloseButton) {
227
- searchCloseButton.addEventListener('click', hideSearch);
228
- }
229
-
230
- if (searchButton) {
231
- searchButton.forEach(function(item) {
232
- item.addEventListener('click', showSearch);
233
- });
234
- }
235
-
236
- if (searchContainer) {
237
- searchContainer.addEventListener('click', hideSearch);
238
- }
239
-
240
- if (searchWrapper) {
241
- searchWrapper.addEventListener('click', function(event) {
242
- event.stopPropagation();
243
- });
244
- }
245
-
246
- if (searchInput) {
247
- searchInput.addEventListener('keyup', debouncedSearch);
248
- }
249
-
250
- // eslint-disable-next-line no-undef
251
- if (window.location.hash === searchHash) {
252
- showSearch();
253
- }
254
- }
255
-
256
- // eslint-disable-next-line no-undef
257
- window.addEventListener('DOMContentLoaded', onDomContentLoaded);
258
-
259
- // eslint-disable-next-line no-undef
260
- window.addEventListener('hashchange', function() {
261
- // eslint-disable-next-line no-undef
262
- if (window.location.hash === searchHash) {
263
- showSearch();
264
- }
265
- });
1
+
2
+ var searchAttr = 'data-search-mode';
3
+ function contains(a,m){
4
+ return (a.textContent || a.innerText || "").toUpperCase().indexOf(m) !== -1;
5
+ };
6
+
7
+ //on search
8
+ document.getElementById("nav-search").addEventListener("keyup", function(event) {
9
+ var search = this.value.toUpperCase();
10
+
11
+ if (!search) {
12
+ //no search, show all results
13
+ document.documentElement.removeAttribute(searchAttr);
14
+
15
+ document.querySelectorAll("nav > ul > li:not(.level-hide)").forEach(function(elem) {
16
+ elem.style.display = "block";
17
+ });
18
+
19
+ if (typeof hideAllButCurrent === "function"){
20
+ //let's do what ever collapse wants to do
21
+ hideAllButCurrent();
22
+ } else {
23
+ //menu by default should be opened
24
+ document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) {
25
+ elem.style.display = "block";
26
+ });
27
+ }
28
+ } else {
29
+ //we are searching
30
+ document.documentElement.setAttribute(searchAttr, '');
31
+
32
+ //show all parents
33
+ document.querySelectorAll("nav > ul > li").forEach(function(elem) {
34
+ elem.style.display = "block";
35
+ });
36
+ document.querySelectorAll("nav > ul").forEach(function(elem) {
37
+ elem.style.display = "block";
38
+ });
39
+ //hide all results
40
+ document.querySelectorAll("nav > ul > li > ul li").forEach(function(elem) {
41
+ elem.style.display = "none";
42
+ });
43
+ //show results matching filter
44
+ document.querySelectorAll("nav > ul > li > ul a").forEach(function(elem) {
45
+ if (!contains(elem.parentNode, search)) {
46
+ return;
47
+ }
48
+ elem.parentNode.style.display = "block";
49
+ });
50
+ //hide parents without children
51
+ document.querySelectorAll("nav > ul > li").forEach(function(parent) {
52
+ var countSearchA = 0;
53
+ parent.querySelectorAll("a").forEach(function(elem) {
54
+ if (contains(elem, search)) {
55
+ countSearchA++;
56
+ }
57
+ });
58
+
59
+ var countUl = 0;
60
+ var countUlVisible = 0;
61
+ parent.querySelectorAll("ul").forEach(function(ulP) {
62
+ // count all elements that match the search
63
+ if (contains(ulP, search)) {
64
+ countUl++;
65
+ }
66
+
67
+ // count all visible elements
68
+ var children = ulP.children
69
+ for (i=0; i<children.length; i++) {
70
+ var elem = children[i];
71
+ if (elem.style.display != "none") {
72
+ countUlVisible++;
73
+ }
74
+ }
75
+ });
76
+
77
+ if (countSearchA == 0 && countUl === 0){
78
+ //has no child at all and does not contain text
79
+ parent.style.display = "none";
80
+ } else if(countSearchA == 0 && countUlVisible == 0){
81
+ //has no visible child and does not contain text
82
+ parent.style.display = "none";
83
+ }
84
+ });
85
+ document.querySelectorAll("nav > ul.collapse_top").forEach(function(parent) {
86
+ var countVisible = 0;
87
+ parent.querySelectorAll("li").forEach(function(elem) {
88
+ if (elem.style.display !== "none") {
89
+ countVisible++;
90
+ }
91
+ });
92
+
93
+ if (countVisible == 0) {
94
+ //has no child at all and does not contain text
95
+ parent.style.display = "none";
96
+ }
97
+ });
98
+ }
99
+ });