1 /** 2 * @fileOverview 3 * @author <a href="https://www.labkey.org">LabKey</a> (<a href="mailto:info@labkey.com">info@labkey.com</a>) 4 * @license Copyright (c) 2008-2018 LabKey Corporation 5 * <p/> 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * <p/> 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * <p/> 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * <p/> 18 */ 19 20 /** 21 * @namespace NavTrail static class to adjust the text in LabKey's 22 * navigation trail. The navigation trail is the list of links across the top of 23 * the main body area, as well as the title for the current page. 24 */ 25 LABKEY.NavTrail = new function() 26 { 27 /** @scope LABKEY.NavTrail */ 28 return { 29 /** 30 * Set the nav trail's elements. 31 * @param {string} currentPageTitle The title for the current page 32 * @param {Object[]} [ancestors] An array of objects that describe the ancestor pages. Each 33 * object in this array can have two properties: url (which contains the URL for the page); 34 * and title (which contains the title for the page). These will be assembled into the full list of ancestor pages at the top of the nav trail. 35 * @param {string} [documentTitle] Document title 36 * @param {boolean} [encode=true] HTML encode the contents of currentPageTitle. Can be set to false if you are looking to include html. 37 * @param {boolean} [removeFolderLink=false] Remove any folder navigation links that are showing after the nav trail 38 * @example 39 <pre name="code" class="xml"> 40 var ancestorURL = LABKEY.ActionURL.buildURL('project', 'begin'); 41 LABKEY.NavTrail.setTrail("People View", [{url: ancestorURL, title: "API Example"}]); 42 </pre> 43 */ 44 setTrail: function (currentPageTitle, ancestors, documentTitle, encode, removeFolderLink) 45 { 46 var elem = document.querySelector('.lk-body-title'); 47 var folderLinkElem = document.querySelector('.lk-body-title-folder-outer'); 48 if (elem) 49 { 50 var newTrail = ''; 51 var newTitle = '<h3 style="display: inline-block;">' + (encode !== false ? LABKEY.Utils.encodeHtml(currentPageTitle) : currentPageTitle) + '</h3>'; 52 53 var trailEl = elem.querySelector('.breadcrumb'); 54 if (trailEl && ancestors) 55 { 56 newTrail = '<ol class="breadcrumb">'; 57 for (var i=0; i < ancestors.length; i++) 58 { 59 var a = ancestors[i]; 60 if (a.url && a.title) 61 { 62 newTrail += '<li><a href="' + a.url + '">' + LABKEY.Utils.encodeHtml(a.title) + '</a></li>'; 63 } 64 else if (a.title) 65 { 66 newTrail += '<li><span>' + LABKEY.Utils.encodeHtml(a.title) + '</span></li>'; 67 } 68 } 69 newTrail += '</ol>'; 70 } 71 72 elem.innerHTML = newTrail + newTitle; 73 } 74 if (!removeFolderLink && folderLinkElem) 75 elem.appendChild(folderLinkElem); 76 77 //set document title: 78 //<currentPageTitle>: <container path> 79 document.title = (documentTitle || currentPageTitle) + ": " + decodeURI(LABKEY.ActionURL.getContainer()); 80 } 81 }; 82 }; 83 84