so://phie

outline

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

blob: 398af6bf9a525a0579c4b327a4a4cdbd55a2ed5b (1735 bytes)[doc][blame][raw]

1export default {

2 opened: false,

3 current: undefined,

4 init: function() {

5 let that = this;

6 this.wrapper = document.querySelector('.wrapper');

7 this.modal = {};

8 Array.from(document.querySelectorAll('.modal')).forEach(function(item) {

9 let modal = { element: item, action: {} };

10 let name = item.dataset.modal;

11 let cancel = item.querySelector('button.action-cancel');

12 if(cancel) {

13 modal.action.cancel = { element: cancel };

14 cancel.addEventListener('click', function(event) {

15 that.close();

16 // that.trigger(modal.action.cancel);

17 });

18 document.addEventListener('keydown', function(event) {

19 if(that.opened && typeof that.current.action.cancel !== 'undefined') {

20 if(event.keyCode == 27) {

21 that.close();

22 }

23 }

24 });

25 }

26 Array.from(item.querySelectorAll('[class*="action-"]')).forEach(function(item) {

27 let name = item.classList[0].substr(7);

28 if(name !== 'cancel') {

29 modal.action[name] = { element: item };

30 }

31 });

32 that.modal[name] = modal;

33 });

34 },

35 open: function(name) {

36 if(this.modal[name]) {

37 this.modal[name].element.style.display = '';

38 this.wrapper.style.display = '';

39 this.opened = true;

40 this.current = this.modal[name];

41 }

42 },

43 close: function() {

44 this.wrapper.style.display = 'none';

45 Object.entries(this.modal).forEach(function([ key, value ]) {

46 value.element.style.display = 'none';

47 });

48 this.opened = false;

49 this.current = undefined;

50 },

51 get: function(name) {

52 if(this.modal[name]) {

53 return this.modal[name];

54 }

55 }

56 /*

57 bind: function(action, callback) {

58 action.callback = callback;

59 },

60 trigger: function(action) {

61 if(typeof action.callback === 'function') {

62 action.callback(this);

63 }

64 }

65 */

66};