|
| 1 | +// jshint strict: false |
| 2 | + |
| 3 | +/** |
| 4 | + * Styles - |
| 5 | + * Handle the creation and embedding of custom styles. |
| 6 | + * @access protected |
| 7 | + * @module modules/Styles |
| 8 | + */ |
| 9 | + |
| 10 | +import Module from '../core/Module'; |
| 11 | + |
| 12 | +const Styles = Module({ |
| 13 | + name: 'Styles', |
| 14 | + |
| 15 | + props: { |
| 16 | + stylesheet: null, |
| 17 | + }, |
| 18 | + |
| 19 | + handlers: { |
| 20 | + events: { |
| 21 | + 'app:destroy': 'destroy' |
| 22 | + } |
| 23 | + }, |
| 24 | + |
| 25 | + methods: { |
| 26 | + setup () { |
| 27 | + this.createStylesheet(); |
| 28 | + }, |
| 29 | + |
| 30 | + init () { |
| 31 | + const { mediator } = this; |
| 32 | + const config = mediator.get('config:styles'); |
| 33 | + let stylesheetContent = this.stylesTemplate(config); |
| 34 | + |
| 35 | + this.appendStylesheet(); |
| 36 | + this.updateStylesheet(stylesheetContent); |
| 37 | + }, |
| 38 | + |
| 39 | + stylesTemplate (config) { |
| 40 | + return ` |
| 41 | + .typester-toolbar .typester-menu-item, |
| 42 | + .typester-input-form input[type=text], |
| 43 | + .typester-link-display a, |
| 44 | + .typester-input-form button { |
| 45 | + color: ${config.colors.menuItemIcon}; |
| 46 | + } |
| 47 | +
|
| 48 | + .typester-toolbar .typester-menu-item svg, |
| 49 | + .typester-link-display .typester-link-edit svg, |
| 50 | + .typester-input-form button svg { |
| 51 | + fill: ${config.colors.menuItemIcon}; |
| 52 | + } |
| 53 | +
|
| 54 | + .typester-input-form button svg { |
| 55 | + stroke: ${config.colors.menuItemIcon}; |
| 56 | + } |
| 57 | +
|
| 58 | + .typester-toolbar .typester-menu-item:hover, |
| 59 | + .typester-link-display .typester-link-edit:hover |
| 60 | + .typester-input-form button:hover { |
| 61 | + background: ${config.colors.menuItemHover}; |
| 62 | + } |
| 63 | +
|
| 64 | + .typester-toolbar .typester-menu-item.s--active { |
| 65 | + background: ${config.colors.menuItemActive}; |
| 66 | + } |
| 67 | +
|
| 68 | + .typester-flyout .typester-flyout-content { |
| 69 | + background: ${config.colors.flyoutBg}; |
| 70 | + } |
| 71 | +
|
| 72 | + .typester-flyout.place-above .typester-flyout-arrow { |
| 73 | + border-top-color: ${config.colors.flyoutBg}; |
| 74 | + } |
| 75 | +
|
| 76 | + .typester-flyout.place-below .typester-flyout-arrow { |
| 77 | + border-bottom-color: ${config.colors.flyoutBg}; |
| 78 | + } |
| 79 | + `; |
| 80 | + }, |
| 81 | + |
| 82 | + createStylesheet () { |
| 83 | + this.stylesheet = document.createElement('style'); |
| 84 | + }, |
| 85 | + |
| 86 | + appendStylesheet () { |
| 87 | + document.head.appendChild(this.stylesheet); |
| 88 | + }, |
| 89 | + |
| 90 | + updateStylesheet (stylesheetContent) { |
| 91 | + this.stylesheet.textContent = stylesheetContent; |
| 92 | + }, |
| 93 | + |
| 94 | + removeStylesheet () { |
| 95 | + document.head.removeChild(this.stylesheet); |
| 96 | + }, |
| 97 | + |
| 98 | + destroy () { |
| 99 | + this.removeStylesheet(); |
| 100 | + } |
| 101 | + } |
| 102 | +}); |
| 103 | + |
| 104 | +export default Styles; |
0 commit comments