Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 92a538e1

Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)

created reusable ModalWindow, Popover and Popup components as ES6 classes

Zobrazit rozdíly:

sources/src/main/webapp/js/components/generic/modalWindow.js
1
/**
2
 * Class representing a modal window.
3
 */
4
class ModalWindow {
5
	/**
6
	 * Creates a new HTML DOM element representing the modal window. Binds user interactions to local handler functions.
7
	 * @public
8
	 * @returns newly created HTML DOM element
9
	 */
10
	render() {
11
		this._bodyElement = DOM.h('div', {
12
			class: 'modal-body',
13
		});
14

  
15
		this._rootElement = DOM.h('div', {
16
			class: 'modal',
17
			hidden: 'hidden',
18
			onClick: this.close.bind(this),
19
		}, [
20
			DOM.h('div', {
21
				class: 'modal-content',
22
				onClick: Utils.stopPropagation,
23
			}, [
24
				DOM.h('button', {
25
					class: 'close-button button',
26
					innerText: '×',
27
					onClick: this.close.bind(this),
28
				}),
29
				this._bodyElement,
30
			]),
31
		]);
32

  
33
		return this._rootElement;
34
	}
35

  
36
	/**
37
	 * @public
38
	 * @returns {boolean} true if the DOM element has been instantiated using render() method, otherwise false
39
	 */
40
	get isInitialized() {
41
		return Utils.isDefined(this._rootElement);
42
	}
43

  
44
	/**
45
	 * @public
46
	 * @returns {boolean} true if the modal window is visible at the moment, otherwise false
47
	 */
48
	get isVisible() {
49
		return this._rootElement.hasAttribute('hidden');
50
	}
51

  
52
	/**
53
	 * Opens the modal window.
54
	 * @public
55
	 */
56
	open() {
57
		this._rootElement.removeAttribute('hidden');
58
	}
59

  
60
	/**
61
	 * Closes the modal window.
62
	 * @public
63
	 */
64
	close() {
65
		this._rootElement.setAttribute('hidden', 'hidden');
66
	}
67

  
68
	/**
69
	 * Toggles visibility of the modal window.
70
	 * @public
71
	 */
72
	toggle() {
73
		if (this.isVisible) {
74
			this.open();
75
		} else {
76
			this.close();
77
		}
78
	}
79
}
sources/src/main/webapp/js/components/generic/popover.js
1
/**
2
 * Class representing a popover.
3
 */
4
class Popover {
5
	/**
6
	 * Creates a new HTML DOM element representing the popover. Binds user interactions to local handler functions.
7
	 * @public
8
	 * @returns newly created HTML DOM element
9
	 */
10
	render() {
11
		this._titleElement = DOM.h('span', {
12
			class: 'popover-title',
13
		});
14

  
15
		this._bodyElement = DOM.h('div', {
16
			class: 'popover-body',
17
		});
18

  
19
		this._rootElement = DOM.h('div', {
20
			class: 'popover',
21
			hidden: 'hidden',
22
			onWheel: Utils.stopPropagation,
23
			onMouseDown: Utils.stopPropagation,
24
			onMouseLeave: this.close.bind(this),
25
		}, [
26
			this._titleElement,
27
			this._bodyElement,
28
		]);
29

  
30
		return this._rootElement;
31
	}
32

  
33
	/**
34
	 * Moves the popover to the coordinates.
35
	 * @public
36
	 * @param {Coordinates} coords Coordinates to display the popover at.
37
	 */
38
	set position(coords) {
39
		this._rootElement.style.top = coords.y + 'px';
40
		this._rootElement.style.left = coords.x + 'px';
41
	}
42

  
43
	/**
44
	 * @public
45
	 * @returns {boolean} true if the DOM element has been instantiated using render() method, otherwise false
46
	 */
47
	get isInitialized() {
48
		return Utils.isDefined(this._rootElement);
49
	}
50

  
51
	/**
52
	 * @public
53
	 * @returns {boolean} true if the modal window is visible at the moment, otherwise false
54
	 */
55
	get isVisible() {
56
		return this._rootElement.hasAttribute('hidden');
57
	}
58

  
59
	/**
60
	 * Opens the modal window.
61
	 * @public
62
	 */
63
	open() {
64
		this._rootElement.removeAttribute('hidden');
65
	}
66

  
67
	/**
68
	 * Closes the modal window.
69
	 * @public
70
	 */
71
	close() {
72
		this._rootElement.setAttribute('hidden', 'hidden');
73
	}
74
}
sources/src/main/webapp/js/components/generic/popup.js
1
class Popup {
2
	/**
3
	 * @public
4
	 * @returns {HTMLElement} newly created HTML DOM element
5
	 */
6
	render() {
7
		this._rootElement = DOM.h('div', {
8
			class: 'popup',
9
			hidden: 'hidden',
10
		});
11

  
12
		return this._rootElement;
13
	}
14

  
15
	/**
16
	 * @public
17
	 * @returns {boolean} true if the DOM element has been instantiated using render() method, otherwise false
18
	 */
19
	get isInitialized() {
20
		return Utils.isDefined(this._rootElement);
21
	}
22

  
23
	/**
24
	 * @returns {boolean} true if the popup is visible at the moment, otherwise false
25
	 */
26
	get isVisible() {
27
		return this._rootElement.hasAttribute('hidden');
28
	}
29

  
30
	/**
31
	 * Opens the popup.
32
	 */
33
	open() {
34
		this._rootElement.removeAttribute('hidden');
35
	}
36

  
37
	/**
38
	 * Closes the popup.
39
	 */
40
	close() {
41
		this._rootElement.setAttribute('hidden', 'hidden');
42
	}
43

  
44
	/**
45
	 * Toggles visibility of the popup.
46
	 */
47
	toggle() {
48
		if (this.isVisible) {
49
			this.open();
50
		} else {
51
			this.close();
52
		}
53
	}
54
}

Také k dispozici: Unified diff