tooltip.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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 = 235);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 12:
  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/dom");
  75. /***/ }),
  76. /***/ 20:
  77. /***/ (function(module, exports) {
  78. module.exports = require("element-ui/lib/utils/vdom");
  79. /***/ }),
  80. /***/ 235:
  81. /***/ (function(module, exports, __webpack_require__) {
  82. module.exports = __webpack_require__(236);
  83. /***/ }),
  84. /***/ 236:
  85. /***/ (function(module, exports, __webpack_require__) {
  86. "use strict";
  87. exports.__esModule = true;
  88. var _main = __webpack_require__(237);
  89. var _main2 = _interopRequireDefault(_main);
  90. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  91. /* istanbul ignore next */
  92. _main2.default.install = function (Vue) {
  93. Vue.component(_main2.default.name, _main2.default);
  94. };
  95. exports.default = _main2.default;
  96. /***/ }),
  97. /***/ 237:
  98. /***/ (function(module, exports, __webpack_require__) {
  99. "use strict";
  100. exports.__esModule = true;
  101. var _vuePopper = __webpack_require__(8);
  102. var _vuePopper2 = _interopRequireDefault(_vuePopper);
  103. var _debounce = __webpack_require__(12);
  104. var _debounce2 = _interopRequireDefault(_debounce);
  105. var _dom = __webpack_require__(2);
  106. var _vdom = __webpack_require__(20);
  107. var _util = __webpack_require__(3);
  108. var _vue = __webpack_require__(5);
  109. var _vue2 = _interopRequireDefault(_vue);
  110. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  111. exports.default = {
  112. name: 'ElTooltip',
  113. mixins: [_vuePopper2.default],
  114. props: {
  115. openDelay: {
  116. type: Number,
  117. default: 0
  118. },
  119. disabled: Boolean,
  120. manual: Boolean,
  121. effect: {
  122. type: String,
  123. default: 'dark'
  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. var on = vnode.data.on = vnode.data.on || {};
  218. var nativeOn = vnode.data.nativeOn = vnode.data.nativeOn || {};
  219. data.staticClass = this.concatClass(data.staticClass, 'el-tooltip');
  220. nativeOn.mouseenter = on.mouseenter = this.addEventHandle(on.mouseenter, this.show);
  221. nativeOn.mouseleave = on.mouseleave = this.addEventHandle(on.mouseleave, this.hide);
  222. nativeOn.focus = on.focus = this.addEventHandle(on.focus, this.handleFocus);
  223. nativeOn.blur = on.blur = this.addEventHandle(on.blur, this.handleBlur);
  224. nativeOn.click = on.click = this.addEventHandle(on.click, function () {
  225. _this2.focusing = false;
  226. });
  227. return vnode;
  228. },
  229. mounted: function mounted() {
  230. this.referenceElm = this.$el;
  231. if (this.$el.nodeType === 1) {
  232. this.$el.setAttribute('aria-describedby', this.tooltipId);
  233. this.$el.setAttribute('tabindex', 0);
  234. }
  235. },
  236. watch: {
  237. focusing: function focusing(val) {
  238. if (val) {
  239. (0, _dom.addClass)(this.referenceElm, 'focusing');
  240. } else {
  241. (0, _dom.removeClass)(this.referenceElm, 'focusing');
  242. }
  243. }
  244. },
  245. methods: {
  246. show: function show() {
  247. this.setExpectedState(true);
  248. this.handleShowPopper();
  249. },
  250. hide: function hide() {
  251. this.setExpectedState(false);
  252. this.debounceClose();
  253. },
  254. handleFocus: function handleFocus() {
  255. this.focusing = true;
  256. this.show();
  257. },
  258. handleBlur: function handleBlur() {
  259. this.focusing = false;
  260. this.hide();
  261. },
  262. addEventHandle: function addEventHandle(old, fn) {
  263. if (!old) {
  264. return fn;
  265. } else if (Array.isArray(old)) {
  266. return old.indexOf(fn) > -1 ? old : old.concat(fn);
  267. } else {
  268. return old === fn ? old : [old, fn];
  269. }
  270. },
  271. concatClass: function concatClass(a, b) {
  272. if (a && a.indexOf(b) > -1) return a;
  273. return a ? b ? a + ' ' + b : a : b || '';
  274. },
  275. handleShowPopper: function handleShowPopper() {
  276. var _this3 = this;
  277. if (!this.expectedState || this.manual) return;
  278. clearTimeout(this.timeout);
  279. this.timeout = setTimeout(function () {
  280. _this3.showPopper = true;
  281. }, this.openDelay);
  282. if (this.hideAfter > 0) {
  283. this.timeoutPending = setTimeout(function () {
  284. _this3.showPopper = false;
  285. }, this.hideAfter);
  286. }
  287. },
  288. handleClosePopper: function handleClosePopper() {
  289. if (this.enterable && this.expectedState || this.manual) return;
  290. clearTimeout(this.timeout);
  291. if (this.timeoutPending) {
  292. clearTimeout(this.timeoutPending);
  293. }
  294. this.showPopper = false;
  295. },
  296. setExpectedState: function setExpectedState(expectedState) {
  297. if (expectedState === false) {
  298. clearTimeout(this.timeoutPending);
  299. }
  300. this.expectedState = expectedState;
  301. }
  302. }
  303. };
  304. /***/ }),
  305. /***/ 3:
  306. /***/ (function(module, exports) {
  307. module.exports = require("element-ui/lib/utils/util");
  308. /***/ }),
  309. /***/ 5:
  310. /***/ (function(module, exports) {
  311. module.exports = require("vue");
  312. /***/ }),
  313. /***/ 8:
  314. /***/ (function(module, exports) {
  315. module.exports = require("element-ui/lib/utils/vue-popper");
  316. /***/ })
  317. /******/ });