diff --git a/src/controls/legend/group.js b/src/controls/legend/group.js index 4f508d070..f0d68a83f 100644 --- a/src/controls/legend/group.js +++ b/src/controls/legend/group.js @@ -96,10 +96,10 @@ const Group = function Group(options = {}, viewer) { }); }, render() { - return `
+ return `
${expandButton.render()} - ${title} + ${title}
${tickButton ? tickButton.render() : ''}
`; diff --git a/src/controls/legend/overlay.js b/src/controls/legend/overlay.js index 44259c416..f14ad5666 100644 --- a/src/controls/legend/overlay.js +++ b/src/controls/legend/overlay.js @@ -1,6 +1,6 @@ import { Component, Button, dom } from '../../ui'; import { HeaderIcon } from '../../utils/legendmaker'; -import PopupMenu from '../../popupmenu'; +import PopupMenu from '../../ui/popupmenu'; const OverlayLayer = function OverlayLayer(options) { let { @@ -20,7 +20,7 @@ const OverlayLayer = function OverlayLayer(options) { const popupMenuItems = []; let layerList; - const cls = `${clsSettings} flex row align-center padding-left padding-right item`.trim(); + const cls = `${clsSettings} flex row align-center padding-left padding-right-smaller item`.trim(); const title = layer.get('title') || 'Titel saknas'; const name = layer.get('name'); const secure = layer.get('secure'); @@ -193,7 +193,8 @@ const OverlayLayer = function OverlayLayer(options) { const { top, left } = getElementOffset(moreInfoButtonEl, viewerEl); const right = viewerEl.offsetWidth - left - moreInfoButtonEl.offsetWidth; const targetRect = moreInfoButtonEl.getBoundingClientRect(); - popupMenu = PopupMenu({ target: viewer.getId(), onUnfocus }); + popupMenu = PopupMenu({ onUnfocus }); + document.getElementById(viewer.getId()).appendChild(dom.html(popupMenu.render())); popupMenu.setContent(popupMenuList.render()); popupMenuList.dispatch('render'); popupMenu.setPosition({ right: `${right}px`, top: `${top + targetRect.height}px` }); diff --git a/src/popupmenu.js b/src/ui/popupmenu.js similarity index 60% rename from src/popupmenu.js rename to src/ui/popupmenu.js index 1d1bf0d6e..3b989fa97 100644 --- a/src/popupmenu.js +++ b/src/ui/popupmenu.js @@ -1,20 +1,13 @@ -import Cuid from 'cuid'; -import { dom } from './ui'; +import { Component } from '.'; export default function popup(options = {}) { const { - target, onUnfocus = () => {} } = options; - const id = Cuid(); + let id; let isVisible = true; - function render(targetId) { - const pop = ``; - document.getElementById(targetId).appendChild(dom.html(pop)); - } - function getEl() { return document.getElementById(id); } @@ -45,23 +38,24 @@ export default function popup(options = {}) { if (content) getEl().innerHTML = content; } - function bindUIActions() { - window.addEventListener('click', (e) => { - const popupMenuEl = document.getElementById(id); - if (!popupMenuEl.contains(e.target)) { - onUnfocus(e); - e.preventDefault(); - } - }); - } - - render(target); - bindUIActions(); - return { + return Component({ + onInit() { + id = this.getId(); + window.addEventListener('click', (e) => { + const popupMenuEl = document.getElementById(id); + if (!popupMenuEl.contains(e.target)) { + onUnfocus(e); + e.preventDefault(); + } + }); + }, getEl, setPosition, setVisibility, toggleVisibility, - setContent - }; + setContent, + render() { + return ``; + } + }); }