|
| 1 | +import BM from './ButtonMouseShadowed.js'; |
| 2 | + |
1 | 3 | /** |
2 | 4 | * Base for the event controllers for button blocks, which automate |
3 | 5 | * mouse pointer shadows |
4 | 6 | */ |
5 | 7 | export default class ButtonAbstract { |
| 8 | +/** |
| 9 | + * @param {String} [modifier = ''] Modifier of the card block. |
| 10 | + * Default '' means mo modifier. |
| 11 | + * @param {function} postTransformFunction for examples, see |
| 12 | + * {js/transformation/TransformableElement/ |
| 13 | + * PostTransformFunctions.js} |
| 14 | + * @returns {void} |
| 15 | + */ |
| 16 | + constructor( |
| 17 | + modifier = '', |
| 18 | + postShadowFunction, |
| 19 | + shadowFunction = ButtonAbstract._shadowFunction |
| 20 | + ) { |
| 21 | + |
| 22 | + this._throwIfAbstractClass(); |
| 23 | + |
| 24 | + this._bm = new BM( |
| 25 | + modifier, |
| 26 | + postShadowFunction, |
| 27 | + shadowFunction |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * function which takes an object args which contains e mousemove |
| 33 | + * event (event) and returns css changes |
| 34 | + * @param {object} args |
| 35 | + * @returns {object} object of css properties and their values |
| 36 | + */ |
| 37 | + static _shadowFunction(args) { |
| 38 | + const |
| 39 | + rect = args.eventControlElement.domElement.getBoundingClientRect(), |
| 40 | + hover = [ |
| 41 | + args.event.clientX - rect.left, |
| 42 | + args.event.clientY - rect.top |
| 43 | + ]; |
| 44 | + |
| 45 | + return { |
| 46 | + '--button--mouse-shadow-left': hover[0] + 'px', |
| 47 | + '--button--mouse-shadow-top': hover[1] + 'px' |
| 48 | + }; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @todo what does this do in simple words |
| 53 | + * @see TransformationController |
| 54 | + * @returns {void} |
| 55 | + */ |
| 56 | + mousemoveEvent() { |
| 57 | + this._bm.mousemoveEventShadow(); |
| 58 | + } |
6 | 59 |
|
| 60 | + /** |
| 61 | + * helper function that throws if class name ends with 'Abstract' |
| 62 | + * @private |
| 63 | + * @throws {Error} 'cannot call functions in abstract class' |
| 64 | + * @returns {void} |
| 65 | + */ |
| 66 | + _throwIfAbstractClass() { |
| 67 | + if((typeof new.target).endsWith('Abstract')) { |
| 68 | + throw new Error('cannot call functions in abstract class'); |
| 69 | + } |
| 70 | + } |
7 | 71 | } |
0 commit comments