salix/front/core/directives/popover.js

25 lines
715 B
JavaScript

import ngModule from '../module';
import Popover from '../components/popover';
import {kebabToCamel} from '../lib/string';
/**
* Directive used to open a popover.
*
* @return {Object} The directive
*/
export function directive() {
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
$element.on('click', function(event) {
if (event.defaultPrevented) return;
let popoverKey = kebabToCamel($attrs.vnPopover);
let popover = $scope[popoverKey];
if (popover instanceof Popover)
popover.show($element[0]);
});
}
};
}
ngModule.directive('vnPopover', directive);