tooltip.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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 = 238);
  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/dom");
  75. /***/ }),
  76. /***/ 20:
  77. /***/ (function(module, exports) {
  78. module.exports = require("element-ui/lib/utils/vdom");
  79. /***/ }),
  80. /***/ 238:
  81. /***/ (function(module, exports, __webpack_require__) {
  82. module.exports = __webpack_require__(239);
  83. /***/ }),
  84. /***/ 239:
  85. /***/ (function(module, exports, __webpack_require__) {
  86. "use strict";
  87. exports.__esModule = true;
  88. var _main = __webpack_require__(240);
  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. /***/ 240:
  98. /***/ (function(module, exports, __webpack_require__) {
  99. "use strict";
  100. exports.__esModule = true;
  101. var _vuePopper = __webpack_require__(7);
  102. var _vuePopper2 = _interopRequireDefault(_vuePopper);
  103. var _debounce = __webpack_require__(14);
  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__(4);
  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. arrowOffset: {
  126. type: Number,
  127. default: 0
  128. },
  129. popperClass: String,
  130. content: String,
  131. visibleArrow: {
  132. default: true
  133. },
  134. transition: {
  135. type: String,
  136. default: 'el-fade-in-linear'
  137. },
  138. popperOptions: {
  139. default: function _default() {
  140. return {
  141. boundariesPadding: 10,
  142. gpuAcceleration: false
  143. };
  144. }
  145. },
  146. enterable: {
  147. type: Boolean,
  148. default: true
  149. },
  150. hideAfter: {
  151. type: Number,
  152. default: 0
  153. }
  154. },
  155. data: function data() {
  156. return {
  157. timeoutPending: null,
  158. focusing: false
  159. };
  160. },
  161. computed: {
  162. tooltipId: function tooltipId() {
  163. return 'el-tooltip-' + (0, _util.generateId)();
  164. }
  165. },
  166. beforeCreate: function beforeCreate() {
  167. var _this = this;
  168. if (this.$isServer) return;
  169. this.popperVM = new _vue2.default({
  170. data: { node: '' },
  171. render: function render(h) {
  172. return this.node;
  173. }
  174. }).$mount();
  175. this.debounceClose = (0, _debounce2.default)(200, function () {
  176. return _this.handleClosePopper();
  177. });
  178. },
  179. render: function render(h) {
  180. var _this2 = this;
  181. if (this.popperVM) {
  182. this.popperVM.node = h(
  183. 'transition',
  184. {
  185. attrs: {
  186. name: this.transition
  187. },
  188. on: {
  189. 'afterLeave': this.doDestroy
  190. }
  191. },
  192. [h(
  193. 'div',
  194. {
  195. on: {
  196. 'mouseleave': function mouseleave() {
  197. _this2.setExpectedState(false);_this2.debounceClose();
  198. },
  199. 'mouseenter': function mouseenter() {
  200. _this2.setExpectedState(true);
  201. }
  202. },
  203. ref: 'popper',
  204. attrs: { role: 'tooltip',
  205. id: this.tooltipId,
  206. 'aria-hidden': this.disabled || !this.showPopper ? 'true' : 'false'
  207. },
  208. directives: [{
  209. name: 'show',
  210. value: !this.disabled && this.showPopper
  211. }],
  212. 'class': ['el-tooltip__popper', 'is-' + this.effect, this.popperClass] },
  213. [this.$slots.content || this.content]
  214. )]
  215. );
  216. }
  217. if (!this.$slots.default || !this.$slots.default.length) return this.$slots.default;
  218. var vnode = (0, _vdom.getFirstComponentChild)(this.$slots.default);
  219. if (!vnode) return vnode;
  220. var data = vnode.data = vnode.data || {};
  221. data.staticClass = this.concatClass(data.staticClass, 'el-tooltip');
  222. return vnode;
  223. },
  224. mounted: function mounted() {
  225. var _this3 = this;
  226. this.referenceElm = this.$el;
  227. if (this.$el.nodeType === 1) {
  228. this.$el.setAttribute('aria-describedby', this.tooltipId);
  229. this.$el.setAttribute('tabindex', 0);
  230. (0, _dom.on)(this.referenceElm, 'mouseenter', this.show);
  231. (0, _dom.on)(this.referenceElm, 'mouseleave', this.hide);
  232. (0, _dom.on)(this.referenceElm, 'focus', function () {
  233. if (!_this3.$slots.default || !_this3.$slots.default.length) {
  234. _this3.handleFocus();
  235. return;
  236. }
  237. var instance = _this3.$slots.default[0].componentInstance;
  238. if (instance && instance.focus) {
  239. instance.focus();
  240. } else {
  241. _this3.handleFocus();
  242. }
  243. });
  244. (0, _dom.on)(this.referenceElm, 'blur', this.handleBlur);
  245. (0, _dom.on)(this.referenceElm, 'click', this.removeFocusing);
  246. }
  247. },
  248. watch: {
  249. focusing: function focusing(val) {
  250. if (val) {
  251. (0, _dom.addClass)(this.referenceElm, 'focusing');
  252. } else {
  253. (0, _dom.removeClass)(this.referenceElm, 'focusing');
  254. }
  255. }
  256. },
  257. methods: {
  258. show: function show() {
  259. this.setExpectedState(true);
  260. this.handleShowPopper();
  261. },
  262. hide: function hide() {
  263. this.setExpectedState(false);
  264. this.debounceClose();
  265. },
  266. handleFocus: function handleFocus() {
  267. this.focusing = true;
  268. this.show();
  269. },
  270. handleBlur: function handleBlur() {
  271. this.focusing = false;
  272. this.hide();
  273. },
  274. removeFocusing: function removeFocusing() {
  275. this.focusing = false;
  276. },
  277. concatClass: function concatClass(a, b) {
  278. if (a && a.indexOf(b) > -1) return a;
  279. return a ? b ? a + ' ' + b : a : b || '';
  280. },
  281. handleShowPopper: function handleShowPopper() {
  282. var _this4 = this;
  283. if (!this.expectedState || this.manual) return;
  284. clearTimeout(this.timeout);
  285. this.timeout = setTimeout(function () {
  286. _this4.showPopper = true;
  287. }, this.openDelay);
  288. if (this.hideAfter > 0) {
  289. this.timeoutPending = setTimeout(function () {
  290. _this4.showPopper = false;
  291. }, this.hideAfter);
  292. }
  293. },
  294. handleClosePopper: function handleClosePopper() {
  295. if (this.enterable && this.expectedState || this.manual) return;
  296. clearTimeout(this.timeout);
  297. if (this.timeoutPending) {
  298. clearTimeout(this.timeoutPending);
  299. }
  300. this.showPopper = false;
  301. if (this.disabled) {
  302. this.doDestroy();
  303. }
  304. },
  305. setExpectedState: function setExpectedState(expectedState) {
  306. if (expectedState === false) {
  307. clearTimeout(this.timeoutPending);
  308. }
  309. this.expectedState = expectedState;
  310. }
  311. },
  312. destroyed: function destroyed() {
  313. var reference = this.referenceElm;
  314. (0, _dom.off)(reference, 'mouseenter', this.show);
  315. (0, _dom.off)(reference, 'mouseleave', this.hide);
  316. (0, _dom.off)(reference, 'focus', this.handleFocus);
  317. (0, _dom.off)(reference, 'blur', this.handleBlur);
  318. (0, _dom.off)(reference, 'click', this.removeFocusing);
  319. }
  320. };
  321. /***/ }),
  322. /***/ 3:
  323. /***/ (function(module, exports) {
  324. module.exports = require("element-ui/lib/utils/util");
  325. /***/ }),
  326. /***/ 4:
  327. /***/ (function(module, exports) {
  328. module.exports = require("vue");
  329. /***/ }),
  330. /***/ 7:
  331. /***/ (function(module, exports) {
  332. module.exports = require("element-ui/lib/utils/vue-popper");
  333. /***/ })
  334. /******/ });