tooltip_js 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/assets/javascripts/tooltip.js +589 -0
- data/lib/tooltip_js.rb +15 -0
- data/lib/tooltip_js/engine.rb +9 -0
- data/lib/tooltip_js/version.rb +5 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d4745efa11a8280027930a14d534b5e1ae2fcb0
|
4
|
+
data.tar.gz: 9f2a2993b9c77afb011a6ba63ce1d03db3b9f44c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc4fc78dc4f654cc2026c4543cf54a00c0ae2044119fe3e454ea1fca0207eccf4e0082612215719db4f28c5aa2bcb3a901b9d6e4b0b306dc8e93ffc41777e408
|
7
|
+
data.tar.gz: 433e8da23e3955ebaab0673b9193adca9e2712b6682356fcdaf93dccfb988d827ddd95434ba0cbe79c38f68edf4bffea2a3cb3eb36c1f60ce3650b96a5a97706
|
@@ -0,0 +1,589 @@
|
|
1
|
+
/**!
|
2
|
+
* @fileOverview Kickass library to create and place poppers near their reference elements.
|
3
|
+
* @version 1.3.1
|
4
|
+
* @license
|
5
|
+
* Copyright (c) 2016 Federico Zivolo and contributors
|
6
|
+
*
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
12
|
+
* furnished to do so, subject to the following conditions:
|
13
|
+
*
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
15
|
+
* copies or substantial portions of the Software.
|
16
|
+
*
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
* SOFTWARE.
|
24
|
+
*/
|
25
|
+
(function (global, factory) {
|
26
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('popper.js')) :
|
27
|
+
typeof define === 'function' && define.amd ? define(['popper.js'], factory) :
|
28
|
+
(global.Tooltip = factory(global.Popper));
|
29
|
+
}(this, (function (Popper) { 'use strict';
|
30
|
+
|
31
|
+
Popper = Popper && Popper.hasOwnProperty('default') ? Popper['default'] : Popper;
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Check if the given variable is a function
|
35
|
+
* @method
|
36
|
+
* @memberof Popper.Utils
|
37
|
+
* @argument {Any} functionToCheck - variable to check
|
38
|
+
* @returns {Boolean} answer to: is a function?
|
39
|
+
*/
|
40
|
+
function isFunction(functionToCheck) {
|
41
|
+
var getType = {};
|
42
|
+
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
|
43
|
+
}
|
44
|
+
|
45
|
+
var classCallCheck = function (instance, Constructor) {
|
46
|
+
if (!(instance instanceof Constructor)) {
|
47
|
+
throw new TypeError("Cannot call a class as a function");
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
var createClass = function () {
|
52
|
+
function defineProperties(target, props) {
|
53
|
+
for (var i = 0; i < props.length; i++) {
|
54
|
+
var descriptor = props[i];
|
55
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
56
|
+
descriptor.configurable = true;
|
57
|
+
if ("value" in descriptor) descriptor.writable = true;
|
58
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
return function (Constructor, protoProps, staticProps) {
|
63
|
+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
64
|
+
if (staticProps) defineProperties(Constructor, staticProps);
|
65
|
+
return Constructor;
|
66
|
+
};
|
67
|
+
}();
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
var _extends = Object.assign || function (target) {
|
76
|
+
for (var i = 1; i < arguments.length; i++) {
|
77
|
+
var source = arguments[i];
|
78
|
+
|
79
|
+
for (var key in source) {
|
80
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
81
|
+
target[key] = source[key];
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
return target;
|
87
|
+
};
|
88
|
+
|
89
|
+
var DEFAULT_OPTIONS = {
|
90
|
+
container: false,
|
91
|
+
delay: 0,
|
92
|
+
html: false,
|
93
|
+
placement: 'top',
|
94
|
+
title: '',
|
95
|
+
template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
|
96
|
+
trigger: 'hover focus',
|
97
|
+
offset: 0,
|
98
|
+
arrowSelector: '.tooltip-arrow, .tooltip__arrow',
|
99
|
+
innerSelector: '.tooltip-inner, .tooltip__inner'
|
100
|
+
};
|
101
|
+
|
102
|
+
var Tooltip = function () {
|
103
|
+
/**
|
104
|
+
* Create a new Tooltip.js instance
|
105
|
+
* @class Tooltip
|
106
|
+
* @param {HTMLElement} reference - The DOM node used as reference of the tooltip (it can be a jQuery element).
|
107
|
+
* @param {Object} options
|
108
|
+
* @param {String} options.placement='top'
|
109
|
+
* Placement of the popper accepted values: `top(-start, -end), right(-start, -end), bottom(-start, -end),
|
110
|
+
* left(-start, -end)`
|
111
|
+
* @param {String} options.arrowSelector='.tooltip-arrow, .tooltip__arrow' - className used to locate the DOM arrow element in the tooltip.
|
112
|
+
* @param {String} options.innerSelector='.tooltip-inner, .tooltip__inner' - className used to locate the DOM inner element in the tooltip.
|
113
|
+
* @param {HTMLElement|String|false} options.container=false - Append the tooltip to a specific element.
|
114
|
+
* @param {Number|Object} options.delay=0
|
115
|
+
* Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type.
|
116
|
+
* If a number is supplied, delay is applied to both hide/show.
|
117
|
+
* Object structure is: `{ show: 500, hide: 100 }`
|
118
|
+
* @param {Boolean} options.html=false - Insert HTML into the tooltip. If false, the content will inserted with `textContent`.
|
119
|
+
* @param {String} [options.template='<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>']
|
120
|
+
* Base HTML to used when creating the tooltip.
|
121
|
+
* The tooltip's `title` will be injected into the `.tooltip-inner` or `.tooltip__inner`.
|
122
|
+
* `.tooltip-arrow` or `.tooltip__arrow` will become the tooltip's arrow.
|
123
|
+
* The outermost wrapper element should have the `.tooltip` class.
|
124
|
+
* @param {String|HTMLElement|TitleFunction} options.title='' - Default title value if `title` attribute isn't present.
|
125
|
+
* @param {String} [options.trigger='hover focus']
|
126
|
+
* How tooltip is triggered - click, hover, focus, manual.
|
127
|
+
* You may pass multiple triggers; separate them with a space. `manual` cannot be combined with any other trigger.
|
128
|
+
* @param {Boolean} options.closeOnClickOutside=false - Close a popper on click outside of the popper and reference element. This has effect only when options.trigger is 'click'.
|
129
|
+
* @param {String|HTMLElement} options.boundariesElement
|
130
|
+
* The element used as boundaries for the tooltip. For more information refer to Popper.js'
|
131
|
+
* [boundariesElement docs](https://popper.js.org/popper-documentation.html)
|
132
|
+
* @param {Number|String} options.offset=0 - Offset of the tooltip relative to its reference. For more information refer to Popper.js'
|
133
|
+
* [offset docs](https://popper.js.org/popper-documentation.html)
|
134
|
+
* @param {Object} options.popperOptions={} - Popper options, will be passed directly to popper instance. For more information refer to Popper.js'
|
135
|
+
* [options docs](https://popper.js.org/popper-documentation.html)
|
136
|
+
* @return {Object} instance - The generated tooltip instance
|
137
|
+
*/
|
138
|
+
function Tooltip(reference, options) {
|
139
|
+
classCallCheck(this, Tooltip);
|
140
|
+
|
141
|
+
_initialiseProps.call(this);
|
142
|
+
|
143
|
+
// apply user options over default ones
|
144
|
+
options = _extends({}, DEFAULT_OPTIONS, options);
|
145
|
+
|
146
|
+
reference.jquery && (reference = reference[0]);
|
147
|
+
|
148
|
+
// cache reference and options
|
149
|
+
this.reference = reference;
|
150
|
+
this.options = options;
|
151
|
+
|
152
|
+
// get events list
|
153
|
+
var events = typeof options.trigger === 'string' ? options.trigger.split(' ').filter(function (trigger) {
|
154
|
+
return ['click', 'hover', 'focus'].indexOf(trigger) !== -1;
|
155
|
+
}) : [];
|
156
|
+
|
157
|
+
// set initial state
|
158
|
+
this._isOpen = false;
|
159
|
+
this._popperOptions = {};
|
160
|
+
|
161
|
+
// set event listeners
|
162
|
+
this._setEventListeners(reference, events, options);
|
163
|
+
}
|
164
|
+
|
165
|
+
//
|
166
|
+
// Public methods
|
167
|
+
//
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Reveals an element's tooltip. This is considered a "manual" triggering of the tooltip.
|
171
|
+
* Tooltips with zero-length titles are never displayed.
|
172
|
+
* @method Tooltip#show
|
173
|
+
* @memberof Tooltip
|
174
|
+
*/
|
175
|
+
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Hides an element’s tooltip. This is considered a “manual” triggering of the tooltip.
|
179
|
+
* @method Tooltip#hide
|
180
|
+
* @memberof Tooltip
|
181
|
+
*/
|
182
|
+
|
183
|
+
|
184
|
+
/**
|
185
|
+
* Hides and destroys an element’s tooltip.
|
186
|
+
* @method Tooltip#dispose
|
187
|
+
* @memberof Tooltip
|
188
|
+
*/
|
189
|
+
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Toggles an element’s tooltip. This is considered a “manual” triggering of the tooltip.
|
193
|
+
* @method Tooltip#toggle
|
194
|
+
* @memberof Tooltip
|
195
|
+
*/
|
196
|
+
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Updates the tooltip's title content
|
200
|
+
* @method Tooltip#updateTitleContent
|
201
|
+
* @memberof Tooltip
|
202
|
+
* @param {String|HTMLElement} title - The new content to use for the title
|
203
|
+
*/
|
204
|
+
|
205
|
+
|
206
|
+
//
|
207
|
+
// Private methods
|
208
|
+
//
|
209
|
+
|
210
|
+
createClass(Tooltip, [{
|
211
|
+
key: '_create',
|
212
|
+
|
213
|
+
|
214
|
+
/**
|
215
|
+
* Creates a new tooltip node
|
216
|
+
* @memberof Tooltip
|
217
|
+
* @private
|
218
|
+
* @param {HTMLElement} reference
|
219
|
+
* @param {String} template
|
220
|
+
* @param {String|HTMLElement|TitleFunction} title
|
221
|
+
* @param {Boolean} allowHtml
|
222
|
+
* @return {HTMLElement} tooltipNode
|
223
|
+
*/
|
224
|
+
value: function _create(reference, template, title, allowHtml) {
|
225
|
+
// create tooltip element
|
226
|
+
var tooltipGenerator = window.document.createElement('div');
|
227
|
+
tooltipGenerator.innerHTML = template.trim();
|
228
|
+
var tooltipNode = tooltipGenerator.childNodes[0];
|
229
|
+
|
230
|
+
// add unique ID to our tooltip (needed for accessibility reasons)
|
231
|
+
tooltipNode.id = 'tooltip_' + Math.random().toString(36).substr(2, 10);
|
232
|
+
|
233
|
+
// set initial `aria-hidden` state to `false` (it's visible!)
|
234
|
+
tooltipNode.setAttribute('aria-hidden', 'false');
|
235
|
+
|
236
|
+
// add title to tooltip
|
237
|
+
var titleNode = tooltipGenerator.querySelector(this.options.innerSelector);
|
238
|
+
this._addTitleContent(reference, title, allowHtml, titleNode);
|
239
|
+
|
240
|
+
// return the generated tooltip node
|
241
|
+
return tooltipNode;
|
242
|
+
}
|
243
|
+
}, {
|
244
|
+
key: '_addTitleContent',
|
245
|
+
value: function _addTitleContent(reference, title, allowHtml, titleNode) {
|
246
|
+
if (title.nodeType === 1 || title.nodeType === 11) {
|
247
|
+
// if title is a element node or document fragment, append it only if allowHtml is true
|
248
|
+
allowHtml && titleNode.appendChild(title);
|
249
|
+
} else if (isFunction(title)) {
|
250
|
+
// if title is a function, call it and set textContent or innerHtml depending by `allowHtml` value
|
251
|
+
var titleText = title.call(reference);
|
252
|
+
allowHtml ? titleNode.innerHTML = titleText : titleNode.textContent = titleText;
|
253
|
+
} else {
|
254
|
+
// if it's just a simple text, set textContent or innerHtml depending by `allowHtml` value
|
255
|
+
allowHtml ? titleNode.innerHTML = title : titleNode.textContent = title;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
}, {
|
259
|
+
key: '_show',
|
260
|
+
value: function _show(reference, options) {
|
261
|
+
// don't show if it's already visible
|
262
|
+
// or if it's not being showed
|
263
|
+
if (this._isOpen && !this._isOpening) {
|
264
|
+
return this;
|
265
|
+
}
|
266
|
+
this._isOpen = true;
|
267
|
+
|
268
|
+
// if the tooltipNode already exists, just show it
|
269
|
+
if (this._tooltipNode) {
|
270
|
+
this._tooltipNode.style.visibility = 'visible';
|
271
|
+
this._tooltipNode.setAttribute('aria-hidden', 'false');
|
272
|
+
this.popperInstance.update();
|
273
|
+
return this;
|
274
|
+
}
|
275
|
+
|
276
|
+
// get title
|
277
|
+
var title = reference.getAttribute('title') || options.title;
|
278
|
+
|
279
|
+
// don't show tooltip if no title is defined
|
280
|
+
if (!title) {
|
281
|
+
return this;
|
282
|
+
}
|
283
|
+
|
284
|
+
// create tooltip node
|
285
|
+
var tooltipNode = this._create(reference, options.template, title, options.html);
|
286
|
+
|
287
|
+
// Add `aria-describedby` to our reference element for accessibility reasons
|
288
|
+
reference.setAttribute('aria-describedby', tooltipNode.id);
|
289
|
+
|
290
|
+
// append tooltip to container
|
291
|
+
var container = this._findContainer(options.container, reference);
|
292
|
+
|
293
|
+
this._append(tooltipNode, container);
|
294
|
+
|
295
|
+
this._popperOptions = _extends({}, options.popperOptions, {
|
296
|
+
placement: options.placement
|
297
|
+
});
|
298
|
+
|
299
|
+
this._popperOptions.modifiers = _extends({}, this._popperOptions.modifiers, {
|
300
|
+
arrow: {
|
301
|
+
element: this.options.arrowSelector
|
302
|
+
},
|
303
|
+
offset: {
|
304
|
+
offset: options.offset
|
305
|
+
}
|
306
|
+
});
|
307
|
+
|
308
|
+
if (options.boundariesElement) {
|
309
|
+
this._popperOptions.modifiers.preventOverflow = {
|
310
|
+
boundariesElement: options.boundariesElement
|
311
|
+
};
|
312
|
+
}
|
313
|
+
|
314
|
+
this.popperInstance = new Popper(reference, tooltipNode, this._popperOptions);
|
315
|
+
|
316
|
+
this._tooltipNode = tooltipNode;
|
317
|
+
|
318
|
+
return this;
|
319
|
+
}
|
320
|
+
}, {
|
321
|
+
key: '_hide',
|
322
|
+
value: function _hide() /*reference, options*/{
|
323
|
+
// don't hide if it's already hidden
|
324
|
+
if (!this._isOpen) {
|
325
|
+
return this;
|
326
|
+
}
|
327
|
+
|
328
|
+
this._isOpen = false;
|
329
|
+
|
330
|
+
// hide tooltipNode
|
331
|
+
this._tooltipNode.style.visibility = 'hidden';
|
332
|
+
this._tooltipNode.setAttribute('aria-hidden', 'true');
|
333
|
+
|
334
|
+
return this;
|
335
|
+
}
|
336
|
+
}, {
|
337
|
+
key: '_dispose',
|
338
|
+
value: function _dispose() {
|
339
|
+
var _this = this;
|
340
|
+
|
341
|
+
// remove event listeners first to prevent any unexpected behaviour
|
342
|
+
this._events.forEach(function (_ref) {
|
343
|
+
var func = _ref.func,
|
344
|
+
event = _ref.event;
|
345
|
+
|
346
|
+
_this.reference.removeEventListener(event, func);
|
347
|
+
});
|
348
|
+
this._events = [];
|
349
|
+
|
350
|
+
if (this._tooltipNode) {
|
351
|
+
this._hide();
|
352
|
+
|
353
|
+
// destroy instance
|
354
|
+
this.popperInstance.destroy();
|
355
|
+
|
356
|
+
// destroy tooltipNode if removeOnDestroy is not set, as popperInstance.destroy() already removes the element
|
357
|
+
if (!this.popperInstance.options.removeOnDestroy) {
|
358
|
+
this._tooltipNode.parentNode.removeChild(this._tooltipNode);
|
359
|
+
this._tooltipNode = null;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
return this;
|
363
|
+
}
|
364
|
+
}, {
|
365
|
+
key: '_findContainer',
|
366
|
+
value: function _findContainer(container, reference) {
|
367
|
+
// if container is a query, get the relative element
|
368
|
+
if (typeof container === 'string') {
|
369
|
+
container = window.document.querySelector(container);
|
370
|
+
} else if (container === false) {
|
371
|
+
// if container is `false`, set it to reference parent
|
372
|
+
container = reference.parentNode;
|
373
|
+
}
|
374
|
+
return container;
|
375
|
+
}
|
376
|
+
|
377
|
+
/**
|
378
|
+
* Append tooltip to container
|
379
|
+
* @memberof Tooltip
|
380
|
+
* @private
|
381
|
+
* @param {HTMLElement} tooltipNode
|
382
|
+
* @param {HTMLElement|String|false} container
|
383
|
+
*/
|
384
|
+
|
385
|
+
}, {
|
386
|
+
key: '_append',
|
387
|
+
value: function _append(tooltipNode, container) {
|
388
|
+
container.appendChild(tooltipNode);
|
389
|
+
}
|
390
|
+
}, {
|
391
|
+
key: '_setEventListeners',
|
392
|
+
value: function _setEventListeners(reference, events, options) {
|
393
|
+
var _this2 = this;
|
394
|
+
|
395
|
+
var directEvents = [];
|
396
|
+
var oppositeEvents = [];
|
397
|
+
|
398
|
+
events.forEach(function (event) {
|
399
|
+
switch (event) {
|
400
|
+
case 'hover':
|
401
|
+
directEvents.push('mouseenter');
|
402
|
+
oppositeEvents.push('mouseleave');
|
403
|
+
break;
|
404
|
+
case 'focus':
|
405
|
+
directEvents.push('focus');
|
406
|
+
oppositeEvents.push('blur');
|
407
|
+
break;
|
408
|
+
case 'click':
|
409
|
+
directEvents.push('click');
|
410
|
+
oppositeEvents.push('click');
|
411
|
+
break;
|
412
|
+
}
|
413
|
+
});
|
414
|
+
|
415
|
+
// schedule show tooltip
|
416
|
+
directEvents.forEach(function (event) {
|
417
|
+
var func = function func(evt) {
|
418
|
+
if (_this2._isOpening === true) {
|
419
|
+
return;
|
420
|
+
}
|
421
|
+
evt.usedByTooltip = true;
|
422
|
+
_this2._scheduleShow(reference, options.delay, options, evt);
|
423
|
+
};
|
424
|
+
_this2._events.push({ event: event, func: func });
|
425
|
+
reference.addEventListener(event, func);
|
426
|
+
});
|
427
|
+
|
428
|
+
// schedule hide tooltip
|
429
|
+
oppositeEvents.forEach(function (event) {
|
430
|
+
var func = function func(evt) {
|
431
|
+
if (evt.usedByTooltip === true) {
|
432
|
+
return;
|
433
|
+
}
|
434
|
+
_this2._scheduleHide(reference, options.delay, options, evt);
|
435
|
+
};
|
436
|
+
_this2._events.push({ event: event, func: func });
|
437
|
+
reference.addEventListener(event, func);
|
438
|
+
if (event === 'click' && options.closeOnClickOutside) {
|
439
|
+
document.addEventListener('mousedown', function (e) {
|
440
|
+
if (!_this2._isOpening) {
|
441
|
+
return;
|
442
|
+
}
|
443
|
+
var popper = _this2.popperInstance.popper;
|
444
|
+
if (reference.contains(e.target) || popper.contains(e.target)) {
|
445
|
+
return;
|
446
|
+
}
|
447
|
+
func(e);
|
448
|
+
}, true);
|
449
|
+
}
|
450
|
+
});
|
451
|
+
}
|
452
|
+
}, {
|
453
|
+
key: '_scheduleShow',
|
454
|
+
value: function _scheduleShow(reference, delay, options /*, evt */) {
|
455
|
+
var _this3 = this;
|
456
|
+
|
457
|
+
this._isOpening = true;
|
458
|
+
// defaults to 0
|
459
|
+
var computedDelay = delay && delay.show || delay || 0;
|
460
|
+
this._showTimeout = window.setTimeout(function () {
|
461
|
+
return _this3._show(reference, options);
|
462
|
+
}, computedDelay);
|
463
|
+
}
|
464
|
+
}, {
|
465
|
+
key: '_scheduleHide',
|
466
|
+
value: function _scheduleHide(reference, delay, options, evt) {
|
467
|
+
var _this4 = this;
|
468
|
+
|
469
|
+
this._isOpening = false;
|
470
|
+
// defaults to 0
|
471
|
+
var computedDelay = delay && delay.hide || delay || 0;
|
472
|
+
window.setTimeout(function () {
|
473
|
+
window.clearTimeout(_this4._showTimeout);
|
474
|
+
if (_this4._isOpen === false) {
|
475
|
+
return;
|
476
|
+
}
|
477
|
+
if (!document.body.contains(_this4._tooltipNode)) {
|
478
|
+
return;
|
479
|
+
}
|
480
|
+
|
481
|
+
// if we are hiding because of a mouseleave, we must check that the new
|
482
|
+
// reference isn't the tooltip, because in this case we don't want to hide it
|
483
|
+
if (evt.type === 'mouseleave') {
|
484
|
+
var isSet = _this4._setTooltipNodeEvent(evt, reference, delay, options);
|
485
|
+
|
486
|
+
// if we set the new event, don't hide the tooltip yet
|
487
|
+
// the new event will take care to hide it if necessary
|
488
|
+
if (isSet) {
|
489
|
+
return;
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
_this4._hide(reference, options);
|
494
|
+
}, computedDelay);
|
495
|
+
}
|
496
|
+
}, {
|
497
|
+
key: '_updateTitleContent',
|
498
|
+
value: function _updateTitleContent(title) {
|
499
|
+
if (typeof this._tooltipNode === 'undefined') {
|
500
|
+
if (typeof this.options.title !== 'undefined') {
|
501
|
+
this.options.title = title;
|
502
|
+
}
|
503
|
+
return;
|
504
|
+
}
|
505
|
+
var titleNode = this._tooltipNode.parentNode.querySelector(this.options.innerSelector);
|
506
|
+
this._clearTitleContent(titleNode, this.options.html, this.reference.getAttribute('title') || this.options.title);
|
507
|
+
this._addTitleContent(this.reference, title, this.options.html, titleNode);
|
508
|
+
this.options.title = title;
|
509
|
+
this.popperInstance.update();
|
510
|
+
}
|
511
|
+
}, {
|
512
|
+
key: '_clearTitleContent',
|
513
|
+
value: function _clearTitleContent(titleNode, allowHtml, lastTitle) {
|
514
|
+
if (lastTitle.nodeType === 1 || lastTitle.nodeType === 11) {
|
515
|
+
allowHtml && titleNode.removeChild(lastTitle);
|
516
|
+
} else {
|
517
|
+
allowHtml ? titleNode.innerHTML = '' : titleNode.textContent = '';
|
518
|
+
}
|
519
|
+
}
|
520
|
+
}]);
|
521
|
+
return Tooltip;
|
522
|
+
}();
|
523
|
+
|
524
|
+
/**
|
525
|
+
* Title function, its context is the Tooltip instance.
|
526
|
+
* @memberof Tooltip
|
527
|
+
* @callback TitleFunction
|
528
|
+
* @return {String} placement - The desired title.
|
529
|
+
*/
|
530
|
+
|
531
|
+
|
532
|
+
var _initialiseProps = function _initialiseProps() {
|
533
|
+
var _this5 = this;
|
534
|
+
|
535
|
+
this.show = function () {
|
536
|
+
return _this5._show(_this5.reference, _this5.options);
|
537
|
+
};
|
538
|
+
|
539
|
+
this.hide = function () {
|
540
|
+
return _this5._hide();
|
541
|
+
};
|
542
|
+
|
543
|
+
this.dispose = function () {
|
544
|
+
return _this5._dispose();
|
545
|
+
};
|
546
|
+
|
547
|
+
this.toggle = function () {
|
548
|
+
if (_this5._isOpen) {
|
549
|
+
return _this5.hide();
|
550
|
+
} else {
|
551
|
+
return _this5.show();
|
552
|
+
}
|
553
|
+
};
|
554
|
+
|
555
|
+
this.updateTitleContent = function (title) {
|
556
|
+
return _this5._updateTitleContent(title);
|
557
|
+
};
|
558
|
+
|
559
|
+
this._events = [];
|
560
|
+
|
561
|
+
this._setTooltipNodeEvent = function (evt, reference, delay, options) {
|
562
|
+
var relatedreference = evt.relatedreference || evt.toElement || evt.relatedTarget;
|
563
|
+
|
564
|
+
var callback = function callback(evt2) {
|
565
|
+
var relatedreference2 = evt2.relatedreference || evt2.toElement || evt2.relatedTarget;
|
566
|
+
|
567
|
+
// Remove event listener after call
|
568
|
+
_this5._tooltipNode.removeEventListener(evt.type, callback);
|
569
|
+
|
570
|
+
// If the new reference is not the reference element
|
571
|
+
if (!reference.contains(relatedreference2)) {
|
572
|
+
// Schedule to hide tooltip
|
573
|
+
_this5._scheduleHide(reference, options.delay, options, evt2);
|
574
|
+
}
|
575
|
+
};
|
576
|
+
|
577
|
+
if (_this5._tooltipNode.contains(relatedreference)) {
|
578
|
+
// listen to mouseleave on the tooltip element to be able to hide the tooltip
|
579
|
+
_this5._tooltipNode.addEventListener(evt.type, callback);
|
580
|
+
return true;
|
581
|
+
}
|
582
|
+
|
583
|
+
return false;
|
584
|
+
};
|
585
|
+
};
|
586
|
+
|
587
|
+
return Tooltip;
|
588
|
+
|
589
|
+
})));
|
data/lib/tooltip_js.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tooltip_js/version'
|
4
|
+
|
5
|
+
if defined?(::Rails)
|
6
|
+
require 'tooltip_js/engine'
|
7
|
+
else
|
8
|
+
gem_path = File.expand_path('..', File.dirname(__FILE__))
|
9
|
+
assets_path = File.join(gem_path, 'assets')
|
10
|
+
if defined?(::Sprockets)
|
11
|
+
Sprockets.append_path(File.join(assets_path, 'javascripts'))
|
12
|
+
elsif defined?(::Hanami)
|
13
|
+
Hanami::Assets.sources << assets_path
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tooltip_js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gleb Mazovetskiy
|
8
|
+
- Christoph Illnar
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-11-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.15'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.15'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rubocop
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: Works with Rails out of the box.
|
71
|
+
email:
|
72
|
+
- glex.spb@gmail.com
|
73
|
+
- illnar@communitor.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- assets/javascripts/tooltip.js
|
79
|
+
- lib/tooltip_js.rb
|
80
|
+
- lib/tooltip_js/engine.rb
|
81
|
+
- lib/tooltip_js/version.rb
|
82
|
+
homepage: https://github.com/mrillo/tooltip_js-rubygem
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.5.2.3
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Tooltip.js assets from Popper.js as a Ruby gem. https://popper.js.org/
|
106
|
+
test_files: []
|