carousel.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  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 = 387);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 0:
  69. /***/ (function(module, exports) {
  70. /* globals __VUE_SSR_CONTEXT__ */
  71. // IMPORTANT: Do NOT use ES2015 features in this file.
  72. // This module is a runtime utility for cleaner component module output and will
  73. // be included in the final webpack user bundle.
  74. module.exports = function normalizeComponent (
  75. rawScriptExports,
  76. compiledTemplate,
  77. functionalTemplate,
  78. injectStyles,
  79. scopeId,
  80. moduleIdentifier /* server only */
  81. ) {
  82. var esModule
  83. var scriptExports = rawScriptExports = rawScriptExports || {}
  84. // ES6 modules interop
  85. var type = typeof rawScriptExports.default
  86. if (type === 'object' || type === 'function') {
  87. esModule = rawScriptExports
  88. scriptExports = rawScriptExports.default
  89. }
  90. // Vue.extend constructor export interop
  91. var options = typeof scriptExports === 'function'
  92. ? scriptExports.options
  93. : scriptExports
  94. // render functions
  95. if (compiledTemplate) {
  96. options.render = compiledTemplate.render
  97. options.staticRenderFns = compiledTemplate.staticRenderFns
  98. options._compiled = true
  99. }
  100. // functional template
  101. if (functionalTemplate) {
  102. options.functional = true
  103. }
  104. // scopedId
  105. if (scopeId) {
  106. options._scopeId = scopeId
  107. }
  108. var hook
  109. if (moduleIdentifier) { // server build
  110. hook = function (context) {
  111. // 2.3 injection
  112. context =
  113. context || // cached call
  114. (this.$vnode && this.$vnode.ssrContext) || // stateful
  115. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  116. // 2.2 with runInNewContext: true
  117. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  118. context = __VUE_SSR_CONTEXT__
  119. }
  120. // inject component styles
  121. if (injectStyles) {
  122. injectStyles.call(this, context)
  123. }
  124. // register component module identifier for async chunk inferrence
  125. if (context && context._registeredComponents) {
  126. context._registeredComponents.add(moduleIdentifier)
  127. }
  128. }
  129. // used by ssr in case component is cached and beforeCreate
  130. // never gets called
  131. options._ssrRegister = hook
  132. } else if (injectStyles) {
  133. hook = injectStyles
  134. }
  135. if (hook) {
  136. var functional = options.functional
  137. var existing = functional
  138. ? options.render
  139. : options.beforeCreate
  140. if (!functional) {
  141. // inject component registration as beforeCreate hook
  142. options.beforeCreate = existing
  143. ? [].concat(existing, hook)
  144. : [hook]
  145. } else {
  146. // for template-only hot-reload because in that case the render fn doesn't
  147. // go through the normalizer
  148. options._injectStyles = hook
  149. // register for functioal component in vue file
  150. options.render = function renderWithStyleInjection (h, context) {
  151. hook.call(context)
  152. return existing(h, context)
  153. }
  154. }
  155. }
  156. return {
  157. esModule: esModule,
  158. exports: scriptExports,
  159. options: options
  160. }
  161. }
  162. /***/ }),
  163. /***/ 19:
  164. /***/ (function(module, exports) {
  165. module.exports = require("element-ui/lib/utils/resize-event");
  166. /***/ }),
  167. /***/ 36:
  168. /***/ (function(module, exports) {
  169. module.exports = require("throttle-debounce/throttle");
  170. /***/ }),
  171. /***/ 387:
  172. /***/ (function(module, exports, __webpack_require__) {
  173. module.exports = __webpack_require__(388);
  174. /***/ }),
  175. /***/ 388:
  176. /***/ (function(module, exports, __webpack_require__) {
  177. "use strict";
  178. exports.__esModule = true;
  179. var _main = __webpack_require__(389);
  180. var _main2 = _interopRequireDefault(_main);
  181. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  182. /* istanbul ignore next */
  183. _main2.default.install = function (Vue) {
  184. Vue.component(_main2.default.name, _main2.default);
  185. };
  186. exports.default = _main2.default;
  187. /***/ }),
  188. /***/ 389:
  189. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  190. "use strict";
  191. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  192. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__ = __webpack_require__(390);
  193. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue__);
  194. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_6d4b548e_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__ = __webpack_require__(391);
  195. var normalizeComponent = __webpack_require__(0)
  196. /* script */
  197. /* template */
  198. /* template functional */
  199. var __vue_template_functional__ = false
  200. /* styles */
  201. var __vue_styles__ = null
  202. /* scopeId */
  203. var __vue_scopeId__ = null
  204. /* moduleIdentifier (server only) */
  205. var __vue_module_identifier__ = null
  206. var Component = normalizeComponent(
  207. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_main_vue___default.a,
  208. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_6d4b548e_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_main_vue__["a" /* default */],
  209. __vue_template_functional__,
  210. __vue_styles__,
  211. __vue_scopeId__,
  212. __vue_module_identifier__
  213. )
  214. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  215. /***/ }),
  216. /***/ 390:
  217. /***/ (function(module, exports, __webpack_require__) {
  218. "use strict";
  219. exports.__esModule = true;
  220. var _throttle = __webpack_require__(36);
  221. var _throttle2 = _interopRequireDefault(_throttle);
  222. var _resizeEvent = __webpack_require__(19);
  223. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  224. //
  225. //
  226. //
  227. //
  228. //
  229. //
  230. //
  231. //
  232. //
  233. //
  234. //
  235. //
  236. //
  237. //
  238. //
  239. //
  240. //
  241. //
  242. //
  243. //
  244. //
  245. //
  246. //
  247. //
  248. //
  249. //
  250. //
  251. //
  252. //
  253. //
  254. //
  255. //
  256. //
  257. //
  258. //
  259. //
  260. //
  261. //
  262. //
  263. //
  264. //
  265. //
  266. //
  267. //
  268. //
  269. //
  270. //
  271. //
  272. //
  273. exports.default = {
  274. name: 'ElCarousel',
  275. props: {
  276. initialIndex: {
  277. type: Number,
  278. default: 0
  279. },
  280. height: String,
  281. trigger: {
  282. type: String,
  283. default: 'hover'
  284. },
  285. autoplay: {
  286. type: Boolean,
  287. default: true
  288. },
  289. interval: {
  290. type: Number,
  291. default: 3000
  292. },
  293. indicatorPosition: String,
  294. indicator: {
  295. type: Boolean,
  296. default: true
  297. },
  298. arrow: {
  299. type: String,
  300. default: 'hover'
  301. },
  302. type: String
  303. },
  304. data: function data() {
  305. return {
  306. items: [],
  307. activeIndex: -1,
  308. containerWidth: 0,
  309. timer: null,
  310. hover: false
  311. };
  312. },
  313. computed: {
  314. hasLabel: function hasLabel() {
  315. return this.items.some(function (item) {
  316. return item.label.toString().length > 0;
  317. });
  318. }
  319. },
  320. watch: {
  321. items: function items(val) {
  322. if (val.length > 0) this.setActiveItem(this.initialIndex);
  323. },
  324. activeIndex: function activeIndex(val, oldVal) {
  325. this.resetItemPosition(oldVal);
  326. this.$emit('change', val, oldVal);
  327. },
  328. autoplay: function autoplay(val) {
  329. val ? this.startTimer() : this.pauseTimer();
  330. }
  331. },
  332. methods: {
  333. handleMouseEnter: function handleMouseEnter() {
  334. this.hover = true;
  335. this.pauseTimer();
  336. },
  337. handleMouseLeave: function handleMouseLeave() {
  338. this.hover = false;
  339. this.startTimer();
  340. },
  341. itemInStage: function itemInStage(item, index) {
  342. var length = this.items.length;
  343. if (index === length - 1 && item.inStage && this.items[0].active || item.inStage && this.items[index + 1] && this.items[index + 1].active) {
  344. return 'left';
  345. } else if (index === 0 && item.inStage && this.items[length - 1].active || item.inStage && this.items[index - 1] && this.items[index - 1].active) {
  346. return 'right';
  347. }
  348. return false;
  349. },
  350. handleButtonEnter: function handleButtonEnter(arrow) {
  351. var _this = this;
  352. this.items.forEach(function (item, index) {
  353. if (arrow === _this.itemInStage(item, index)) {
  354. item.hover = true;
  355. }
  356. });
  357. },
  358. handleButtonLeave: function handleButtonLeave() {
  359. this.items.forEach(function (item) {
  360. item.hover = false;
  361. });
  362. },
  363. updateItems: function updateItems() {
  364. this.items = this.$children.filter(function (child) {
  365. return child.$options.name === 'ElCarouselItem';
  366. });
  367. },
  368. resetItemPosition: function resetItemPosition(oldIndex) {
  369. var _this2 = this;
  370. this.items.forEach(function (item, index) {
  371. item.translateItem(index, _this2.activeIndex, oldIndex);
  372. });
  373. },
  374. playSlides: function playSlides() {
  375. if (this.activeIndex < this.items.length - 1) {
  376. this.activeIndex++;
  377. } else {
  378. this.activeIndex = 0;
  379. }
  380. },
  381. pauseTimer: function pauseTimer() {
  382. clearInterval(this.timer);
  383. },
  384. startTimer: function startTimer() {
  385. if (this.interval <= 0 || !this.autoplay) return;
  386. this.timer = setInterval(this.playSlides, this.interval);
  387. },
  388. setActiveItem: function setActiveItem(index) {
  389. if (typeof index === 'string') {
  390. var filteredItems = this.items.filter(function (item) {
  391. return item.name === index;
  392. });
  393. if (filteredItems.length > 0) {
  394. index = this.items.indexOf(filteredItems[0]);
  395. }
  396. }
  397. index = Number(index);
  398. if (isNaN(index) || index !== Math.floor(index)) {
  399. "production" !== 'production' && console.warn('[Element Warn][Carousel]index must be an integer.');
  400. return;
  401. }
  402. var length = this.items.length;
  403. if (index < 0) {
  404. this.activeIndex = length - 1;
  405. } else if (index >= length) {
  406. this.activeIndex = 0;
  407. } else {
  408. this.activeIndex = index;
  409. }
  410. },
  411. prev: function prev() {
  412. this.setActiveItem(this.activeIndex - 1);
  413. },
  414. next: function next() {
  415. this.setActiveItem(this.activeIndex + 1);
  416. },
  417. handleIndicatorClick: function handleIndicatorClick(index) {
  418. this.activeIndex = index;
  419. },
  420. handleIndicatorHover: function handleIndicatorHover(index) {
  421. if (this.trigger === 'hover' && index !== this.activeIndex) {
  422. this.activeIndex = index;
  423. }
  424. }
  425. },
  426. created: function created() {
  427. var _this3 = this;
  428. this.throttledArrowClick = (0, _throttle2.default)(300, true, function (index) {
  429. _this3.setActiveItem(index);
  430. });
  431. this.throttledIndicatorHover = (0, _throttle2.default)(300, function (index) {
  432. _this3.handleIndicatorHover(index);
  433. });
  434. },
  435. mounted: function mounted() {
  436. var _this4 = this;
  437. this.updateItems();
  438. this.$nextTick(function () {
  439. (0, _resizeEvent.addResizeListener)(_this4.$el, _this4.resetItemPosition);
  440. if (_this4.initialIndex < _this4.items.length && _this4.initialIndex >= 0) {
  441. _this4.activeIndex = _this4.initialIndex;
  442. }
  443. _this4.startTimer();
  444. });
  445. },
  446. beforeDestroy: function beforeDestroy() {
  447. if (this.$el) (0, _resizeEvent.removeResizeListener)(this.$el, this.resetItemPosition);
  448. }
  449. };
  450. /***/ }),
  451. /***/ 391:
  452. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  453. "use strict";
  454. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"el-carousel",class:{ 'el-carousel--card': _vm.type === 'card' },on:{"mouseenter":function($event){$event.stopPropagation();_vm.handleMouseEnter($event)},"mouseleave":function($event){$event.stopPropagation();_vm.handleMouseLeave($event)}}},[_c('div',{staticClass:"el-carousel__container",style:({ height: _vm.height })},[_c('transition',{attrs:{"name":"carousel-arrow-left"}},[(_vm.arrow !== 'never')?_c('button',{directives:[{name:"show",rawName:"v-show",value:(_vm.arrow === 'always' || _vm.hover),expression:"arrow === 'always' || hover"}],staticClass:"el-carousel__arrow el-carousel__arrow--left",on:{"mouseenter":function($event){_vm.handleButtonEnter('left')},"mouseleave":_vm.handleButtonLeave,"click":function($event){$event.stopPropagation();_vm.throttledArrowClick(_vm.activeIndex - 1)}}},[_c('i',{staticClass:"el-icon-arrow-left"})]):_vm._e()]),_c('transition',{attrs:{"name":"carousel-arrow-right"}},[(_vm.arrow !== 'never')?_c('button',{directives:[{name:"show",rawName:"v-show",value:(_vm.arrow === 'always' || _vm.hover),expression:"arrow === 'always' || hover"}],staticClass:"el-carousel__arrow el-carousel__arrow--right",on:{"mouseenter":function($event){_vm.handleButtonEnter('right')},"mouseleave":_vm.handleButtonLeave,"click":function($event){$event.stopPropagation();_vm.throttledArrowClick(_vm.activeIndex + 1)}}},[_c('i',{staticClass:"el-icon-arrow-right"})]):_vm._e()]),_vm._t("default")],2),(_vm.indicatorPosition !== 'none')?_c('ul',{staticClass:"el-carousel__indicators",class:{ 'el-carousel__indicators--labels': _vm.hasLabel, 'el-carousel__indicators--outside': _vm.indicatorPosition === 'outside' || _vm.type === 'card' }},_vm._l((_vm.items),function(item,index){return _c('li',{staticClass:"el-carousel__indicator",class:{ 'is-active': index === _vm.activeIndex },on:{"mouseenter":function($event){_vm.throttledIndicatorHover(index)},"click":function($event){$event.stopPropagation();_vm.handleIndicatorClick(index)}}},[_c('button',{staticClass:"el-carousel__button"},[(_vm.hasLabel)?_c('span',[_vm._v(_vm._s(item.label))]):_vm._e()])])})):_vm._e()])}
  455. var staticRenderFns = []
  456. var esExports = { render: render, staticRenderFns: staticRenderFns }
  457. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  458. /***/ })
  459. /******/ });