|
202 | 202 | {% endif %} |
203 | 203 |
|
204 | 204 |
|
205 | | - |
206 | 205 | <!-- Side Catalog --> |
207 | 206 | {% if page.catalog %} |
208 | 207 | <script type="text/javascript"> |
209 | 208 | function generateCatalog (selector) { |
210 | | - var P = $('div.post-container'),a,n,t,l,i,c; |
| 209 | + |
| 210 | + // interop with multilangual |
| 211 | + if ({{ page.multilingual }}) { |
| 212 | + _containerSelector = 'div.post-container.active' |
| 213 | + } else { |
| 214 | + _containerSelector = 'div.post-container' |
| 215 | + } |
| 216 | + |
| 217 | + // init |
| 218 | + var P = $(_containerSelector),a,n,t,l,i,c; |
211 | 219 | a = P.find('h1,h2,h3,h4,h5,h6'); |
| 220 | + |
| 221 | + // clean |
| 222 | + $(selector).html('') |
| 223 | + |
| 224 | + // appending |
212 | 225 | a.each(function () { |
213 | 226 | n = $(this).prop('tagName').toLowerCase(); |
214 | 227 | i = "#"+$(this).prop('id'); |
|
249 | 262 | }); |
250 | 263 | </script> |
251 | 264 | {% endif %} |
| 265 | + |
| 266 | + |
| 267 | +<!-- Multi-Lingual --> |
| 268 | +{% if page.multilingual %} |
| 269 | +<!-- Handle Language Change --> |
| 270 | +<script type="text/javascript"> |
| 271 | + // get nodes |
| 272 | + var $zh = document.querySelector(".zh"); |
| 273 | + var $en = document.querySelector(".en"); |
| 274 | + var $select = document.querySelector("select"); |
| 275 | + |
| 276 | + // bind hashchange event |
| 277 | + // Changes at v1.7.2: change the language flag from hash-based to in-memory based |
| 278 | + // due to its confliction with catalog anchors. |
| 279 | + // window.addEventListener('hashchange', _render); |
| 280 | + |
| 281 | + // handle render |
| 282 | + function _render(_hash){ |
| 283 | + var _hash = _hash || window.location.hash; |
| 284 | + // en |
| 285 | + if(_hash == "#en"){ |
| 286 | + $select.selectedIndex = 1; |
| 287 | + $en.style.display = "block"; |
| 288 | + $en.classList.add("active"); |
| 289 | + $zh.style.display = "none"; |
| 290 | + $zh.classList.remove("active"); |
| 291 | + // zh by default |
| 292 | + }else{ |
| 293 | + // not trigger onChange, otherwise cause a loop call. |
| 294 | + $select.selectedIndex = 0; |
| 295 | + $zh.style.display = "block"; |
| 296 | + $zh.classList.add("active"); |
| 297 | + $en.style.display = "none"; |
| 298 | + $en.classList.remove("active"); |
| 299 | + } |
| 300 | + // interop with catalog |
| 301 | + if ("{{ page.catalog }}") generateCatalog(".catalog-body"); |
| 302 | + } |
| 303 | + |
| 304 | + // handle select change |
| 305 | + function onLanChange(index){ |
| 306 | + if(index == 0){ |
| 307 | + _hash = "#zh" |
| 308 | + }else{ |
| 309 | + _hash = "#en" |
| 310 | + } |
| 311 | + _render(_hash) |
| 312 | + } |
| 313 | + |
| 314 | + // init |
| 315 | + _render(); |
| 316 | +</script> |
| 317 | +{% endif %} |
0 commit comments