| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | import BaseControl from '../baseControl/BaseControl.js'; |
| 26 | import theHTMLElementsFactory from '../../core/uiLib/HTMLElementsFactory.js'; |
| 27 | import TouchListItemEL from './TouchListItemEL.js'; |
| 28 | import DragStartListItemEL from './DragStartListItemEL.js'; |
| 29 | import DropListItemEL from './DropListItemEL.js'; |
| 30 | import ContextMenuListItemEL from './ContextMenuListItemEL.js'; |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | class SortableListControl extends BaseControl { |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | #dragStartListItemEL; |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | #dropListItemEL; |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | #contextMenuListItemEL; |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | #touchListItemEL; |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | #sortableListHTMLElement; |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | constructor ( dropFunction, contextMenuClass, headingText ) { |
| 83 | super ( ); |
| 84 | this.#dragStartListItemEL = new DragStartListItemEL ( ); |
| 85 | this.#dropListItemEL = new DropListItemEL ( dropFunction ); |
| 86 | this.#contextMenuListItemEL = new ContextMenuListItemEL ( contextMenuClass ); |
| 87 | this.#touchListItemEL = new TouchListItemEL ( dropFunction ); |
| 88 | if ( headingText ) { |
| 89 | theHTMLElementsFactory.create ( |
| 90 | 'div', |
| 91 | { |
| 92 | className : 'TravelNotes-BaseDialog-FlexRow', |
| 93 | textContent : headingText |
| 94 | }, |
| 95 | this.controlHTMLElement |
| 96 | ); |
| 97 | } |
| 98 | this.#sortableListHTMLElement = theHTMLElementsFactory.create ( |
| 99 | 'div', |
| 100 | { |
| 101 | className : 'TravelNotes-SortableList-ListHTMLElement' |
| 102 | }, |
| 103 | this.controlHTMLElement |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | updateContent ( listItemsHTMLElements ) { |
| 113 | while ( this.#sortableListHTMLElement.firstChild ) { |
| 114 | this.#sortableListHTMLElement.firstChild.removeEventListener ( 'dragstart', this.#dragStartListItemEL, false ); |
| 115 | this.#sortableListHTMLElement.firstChild.removeEventListener ( 'drop', this.#dropListItemEL, false ); |
| 116 | this.#sortableListHTMLElement.firstChild.removeEventListener ( 'contextmenu', this.#contextMenuListItemEL, false ); |
| 117 | this.#sortableListHTMLElement.firstChild.removeEventListener ( 'touchstart', this.#touchListItemEL, false ); |
| 118 | this.#sortableListHTMLElement.firstChild.removeEventListener ( 'touchmove', this.#touchListItemEL, false ); |
| 119 | this.#sortableListHTMLElement.firstChild.removeEventListener ( 'touchend', this.#touchListItemEL, false ); |
| 120 | this.#sortableListHTMLElement.removeChild ( this.#sortableListHTMLElement.firstChild ); |
| 121 | } |
| 122 | listItemsHTMLElements.forEach ( |
| 123 | listItemHTMLElement => { |
| 124 | listItemHTMLElement.draggable = true; |
| 125 | listItemHTMLElement.addEventListener ( 'dragstart', this.#dragStartListItemEL, false ); |
| 126 | listItemHTMLElement.addEventListener ( 'drop', this.#dropListItemEL, false ); |
| 127 | listItemHTMLElement.addEventListener ( 'contextmenu', this.#contextMenuListItemEL, false ); |
| 128 | listItemHTMLElement.addEventListener ( 'touchstart', this.#touchListItemEL, false ); |
| 129 | listItemHTMLElement.addEventListener ( 'touchmove', this.#touchListItemEL, false ); |
| 130 | listItemHTMLElement.addEventListener ( 'touchend', this.#touchListItemEL, false ); |
| 131 | this.#sortableListHTMLElement.appendChild ( listItemHTMLElement ); |
| 132 | listItemHTMLElement.classList.add ( 'TravelNotes-SortableList-ListItemHTMLElement' ); |
| 133 | } |
| 134 | ); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | export default SortableListControl; |
| 139 | |
| 140 | |
| 141 | |