|
1 | 1 | (function () {
|
| 2 | + // initHashLevelRedirects() |
2 | 3 | initMobileMenu()
|
3 | 4 | initVideoModal()
|
4 | 5 | if (PAGE_TYPE) {
|
|
8 | 9 | initLocationHashFuzzyMatching()
|
9 | 10 | }
|
10 | 11 |
|
| 12 | + // Most redirects should be specified in Hexo's |
| 13 | + // _config.yml. However, it can't handle hash-level |
| 14 | + // redirects, such as: |
| 15 | + // |
| 16 | + // /foo#hello -> /bar#hello |
| 17 | + // |
| 18 | + // For these cases where a section on one page has |
| 19 | + // moved to a perhaps differently-named section on |
| 20 | + // another page, we need this. |
| 21 | + function initHashLevelRedirects() { |
| 22 | + checkForHashRedirect(/components\.html$/, { |
| 23 | + 'What-are-Components': '/v2/guide/components.html', |
| 24 | + 'Using-Components': '/v2/guide/components-registration.html', |
| 25 | + 'Global-Registration': |
| 26 | + '/v2/guide/components-registration.html#Global-Registration', |
| 27 | + 'Local-Registration': |
| 28 | + '/v2/guide/components-registration.html#Local-Registration', |
| 29 | + 'Composing-Components': |
| 30 | + '/v2/guide/components.html#Organizing-Components', |
| 31 | + Props: |
| 32 | + '/v2/guide/components.html#Passing-Data-to-Child-Components-with-Props', |
| 33 | + 'Passing-Data-with-Props': |
| 34 | + '/v2/guide/components.html#Passing-Data-to-Child-Components-with-Props', |
| 35 | + 'camelCase-vs-kebab-case': |
| 36 | + '/v2/guide/components-props.html#Prop-Casing-camelCase-vs-kebab-case', |
| 37 | + 'Dynamic-Props': |
| 38 | + '/v2/guide/components-props.html#Static-and-Dynamic-Props', |
| 39 | + 'Literal-vs-Dynamic': |
| 40 | + '/v2/guide/components-props.html#Static-and-Dynamic-Props', |
| 41 | + 'One-Way-Data-Flow': |
| 42 | + '/v2/guide/components-props.html#One-Way-Data-Flow', |
| 43 | + 'Prop-Validation': '/v2/guide/components-props.html#Prop-Validation', |
| 44 | + 'Non-Prop-Attributes': |
| 45 | + '/v2/guide/components-props.html#Non-Prop-Attributes', |
| 46 | + 'Replacing-Merging-with-Existing-Attributes': |
| 47 | + '/v2/guide/components-props.html#Replacing-Merging-with-Existing-Attributes', |
| 48 | + 'Custom-Events': |
| 49 | + '/v2/guide/components.html#Sending-Messages-to-Parents-with-Events', |
| 50 | + 'Using-v-on-with-Custom-Events': |
| 51 | + '/v2/guide/components.html#Sending-Messages-to-Parents-with-Events', |
| 52 | + 'Binding-Native-Events-to-Components': |
| 53 | + '/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components', |
| 54 | + 'sync-Modifier': |
| 55 | + '/v2/guide/components-custom-events.html#sync-Modifier', |
| 56 | + 'Form-Input-Components-using-Custom-Events': |
| 57 | + '/v2/guide/components-custom-events.html#Binding-Native-Events-to-Components', |
| 58 | + 'Customizing-Component-v-model': |
| 59 | + '/v2/guide/components-custom-events.html#Customizing-Component-v-model', |
| 60 | + 'Non-Parent-Child-Communication': '/v2/guide/state-management.html', |
| 61 | + 'Compilation-Scope': |
| 62 | + '/v2/guide/components-slots.html#Compilation-Scope', |
| 63 | + 'Single-Slot': '/v2/guide/components-slots.html#Slot-Content', |
| 64 | + 'Named-Slots': '/v2/guide/components-slots.html#Named-Slots', |
| 65 | + 'Scoped-Slots': '/v2/guide/components-slots.html#Scoped-Slots', |
| 66 | + 'Dynamic-Components': '/v2/guide/components.html#Dynamic-Components', |
| 67 | + 'keep-alive': |
| 68 | + '/v2/guide/components-dynamic-async.html#keep-alive-with-Dynamic-Components', |
| 69 | + Misc: '/v2/guide/components-edge-cases.html', |
| 70 | + 'Authoring-Reusable-Components': |
| 71 | + '/v2/guide/components.html#Organizing-Components', |
| 72 | + 'Child-Component-Refs': |
| 73 | + '/v2/guide/components-edge-cases.html#Accessing-Child-Component-Instances-amp-Child-Elements', |
| 74 | + 'Async-Components': |
| 75 | + '/v2/guide/components-dynamic-async.html#Async-Components', |
| 76 | + 'Advanced-Async-Components': |
| 77 | + '/v2/guide/components-dynamic-async.html#Handling-Loading-State', |
| 78 | + 'Component-Naming-Conventions': |
| 79 | + '/v2/guide/components-registration.html#Component-Names', |
| 80 | + 'Recursive-Components': |
| 81 | + '/v2/guide/components-edge-cases.html#Recursive-Components', |
| 82 | + 'Circular-References-Between-Components': |
| 83 | + '/v2/guide/components-edge-cases.html#Circular-References-Between-Components', |
| 84 | + 'Inline-Templates': |
| 85 | + '/v2/guide/components-edge-cases.html#Inline-Templates', |
| 86 | + 'X-Templates': '/v2/guide/components-edge-cases.html#X-Templates', |
| 87 | + 'Cheap-Static-Components-with-v-once': |
| 88 | + '/v2/guide/components-edge-cases.html#Cheap-Static-Components-with-v-once' |
| 89 | + }) |
| 90 | + function checkForHashRedirect(pageRegex, redirects) { |
| 91 | + // Abort if the current page doesn't match the page regex |
| 92 | + if (!pageRegex.test(window.location.pathname)) return |
| 93 | + |
| 94 | + var redirectPath = redirects[window.location.hash.slice(1)] |
| 95 | + if (redirectPath) { |
| 96 | + window.location.href = window.location.origin + redirectPath |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + |
11 | 101 | function initApiSpecLinks () {
|
12 | 102 | var apiContent = document.querySelector('.content.api')
|
13 | 103 | if (apiContent) {
|
|
260 | 350 | }, true)
|
261 | 351 |
|
262 | 352 | // make links clickable
|
263 |
| - allHeaders.forEach(makeHeaderClickable) |
| 353 | + allHeaders |
| 354 | + .filter(function(el) { |
| 355 | + if (!el.querySelector('a')) { |
| 356 | + return false |
| 357 | + } |
| 358 | + var demos = [].slice.call(document.querySelectorAll('demo')) |
| 359 | + return !demos.some(function(demoEl) { |
| 360 | + return demoEl.contains(el) |
| 361 | + }) |
| 362 | + }) |
| 363 | + .forEach(makeHeaderClickable) |
264 | 364 |
|
265 | 365 | smoothScroll.init({
|
266 | 366 | speed: 400,
|
|
421 | 521 | .replace(rControl, '')
|
422 | 522 | // Replace special characters
|
423 | 523 | .replace(rSpecial, separator)
|
424 |
| - // Remove continous separators |
| 524 | + // Remove continuous separators |
425 | 525 | .replace(new RegExp(escapedSep + '{2,}', 'g'), separator)
|
426 | 526 | // Remove prefixing and trailing separtors
|
427 | 527 | .replace(new RegExp('^' + escapedSep + '+|' + escapedSep + '+$', 'g'), '')
|
|
0 commit comments