A web-based drawing app
git clone git://soophie.de/outline
blob: ae4ed5344ba8963d4b1c4a697236b7200b63e38b (2318 bytes)[doc][blame][raw]
1
export default {2
init: function(app) {3
this.app = app;4
let that = this;5
for(let item of this.app.node.modal) {6
let name = item.dataset.modal;7
let modal = { element: item, action: {} };8
let cancel = item.querySelector('button.action-cancel');9
if(cancel) {10
modal.action.cancel = { element: cancel };11
cancel.addEventListener('click', function(event) {12
that.close();13
});14
}15
this.app.state.modal[name] = modal;16
for(let item of modal.element.querySelectorAll('[class*="action-"]')) {17
let name = item.classList[0].substr(7);18
if(name !== 'cancel') {19
modal.action[name] = { element: item };20
}21
}22
}23
this.app.state.current = this.get('join');24
for(let item of this.app.node.action) {25
let name = item.dataset.action;26
if(this.app.state.modal[name]) {27
let modal = this.app.state.modal[name];28
modal.action.open = {};29
item.addEventListener('click', function(event) {30
if(typeof modal.action.open.before === 'function') {31
modal.action.open.before(modal);32
}33
that.open(name);34
if(typeof modal.action.open.after === 'function') {35
modal.action.open.after(modal);36
}37
});38
}39
}40
},41
open: function(name) {42
if(this.app.state.modal[name]) {43
this.app.node.spinner.classList.add('hidden');44
for(let item of Object.values(this.app.state.modal)) {45
item.element.classList.add('hidden');46
}47
this.app.state.modal[name].element.classList.remove('hidden');48
this.app.node.wrapper.classList.remove('hidden');49
this.app.state.opened = true;50
this.app.state.current = this.app.state.modal[name];51
}52
},53
load: function() {54
this.app.node.wrapper.classList.remove('hidden');55
for(let item of Object.values(this.app.state.modal)) {56
item.element.classList.add('hidden');57
}58
this.app.node.spinner.classList.remove('hidden');59
this.app.state.opened = true;60
this.app.state.current = undefined;61
},62
close: function() {63
this.app.node.wrapper.classList.add('hidden');64
this.app.node.spinner.classList.add('hidden');65
for(let item of Object.values(this.app.state.modal)) {66
item.element.classList.add('hidden');67
}68
this.app.state.opened = false;69
this.app.state.current = undefined;70
},71
get: function(name) {72
if(this.app.state.modal[name]) {73
return this.app.state.modal[name];74
}75
}76
};