1 // Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information.
5 var collapsed = 'collapsed';
6 var filtered = 'filtered';
9 var util = new utility();
11 workAroundFixedHeaderForAnchors();
27 window.refresh = function (article) {
28 // Update markup result
29 if (typeof article == 'undefined' || typeof article.content == 'undefined')
30 console.error("Null Argument");
31 $("article.content").html(article.content);
40 // Add this event listener when needed
41 // window.addEventListener('content-update', contentUpdate);
43 function breakText() {
44 $(".xref").addClass("text-break");
45 var texts = $(".text-break");
46 texts.each(function () {
51 // Styling for tables in conceptual documents using Bootstrap.
52 // See http://getbootstrap.com/css/#tables
53 function renderTables() {
54 $('table').addClass('table table-bordered table-striped table-condensed').wrap('<div class=\"table-responsive\"></div>');
57 // Styling for alerts.
58 function renderAlerts() {
59 $('.NOTE, .TIP').addClass('alert alert-info');
60 $('.WARNING').addClass('alert alert-warning');
61 $('.IMPORTANT, .CAUTION').addClass('alert alert-danger');
64 // Enable anchors for headings.
70 anchors.add('article h2:not(.no-anchor), article h3:not(.no-anchor), article h4:not(.no-anchor)');
73 // Open links to different host in a new window.
74 function renderLinks() {
75 if ($("meta[property='docfx:newtab']").attr("content") === "true") {
76 $(document.links).filter(function () {
77 return this.hostname !== window.location.hostname;
78 }).attr('target', '_blank');
82 // Enable highlight.js
83 function highlight() {
84 $('pre code').each(function (i, block) {
85 hljs.highlightBlock(block);
87 $('pre code[highlight-lines]').each(function (i, block) {
88 if (block.innerHTML === "") return;
89 var lines = block.innerHTML.split('\n');
91 queryString = block.getAttribute('highlight-lines');
92 if (!queryString) return;
94 var ranges = queryString.split(',');
95 for (var j = 0, range; range = ranges[j++];) {
96 var found = range.match(/^(\d+)\-(\d+)?$/);
98 // consider region as `{startlinenumber}-{endlinenumber}`, in which {endlinenumber} is optional
99 var start = +found[1];
101 if (isNaN(end) || end > lines.length) {
105 // consider region as a sigine line number
106 if (isNaN(range)) continue;
110 if (start <= 0 || end <= 0 || start > end || start > lines.length) {
111 // skip current region if invalid
114 lines[start - 1] = '<span class="line-highlight">' + lines[start - 1];
115 lines[end - 1] = lines[end - 1] + '</span>';
118 block.innerHTML = lines.join('\n');
122 // Support full-text-search
123 function enableSearch() {
125 var relHref = $("meta[property='docfx\\:rel']").attr("content");
126 if (typeof relHref === 'undefined') {
130 var worker = new Worker(relHref + 'styles/search-worker.js');
131 if (!worker && !window.worker) {
144 //Adjust the position of search box in navbar
145 function renderSearchBox() {
147 $(window).on('resize', autoCollapse);
148 $(document).on('click', '.navbar-collapse.in', function (e) {
149 if ($(e.target).is('a')) {
150 $(this).collapse('hide');
154 function autoCollapse() {
155 var navbar = $('#autocollapse');
156 if (navbar.height() === null) {
157 setTimeout(autoCollapse, 300);
159 navbar.removeClass(collapsed);
160 if (navbar.height() > 60) {
161 navbar.addClass(collapsed);
167 function localSearch() {
168 console.log("using local search");
169 var lunrIndex = lunr(function () {
171 this.field('title', { boost: 50 });
172 this.field('keywords', { boost: 20 });
174 lunr.tokenizer.seperator = /[\s\-\.]+/;
176 var searchDataRequest = new XMLHttpRequest();
178 var indexPath = relHref + "index.json";
180 searchDataRequest.open('GET', indexPath);
181 searchDataRequest.onload = function () {
182 if (this.status != 200) {
185 searchData = JSON.parse(this.responseText);
186 for (var prop in searchData) {
187 if (searchData.hasOwnProperty(prop)) {
188 lunrIndex.add(searchData[prop]);
192 searchDataRequest.send();
195 $("body").bind("queryReady", function () {
196 var hits = lunrIndex.search(query);
198 hits.forEach(function (hit) {
199 var item = searchData[hit.ref];
200 results.push({ 'href': item.href, 'title': item.title, 'keywords': item.keywords });
202 handleSearchResults(results);
206 function webWorkerSearch() {
207 console.log("using Web Worker");
208 var indexReady = $.Deferred();
210 worker.onmessage = function (oEvent) {
211 switch (oEvent.data.e) {
213 indexReady.resolve();
216 var hits = oEvent.data.d;
217 handleSearchResults(hits);
222 indexReady.promise().done(function () {
223 $("body").bind("queryReady", function () {
224 worker.postMessage({ q: query });
226 if (query && (query.length >= 3)) {
227 worker.postMessage({ q: query });
232 // Highlight the searching keywords
233 function highlightKeywords() {
236 var keywords = q.split("%20");
237 keywords.forEach(function (keyword) {
238 if (keyword !== "") {
239 $('.data-searchable *').mark(keyword);
240 $('article *').mark(keyword);
246 function addSearchEvent() {
247 $('body').bind("searchEvent", function () {
248 $('#search-query').keypress(function (e) {
249 return e.which !== 13;
252 $('#search-query').keyup(function () {
253 query = $(this).val();
254 if (query.length < 3) {
255 flipContents("show");
257 flipContents("hide");
258 $("body").trigger("queryReady");
259 $('#search-results>.search-list').text('Search Results for "' + query + '"');
265 function flipContents(action) {
266 if (action === "show") {
267 $('.hide-when-search').show();
268 $('#search-results').hide();
270 $('.hide-when-search').hide();
271 $('#search-results').show();
275 function relativeUrlToAbsoluteUrl(currentUrl, relativeUrl) {
276 var currentItems = currentUrl.split(/\/+/);
277 var relativeItems = relativeUrl.split(/\/+/);
278 var depth = currentItems.length - 1;
280 for (var i = 0; i < relativeItems.length; i++) {
281 if (relativeItems[i] === '..') {
283 } else if (relativeItems[i] !== '.') {
284 items.push(relativeItems[i]);
287 return currentItems.slice(0, depth).concat(items).join('/');
290 function extractContentBrief(content) {
291 var briefOffset = 512;
292 var words = query.split(/\s+/g);
293 var queryIndex = content.indexOf(words[0]);
295 if (queryIndex > briefOffset) {
296 return "..." + content.slice(queryIndex - briefOffset, queryIndex + briefOffset) + "...";
297 } else if (queryIndex <= briefOffset) {
298 return content.slice(0, queryIndex + briefOffset) + "...";
302 function handleSearchResults(hits) {
304 $('#pagination').empty();
305 $('#pagination').removeData("twbs-pagination");
306 if (hits.length === 0) {
307 $('#search-results>.sr-items').html('<p>No results found</p>');
309 $('#pagination').twbsPagination({
310 totalPages: Math.ceil(hits.length / numPerPage),
312 onPageClick: function (event, page) {
313 var start = (page - 1) * numPerPage;
314 var curHits = hits.slice(start, start + numPerPage);
315 $('#search-results>.sr-items').empty().append(
316 curHits.map(function (hit) {
317 var currentUrl = window.location.href;
318 var itemRawHref = relativeUrlToAbsoluteUrl(currentUrl, relHref + hit.href);
319 var itemHref = relHref + hit.href + "?q=" + query;
320 var itemTitle = hit.title;
321 var itemBrief = extractContentBrief(hit.keywords);
323 var itemNode = $('<div>').attr('class', 'sr-item');
324 var itemTitleNode = $('<div>').attr('class', 'item-title').append($('<a>').attr('href', itemHref).attr("target", "_blank").text(itemTitle));
325 var itemHrefNode = $('<div>').attr('class', 'item-href').text(itemRawHref);
326 var itemBriefNode = $('<div>').attr('class', 'item-brief').text(itemBrief);
327 itemNode.append(itemTitleNode).append(itemHrefNode).append(itemBriefNode);
331 query.split(/\s+/).forEach(function (word) {
333 $('#search-results>.sr-items *').mark(word);
342 // Update href in navbar
343 function renderNavbar() {
344 var navbar = $('#navbar ul')[0];
345 if (typeof (navbar) === 'undefined') {
348 $('#navbar ul a.active').parents('li').addClass(active);
352 function loadNavbar() {
353 var navbarPath = $("meta[property='docfx\\:navrel']").attr("content");
357 navbarPath = navbarPath.replace(/\\/g, '/');
358 var tocPath = $("meta[property='docfx\\:tocrel']").attr("content") || '';
359 if (tocPath) tocPath = tocPath.replace(/\\/g, '/');
360 $.get(navbarPath, function (data) {
361 $(data).find("#toc>ul").appendTo("#navbar");
362 if ($('#search-results').length !== 0) {
364 $('body').trigger("searchEvent");
366 var index = navbarPath.lastIndexOf('/');
369 navrel = navbarPath.substr(0, index + 1);
371 $('#navbar>ul').addClass('navbar-nav');
372 var currentAbsPath = util.getAbsolutePath(window.location.pathname);
374 $('#navbar').find('a[href]').each(function (i, e) {
375 var href = $(e).attr("href");
376 if (util.isRelativePath(href)) {
377 href = navrel + href;
378 $(e).attr("href", href);
380 // TODO: currently only support one level navbar
381 var isActive = false;
382 var originalHref = e.name;
384 originalHref = navrel + originalHref;
385 if (util.getDirectory(util.getAbsolutePath(originalHref)) === util.getDirectory(util.getAbsolutePath(tocPath))) {
389 if (util.getAbsolutePath(href) === currentAbsPath) {
394 $(e).addClass(active);
403 function renderSidebar() {
404 var sidetoc = $('#sidetoggle .sidetoc')[0];
405 if (typeof (sidetoc) === 'undefined') {
409 if ($('footer').is(':visible')) {
410 $('.sidetoc').addClass('shiftup');
413 // Scroll to active item
415 $('#toc a.active').parents('li').each(function (i, e) {
416 $(e).addClass(active).addClass(expanded);
417 $(e).children('a').addClass(active);
418 top += $(e).position().top;
420 $('.sidetoc').scrollTop(top - 50);
422 if ($('footer').is(':visible')) {
423 $('.sidetoc').addClass('shiftup');
429 function registerTocEvents() {
430 $('.toc .nav > li > .expand-stub').click(function (e) {
431 $(e.target).parent().toggleClass(expanded);
433 $('.toc .nav > li > .expand-stub + a:not([href])').click(function (e) {
434 $(e.target).parent().toggleClass(expanded);
436 $('#toc_filter_input').on('input', function (e) {
437 var val = this.value;
439 // Clear 'filtered' class
440 $('#toc li').removeClass(filtered).removeClass(hide);
445 $('#toc li>a').filter(function (i, e) {
446 return $(e).siblings().length === 0
447 }).each(function (i, anchor) {
448 var text = $(anchor).attr('title');
449 var parent = $(anchor).parent();
450 var parentNodes = parent.parents('ul>li');
451 for (var i = 0; i < parentNodes.length; i++) {
452 var parentText = $(parentNodes[i]).children('a').attr('title');
453 if (parentText) text = parentText + '.' + text;
455 if (filterNavItem(text, val)) {
456 parent.addClass(show);
457 parent.removeClass(hide);
459 parent.addClass(hide);
460 parent.removeClass(show);
463 $('#toc li>a').filter(function (i, e) {
464 return $(e).siblings().length > 0
465 }).each(function (i, anchor) {
466 var parent = $(anchor).parent();
467 if (parent.find('li.show').length > 0) {
468 parent.addClass(show);
469 parent.addClass(filtered);
470 parent.removeClass(hide);
472 parent.addClass(hide);
473 parent.removeClass(show);
474 parent.removeClass(filtered);
478 function filterNavItem(name, text) {
479 if (!text) return true;
480 if (name && name.toLowerCase().indexOf(text.toLowerCase()) > -1) return true;
487 var tocPath = $("meta[property='docfx\\:tocrel']").attr("content");
491 tocPath = tocPath.replace(/\\/g, '/');
492 $('#sidetoc').load(tocPath + " #sidetoggle > div", function () {
493 var index = tocPath.lastIndexOf('/');
496 tocrel = tocPath.substr(0, index + 1);
498 var currentHref = util.getAbsolutePath(window.location.pathname);
499 $('#sidetoc').find('a[href]').each(function (i, e) {
500 var href = $(e).attr("href");
501 if (util.isRelativePath(href)) {
502 href = tocrel + href;
503 $(e).attr("href", href);
506 if (util.getAbsolutePath(e.href) === currentHref) {
507 $(e).addClass(active);
518 function renderBreadcrumb() {
520 $('#navbar a.active').each(function (i, e) {
526 $('#toc a.active').each(function (i, e) {
533 var html = util.formList(breadcrumb, 'breadcrumb');
534 $('#breadcrumb').html(html);
538 function renderAffix() {
539 var hierarchy = getHierarchy();
540 if (hierarchy && hierarchy.length > 0) {
541 var html = '<h5 class="title">In This Article</h5>'
542 html += util.formList(hierarchy, ['nav', 'bs-docs-sidenav']);
543 $("#affix").empty().append(html);
544 if ($('footer').is(':visible')) {
545 $(".sideaffix").css("bottom", "70px");
547 $('#affix a').click(function() {
548 var scrollspy = $('[data-spy="scroll"]').data()['bs.scrollspy'];
549 var target = e.target.hash;
550 if (scrollspy && target) {
551 scrollspy.activate(target);
556 function getHierarchy() {
557 // supported headers are h1, h2, h3, and h4
558 var $headers = $($.map(['h1', 'h2', 'h3', 'h4'], function (h) { return ".article article " + h; }).join(", "));
560 // a stack of hierarchy items that are currently being built
562 $headers.each(function (i, e) {
568 name: htmlEncode($(e).text()),
574 stack.push({ type: e.tagName, siblings: [item] });
578 var frame = stack[stack.length - 1];
579 if (e.tagName === frame.type) {
580 frame.siblings.push(item);
581 } else if (e.tagName[1] > frame.type[1]) {
582 // we are looking at a child of the last element of frame.siblings.
583 // push a frame onto the stack. After we've finished building this item's children,
584 // we'll attach it as a child of the last element
585 stack.push({ type: e.tagName, siblings: [item] });
586 } else { // e.tagName[1] < frame.type[1]
587 // we are looking at a sibling of an ancestor of the current item.
588 // pop frames from the stack, building items as we go, until we reach the correct level at which to attach this item.
589 while (e.tagName[1] < stack[stack.length - 1].type[1]) {
592 if (e.tagName === stack[stack.length - 1].type) {
593 stack[stack.length - 1].siblings.push(item);
595 stack.push({ type: e.tagName, siblings: [item] });
599 while (stack.length > 1) {
603 function buildParent() {
604 var childrenToAttach = stack.pop();
605 var parentFrame = stack[stack.length - 1];
606 var parent = parentFrame.siblings[parentFrame.siblings.length - 1];
607 $.each(childrenToAttach.siblings, function (i, child) {
608 parent.items.push(child);
611 if (stack.length > 0) {
613 var topLevel = stack.pop().siblings;
614 if (topLevel.length === 1) { // if there's only one topmost header, dump it
615 return topLevel[0].items;
622 function htmlEncode(str) {
623 if (!str) return str;
625 .replace(/&/g, '&')
626 .replace(/"/g, '"')
627 .replace(/'/g, ''')
628 .replace(/</g, '<')
629 .replace(/>/g, '>');
632 function htmlDecode(value) {
633 if (!str) return str;
635 .replace(/"/g, '"')
636 .replace(/'/g, "'")
637 .replace(/</g, '<')
638 .replace(/>/g, '>')
639 .replace(/&/g, '&');
642 function cssEscape(str) {
643 // see: http://stackoverflow.com/questions/2786538/need-to-escape-a-special-character-in-a-jquery-selector-string#answer-2837646
644 if (!str) return str;
646 .replace(/[!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~]/g, "\\$&");
651 function renderFooter() {
653 $(window).on("scroll", showFooterCore);
655 function initFooter() {
665 function showFooterCore() {
668 $("footer").fadeIn();
671 $("footer").fadeOut();
675 function needFooter() {
676 var scrollHeight = $(document).height();
677 var scrollPosition = $(window).height() + $(window).scrollTop();
678 return (scrollHeight - scrollPosition) < 1;
681 function resetBottomCss() {
682 $(".sidetoc").removeClass("shiftup");
683 $(".sideaffix").removeClass("shiftup");
686 function shiftUpBottomCss() {
687 $(".sidetoc").addClass("shiftup");
688 $(".sideaffix").addClass("shiftup");
692 function renderLogo() {
694 // Replace SVG with inline SVG
695 // http://stackoverflow.com/questions/11978995/how-to-change-color-of-svg-image-using-css-jquery-svg-image-replacement
696 jQuery('img.svg').each(function () {
697 var $img = jQuery(this);
698 var imgID = $img.attr('id');
699 var imgClass = $img.attr('class');
700 var imgURL = $img.attr('src');
702 jQuery.get(imgURL, function (data) {
703 // Get the SVG tag, ignore the rest
704 var $svg = jQuery(data).find('svg');
706 // Add replaced image's ID to the new SVG
707 if (typeof imgID !== 'undefined') {
708 $svg = $svg.attr('id', imgID);
710 // Add replaced image's classes to the new SVG
711 if (typeof imgClass !== 'undefined') {
712 $svg = $svg.attr('class', imgClass + ' replaced-svg');
715 // Remove any invalid XML tags as per http://validator.w3.org
716 $svg = $svg.removeAttr('xmlns:a');
718 // Replace image with new SVG
719 $img.replaceWith($svg);
725 function renderTabs() {
728 name: 'data-bi-name',
732 var Tab = (function () {
733 function Tab(li, a, section) {
736 this.section = section;
738 Object.defineProperty(Tab.prototype, "tabIds", {
739 get: function () { return this.a.getAttribute('data-tab').split(' '); },
743 Object.defineProperty(Tab.prototype, "condition", {
744 get: function () { return this.a.getAttribute('data-condition'); },
748 Object.defineProperty(Tab.prototype, "visible", {
749 get: function () { return !this.li.hasAttribute('hidden'); },
750 set: function (value) {
752 this.li.removeAttribute('hidden');
753 this.li.removeAttribute('aria-hidden');
756 this.li.setAttribute('hidden', 'hidden');
757 this.li.setAttribute('aria-hidden', 'true');
763 Object.defineProperty(Tab.prototype, "selected", {
764 get: function () { return !this.section.hasAttribute('hidden'); },
765 set: function (value) {
767 this.a.setAttribute('aria-selected', 'true');
769 this.section.removeAttribute('hidden');
770 this.section.removeAttribute('aria-hidden');
773 this.a.setAttribute('aria-selected', 'false');
774 this.a.tabIndex = -1;
775 this.section.setAttribute('hidden', 'hidden');
776 this.section.setAttribute('aria-hidden', 'true');
782 Tab.prototype.focus = function () {
788 initTabs(document.body);
790 function initTabs(container) {
791 var queryStringTabs = readTabsQueryStringParam();
792 var elements = container.querySelectorAll('.tabGroup');
793 var state = { groups: [], selectedTabs: [] };
794 for (var i = 0; i < elements.length; i++) {
795 var group = initTabGroup(elements.item(i));
796 if (!group.independent) {
797 updateVisibilityAndSelection(group, state);
798 state.groups.push(group);
801 container.addEventListener('click', function (event) { return handleClick(event, state); });
802 if (state.groups.length === 0) {
805 selectTabs(queryStringTabs, container);
806 updateTabsQueryStringParam(state);
807 notifyContentUpdated();
811 function initTabGroup(element) {
813 independent: element.hasAttribute('data-tab-group-independent'),
816 var li = element.firstElementChild.firstElementChild;
818 var a = li.firstElementChild;
819 a.setAttribute(contentAttrs.name, 'tab');
820 var dataTab = a.getAttribute('data-tab').replace(/\+/g, ' ');
821 a.setAttribute('data-tab', dataTab);
822 var section = element.querySelector("[id=\"" + a.getAttribute('aria-controls') + "\"]");
823 var tab = new Tab(li, a, section);
824 group.tabs.push(tab);
825 li = li.nextElementSibling;
827 element.setAttribute(contentAttrs.name, 'tab-group');
828 element.tabGroup = group;
832 function updateVisibilityAndSelection(group, state) {
833 var anySelected = false;
835 for (var _i = 0, _a = group.tabs; _i < _a.length; _i++) {
837 tab.visible = tab.condition === null || state.selectedTabs.indexOf(tab.condition) !== -1;
839 if (!firstVisibleTab) {
840 firstVisibleTab = tab;
843 tab.selected = tab.visible && arraysIntersect(state.selectedTabs, tab.tabIds);
844 anySelected = anySelected || tab.selected;
847 for (var _b = 0, _c = group.tabs; _b < _c.length; _b++) {
848 var tabIds = _c[_b].tabIds;
849 for (var _d = 0, tabIds_1 = tabIds; _d < tabIds_1.length; _d++) {
850 var tabId = tabIds_1[_d];
851 var index = state.selectedTabs.indexOf(tabId);
855 state.selectedTabs.splice(index, 1);
858 var tab = firstVisibleTab;
860 state.selectedTabs.push(tab.tabIds[0]);
864 function getTabInfoFromEvent(event) {
865 if (!(event.target instanceof HTMLElement)) {
868 var anchor = event.target.closest('a[data-tab]');
869 if (anchor === null) {
872 var tabIds = anchor.getAttribute('data-tab').split(' ');
873 var group = anchor.parentElement.parentElement.parentElement.tabGroup;
874 if (group === undefined) {
877 return { tabIds: tabIds, group: group, anchor: anchor };
880 function handleClick(event, state) {
881 var info = getTabInfoFromEvent(event);
885 event.preventDefault();
886 info.anchor.href = 'javascript:';
887 setTimeout(function () { return info.anchor.href = '#' + info.anchor.getAttribute('aria-controls'); });
888 var tabIds = info.tabIds, group = info.group;
889 var originalTop = info.anchor.getBoundingClientRect().top;
890 if (group.independent) {
891 for (var _i = 0, _a = group.tabs; _i < _a.length; _i++) {
893 tab.selected = arraysIntersect(tab.tabIds, tabIds);
897 if (arraysIntersect(state.selectedTabs, tabIds)) {
900 var previousTabId = group.tabs.filter(function (t) { return t.selected; })[0].tabIds[0];
901 state.selectedTabs.splice(state.selectedTabs.indexOf(previousTabId), 1, tabIds[0]);
902 for (var _b = 0, _c = state.groups; _b < _c.length; _b++) {
903 var group_1 = _c[_b];
904 updateVisibilityAndSelection(group_1, state);
906 updateTabsQueryStringParam(state);
908 notifyContentUpdated();
909 var top = info.anchor.getBoundingClientRect().top;
910 if (top !== originalTop && event instanceof MouseEvent) {
911 window.scrollTo(0, window.pageYOffset + top - originalTop);
915 function selectTabs(tabIds) {
916 for (var _i = 0, tabIds_1 = tabIds; _i < tabIds_1.length; _i++) {
917 var tabId = tabIds_1[_i];
918 var a = document.querySelector(".tabGroup > ul > li > a[data-tab=\"" + tabId + "\"]:not([hidden])");
922 a.dispatchEvent(new CustomEvent('click', { bubbles: true }));
926 function readTabsQueryStringParam() {
927 var qs = parseQueryString();
929 if (t === undefined || t === '') {
935 function updateTabsQueryStringParam(state) {
936 var qs = parseQueryString();
937 qs.tabs = state.selectedTabs.join();
938 var url = location.protocol + "//" + location.host + location.pathname + "?" + toQueryString(qs) + location.hash;
939 if (location.href === url) {
942 history.replaceState({}, document.title, url);
945 function toQueryString(args) {
947 for (var name_1 in args) {
948 if (args.hasOwnProperty(name_1) && args[name_1] !== '' && args[name_1] !== null && args[name_1] !== undefined) {
949 parts.push(encodeURIComponent(name_1) + '=' + encodeURIComponent(args[name_1]));
952 return parts.join('&');
955 function parseQueryString(queryString) {
958 var search = /([^&=]+)=?([^&]*)/g;
959 var decode = function (s) { return decodeURIComponent(s.replace(pl, ' ')); };
960 if (queryString === undefined) {
963 queryString = queryString.substring(1);
965 while (match = search.exec(queryString)) {
966 urlParams[decode(match[1])] = decode(match[2]);
971 function arraysIntersect(a, b) {
972 for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
974 for (var _a = 0, b_1 = b; _a < b_1.length; _a++) {
976 if (itemA === itemB) {
984 function notifyContentUpdated() {
985 // Dispatch this event when needed
986 // window.dispatchEvent(new CustomEvent('content-update'));
991 this.getAbsolutePath = getAbsolutePath;
992 this.isRelativePath = isRelativePath;
993 this.isAbsolutePath = isAbsolutePath;
994 this.getDirectory = getDirectory;
995 this.formList = formList;
997 function getAbsolutePath(href) {
998 // Use anchor to normalize href
999 var anchor = $('<a href="' + href + '"></a>')[0];
1000 // Ignore protocal, remove search and query
1001 return anchor.host + anchor.pathname;
1004 function isRelativePath(href) {
1005 if (href === undefined || href === '' || href[0] === '/') {
1008 return !isAbsolutePath(href);
1011 function isAbsolutePath(href) {
1012 return (/^(?:[a-z]+:)?\/\//i).test(href);
1015 function getDirectory(href) {
1016 if (!href) return '';
1017 var index = href.lastIndexOf('/');
1018 if (index == -1) return '';
1020 return href.substr(0, index);
1024 function formList(item, classes) {
1029 var cls = [].concat(classes).join(" ");
1030 return getList(model, cls);
1032 function getList(model, cls) {
1033 if (!model || !model.items) return null;
1034 var l = model.items.length;
1035 if (l === 0) return null;
1036 var html = '<ul class="level' + level + ' ' + (cls || '') + '">';
1038 for (var i = 0; i < l; i++) {
1039 var item = model.items[i];
1040 var href = item.href;
1041 var name = item.name;
1042 if (!name) continue;
1043 html += href ? '<li><a href="' + href + '">' + name + '</a>' : '<li>' + name;
1044 html += getList(item, cls) || '';
1053 * Add <wbr> into long word.
1054 * @param {String} text - The word to break. It should be in plain text without HTML tags.
1056 function breakPlainText(text) {
1057 if (!text) return text;
1058 return text.replace(/([a-z])([A-Z])|(\.)(\w)/g, '$1$3<wbr>$2$4')
1062 * Add <wbr> into long word. The jQuery element should contain no html tags.
1063 * If the jQuery element contains tags, this function will not change the element.
1065 $.fn.breakWord = function () {
1066 if (this.html() == this.text()) {
1067 this.html(function (index, text) {
1068 return breakPlainText(text);
1075 // adjusted from https://stackoverflow.com/a/13067009/1523776
1076 function workAroundFixedHeaderForAnchors() {
1077 var HISTORY_SUPPORT = !!(history && history.pushState);
1078 var ANCHOR_REGEX = /^#[^ ]+$/;
1080 function getFixedOffset() {
1081 return $('header').first().height();
1085 * If the provided href is an anchor which resolves to an element on the
1086 * page, scroll to it.
1087 * @param {String} href
1088 * @return {Boolean} - Was the href an anchor.
1090 function scrollIfAnchor(href, pushToHistory) {
1091 var match, rect, anchorOffset;
1093 if (!ANCHOR_REGEX.test(href)) {
1097 match = document.getElementById(href.slice(1));
1100 rect = match.getBoundingClientRect();
1101 anchorOffset = window.pageYOffset + rect.top - getFixedOffset();
1102 window.scrollTo(window.pageXOffset, anchorOffset);
1104 // Add the state to history as-per normal anchor links
1105 if (HISTORY_SUPPORT && pushToHistory) {
1106 history.pushState({}, document.title, location.pathname + href);
1114 * Attempt to scroll to the current location's hash.
1116 function scrollToCurrent() {
1117 scrollIfAnchor(window.location.hash);
1121 * If the click event's target was an anchor, fix the scroll position.
1123 function delegateAnchors(e) {
1124 var elem = e.target;
1126 if (scrollIfAnchor(elem.getAttribute('href'), true)) {
1131 $(window).on('hashchange', scrollToCurrent);
1132 // Exclude tabbed content case
1133 $('a:not([data-tab])').click(delegateAnchors);