tooltip.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, {
  41. /******/ configurable: false,
  42. /******/ enumerable: true,
  43. /******/ get: getter
  44. /******/ });
  45. /******/ }
  46. /******/ };
  47. /******/
  48. /******/ // getDefaultExport function for compatibility with non-harmony modules
  49. /******/ __webpack_require__.n = function(module) {
  50. /******/ var getter = module && module.__esModule ?
  51. /******/ function getDefault() { return module['default']; } :
  52. /******/ function getModuleExports() { return module; };
  53. /******/ __webpack_require__.d(getter, 'a', getter);
  54. /******/ return getter;
  55. /******/ };
  56. /******/
  57. /******/ // Object.prototype.hasOwnProperty.call
  58. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  59. /******/
  60. /******/ // __webpack_public_path__
  61. /******/ __webpack_require__.p = "/dist/";
  62. /******/
  63. /******/ // Load entry module and return exports
  64. /******/ return __webpack_require__(__webpack_require__.s = 207);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 14:
  69. /***/ (function(module, exports) {
  70. module.exports = require("throttle-debounce/debounce");
  71. /***/ }),
  72. /***/ 2:
  73. /***/ (function(module, exports) {
  74. module.exports = require("element-ui/lib/utils/util");
  75. /***/ }),
  76. /***/ 20:
  77. /***/ (function(module, exports) {
  78. module.exports = require("element-ui/lib/utils/vdom");
  79. /***/ }),
  80. /***/ 207:
  81. /***/ (function(module, exports, __webpack_require__) {
  82. "use strict";
  83. exports.__esModule = true;
  84. var _main = __webpack_require__(208);
  85. var _main2 = _interopRequireDefault(_main);
  86. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  87. /* istanbul ignore next */
  88. _main2.default.install = function (Vue) {
  89. Vue.component(_main2.default.name, _main2.default);
  90. };
  91. exports.default = _main2.default;
  92. /***/ }),
  93. /***/ 208:
  94. /***/ (function(module, exports, __webpack_require__) {
  95. "use strict";
  96. exports.__esModule = true;
  97. var _vuePopper = __webpack_require__(7);
  98. var _vuePopper2 = _interopRequireDefault(_vuePopper);
  99. var _debounce = __webpack_require__(14);
  100. var _debounce2 = _interopRequireDefault(_debounce);
  101. var _dom = __webpack_require__(3);
  102. var _vdom = __webpack_require__(20);
  103. var _util = __webpack_require__(2);
  104. var _vue = __webpack_require__(4);
  105. var _vue2 = _interopRequireDefault(_vue);
  106. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  107. exports.default = {
  108. name: 'ElTooltip',
  109. mixins: [_vuePopper2.default],
  110. props: {
  111. openDelay: {
  112. type: Number,
  113. default: 0
  114. },
  115. disabled: Boolean,
  116. manual: Boolean,
  117. effect: {
  118. type: String,
  119. default: 'dark'
  120. },
  121. arrowOffset: {
  122. type: Number,
  123. default: 0
  124. },
  125. popperClass: String,
  126. content: String,
  127. visibleArrow: {
  128. default: true
  129. },
  130. transition: {
  131. type: String,
  132. default: 'el-fade-in-linear'
  133. },
  134. popperOptions: {
  135. default: function _default() {
  136. return {
  137. boundariesPadding: 10,
  138. gpuAcceleration: false
  139. };
  140. }
  141. },
  142. enterable: {
  143. type: Boolean,
  144. default: true
  145. },
  146. hideAfter: {
  147. type: Number,
  148. default: 0
  149. }
  150. },
  151. data: function data() {
  152. return {
  153. timeoutPending: null,
  154. focusing: false
  155. };
  156. },
  157. computed: {
  158. tooltipId: function tooltipId() {
  159. return 'el-tooltip-' + (0, _util.generateId)();
  160. }
  161. },
  162. beforeCreate: function beforeCreate() {
  163. var _this = this;
  164. if (this.$isServer) return;
  165. this.popperVM = new _vue2.default({
  166. data: { node: '' },
  167. render: function render(h) {
  168. return this.node;
  169. }
  170. }).$mount();
  171. this.debounceClose = (0, _debounce2.default)(200, function () {
  172. return _this.handleClosePopper();
  173. });
  174. },
  175. render: function render(h) {
  176. var _this2 = this;
  177. if (this.popperVM) {
  178. this.popperVM.node = h(
  179. 'transition',
  180. {
  181. attrs: {
  182. name: this.transition
  183. },
  184. on: {
  185. 'afterLeave': this.doDestroy
  186. }
  187. },
  188. [h(
  189. 'div',
  190. {
  191. on: {
  192. 'mouseleave': function mouseleave() {
  193. _this2.setExpectedState(false);_this2.debounceClose();
  194. },
  195. 'mouseenter': function mouseenter() {
  196. _this2.setExpectedState(true);
  197. }
  198. },
  199. ref: 'popper',
  200. attrs: { role: 'tooltip',
  201. id: this.tooltipId,
  202. 'aria-hidden': this.disabled || !this.showPopper ? 'true' : 'false'
  203. },
  204. directives: [{
  205. name: 'show',
  206. value: !this.disabled && this.showPopper
  207. }],
  208. 'class': ['el-tooltip__popper', 'is-' + this.effect, this.popperClass] },
  209. [this.$slots.content || this.content]
  210. )]
  211. );
  212. }
  213. if (!this.$slots.default || !this.$slots.default.length) return this.$slots.default;
  214. var vnode = (0, _vdom.getFirstComponentChild)(this.$slots.default);
  215. if (!vnode) return vnode;
  216. var data = vnode.data = vnode.data || {};
  217. data.staticClass = this.concatClass(data.staticClass, 'el-tooltip');
  218. return vnode;
  219. },
  220. mounted: function mounted() {
  221. var _this3 = this;
  222. this.referenceElm = this.$el;
  223. if (this.$el.nodeType === 1) {
  224. this.$el.setAttribute('aria-describedby', this.tooltipId);
  225. this.$el.setAttribute('tabindex', 0);
  226. (0, _dom.on)(this.referenceElm, 'mouseenter', this.show);
  227. (0, _dom.on)(this.referenceElm, 'mouseleave', this.hide);
  228. (0, _dom.on)(this.referenceElm, 'focus', function () {
  229. if (!_this3.$slots.default || !_this3.$slots.default.length) {
  230. _this3.handleFocus();
  231. return;
  232. }
  233. var instance = _this3.$slots.default[0].componentInstance;
  234. if (instance && instance.focus) {
  235. instance.focus();
  236. } else {
  237. _this3.handleFocus();
  238. }
  239. });
  240. (0, _dom.on)(this.referenceElm, 'blur', this.handleBlur);
  241. (0, _dom.on)(this.referenceElm, 'click', this.removeFocusing);
  242. }
  243. },
  244. watch: {
  245. focusing: function focusing(val) {
  246. if (val) {
  247. (0, _dom.addClass)(this.referenceElm, 'focusing');
  248. } else {
  249. (0, _dom.removeClass)(this.referenceElm, 'focusing');
  250. }
  251. }
  252. },
  253. methods: {
  254. show: function show() {
  255. this.setExpectedState(true);
  256. this.handleShowPopper();
  257. },
  258. hide: function hide() {
  259. this.setExpectedState(false);
  260. this.debounceClose();
  261. },
  262. handleFocus: function handleFocus() {
  263. this.focusing = true;
  264. this.show();
  265. },
  266. handleBlur: function handleBlur() {
  267. this.focusing = false;
  268. this.hide();
  269. },
  270. removeFocusing: function removeFocusing() {
  271. this.focusing = false;
  272. },
  273. concatClass: function concatClass(a, b) {
  274. if (a && a.indexOf(b) > -1) return a;
  275. return a ? b ? a + ' ' + b : a : b || '';
  276. },
  277. handleShowPopper: function handleShowPopper() {
  278. var _this4 = this;
  279. if (!this.expectedState || this.manual) return;
  280. clearTimeout(this.timeout);
  281. this.timeout = setTimeout(function () {
  282. _this4.showPopper = true;
  283. }, this.openDelay);
  284. if (this.hideAfter > 0) {
  285. this.timeoutPending = setTimeout(function () {
  286. _this4.showPopper = false;
  287. }, this.hideAfter);
  288. }
  289. },
  290. handleClosePopper: function handleClosePopper() {
  291. if (this.enterable && this.expectedState || this.manual) return;
  292. clearTimeout(this.timeout);
  293. if (this.timeoutPending) {
  294. clearTimeout(this.timeoutPending);
  295. }
  296. this.showPopper = false;
  297. if (this.disabled) {
  298. this.doDestroy();
  299. }
  300. },
  301. setExpectedState: function setExpectedState(expectedState) {
  302. if (expectedState === false) {
  303. clearTimeout(this.timeoutPending);
  304. }
  305. this.expectedState = expectedState;
  306. }
  307. },
  308. destroyed: function destroyed() {
  309. var reference = this.referenceElm;
  310. (0, _dom.off)(reference, 'mouseenter', this.show);
  311. (0, _dom.off)(reference, 'mouseleave', this.hide);
  312. (0, _dom.off)(reference, 'focus', this.handleFocus);
  313. (0, _dom.off)(reference, 'blur', this.handleBlur);
  314. (0, _dom.off)(reference, 'click', this.removeFocusing);
  315. }
  316. };
  317. /***/ }),
  318. /***/ 3:
  319. /***/ (function(module, exports) {
  320. module.exports = require("element-ui/lib/utils/dom");
  321. /***/ }),
  322. /***/ 4:
  323. /***/ (function(module, exports) {
  324. module.exports = require("vue");
  325. /***/ }),
  326. /***/ 7:
  327. /***/ (function(module, exports) {
  328. module.exports = require("element-ui/lib/utils/vue-popper");
  329. /***/ })
  330. /******/ });