| 1 | /* |
| 2 | Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/ |
| 3 | |
| 4 | This program is free software; |
| 5 | you can redistribute it and/or modify it under the terms of the |
| 6 | GNU General Public License as published by the Free Software Foundation; |
| 7 | either version 3 of the License, or any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | /* |
| 19 | Changes: |
| 20 | - v4.0.0: |
| 21 | - created from v3.6.0 |
| 22 | Doc reviewed 202208 |
| 23 | */ |
| 24 | |
| 25 | import BaseDialogMover from './BaseDialogMover.js'; |
| 26 | |
| 27 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 28 | /** |
| 29 | This class store the dialog position and expose methods to move and dock the dialog |
| 30 | */ |
| 31 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 32 | |
| 33 | class DockableBaseDialogMover extends BaseDialogMover { |
| 34 | |
| 35 | /** |
| 36 | a flag to store the docked status of the dialog |
| 37 | @type {boolean} |
| 38 | */ |
| 39 | |
| 40 | #dialogDocked; |
| 41 | |
| 42 | /** |
| 43 | Dock the dialog on top f the screen when possible |
| 44 | */ |
| 45 | |
| 46 | #dockDialog ( ) { |
| 47 | if ( this.onTop ) { |
| 48 | this.dialogHTMLElement.classList.add ( 'TravelNotes-DockableBaseDialog-Docked' ); |
| 49 | this.dialogHTMLElement.classList.add ( 'TravelNotes-DockableBaseDialog-HiddenContent' ); |
| 50 | this.dialogHTMLElement.style.top = '0px'; |
| 51 | this.#dialogDocked = true; |
| 52 | } |
| 53 | else { |
| 54 | this.dialogHTMLElement.classList.remove ( 'TravelNotes-DockableBaseDialog-Docked' ); |
| 55 | this.dialogHTMLElement.classList.remove ( 'TravelNotes-DockableBaseDialog-HiddenContent' ); |
| 56 | this.#dialogDocked = false; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | The constructor |
| 62 | */ |
| 63 | |
| 64 | constructor ( ) { |
| 65 | super ( ); |
| 66 | this.#dialogDocked = false; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | A method to test if a dialog is docked. True when the dialog is docked |
| 71 | @type {boolean} |
| 72 | */ |
| 73 | |
| 74 | get dialogDocked ( ) { return this.#dialogDocked; } |
| 75 | |
| 76 | /** |
| 77 | Center the dialog on the screen. Overload of the base class method. |
| 78 | */ |
| 79 | |
| 80 | centerDialog ( ) { |
| 81 | this.dialogHTMLElement.classList.remove ( 'TravelNotes-DockableBaseDialog-Docked' ); |
| 82 | this.dialogHTMLElement.classList.remove ( 'TravelNotes-DockableBaseDialog-HiddenContent' ); |
| 83 | super.centerDialog ( ); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | Move the dialog on the screen |
| 88 | @param {Number} newDialogX The new X position of the dialog in pixels |
| 89 | @param {Number} newDialogY The new Y position of the dialog in pixels |
| 90 | @param {?String} eventType The type of the event that have triggered the call to the method |
| 91 | */ |
| 92 | |
| 93 | moveDialogTo ( newDialogX, newDialogY, eventType ) { |
| 94 | super.moveDialogTo ( newDialogX, newDialogY, eventType ); |
| 95 | if ( ! eventType || 'touchmove' !== eventType ) { |
| 96 | this.#dockDialog ( ); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | export default DockableBaseDialogMover; |
| 102 | |
| 103 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
| 104 |