1/* 2 * Add classes to the body of each page of the documentation. 3 * 4 * From: [...]/outgoing/api_responses.html 5 * Into: ci-outgoing ci-api-responses 6 */ 7window.onload = function() { 8 // Regular expression for finding chapter and subject in the current url 9 const regexUrl = new RegExp(/\/([a-z0-9_.-]+)\/([a-z0-9_.-]+)\.html/); 10 11 // Get the current url 12 const currentUrl = window.location.href; 13 14 // Get the document body 15 const documentBody = document.body; 16 17 // Placeholder for documentation index 18 var index = null; 19 20 if ((index = regexUrl.exec(currentUrl)) !== null) 21 { 22 // Sanitize the documentation chapter and subject 23 var chapter = sanitizeClass(index[1]); 24 var subject = sanitizeClass(index[2]); 25 26 // Documentation is generated into an html-folder for developers. 27 // This isn't a valid chapter. We are on documentation index. 28 if (chapter === 'html') 29 { 30 index = null; 31 } 32 // Add chapter and subject className(s) to the document body 33 else 34 { 35 addClass(documentBody, chapter); 36 addClass(documentBody, subject); 37 } 38 } 39 40 // No chapter and subject found. We are on documentation index. 41 if (index === null) 42 { 43 addClass(documentBody, 'documentation'); 44 addClass(documentBody, 'index'); 45 } 46} 47 48/** 49 * Sanitize the string - removing invalid characters 50 * 51 * @param {string} className className to be sanitized 52 * 53 * @return {string} 54 */ 55sanitizeClass = function(className) { 56 return className.replace(/_/g, '-').replace(/[^a-z0-9-]/g, ''); 57} 58 59/** 60 * Add class to HTML DOM Element Object 61 * 62 * @param {object} el The HTML DOM Element Object 63 * @param {string} className className to be added 64 * @param {string} namePrefix namePrefix to be added to className 65 * 66 * @return {void} 67 */ 68addClass = function(el, className, namePrefix) {
69 namePrefix = namePrefix || 'ci-'; 70 71 if (el.classList && className.length > 0) 72 { 73 el.classList.add(namePrefix + className); 74 } 75}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.