so://phie

outline

A web-based drawing app
git clone git://soophie.de/outline

blob: 1f87329c4c0ad6d6273a10c3c59013503eb19b67 (1823 bytes)[doc][blame][raw]

1export 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.app.state.modal.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.state.modal[name].element.classList.remove('hidden');

44 this.app.node.wrapper.classList.remove('hidden');

45 this.app.state.opened = true;

46 this.app.state.current = this.app.state.modal[name];

47 }

48 },

49 close: function() {

50 this.app.node.wrapper.classList.add('hidden');

51 for(let item of Object.values(this.app.state.modal)) {

52 item.element.classList.add('hidden');

53 }

54 this.app.state.opened = false;

55 this.app.state.current = undefined;

56 },

57 get: function(name) {

58 if(this.app.state.modal[name]) {

59 return this.app.state.modal[name];

60 }

61 }

62};