|
| 1 | +/*! docsify-sidebar 5.0.7 | (c) Mark Battistella */ |
| 2 | +; (function () { |
| 3 | + 'use strict'; |
| 4 | + |
| 5 | + const autoFooter = (hook, vm) => { |
| 6 | + // Default options |
| 7 | + const footerOptions = { |
| 8 | + name: '', |
| 9 | + url: '', |
| 10 | + copyYear: '', |
| 11 | + policy: true, |
| 12 | + terms: true, |
| 13 | + cookies: true, |
| 14 | + customStyle: 'body' |
| 15 | + }; |
| 16 | + |
| 17 | + // Extend defaults with user options |
| 18 | + Object.assign(footerOptions, $docsify.autoFooter || {}); |
| 19 | + |
| 20 | + const isObject = (obj) => obj && obj.constructor === Object && Object.keys(obj).length > 0; |
| 21 | + |
| 22 | + if (!isObject(footerOptions)) { |
| 23 | + throw new Error('Sidebar-footer configuration is invalid or empty. Please check the $docsify.autoFooter config.'); |
| 24 | + } |
| 25 | + |
| 26 | + // Auto-update the year |
| 27 | + if (!footerOptions.copyYear) { |
| 28 | + footerOptions.copyYear = new Date().getFullYear(); |
| 29 | + } |
| 30 | + |
| 31 | + // MARK: run with docsify init |
| 32 | + hook.init(function () { |
| 33 | + |
| 34 | + // -- initialise the options |
| 35 | + // getFooter(footerOptions, $docsify.autoFooter || {}); |
| 36 | + |
| 37 | + // -- check the options for bool or string |
| 38 | + if (typeof footerOptions.customStyle === "boolean" || typeof footerOptions.customStyle === "string") { |
| 39 | + |
| 40 | + // -- dont continue if using custom styles |
| 41 | + if ((typeof footerOptions.customStyle === "boolean" && footerOptions.customStyle === true)) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + // -- global style |
| 46 | + let style = `#mb-footer { border-top: 1px solid; font-size: 0.8em; line-height: 1.5; transition: all var(--sidebar-transition-duration) ease-out; }`; |
| 47 | + |
| 48 | + // -- custom style for sidebar |
| 49 | + if ((typeof footerOptions.customStyle === "boolean" && footerOptions.customStyle === false) || |
| 50 | + (footerOptions.customStyle === "sidebar") |
| 51 | + ) { |
| 52 | + style += `#mb-footer { padding-top: 1.5rem; margin-top: 1.5rem; } #mb-footer .footer-text, #mb-footer .footer-text a { font-weight: bold; }`; |
| 53 | + } |
| 54 | + |
| 55 | + // -- custom style for sidebar |
| 56 | + if (footerOptions.customStyle === "body") { |
| 57 | + |
| 58 | + // --> if there is a sidebar |
| 59 | + if ($docsify.loadSidebar || $docsify.loadSidebar === null || !$docsify.hideSidebar) { |
| 60 | + style += `body #mb-footer { margin-left: var(--sidebar-width); } body.close #mb-footer { margin-left: 0; }`; |
| 61 | + } |
| 62 | + |
| 63 | + // --> standard |
| 64 | + style += `#mb-footer { padding: 1.5rem; } #mb-footer .footer-container { max-width: var(--content-max-width); margin: 0 auto; } #mb-footer .footer-container { display: grid; grid-template-columns: auto auto; } #mb-footer .footer-container a { margin-left: 2em; } #mb-footer .footer-link { text-align: right; }`; |
| 65 | + |
| 66 | + // --> media queries |
| 67 | + style += `@media (max-width: 680px) { #mb-footer .footer-container { grid-template-columns: auto; }#mb-footer .footer-text, #mb-footer .footer-link { text-align: center; } } @media (max-width: 400px) { #mb-footer .footer-text, #mb-footer .footer-link { text-align: left; } #mb-footer span { display: block; } #mb-footer .footer-container a { margin: 0; } }`; |
| 68 | + } |
| 69 | + |
| 70 | + // create the variables |
| 71 | + const head = document.querySelector("head"), |
| 72 | + sheet = document.createElement("style"); |
| 73 | + |
| 74 | + // add to the page |
| 75 | + head.appendChild(sheet); |
| 76 | + sheet.appendChild(document.createTextNode(style)); |
| 77 | + } |
| 78 | + }); |
| 79 | + |
| 80 | + // MARK: after the HTML appended to DOM |
| 81 | + hook.doneEach(function () { |
| 82 | + |
| 83 | + // set the scope |
| 84 | + const contentScope = document.getElementById("mb-footer"); |
| 85 | + |
| 86 | + // if the scope is empty |
| 87 | + if (!contentScope) { return; } |
| 88 | + |
| 89 | + // |
| 90 | + // MARK: - add the info |
| 91 | + // |
| 92 | + |
| 93 | + // get the date |
| 94 | + const date = new Date().getFullYear(), |
| 95 | + |
| 96 | + // -- url building |
| 97 | + baseUrl = window.location.origin + window.location.pathname + "#/", |
| 98 | + |
| 99 | + // -- check if link is internal or external |
| 100 | + isExternalLink = (url) => { |
| 101 | + const tmp = document.createElement('a'); |
| 102 | + tmp.href = url; |
| 103 | + return tmp.host !== window.location.host; |
| 104 | + }, |
| 105 | + |
| 106 | + // -- link generator |
| 107 | + createLink = (option, linkText, defaultLink, className) => { |
| 108 | + let result = ""; |
| 109 | + |
| 110 | + // --> only accept bool and string |
| 111 | + if (typeof option === "boolean" || typeof option === "string") { |
| 112 | + |
| 113 | + // --> if bool, and true |
| 114 | + if (typeof option === "boolean" && option) { |
| 115 | + |
| 116 | + // --> use the default options |
| 117 | + result = `<a href="${baseUrl + defaultLink}">${linkText}</a>`; |
| 118 | + |
| 119 | + // --> if it is a string url |
| 120 | + } else if (typeof option === "string") { |
| 121 | + |
| 122 | + // --> is the link external |
| 123 | + result = isExternalLink(option) |
| 124 | + |
| 125 | + // --> if external, add the _blank |
| 126 | + ? `<a target="_blank" href="${option}">${linkText}</a>` |
| 127 | + |
| 128 | + // --> if internal, then add the page name |
| 129 | + : `<a href="${baseUrl + option}">${linkText}</a>`; |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + // --> if the result is not empty |
| 134 | + if (result) { |
| 135 | + |
| 136 | + // --> create the class name |
| 137 | + const classname = `${className.toLowerCase().replace(/\s+/g, '-')}`; |
| 138 | + |
| 139 | + // -- compile the elements |
| 140 | + result = `<span class="${classname}">${result}</span>`; |
| 141 | + } |
| 142 | + |
| 143 | + return result; |
| 144 | + }, |
| 145 | + |
| 146 | + // MARK: - html elements |
| 147 | + |
| 148 | + divclose = `</div>`, |
| 149 | + |
| 150 | + // -- divs |
| 151 | + div1open = `<div class="footer-container">`, |
| 152 | + div2open = `<div class="footer-text">`, |
| 153 | + div3open = `<div class="footer-link">`, |
| 154 | + |
| 155 | + // -- text |
| 156 | + copyright = ( |
| 157 | + `<span class="footer-text-copyright">Copyright © ${footerOptions.copyYear && footerOptions.copyYear <= date |
| 158 | + ? `${footerOptions.copyYear}${footerOptions.copyYear < date ? "-" + date : ""}` |
| 159 | + : date |
| 160 | + }</span>` |
| 161 | + ), |
| 162 | + author = createLink(footerOptions.url, footerOptions.name, '', 'footer-text-author'), |
| 163 | + |
| 164 | + // -- links |
| 165 | + policyURL = createLink(footerOptions.policy, 'Policy', '_policy', 'footer-links-policy'), |
| 166 | + termsURL = createLink(footerOptions.terms, 'Terms', '_terms', 'footer-links-terms'), |
| 167 | + cookiesURL = createLink(footerOptions.cookies, 'Cookies', '_cookies', 'footer-links-cookies'), |
| 168 | + |
| 169 | + // output |
| 170 | + output = ( |
| 171 | + div1open + |
| 172 | + div2open + copyright + author + divclose + |
| 173 | + div3open + policyURL + termsURL + cookiesURL + divclose + |
| 174 | + divclose |
| 175 | + ); |
| 176 | + |
| 177 | + contentScope.innerHTML = output; |
| 178 | + }); |
| 179 | + } |
| 180 | + |
| 181 | + // Register the plugin |
| 182 | + $docsify = $docsify || {}; |
| 183 | + $docsify.plugins = [].concat(autoFooter, $docsify.plugins || []); |
| 184 | +}()); |
0 commit comments