| 9 | * @property {Function} [callback=undefined] |
| 10 | */ |
| 11 | export class ScaleManager { |
| 12 | /** |
| 13 | *Creates an instance of ScaleManager. |
| 14 | */ |
| 15 | constructor(callback = () => {}) { |
| 16 | console.warn('SpringRoll.ScaleManager has been deprecated. Use SpringRoll.SafeScaleManager instead.'); |
| 17 | |
| 18 | this.width = 1; |
| 19 | this.height = 1; |
| 20 | this.callback = callback; |
| 21 | |
| 22 | /** @private */ |
| 23 | this.resizer = new ResizeHelper(this.onResize.bind(this)); |
| 24 | |
| 25 | if (callback instanceof Function) { |
| 26 | this.enable(callback); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * onResize maps and passes the relevant data to the user provided callback function. |
| 32 | * @param {object} param |
| 33 | * @param {number} param.width - Current window width |
| 34 | * @param {number} param.height - Current window height |
| 35 | * @private |
| 36 | */ |
| 37 | onResize({ width, height }) { |
| 38 | this.width = width; |
| 39 | this.height = height; |
| 40 | |
| 41 | const ratio = width / height; |
| 42 | this.callback({ width, height, ratio }); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Enables the scale manager listener. Will not be enabled if a callback is not supplied. |
| 47 | * @param {Function} callback The function to be called on resize events. |
| 48 | */ |
| 49 | enable(callback) { |
| 50 | if (callback instanceof Function) { |
| 51 | this.callback = callback; |
| 52 | this.resizer.enabled = true; |
| 53 | } else { |
| 54 | console.warn('Scale Manager was not passed a function'); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Disables the scale manager. |
| 60 | */ |
| 61 | disable() { |
| 62 | this.resizer.enabled = false; |
| 63 | } |
| 64 | } |
nothing calls this directly
no outgoing calls
no test coverage detected