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