popover.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. (function (global, factory) {
  2. if (typeof define === 'function' && define.amd) {
  3. define(['exports', 'module', './tooltip'], factory);
  4. } else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
  5. factory(exports, module, require('./tooltip'));
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory(mod.exports, mod, global.Tooltip);
  11. global.popover = mod.exports;
  12. }
  13. })(this, function (exports, module, _tooltip) {
  14. 'use strict';
  15. var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
  16. var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
  17. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  18. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  19. function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  20. var _Tooltip2 = _interopRequireDefault(_tooltip);
  21. /**
  22. * --------------------------------------------------------------------------
  23. * Bootstrap (v4.0.0-alpha.2): popover.js
  24. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  25. * --------------------------------------------------------------------------
  26. */
  27. var Popover = (function ($) {
  28. /**
  29. * ------------------------------------------------------------------------
  30. * Constants
  31. * ------------------------------------------------------------------------
  32. */
  33. var NAME = 'popover';
  34. var VERSION = '4.0.0-alpha';
  35. var DATA_KEY = 'bs.popover';
  36. var EVENT_KEY = '.' + DATA_KEY;
  37. var JQUERY_NO_CONFLICT = $.fn[NAME];
  38. var Default = $.extend({}, _Tooltip2['default'].Default, {
  39. placement: 'right',
  40. trigger: 'click',
  41. content: '',
  42. template: '<div class="popover" role="tooltip">' + '<div class="popover-arrow"></div>' + '<h3 class="popover-title"></h3>' + '<div class="popover-content"></div></div>'
  43. });
  44. var DefaultType = $.extend({}, _Tooltip2['default'].DefaultType, {
  45. content: '(string|element|function)'
  46. });
  47. var ClassName = {
  48. FADE: 'fade',
  49. IN: 'in'
  50. };
  51. var Selector = {
  52. TITLE: '.popover-title',
  53. CONTENT: '.popover-content',
  54. ARROW: '.popover-arrow'
  55. };
  56. var Event = {
  57. HIDE: 'hide' + EVENT_KEY,
  58. HIDDEN: 'hidden' + EVENT_KEY,
  59. SHOW: 'show' + EVENT_KEY,
  60. SHOWN: 'shown' + EVENT_KEY,
  61. INSERTED: 'inserted' + EVENT_KEY,
  62. CLICK: 'click' + EVENT_KEY,
  63. FOCUSIN: 'focusin' + EVENT_KEY,
  64. FOCUSOUT: 'focusout' + EVENT_KEY,
  65. MOUSEENTER: 'mouseenter' + EVENT_KEY,
  66. MOUSELEAVE: 'mouseleave' + EVENT_KEY
  67. };
  68. /**
  69. * ------------------------------------------------------------------------
  70. * Class Definition
  71. * ------------------------------------------------------------------------
  72. */
  73. var Popover = (function (_Tooltip) {
  74. _inherits(Popover, _Tooltip);
  75. function Popover() {
  76. _classCallCheck(this, Popover);
  77. _get(Object.getPrototypeOf(Popover.prototype), 'constructor', this).apply(this, arguments);
  78. }
  79. /**
  80. * ------------------------------------------------------------------------
  81. * jQuery
  82. * ------------------------------------------------------------------------
  83. */
  84. _createClass(Popover, [{
  85. key: 'isWithContent',
  86. // overrides
  87. value: function isWithContent() {
  88. return this.getTitle() || this._getContent();
  89. }
  90. }, {
  91. key: 'getTipElement',
  92. value: function getTipElement() {
  93. return this.tip = this.tip || $(this.config.template)[0];
  94. }
  95. }, {
  96. key: 'setContent',
  97. value: function setContent() {
  98. var $tip = $(this.getTipElement());
  99. // we use append for html objects to maintain js events
  100. this.setElementContent($tip.find(Selector.TITLE), this.getTitle());
  101. this.setElementContent($tip.find(Selector.CONTENT), this._getContent());
  102. $tip.removeClass(ClassName.FADE).removeClass(ClassName.IN);
  103. this.cleanupTether();
  104. }
  105. // private
  106. }, {
  107. key: '_getContent',
  108. value: function _getContent() {
  109. return this.element.getAttribute('data-content') || (typeof this.config.content === 'function' ? this.config.content.call(this.element) : this.config.content);
  110. }
  111. // static
  112. }], [{
  113. key: '_jQueryInterface',
  114. value: function _jQueryInterface(config) {
  115. return this.each(function () {
  116. var data = $(this).data(DATA_KEY);
  117. var _config = typeof config === 'object' ? config : null;
  118. if (!data && /destroy|hide/.test(config)) {
  119. return;
  120. }
  121. if (!data) {
  122. data = new Popover(this, _config);
  123. $(this).data(DATA_KEY, data);
  124. }
  125. if (typeof config === 'string') {
  126. if (data[config] === undefined) {
  127. throw new Error('No method named "' + config + '"');
  128. }
  129. data[config]();
  130. }
  131. });
  132. }
  133. }, {
  134. key: 'VERSION',
  135. // getters
  136. get: function get() {
  137. return VERSION;
  138. }
  139. }, {
  140. key: 'Default',
  141. get: function get() {
  142. return Default;
  143. }
  144. }, {
  145. key: 'NAME',
  146. get: function get() {
  147. return NAME;
  148. }
  149. }, {
  150. key: 'DATA_KEY',
  151. get: function get() {
  152. return DATA_KEY;
  153. }
  154. }, {
  155. key: 'Event',
  156. get: function get() {
  157. return Event;
  158. }
  159. }, {
  160. key: 'EVENT_KEY',
  161. get: function get() {
  162. return EVENT_KEY;
  163. }
  164. }, {
  165. key: 'DefaultType',
  166. get: function get() {
  167. return DefaultType;
  168. }
  169. }]);
  170. return Popover;
  171. })(_Tooltip2['default']);
  172. $.fn[NAME] = Popover._jQueryInterface;
  173. $.fn[NAME].Constructor = Popover;
  174. $.fn[NAME].noConflict = function () {
  175. $.fn[NAME] = JQUERY_NO_CONFLICT;
  176. return Popover._jQueryInterface;
  177. };
  178. return Popover;
  179. })(jQuery);
  180. module.exports = Popover;
  181. });