7727302b530546ed1ac9aa353ceff32cccd14f34.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  4. /**
  5. * --------------------------------------------------------------------------
  6. * Bootstrap (v4.0.0): tooltip.js
  7. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  8. * --------------------------------------------------------------------------
  9. */
  10. var Tooltip = (function ($) {
  11. /**
  12. * ------------------------------------------------------------------------
  13. * Constants
  14. * ------------------------------------------------------------------------
  15. */
  16. var NAME = 'tooltip';
  17. var VERSION = '4.0.0';
  18. var DATA_KEY = 'bs.tooltip';
  19. var EVENT_KEY = '.' + DATA_KEY;
  20. var JQUERY_NO_CONFLICT = $.fn[NAME];
  21. var TRANSITION_DURATION = 150;
  22. var CLASS_PREFIX = 'bs-tether';
  23. var Default = {
  24. animation: true,
  25. template: '<div class="tooltip" role="tooltip">' + '<div class="tooltip-arrow"></div>' + '<div class="tooltip-inner"></div></div>',
  26. trigger: 'hover focus',
  27. title: '',
  28. delay: 0,
  29. html: false,
  30. selector: false,
  31. placement: 'top',
  32. offset: '0 0',
  33. constraints: []
  34. };
  35. var DefaultType = {
  36. animation: 'boolean',
  37. template: 'string',
  38. title: '(string|function)',
  39. trigger: 'string',
  40. delay: '(number|object)',
  41. html: 'boolean',
  42. selector: '(string|boolean)',
  43. placement: '(string|function)',
  44. offset: 'string',
  45. constraints: 'array'
  46. };
  47. var AttachmentMap = {
  48. TOP: 'bottom center',
  49. RIGHT: 'middle left',
  50. BOTTOM: 'top center',
  51. LEFT: 'middle right'
  52. };
  53. var HoverState = {
  54. IN: 'in',
  55. OUT: 'out'
  56. };
  57. var Event = {
  58. HIDE: 'hide' + EVENT_KEY,
  59. HIDDEN: 'hidden' + EVENT_KEY,
  60. SHOW: 'show' + EVENT_KEY,
  61. SHOWN: 'shown' + EVENT_KEY,
  62. INSERTED: 'inserted' + EVENT_KEY,
  63. CLICK: 'click' + EVENT_KEY,
  64. FOCUSIN: 'focusin' + EVENT_KEY,
  65. FOCUSOUT: 'focusout' + EVENT_KEY,
  66. MOUSEENTER: 'mouseenter' + EVENT_KEY,
  67. MOUSELEAVE: 'mouseleave' + EVENT_KEY
  68. };
  69. var ClassName = {
  70. FADE: 'fade',
  71. IN: 'in'
  72. };
  73. var Selector = {
  74. TOOLTIP: '.tooltip',
  75. TOOLTIP_INNER: '.tooltip-inner'
  76. };
  77. var TetherClass = {
  78. element: false,
  79. enabled: false
  80. };
  81. var Trigger = {
  82. HOVER: 'hover',
  83. FOCUS: 'focus',
  84. CLICK: 'click',
  85. MANUAL: 'manual'
  86. };
  87. /**
  88. * ------------------------------------------------------------------------
  89. * Class Definition
  90. * ------------------------------------------------------------------------
  91. */
  92. var Tooltip = (function () {
  93. function Tooltip(element, config) {
  94. _classCallCheck(this, Tooltip);
  95. // private
  96. this._isEnabled = true;
  97. this._timeout = 0;
  98. this._hoverState = '';
  99. this._activeTrigger = {};
  100. this._tether = null;
  101. // protected
  102. this.element = element;
  103. this.config = this._getConfig(config);
  104. this.tip = null;
  105. this._setListeners();
  106. }
  107. /**
  108. * ------------------------------------------------------------------------
  109. * jQuery
  110. * ------------------------------------------------------------------------
  111. */
  112. // getters
  113. _createClass(Tooltip, [{
  114. key: 'enable',
  115. // public
  116. value: function enable() {
  117. this._isEnabled = true;
  118. }
  119. }, {
  120. key: 'disable',
  121. value: function disable() {
  122. this._isEnabled = false;
  123. }
  124. }, {
  125. key: 'toggleEnabled',
  126. value: function toggleEnabled() {
  127. this._isEnabled = !this._isEnabled;
  128. }
  129. }, {
  130. key: 'toggle',
  131. value: function toggle(event) {
  132. if (event) {
  133. var dataKey = this.constructor.DATA_KEY;
  134. var context = $(event.currentTarget).data(dataKey);
  135. if (!context) {
  136. context = new this.constructor(event.currentTarget, this._getDelegateConfig());
  137. $(event.currentTarget).data(dataKey, context);
  138. }
  139. context._activeTrigger.click = !context._activeTrigger.click;
  140. if (context._isWithActiveTrigger()) {
  141. context._enter(null, context);
  142. } else {
  143. context._leave(null, context);
  144. }
  145. } else {
  146. if ($(this.getTipElement()).hasClass(ClassName.IN)) {
  147. this._leave(null, this);
  148. return;
  149. }
  150. this._enter(null, this);
  151. }
  152. }
  153. }, {
  154. key: 'dispose',
  155. value: function dispose() {
  156. clearTimeout(this._timeout);
  157. this.cleanupTether();
  158. $.removeData(this.element, this.constructor.DATA_KEY);
  159. $(this.element).off(this.constructor.EVENT_KEY);
  160. if (this.tip) {
  161. $(this.tip).remove();
  162. }
  163. this._isEnabled = null;
  164. this._timeout = null;
  165. this._hoverState = null;
  166. this._activeTrigger = null;
  167. this._tether = null;
  168. this.element = null;
  169. this.config = null;
  170. this.tip = null;
  171. }
  172. }, {
  173. key: 'show',
  174. value: function show() {
  175. var _this = this;
  176. var showEvent = $.Event(this.constructor.Event.SHOW);
  177. if (this.isWithContent() && this._isEnabled) {
  178. $(this.element).trigger(showEvent);
  179. var isInTheDom = $.contains(this.element.ownerDocument.documentElement, this.element);
  180. if (showEvent.isDefaultPrevented() || !isInTheDom) {
  181. return;
  182. }
  183. var tip = this.getTipElement();
  184. var tipId = Util.getUID(this.constructor.NAME);
  185. tip.setAttribute('id', tipId);
  186. this.element.setAttribute('aria-describedby', tipId);
  187. this.setContent();
  188. if (this.config.animation) {
  189. $(tip).addClass(ClassName.FADE);
  190. }
  191. var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this.element) : this.config.placement;
  192. var attachment = this._getAttachment(placement);
  193. $(tip).data(this.constructor.DATA_KEY, this).appendTo(document.body);
  194. $(this.element).trigger(this.constructor.Event.INSERTED);
  195. this._tether = new Tether({
  196. attachment: attachment,
  197. element: tip,
  198. target: this.element,
  199. classes: TetherClass,
  200. classPrefix: CLASS_PREFIX,
  201. offset: this.config.offset,
  202. constraints: this.config.constraints
  203. });
  204. Util.reflow(tip);
  205. this._tether.position();
  206. $(tip).addClass(ClassName.IN);
  207. var complete = function complete() {
  208. var prevHoverState = _this._hoverState;
  209. _this._hoverState = null;
  210. $(_this.element).trigger(_this.constructor.Event.SHOWN);
  211. if (prevHoverState === HoverState.OUT) {
  212. _this._leave(null, _this);
  213. }
  214. };
  215. if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
  216. $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION);
  217. return;
  218. }
  219. complete();
  220. }
  221. }
  222. }, {
  223. key: 'hide',
  224. value: function hide(callback) {
  225. var _this2 = this;
  226. var tip = this.getTipElement();
  227. var hideEvent = $.Event(this.constructor.Event.HIDE);
  228. var complete = function complete() {
  229. if (_this2._hoverState !== HoverState.IN && tip.parentNode) {
  230. tip.parentNode.removeChild(tip);
  231. }
  232. _this2.element.removeAttribute('aria-describedby');
  233. $(_this2.element).trigger(_this2.constructor.Event.HIDDEN);
  234. _this2.cleanupTether();
  235. if (callback) {
  236. callback();
  237. }
  238. };
  239. $(this.element).trigger(hideEvent);
  240. if (hideEvent.isDefaultPrevented()) {
  241. return;
  242. }
  243. $(tip).removeClass(ClassName.IN);
  244. if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
  245. $(tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
  246. } else {
  247. complete();
  248. }
  249. this._hoverState = '';
  250. }
  251. // protected
  252. }, {
  253. key: 'isWithContent',
  254. value: function isWithContent() {
  255. return Boolean(this.getTitle());
  256. }
  257. }, {
  258. key: 'getTipElement',
  259. value: function getTipElement() {
  260. return this.tip = this.tip || $(this.config.template)[0];
  261. }
  262. }, {
  263. key: 'setContent',
  264. value: function setContent() {
  265. var tip = this.getTipElement();
  266. var title = this.getTitle();
  267. var method = this.config.html ? 'innerHTML' : 'innerText';
  268. $(tip).find(Selector.TOOLTIP_INNER)[0][method] = title;
  269. $(tip).removeClass(ClassName.FADE).removeClass(ClassName.IN);
  270. this.cleanupTether();
  271. }
  272. }, {
  273. key: 'getTitle',
  274. value: function getTitle() {
  275. var title = this.element.getAttribute('data-original-title');
  276. if (!title) {
  277. title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
  278. }
  279. return title;
  280. }
  281. }, {
  282. key: 'cleanupTether',
  283. value: function cleanupTether() {
  284. if (this._tether) {
  285. this._tether.destroy();
  286. // clean up after tether's junk classes
  287. // remove after they fix issue
  288. // (https://github.com/HubSpot/tether/issues/36)
  289. $(this.element).removeClass(this._removeTetherClasses);
  290. $(this.tip).removeClass(this._removeTetherClasses);
  291. }
  292. }
  293. // private
  294. }, {
  295. key: '_getAttachment',
  296. value: function _getAttachment(placement) {
  297. return AttachmentMap[placement.toUpperCase()];
  298. }
  299. }, {
  300. key: '_setListeners',
  301. value: function _setListeners() {
  302. var _this3 = this;
  303. var triggers = this.config.trigger.split(' ');
  304. triggers.forEach(function (trigger) {
  305. if (trigger === 'click') {
  306. $(_this3.element).on(_this3.constructor.Event.CLICK, _this3.config.selector, $.proxy(_this3.toggle, _this3));
  307. } else if (trigger !== Trigger.MANUAL) {
  308. var eventIn = trigger === Trigger.HOVER ? _this3.constructor.Event.MOUSEENTER : _this3.constructor.Event.FOCUSIN;
  309. var eventOut = trigger === Trigger.HOVER ? _this3.constructor.Event.MOUSELEAVE : _this3.constructor.Event.FOCUSOUT;
  310. $(_this3.element).on(eventIn, _this3.config.selector, $.proxy(_this3._enter, _this3)).on(eventOut, _this3.config.selector, $.proxy(_this3._leave, _this3));
  311. }
  312. });
  313. if (this.config.selector) {
  314. this.config = $.extend({}, this.config, {
  315. trigger: 'manual',
  316. selector: ''
  317. });
  318. } else {
  319. this._fixTitle();
  320. }
  321. }
  322. }, {
  323. key: '_removeTetherClasses',
  324. value: function _removeTetherClasses(i, css) {
  325. return ((css.baseVal || css).match(new RegExp('(^|\\s)' + CLASS_PREFIX + '-\\S+', 'g')) || []).join(' ');
  326. }
  327. }, {
  328. key: '_fixTitle',
  329. value: function _fixTitle() {
  330. var titleType = typeof this.element.getAttribute('data-original-title');
  331. if (this.element.getAttribute('title') || titleType !== 'string') {
  332. this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '');
  333. this.element.setAttribute('title', '');
  334. }
  335. }
  336. }, {
  337. key: '_enter',
  338. value: function _enter(event, context) {
  339. var dataKey = this.constructor.DATA_KEY;
  340. context = context || $(event.currentTarget).data(dataKey);
  341. if (!context) {
  342. context = new this.constructor(event.currentTarget, this._getDelegateConfig());
  343. $(event.currentTarget).data(dataKey, context);
  344. }
  345. if (event) {
  346. context._activeTrigger[event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
  347. }
  348. if ($(context.getTipElement()).hasClass(ClassName.IN) || context._hoverState === HoverState.IN) {
  349. context._hoverState = HoverState.IN;
  350. return;
  351. }
  352. clearTimeout(context._timeout);
  353. context._hoverState = HoverState.IN;
  354. if (!context.config.delay || !context.config.delay.show) {
  355. context.show();
  356. return;
  357. }
  358. context._timeout = setTimeout(function () {
  359. if (context._hoverState === HoverState.IN) {
  360. context.show();
  361. }
  362. }, context.config.delay.show);
  363. }
  364. }, {
  365. key: '_leave',
  366. value: function _leave(event, context) {
  367. var dataKey = this.constructor.DATA_KEY;
  368. context = context || $(event.currentTarget).data(dataKey);
  369. if (!context) {
  370. context = new this.constructor(event.currentTarget, this._getDelegateConfig());
  371. $(event.currentTarget).data(dataKey, context);
  372. }
  373. if (event) {
  374. context._activeTrigger[event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
  375. }
  376. if (context._isWithActiveTrigger()) {
  377. return;
  378. }
  379. clearTimeout(context._timeout);
  380. context._hoverState = HoverState.OUT;
  381. if (!context.config.delay || !context.config.delay.hide) {
  382. context.hide();
  383. return;
  384. }
  385. context._timeout = setTimeout(function () {
  386. if (context._hoverState === HoverState.OUT) {
  387. context.hide();
  388. }
  389. }, context.config.delay.hide);
  390. }
  391. }, {
  392. key: '_isWithActiveTrigger',
  393. value: function _isWithActiveTrigger() {
  394. for (var trigger in this._activeTrigger) {
  395. if (this._activeTrigger[trigger]) {
  396. return true;
  397. }
  398. }
  399. return false;
  400. }
  401. }, {
  402. key: '_getConfig',
  403. value: function _getConfig(config) {
  404. config = $.extend({}, this.constructor.Default, $(this.element).data(), config);
  405. if (config.delay && typeof config.delay === 'number') {
  406. config.delay = {
  407. show: config.delay,
  408. hide: config.delay
  409. };
  410. }
  411. Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
  412. return config;
  413. }
  414. }, {
  415. key: '_getDelegateConfig',
  416. value: function _getDelegateConfig() {
  417. var config = {};
  418. if (this.config) {
  419. for (var key in this.config) {
  420. if (this.constructor.Default[key] !== this.config[key]) {
  421. config[key] = this.config[key];
  422. }
  423. }
  424. }
  425. return config;
  426. }
  427. // static
  428. }], [{
  429. key: '_jQueryInterface',
  430. value: function _jQueryInterface(config) {
  431. return this.each(function () {
  432. var data = $(this).data(DATA_KEY);
  433. var _config = typeof config === 'object' ? config : null;
  434. if (!data && /destroy|hide/.test(config)) {
  435. return;
  436. }
  437. if (!data) {
  438. data = new Tooltip(this, _config);
  439. $(this).data(DATA_KEY, data);
  440. }
  441. if (typeof config === 'string') {
  442. data[config]();
  443. }
  444. });
  445. }
  446. }, {
  447. key: 'VERSION',
  448. get: function get() {
  449. return VERSION;
  450. }
  451. }, {
  452. key: 'Default',
  453. get: function get() {
  454. return Default;
  455. }
  456. }, {
  457. key: 'NAME',
  458. get: function get() {
  459. return NAME;
  460. }
  461. }, {
  462. key: 'DATA_KEY',
  463. get: function get() {
  464. return DATA_KEY;
  465. }
  466. }, {
  467. key: 'Event',
  468. get: function get() {
  469. return Event;
  470. }
  471. }, {
  472. key: 'EVENT_KEY',
  473. get: function get() {
  474. return EVENT_KEY;
  475. }
  476. }, {
  477. key: 'DefaultType',
  478. get: function get() {
  479. return DefaultType;
  480. }
  481. }]);
  482. return Tooltip;
  483. })();
  484. $.fn[NAME] = Tooltip._jQueryInterface;
  485. $.fn[NAME].Constructor = Tooltip;
  486. $.fn[NAME].noConflict = function () {
  487. $.fn[NAME] = JQUERY_NO_CONFLICT;
  488. return Tooltip._jQueryInterface;
  489. };
  490. return Tooltip;
  491. })(jQuery);
  492. //# sourceMappingURL=tooltip.js.map