popover.js 6.7 KB

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