@materializecss/materialize 1.2.0 → 1.2.2
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 +722 -712
- package/LICENSE +21 -21
- package/README.md +91 -91
- package/dist/css/materialize.css +78 -137
- package/dist/css/materialize.min.css +12 -12
- package/dist/js/materialize.js +1502 -1378
- package/dist/js/materialize.min.js +6 -6
- package/extras/noUiSlider/nouislider.css +403 -403
- package/extras/noUiSlider/nouislider.js +2147 -2147
- package/js/anime.min.js +34 -34
- package/js/autocomplete.js +479 -479
- package/js/buttons.js +354 -354
- package/js/cards.js +40 -40
- package/js/carousel.js +732 -732
- package/js/cash.js +960 -960
- package/js/characterCounter.js +136 -136
- package/js/chips.js +486 -486
- package/js/collapsible.js +275 -275
- package/js/component.js +44 -44
- package/js/datepicker.js +983 -983
- package/js/dropdown.js +669 -669
- package/js/forms.js +285 -285
- package/js/global.js +428 -428
- package/js/materialbox.js +453 -453
- package/js/modal.js +382 -382
- package/js/parallax.js +138 -138
- package/js/pushpin.js +148 -148
- package/js/range.js +263 -263
- package/js/scrollspy.js +295 -295
- package/js/select.js +391 -391
- package/js/sidenav.js +583 -583
- package/js/slider.js +497 -359
- package/js/tabs.js +402 -402
- package/js/tapTarget.js +315 -315
- package/js/timepicker.js +712 -712
- package/js/toasts.js +325 -325
- package/js/tooltip.js +320 -320
- package/js/waves.js +614 -614
- package/package.json +87 -84
- package/sass/components/_badges.scss +55 -55
- package/sass/components/_buttons.scss +322 -322
- package/sass/components/_cards.scss +195 -195
- package/sass/components/_carousel.scss +90 -90
- package/sass/components/_chips.scss +96 -96
- package/sass/components/_collapsible.scss +91 -91
- package/sass/components/_collection.scss +106 -106
- package/sass/components/_color-classes.scss +32 -32
- package/sass/components/_color-variables.scss +370 -370
- package/sass/components/_datepicker.scss +191 -191
- package/sass/components/_dropdown.scss +84 -84
- package/sass/components/_global.scss +646 -646
- package/sass/components/_grid.scss +158 -158
- package/sass/components/_icons-material-design.scss +5 -5
- package/sass/components/_materialbox.scss +42 -42
- package/sass/components/_modal.scss +97 -97
- package/sass/components/_navbar.scss +208 -208
- package/sass/components/_normalize.scss +447 -447
- package/sass/components/_preloader.scss +334 -334
- package/sass/components/_pulse.scss +34 -34
- package/sass/components/_sidenav.scss +214 -214
- package/sass/components/_slider.scss +100 -91
- package/sass/components/_table_of_contents.scss +33 -33
- package/sass/components/_tabs.scss +99 -99
- package/sass/components/_tapTarget.scss +103 -103
- package/sass/components/_timepicker.scss +199 -199
- package/sass/components/_toast.scss +58 -58
- package/sass/components/_tooltip.scss +32 -32
- package/sass/components/_transitions.scss +12 -12
- package/sass/components/_typography.scss +62 -62
- package/sass/components/_variables.scss +352 -352
- package/sass/components/_waves.scss +187 -187
- package/sass/components/forms/_checkboxes.scss +200 -200
- package/sass/components/forms/_file-input.scss +44 -44
- package/sass/components/forms/_forms.scss +22 -22
- package/sass/components/forms/_input-fields.scss +388 -388
- package/sass/components/forms/_radio-buttons.scss +115 -115
- package/sass/components/forms/_range.scss +161 -161
- package/sass/components/forms/_select.scss +199 -199
- package/sass/components/forms/_switches.scss +91 -91
- package/sass/materialize.scss +42 -42
- package/sass/_style.scss +0 -929
- package/sass/ghpages-materialize.scss +0 -7
package/js/tapTarget.js
CHANGED
|
@@ -1,315 +1,315 @@
|
|
|
1
|
-
(function($) {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
let _defaults = {
|
|
5
|
-
onOpen: undefined,
|
|
6
|
-
onClose: undefined
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @class
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
class TapTarget extends Component {
|
|
14
|
-
/**
|
|
15
|
-
* Construct TapTarget instance
|
|
16
|
-
* @constructor
|
|
17
|
-
* @param {Element} el
|
|
18
|
-
* @param {Object} options
|
|
19
|
-
*/
|
|
20
|
-
constructor(el, options) {
|
|
21
|
-
super(TapTarget, el, options);
|
|
22
|
-
|
|
23
|
-
this.el.M_TapTarget = this;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Options for the select
|
|
27
|
-
* @member TapTarget#options
|
|
28
|
-
* @prop {Function} onOpen - Callback function called when feature discovery is opened
|
|
29
|
-
* @prop {Function} onClose - Callback function called when feature discovery is closed
|
|
30
|
-
*/
|
|
31
|
-
this.options = $.extend({}, TapTarget.defaults, options);
|
|
32
|
-
|
|
33
|
-
this.isOpen = false;
|
|
34
|
-
|
|
35
|
-
// setup
|
|
36
|
-
this.$origin = $('#' + this.$el.attr('data-target'));
|
|
37
|
-
this._setup();
|
|
38
|
-
|
|
39
|
-
this._calculatePositioning();
|
|
40
|
-
this._setupEventHandlers();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static get defaults() {
|
|
44
|
-
return _defaults;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static init(els, options) {
|
|
48
|
-
return super.init(this, els, options);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Get Instance
|
|
53
|
-
*/
|
|
54
|
-
static getInstance(el) {
|
|
55
|
-
let domElem = !!el.jquery ? el[0] : el;
|
|
56
|
-
return domElem.M_TapTarget;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Teardown component
|
|
61
|
-
*/
|
|
62
|
-
destroy() {
|
|
63
|
-
this._removeEventHandlers();
|
|
64
|
-
this.el.TapTarget = undefined;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Setup Event Handlers
|
|
69
|
-
*/
|
|
70
|
-
_setupEventHandlers() {
|
|
71
|
-
this._handleDocumentClickBound = this._handleDocumentClick.bind(this);
|
|
72
|
-
this._handleTargetClickBound = this._handleTargetClick.bind(this);
|
|
73
|
-
this._handleOriginClickBound = this._handleOriginClick.bind(this);
|
|
74
|
-
|
|
75
|
-
this.el.addEventListener('click', this._handleTargetClickBound);
|
|
76
|
-
this.originEl.addEventListener('click', this._handleOriginClickBound);
|
|
77
|
-
|
|
78
|
-
// Resize
|
|
79
|
-
let throttledResize = M.throttle(this._handleResize, 200);
|
|
80
|
-
this._handleThrottledResizeBound = throttledResize.bind(this);
|
|
81
|
-
|
|
82
|
-
window.addEventListener('resize', this._handleThrottledResizeBound);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Remove Event Handlers
|
|
87
|
-
*/
|
|
88
|
-
_removeEventHandlers() {
|
|
89
|
-
this.el.removeEventListener('click', this._handleTargetClickBound);
|
|
90
|
-
this.originEl.removeEventListener('click', this._handleOriginClickBound);
|
|
91
|
-
window.removeEventListener('resize', this._handleThrottledResizeBound);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Handle Target Click
|
|
96
|
-
* @param {Event} e
|
|
97
|
-
*/
|
|
98
|
-
_handleTargetClick(e) {
|
|
99
|
-
this.open();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Handle Origin Click
|
|
104
|
-
* @param {Event} e
|
|
105
|
-
*/
|
|
106
|
-
_handleOriginClick(e) {
|
|
107
|
-
this.close();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Handle Resize
|
|
112
|
-
* @param {Event} e
|
|
113
|
-
*/
|
|
114
|
-
_handleResize(e) {
|
|
115
|
-
this._calculatePositioning();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Handle Resize
|
|
120
|
-
* @param {Event} e
|
|
121
|
-
*/
|
|
122
|
-
_handleDocumentClick(e) {
|
|
123
|
-
if (!$(e.target).closest('.tap-target-wrapper').length) {
|
|
124
|
-
this.close();
|
|
125
|
-
e.preventDefault();
|
|
126
|
-
e.stopPropagation();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Setup Tap Target
|
|
132
|
-
*/
|
|
133
|
-
_setup() {
|
|
134
|
-
// Creating tap target
|
|
135
|
-
this.wrapper = this.$el.parent()[0];
|
|
136
|
-
this.waveEl = $(this.wrapper).find('.tap-target-wave')[0];
|
|
137
|
-
this.originEl = $(this.wrapper).find('.tap-target-origin')[0];
|
|
138
|
-
this.contentEl = this.$el.find('.tap-target-content')[0];
|
|
139
|
-
|
|
140
|
-
// Creating wrapper
|
|
141
|
-
if (!$(this.wrapper).hasClass('.tap-target-wrapper')) {
|
|
142
|
-
this.wrapper = document.createElement('div');
|
|
143
|
-
this.wrapper.classList.add('tap-target-wrapper');
|
|
144
|
-
this.$el.before($(this.wrapper));
|
|
145
|
-
this.wrapper.append(this.el);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Creating content
|
|
149
|
-
if (!this.contentEl) {
|
|
150
|
-
this.contentEl = document.createElement('div');
|
|
151
|
-
this.contentEl.classList.add('tap-target-content');
|
|
152
|
-
this.$el.append(this.contentEl);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Creating foreground wave
|
|
156
|
-
if (!this.waveEl) {
|
|
157
|
-
this.waveEl = document.createElement('div');
|
|
158
|
-
this.waveEl.classList.add('tap-target-wave');
|
|
159
|
-
|
|
160
|
-
// Creating origin
|
|
161
|
-
if (!this.originEl) {
|
|
162
|
-
this.originEl = this.$origin.clone(true, true);
|
|
163
|
-
this.originEl.addClass('tap-target-origin');
|
|
164
|
-
this.originEl.removeAttr('id');
|
|
165
|
-
this.originEl.removeAttr('style');
|
|
166
|
-
this.originEl = this.originEl[0];
|
|
167
|
-
this.waveEl.append(this.originEl);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
this.wrapper.append(this.waveEl);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Calculate positioning
|
|
176
|
-
*/
|
|
177
|
-
_calculatePositioning() {
|
|
178
|
-
// Element or parent is fixed position?
|
|
179
|
-
let isFixed = this.$origin.css('position') === 'fixed';
|
|
180
|
-
if (!isFixed) {
|
|
181
|
-
let parents = this.$origin.parents();
|
|
182
|
-
for (let i = 0; i < parents.length; i++) {
|
|
183
|
-
isFixed = $(parents[i]).css('position') == 'fixed';
|
|
184
|
-
if (isFixed) {
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Calculating origin
|
|
191
|
-
let originWidth = this.$origin.outerWidth();
|
|
192
|
-
let originHeight = this.$origin.outerHeight();
|
|
193
|
-
let originTop = isFixed
|
|
194
|
-
? this.$origin.offset().top - M.getDocumentScrollTop()
|
|
195
|
-
: this.$origin.offset().top;
|
|
196
|
-
let originLeft = isFixed
|
|
197
|
-
? this.$origin.offset().left - M.getDocumentScrollLeft()
|
|
198
|
-
: this.$origin.offset().left;
|
|
199
|
-
|
|
200
|
-
// Calculating screen
|
|
201
|
-
let windowWidth = window.innerWidth;
|
|
202
|
-
let windowHeight = window.innerHeight;
|
|
203
|
-
let scrollBarWidth = windowWidth - document.documentElement.clientWidth;
|
|
204
|
-
let centerX = windowWidth / 2;
|
|
205
|
-
let centerY = windowHeight / 2;
|
|
206
|
-
let isLeft = originLeft <= centerX;
|
|
207
|
-
let isRight = originLeft > centerX;
|
|
208
|
-
let isTop = originTop <= centerY;
|
|
209
|
-
let isBottom = originTop > centerY;
|
|
210
|
-
let isCenterX = originLeft >= windowWidth * 0.25 && originLeft <= windowWidth * 0.75;
|
|
211
|
-
|
|
212
|
-
// Calculating tap target
|
|
213
|
-
let tapTargetWidth = this.$el.outerWidth();
|
|
214
|
-
let tapTargetHeight = this.$el.outerHeight();
|
|
215
|
-
let tapTargetTop = originTop + originHeight / 2 - tapTargetHeight / 2;
|
|
216
|
-
let tapTargetLeft = originLeft + originWidth / 2 - tapTargetWidth / 2;
|
|
217
|
-
let tapTargetPosition = isFixed ? 'fixed' : 'absolute';
|
|
218
|
-
|
|
219
|
-
// Calculating content
|
|
220
|
-
let tapTargetTextWidth = isCenterX ? tapTargetWidth : tapTargetWidth / 2 + originWidth;
|
|
221
|
-
let tapTargetTextHeight = tapTargetHeight / 2;
|
|
222
|
-
let tapTargetTextTop = isTop ? tapTargetHeight / 2 : 0;
|
|
223
|
-
let tapTargetTextBottom = 0;
|
|
224
|
-
let tapTargetTextLeft = isLeft && !isCenterX ? tapTargetWidth / 2 - originWidth : 0;
|
|
225
|
-
let tapTargetTextRight = 0;
|
|
226
|
-
let tapTargetTextPadding = originWidth;
|
|
227
|
-
let tapTargetTextAlign = isBottom ? 'bottom' : 'top';
|
|
228
|
-
|
|
229
|
-
// Calculating wave
|
|
230
|
-
let tapTargetWaveWidth = originWidth > originHeight ? originWidth * 2 : originWidth * 2;
|
|
231
|
-
let tapTargetWaveHeight = tapTargetWaveWidth;
|
|
232
|
-
let tapTargetWaveTop = tapTargetHeight / 2 - tapTargetWaveHeight / 2;
|
|
233
|
-
let tapTargetWaveLeft = tapTargetWidth / 2 - tapTargetWaveWidth / 2;
|
|
234
|
-
|
|
235
|
-
// Setting tap target
|
|
236
|
-
let tapTargetWrapperCssObj = {};
|
|
237
|
-
tapTargetWrapperCssObj.top = isTop ? tapTargetTop + 'px' : '';
|
|
238
|
-
tapTargetWrapperCssObj.right = isRight
|
|
239
|
-
? windowWidth - tapTargetLeft - tapTargetWidth - scrollBarWidth + 'px'
|
|
240
|
-
: '';
|
|
241
|
-
tapTargetWrapperCssObj.bottom = isBottom
|
|
242
|
-
? windowHeight - tapTargetTop - tapTargetHeight + 'px'
|
|
243
|
-
: '';
|
|
244
|
-
tapTargetWrapperCssObj.left = isLeft ? tapTargetLeft + 'px' : '';
|
|
245
|
-
tapTargetWrapperCssObj.position = tapTargetPosition;
|
|
246
|
-
$(this.wrapper).css(tapTargetWrapperCssObj);
|
|
247
|
-
|
|
248
|
-
// Setting content
|
|
249
|
-
$(this.contentEl).css({
|
|
250
|
-
width: tapTargetTextWidth + 'px',
|
|
251
|
-
height: tapTargetTextHeight + 'px',
|
|
252
|
-
top: tapTargetTextTop + 'px',
|
|
253
|
-
right: tapTargetTextRight + 'px',
|
|
254
|
-
bottom: tapTargetTextBottom + 'px',
|
|
255
|
-
left: tapTargetTextLeft + 'px',
|
|
256
|
-
padding: tapTargetTextPadding + 'px',
|
|
257
|
-
verticalAlign: tapTargetTextAlign
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// Setting wave
|
|
261
|
-
$(this.waveEl).css({
|
|
262
|
-
top: tapTargetWaveTop + 'px',
|
|
263
|
-
left: tapTargetWaveLeft + 'px',
|
|
264
|
-
width: tapTargetWaveWidth + 'px',
|
|
265
|
-
height: tapTargetWaveHeight + 'px'
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Open TapTarget
|
|
271
|
-
*/
|
|
272
|
-
open() {
|
|
273
|
-
if (this.isOpen) {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// onOpen callback
|
|
278
|
-
if (typeof this.options.onOpen === 'function') {
|
|
279
|
-
this.options.onOpen.call(this, this.$origin[0]);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
this.isOpen = true;
|
|
283
|
-
this.wrapper.classList.add('open');
|
|
284
|
-
|
|
285
|
-
document.body.addEventListener('click', this._handleDocumentClickBound, true);
|
|
286
|
-
document.body.addEventListener('touchend', this._handleDocumentClickBound);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Close Tap Target
|
|
291
|
-
*/
|
|
292
|
-
close() {
|
|
293
|
-
if (!this.isOpen) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// onClose callback
|
|
298
|
-
if (typeof this.options.onClose === 'function') {
|
|
299
|
-
this.options.onClose.call(this, this.$origin[0]);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
this.isOpen = false;
|
|
303
|
-
this.wrapper.classList.remove('open');
|
|
304
|
-
|
|
305
|
-
document.body.removeEventListener('click', this._handleDocumentClickBound, true);
|
|
306
|
-
document.body.removeEventListener('touchend', this._handleDocumentClickBound);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
M.TapTarget = TapTarget;
|
|
311
|
-
|
|
312
|
-
if (M.jQueryLoaded) {
|
|
313
|
-
M.initializeJqueryWrapper(TapTarget, 'tapTarget', 'M_TapTarget');
|
|
314
|
-
}
|
|
315
|
-
})(cash);
|
|
1
|
+
(function($) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
let _defaults = {
|
|
5
|
+
onOpen: undefined,
|
|
6
|
+
onClose: undefined
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @class
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
class TapTarget extends Component {
|
|
14
|
+
/**
|
|
15
|
+
* Construct TapTarget instance
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param {Element} el
|
|
18
|
+
* @param {Object} options
|
|
19
|
+
*/
|
|
20
|
+
constructor(el, options) {
|
|
21
|
+
super(TapTarget, el, options);
|
|
22
|
+
|
|
23
|
+
this.el.M_TapTarget = this;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Options for the select
|
|
27
|
+
* @member TapTarget#options
|
|
28
|
+
* @prop {Function} onOpen - Callback function called when feature discovery is opened
|
|
29
|
+
* @prop {Function} onClose - Callback function called when feature discovery is closed
|
|
30
|
+
*/
|
|
31
|
+
this.options = $.extend({}, TapTarget.defaults, options);
|
|
32
|
+
|
|
33
|
+
this.isOpen = false;
|
|
34
|
+
|
|
35
|
+
// setup
|
|
36
|
+
this.$origin = $('#' + this.$el.attr('data-target'));
|
|
37
|
+
this._setup();
|
|
38
|
+
|
|
39
|
+
this._calculatePositioning();
|
|
40
|
+
this._setupEventHandlers();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static get defaults() {
|
|
44
|
+
return _defaults;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static init(els, options) {
|
|
48
|
+
return super.init(this, els, options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get Instance
|
|
53
|
+
*/
|
|
54
|
+
static getInstance(el) {
|
|
55
|
+
let domElem = !!el.jquery ? el[0] : el;
|
|
56
|
+
return domElem.M_TapTarget;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Teardown component
|
|
61
|
+
*/
|
|
62
|
+
destroy() {
|
|
63
|
+
this._removeEventHandlers();
|
|
64
|
+
this.el.TapTarget = undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Setup Event Handlers
|
|
69
|
+
*/
|
|
70
|
+
_setupEventHandlers() {
|
|
71
|
+
this._handleDocumentClickBound = this._handleDocumentClick.bind(this);
|
|
72
|
+
this._handleTargetClickBound = this._handleTargetClick.bind(this);
|
|
73
|
+
this._handleOriginClickBound = this._handleOriginClick.bind(this);
|
|
74
|
+
|
|
75
|
+
this.el.addEventListener('click', this._handleTargetClickBound);
|
|
76
|
+
this.originEl.addEventListener('click', this._handleOriginClickBound);
|
|
77
|
+
|
|
78
|
+
// Resize
|
|
79
|
+
let throttledResize = M.throttle(this._handleResize, 200);
|
|
80
|
+
this._handleThrottledResizeBound = throttledResize.bind(this);
|
|
81
|
+
|
|
82
|
+
window.addEventListener('resize', this._handleThrottledResizeBound);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Remove Event Handlers
|
|
87
|
+
*/
|
|
88
|
+
_removeEventHandlers() {
|
|
89
|
+
this.el.removeEventListener('click', this._handleTargetClickBound);
|
|
90
|
+
this.originEl.removeEventListener('click', this._handleOriginClickBound);
|
|
91
|
+
window.removeEventListener('resize', this._handleThrottledResizeBound);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Handle Target Click
|
|
96
|
+
* @param {Event} e
|
|
97
|
+
*/
|
|
98
|
+
_handleTargetClick(e) {
|
|
99
|
+
this.open();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Handle Origin Click
|
|
104
|
+
* @param {Event} e
|
|
105
|
+
*/
|
|
106
|
+
_handleOriginClick(e) {
|
|
107
|
+
this.close();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Handle Resize
|
|
112
|
+
* @param {Event} e
|
|
113
|
+
*/
|
|
114
|
+
_handleResize(e) {
|
|
115
|
+
this._calculatePositioning();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Handle Resize
|
|
120
|
+
* @param {Event} e
|
|
121
|
+
*/
|
|
122
|
+
_handleDocumentClick(e) {
|
|
123
|
+
if (!$(e.target).closest('.tap-target-wrapper').length) {
|
|
124
|
+
this.close();
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
e.stopPropagation();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Setup Tap Target
|
|
132
|
+
*/
|
|
133
|
+
_setup() {
|
|
134
|
+
// Creating tap target
|
|
135
|
+
this.wrapper = this.$el.parent()[0];
|
|
136
|
+
this.waveEl = $(this.wrapper).find('.tap-target-wave')[0];
|
|
137
|
+
this.originEl = $(this.wrapper).find('.tap-target-origin')[0];
|
|
138
|
+
this.contentEl = this.$el.find('.tap-target-content')[0];
|
|
139
|
+
|
|
140
|
+
// Creating wrapper
|
|
141
|
+
if (!$(this.wrapper).hasClass('.tap-target-wrapper')) {
|
|
142
|
+
this.wrapper = document.createElement('div');
|
|
143
|
+
this.wrapper.classList.add('tap-target-wrapper');
|
|
144
|
+
this.$el.before($(this.wrapper));
|
|
145
|
+
this.wrapper.append(this.el);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Creating content
|
|
149
|
+
if (!this.contentEl) {
|
|
150
|
+
this.contentEl = document.createElement('div');
|
|
151
|
+
this.contentEl.classList.add('tap-target-content');
|
|
152
|
+
this.$el.append(this.contentEl);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Creating foreground wave
|
|
156
|
+
if (!this.waveEl) {
|
|
157
|
+
this.waveEl = document.createElement('div');
|
|
158
|
+
this.waveEl.classList.add('tap-target-wave');
|
|
159
|
+
|
|
160
|
+
// Creating origin
|
|
161
|
+
if (!this.originEl) {
|
|
162
|
+
this.originEl = this.$origin.clone(true, true);
|
|
163
|
+
this.originEl.addClass('tap-target-origin');
|
|
164
|
+
this.originEl.removeAttr('id');
|
|
165
|
+
this.originEl.removeAttr('style');
|
|
166
|
+
this.originEl = this.originEl[0];
|
|
167
|
+
this.waveEl.append(this.originEl);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
this.wrapper.append(this.waveEl);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Calculate positioning
|
|
176
|
+
*/
|
|
177
|
+
_calculatePositioning() {
|
|
178
|
+
// Element or parent is fixed position?
|
|
179
|
+
let isFixed = this.$origin.css('position') === 'fixed';
|
|
180
|
+
if (!isFixed) {
|
|
181
|
+
let parents = this.$origin.parents();
|
|
182
|
+
for (let i = 0; i < parents.length; i++) {
|
|
183
|
+
isFixed = $(parents[i]).css('position') == 'fixed';
|
|
184
|
+
if (isFixed) {
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Calculating origin
|
|
191
|
+
let originWidth = this.$origin.outerWidth();
|
|
192
|
+
let originHeight = this.$origin.outerHeight();
|
|
193
|
+
let originTop = isFixed
|
|
194
|
+
? this.$origin.offset().top - M.getDocumentScrollTop()
|
|
195
|
+
: this.$origin.offset().top;
|
|
196
|
+
let originLeft = isFixed
|
|
197
|
+
? this.$origin.offset().left - M.getDocumentScrollLeft()
|
|
198
|
+
: this.$origin.offset().left;
|
|
199
|
+
|
|
200
|
+
// Calculating screen
|
|
201
|
+
let windowWidth = window.innerWidth;
|
|
202
|
+
let windowHeight = window.innerHeight;
|
|
203
|
+
let scrollBarWidth = windowWidth - document.documentElement.clientWidth;
|
|
204
|
+
let centerX = windowWidth / 2;
|
|
205
|
+
let centerY = windowHeight / 2;
|
|
206
|
+
let isLeft = originLeft <= centerX;
|
|
207
|
+
let isRight = originLeft > centerX;
|
|
208
|
+
let isTop = originTop <= centerY;
|
|
209
|
+
let isBottom = originTop > centerY;
|
|
210
|
+
let isCenterX = originLeft >= windowWidth * 0.25 && originLeft <= windowWidth * 0.75;
|
|
211
|
+
|
|
212
|
+
// Calculating tap target
|
|
213
|
+
let tapTargetWidth = this.$el.outerWidth();
|
|
214
|
+
let tapTargetHeight = this.$el.outerHeight();
|
|
215
|
+
let tapTargetTop = originTop + originHeight / 2 - tapTargetHeight / 2;
|
|
216
|
+
let tapTargetLeft = originLeft + originWidth / 2 - tapTargetWidth / 2;
|
|
217
|
+
let tapTargetPosition = isFixed ? 'fixed' : 'absolute';
|
|
218
|
+
|
|
219
|
+
// Calculating content
|
|
220
|
+
let tapTargetTextWidth = isCenterX ? tapTargetWidth : tapTargetWidth / 2 + originWidth;
|
|
221
|
+
let tapTargetTextHeight = tapTargetHeight / 2;
|
|
222
|
+
let tapTargetTextTop = isTop ? tapTargetHeight / 2 : 0;
|
|
223
|
+
let tapTargetTextBottom = 0;
|
|
224
|
+
let tapTargetTextLeft = isLeft && !isCenterX ? tapTargetWidth / 2 - originWidth : 0;
|
|
225
|
+
let tapTargetTextRight = 0;
|
|
226
|
+
let tapTargetTextPadding = originWidth;
|
|
227
|
+
let tapTargetTextAlign = isBottom ? 'bottom' : 'top';
|
|
228
|
+
|
|
229
|
+
// Calculating wave
|
|
230
|
+
let tapTargetWaveWidth = originWidth > originHeight ? originWidth * 2 : originWidth * 2;
|
|
231
|
+
let tapTargetWaveHeight = tapTargetWaveWidth;
|
|
232
|
+
let tapTargetWaveTop = tapTargetHeight / 2 - tapTargetWaveHeight / 2;
|
|
233
|
+
let tapTargetWaveLeft = tapTargetWidth / 2 - tapTargetWaveWidth / 2;
|
|
234
|
+
|
|
235
|
+
// Setting tap target
|
|
236
|
+
let tapTargetWrapperCssObj = {};
|
|
237
|
+
tapTargetWrapperCssObj.top = isTop ? tapTargetTop + 'px' : '';
|
|
238
|
+
tapTargetWrapperCssObj.right = isRight
|
|
239
|
+
? windowWidth - tapTargetLeft - tapTargetWidth - scrollBarWidth + 'px'
|
|
240
|
+
: '';
|
|
241
|
+
tapTargetWrapperCssObj.bottom = isBottom
|
|
242
|
+
? windowHeight - tapTargetTop - tapTargetHeight + 'px'
|
|
243
|
+
: '';
|
|
244
|
+
tapTargetWrapperCssObj.left = isLeft ? tapTargetLeft + 'px' : '';
|
|
245
|
+
tapTargetWrapperCssObj.position = tapTargetPosition;
|
|
246
|
+
$(this.wrapper).css(tapTargetWrapperCssObj);
|
|
247
|
+
|
|
248
|
+
// Setting content
|
|
249
|
+
$(this.contentEl).css({
|
|
250
|
+
width: tapTargetTextWidth + 'px',
|
|
251
|
+
height: tapTargetTextHeight + 'px',
|
|
252
|
+
top: tapTargetTextTop + 'px',
|
|
253
|
+
right: tapTargetTextRight + 'px',
|
|
254
|
+
bottom: tapTargetTextBottom + 'px',
|
|
255
|
+
left: tapTargetTextLeft + 'px',
|
|
256
|
+
padding: tapTargetTextPadding + 'px',
|
|
257
|
+
verticalAlign: tapTargetTextAlign
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// Setting wave
|
|
261
|
+
$(this.waveEl).css({
|
|
262
|
+
top: tapTargetWaveTop + 'px',
|
|
263
|
+
left: tapTargetWaveLeft + 'px',
|
|
264
|
+
width: tapTargetWaveWidth + 'px',
|
|
265
|
+
height: tapTargetWaveHeight + 'px'
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Open TapTarget
|
|
271
|
+
*/
|
|
272
|
+
open() {
|
|
273
|
+
if (this.isOpen) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// onOpen callback
|
|
278
|
+
if (typeof this.options.onOpen === 'function') {
|
|
279
|
+
this.options.onOpen.call(this, this.$origin[0]);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
this.isOpen = true;
|
|
283
|
+
this.wrapper.classList.add('open');
|
|
284
|
+
|
|
285
|
+
document.body.addEventListener('click', this._handleDocumentClickBound, true);
|
|
286
|
+
document.body.addEventListener('touchend', this._handleDocumentClickBound);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Close Tap Target
|
|
291
|
+
*/
|
|
292
|
+
close() {
|
|
293
|
+
if (!this.isOpen) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// onClose callback
|
|
298
|
+
if (typeof this.options.onClose === 'function') {
|
|
299
|
+
this.options.onClose.call(this, this.$origin[0]);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
this.isOpen = false;
|
|
303
|
+
this.wrapper.classList.remove('open');
|
|
304
|
+
|
|
305
|
+
document.body.removeEventListener('click', this._handleDocumentClickBound, true);
|
|
306
|
+
document.body.removeEventListener('touchend', this._handleDocumentClickBound);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
M.TapTarget = TapTarget;
|
|
311
|
+
|
|
312
|
+
if (M.jQueryLoaded) {
|
|
313
|
+
M.initializeJqueryWrapper(TapTarget, 'tapTarget', 'M_TapTarget');
|
|
314
|
+
}
|
|
315
|
+
})(cash);
|