| 1 | import layoutHelpers from '@/layout/helpers.js' | = | 1 | import layoutHelpers from '@/layout/helpers.js' |
| 2 | 2 | |||
| 3 | export default function () { | 3 | export default function () { | |
| 4 | return { | 4 | return { | |
| 5 | // Base url | <> | 5 | // Public url |
| 6 | baseUrl: '/', | 6 | publicUrl: '/', | |
| 7 | = | 7 | ||
| 8 | // Layout helpers | 8 | // Layout helpers | |
| 9 | layoutHelpers, | 9 | layoutHelpers, | |
| 10 | 10 | |||
| 11 | // Check for RTL layout | 11 | // Check for RTL layout | |
| 12 | get isRTL () { | 12 | get isRTL () { | |
| 13 | return document.documentElement.getAttribute('dir') === 'rtl' || | 13 | return document.documentElement.getAttribute('dir') === 'rtl' || | |
| 14 | document.body.getAttribute('dir') === 'rtl' | 14 | document.body.getAttribute('dir') === 'rtl' | |
| 15 | }, | 15 | }, | |
| 16 | 16 | |||
| 17 | // Check if IE | 17 | // Check if IE | |
| 18 | get isIEMode () { | 18 | get isIEMode () { | |
| 19 | return typeof document['documentMode'] === 'number' | 19 | return typeof document['documentMode'] === 'number' | |
| 20 | }, | 20 | }, | |
| 21 | 21 | |||
| 22 | // Check if IE10 | 22 | // Check if IE10 | |
| 23 | get isIE10Mode () { | 23 | get isIE10Mode () { | |
| 24 | return this.isIEMode && document['documentMode'] === 10 | 24 | return this.isIEMode && document['documentMode'] === 10 | |
| 25 | }, | 25 | }, | |
| 26 | 26 | |||
| 27 | // Layout navbar color | 27 | // Layout navbar color | |
| 28 | get layoutNavbarBg () { | 28 | get layoutNavbarBg () { | |
| 29 | return 'navbar-theme' | 29 | return 'navbar-theme' | |
| 30 | }, | 30 | }, | |
| 31 | 31 | |||
| 32 | // Layout sidenav color | 32 | // Layout sidenav color | |
| 33 | get layoutSidenavBg () { | 33 | get layoutSidenavBg () { | |
| 34 | return 'sidenav-theme' | 34 | return 'sidenav-theme' | |
| 35 | }, | 35 | }, | |
| 36 | 36 | |||
| 37 | // Layout footer color | 37 | // Layout footer color | |
| 38 | get layoutFooterBg () { | 38 | get layoutFooterBg () { | |
| 39 | return 'footer-theme' | 39 | return 'footer-theme' | |
| 40 | }, | 40 | }, | |
| 41 | 41 | |||
| 42 | // Animate scrollTop | 42 | // Animate scrollTop | |
| 43 | scrollTop (to, duration, element = document.scrollingElement || document.documentElement) { | 43 | scrollTop (to, duration, element = document.scrollingElement || document.documentElement) { | |
| 44 | if (element.scrollTop === to) return | 44 | if (element.scrollTop === to) return | |
| 45 | const start = element.scrollTop | 45 | const start = element.scrollTop | |
| 46 | const change = to - start | 46 | const change = to - start | |
| 47 | const startDate = +new Date() | 47 | const startDate = +new Date() | |
| 48 | 48 | |||
| 49 | // t = current time; b = start value; c = change in value; d = duration | 49 | // t = current time; b = start value; c = change in value; d = duration | |
| 50 | const easeInOutQuad = (t, b, c, d) => { | 50 | const easeInOutQuad = (t, b, c, d) => { | |
| 51 | t /= d / 2 | 51 | t /= d / 2 | |
| 52 | if (t < 1) return c / 2 * t * t + b | 52 | if (t < 1) return c / 2 * t * t + b | |
| 53 | t-- | 53 | t-- | |
| 54 | return -c / 2 * (t * (t - 2) - 1) + b | 54 | return -c / 2 * (t * (t - 2) - 1) + b | |
| 55 | } | 55 | } | |
| 56 | 56 | |||
| 57 | const animateScroll = () => { | 57 | const animateScroll = () => { | |
| 58 | const currentDate = +new Date() | 58 | const currentDate = +new Date() | |
| 59 | const currentTime = currentDate - startDate | 59 | const currentTime = currentDate - startDate | |
| 60 | element.scrollTop = parseInt(easeInOutQuad(currentTime, start, change, duration)) | 60 | element.scrollTop = parseInt(easeInOutQuad(currentTime, start, change, duration)) | |
| 61 | if (currentTime < duration) { | 61 | if (currentTime < duration) { | |
| 62 | requestAnimationFrame(animateScroll) | 62 | requestAnimationFrame(animateScroll) | |
| 63 | } else { | 63 | } else { | |
| 64 | element.scrollTop = to | 64 | element.scrollTop = to | |
| 65 | } | 65 | } | |
| 66 | } | 66 | } | |
| 67 | 67 | |||
| 68 | animateScroll() | 68 | animateScroll() | |
| 69 | } | 69 | } | |
| 70 | } | 70 | } | |
| 71 | } | 71 | } |