popover.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import $ from 'jquery';
  4. import coreModule from '../../core_module';
  5. import Drop from 'tether-drop';
  6. export function popoverDirective() {
  7. return {
  8. restrict: 'E',
  9. transclude: true,
  10. link: function(scope, elem, attrs, ctrl, transclude) {
  11. var inputElem = elem.prev();
  12. if (inputElem.length === 0) {
  13. console.log('Failed to find input element for popover');
  14. return;
  15. }
  16. var offset = attrs.offset || '0 -10px';
  17. transclude(function(clone, newScope) {
  18. var content = document.createElement("div");
  19. _.each(clone, (node) => {
  20. content.appendChild(node);
  21. });
  22. var drop = new Drop({
  23. target: inputElem[0],
  24. content: content,
  25. position: 'right middle',
  26. classes: 'drop-help',
  27. openOn: 'click',
  28. tetherOptions: {
  29. offset: offset
  30. }
  31. });
  32. // inputElem.on('focus.popover', function() {
  33. // drop.open();
  34. // });
  35. //
  36. // inputElem.on('blur.popover', function() {
  37. // close();
  38. // });
  39. scope.$on('$destroy', function() {
  40. drop.destroy();
  41. });
  42. });
  43. }
  44. };
  45. }
  46. coreModule.directive('gfPopover', popoverDirective);