slider.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  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 = 55);
  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. /***/ 24:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/tooltip");
  182. /***/ }),
  183. /***/ 3:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/mixins/emitter");
  186. /***/ }),
  187. /***/ 46:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/input-number");
  190. /***/ }),
  191. /***/ 55:
  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: {
  231. change: function($event) {
  232. _vm.$nextTick(_vm.emitChange)
  233. }
  234. },
  235. model: {
  236. value: _vm.firstValue,
  237. callback: function($$v) {
  238. _vm.firstValue = $$v
  239. },
  240. expression: "firstValue"
  241. }
  242. })
  243. : _vm._e(),
  244. _c(
  245. "div",
  246. {
  247. ref: "slider",
  248. staticClass: "el-slider__runway",
  249. class: { "show-input": _vm.showInput, disabled: _vm.sliderDisabled },
  250. style: _vm.runwayStyle,
  251. on: { click: _vm.onSliderClick }
  252. },
  253. [
  254. _c("div", { staticClass: "el-slider__bar", style: _vm.barStyle }),
  255. _c("slider-button", {
  256. ref: "button1",
  257. attrs: {
  258. vertical: _vm.vertical,
  259. "tooltip-class": _vm.tooltipClass
  260. },
  261. model: {
  262. value: _vm.firstValue,
  263. callback: function($$v) {
  264. _vm.firstValue = $$v
  265. },
  266. expression: "firstValue"
  267. }
  268. }),
  269. _vm.range
  270. ? _c("slider-button", {
  271. ref: "button2",
  272. attrs: {
  273. vertical: _vm.vertical,
  274. "tooltip-class": _vm.tooltipClass
  275. },
  276. model: {
  277. value: _vm.secondValue,
  278. callback: function($$v) {
  279. _vm.secondValue = $$v
  280. },
  281. expression: "secondValue"
  282. }
  283. })
  284. : _vm._e(),
  285. _vm._l(_vm.stops, function(item, key) {
  286. return _vm.showStops
  287. ? _c("div", {
  288. key: key,
  289. staticClass: "el-slider__stop",
  290. style: _vm.getStopStyle(item)
  291. })
  292. : _vm._e()
  293. }),
  294. _vm.markList.length > 0
  295. ? [
  296. _c(
  297. "div",
  298. _vm._l(_vm.markList, function(item, key) {
  299. return _c("div", {
  300. key: key,
  301. staticClass: "el-slider__stop el-slider__marks-stop",
  302. style: _vm.getStopStyle(item.position)
  303. })
  304. }),
  305. 0
  306. ),
  307. _c(
  308. "div",
  309. { staticClass: "el-slider__marks" },
  310. _vm._l(_vm.markList, function(item, key) {
  311. return _c("slider-marker", {
  312. key: key,
  313. style: _vm.getStopStyle(item.position),
  314. attrs: { mark: item.mark }
  315. })
  316. }),
  317. 1
  318. )
  319. ]
  320. : _vm._e()
  321. ],
  322. 2
  323. )
  324. ],
  325. 1
  326. )
  327. }
  328. var staticRenderFns = []
  329. render._withStripped = true
  330. // CONCATENATED MODULE: ./packages/slider/src/main.vue?vue&type=template&id=32708644&
  331. // EXTERNAL MODULE: external "element-ui/lib/input-number"
  332. var input_number_ = __webpack_require__(46);
  333. var input_number_default = /*#__PURE__*/__webpack_require__.n(input_number_);
  334. // 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&
  335. var buttonvue_type_template_id_e72d2ad2_render = function() {
  336. var _vm = this
  337. var _h = _vm.$createElement
  338. var _c = _vm._self._c || _h
  339. return _c(
  340. "div",
  341. {
  342. ref: "button",
  343. staticClass: "el-slider__button-wrapper",
  344. class: { hover: _vm.hovering, dragging: _vm.dragging },
  345. style: _vm.wrapperStyle,
  346. attrs: { tabindex: "0" },
  347. on: {
  348. mouseenter: _vm.handleMouseEnter,
  349. mouseleave: _vm.handleMouseLeave,
  350. mousedown: _vm.onButtonDown,
  351. touchstart: _vm.onButtonDown,
  352. focus: _vm.handleMouseEnter,
  353. blur: _vm.handleMouseLeave,
  354. keydown: [
  355. function($event) {
  356. if (
  357. !("button" in $event) &&
  358. _vm._k($event.keyCode, "left", 37, $event.key, [
  359. "Left",
  360. "ArrowLeft"
  361. ])
  362. ) {
  363. return null
  364. }
  365. if ("button" in $event && $event.button !== 0) {
  366. return null
  367. }
  368. return _vm.onLeftKeyDown($event)
  369. },
  370. function($event) {
  371. if (
  372. !("button" in $event) &&
  373. _vm._k($event.keyCode, "right", 39, $event.key, [
  374. "Right",
  375. "ArrowRight"
  376. ])
  377. ) {
  378. return null
  379. }
  380. if ("button" in $event && $event.button !== 2) {
  381. return null
  382. }
  383. return _vm.onRightKeyDown($event)
  384. },
  385. function($event) {
  386. if (
  387. !("button" in $event) &&
  388. _vm._k($event.keyCode, "down", 40, $event.key, [
  389. "Down",
  390. "ArrowDown"
  391. ])
  392. ) {
  393. return null
  394. }
  395. $event.preventDefault()
  396. return _vm.onLeftKeyDown($event)
  397. },
  398. function($event) {
  399. if (
  400. !("button" in $event) &&
  401. _vm._k($event.keyCode, "up", 38, $event.key, ["Up", "ArrowUp"])
  402. ) {
  403. return null
  404. }
  405. $event.preventDefault()
  406. return _vm.onRightKeyDown($event)
  407. }
  408. ]
  409. }
  410. },
  411. [
  412. _c(
  413. "el-tooltip",
  414. {
  415. ref: "tooltip",
  416. attrs: {
  417. placement: "top",
  418. "popper-class": _vm.tooltipClass,
  419. disabled: !_vm.showTooltip
  420. }
  421. },
  422. [
  423. _c("span", { attrs: { slot: "content" }, slot: "content" }, [
  424. _vm._v(_vm._s(_vm.formatValue))
  425. ]),
  426. _c("div", {
  427. staticClass: "el-slider__button",
  428. class: { hover: _vm.hovering, dragging: _vm.dragging }
  429. })
  430. ]
  431. )
  432. ],
  433. 1
  434. )
  435. }
  436. var buttonvue_type_template_id_e72d2ad2_staticRenderFns = []
  437. buttonvue_type_template_id_e72d2ad2_render._withStripped = true
  438. // CONCATENATED MODULE: ./packages/slider/src/button.vue?vue&type=template&id=e72d2ad2&
  439. // EXTERNAL MODULE: external "element-ui/lib/tooltip"
  440. var tooltip_ = __webpack_require__(24);
  441. var tooltip_default = /*#__PURE__*/__webpack_require__.n(tooltip_);
  442. // 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&
  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. //
  469. //
  470. //
  471. //
  472. /* harmony default export */ var buttonvue_type_script_lang_js_ = ({
  473. name: 'ElSliderButton',
  474. components: {
  475. ElTooltip: tooltip_default.a
  476. },
  477. props: {
  478. value: {
  479. type: Number,
  480. default: 0
  481. },
  482. vertical: {
  483. type: Boolean,
  484. default: false
  485. },
  486. tooltipClass: String
  487. },
  488. data: function data() {
  489. return {
  490. hovering: false,
  491. dragging: false,
  492. isClick: false,
  493. startX: 0,
  494. currentX: 0,
  495. startY: 0,
  496. currentY: 0,
  497. startPosition: 0,
  498. newPosition: null,
  499. oldValue: this.value
  500. };
  501. },
  502. computed: {
  503. disabled: function disabled() {
  504. return this.$parent.sliderDisabled;
  505. },
  506. max: function max() {
  507. return this.$parent.max;
  508. },
  509. min: function min() {
  510. return this.$parent.min;
  511. },
  512. step: function step() {
  513. return this.$parent.step;
  514. },
  515. showTooltip: function showTooltip() {
  516. return this.$parent.showTooltip;
  517. },
  518. precision: function precision() {
  519. return this.$parent.precision;
  520. },
  521. currentPosition: function currentPosition() {
  522. return (this.value - this.min) / (this.max - this.min) * 100 + '%';
  523. },
  524. enableFormat: function enableFormat() {
  525. return this.$parent.formatTooltip instanceof Function;
  526. },
  527. formatValue: function formatValue() {
  528. return this.enableFormat && this.$parent.formatTooltip(this.value) || this.value;
  529. },
  530. wrapperStyle: function wrapperStyle() {
  531. return this.vertical ? { bottom: this.currentPosition } : { left: this.currentPosition };
  532. }
  533. },
  534. watch: {
  535. dragging: function dragging(val) {
  536. this.$parent.dragging = val;
  537. }
  538. },
  539. methods: {
  540. displayTooltip: function displayTooltip() {
  541. this.$refs.tooltip && (this.$refs.tooltip.showPopper = true);
  542. },
  543. hideTooltip: function hideTooltip() {
  544. this.$refs.tooltip && (this.$refs.tooltip.showPopper = false);
  545. },
  546. handleMouseEnter: function handleMouseEnter() {
  547. this.hovering = true;
  548. this.displayTooltip();
  549. },
  550. handleMouseLeave: function handleMouseLeave() {
  551. this.hovering = false;
  552. this.hideTooltip();
  553. },
  554. onButtonDown: function onButtonDown(event) {
  555. if (this.disabled) return;
  556. event.preventDefault();
  557. this.onDragStart(event);
  558. window.addEventListener('mousemove', this.onDragging);
  559. window.addEventListener('touchmove', this.onDragging);
  560. window.addEventListener('mouseup', this.onDragEnd);
  561. window.addEventListener('touchend', this.onDragEnd);
  562. window.addEventListener('contextmenu', this.onDragEnd);
  563. },
  564. onLeftKeyDown: function onLeftKeyDown() {
  565. if (this.disabled) return;
  566. this.newPosition = parseFloat(this.currentPosition) - this.step / (this.max - this.min) * 100;
  567. this.setPosition(this.newPosition);
  568. this.$parent.emitChange();
  569. },
  570. onRightKeyDown: function onRightKeyDown() {
  571. if (this.disabled) return;
  572. this.newPosition = parseFloat(this.currentPosition) + this.step / (this.max - this.min) * 100;
  573. this.setPosition(this.newPosition);
  574. this.$parent.emitChange();
  575. },
  576. onDragStart: function onDragStart(event) {
  577. this.dragging = true;
  578. this.isClick = true;
  579. if (event.type === 'touchstart') {
  580. event.clientY = event.touches[0].clientY;
  581. event.clientX = event.touches[0].clientX;
  582. }
  583. if (this.vertical) {
  584. this.startY = event.clientY;
  585. } else {
  586. this.startX = event.clientX;
  587. }
  588. this.startPosition = parseFloat(this.currentPosition);
  589. this.newPosition = this.startPosition;
  590. },
  591. onDragging: function onDragging(event) {
  592. if (this.dragging) {
  593. this.isClick = false;
  594. this.displayTooltip();
  595. this.$parent.resetSize();
  596. var diff = 0;
  597. if (event.type === 'touchmove') {
  598. event.clientY = event.touches[0].clientY;
  599. event.clientX = event.touches[0].clientX;
  600. }
  601. if (this.vertical) {
  602. this.currentY = event.clientY;
  603. diff = (this.startY - this.currentY) / this.$parent.sliderSize * 100;
  604. } else {
  605. this.currentX = event.clientX;
  606. diff = (this.currentX - this.startX) / this.$parent.sliderSize * 100;
  607. }
  608. this.newPosition = this.startPosition + diff;
  609. this.setPosition(this.newPosition);
  610. }
  611. },
  612. onDragEnd: function onDragEnd() {
  613. var _this = this;
  614. if (this.dragging) {
  615. /*
  616. * 防止在 mouseup 后立即触发 click,导致滑块有几率产生一小段位移
  617. * 不使用 preventDefault 是因为 mouseup 和 click 没有注册在同一个 DOM 上
  618. */
  619. setTimeout(function () {
  620. _this.dragging = false;
  621. _this.hideTooltip();
  622. if (!_this.isClick) {
  623. _this.setPosition(_this.newPosition);
  624. _this.$parent.emitChange();
  625. }
  626. }, 0);
  627. window.removeEventListener('mousemove', this.onDragging);
  628. window.removeEventListener('touchmove', this.onDragging);
  629. window.removeEventListener('mouseup', this.onDragEnd);
  630. window.removeEventListener('touchend', this.onDragEnd);
  631. window.removeEventListener('contextmenu', this.onDragEnd);
  632. }
  633. },
  634. setPosition: function setPosition(newPosition) {
  635. var _this2 = this;
  636. if (newPosition === null || isNaN(newPosition)) return;
  637. if (newPosition < 0) {
  638. newPosition = 0;
  639. } else if (newPosition > 100) {
  640. newPosition = 100;
  641. }
  642. var lengthPerStep = 100 / ((this.max - this.min) / this.step);
  643. var steps = Math.round(newPosition / lengthPerStep);
  644. var value = steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min;
  645. value = parseFloat(value.toFixed(this.precision));
  646. this.$emit('input', value);
  647. this.$nextTick(function () {
  648. _this2.$refs.tooltip && _this2.$refs.tooltip.updatePopper();
  649. });
  650. if (!this.dragging && this.value !== this.oldValue) {
  651. this.oldValue = this.value;
  652. }
  653. }
  654. }
  655. });
  656. // CONCATENATED MODULE: ./packages/slider/src/button.vue?vue&type=script&lang=js&
  657. /* harmony default export */ var src_buttonvue_type_script_lang_js_ = (buttonvue_type_script_lang_js_);
  658. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  659. var componentNormalizer = __webpack_require__(0);
  660. // CONCATENATED MODULE: ./packages/slider/src/button.vue
  661. /* normalize component */
  662. var component = Object(componentNormalizer["a" /* default */])(
  663. src_buttonvue_type_script_lang_js_,
  664. buttonvue_type_template_id_e72d2ad2_render,
  665. buttonvue_type_template_id_e72d2ad2_staticRenderFns,
  666. false,
  667. null,
  668. null,
  669. null
  670. )
  671. /* hot reload */
  672. if (false) { var api; }
  673. component.options.__file = "packages/slider/src/button.vue"
  674. /* harmony default export */ var src_button = (component.exports);
  675. // CONCATENATED MODULE: ./packages/slider/src/marker.js
  676. /* harmony default export */ var marker = ({
  677. name: 'ElMarker',
  678. props: {
  679. mark: {
  680. type: [String, Object]
  681. }
  682. },
  683. render: function render() {
  684. var h = arguments[0];
  685. var label = typeof this.mark === 'string' ? this.mark : this.mark.label;
  686. return h(
  687. 'div',
  688. { 'class': 'el-slider__marks-text', style: this.mark.style || {} },
  689. [label]
  690. );
  691. }
  692. });
  693. // EXTERNAL MODULE: external "element-ui/lib/mixins/emitter"
  694. var emitter_ = __webpack_require__(3);
  695. var emitter_default = /*#__PURE__*/__webpack_require__.n(emitter_);
  696. // 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&
  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. //
  770. //
  771. //
  772. /* harmony default export */ var mainvue_type_script_lang_js_ = ({
  773. name: 'ElSlider',
  774. mixins: [emitter_default.a],
  775. inject: {
  776. elForm: {
  777. default: ''
  778. }
  779. },
  780. props: {
  781. min: {
  782. type: Number,
  783. default: 0
  784. },
  785. max: {
  786. type: Number,
  787. default: 100
  788. },
  789. step: {
  790. type: Number,
  791. default: 1
  792. },
  793. value: {
  794. type: [Number, Array],
  795. default: 0
  796. },
  797. showInput: {
  798. type: Boolean,
  799. default: false
  800. },
  801. showInputControls: {
  802. type: Boolean,
  803. default: true
  804. },
  805. inputSize: {
  806. type: String,
  807. default: 'small'
  808. },
  809. showStops: {
  810. type: Boolean,
  811. default: false
  812. },
  813. showTooltip: {
  814. type: Boolean,
  815. default: true
  816. },
  817. formatTooltip: Function,
  818. disabled: {
  819. type: Boolean,
  820. default: false
  821. },
  822. range: {
  823. type: Boolean,
  824. default: false
  825. },
  826. vertical: {
  827. type: Boolean,
  828. default: false
  829. },
  830. height: {
  831. type: String
  832. },
  833. debounce: {
  834. type: Number,
  835. default: 300
  836. },
  837. label: {
  838. type: String
  839. },
  840. tooltipClass: String,
  841. marks: Object
  842. },
  843. components: {
  844. ElInputNumber: input_number_default.a,
  845. SliderButton: src_button,
  846. SliderMarker: marker
  847. },
  848. data: function data() {
  849. return {
  850. firstValue: null,
  851. secondValue: null,
  852. oldValue: null,
  853. dragging: false,
  854. sliderSize: 1
  855. };
  856. },
  857. watch: {
  858. value: function value(val, oldVal) {
  859. if (this.dragging || Array.isArray(val) && Array.isArray(oldVal) && val.every(function (item, index) {
  860. return item === oldVal[index];
  861. })) {
  862. return;
  863. }
  864. this.setValues();
  865. },
  866. dragging: function dragging(val) {
  867. if (!val) {
  868. this.setValues();
  869. }
  870. },
  871. firstValue: function firstValue(val) {
  872. if (this.range) {
  873. this.$emit('input', [this.minValue, this.maxValue]);
  874. } else {
  875. this.$emit('input', val);
  876. }
  877. },
  878. secondValue: function secondValue() {
  879. if (this.range) {
  880. this.$emit('input', [this.minValue, this.maxValue]);
  881. }
  882. },
  883. min: function min() {
  884. this.setValues();
  885. },
  886. max: function max() {
  887. this.setValues();
  888. }
  889. },
  890. methods: {
  891. valueChanged: function valueChanged() {
  892. var _this = this;
  893. if (this.range) {
  894. return ![this.minValue, this.maxValue].every(function (item, index) {
  895. return item === _this.oldValue[index];
  896. });
  897. } else {
  898. return this.value !== this.oldValue;
  899. }
  900. },
  901. setValues: function setValues() {
  902. if (this.min > this.max) {
  903. console.error('[Element Error][Slider]min should not be greater than max.');
  904. return;
  905. }
  906. var val = this.value;
  907. if (this.range && Array.isArray(val)) {
  908. if (val[1] < this.min) {
  909. this.$emit('input', [this.min, this.min]);
  910. } else if (val[0] > this.max) {
  911. this.$emit('input', [this.max, this.max]);
  912. } else if (val[0] < this.min) {
  913. this.$emit('input', [this.min, val[1]]);
  914. } else if (val[1] > this.max) {
  915. this.$emit('input', [val[0], this.max]);
  916. } else {
  917. this.firstValue = val[0];
  918. this.secondValue = val[1];
  919. if (this.valueChanged()) {
  920. this.dispatch('ElFormItem', 'el.form.change', [this.minValue, this.maxValue]);
  921. this.oldValue = val.slice();
  922. }
  923. }
  924. } else if (!this.range && typeof val === 'number' && !isNaN(val)) {
  925. if (val < this.min) {
  926. this.$emit('input', this.min);
  927. } else if (val > this.max) {
  928. this.$emit('input', this.max);
  929. } else {
  930. this.firstValue = val;
  931. if (this.valueChanged()) {
  932. this.dispatch('ElFormItem', 'el.form.change', val);
  933. this.oldValue = val;
  934. }
  935. }
  936. }
  937. },
  938. setPosition: function setPosition(percent) {
  939. var targetValue = this.min + percent * (this.max - this.min) / 100;
  940. if (!this.range) {
  941. this.$refs.button1.setPosition(percent);
  942. return;
  943. }
  944. var button = void 0;
  945. if (Math.abs(this.minValue - targetValue) < Math.abs(this.maxValue - targetValue)) {
  946. button = this.firstValue < this.secondValue ? 'button1' : 'button2';
  947. } else {
  948. button = this.firstValue > this.secondValue ? 'button1' : 'button2';
  949. }
  950. this.$refs[button].setPosition(percent);
  951. },
  952. onSliderClick: function onSliderClick(event) {
  953. if (this.sliderDisabled || this.dragging) return;
  954. this.resetSize();
  955. if (this.vertical) {
  956. var sliderOffsetBottom = this.$refs.slider.getBoundingClientRect().bottom;
  957. this.setPosition((sliderOffsetBottom - event.clientY) / this.sliderSize * 100);
  958. } else {
  959. var sliderOffsetLeft = this.$refs.slider.getBoundingClientRect().left;
  960. this.setPosition((event.clientX - sliderOffsetLeft) / this.sliderSize * 100);
  961. }
  962. this.emitChange();
  963. },
  964. resetSize: function resetSize() {
  965. if (this.$refs.slider) {
  966. this.sliderSize = this.$refs.slider['client' + (this.vertical ? 'Height' : 'Width')];
  967. }
  968. },
  969. emitChange: function emitChange() {
  970. var _this2 = this;
  971. this.$nextTick(function () {
  972. _this2.$emit('change', _this2.range ? [_this2.minValue, _this2.maxValue] : _this2.value);
  973. });
  974. },
  975. getStopStyle: function getStopStyle(position) {
  976. return this.vertical ? { 'bottom': position + '%' } : { 'left': position + '%' };
  977. }
  978. },
  979. computed: {
  980. stops: function stops() {
  981. var _this3 = this;
  982. if (!this.showStops || this.min > this.max) return [];
  983. if (this.step === 0) {
  984. false && false;
  985. return [];
  986. }
  987. var stopCount = (this.max - this.min) / this.step;
  988. var stepWidth = 100 * this.step / (this.max - this.min);
  989. var result = [];
  990. for (var i = 1; i < stopCount; i++) {
  991. result.push(i * stepWidth);
  992. }
  993. if (this.range) {
  994. return result.filter(function (step) {
  995. return step < 100 * (_this3.minValue - _this3.min) / (_this3.max - _this3.min) || step > 100 * (_this3.maxValue - _this3.min) / (_this3.max - _this3.min);
  996. });
  997. } else {
  998. return result.filter(function (step) {
  999. return step > 100 * (_this3.firstValue - _this3.min) / (_this3.max - _this3.min);
  1000. });
  1001. }
  1002. },
  1003. markList: function markList() {
  1004. var _this4 = this;
  1005. if (!this.marks) {
  1006. return [];
  1007. }
  1008. var marksKeys = Object.keys(this.marks);
  1009. return marksKeys.map(parseFloat).sort(function (a, b) {
  1010. return a - b;
  1011. }).filter(function (point) {
  1012. return point <= _this4.max && point >= _this4.min;
  1013. }).map(function (point) {
  1014. return {
  1015. point: point,
  1016. position: (point - _this4.min) * 100 / (_this4.max - _this4.min),
  1017. mark: _this4.marks[point]
  1018. };
  1019. });
  1020. },
  1021. minValue: function minValue() {
  1022. return Math.min(this.firstValue, this.secondValue);
  1023. },
  1024. maxValue: function maxValue() {
  1025. return Math.max(this.firstValue, this.secondValue);
  1026. },
  1027. barSize: function barSize() {
  1028. return this.range ? 100 * (this.maxValue - this.minValue) / (this.max - this.min) + '%' : 100 * (this.firstValue - this.min) / (this.max - this.min) + '%';
  1029. },
  1030. barStart: function barStart() {
  1031. return this.range ? 100 * (this.minValue - this.min) / (this.max - this.min) + '%' : '0%';
  1032. },
  1033. precision: function precision() {
  1034. var precisions = [this.min, this.max, this.step].map(function (item) {
  1035. var decimal = ('' + item).split('.')[1];
  1036. return decimal ? decimal.length : 0;
  1037. });
  1038. return Math.max.apply(null, precisions);
  1039. },
  1040. runwayStyle: function runwayStyle() {
  1041. return this.vertical ? { height: this.height } : {};
  1042. },
  1043. barStyle: function barStyle() {
  1044. return this.vertical ? {
  1045. height: this.barSize,
  1046. bottom: this.barStart
  1047. } : {
  1048. width: this.barSize,
  1049. left: this.barStart
  1050. };
  1051. },
  1052. sliderDisabled: function sliderDisabled() {
  1053. return this.disabled || (this.elForm || {}).disabled;
  1054. }
  1055. },
  1056. mounted: function mounted() {
  1057. var valuetext = void 0;
  1058. if (this.range) {
  1059. if (Array.isArray(this.value)) {
  1060. this.firstValue = Math.max(this.min, this.value[0]);
  1061. this.secondValue = Math.min(this.max, this.value[1]);
  1062. } else {
  1063. this.firstValue = this.min;
  1064. this.secondValue = this.max;
  1065. }
  1066. this.oldValue = [this.firstValue, this.secondValue];
  1067. valuetext = this.firstValue + '-' + this.secondValue;
  1068. } else {
  1069. if (typeof this.value !== 'number' || isNaN(this.value)) {
  1070. this.firstValue = this.min;
  1071. } else {
  1072. this.firstValue = Math.min(this.max, Math.max(this.min, this.value));
  1073. }
  1074. this.oldValue = this.firstValue;
  1075. valuetext = this.firstValue;
  1076. }
  1077. this.$el.setAttribute('aria-valuetext', valuetext);
  1078. // label screen reader
  1079. this.$el.setAttribute('aria-label', this.label ? this.label : 'slider between ' + this.min + ' and ' + this.max);
  1080. this.resetSize();
  1081. window.addEventListener('resize', this.resetSize);
  1082. },
  1083. beforeDestroy: function beforeDestroy() {
  1084. window.removeEventListener('resize', this.resetSize);
  1085. }
  1086. });
  1087. // CONCATENATED MODULE: ./packages/slider/src/main.vue?vue&type=script&lang=js&
  1088. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  1089. // CONCATENATED MODULE: ./packages/slider/src/main.vue
  1090. /* normalize component */
  1091. var main_component = Object(componentNormalizer["a" /* default */])(
  1092. src_mainvue_type_script_lang_js_,
  1093. render,
  1094. staticRenderFns,
  1095. false,
  1096. null,
  1097. null,
  1098. null
  1099. )
  1100. /* hot reload */
  1101. if (false) { var main_api; }
  1102. main_component.options.__file = "packages/slider/src/main.vue"
  1103. /* harmony default export */ var main = (main_component.exports);
  1104. // CONCATENATED MODULE: ./packages/slider/index.js
  1105. /* istanbul ignore next */
  1106. main.install = function (Vue) {
  1107. Vue.component(main.name, main);
  1108. };
  1109. /* harmony default export */ var slider = __webpack_exports__["default"] = (main);
  1110. /***/ })
  1111. /******/ });