Path: blob/main/static/script/selection.js
917 views
/**1* Incognito2*3* This program is free software: you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation, either version 3 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program. If not, see <https://www.gnu.org/licenses/>.15*/1617/*18_____ _ _ _19| __ \ | | | | | |20| |__) | ___ _ __ | |_ ___ __| | | |__ _ _21| ___/ / _ \ | '__| | __| / _ \ / _` | | '_ \ | | | |22| | | (_) | | | | |_ | __/ | (_| | | |_) | | |_| |23|_| \___/ |_| \__| \___| \__,_| |_.__/ \__, |24__/ |25|___/26_ _ _ _ _ _ _27/\ | | | | | | | \ | | | | | |28/ \ _ __ ___ ___ | |_ | |__ _ _ ___ | |_ | \| | ___ | |_ __ __ ___ _ __ | | __29/ /\ \ | '_ ` _ \ / _ \ | __| | '_ \ | | | | / __| | __| | . ` | / _ \ | __| \ \ /\ / / / _ \ | '__| | |/ /30/ ____ \ | | | | | | | __/ | |_ | | | | | |_| | \__ \ | |_ | |\ | | __/ | |_ \ V V / | (_) | | | | <31/_/ \_\ |_| |_| |_| \___| \__| |_| |_| \__, | |___/ \__| |_| \_| \___| \__| \_/\_/ \___/ |_| |_|\_\32__/ |33|___/34*/35import EventEmitter from "./events.js";3637class Selection extends EventEmitter {38constructor(app) {39super();40this.app = app;41this.createElement = app.createElement;42this.selectors = {};43this.element = app.createElement('div', [], {44class: 'selector-wrapper'45});46};47switchSelector(id) {48if (!(id in this.selectors)) return false;49this.unselectAll();50this.emit('select', id);51this.selectors[id].setAttribute('data-selected', '');52return this.selectors[id];53};54createSelector(id, element) {55this.selectors[id] = element;5657element.addEventListener('click', () =>58this.switchSelector(id)59);6061this.element.append(element);62return element;63};64unselectAll() {65for (const key in this.selectors) {66if (this.selectors[key].hasAttribute('data-selected')) {67this.selectors[key].removeAttribute('data-selected')68};69};70return true;71};72};7374export { Selection };7576