slider.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  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, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 63);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 29:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/tooltip");
  182. /***/ }),
  183. /***/ 4:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/mixins/emitter");
  186. /***/ }),
  187. /***/ 49:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/input-number");
  190. /***/ }),
  191. /***/ 63:
  192. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  193. "use strict";
  194. __webpack_require__.r(__webpack_exports__);
  195. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/slider/src/main.vue?vue&type=template&id=32708644&
  196. var render = function() {
  197. var _vm = this
  198. var _h = _vm.$createElement
  199. var _c = _vm._self._c || _h
  200. return _c(
  201. "div",
  202. {
  203. staticClass: "el-slider",
  204. class: {
  205. "is-vertical": _vm.vertical,
  206. "el-slider--with-input": _vm.showInput
  207. },
  208. attrs: {
  209. role: "slider",
  210. "aria-valuemin": _vm.min,
  211. "aria-valuemax": _vm.max,
  212. "aria-orientation": _vm.vertical ? "vertical" : "horizontal",
  213. "aria-disabled": _vm.sliderDisabled
  214. }
  215. },
  216. [
  217. _vm.showInput && !_vm.range
  218. ? _c("el-input-number", {
  219. ref: "input",
  220. staticClass: "el-slider__input",
  221. attrs: {
  222. step: _vm.step,
  223. disabled: _vm.sliderDisabled,
  224. controls: _vm.showInputControls,
  225. min: _vm.min,
  226. max: _vm.max,
  227. debounce: _vm.debounce,
  228. size: _vm.inputSize
  229. },
  230. on: { change: _vm.emitChange },
  231. model: {
  232. value: _vm.firstValue,
  233. callback: function($$v) {
  234. _vm.firstValue = $$v
  235. },
  236. expression: "firstValue"
  237. }
  238. })
  239. : _vm._e(),
  240. _c(
  241. "div",
  242. {
  243. ref: "slider",
  244. staticClass: "el-slider__runway",
  245. class: { "show-input": _vm.showInput, disabled: _vm.sliderDisabled },
  246. style: _vm.runwayStyle,
  247. on: { click: _vm.onSliderClick }
  248. },
  249. [
  250. _c("div", { staticClass: "el-slider__bar", style: _vm.barStyle }),
  251. _c("slider-button", {
  252. ref: "button1",
  253. attrs: {
  254. vertical: _vm.vertical,
  255. "tooltip-class": _vm.tooltipClass
  256. },
  257. model: {
  258. value: _vm.firstValue,
  259. callback: function($$v) {
  260. _vm.firstValue = $$v
  261. },
  262. expression: "firstValue"
  263. }
  264. }),
  265. _vm.range
  266. ? _c("slider-button", {
  267. ref: "button2",
  268. attrs: {
  269. vertical: _vm.vertical,
  270. "tooltip-class": _vm.tooltipClass
  271. },
  272. model: {
  273. value: _vm.secondValue,
  274. callback: function($$v) {
  275. _vm.secondValue = $$v
  276. },
  277. expression: "secondValue"
  278. }
  279. })
  280. : _vm._e(),
  281. _vm._l(_vm.stops, function(item, key) {
  282. return _vm.showStops
  283. ? _c("div", {
  284. key: key,
  285. staticClass: "el-slider__stop",
  286. style: _vm.getStopStyle(item)
  287. })
  288. : _vm._e()
  289. }),
  290. _vm.markList.length > 0
  291. ? [
  292. _c(
  293. "div",
  294. _vm._l(_vm.markList, function(item, key) {
  295. return _c("div", {
  296. key: key,
  297. staticClass: "el-slider__stop el-slider__marks-stop",
  298. style: _vm.getStopStyle(item.position)
  299. })
  300. }),
  301. 0
  302. ),
  303. _c(
  304. "div",
  305. { staticClass: "el-slider__marks" },
  306. _vm._l(_vm.markList, function(item, key) {
  307. return _c("slider-marker", {
  308. key: key,
  309. style: _vm.getStopStyle(item.position),
  310. attrs: { mark: item.mark }
  311. })
  312. }),
  313. 1
  314. )
  315. ]
  316. : _vm._e()
  317. ],
  318. 2
  319. )
  320. ],
  321. 1
  322. )
  323. }
  324. var staticRenderFns = []
  325. render._withStripped = true
  326. // CONCATENATED MODULE: ./packages/slider/src/main.vue?vue&type=template&id=32708644&
  327. // EXTERNAL MODULE: external "element-ui/lib/input-number"
  328. var input_number_ = __webpack_require__(49);
  329. var input_number_default = /*#__PURE__*/__webpack_require__.n(input_number_);
  330. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/slider/src/button.vue?vue&type=template&id=e72d2ad2&
  331. var buttonvue_type_template_id_e72d2ad2_render = function() {
  332. var _vm = this
  333. var _h = _vm.$createElement
  334. var _c = _vm._self._c || _h
  335. return _c(
  336. "div",
  337. {
  338. ref: "button",
  339. staticClass: "el-slider__button-wrapper",
  340. class: { hover: _vm.hovering, dragging: _vm.dragging },
  341. style: _vm.wrapperStyle,
  342. attrs: { tabindex: "0" },
  343. on: {
  344. mouseenter: _vm.handleMouseEnter,
  345. mouseleave: _vm.handleMouseLeave,
  346. mousedown: _vm.onButtonDown,
  347. touchstart: _vm.onButtonDown,
  348. focus: _vm.handleMouseEnter,
  349. blur: _vm.handleMouseLeave,
  350. keydown: [
  351. function($event) {
  352. if (
  353. !("button" in $event) &&
  354. _vm._k($event.keyCode, "left", 37, $event.key, [
  355. "Left",
  356. "ArrowLeft"
  357. ])
  358. ) {
  359. return null
  360. }
  361. if ("button" in $event && $event.button !== 0) {
  362. return null
  363. }
  364. return _vm.onLeftKeyDown($event)
  365. },
  366. function($event) {
  367. if (
  368. !("button" in $event) &&
  369. _vm._k($event.keyCode, "right", 39, $event.key, [
  370. "Right",
  371. "ArrowRight"
  372. ])
  373. ) {
  374. return null
  375. }
  376. if ("button" in $event && $event.button !== 2) {
  377. return null
  378. }
  379. return _vm.onRightKeyDown($event)
  380. },
  381. function($event) {
  382. if (
  383. !("button" in $event) &&
  384. _vm._k($event.keyCode, "down", 40, $event.key, [
  385. "Down",
  386. "ArrowDown"
  387. ])
  388. ) {
  389. return null
  390. }
  391. $event.preventDefault()
  392. return _vm.onLeftKeyDown($event)
  393. },
  394. function($event) {
  395. if (
  396. !("button" in $event) &&
  397. _vm._k($event.keyCode, "up", 38, $event.key, ["Up", "ArrowUp"])
  398. ) {
  399. return null
  400. }
  401. $event.preventDefault()
  402. return _vm.onRightKeyDown($event)
  403. }
  404. ]
  405. }
  406. },
  407. [
  408. _c(
  409. "el-tooltip",
  410. {
  411. ref: "tooltip",
  412. attrs: {
  413. placement: "top",
  414. "popper-class": _vm.tooltipClass,
  415. disabled: !_vm.showTooltip
  416. }
  417. },
  418. [
  419. _c("span", { attrs: { slot: "content" }, slot: "content" }, [
  420. _vm._v(_vm._s(_vm.formatValue))
  421. ]),
  422. _c("div", {
  423. staticClass: "el-slider__button",
  424. class: { hover: _vm.hovering, dragging: _vm.dragging }
  425. })
  426. ]
  427. )
  428. ],
  429. 1
  430. )
  431. }
  432. var buttonvue_type_template_id_e72d2ad2_staticRenderFns = []
  433. buttonvue_type_template_id_e72d2ad2_render._withStripped = true
  434. // CONCATENATED MODULE: ./packages/slider/src/button.vue?vue&type=template&id=e72d2ad2&
  435. // EXTERNAL MODULE: external "element-ui/lib/tooltip"
  436. var tooltip_ = __webpack_require__(29);
  437. var tooltip_default = /*#__PURE__*/__webpack_require__.n(tooltip_);
  438. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/slider/src/button.vue?vue&type=script&lang=js&
  439. //
  440. //
  441. //
  442. //
  443. //
  444. //
  445. //
  446. //
  447. //
  448. //
  449. //
  450. //
  451. //
  452. //
  453. //
  454. //
  455. //
  456. //
  457. //
  458. //
  459. //
  460. //
  461. //
  462. //
  463. //
  464. //
  465. //
  466. //
  467. //
  468. /* harmony default export */ var buttonvue_type_script_lang_js_ = ({
  469. name: 'ElSliderButton',
  470. components: {
  471. ElTooltip: tooltip_default.a
  472. },
  473. props: {
  474. value: {
  475. type: Number,
  476. default: 0
  477. },
  478. vertical: {
  479. type: Boolean,
  480. default: false
  481. },
  482. tooltipClass: String
  483. },
  484. data: function data() {
  485. return {
  486. hovering: false,
  487. dragging: false,
  488. isClick: false,
  489. startX: 0,
  490. currentX: 0,
  491. startY: 0,
  492. currentY: 0,
  493. startPosition: 0,
  494. newPosition: null,
  495. oldValue: this.value
  496. };
  497. },
  498. computed: {
  499. disabled: function disabled() {
  500. return this.$parent.sliderDisabled;
  501. },
  502. max: function max() {
  503. return this.$parent.max;
  504. },
  505. min: function min() {
  506. return this.$parent.min;
  507. },
  508. step: function step() {
  509. return this.$parent.step;
  510. },
  511. showTooltip: function showTooltip() {
  512. return this.$parent.showTooltip;
  513. },
  514. precision: function precision() {
  515. return this.$parent.precision;
  516. },
  517. currentPosition: function currentPosition() {
  518. return (this.value - this.min) / (this.max - this.min) * 100 + '%';
  519. },
  520. enableFormat: function enableFormat() {
  521. return this.$parent.formatTooltip instanceof Function;
  522. },
  523. formatValue: function formatValue() {
  524. return this.enableFormat && this.$parent.formatTooltip(this.value) || this.value;
  525. },
  526. wrapperStyle: function wrapperStyle() {
  527. return this.vertical ? { bottom: this.currentPosition } : { left: this.currentPosition };
  528. }
  529. },
  530. watch: {
  531. dragging: function dragging(val) {
  532. this.$parent.dragging = val;
  533. }
  534. },
  535. methods: {
  536. displayTooltip: function displayTooltip() {
  537. this.$refs.tooltip && (this.$refs.tooltip.showPopper = true);
  538. },
  539. hideTooltip: function hideTooltip() {
  540. this.$refs.tooltip && (this.$refs.tooltip.showPopper = false);
  541. },
  542. handleMouseEnter: function handleMouseEnter() {
  543. this.hovering = true;
  544. this.displayTooltip();
  545. },
  546. handleMouseLeave: function handleMouseLeave() {
  547. this.hovering = false;
  548. this.hideTooltip();
  549. },
  550. onButtonDown: function onButtonDown(event) {
  551. if (this.disabled) return;
  552. event.preventDefault();
  553. this.onDragStart(event);
  554. window.addEventListener('mousemove', this.onDragging);
  555. window.addEventListener('touchmove', this.onDragging);
  556. window.addEventListener('mouseup', this.onDragEnd);
  557. window.addEventListener('touchend', this.onDragEnd);
  558. window.addEventListener('contextmenu', this.onDragEnd);
  559. },
  560. onLeftKeyDown: function onLeftKeyDown() {
  561. if (this.disabled) return;
  562. this.newPosition = parseFloat(this.currentPosition) - this.step / (this.max - this.min) * 100;
  563. this.setPosition(this.newPosition);
  564. this.$parent.emitChange();
  565. },
  566. onRightKeyDown: function onRightKeyDown() {
  567. if (this.disabled) return;
  568. this.newPosition = parseFloat(this.currentPosition) + this.step / (this.max - this.min) * 100;
  569. this.setPosition(this.newPosition);
  570. this.$parent.emitChange();
  571. },
  572. onDragStart: function onDragStart(event) {
  573. this.dragging = true;
  574. this.isClick = true;
  575. if (event.type === 'touchstart') {
  576. event.clientY = event.touches[0].clientY;
  577. event.clientX = event.touches[0].clientX;
  578. }
  579. if (this.vertical) {
  580. this.startY = event.clientY;
  581. } else {
  582. this.startX = event.clientX;
  583. }
  584. this.startPosition = parseFloat(this.currentPosition);
  585. this.newPosition = this.startPosition;
  586. },
  587. onDragging: function onDragging(event) {
  588. if (this.dragging) {
  589. this.isClick = false;
  590. this.displayTooltip();
  591. this.$parent.resetSize();
  592. var diff = 0;
  593. if (event.type === 'touchmove') {
  594. event.clientY = event.touches[0].clientY;
  595. event.clientX = event.touches[0].clientX;
  596. }
  597. if (this.vertical) {
  598. this.currentY = event.clientY;
  599. diff = (this.startY - this.currentY) / this.$parent.sliderSize * 100;
  600. } else {
  601. this.currentX = event.clientX;
  602. diff = (this.currentX - this.startX) / this.$parent.sliderSize * 100;
  603. }
  604. this.newPosition = this.startPosition + diff;
  605. this.setPosition(this.newPosition);
  606. }
  607. },
  608. onDragEnd: function onDragEnd() {
  609. var _this = this;
  610. if (this.dragging) {
  611. /*
  612. * 防止在 mouseup 后立即触发 click,导致滑块有几率产生一小段位移
  613. * 不使用 preventDefault 是因为 mouseup 和 click 没有注册在同一个 DOM 上
  614. */
  615. setTimeout(function () {
  616. _this.dragging = false;
  617. _this.hideTooltip();
  618. if (!_this.isClick) {
  619. _this.setPosition(_this.newPosition);
  620. _this.$parent.emitChange();
  621. }
  622. }, 0);
  623. window.removeEventListener('mousemove', this.onDragging);
  624. window.removeEventListener('touchmove', this.onDragging);
  625. window.removeEventListener('mouseup', this.onDragEnd);
  626. window.removeEventListener('touchend', this.onDragEnd);
  627. window.removeEventListener('contextmenu', this.onDragEnd);
  628. }
  629. },
  630. setPosition: function setPosition(newPosition) {
  631. var _this2 = this;
  632. if (newPosition === null || isNaN(newPosition)) return;
  633. if (newPosition < 0) {
  634. newPosition = 0;
  635. } else if (newPosition > 100) {
  636. newPosition = 100;
  637. }
  638. var lengthPerStep = 100 / ((this.max - this.min) / this.step);
  639. var steps = Math.round(newPosition / lengthPerStep);
  640. var value = steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min;
  641. value = parseFloat(value.toFixed(this.precision));
  642. this.$emit('input', value);
  643. this.$nextTick(function () {
  644. _this2.displayTooltip();
  645. _this2.$refs.tooltip && _this2.$refs.tooltip.updatePopper();
  646. });
  647. if (!this.dragging && this.value !== this.oldValue) {
  648. this.oldValue = this.value;
  649. }
  650. }
  651. }
  652. });
  653. // CONCATENATED MODULE: ./packages/slider/src/button.vue?vue&type=script&lang=js&
  654. /* harmony default export */ var src_buttonvue_type_script_lang_js_ = (buttonvue_type_script_lang_js_);
  655. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  656. var componentNormalizer = __webpack_require__(0);
  657. // CONCATENATED MODULE: ./packages/slider/src/button.vue
  658. /* normalize component */
  659. var component = Object(componentNormalizer["a" /* default */])(
  660. src_buttonvue_type_script_lang_js_,
  661. buttonvue_type_template_id_e72d2ad2_render,
  662. buttonvue_type_template_id_e72d2ad2_staticRenderFns,
  663. false,
  664. null,
  665. null,
  666. null
  667. )
  668. /* hot reload */
  669. if (false) { var api; }
  670. component.options.__file = "packages/slider/src/button.vue"
  671. /* harmony default export */ var src_button = (component.exports);
  672. // CONCATENATED MODULE: ./packages/slider/src/marker.js
  673. /* harmony default export */ var marker = ({
  674. name: 'ElMarker',
  675. props: {
  676. mark: {
  677. type: [String, Object]
  678. }
  679. },
  680. render: function render() {
  681. var h = arguments[0];
  682. var label = typeof this.mark === 'string' ? this.mark : this.mark.label;
  683. return h(
  684. 'div',
  685. { 'class': 'el-slider__marks-text', style: this.mark.style || {} },
  686. [label]
  687. );
  688. }
  689. });
  690. // EXTERNAL MODULE: external "element-ui/lib/mixins/emitter"
  691. var emitter_ = __webpack_require__(4);
  692. var emitter_default = /*#__PURE__*/__webpack_require__.n(emitter_);
  693. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/slider/src/main.vue?vue&type=script&lang=js&
  694. //
  695. //
  696. //
  697. //
  698. //
  699. //
  700. //
  701. //
  702. //
  703. //
  704. //
  705. //
  706. //
  707. //
  708. //
  709. //
  710. //
  711. //
  712. //
  713. //
  714. //
  715. //
  716. //
  717. //
  718. //
  719. //
  720. //
  721. //
  722. //
  723. //
  724. //
  725. //
  726. //
  727. //
  728. //
  729. //
  730. //
  731. //
  732. //
  733. //
  734. //
  735. //
  736. //
  737. //
  738. //
  739. //
  740. //
  741. //
  742. //
  743. //
  744. //
  745. //
  746. //
  747. //
  748. //
  749. //
  750. //
  751. //
  752. //
  753. //
  754. //
  755. //
  756. //
  757. //
  758. //
  759. //
  760. //
  761. //
  762. //
  763. //
  764. //
  765. //
  766. //
  767. //
  768. //
  769. /* harmony default export */ var mainvue_type_script_lang_js_ = ({
  770. name: 'ElSlider',
  771. mixins: [emitter_default.a],
  772. inject: {
  773. elForm: {
  774. default: ''
  775. }
  776. },
  777. props: {
  778. min: {
  779. type: Number,
  780. default: 0
  781. },
  782. max: {
  783. type: Number,
  784. default: 100
  785. },
  786. step: {
  787. type: Number,
  788. default: 1
  789. },
  790. value: {
  791. type: [Number, Array],
  792. default: 0
  793. },
  794. showInput: {
  795. type: Boolean,
  796. default: false
  797. },
  798. showInputControls: {
  799. type: Boolean,
  800. default: true
  801. },
  802. inputSize: {
  803. type: String,
  804. default: 'small'
  805. },
  806. showStops: {
  807. type: Boolean,
  808. default: false
  809. },
  810. showTooltip: {
  811. type: Boolean,
  812. default: true
  813. },
  814. formatTooltip: Function,
  815. disabled: {
  816. type: Boolean,
  817. default: false
  818. },
  819. range: {
  820. type: Boolean,
  821. default: false
  822. },
  823. vertical: {
  824. type: Boolean,
  825. default: false
  826. },
  827. height: {
  828. type: String
  829. },
  830. debounce: {
  831. type: Number,
  832. default: 300
  833. },
  834. label: {
  835. type: String
  836. },
  837. tooltipClass: String,
  838. marks: Object
  839. },
  840. components: {
  841. ElInputNumber: input_number_default.a,
  842. SliderButton: src_button,
  843. SliderMarker: marker
  844. },
  845. data: function data() {
  846. return {
  847. firstValue: null,
  848. secondValue: null,
  849. oldValue: null,
  850. dragging: false,
  851. sliderSize: 1
  852. };
  853. },
  854. watch: {
  855. value: function value(val, oldVal) {
  856. if (this.dragging || Array.isArray(val) && Array.isArray(oldVal) && val.every(function (item, index) {
  857. return item === oldVal[index];
  858. })) {
  859. return;
  860. }
  861. this.setValues();
  862. },
  863. dragging: function dragging(val) {
  864. if (!val) {
  865. this.setValues();
  866. }
  867. },
  868. firstValue: function firstValue(val) {
  869. if (this.range) {
  870. this.$emit('input', [this.minValue, this.maxValue]);
  871. } else {
  872. this.$emit('input', val);
  873. }
  874. },
  875. secondValue: function secondValue() {
  876. if (this.range) {
  877. this.$emit('input', [this.minValue, this.maxValue]);
  878. }
  879. },
  880. min: function min() {
  881. this.setValues();
  882. },
  883. max: function max() {
  884. this.setValues();
  885. }
  886. },
  887. methods: {
  888. valueChanged: function valueChanged() {
  889. var _this = this;
  890. if (this.range) {
  891. return ![this.minValue, this.maxValue].every(function (item, index) {
  892. return item === _this.oldValue[index];
  893. });
  894. } else {
  895. return this.value !== this.oldValue;
  896. }
  897. },
  898. setValues: function setValues() {
  899. if (this.min > this.max) {
  900. console.error('[Element Error][Slider]min should not be greater than max.');
  901. return;
  902. }
  903. var val = this.value;
  904. if (this.range && Array.isArray(val)) {
  905. if (val[1] < this.min) {
  906. this.$emit('input', [this.min, this.min]);
  907. } else if (val[0] > this.max) {
  908. this.$emit('input', [this.max, this.max]);
  909. } else if (val[0] < this.min) {
  910. this.$emit('input', [this.min, val[1]]);
  911. } else if (val[1] > this.max) {
  912. this.$emit('input', [val[0], this.max]);
  913. } else {
  914. this.firstValue = val[0];
  915. this.secondValue = val[1];
  916. if (this.valueChanged()) {
  917. this.dispatch('ElFormItem', 'el.form.change', [this.minValue, this.maxValue]);
  918. this.oldValue = val.slice();
  919. }
  920. }
  921. } else if (!this.range && typeof val === 'number' && !isNaN(val)) {
  922. if (val < this.min) {
  923. this.$emit('input', this.min);
  924. } else if (val > this.max) {
  925. this.$emit('input', this.max);
  926. } else {
  927. this.firstValue = val;
  928. if (this.valueChanged()) {
  929. this.dispatch('ElFormItem', 'el.form.change', val);
  930. this.oldValue = val;
  931. }
  932. }
  933. }
  934. },
  935. setPosition: function setPosition(percent) {
  936. var targetValue = this.min + percent * (this.max - this.min) / 100;
  937. if (!this.range) {
  938. this.$refs.button1.setPosition(percent);
  939. return;
  940. }
  941. var button = void 0;
  942. if (Math.abs(this.minValue - targetValue) < Math.abs(this.maxValue - targetValue)) {
  943. button = this.firstValue < this.secondValue ? 'button1' : 'button2';
  944. } else {
  945. button = this.firstValue > this.secondValue ? 'button1' : 'button2';
  946. }
  947. this.$refs[button].setPosition(percent);
  948. },
  949. onSliderClick: function onSliderClick(event) {
  950. if (this.sliderDisabled || this.dragging) return;
  951. this.resetSize();
  952. if (this.vertical) {
  953. var sliderOffsetBottom = this.$refs.slider.getBoundingClientRect().bottom;
  954. this.setPosition((sliderOffsetBottom - event.clientY) / this.sliderSize * 100);
  955. } else {
  956. var sliderOffsetLeft = this.$refs.slider.getBoundingClientRect().left;
  957. this.setPosition((event.clientX - sliderOffsetLeft) / this.sliderSize * 100);
  958. }
  959. this.emitChange();
  960. },
  961. resetSize: function resetSize() {
  962. if (this.$refs.slider) {
  963. this.sliderSize = this.$refs.slider['client' + (this.vertical ? 'Height' : 'Width')];
  964. }
  965. },
  966. emitChange: function emitChange() {
  967. var _this2 = this;
  968. this.$nextTick(function () {
  969. _this2.$emit('change', _this2.range ? [_this2.minValue, _this2.maxValue] : _this2.value);
  970. });
  971. },
  972. getStopStyle: function getStopStyle(position) {
  973. return this.vertical ? { 'bottom': position + '%' } : { 'left': position + '%' };
  974. }
  975. },
  976. computed: {
  977. stops: function stops() {
  978. var _this3 = this;
  979. if (!this.showStops || this.min > this.max) return [];
  980. if (this.step === 0) {
  981. false && false;
  982. return [];
  983. }
  984. var stopCount = (this.max - this.min) / this.step;
  985. var stepWidth = 100 * this.step / (this.max - this.min);
  986. var result = [];
  987. for (var i = 1; i < stopCount; i++) {
  988. result.push(i * stepWidth);
  989. }
  990. if (this.range) {
  991. return result.filter(function (step) {
  992. return step < 100 * (_this3.minValue - _this3.min) / (_this3.max - _this3.min) || step > 100 * (_this3.maxValue - _this3.min) / (_this3.max - _this3.min);
  993. });
  994. } else {
  995. return result.filter(function (step) {
  996. return step > 100 * (_this3.firstValue - _this3.min) / (_this3.max - _this3.min);
  997. });
  998. }
  999. },
  1000. markList: function markList() {
  1001. var _this4 = this;
  1002. if (!this.marks) {
  1003. return [];
  1004. }
  1005. var marksKeys = Object.keys(this.marks);
  1006. return marksKeys.map(parseFloat).sort(function (a, b) {
  1007. return a - b;
  1008. }).filter(function (point) {
  1009. return point <= _this4.max && point >= _this4.min;
  1010. }).map(function (point) {
  1011. return {
  1012. point: point,
  1013. position: (point - _this4.min) * 100 / (_this4.max - _this4.min),
  1014. mark: _this4.marks[point]
  1015. };
  1016. });
  1017. },
  1018. minValue: function minValue() {
  1019. return Math.min(this.firstValue, this.secondValue);
  1020. },
  1021. maxValue: function maxValue() {
  1022. return Math.max(this.firstValue, this.secondValue);
  1023. },
  1024. barSize: function barSize() {
  1025. return this.range ? 100 * (this.maxValue - this.minValue) / (this.max - this.min) + '%' : 100 * (this.firstValue - this.min) / (this.max - this.min) + '%';
  1026. },
  1027. barStart: function barStart() {
  1028. return this.range ? 100 * (this.minValue - this.min) / (this.max - this.min) + '%' : '0%';
  1029. },
  1030. precision: function precision() {
  1031. var precisions = [this.min, this.max, this.step].map(function (item) {
  1032. var decimal = ('' + item).split('.')[1];
  1033. return decimal ? decimal.length : 0;
  1034. });
  1035. return Math.max.apply(null, precisions);
  1036. },
  1037. runwayStyle: function runwayStyle() {
  1038. return this.vertical ? { height: this.height } : {};
  1039. },
  1040. barStyle: function barStyle() {
  1041. return this.vertical ? {
  1042. height: this.barSize,
  1043. bottom: this.barStart
  1044. } : {
  1045. width: this.barSize,
  1046. left: this.barStart
  1047. };
  1048. },
  1049. sliderDisabled: function sliderDisabled() {
  1050. return this.disabled || (this.elForm || {}).disabled;
  1051. }
  1052. },
  1053. mounted: function mounted() {
  1054. var valuetext = void 0;
  1055. if (this.range) {
  1056. if (Array.isArray(this.value)) {
  1057. this.firstValue = Math.max(this.min, this.value[0]);
  1058. this.secondValue = Math.min(this.max, this.value[1]);
  1059. } else {
  1060. this.firstValue = this.min;
  1061. this.secondValue = this.max;
  1062. }
  1063. this.oldValue = [this.firstValue, this.secondValue];
  1064. valuetext = this.firstValue + '-' + this.secondValue;
  1065. } else {
  1066. if (typeof this.value !== 'number' || isNaN(this.value)) {
  1067. this.firstValue = this.min;
  1068. } else {
  1069. this.firstValue = Math.min(this.max, Math.max(this.min, this.value));
  1070. }
  1071. this.oldValue = this.firstValue;
  1072. valuetext = this.firstValue;
  1073. }
  1074. this.$el.setAttribute('aria-valuetext', valuetext);
  1075. // label screen reader
  1076. this.$el.setAttribute('aria-label', this.label ? this.label : 'slider between ' + this.min + ' and ' + this.max);
  1077. this.resetSize();
  1078. window.addEventListener('resize', this.resetSize);
  1079. },
  1080. beforeDestroy: function beforeDestroy() {
  1081. window.removeEventListener('resize', this.resetSize);
  1082. }
  1083. });
  1084. // CONCATENATED MODULE: ./packages/slider/src/main.vue?vue&type=script&lang=js&
  1085. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  1086. // CONCATENATED MODULE: ./packages/slider/src/main.vue
  1087. /* normalize component */
  1088. var main_component = Object(componentNormalizer["a" /* default */])(
  1089. src_mainvue_type_script_lang_js_,
  1090. render,
  1091. staticRenderFns,
  1092. false,
  1093. null,
  1094. null,
  1095. null
  1096. )
  1097. /* hot reload */
  1098. if (false) { var main_api; }
  1099. main_component.options.__file = "packages/slider/src/main.vue"
  1100. /* harmony default export */ var main = (main_component.exports);
  1101. // CONCATENATED MODULE: ./packages/slider/index.js
  1102. /* istanbul ignore next */
  1103. main.install = function (Vue) {
  1104. Vue.component(main.name, main);
  1105. };
  1106. /* harmony default export */ var slider = __webpack_exports__["default"] = (main);
  1107. /***/ })
  1108. /******/ });