@materializecss/materialize 2.0.1-alpha → 2.0.2-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Gruntfile.js +5 -2
- package/dist/css/materialize.css +90 -86
- package/dist/css/materialize.min.css +2 -2
- package/dist/js/materialize.js +2797 -2705
- package/dist/js/materialize.min.js +2 -8967
- package/dist/js/materialize.min.js.map +1 -1
- package/package.json +1 -1
- package/sass/components/_collapsible.scss +0 -41
- package/sass/components/_global.scss +3 -2
- package/sass/components/_icons-material-design.scss +2 -1
- package/sass/components/_navbar.scss +6 -3
- package/sass/components/_sidenav.scss +66 -37
- package/sass/components/_theme_variables.scss +2 -2
- package/sass/components/_typography.scss +2 -2
- package/sass/components/forms/_input-fields.scss +4 -10
- package/sass/materialize.scss +0 -4
- package/src/autocomplete.ts +188 -94
- package/src/buttons.ts +225 -260
- package/src/cards.ts +5 -6
- package/src/carousel.ts +611 -542
- package/src/characterCounter.ts +50 -21
- package/src/chips.ts +152 -63
- package/src/collapsible.ts +97 -32
- package/src/component.ts +99 -10
- package/src/datepicker.ts +905 -726
- package/src/dropdown.ts +576 -484
- package/src/edges.ts +4 -4
- package/src/forms.ts +17 -14
- package/src/global.ts +55 -324
- package/src/materialbox.ts +354 -298
- package/src/modal.ts +296 -211
- package/src/parallax.ts +129 -105
- package/src/pushpin.ts +148 -103
- package/src/range.ts +166 -150
- package/src/scrollspy.ts +214 -174
- package/src/select.ts +434 -398
- package/src/sidenav.ts +447 -381
- package/src/slider.ts +421 -362
- package/src/tabs.ts +276 -222
- package/src/tapTarget.ts +246 -213
- package/src/timepicker.ts +738 -614
- package/src/toasts.ts +254 -230
- package/src/tooltip.ts +315 -252
- package/src/utils.ts +271 -0
- package/src/waves.ts +10 -10
package/src/tapTarget.ts
CHANGED
|
@@ -1,240 +1,273 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Utils } from "./utils";
|
|
2
|
+
import { Component, BaseOptions, InitElements, MElement, Openable } from "./component";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export interface TapTargetOptions extends BaseOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Callback function called when Tap Target is opened.
|
|
7
|
+
* @default null
|
|
8
|
+
*/
|
|
9
|
+
onOpen: (origin: HTMLElement) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Callback function called when Tap Target is closed.
|
|
12
|
+
* @default null
|
|
13
|
+
*/
|
|
14
|
+
onClose: (origin: HTMLElement) => void;
|
|
7
15
|
};
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
private _handleDocumentClickBound: (this: HTMLElement, ev: MouseEvent) => any;
|
|
14
|
-
private _origin: HTMLElement;
|
|
15
|
-
private _handleTargetClickBound: EventListenerOrEventListenerObject;
|
|
16
|
-
private originEl: HTMLElement;
|
|
17
|
-
private _handleOriginClickBound: any;
|
|
18
|
-
private _handleThrottledResizeBound: any;
|
|
19
|
-
private waveEl: HTMLElement & Element & Node;
|
|
20
|
-
private contentEl: HTMLElement;
|
|
21
|
-
|
|
22
|
-
constructor(el, options) {
|
|
23
|
-
super(TapTarget, el, options);
|
|
24
|
-
(this.el as any).M_TapTarget = this;
|
|
25
|
-
this.options = {...TapTarget.defaults, ...options};
|
|
26
|
-
this.isOpen = false;
|
|
27
|
-
// setup
|
|
28
|
-
this._origin = document.querySelector('#'+this.el.getAttribute('data-target'));
|
|
29
|
-
this._setup();
|
|
30
|
-
this._calculatePositioning();
|
|
31
|
-
this._setupEventHandlers();
|
|
32
|
-
}
|
|
17
|
+
let _defaults: TapTargetOptions = {
|
|
18
|
+
onOpen: null,
|
|
19
|
+
onClose: null
|
|
20
|
+
};
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
export class TapTarget extends Component<TapTargetOptions> implements Openable {
|
|
23
|
+
/**
|
|
24
|
+
* If the tap target is open.
|
|
25
|
+
*/
|
|
26
|
+
isOpen: boolean;
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
private wrapper: HTMLElement;
|
|
29
|
+
private _origin: HTMLElement;
|
|
30
|
+
private originEl: HTMLElement;
|
|
31
|
+
private waveEl: HTMLElement & Element & Node;
|
|
32
|
+
private contentEl: HTMLElement;
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
34
|
+
constructor(el: HTMLElement, options: Partial<TapTargetOptions>) {
|
|
35
|
+
super(el, options, TapTarget);
|
|
36
|
+
(this.el as any).M_TapTarget = this;
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
38
|
+
this.options = {
|
|
39
|
+
...TapTarget.defaults,
|
|
40
|
+
...options
|
|
41
|
+
};
|
|
51
42
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let throttledResize = M.throttle(this._handleResize, 200);
|
|
60
|
-
this._handleThrottledResizeBound = throttledResize.bind(this);
|
|
61
|
-
window.addEventListener('resize', this._handleThrottledResizeBound);
|
|
62
|
-
}
|
|
43
|
+
this.isOpen = false;
|
|
44
|
+
// setup
|
|
45
|
+
this._origin = document.querySelector(`#${el.dataset.target}`);
|
|
46
|
+
this._setup();
|
|
47
|
+
this._calculatePositioning();
|
|
48
|
+
this._setupEventHandlers();
|
|
49
|
+
}
|
|
63
50
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
window.removeEventListener('resize', this._handleThrottledResizeBound);
|
|
68
|
-
}
|
|
51
|
+
static get defaults(): TapTargetOptions {
|
|
52
|
+
return _defaults;
|
|
53
|
+
}
|
|
69
54
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Initializes instance of TapTarget.
|
|
57
|
+
* @param el HTML element.
|
|
58
|
+
* @param options Component options.
|
|
59
|
+
*/
|
|
60
|
+
static init(el: HTMLElement, options?: Partial<TapTargetOptions>): TapTarget;
|
|
61
|
+
/**
|
|
62
|
+
* Initializes instances of TapTarget.
|
|
63
|
+
* @param els HTML elements.
|
|
64
|
+
* @param options Component options.
|
|
65
|
+
*/
|
|
66
|
+
static init(els: InitElements<MElement>, options?: Partial<TapTargetOptions>): TapTarget[];
|
|
67
|
+
/**
|
|
68
|
+
* Initializes instances of TapTarget.
|
|
69
|
+
* @param els HTML elements.
|
|
70
|
+
* @param options Component options.
|
|
71
|
+
*/
|
|
72
|
+
static init(els: HTMLElement | InitElements<MElement>, options: Partial<TapTargetOptions> = {}): TapTarget | TapTarget[] {
|
|
73
|
+
return super.init(els, options, TapTarget);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static getInstance(el: HTMLElement): TapTarget {
|
|
77
|
+
return (el as any).M_TapTarget;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
destroy() {
|
|
81
|
+
this._removeEventHandlers();
|
|
82
|
+
(this.el as any).TapTarget = undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_setupEventHandlers() {
|
|
86
|
+
this.el.addEventListener('click', this._handleTargetClick);
|
|
87
|
+
this.originEl.addEventListener('click', this._handleOriginClick);
|
|
88
|
+
// Resize
|
|
89
|
+
window.addEventListener('resize', this._handleThrottledResize);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_removeEventHandlers() {
|
|
93
|
+
this.el.removeEventListener('click', this._handleTargetClick);
|
|
94
|
+
this.originEl.removeEventListener('click', this._handleOriginClick);
|
|
95
|
+
window.removeEventListener('resize', this._handleThrottledResize);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
_handleThrottledResize: () => void = Utils.throttle(function(){ this._handleResize(); }, 200).bind(this);
|
|
99
|
+
|
|
100
|
+
_handleTargetClick = () => {
|
|
101
|
+
this.open();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_handleOriginClick = () => {
|
|
105
|
+
this.close();
|
|
106
|
+
}
|
|
73
107
|
|
|
74
|
-
|
|
108
|
+
_handleResize = () => {
|
|
109
|
+
this._calculatePositioning();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_handleDocumentClick = (e: MouseEvent | TouchEvent) => {
|
|
113
|
+
if (!(e.target as HTMLElement).closest('.tap-target-wrapper')) {
|
|
75
114
|
this.close();
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
e.stopPropagation();
|
|
76
117
|
}
|
|
118
|
+
}
|
|
77
119
|
|
|
78
|
-
|
|
79
|
-
|
|
120
|
+
_setup() {
|
|
121
|
+
// Creating tap target
|
|
122
|
+
this.wrapper = this.el.parentElement;
|
|
123
|
+
this.waveEl = this.wrapper.querySelector('.tap-target-wave');
|
|
124
|
+
this.originEl = this.wrapper.querySelector('.tap-target-origin');
|
|
125
|
+
this.contentEl = this.el.querySelector('.tap-target-content');
|
|
126
|
+
// Creating wrapper
|
|
127
|
+
if (!this.wrapper.classList.contains('.tap-target-wrapper')) {
|
|
128
|
+
this.wrapper = document.createElement('div');
|
|
129
|
+
this.wrapper.classList.add('tap-target-wrapper');
|
|
130
|
+
this.el.before(this.wrapper);
|
|
131
|
+
this.wrapper.append(this.el);
|
|
80
132
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
e.stopPropagation();
|
|
87
|
-
}
|
|
133
|
+
// Creating content
|
|
134
|
+
if (!this.contentEl) {
|
|
135
|
+
this.contentEl = document.createElement('div');
|
|
136
|
+
this.contentEl.classList.add('tap-target-content');
|
|
137
|
+
this.el.append(this.contentEl);
|
|
88
138
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.
|
|
93
|
-
|
|
94
|
-
this.originEl
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
100
|
-
this.el.before(this.wrapper);
|
|
101
|
-
this.wrapper.append(this.el);
|
|
102
|
-
}
|
|
103
|
-
// Creating content
|
|
104
|
-
if (!this.contentEl) {
|
|
105
|
-
this.contentEl = document.createElement('div');
|
|
106
|
-
this.contentEl.classList.add('tap-target-content');
|
|
107
|
-
this.el.append(this.contentEl);
|
|
108
|
-
}
|
|
109
|
-
// Creating foreground wave
|
|
110
|
-
if (!this.waveEl) {
|
|
111
|
-
this.waveEl = document.createElement('div');
|
|
112
|
-
this.waveEl.classList.add('tap-target-wave');
|
|
113
|
-
// Creating origin
|
|
114
|
-
if (!this.originEl) {
|
|
115
|
-
this.originEl = <HTMLElement>this._origin.cloneNode(true); // .clone(true, true);
|
|
116
|
-
this.originEl.classList.add('tap-target-origin');
|
|
117
|
-
this.originEl.removeAttribute('id');
|
|
118
|
-
this.originEl.removeAttribute('style');
|
|
119
|
-
this.waveEl.append(this.originEl);
|
|
120
|
-
}
|
|
121
|
-
this.wrapper.append(this.waveEl);
|
|
139
|
+
// Creating foreground wave
|
|
140
|
+
if (!this.waveEl) {
|
|
141
|
+
this.waveEl = document.createElement('div');
|
|
142
|
+
this.waveEl.classList.add('tap-target-wave');
|
|
143
|
+
// Creating origin
|
|
144
|
+
if (!this.originEl) {
|
|
145
|
+
this.originEl = <HTMLElement>this._origin.cloneNode(true); // .clone(true, true);
|
|
146
|
+
this.originEl.classList.add('tap-target-origin');
|
|
147
|
+
this.originEl.removeAttribute('id');
|
|
148
|
+
this.originEl.removeAttribute('style');
|
|
149
|
+
this.waveEl.append(this.originEl);
|
|
122
150
|
}
|
|
151
|
+
this.wrapper.append(this.waveEl);
|
|
123
152
|
}
|
|
153
|
+
}
|
|
124
154
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
155
|
+
private _offset(el: HTMLElement) {
|
|
156
|
+
const box = el.getBoundingClientRect();
|
|
157
|
+
const docElem = document.documentElement;
|
|
158
|
+
return {
|
|
159
|
+
top: box.top + window.pageYOffset - docElem.clientTop,
|
|
160
|
+
left: box.left + window.pageXOffset - docElem.clientLeft
|
|
161
|
+
};
|
|
162
|
+
}
|
|
133
163
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
let currentElem: any = this._origin;
|
|
140
|
-
const parents = [];
|
|
141
|
-
while ((currentElem = currentElem.parentNode) && currentElem !== document)
|
|
142
|
-
parents.push(currentElem);
|
|
143
|
-
|
|
144
|
-
for (let i = 0; i < parents.length; i++) {
|
|
145
|
-
isFixed = getComputedStyle(parents[i]).position === 'fixed';
|
|
146
|
-
if (isFixed) break;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
// Calculating origin
|
|
150
|
-
const originWidth = this._origin.offsetWidth;
|
|
151
|
-
const originHeight = this._origin.offsetHeight;
|
|
152
|
-
const originTop = isFixed ? this._offset(this._origin).top - M.getDocumentScrollTop() : this._offset(this._origin).top;
|
|
153
|
-
const originLeft = isFixed ? this._offset(this._origin).left - M.getDocumentScrollLeft() : this._offset(this._origin).left;
|
|
154
|
-
|
|
155
|
-
// Calculating screen
|
|
156
|
-
const windowWidth = window.innerWidth;
|
|
157
|
-
const windowHeight = window.innerHeight;
|
|
158
|
-
const scrollBarWidth = windowWidth - document.documentElement.clientWidth;
|
|
159
|
-
const centerX = windowWidth / 2;
|
|
160
|
-
const centerY = windowHeight / 2;
|
|
161
|
-
const isLeft = originLeft <= centerX;
|
|
162
|
-
const isRight = originLeft > centerX;
|
|
163
|
-
const isTop = originTop <= centerY;
|
|
164
|
-
const isBottom = originTop > centerY;
|
|
165
|
-
const isCenterX = originLeft >= windowWidth * 0.25 && originLeft <= windowWidth * 0.75;
|
|
166
|
-
|
|
167
|
-
// Calculating tap target
|
|
168
|
-
const tapTargetWidth = this.el.offsetWidth;
|
|
169
|
-
const tapTargetHeight = this.el.offsetHeight;
|
|
170
|
-
const tapTargetTop = originTop + originHeight / 2 - tapTargetHeight / 2;
|
|
171
|
-
const tapTargetLeft = originLeft + originWidth / 2 - tapTargetWidth / 2;
|
|
172
|
-
const tapTargetPosition = isFixed ? 'fixed' : 'absolute';
|
|
173
|
-
|
|
174
|
-
// Calculating content
|
|
175
|
-
const tapTargetTextWidth = isCenterX ? tapTargetWidth : tapTargetWidth / 2 + originWidth;
|
|
176
|
-
const tapTargetTextHeight = tapTargetHeight / 2;
|
|
177
|
-
const tapTargetTextTop = isTop ? tapTargetHeight / 2 : 0;
|
|
178
|
-
const tapTargetTextBottom = 0;
|
|
179
|
-
const tapTargetTextLeft = isLeft && !isCenterX ? tapTargetWidth / 2 - originWidth : 0;
|
|
180
|
-
const tapTargetTextRight = 0;
|
|
181
|
-
const tapTargetTextPadding = originWidth;
|
|
182
|
-
const tapTargetTextAlign = isBottom ? 'bottom' : 'top';
|
|
183
|
-
|
|
184
|
-
// Calculating wave
|
|
185
|
-
const tapTargetWaveWidth = originWidth > originHeight ? originWidth * 2 : originWidth * 2;
|
|
186
|
-
const tapTargetWaveHeight = tapTargetWaveWidth;
|
|
187
|
-
const tapTargetWaveTop = tapTargetHeight / 2 - tapTargetWaveHeight / 2;
|
|
188
|
-
const tapTargetWaveLeft = tapTargetWidth / 2 - tapTargetWaveWidth / 2;
|
|
189
|
-
|
|
190
|
-
// Setting tap target
|
|
191
|
-
this.wrapper.style.top = isTop ? tapTargetTop + 'px' : '';
|
|
192
|
-
this.wrapper.style.right = isRight ? windowWidth - tapTargetLeft - tapTargetWidth - scrollBarWidth + 'px' : '';
|
|
193
|
-
this.wrapper.style.bottom = isBottom ? windowHeight - tapTargetTop - tapTargetHeight + 'px' : '';
|
|
194
|
-
this.wrapper.style.left = isLeft ? tapTargetLeft + 'px' : '';
|
|
195
|
-
this.wrapper.style.position = tapTargetPosition;
|
|
196
|
-
|
|
197
|
-
// Setting content
|
|
198
|
-
this.contentEl.style.width = tapTargetTextWidth + 'px';
|
|
199
|
-
this.contentEl.style.height = tapTargetTextHeight + 'px';
|
|
200
|
-
this.contentEl.style.top = tapTargetTextTop + 'px';
|
|
201
|
-
this.contentEl.style.right = tapTargetTextRight + 'px';
|
|
202
|
-
this.contentEl.style.bottom = tapTargetTextBottom + 'px';
|
|
203
|
-
this.contentEl.style.left = tapTargetTextLeft + 'px';
|
|
204
|
-
this.contentEl.style.padding = tapTargetTextPadding + 'px';
|
|
205
|
-
this.contentEl.style.verticalAlign = tapTargetTextAlign;
|
|
206
|
-
|
|
207
|
-
// Setting wave
|
|
208
|
-
this.waveEl.style.top = tapTargetWaveTop+'px';
|
|
209
|
-
this.waveEl.style.left = tapTargetWaveLeft+'px';
|
|
210
|
-
this.waveEl.style.width = tapTargetWaveWidth+'px';
|
|
211
|
-
this.waveEl.style.height = tapTargetWaveHeight+'px';
|
|
212
|
-
}
|
|
164
|
+
_calculatePositioning() {
|
|
165
|
+
// Element or parent is fixed position?
|
|
166
|
+
let isFixed = getComputedStyle(this._origin).position === 'fixed';
|
|
167
|
+
if (!isFixed) {
|
|
213
168
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.options.onOpen.call(this, this._origin);
|
|
219
|
-
}
|
|
220
|
-
this.isOpen = true;
|
|
221
|
-
this.wrapper.classList.add('open');
|
|
222
|
-
document.body.addEventListener('click', this._handleDocumentClickBound, true);
|
|
223
|
-
document.body.addEventListener('touchend', this._handleDocumentClickBound);
|
|
224
|
-
}
|
|
169
|
+
let currentElem: any = this._origin;
|
|
170
|
+
const parents = [];
|
|
171
|
+
while ((currentElem = currentElem.parentNode) && currentElem !== document)
|
|
172
|
+
parents.push(currentElem);
|
|
225
173
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (typeof this.options.onClose === 'function') {
|
|
230
|
-
this.options.onClose.call(this, this._origin);
|
|
174
|
+
for (let i = 0; i < parents.length; i++) {
|
|
175
|
+
isFixed = getComputedStyle(parents[i]).position === 'fixed';
|
|
176
|
+
if (isFixed) break;
|
|
231
177
|
}
|
|
232
|
-
this.isOpen = false;
|
|
233
|
-
this.wrapper.classList.remove('open');
|
|
234
|
-
document.body.removeEventListener('click', this._handleDocumentClickBound, true);
|
|
235
|
-
document.body.removeEventListener('touchend', this._handleDocumentClickBound);
|
|
236
178
|
}
|
|
179
|
+
// Calculating origin
|
|
180
|
+
const originWidth = this._origin.offsetWidth;
|
|
181
|
+
const originHeight = this._origin.offsetHeight;
|
|
182
|
+
const originTop = isFixed ? this._offset(this._origin).top - Utils.getDocumentScrollTop() : this._offset(this._origin).top;
|
|
183
|
+
const originLeft = isFixed ? this._offset(this._origin).left - Utils.getDocumentScrollLeft() : this._offset(this._origin).left;
|
|
184
|
+
|
|
185
|
+
// Calculating screen
|
|
186
|
+
const windowWidth = window.innerWidth;
|
|
187
|
+
const windowHeight = window.innerHeight;
|
|
188
|
+
const scrollBarWidth = windowWidth - document.documentElement.clientWidth;
|
|
189
|
+
const centerX = windowWidth / 2;
|
|
190
|
+
const centerY = windowHeight / 2;
|
|
191
|
+
const isLeft = originLeft <= centerX;
|
|
192
|
+
const isRight = originLeft > centerX;
|
|
193
|
+
const isTop = originTop <= centerY;
|
|
194
|
+
const isBottom = originTop > centerY;
|
|
195
|
+
const isCenterX = originLeft >= windowWidth * 0.25 && originLeft <= windowWidth * 0.75;
|
|
196
|
+
|
|
197
|
+
// Calculating tap target
|
|
198
|
+
const tapTargetWidth = this.el.offsetWidth;
|
|
199
|
+
const tapTargetHeight = this.el.offsetHeight;
|
|
200
|
+
const tapTargetTop = originTop + originHeight / 2 - tapTargetHeight / 2;
|
|
201
|
+
const tapTargetLeft = originLeft + originWidth / 2 - tapTargetWidth / 2;
|
|
202
|
+
const tapTargetPosition = isFixed ? 'fixed' : 'absolute';
|
|
203
|
+
|
|
204
|
+
// Calculating content
|
|
205
|
+
const tapTargetTextWidth = isCenterX ? tapTargetWidth : tapTargetWidth / 2 + originWidth;
|
|
206
|
+
const tapTargetTextHeight = tapTargetHeight / 2;
|
|
207
|
+
const tapTargetTextTop = isTop ? tapTargetHeight / 2 : 0;
|
|
208
|
+
const tapTargetTextBottom = 0;
|
|
209
|
+
const tapTargetTextLeft = isLeft && !isCenterX ? tapTargetWidth / 2 - originWidth : 0;
|
|
210
|
+
const tapTargetTextRight = 0;
|
|
211
|
+
const tapTargetTextPadding = originWidth;
|
|
212
|
+
const tapTargetTextAlign = isBottom ? 'bottom' : 'top';
|
|
213
|
+
|
|
214
|
+
// Calculating wave
|
|
215
|
+
const tapTargetWaveWidth = originWidth > originHeight ? originWidth * 2 : originWidth * 2;
|
|
216
|
+
const tapTargetWaveHeight = tapTargetWaveWidth;
|
|
217
|
+
const tapTargetWaveTop = tapTargetHeight / 2 - tapTargetWaveHeight / 2;
|
|
218
|
+
const tapTargetWaveLeft = tapTargetWidth / 2 - tapTargetWaveWidth / 2;
|
|
219
|
+
|
|
220
|
+
// Setting tap target
|
|
221
|
+
this.wrapper.style.top = isTop ? tapTargetTop + 'px' : '';
|
|
222
|
+
this.wrapper.style.right = isRight ? windowWidth - tapTargetLeft - tapTargetWidth - scrollBarWidth + 'px' : '';
|
|
223
|
+
this.wrapper.style.bottom = isBottom ? windowHeight - tapTargetTop - tapTargetHeight + 'px' : '';
|
|
224
|
+
this.wrapper.style.left = isLeft ? tapTargetLeft + 'px' : '';
|
|
225
|
+
this.wrapper.style.position = tapTargetPosition;
|
|
226
|
+
|
|
227
|
+
// Setting content
|
|
228
|
+
this.contentEl.style.width = tapTargetTextWidth + 'px';
|
|
229
|
+
this.contentEl.style.height = tapTargetTextHeight + 'px';
|
|
230
|
+
this.contentEl.style.top = tapTargetTextTop + 'px';
|
|
231
|
+
this.contentEl.style.right = tapTargetTextRight + 'px';
|
|
232
|
+
this.contentEl.style.bottom = tapTargetTextBottom + 'px';
|
|
233
|
+
this.contentEl.style.left = tapTargetTextLeft + 'px';
|
|
234
|
+
this.contentEl.style.padding = tapTargetTextPadding + 'px';
|
|
235
|
+
this.contentEl.style.verticalAlign = tapTargetTextAlign;
|
|
236
|
+
|
|
237
|
+
// Setting wave
|
|
238
|
+
this.waveEl.style.top = tapTargetWaveTop+'px';
|
|
239
|
+
this.waveEl.style.left = tapTargetWaveLeft+'px';
|
|
240
|
+
this.waveEl.style.width = tapTargetWaveWidth+'px';
|
|
241
|
+
this.waveEl.style.height = tapTargetWaveHeight+'px';
|
|
237
242
|
}
|
|
238
243
|
|
|
239
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Open Tap Target.
|
|
246
|
+
*/
|
|
247
|
+
open = () => {
|
|
248
|
+
if (this.isOpen) return;
|
|
249
|
+
// onOpen callback
|
|
250
|
+
if (typeof this.options.onOpen === 'function') {
|
|
251
|
+
this.options.onOpen.call(this, this._origin);
|
|
252
|
+
}
|
|
253
|
+
this.isOpen = true;
|
|
254
|
+
this.wrapper.classList.add('open');
|
|
255
|
+
document.body.addEventListener('click', this._handleDocumentClick, true);
|
|
256
|
+
document.body.addEventListener('touchend', this._handleDocumentClick);
|
|
257
|
+
};
|
|
240
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Close Tap Target.
|
|
261
|
+
*/
|
|
262
|
+
close = () => {
|
|
263
|
+
if (!this.isOpen) return;
|
|
264
|
+
// onClose callback
|
|
265
|
+
if (typeof this.options.onClose === 'function') {
|
|
266
|
+
this.options.onClose.call(this, this._origin);
|
|
267
|
+
}
|
|
268
|
+
this.isOpen = false;
|
|
269
|
+
this.wrapper.classList.remove('open');
|
|
270
|
+
document.body.removeEventListener('click', this._handleDocumentClick, true);
|
|
271
|
+
document.body.removeEventListener('touchend', this._handleDocumentClick);
|
|
272
|
+
};
|
|
273
|
+
}
|