forked from mrjoelkemp/assets-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtooltip.js
31 lines (22 loc) · 880 Bytes
/
tooltip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
define(['jquery'], function($) {
'use strict';
function tooltip($context, message, classes) {
var $formItem, $tooltip, positionOffset;
classes = classes || [];
$formItem = $context.closest('.js-form-item, .form-item');
if (!$formItem.length) {
$formItem = $context;
}
$tooltip = $('<div>' + message + '</div>')
.addClass(classes.join(' '))
.appendTo($formItem);
positionOffset = $context[0].offsetParent == null ? 0 : $context.position().top;
// Have to hard code 8 in here as it's the border-height of
// the :after style that creates a triangle
$tooltip.css('top', -(($tooltip.outerHeight() + 8) - positionOffset));
// Apply class to form-item element since certain error sytles require that.
$formItem.addClass('form-item-error');
return $tooltip;
}
return tooltip;
});