-
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move alert to dedicated module
- Loading branch information
1 parent
03f6080
commit 142a89f
Showing
15 changed files
with
184 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#umap-alert-container { | ||
min-height: 46px; | ||
line-height: 46px; | ||
padding-left: 10px; | ||
width: calc(100% - 500px); | ||
position: absolute; | ||
top: -46px; | ||
left: 250px; /* Keep save/cancel button accessible. */ | ||
right: 250px; | ||
box-shadow: 0 1px 7px #999999; | ||
visibility: hidden; | ||
background: none repeat scroll 0 0 rgba(20, 22, 23, 0.8); | ||
font-weight: bold; | ||
color: #fff; | ||
font-size: 0.8em; | ||
z-index: 1012; | ||
border-radius: 2px; | ||
} | ||
#umap-alert-container.error { | ||
background-color: #c60f13; | ||
} | ||
.umap-alert #umap-alert-container { | ||
visibility: visible; | ||
top: 23px; | ||
} | ||
.umap-alert-container .umap-action { | ||
margin-left: 10px; | ||
background-color: #fff; | ||
color: #000; | ||
padding: 5px; | ||
border-radius: 4px; | ||
} | ||
.umap-alert-container .umap-action:hover { | ||
color: #000; | ||
} | ||
.umap-alert-container .error .umap-action { | ||
background-color: #666; | ||
color: #eee; | ||
} | ||
.umap-alert-container .error .umap-action:hover { | ||
color: #fff; | ||
} | ||
.umap-alert-container input { | ||
padding: 5px; | ||
border-radius: 4px; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { DomUtil, DomEvent } from '../../../vendors/leaflet/leaflet-src.esm.js' | ||
import { translate } from '../i18n.js' | ||
|
||
const ALERTS = [] | ||
let ALERT_ID = null | ||
|
||
export default class Alert { | ||
constructor(map) { | ||
this.parent = map._controlContainer | ||
this.map = map | ||
this.container = DomUtil.create('div', 'with-transition', this.parent) | ||
this.container.id = 'umap-alert-container' | ||
DomEvent.disableClickPropagation(this.container) | ||
DomEvent.on(this.container, 'contextmenu', DomEvent.stopPropagation) // Do not activate our custom context menu. | ||
DomEvent.on(this.container, 'wheel', DomEvent.stopPropagation) | ||
DomEvent.on(this.container, 'MozMousePixelScroll', DomEvent.stopPropagation) | ||
} | ||
|
||
open(params) { | ||
if (DomUtil.hasClass(this.parent, 'umap-alert')) ALERTS.push(params) | ||
else this._open(params) | ||
} | ||
|
||
_open(params) { | ||
if (!params) { | ||
if (ALERTS.length) params = ALERTS.pop() | ||
else return | ||
} | ||
let timeoutID | ||
const level_class = params.level && params.level == 'info' ? 'info' : 'error' | ||
this.container.innerHTML = '' | ||
DomUtil.addClass(this.parent, 'umap-alert') | ||
DomUtil.addClass(this.container, level_class) | ||
const close = () => { | ||
if (timeoutID && timeoutID !== ALERT_ID) { | ||
return | ||
} // Another alert has been forced | ||
this.container.innerHTML = '' | ||
DomUtil.removeClass(this.parent, 'umap-alert') | ||
DomUtil.removeClass(this.container, level_class) | ||
if (timeoutID) window.clearTimeout(timeoutID) | ||
this._open() | ||
} | ||
const closeButton = DomUtil.createButton( | ||
'umap-close-link', | ||
this.container, | ||
'', | ||
close, | ||
this | ||
) | ||
DomUtil.create('i', 'umap-close-icon', closeButton) | ||
const label = DomUtil.create('span', '', closeButton) | ||
label.title = label.textContent = translate('Close') | ||
DomUtil.element({ | ||
tagName: 'div', | ||
innerHTML: params.content, | ||
parent: this.container, | ||
}) | ||
this.addActions(params.actions) | ||
if (params.duration !== Infinity) { | ||
ALERT_ID = timeoutID = window.setTimeout(close, params.duration || 3000) | ||
} | ||
} | ||
|
||
addActions(actions) { | ||
actions = actions || [] | ||
let action, el, input | ||
const form = DomUtil.create('div', 'umap-alert-actions', this.container) | ||
for (let action of actions) { | ||
if (action.input) { | ||
input = DomUtil.element({ | ||
tagName: 'input', | ||
parent: form, | ||
className: 'umap-alert-input', | ||
placeholder: action.input, | ||
}) | ||
} | ||
el = DomUtil.createButton( | ||
'umap-action', | ||
form, | ||
action.label, | ||
action.callback, | ||
action.callbackContext || this.map | ||
) | ||
DomEvent.on(el, 'click', close, this) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.