hdoc-tools 0.13.0 → 0.14.1

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.
@@ -5,133 +5,116 @@
5
5
  var jqContentContainer = null;
6
6
  var jqDocumentHeader = null;
7
7
  var jqLeftNav = null;
8
- var global = {stateParams:{},lastLayoutClass:""};
8
+ var global = { stateParams: {}, lastLayoutClass: "" };
9
9
 
10
10
  var docAppMethods = {
11
- setSessionInfo:function(info)
12
- {
11
+ setSessionInfo: function (info) {
13
12
  let self = this;
14
13
  self.docApp.userSession = info;
15
14
  },
16
- switchViewTheme:function()
17
- {
18
- if(ThemePreference)document.documentElement.classList.remove(ThemePreference);
15
+ switchViewTheme: function () {
16
+ if (ThemePreference) document.documentElement.classList.remove(ThemePreference);
19
17
 
20
- if(ThemePreference === 'dark')
21
- {
18
+ if (ThemePreference === 'dark') {
22
19
  ThemePreference = 'light';
23
20
  }
24
- else{
21
+ else {
25
22
  ThemePreference = 'dark';
26
23
  }
27
24
 
28
- localStorage.setItem('hdocbook-theme-appearance',ThemePreference);
25
+ localStorage.setItem('hdocbook-theme-appearance', ThemePreference);
29
26
  document.documentElement.classList.add(ThemePreference);
30
27
  },
31
- renderNavigation:function()
32
- {
28
+ renderNavigation: function () {
33
29
  let self = this;
34
30
  self.docApp.navSections = self.docApp.book.navigation.items; //-- show be an array of nav groups
31
+
35
32
  },
36
- toggleMobileMenu:function()
37
- {
33
+ toggleMobileMenu: function () {
38
34
  let isOpen = $(".mobile-menu-btn").data("isopen");
39
- if(isOpen)
40
- {
35
+ if (isOpen) {
41
36
  $(".DocSidebar").removeClass("open");
42
37
  }
43
- else
44
- {
38
+ else {
45
39
  $(".DocSidebar").addClass("open");
46
40
  }
47
41
  //-- store new mode
48
- $(".mobile-menu-btn").data("isopen",!isOpen);
42
+ $(".mobile-menu-btn").data("isopen", !isOpen);
49
43
  },
50
- resetMobileMenu:function(ev)
51
- {
52
- if( ev && ($(ev.srcElement).hasClass("mobile-menu-btn")[0] || $(ev.srcElement).closest(".mobile-menu-btn")[0]) )
53
- {
44
+ resetMobileMenu: function (ev) {
45
+ if (ev && ($(ev.srcElement).hasClass("mobile-menu-btn")[0] || $(ev.srcElement).closest(".mobile-menu-btn")[0])) {
54
46
  //-- skp as have clikc no menu btn
55
47
  }
56
- else
57
- {
58
- $(".mobile-menu-btn").data("isopen",false);
48
+ else {
49
+ $(".mobile-menu-btn").data("isopen", false);
59
50
  $(".DocSidebar").removeClass("open");
60
51
  }
61
52
  }
62
-
53
+
63
54
  };
64
55
 
65
-
66
- //--
67
- //-- user clicked back or forwards
68
- window.addEventListener('popstate', function (event)
69
- {
56
+
57
+ //--
58
+ //-- user clicked back or forwards
59
+ window.addEventListener('popstate', function (event) {
70
60
  const loadUrl = new URL(event.target.location.href);
71
- loadContentUrl(loadUrl.pathname + loadUrl.hash,{},false,true);
61
+ loadContentUrl(loadUrl.pathname + loadUrl.hash, {}, false, true);
72
62
  });
73
63
 
74
64
 
75
65
  //--- GLOBAL FUNCTIONS
76
66
  function removeTrailingSlash(str) {
77
67
  return str.endsWith('/') ? str.slice(0, -1) : str;
78
- }
68
+ }
79
69
  function removeStartingSlash(str) {
80
70
  return str.startsWith('/') ? str.slice(1, str.length) : str;
81
71
 
82
72
  //if(linkRef.indexOf("/")===0)linkRef = linkRef.replace("/","");
83
- }
73
+ }
84
74
 
85
75
  function toSeoUrl(url) {
86
76
  return url.toString() // Convert to string
87
77
  .normalize('NFD') // Change diacritics
88
- .replace(/[\u0300-\u036f]/g,'') // Remove illegal characters
89
- .replace(/\s+/g,'-') // Change whitespace to dashes
78
+ .replace(/[\u0300-\u036f]/g, '') // Remove illegal characters
79
+ .replace(/\s+/g, '-') // Change whitespace to dashes
90
80
  .toLowerCase() // Change to lowercase
91
- .replace(/&/g,'-and-') // Replace ampersand
92
- .replace(/[^a-z0-9\-]/g,'') // Remove anything that is not a letter, number or dash
93
- .replace(/-+/g,'-') // Remove duplicate dashes
94
- .replace(/^-*/,'') // Remove starting dashes
95
- .replace(/-*$/,''); // Remove trailing dashes
81
+ .replace(/&/g, '-and-') // Replace ampersand
82
+ .replace(/[^a-z0-9\-]/g, '') // Remove anything that is not a letter, number or dash
83
+ .replace(/-+/g, '-') // Remove duplicate dashes
84
+ .replace(/^-*/, '') // Remove starting dashes
85
+ .replace(/-*$/, ''); // Remove trailing dashes
96
86
  }
97
87
 
98
- function listenForHrefClicks()
99
- {
88
+ function listenForHrefClicks() {
100
89
  //-- trap all link click events - we want to handle links so can cancel and load content ourselves
101
- $("A").off("click").on("click", function(ev)
102
- {
103
- let ele = this;
104
- if(ele.href)
105
- {
90
+ $("A").off("click").on("click", function (ev) {
91
+ let ele = this;
92
+ if (ele.href) {
106
93
  const checkUrl = new URL(ele.href);
107
94
 
108
95
  view.resetMobileMenu();
109
96
 
110
97
  //-- clicking on a hash tag header link element - so jsut scroll to element
111
- if(checkUrl.origin +"/"===siteBaseLocation)
112
- {
98
+ if (checkUrl.origin + "/" === siteBaseLocation) {
113
99
  //-- if a url that is part of this doc site then handle loading content inline else let link do whatever (i.e. its an external link)
114
100
  ev.stopImmediatePropagation();
115
- ev.preventDefault();
101
+ ev.preventDefault();
116
102
 
117
103
  //-- do we need to scroll into view element on this page
118
- if(checkUrl.hash && getAnchorFromHash(checkUrl.hash,"faq-toc-item"))
119
- {
120
- let eleAnc = getAnchorFromHash(checkUrl.hash,"faq-toc-item");
121
- if(eleAnc[0] && eleAnc[0].scrollIntoView)scrollIntoView[0].scrollIntoView();
122
-
123
- if(ele.href!==document.location.href) window.history.pushState(null, null, ele.href); //-- user has clicked a link so we want to add state to history so we can click back
104
+ if (checkUrl.hash && getAnchorFromHash(checkUrl.hash, "faq-toc-item")) {
105
+ let eleAnc = getAnchorFromHash(checkUrl.hash, "faq-toc-item");
106
+ if (eleAnc[0] && eleAnc[0].scrollIntoView) scrollIntoView[0].scrollIntoView();
107
+
108
+ if (ele.href !== document.location.href) window.history.pushState(null, null, ele.href); //-- user has clicked a link so we want to add state to history so we can click back
124
109
  }
125
- else
126
- {
127
- loadContentUrl(ele.getAttribute("href"),false,false);
110
+ else {
111
+ loadContentUrl(ele.getAttribute("href"), false, false);
128
112
  }
129
113
  return false;
130
114
  }
131
- else
132
- {
115
+ else {
133
116
  //-- if not part of this website then always open in new tab as considered an external site
134
- ele.setAttribute("target","_blank");
117
+ ele.setAttribute("target", "_blank");
135
118
  }
136
119
  }
137
120
  });
@@ -140,45 +123,38 @@ function listenForHrefClicks()
140
123
 
141
124
  //-- based on content url highlight match navigation menu item
142
125
  //-- based on content url highlight match navigation menu item
143
- function highlightNavigationLinkFromUrl(matchLinkHref)
144
- {
145
-
126
+ function highlightNavigationLinkFromUrl(matchLinkHref) {
127
+
146
128
  matchLinkHref = removeStartingSlash(matchLinkHref).split("#")[0]; //-- remvoe # link
147
129
  $('a.DocLink').removeClass("active");
148
-
130
+
149
131
  let arrItems = document.querySelectorAll('a.DocLink');
150
-
151
- for(let x=0;x<arrItems.length;x++)
152
- {
132
+
133
+ for (let x = 0; x < arrItems.length; x++) {
153
134
  let checkUrl = null;
154
- try{
135
+ try {
155
136
  checkUrl = new URL(el.href);
156
137
  }
157
- catch(e)
158
- {
138
+ catch (e) {
159
139
  //hslDocLog.log("BAD navigation menu item found",el);
160
140
  }
161
141
 
162
- if(checkUrl)
163
- {
142
+ if (checkUrl) {
164
143
  //hslDocLog.log(checkUrl.pathname,matchLinkHref)
165
144
  let testCurrPath = removeStartingSlash(checkUrl.pathname);
166
- if(testCurrPath===matchLinkHref)
167
- {
145
+ if (testCurrPath === matchLinkHref) {
168
146
  //-- exact match
169
147
  $(el).addClass("active")
170
148
  el.scrollIntoView();
171
149
  return false;//break out
172
150
  }
173
- else if(testCurrPath.indexOf(matchLinkHref)===0)
174
- {
151
+ else if (testCurrPath.indexOf(matchLinkHref) === 0) {
175
152
  //--
176
153
  $(el).addClass("active")
177
154
  el.scrollIntoView();
178
155
  return false;//break out
179
156
  }
180
- else if(matchLinkHref.indexOf(removeStartingSlash(checkUrl.pathname) + "/")===0)
181
- {
157
+ else if (matchLinkHref.indexOf(removeStartingSlash(checkUrl.pathname) + "/") === 0) {
182
158
  $(el).addClass("active");
183
159
  el.scrollIntoView();
184
160
  return false;//break out
@@ -187,25 +163,21 @@ function highlightNavigationLinkFromUrl(matchLinkHref)
187
163
  }
188
164
  }
189
165
 
190
- function getAnchorFromHash(strHash,strHasClass)
191
- {
192
- try{
193
- let strSelector = toSeoUrl(strHash.replace("#",""));
194
- if(strHasClass)strSelector += "." + strHasClass;
166
+ function getAnchorFromHash(strHash, strHasClass) {
167
+ try {
168
+ let strSelector = toSeoUrl(strHash.replace("#", ""));
169
+ if (strHasClass) strSelector += "." + strHasClass;
195
170
 
196
- let jqEle = $("#"+strSelector);
197
- if(jqEle[0])
198
- {
171
+ let jqEle = $("#" + strSelector);
172
+ if (jqEle[0]) {
199
173
  return jqEle;
200
174
  }
201
- else
202
- {
175
+ else {
203
176
  return null;
204
177
  }
205
178
  }
206
- catch(e)
207
- {
208
- hslDocLog.log("Get document anchor element by hash failed ["+strHash+"]",e);
179
+ catch (e) {
180
+ hslDocLog.log("Get document anchor element by hash failed [" + strHash + "]", e);
209
181
  return null;
210
182
  }
211
183
 
@@ -214,55 +186,47 @@ function getAnchorFromHash(strHash,strHasClass)
214
186
 
215
187
  //-- create items to stick in toc from current loaded content
216
188
  //-- searches for H2,H3
217
- function generateTableOfContentsFromDoc()
218
- {
189
+ function generateTableOfContentsFromDoc() {
219
190
  let container = jqContentContainer[0];
220
- if(container)
221
- {
191
+ if (container) {
222
192
  const currUrl = new URL(document.location.href);
223
193
  view.docApp.tableOfContents = [];
224
- for (let i=2; i<=3; i++)
225
- {
226
- let headers = container.getElementsByTagName("h"+i);
227
- for (let j=0; j<headers.length; j++)
228
- {
194
+ for (let i = 2; i <= 3; i++) {
195
+ let headers = container.getElementsByTagName("h" + i);
196
+ for (let j = 0; j < headers.length; j++) {
229
197
  let jqCurrHeader = $(headers[j]);
230
198
  //-- only process headers that do not have this class
231
- if(!jqCurrHeader.hasClass("no-auto-anchor")) jqCurrHeader.addClass("faq-toc-item");
199
+ if (!jqCurrHeader.hasClass("no-auto-anchor")) jqCurrHeader.addClass("faq-toc-item");
232
200
  }
233
201
  }
234
202
 
235
203
  var headersTocItem = container.getElementsByClassName("faq-toc-item");
236
- for (let k = 0; k < headersTocItem.length; k++)
237
- {
204
+ for (let k = 0; k < headersTocItem.length; k++) {
238
205
  let item = headersTocItem[k];
239
206
  let strLabel = $.trim(item.innerText);
240
- if(strLabel)
241
- {
207
+ if (strLabel) {
242
208
  let seoSafeId = toSeoUrl(strLabel); //-- will use SEO to set in url so can scroll to element from url
243
- let linkUrl = currUrl.pathname + "#" + seoSafeId;
209
+ let linkUrl = currUrl.pathname + "#" + seoSafeId;
244
210
  item.id = seoSafeId;
245
211
 
246
- view.docApp.tableOfContents.push({ele:item,eleText:strLabel,tagName:item.tagName,href:linkUrl});
212
+ view.docApp.tableOfContents.push({ ele: item, eleText: strLabel, tagName: item.tagName, href: linkUrl });
247
213
 
248
214
  //-- add link icon to header (using seo id)
249
215
  $(item).append("<a class='header-anchor'><i class='bi bi-link'></i></a>");
250
- $(item).find("a").attr("href",linkUrl);
251
-
216
+ $(item).find("a").attr("href", linkUrl);
217
+
252
218
  }
253
219
  }
254
220
  }
255
221
  }
256
222
 
257
223
 
258
- function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
259
- {
224
+ function loadContentUrl(linkRef, fromPageRefresh, fromPopState) {
260
225
  //-- clear table of contents
261
226
  view.docApp.tableOfContents = [];
262
227
 
263
- if(linkRef.indexOf(window.location.origin +"/")===0)
264
- {
265
- linkRef = linkRef.replace(window.location.origin +"/","");
228
+ if (linkRef.indexOf(window.location.origin + "/") === 0) {
229
+ linkRef = linkRef.replace(window.location.origin + "/", "");
266
230
  }
267
231
 
268
232
  //-- remove trailing / if has one
@@ -271,7 +235,7 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
271
235
  linkRef = removeStartingSlash(linkRef);
272
236
 
273
237
  //-- update url in browser
274
- setBrowserViewUrl(linkRef,{},fromPageRefresh,fromPopState);
238
+ setBrowserViewUrl(linkRef, {}, fromPageRefresh, fromPopState);
275
239
 
276
240
  //-- destroy any existing content children and events properly
277
241
  jqContentContainer.empty();
@@ -279,53 +243,47 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
279
243
 
280
244
  //-- for now just load whatever the href prop is (we can add actions to perform specific processing and then load content based on element atts etc)
281
245
  let frontmatterData = {};
282
- let booksLinkRef = linkRef.includes('_books/') ? linkRef : "_books/"+linkRef;
283
- fetch(booksLinkRef).then(response =>
284
- {
285
- if(response.headers.has("X-frontmatter"))
286
- {
246
+ let booksLinkRef = linkRef.includes('_books/') ? linkRef : "_books/" + linkRef;
247
+ fetch(booksLinkRef).then(response => {
248
+ if (response.headers.has("X-frontmatter")) {
287
249
  frontmatterData = response.headers.get("X-frontmatter");
288
250
  frontmatterData = JSON.parse(atob(frontmatterData));
289
251
  }
290
252
  return response.text();
291
- }).then(html =>
292
- {
253
+ }).then(html => {
293
254
  jqContentContainer.html(html);
294
255
 
295
256
  //-- remove previous layoutclass if have one
296
- if(global.lastLayoutClass)
297
- {
257
+ if (global.lastLayoutClass) {
298
258
  $("#DocContent").removeClass(global.lastLayoutClass);
299
259
  global.lastLayoutClass = "";
300
260
  }
301
261
 
302
262
  //-- if have layoutclass add it to content container - this is so we can specify table list view sizes etc
303
- if(frontmatterData.layout)
304
- {
263
+ if (frontmatterData.layout) {
305
264
  $("#DocContent").addClass(frontmatterData.layout);
306
265
  global.lastLayoutClass = frontmatterData.layout;
307
266
  }
308
267
 
309
268
  //--generate toc for all layouts that have h2/h3
310
269
  view.docApp.keepTocLayout = (frontmatterData.layout == "article-no-toc");
311
- if(!frontmatterData.layout || frontmatterData.layout==="article" || frontmatterData.layout==="article-toc")
312
- {
270
+ if (!frontmatterData.layout || frontmatterData.layout === "article" || frontmatterData.layout === "article-toc") {
313
271
  view.docApp.keepTocLayout = true;
314
272
  generateTableOfContentsFromDoc();
315
273
  }
316
274
 
317
275
  //-- find any <tabs> and andd a bootstrap tab item strip
318
- $("#DocContent").find('tabs').each((idx,el) => {
276
+ $("#DocContent").find('tabs').each((idx, el) => {
319
277
  let tabClass = el.getAttribute("tabstyle");
320
278
  let tabMarkup = "<ul class='nav nav-tabs'>";
321
279
  //-- for each tab we need to create a tab link
322
- $(el).find("tab").each((idx,aTab) => {
280
+ $(el).find("tab").each((idx, aTab) => {
323
281
 
324
- let activeClass=(idx===0)?" active":"";
282
+ let activeClass = (idx === 0) ? " active" : "";
325
283
  tabMarkup += `<li class='nav-item c-pointer' contentidx='${idx}'><span class='nav-link${activeClass}'>${aTab.getAttribute("name")}</span></li>`;
326
284
 
327
285
  //-- hide the tab element if it is not the active one (first)
328
- if(idx>0)$(aTab).addClass("d-none");
286
+ if (idx > 0) $(aTab).addClass("d-none");
329
287
 
330
288
  });
331
289
 
@@ -334,36 +292,33 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
334
292
  $(el).prepend(tabMarkup).find(".nav.nav-tabs").addClass(tabClass);
335
293
 
336
294
  //-- add event handler for switching tab items
337
- $(el).find("li").off("click").on("click",function()
338
- {
295
+ $(el).find("li").off("click").on("click", function () {
339
296
  let contentIdx = this.getAttribute('contentidx');
340
297
  let tabsContainer = $(this).closest("tabs").eq(0);
341
- let tabs= tabsContainer.find("tab");
342
-
298
+ let tabs = tabsContainer.find("tab");
299
+
343
300
  //-- hide other tab content and show this tabs content
344
301
  tabs.addClass("d-none");
345
- tabs.eq(contentIdx-0).removeClass("d-none");
302
+ tabs.eq(contentIdx - 0).removeClass("d-none");
346
303
 
347
304
  //-- set clicked tab item to active
348
305
  tabsContainer.find(".nav-link").removeClass("active");
349
306
  $(this).find(".nav-link").addClass("active");
350
-
307
+
351
308
  });
352
309
  });
353
310
 
354
311
 
355
312
  //-- do any code highlighting
356
- if(hljs)
357
- {
313
+ if (hljs) {
358
314
  document.querySelectorAll('pre code').forEach((el) => {
359
315
  hljs.highlightBlock(el);
360
316
  });
361
317
  }
362
- else
363
- {
318
+ else {
364
319
  hslDocLog.log("code highlighting js could not be loaded. code block highlighting will not be enabled");
365
320
  }
366
-
321
+
367
322
  //-- show copy button by any code blocks
368
323
  var options = {
369
324
  contentSelector: ".injected-document-content",
@@ -371,7 +326,7 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
371
326
  // Use if you need to time highlighting and badge application
372
327
  // since the badges need to be applied afterwards.
373
328
  // 0 - direct execution (ie. you handle timing
374
- loadDelay:0,
329
+ loadDelay: 0,
375
330
 
376
331
  // CSS class(es) used to render the copy icon.
377
332
  copyIconClass: "bi bi-clipboard",
@@ -379,7 +334,7 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
379
334
  checkIconClass: "bi bi-clipboard-check --htl-c-brand",
380
335
 
381
336
  // intercept text copying - passed in text return text out
382
- onBeforeCodeCopied: function(text) {
337
+ onBeforeCodeCopied: function (text) {
383
338
  return text;
384
339
  }
385
340
  };
@@ -388,27 +343,24 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
388
343
 
389
344
  //-- get first H1 and put it into our header section header
390
345
  let docHeader = jqContentContainer.find("H1").eq(0)
391
- jqDocumentHeader.find(".document-title").append( docHeader );
346
+ jqDocumentHeader.find(".document-title").append(docHeader);
392
347
 
393
348
 
394
349
  setGitHubBookUrl(linkRef);
395
350
 
396
351
 
397
352
  //-- make sure selected link parents are set to .expand=true
398
- if(expandNavParentSectionBySelectedLinkHref(linkRef))
399
- {
353
+ if (expandNavParentSectionBySelectedLinkHref(linkRef)) {
400
354
  view.updateCounter++;
401
- view.$nextTick(function()
402
- {
355
+ view.$nextTick(function () {
403
356
  //-- find any navigation links that match url and highlight
404
- // listenForHrefClicks();
405
- highlightNavigationLinkFromUrl(linkRef);
357
+ // listenForHrefClicks();
358
+ highlightNavigationLinkFromUrl(linkRef);
406
359
 
407
360
  //-- scroll to element that match hash (if have one)
408
- if(document.location.hash)
409
- {
410
- let gotoEle = getAnchorFromHash(document.location.hash) ;
411
- if(gotoEle)gotoEle[0].scrollIntoView();
361
+ if (document.location.hash) {
362
+ let gotoEle = getAnchorFromHash(document.location.hash);
363
+ if (gotoEle) gotoEle[0].scrollIntoView();
412
364
  }
413
365
  });
414
366
  view.$forceUpdate();
@@ -418,76 +370,60 @@ function loadContentUrl(linkRef,fromPageRefresh,fromPopState)
418
370
  });
419
371
  }
420
372
 
421
- function setGitHubBookUrl(linkRef)
422
- {
373
+ function setGitHubBookUrl(linkRef) {
423
374
  let bookRef = linkRef.split(siteBaseLocation);
424
- bookRef = (bookRef[1])?bookRef[1]:bookRef[0];
375
+ bookRef = (bookRef[1]) ? bookRef[1] : bookRef[0];
425
376
  let bookId = bookRef.split("/")[0];
426
377
  view.docApp.documentGithubUrl = "https://github.com/Hornbill-Docs/" + bookId + "/blob/main/" + bookRef + ".md";
427
378
  //--https://github.com/Hornbill-Docs/hdoc-guide/blob/main/hdoc-guide/overview.md
428
379
  }
429
380
 
430
- function loadBookDefaultLink()
431
- {
381
+ function loadBookDefaultLink() {
432
382
  $(".DocLink.link").first().click();
433
383
  }
434
384
 
435
- function findFirstClickableBookLink(findByLinkRef,currentNavSection)
436
- {
437
- if(currentNavSection === undefined)
385
+ function findFirstClickableBookLink(findByLinkRef, currentNavSection) {
386
+ if (currentNavSection === undefined)
438
387
  currentNavSection = view.docApp.navSections;
439
388
 
440
389
 
441
- for(let x=0;x<currentNavSection.length;x++)
442
- {
443
- if(currentNavSection[x].items)
444
- {
445
- let clickableItem = findFirstClickableBookLink(findByLinkRef,currentNavSection[x].items);
446
- if(clickableItem)
447
- {
390
+ for (let x = 0; x < currentNavSection.length; x++) {
391
+ if (currentNavSection[x].items) {
392
+ let clickableItem = findFirstClickableBookLink(findByLinkRef, currentNavSection[x].items);
393
+ if (clickableItem) {
448
394
  return clickableItem;
449
395
  }
450
396
  }
451
- else if(currentNavSection[x].link)
452
- {
453
- if(findByLinkRef)
454
- {
455
- if(removeStartingSlash(removeTrailingSlash(currentNavSection[x].link)) == findByLinkRef) return currentNavSection[x].link;
397
+ else if (currentNavSection[x].link) {
398
+ if (findByLinkRef) {
399
+ if (removeStartingSlash(removeTrailingSlash(currentNavSection[x].link)) == findByLinkRef) return currentNavSection[x].link;
456
400
  }
457
- else
458
- {
401
+ else {
459
402
  return currentNavSection[x].link;
460
403
  }
461
404
  }
462
- }
405
+ }
463
406
  }
464
407
 
465
- function expandNavParentSectionBySelectedLinkHref(findByLinkRef, currentNavSection)
466
- {
408
+ function expandNavParentSectionBySelectedLinkHref(findByLinkRef, currentNavSection) {
467
409
  findByLinkRef = findByLinkRef.split("#")[0];
468
- if(currentNavSection === undefined)
469
- {
410
+ if (currentNavSection === undefined) {
470
411
  view.docApp.bookBreadCrumb = []; //-- reset bread crumb
471
412
  currentNavSection = view.docApp.navSections;
472
413
  }
473
-
474
- for(let x=0;x<currentNavSection.length;x++)
475
- {
476
- if(currentNavSection[x].items)
477
- {
478
- let res = expandNavParentSectionBySelectedLinkHref(findByLinkRef,currentNavSection[x].items);
479
- if(res)
480
- {
481
- currentNavSection[x].expand=true;
482
- view.docApp.bookBreadCrumb.unshift({title:currentNavSection[x].text,link:currentNavSection[x].items[0].link});
414
+
415
+ for (let x = 0; x < currentNavSection.length; x++) {
416
+ if (currentNavSection[x].items) {
417
+ let res = expandNavParentSectionBySelectedLinkHref(findByLinkRef, currentNavSection[x].items);
418
+ if (res) {
419
+ currentNavSection[x].expand = true;
420
+ view.docApp.bookBreadCrumb.unshift({ title: currentNavSection[x].text, link: currentNavSection[x].items[0].link });
483
421
  return res;
484
422
  }
485
423
  }
486
- else
487
- {
424
+ else {
488
425
  //-- check item to see if it matches url
489
- if(removeStartingSlash(removeTrailingSlash(currentNavSection[x].link)) == findByLinkRef)
490
- {
426
+ if (removeStartingSlash(removeTrailingSlash(currentNavSection[x].link)) == findByLinkRef) {
491
427
  return true;
492
428
  }
493
429
  }
@@ -496,29 +432,23 @@ function expandNavParentSectionBySelectedLinkHref(findByLinkRef, currentNavSecti
496
432
  }
497
433
 
498
434
 
499
- function old_expandNavParentSectionBySelectedLinkHref(findByLinkRef, currentNavSection)
500
- {
435
+ function old_expandNavParentSectionBySelectedLinkHref(findByLinkRef, currentNavSection) {
501
436
  findByLinkRef = findByLinkRef.split("#")[0];
502
- if(currentNavSection === undefined)
437
+ if (currentNavSection === undefined)
503
438
  currentNavSection = view.docApp.navSections;
504
439
 
505
440
 
506
- for(let x=0;x<currentNavSection.length;x++)
507
- {
508
- if(currentNavSection[x].items)
509
- {
510
- let res = expandNavParentSectionBySelectedLinkHref(findByLinkRef,currentNavSection[x].items);
511
- if(res)
512
- {
513
- currentNavSection[x].expand=true;
441
+ for (let x = 0; x < currentNavSection.length; x++) {
442
+ if (currentNavSection[x].items) {
443
+ let res = expandNavParentSectionBySelectedLinkHref(findByLinkRef, currentNavSection[x].items);
444
+ if (res) {
445
+ currentNavSection[x].expand = true;
514
446
  return res;
515
447
  }
516
448
  }
517
- else
518
- {
449
+ else {
519
450
  //-- check item to see if it matches url
520
- if(removeStartingSlash(removeTrailingSlash(currentNavSection[x].link)) == findByLinkRef)
521
- {
451
+ if (removeStartingSlash(removeTrailingSlash(currentNavSection[x].link)) == findByLinkRef) {
522
452
  return true;
523
453
  }
524
454
  }
@@ -526,106 +456,91 @@ function old_expandNavParentSectionBySelectedLinkHref(findByLinkRef, currentNavS
526
456
 
527
457
  }
528
458
 
529
- function setBrowserViewUrl(strHrefToLoad,viewData,fromPageRefresh,fromPopState)
530
- {
531
-
532
- let urlToSet = window.location.origin + "/" + strHrefToLoad;
533
- const url = new URL(urlToSet);
534
-
535
- //-- remove any old params
536
- for(let strKey in global.stateParams)
537
- {
538
- url.searchParams.delete(strKey);
539
- }
540
-
541
- //-- now set new data params in url
542
- for(let strKey in viewData)
543
- {
544
- url.searchParams.set(strKey,viewData[strKey]);
545
- }
546
-
547
- //-- store global params
548
- global.stateParams = viewData;
549
-
550
- if(!fromPopState)
551
- {
552
- if(fromPageRefresh)
553
- {
554
- window.history.replaceState(null, null, url); //-- user has refreshed page or jsut visited page
555
- }
556
- else
557
- {
558
- window.history.pushState(null, null, url); //-- user has clicked a link so we want to add state to history so we can click back
559
- }
560
- }
459
+ function setBrowserViewUrl(strHrefToLoad, viewData, fromPageRefresh, fromPopState) {
460
+
461
+ let urlToSet = window.location.origin + "/" + strHrefToLoad;
462
+ const url = new URL(urlToSet);
463
+
464
+ //-- remove any old params
465
+ for (let strKey in global.stateParams) {
466
+ url.searchParams.delete(strKey);
467
+ }
468
+
469
+ //-- now set new data params in url
470
+ for (let strKey in viewData) {
471
+ url.searchParams.set(strKey, viewData[strKey]);
472
+ }
473
+
474
+ //-- store global params
475
+ global.stateParams = viewData;
476
+
477
+ if (!fromPopState) {
478
+ if (fromPageRefresh) {
479
+ window.history.replaceState(null, null, url); //-- user has refreshed page or jsut visited page
480
+ }
481
+ else {
482
+ window.history.pushState(null, null, url); //-- user has clicked a link so we want to add state to history so we can click back
483
+ }
484
+ }
561
485
 
562
486
  }
563
487
 
564
- async function fetchContentFile(strFilePath)
565
- {
566
- return await fetch(strFilePath).then(response => response.text()).then(fileContent =>
567
- {
568
- return fileContent;
569
- });
488
+ async function fetchContentFile(strFilePath) {
489
+ return await fetch(strFilePath).then(response => response.text()).then(fileContent => {
490
+ return fileContent;
491
+ });
570
492
  }
571
493
 
572
- async function fetchJsonFile(strFilePath)
573
- {
574
- return await fetch(strFilePath).then(response => response.json()).then(jsonObject =>
575
- {
576
- return jsonObject;
577
- });
494
+ async function fetchJsonFile(strFilePath) {
495
+ return await fetch(strFilePath).then(response => response.json()).then(jsonObject => {
496
+ return jsonObject;
497
+ });
578
498
  }
579
499
 
580
500
 
581
501
  //-- THE INIT APP CALLED FROM index.html
582
- $(".document-body").attr("v-pre","");
502
+ $(".document-body").attr("v-pre", "");
583
503
 
584
504
  var view = new Vue({
585
505
  el: '#vDocDevApp',
586
- data: {userSession:{},updateCounter:0,bookId:"", docApp:{keepTocLayout:false,book:{},navSections:[],tableOfContents:[],bookBreadCrumb:[]}},
587
- methods:docAppMethods,
506
+ data: { userSession: {}, updateCounter: 0, bookId: "", docApp: { keepTocLayout: false, book: {}, navSections: [], tableOfContents: [], bookBreadCrumb: [] } },
507
+ methods: docAppMethods,
588
508
  directives: {
589
- somedirectivename: {
590
- bind (el, binding, vnode) {
509
+ somedirectivename: {
510
+ bind(el, binding, vnode) {
591
511
  //-- do something when created on element
592
512
  }
593
513
  }
594
- } ,
595
- mounted:function()
596
- {
514
+ },
515
+ mounted: function () {
597
516
 
598
- }
517
+ }
599
518
  });
600
519
 
601
520
  //-- repeatable conmponent for nav sections
602
521
  Vue.component('nav-section-component', {
603
522
  props: ['asection'],
604
523
  template: '#nav-section-template',
605
- methods:{
606
- toggleNavCollapse:function(navSection)
607
- {
608
- navSection.expand=!navSection.expand;
524
+ methods: {
525
+ toggleNavCollapse: function (navSection) {
526
+ navSection.expand = !navSection.expand;
609
527
  this.$forceUpdate();
610
- }
528
+ }
611
529
  }
612
- });
530
+ });
613
531
 
614
532
 
615
- var hslDocLog={
616
- _entry:[],
617
- log:function(strMessage,varData)
618
- {
619
- if(varData!==undefined) console.log(strMessage,varData)
620
- else console.log(strMessage);
533
+ var hslDocLog = {
534
+ _entry: [],
535
+ log: function (strMessage, varData) {
536
+ if (varData !== undefined) console.log(strMessage, varData)
537
+ else console.log(strMessage);
621
538
 
622
- this._entry.push({msg:strMessage,data:varData})
539
+ this._entry.push({ msg: strMessage, data: varData })
623
540
  },
624
- dump:function()
625
- {
626
- for(let x=0;x<this._entry.length;x++)
627
- {
628
- console.log(this._entry[x].msg,this._entry[x].data || null);
541
+ dump: function () {
542
+ for (let x = 0; x < this._entry.length; x++) {
543
+ console.log(this._entry[x].msg, this._entry[x].data || null);
629
544
  }
630
545
  }
631
546
  }
@@ -636,7 +551,7 @@ async function intialiseApp() {
636
551
  $(".theme-switch-checkbox").prop('checked', (ThemePreference === 'dark'));
637
552
 
638
553
  jqDocumentHeader = $(".injected-document-content .document-header");
639
- jqContentContainer = $(".injected-document-content .document-body");
554
+ jqContentContainer = $(".injected-document-content .document-body");
640
555
  //jqContentContainer = $(".injected-document-content");
641
556
  jqLeftNav = $("#DocSidebarNav");
642
557
 
@@ -656,61 +571,60 @@ async function intialiseApp() {
656
571
  dummyResponse.expiresDateTime = new Date(dummyResponse.validUntil).toLocaleDateString() + ' ' + new Date(dummyResponse.validUntil).toLocaleTimeString();
657
572
  */
658
573
 
659
- fetchJsonFile("_api/session/").then(function(sessionData)
660
- {
661
- hslDocLog.log("Hornbill docs get session data response",sessionData)
662
- if(sessionData && sessionData.type==="user")
663
- {
574
+ fetchJsonFile("_api/session/").then(function (sessionData) {
575
+ hslDocLog.log("Hornbill docs get session data response", sessionData)
576
+ if (sessionData && sessionData.type === "user") {
664
577
  hslDocLog.log("Hornbill docs set session set expires date time to browser locale")
665
578
  sessionData.expiresDateTime = new Date(sessionData.validUntil).toLocaleDateString() + ' ' + new Date(sessionData.validUntil).toLocaleTimeString();
666
- hslDocLog.log("Hornbill docs update vue session object model",sessionData);
579
+ hslDocLog.log("Hornbill docs update vue session object model", sessionData);
667
580
  view.setSessionInfo(sessionData);
668
581
  }
669
582
  });
670
583
 
671
584
  //-- eof session stuff
672
585
 
673
- await fetchJsonFile("_books/library.json").then(function(data){
586
+ await fetchJsonFile("_books/library.json").then(function (data) {
674
587
 
675
588
  // Get docbook library list
676
589
  view.docApp.library = data;
677
590
  view.docId = view.docApp.library.books[0].docId;
678
591
 
679
- }).then(function(){
592
+ }).then(function () {
680
593
  // Get hdocbook.json
681
- fetchJsonFile("_books/" + view.docId + "/hdocbook.json").then(function(data)
682
- {
594
+ fetchJsonFile("_books/" + view.docId + "/hdocbook.json").then(function (data) {
595
+ console.log(view.docApp.library.books[0].nav_inline)
683
596
  view.docApp.book = data;
684
597
  view.bookId = data.docId;
685
598
  view.docApp.title = data.title || "";
686
599
  view.docApp.description = data.description || "";
600
+
601
+ if (view.docApp.library.books[0].nav_inline.text)
602
+ view.docApp.book.navigation.items.push(view.docApp.library.books[0].nav_inline);
603
+
687
604
  //-- now render out the nav menu
688
605
  view.renderNavigation();
689
-
690
-
691
- setTimeout(function()
692
- {
606
+
607
+
608
+ setTimeout(function () {
693
609
  listenForHrefClicks();
694
-
610
+
695
611
  //-- check if url is not root - in which case we need to load content for url
696
- var initialLoadContentHref = window.location.href.replace(window.location.origin+"/","");
612
+ var initialLoadContentHref = window.location.href.replace(window.location.origin + "/", "");
697
613
  initialLoadContentHref = findFirstClickableBookLink(initialLoadContentHref);
698
-
699
- if(initialLoadContentHref)
700
- {
614
+
615
+ if (initialLoadContentHref) {
701
616
  //-- find the link we are going to show and make sure parent/s are set to .expand=true
702
- loadContentUrl(initialLoadContentHref,true,false);
703
-
704
-
617
+ loadContentUrl(initialLoadContentHref, true, false);
618
+
619
+
705
620
  }
706
- else
707
- {
621
+ else {
708
622
  hslDocLog.log("initial first view link to laod is not present");
709
623
  }
710
624
 
711
625
  $(".hb-hidden").removeClass("hb-hidden");
712
-
713
- },200);
626
+
627
+ }, 200);
714
628
  });
715
629
  });
716
- }
630
+ }