ui: put popup class back in utils
This commit is contained in:
parent
15128b05ec
commit
7d2e7843cd
5 changed files with 63 additions and 67 deletions
|
|
@ -1,6 +1,6 @@
|
|||
var {updateWidget, incrementWidget} = require('./data-workers'),
|
||||
{editObject, editClean} = require('./edit-objects'),
|
||||
Popup = require('../ui/popup'),
|
||||
{Popup} = require('../ui/utils'),
|
||||
{widgets, categories} = require('../widgets/'),
|
||||
widgetManager = require('../managers/widgets'),
|
||||
ContextMenu = require('./context-menu')
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ var callbacks = module.exports = {
|
|||
},
|
||||
|
||||
error: function(data){
|
||||
utils.createPopup(utils.icon('warning') + ' Error', data, true)
|
||||
new utils.Poup({title: utils.icon('warning') + ' Error', content: data, closable:true})
|
||||
},
|
||||
|
||||
reloadCss: function(){
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ var ipc = require('../ipc/'),
|
|||
parser = require('../parser'),
|
||||
state = require('./state'),
|
||||
editor = require('../editor/'),
|
||||
Popup = require('../ui/popup'),
|
||||
lobby = require('../ui/lobby'),
|
||||
{loading, icon} = require('../ui/utils'),
|
||||
{loading, icon, Popup} = require('../ui/utils'),
|
||||
{saveAs} = require('file-saver')
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
var {icon} = require('./utils')
|
||||
|
||||
module.exports = class Popup {
|
||||
|
||||
constructor(options) {
|
||||
|
||||
this.closable = options.closable
|
||||
this.escKey = options.closable || options.escKey
|
||||
this.enterKey = options.enterKey
|
||||
this.content = options.content
|
||||
this.title = options.title
|
||||
|
||||
this.html = DOM.create(`
|
||||
<div class="popup show">
|
||||
<div class="popup-wrapper">
|
||||
<div class="popup-title ${this.closable? 'closable' : ''}">${this.title}${this.closable? `<span class="closer">${module.exports.icon('times')}</span>` : ''}</div>
|
||||
<div class="popup-content">
|
||||
${this.content}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`)
|
||||
|
||||
if (this.closable) {
|
||||
DOM.get(this.html, '.popup-title .closer')[0].addEventListener('fake-click', ()=>{
|
||||
this.close()
|
||||
})
|
||||
}
|
||||
|
||||
if (this.escKey) {
|
||||
this.escKeyHandler = ((e)=>{
|
||||
if (e.keyCode==27) this.close()
|
||||
}).bind(this)
|
||||
}
|
||||
|
||||
if (this.enterKey) {
|
||||
this.enterKeyHandler = ((e)=>{
|
||||
if (e.keyCode == 13) this.enterKey.call(this, e)
|
||||
}).bind(this)
|
||||
}
|
||||
|
||||
this.open()
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
close() {
|
||||
if (this.escKey) document.removeEventListener('keydown', this.escKeyHandler)
|
||||
if (this.enterKey) document.removeEventListener('keydown', this.enterKeyHandler)
|
||||
document.body.removeChild(this.html)
|
||||
}
|
||||
|
||||
open() {
|
||||
if (this.escKey) document.addEventListener('keydown', this.escKeyHandler)
|
||||
if (this.enterKey) document.addEventListener('keydown', this.enterKeyHandler)
|
||||
document.body.appendChild(this.html)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,66 @@
|
|||
var Popup = require('./popup')
|
||||
|
||||
module.exports = {
|
||||
|
||||
Popup: class Popup {
|
||||
|
||||
constructor(options) {
|
||||
|
||||
this.closable = options.closable
|
||||
this.escKey = options.closable || options.escKey
|
||||
this.enterKey = options.enterKey
|
||||
this.content = options.content
|
||||
this.title = options.title
|
||||
|
||||
this.html = DOM.create(`
|
||||
<div class="popup show">
|
||||
<div class="popup-wrapper">
|
||||
<div class="popup-title ${this.closable? 'closable' : ''}">${this.title}${this.closable? `<span class="closer">${module.exports.icon('times')}</span>` : ''}</div>
|
||||
<div class="popup-content">
|
||||
${this.content}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`)
|
||||
|
||||
if (this.closable) {
|
||||
DOM.get(this.html, '.popup-title .closer')[0].addEventListener('fake-click', ()=>{
|
||||
this.close()
|
||||
})
|
||||
}
|
||||
|
||||
if (this.escKey) {
|
||||
this.escKeyHandler = ((e)=>{
|
||||
if (e.keyCode==27) this.close()
|
||||
}).bind(this)
|
||||
}
|
||||
|
||||
if (this.enterKey) {
|
||||
this.enterKeyHandler = ((e)=>{
|
||||
if (e.keyCode == 13) this.enterKey.call(this, e)
|
||||
}).bind(this)
|
||||
}
|
||||
|
||||
this.open()
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
close() {
|
||||
if (this.escKey) document.removeEventListener('keydown', this.escKeyHandler)
|
||||
if (this.enterKey) document.removeEventListener('keydown', this.enterKeyHandler)
|
||||
document.body.removeChild(this.html)
|
||||
}
|
||||
|
||||
open() {
|
||||
if (this.escKey) document.addEventListener('keydown', this.escKeyHandler)
|
||||
if (this.enterKey) document.addEventListener('keydown', this.enterKeyHandler)
|
||||
document.body.appendChild(this.html)
|
||||
}
|
||||
},
|
||||
|
||||
loading: function(title){
|
||||
return new Popup({
|
||||
return new module.exports.Popup({
|
||||
title: title,
|
||||
content: '<p><div class="spinner"></div></p>',
|
||||
closable: false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue