activeadmin_materialize_theme 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +26 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/config/activeadmin_materialize_theme_manifest.js +1 -0
  6. data/app/assets/javascripts/activeadmin_materialize_theme.js +65 -0
  7. data/app/assets/javascripts/materialize/anime.min.js +34 -0
  8. data/app/assets/javascripts/materialize/autocomplete.js +450 -0
  9. data/app/assets/javascripts/materialize/bin/materialize.js +12374 -0
  10. data/app/assets/javascripts/materialize/bin/materialize.min.js +6 -0
  11. data/app/assets/javascripts/materialize/buttons.js +354 -0
  12. data/app/assets/javascripts/materialize/cards.js +40 -0
  13. data/app/assets/javascripts/materialize/carousel.js +717 -0
  14. data/app/assets/javascripts/materialize/cash.js +960 -0
  15. data/app/assets/javascripts/materialize/characterCounter.js +136 -0
  16. data/app/assets/javascripts/materialize/chips.js +481 -0
  17. data/app/assets/javascripts/materialize/collapsible.js +275 -0
  18. data/app/assets/javascripts/materialize/component.js +44 -0
  19. data/app/assets/javascripts/materialize/datepicker.js +975 -0
  20. data/app/assets/javascripts/materialize/dropdown.js +617 -0
  21. data/app/assets/javascripts/materialize/forms.js +275 -0
  22. data/app/assets/javascripts/materialize/global.js +427 -0
  23. data/app/assets/javascripts/materialize/materialbox.js +453 -0
  24. data/app/assets/javascripts/materialize/modal.js +382 -0
  25. data/app/assets/javascripts/materialize/parallax.js +138 -0
  26. data/app/assets/javascripts/materialize/pushpin.js +145 -0
  27. data/app/assets/javascripts/materialize/range.js +263 -0
  28. data/app/assets/javascripts/materialize/scrollspy.js +295 -0
  29. data/app/assets/javascripts/materialize/select.js +432 -0
  30. data/app/assets/javascripts/materialize/sidenav.js +580 -0
  31. data/app/assets/javascripts/materialize/slider.js +359 -0
  32. data/app/assets/javascripts/materialize/tabs.js +402 -0
  33. data/app/assets/javascripts/materialize/tapTarget.js +314 -0
  34. data/app/assets/javascripts/materialize/timepicker.js +647 -0
  35. data/app/assets/javascripts/materialize/toasts.js +310 -0
  36. data/app/assets/javascripts/materialize/tooltip.js +303 -0
  37. data/app/assets/javascripts/materialize/waves.js +335 -0
  38. data/app/assets/stylesheets/activeadmin_materialize_theme/base.scss +107 -0
  39. data/app/assets/stylesheets/activeadmin_materialize_theme/components/footer.scss +18 -0
  40. data/app/assets/stylesheets/activeadmin_materialize_theme/components/form.scss +140 -0
  41. data/app/assets/stylesheets/activeadmin_materialize_theme/components/header.scss +61 -0
  42. data/app/assets/stylesheets/activeadmin_materialize_theme/components/layout_index.scss +83 -0
  43. data/app/assets/stylesheets/activeadmin_materialize_theme/components/layout_show.scss +56 -0
  44. data/app/assets/stylesheets/activeadmin_materialize_theme/components/sidebar.scss +37 -0
  45. data/app/assets/stylesheets/activeadmin_materialize_theme/components/title_bar.scss +43 -0
  46. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/LICENSE +21 -0
  47. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/README.md +91 -0
  48. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_badges.scss +55 -0
  49. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_buttons.scss +322 -0
  50. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_cards.scss +195 -0
  51. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_carousel.scss +90 -0
  52. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_chips.scss +90 -0
  53. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_collapsible.scss +91 -0
  54. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_color-classes.scss +32 -0
  55. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_color-variables.scss +370 -0
  56. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_datepicker.scss +191 -0
  57. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_dropdown.scss +85 -0
  58. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_global.scss +769 -0
  59. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_grid.scss +156 -0
  60. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_icons-material-design.scss +5 -0
  61. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_materialbox.scss +43 -0
  62. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_modal.scss +94 -0
  63. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_navbar.scss +208 -0
  64. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_normalize.scss +447 -0
  65. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_preloader.scss +334 -0
  66. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_pulse.scss +34 -0
  67. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_sidenav.scss +216 -0
  68. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_slider.scss +92 -0
  69. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_table_of_contents.scss +33 -0
  70. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_tabs.scss +99 -0
  71. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_tapTarget.scss +103 -0
  72. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_timepicker.scss +183 -0
  73. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_toast.scss +58 -0
  74. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_tooltip.scss +32 -0
  75. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_transitions.scss +13 -0
  76. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_typography.scss +60 -0
  77. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_variables.scss +349 -0
  78. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/_waves.scss +114 -0
  79. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/forms/_checkboxes.scss +200 -0
  80. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/forms/_file-input.scss +44 -0
  81. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/forms/_forms.scss +22 -0
  82. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/forms/_input-fields.scss +354 -0
  83. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/forms/_radio-buttons.scss +115 -0
  84. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/forms/_range.scss +161 -0
  85. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/forms/_select.scss +180 -0
  86. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/components/forms/_switches.scss +89 -0
  87. data/app/assets/stylesheets/activeadmin_materialize_theme/materialize/materialize.scss +41 -0
  88. data/app/assets/stylesheets/activeadmin_materialize_theme/normalize.css +349 -0
  89. data/app/assets/stylesheets/activeadmin_materialize_theme/theme.scss +13 -0
  90. data/app/assets/stylesheets/activeadmin_materialize_theme/variables.scss +14 -0
  91. data/lib/activeadmin_materialize_theme.rb +6 -0
  92. data/lib/activeadmin_materialize_theme/engine.rb +7 -0
  93. data/lib/activeadmin_materialize_theme/version.rb +5 -0
  94. metadata +149 -0
@@ -0,0 +1,310 @@
1
+ (function($, anim) {
2
+ 'use strict';
3
+
4
+ let _defaults = {
5
+ html: '',
6
+ displayLength: 4000,
7
+ inDuration: 300,
8
+ outDuration: 375,
9
+ classes: '',
10
+ completeCallback: null,
11
+ activationPercent: 0.8
12
+ };
13
+
14
+ class Toast {
15
+ constructor(options) {
16
+ /**
17
+ * Options for the toast
18
+ * @member Toast#options
19
+ */
20
+ this.options = $.extend({}, Toast.defaults, options);
21
+ this.message = this.options.html;
22
+
23
+ /**
24
+ * Describes current pan state toast
25
+ * @type {Boolean}
26
+ */
27
+ this.panning = false;
28
+
29
+ /**
30
+ * Time remaining until toast is removed
31
+ */
32
+ this.timeRemaining = this.options.displayLength;
33
+
34
+ if (Toast._toasts.length === 0) {
35
+ Toast._createContainer();
36
+ }
37
+
38
+ // Create new toast
39
+ Toast._toasts.push(this);
40
+ let toastElement = this._createToast();
41
+ toastElement.M_Toast = this;
42
+ this.el = toastElement;
43
+ this.$el = $(toastElement);
44
+ this._animateIn();
45
+ this._setTimer();
46
+ }
47
+
48
+ static get defaults() {
49
+ return _defaults;
50
+ }
51
+
52
+ /**
53
+ * Get Instance
54
+ */
55
+ static getInstance(el) {
56
+ let domElem = !!el.jquery ? el[0] : el;
57
+ return domElem.M_Toast;
58
+ }
59
+
60
+ /**
61
+ * Append toast container and add event handlers
62
+ */
63
+ static _createContainer() {
64
+ let container = document.createElement('div');
65
+ container.setAttribute('id', 'toast-container');
66
+
67
+ // Add event handler
68
+ container.addEventListener('touchstart', Toast._onDragStart);
69
+ container.addEventListener('touchmove', Toast._onDragMove);
70
+ container.addEventListener('touchend', Toast._onDragEnd);
71
+
72
+ container.addEventListener('mousedown', Toast._onDragStart);
73
+ document.addEventListener('mousemove', Toast._onDragMove);
74
+ document.addEventListener('mouseup', Toast._onDragEnd);
75
+
76
+ document.body.appendChild(container);
77
+ Toast._container = container;
78
+ }
79
+
80
+ /**
81
+ * Remove toast container and event handlers
82
+ */
83
+ static _removeContainer() {
84
+ // Add event handler
85
+ document.removeEventListener('mousemove', Toast._onDragMove);
86
+ document.removeEventListener('mouseup', Toast._onDragEnd);
87
+
88
+ $(Toast._container).remove();
89
+ Toast._container = null;
90
+ }
91
+
92
+ /**
93
+ * Begin drag handler
94
+ * @param {Event} e
95
+ */
96
+ static _onDragStart(e) {
97
+ if (e.target && $(e.target).closest('.toast').length) {
98
+ let $toast = $(e.target).closest('.toast');
99
+ let toast = $toast[0].M_Toast;
100
+ toast.panning = true;
101
+ Toast._draggedToast = toast;
102
+ toast.el.classList.add('panning');
103
+ toast.el.style.transition = '';
104
+ toast.startingXPos = Toast._xPos(e);
105
+ toast.time = Date.now();
106
+ toast.xPos = Toast._xPos(e);
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Drag move handler
112
+ * @param {Event} e
113
+ */
114
+ static _onDragMove(e) {
115
+ if (!!Toast._draggedToast) {
116
+ e.preventDefault();
117
+ let toast = Toast._draggedToast;
118
+ toast.deltaX = Math.abs(toast.xPos - Toast._xPos(e));
119
+ toast.xPos = Toast._xPos(e);
120
+ toast.velocityX = toast.deltaX / (Date.now() - toast.time);
121
+ toast.time = Date.now();
122
+
123
+ let totalDeltaX = toast.xPos - toast.startingXPos;
124
+ let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
125
+ toast.el.style.transform = `translateX(${totalDeltaX}px)`;
126
+ toast.el.style.opacity = 1 - Math.abs(totalDeltaX / activationDistance);
127
+ }
128
+ }
129
+
130
+ /**
131
+ * End drag handler
132
+ */
133
+ static _onDragEnd() {
134
+ if (!!Toast._draggedToast) {
135
+ let toast = Toast._draggedToast;
136
+ toast.panning = false;
137
+ toast.el.classList.remove('panning');
138
+
139
+ let totalDeltaX = toast.xPos - toast.startingXPos;
140
+ let activationDistance = toast.el.offsetWidth * toast.options.activationPercent;
141
+ let shouldBeDismissed = Math.abs(totalDeltaX) > activationDistance || toast.velocityX > 1;
142
+
143
+ // Remove toast
144
+ if (shouldBeDismissed) {
145
+ toast.wasSwiped = true;
146
+ toast.dismiss();
147
+
148
+ // Animate toast back to original position
149
+ } else {
150
+ toast.el.style.transition = 'transform .2s, opacity .2s';
151
+ toast.el.style.transform = '';
152
+ toast.el.style.opacity = '';
153
+ }
154
+ Toast._draggedToast = null;
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Get x position of mouse or touch event
160
+ * @param {Event} e
161
+ */
162
+ static _xPos(e) {
163
+ if (e.targetTouches && e.targetTouches.length >= 1) {
164
+ return e.targetTouches[0].clientX;
165
+ }
166
+ // mouse event
167
+ return e.clientX;
168
+ }
169
+
170
+ /**
171
+ * Remove all toasts
172
+ */
173
+ static dismissAll() {
174
+ for (let toastIndex in Toast._toasts) {
175
+ Toast._toasts[toastIndex].dismiss();
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Create toast and append it to toast container
181
+ */
182
+ _createToast() {
183
+ let toast = document.createElement('div');
184
+ toast.classList.add('toast');
185
+
186
+ // Add custom classes onto toast
187
+ if (!!this.options.classes.length) {
188
+ $(toast).addClass(this.options.classes);
189
+ }
190
+
191
+ // Set content
192
+ if (
193
+ typeof HTMLElement === 'object'
194
+ ? this.message instanceof HTMLElement
195
+ : this.message &&
196
+ typeof this.message === 'object' &&
197
+ this.message !== null &&
198
+ this.message.nodeType === 1 &&
199
+ typeof this.message.nodeName === 'string'
200
+ ) {
201
+ toast.appendChild(this.message);
202
+
203
+ // Check if it is jQuery object
204
+ } else if (!!this.message.jquery) {
205
+ $(toast).append(this.message[0]);
206
+
207
+ // Insert as html;
208
+ } else {
209
+ toast.innerHTML = this.message;
210
+ }
211
+
212
+ // Append toasft
213
+ Toast._container.appendChild(toast);
214
+ return toast;
215
+ }
216
+
217
+ /**
218
+ * Animate in toast
219
+ */
220
+ _animateIn() {
221
+ // Animate toast in
222
+ anim({
223
+ targets: this.el,
224
+ top: 0,
225
+ opacity: 1,
226
+ duration: this.options.inDuration,
227
+ easing: 'easeOutCubic'
228
+ });
229
+ }
230
+
231
+ /**
232
+ * Create setInterval which automatically removes toast when timeRemaining >= 0
233
+ * has been reached
234
+ */
235
+ _setTimer() {
236
+ if (this.timeRemaining !== Infinity) {
237
+ this.counterInterval = setInterval(() => {
238
+ // If toast is not being dragged, decrease its time remaining
239
+ if (!this.panning) {
240
+ this.timeRemaining -= 20;
241
+ }
242
+
243
+ // Animate toast out
244
+ if (this.timeRemaining <= 0) {
245
+ this.dismiss();
246
+ }
247
+ }, 20);
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Dismiss toast with animation
253
+ */
254
+ dismiss() {
255
+ window.clearInterval(this.counterInterval);
256
+ let activationDistance = this.el.offsetWidth * this.options.activationPercent;
257
+
258
+ if (this.wasSwiped) {
259
+ this.el.style.transition = 'transform .05s, opacity .05s';
260
+ this.el.style.transform = `translateX(${activationDistance}px)`;
261
+ this.el.style.opacity = 0;
262
+ }
263
+
264
+ anim({
265
+ targets: this.el,
266
+ opacity: 0,
267
+ marginTop: -40,
268
+ duration: this.options.outDuration,
269
+ easing: 'easeOutExpo',
270
+ complete: () => {
271
+ // Call the optional callback
272
+ if (typeof this.options.completeCallback === 'function') {
273
+ this.options.completeCallback();
274
+ }
275
+ // Remove toast from DOM
276
+ this.$el.remove();
277
+ Toast._toasts.splice(Toast._toasts.indexOf(this), 1);
278
+ if (Toast._toasts.length === 0) {
279
+ Toast._removeContainer();
280
+ }
281
+ }
282
+ });
283
+ }
284
+ }
285
+
286
+ /**
287
+ * @static
288
+ * @memberof Toast
289
+ * @type {Array.<Toast>}
290
+ */
291
+ Toast._toasts = [];
292
+
293
+ /**
294
+ * @static
295
+ * @memberof Toast
296
+ */
297
+ Toast._container = null;
298
+
299
+ /**
300
+ * @static
301
+ * @memberof Toast
302
+ * @type {Toast}
303
+ */
304
+ Toast._draggedToast = null;
305
+
306
+ M.Toast = Toast;
307
+ M.toast = function(options) {
308
+ return new Toast(options);
309
+ };
310
+ })(cash, M.anime);
@@ -0,0 +1,303 @@
1
+ (function($, anim) {
2
+ 'use strict';
3
+
4
+ let _defaults = {
5
+ exitDelay: 200,
6
+ enterDelay: 0,
7
+ html: null,
8
+ margin: 5,
9
+ inDuration: 250,
10
+ outDuration: 200,
11
+ position: 'bottom',
12
+ transitionMovement: 10
13
+ };
14
+
15
+ /**
16
+ * @class
17
+ *
18
+ */
19
+ class Tooltip extends Component {
20
+ /**
21
+ * Construct Tooltip instance
22
+ * @constructor
23
+ * @param {Element} el
24
+ * @param {Object} options
25
+ */
26
+ constructor(el, options) {
27
+ super(Tooltip, el, options);
28
+
29
+ this.el.M_Tooltip = this;
30
+ this.options = $.extend({}, Tooltip.defaults, options);
31
+
32
+ this.isOpen = false;
33
+ this.isHovered = false;
34
+ this.isFocused = false;
35
+ this._appendTooltipEl();
36
+ this._setupEventHandlers();
37
+ }
38
+
39
+ static get defaults() {
40
+ return _defaults;
41
+ }
42
+
43
+ static init(els, options) {
44
+ return super.init(this, els, options);
45
+ }
46
+
47
+ /**
48
+ * Get Instance
49
+ */
50
+ static getInstance(el) {
51
+ let domElem = !!el.jquery ? el[0] : el;
52
+ return domElem.M_Tooltip;
53
+ }
54
+
55
+ /**
56
+ * Teardown component
57
+ */
58
+ destroy() {
59
+ $(this.tooltipEl).remove();
60
+ this._removeEventHandlers();
61
+ this.el.M_Tooltip = undefined;
62
+ }
63
+
64
+ _appendTooltipEl() {
65
+ let tooltipEl = document.createElement('div');
66
+ tooltipEl.classList.add('material-tooltip');
67
+ this.tooltipEl = tooltipEl;
68
+
69
+ let tooltipContentEl = document.createElement('div');
70
+ tooltipContentEl.classList.add('tooltip-content');
71
+ tooltipContentEl.innerHTML = this.options.html;
72
+ tooltipEl.appendChild(tooltipContentEl);
73
+ document.body.appendChild(tooltipEl);
74
+ }
75
+
76
+ _updateTooltipContent() {
77
+ this.tooltipEl.querySelector('.tooltip-content').innerHTML = this.options.html;
78
+ }
79
+
80
+ _setupEventHandlers() {
81
+ this._handleMouseEnterBound = this._handleMouseEnter.bind(this);
82
+ this._handleMouseLeaveBound = this._handleMouseLeave.bind(this);
83
+ this._handleFocusBound = this._handleFocus.bind(this);
84
+ this._handleBlurBound = this._handleBlur.bind(this);
85
+ this.el.addEventListener('mouseenter', this._handleMouseEnterBound);
86
+ this.el.addEventListener('mouseleave', this._handleMouseLeaveBound);
87
+ this.el.addEventListener('focus', this._handleFocusBound, true);
88
+ this.el.addEventListener('blur', this._handleBlurBound, true);
89
+ }
90
+
91
+ _removeEventHandlers() {
92
+ this.el.removeEventListener('mouseenter', this._handleMouseEnterBound);
93
+ this.el.removeEventListener('mouseleave', this._handleMouseLeaveBound);
94
+ this.el.removeEventListener('focus', this._handleFocusBound, true);
95
+ this.el.removeEventListener('blur', this._handleBlurBound, true);
96
+ }
97
+
98
+ open(isManual) {
99
+ if (this.isOpen) {
100
+ return;
101
+ }
102
+ isManual = isManual === undefined ? true : undefined; // Default value true
103
+ this.isOpen = true;
104
+ // Update tooltip content with HTML attribute options
105
+ this.options = $.extend({}, this.options, this._getAttributeOptions());
106
+ this._updateTooltipContent();
107
+ this._setEnterDelayTimeout(isManual);
108
+ }
109
+
110
+ close() {
111
+ if (!this.isOpen) {
112
+ return;
113
+ }
114
+
115
+ this.isHovered = false;
116
+ this.isFocused = false;
117
+ this.isOpen = false;
118
+ this._setExitDelayTimeout();
119
+ }
120
+
121
+ /**
122
+ * Create timeout which delays when the tooltip closes
123
+ */
124
+ _setExitDelayTimeout() {
125
+ clearTimeout(this._exitDelayTimeout);
126
+
127
+ this._exitDelayTimeout = setTimeout(() => {
128
+ if (this.isHovered || this.isFocused) {
129
+ return;
130
+ }
131
+
132
+ this._animateOut();
133
+ }, this.options.exitDelay);
134
+ }
135
+
136
+ /**
137
+ * Create timeout which delays when the toast closes
138
+ */
139
+ _setEnterDelayTimeout(isManual) {
140
+ clearTimeout(this._enterDelayTimeout);
141
+
142
+ this._enterDelayTimeout = setTimeout(() => {
143
+ if (!this.isHovered && !this.isFocused && !isManual) {
144
+ return;
145
+ }
146
+
147
+ this._animateIn();
148
+ }, this.options.enterDelay);
149
+ }
150
+
151
+ _positionTooltip() {
152
+ let origin = this.el,
153
+ tooltip = this.tooltipEl,
154
+ originHeight = origin.offsetHeight,
155
+ originWidth = origin.offsetWidth,
156
+ tooltipHeight = tooltip.offsetHeight,
157
+ tooltipWidth = tooltip.offsetWidth,
158
+ newCoordinates,
159
+ margin = this.options.margin,
160
+ targetTop,
161
+ targetLeft;
162
+
163
+ (this.xMovement = 0), (this.yMovement = 0);
164
+
165
+ targetTop = origin.getBoundingClientRect().top + M.getDocumentScrollTop();
166
+ targetLeft = origin.getBoundingClientRect().left + M.getDocumentScrollLeft();
167
+
168
+ if (this.options.position === 'top') {
169
+ targetTop += -tooltipHeight - margin;
170
+ targetLeft += originWidth / 2 - tooltipWidth / 2;
171
+ this.yMovement = -this.options.transitionMovement;
172
+ } else if (this.options.position === 'right') {
173
+ targetTop += originHeight / 2 - tooltipHeight / 2;
174
+ targetLeft += originWidth + margin;
175
+ this.xMovement = this.options.transitionMovement;
176
+ } else if (this.options.position === 'left') {
177
+ targetTop += originHeight / 2 - tooltipHeight / 2;
178
+ targetLeft += -tooltipWidth - margin;
179
+ this.xMovement = -this.options.transitionMovement;
180
+ } else {
181
+ targetTop += originHeight + margin;
182
+ targetLeft += originWidth / 2 - tooltipWidth / 2;
183
+ this.yMovement = this.options.transitionMovement;
184
+ }
185
+
186
+ newCoordinates = this._repositionWithinScreen(
187
+ targetLeft,
188
+ targetTop,
189
+ tooltipWidth,
190
+ tooltipHeight
191
+ );
192
+ $(tooltip).css({
193
+ top: newCoordinates.y + 'px',
194
+ left: newCoordinates.x + 'px'
195
+ });
196
+ }
197
+
198
+ _repositionWithinScreen(x, y, width, height) {
199
+ let scrollLeft = M.getDocumentScrollLeft();
200
+ let scrollTop = M.getDocumentScrollTop();
201
+ let newX = x - scrollLeft;
202
+ let newY = y - scrollTop;
203
+
204
+ let bounding = {
205
+ left: newX,
206
+ top: newY,
207
+ width: width,
208
+ height: height
209
+ };
210
+
211
+ let offset = this.options.margin + this.options.transitionMovement;
212
+ let edges = M.checkWithinContainer(document.body, bounding, offset);
213
+
214
+ if (edges.left) {
215
+ newX = offset;
216
+ } else if (edges.right) {
217
+ newX -= newX + width - window.innerWidth;
218
+ }
219
+
220
+ if (edges.top) {
221
+ newY = offset;
222
+ } else if (edges.bottom) {
223
+ newY -= newY + height - window.innerHeight;
224
+ }
225
+
226
+ return {
227
+ x: newX + scrollLeft,
228
+ y: newY + scrollTop
229
+ };
230
+ }
231
+
232
+ _animateIn() {
233
+ this._positionTooltip();
234
+ this.tooltipEl.style.visibility = 'visible';
235
+ anim.remove(this.tooltipEl);
236
+ anim({
237
+ targets: this.tooltipEl,
238
+ opacity: 1,
239
+ translateX: this.xMovement,
240
+ translateY: this.yMovement,
241
+ duration: this.options.inDuration,
242
+ easing: 'easeOutCubic'
243
+ });
244
+ }
245
+
246
+ _animateOut() {
247
+ anim.remove(this.tooltipEl);
248
+ anim({
249
+ targets: this.tooltipEl,
250
+ opacity: 0,
251
+ translateX: 0,
252
+ translateY: 0,
253
+ duration: this.options.outDuration,
254
+ easing: 'easeOutCubic'
255
+ });
256
+ }
257
+
258
+ _handleMouseEnter() {
259
+ this.isHovered = true;
260
+ this.isFocused = false; // Allows close of tooltip when opened by focus.
261
+ this.open(false);
262
+ }
263
+
264
+ _handleMouseLeave() {
265
+ this.isHovered = false;
266
+ this.isFocused = false; // Allows close of tooltip when opened by focus.
267
+ this.close();
268
+ }
269
+
270
+ _handleFocus() {
271
+ if (M.tabPressed) {
272
+ this.isFocused = true;
273
+ this.open(false);
274
+ }
275
+ }
276
+
277
+ _handleBlur() {
278
+ this.isFocused = false;
279
+ this.close();
280
+ }
281
+
282
+ _getAttributeOptions() {
283
+ let attributeOptions = {};
284
+ let tooltipTextOption = this.el.getAttribute('data-tooltip');
285
+ let positionOption = this.el.getAttribute('data-position');
286
+
287
+ if (tooltipTextOption) {
288
+ attributeOptions.html = tooltipTextOption;
289
+ }
290
+
291
+ if (positionOption) {
292
+ attributeOptions.position = positionOption;
293
+ }
294
+ return attributeOptions;
295
+ }
296
+ }
297
+
298
+ M.Tooltip = Tooltip;
299
+
300
+ if (M.jQueryLoaded) {
301
+ M.initializeJqueryWrapper(Tooltip, 'tooltip', 'M_Tooltip');
302
+ }
303
+ })(cash, M.anime);