2017-12-20 05:33:33 -06:00
|
|
|
import _ from 'lodash';
|
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
import Drop from 'tether-drop';
|
2016-02-21 11:08:44 -06:00
|
|
|
|
2016-03-01 14:01:41 -06:00
|
|
|
export function infoPopover() {
|
2016-02-21 11:08:44 -06:00
|
|
|
return {
|
2017-12-20 05:33:33 -06:00
|
|
|
restrict: 'E',
|
2016-04-15 18:56:39 -05:00
|
|
|
template: '<i class="fa fa-info-circle"></i>',
|
2016-02-22 03:17:35 -06:00
|
|
|
transclude: true,
|
|
|
|
link: function(scope, elem, attrs, ctrl, transclude) {
|
2017-12-31 05:26:02 -06:00
|
|
|
let offset = attrs.offset || '0 -10px';
|
|
|
|
let position = attrs.position || 'right middle';
|
|
|
|
let classes = 'drop-help drop-hide-out-of-bounds';
|
|
|
|
let openOn = 'hover';
|
2016-04-15 18:56:39 -05:00
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
elem.addClass('gf-form-help-icon');
|
2016-04-15 18:56:39 -05:00
|
|
|
|
2016-03-01 14:01:41 -06:00
|
|
|
if (attrs.wide) {
|
2017-12-20 05:33:33 -06:00
|
|
|
classes += ' drop-wide';
|
2016-03-01 14:01:41 -06:00
|
|
|
}
|
2016-02-22 03:17:35 -06:00
|
|
|
|
2016-04-15 18:56:39 -05:00
|
|
|
if (attrs.mode) {
|
2017-12-20 05:33:33 -06:00
|
|
|
elem.addClass('gf-form-help-icon--' + attrs.mode);
|
2016-04-15 18:56:39 -05:00
|
|
|
}
|
|
|
|
|
2016-02-22 03:17:35 -06:00
|
|
|
transclude(function(clone, newScope) {
|
2017-12-31 05:26:02 -06:00
|
|
|
let content = document.createElement('div');
|
2017-12-20 05:33:33 -06:00
|
|
|
content.className = 'markdown-html';
|
2017-10-07 03:31:39 -05:00
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
_.each(clone, node => {
|
2016-02-22 03:17:35 -06:00
|
|
|
content.appendChild(node);
|
|
|
|
});
|
|
|
|
|
2017-12-31 05:26:02 -06:00
|
|
|
let dropOptions = {
|
2016-04-15 18:56:39 -05:00
|
|
|
target: elem[0],
|
2016-02-22 03:17:35 -06:00
|
|
|
content: content,
|
2016-03-01 14:01:41 -06:00
|
|
|
position: position,
|
|
|
|
classes: classes,
|
2016-04-15 18:56:39 -05:00
|
|
|
openOn: openOn,
|
2016-04-16 11:03:29 -05:00
|
|
|
hoverOpenDelay: 400,
|
2016-02-22 03:17:35 -06:00
|
|
|
tetherOptions: {
|
2017-04-12 14:20:47 -05:00
|
|
|
offset: offset,
|
|
|
|
constraints: [
|
2017-12-19 09:06:54 -06:00
|
|
|
{
|
2017-12-20 05:33:33 -06:00
|
|
|
to: 'window',
|
|
|
|
attachment: 'together',
|
|
|
|
pin: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2017-12-31 05:26:02 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create drop in next digest after directive content is rendered.
|
|
|
|
scope.$applyAsync(() => {
|
|
|
|
let drop = new Drop(dropOptions);
|
2016-02-22 03:17:35 -06:00
|
|
|
|
2017-12-31 05:26:02 -06:00
|
|
|
let unbind = scope.$on('$destroy', function() {
|
|
|
|
drop.destroy();
|
|
|
|
unbind();
|
|
|
|
});
|
2016-02-22 03:17:35 -06:00
|
|
|
});
|
2016-02-21 11:08:44 -06:00
|
|
|
});
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2016-02-21 11:08:44 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.directive('infoPopover', infoPopover);
|