Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VCarousel.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // Styles
  2. import '../../../src/stylus/components/_carousel.styl';
  3. // Extensions
  4. import VWindow from '../VWindow/VWindow';
  5. // Components
  6. import VBtn from '../VBtn';
  7. import VIcon from '../VIcon';
  8. // Mixins
  9. // TODO: Move this into core components v2.0
  10. import ButtonGroup from '../../mixins/button-group';
  11. // Utilities
  12. import { convertToUnit } from '../../util/helpers';
  13. import { deprecate } from '../../util/console';
  14. export default VWindow.extend({
  15. name: 'v-carousel',
  16. props: {
  17. cycle: {
  18. type: Boolean,
  19. default: true
  20. },
  21. delimiterIcon: {
  22. type: String,
  23. default: '$vuetify.icons.delimiter'
  24. },
  25. height: {
  26. type: [Number, String],
  27. default: 500
  28. },
  29. hideControls: Boolean,
  30. hideDelimiters: Boolean,
  31. interval: {
  32. type: [Number, String],
  33. default: 6000,
  34. validator: function validator(value) {
  35. return value > 0;
  36. }
  37. },
  38. mandatory: {
  39. type: Boolean,
  40. default: true
  41. },
  42. nextIcon: {
  43. type: [Boolean, String],
  44. default: '$vuetify.icons.next'
  45. },
  46. prevIcon: {
  47. type: [Boolean, String],
  48. default: '$vuetify.icons.prev'
  49. }
  50. },
  51. data: function data() {
  52. return {
  53. changedByDelimiters: false,
  54. internalHeight: this.height,
  55. slideTimeout: undefined
  56. };
  57. },
  58. computed: {
  59. isDark: function isDark() {
  60. return this.dark || !this.light;
  61. }
  62. },
  63. watch: {
  64. internalValue: function internalValue(val) {
  65. this.restartTimeout();
  66. /* @deprecate */
  67. /* istanbul ignore else */
  68. if (!this.$listeners['input']) return;
  69. this.$emit('input', val);
  70. },
  71. interval: 'restartTimeout',
  72. height: function height(val, oldVal) {
  73. if (val === oldVal || !val) return;
  74. this.internalHeight = val;
  75. },
  76. cycle: function cycle(val) {
  77. if (val) {
  78. this.restartTimeout();
  79. } else {
  80. clearTimeout(this.slideTimeout);
  81. this.slideTimeout = undefined;
  82. }
  83. }
  84. },
  85. mounted: function mounted() {
  86. /* @deprecate */
  87. /* istanbul ignore next */
  88. if (this.$listeners['input']) {
  89. deprecate('@input', '@change', this);
  90. }
  91. this.startTimeout();
  92. },
  93. methods: {
  94. genDelimiters: function genDelimiters() {
  95. return this.$createElement('div', {
  96. staticClass: 'v-carousel__controls'
  97. }, [this.genItems()]);
  98. },
  99. genIcon: function genIcon(direction, icon, fn) {
  100. var _this = this;
  101. return this.$createElement('div', {
  102. staticClass: 'v-carousel__' + direction
  103. }, [this.$createElement(VBtn, {
  104. props: {
  105. icon: true
  106. },
  107. attrs: {
  108. 'aria-label': this.$vuetify.t('$vuetify.carousel.' + direction)
  109. },
  110. on: {
  111. click: function click() {
  112. _this.changedByDelimiters = true;
  113. fn();
  114. }
  115. }
  116. }, [this.$createElement(VIcon, {
  117. props: { 'size': '46px' }
  118. }, icon)])]);
  119. },
  120. genIcons: function genIcons() {
  121. var icons = [];
  122. var prevIcon = this.$vuetify.rtl ? this.nextIcon : this.prevIcon;
  123. if (prevIcon && typeof prevIcon === 'string') {
  124. icons.push(this.genIcon('prev', prevIcon, this.prev));
  125. }
  126. var nextIcon = this.$vuetify.rtl ? this.prevIcon : this.nextIcon;
  127. if (nextIcon && typeof nextIcon === 'string') {
  128. icons.push(this.genIcon('next', nextIcon, this.next));
  129. }
  130. return icons;
  131. },
  132. genItems: function genItems() {
  133. var _this2 = this;
  134. var length = this.items.length;
  135. var children = [];
  136. for (var i = 0; i < length; i++) {
  137. var child = this.$createElement(VBtn, {
  138. class: {
  139. 'v-carousel__controls__item': true
  140. },
  141. props: {
  142. icon: true,
  143. small: true,
  144. value: this.getValue(this.items[i], i)
  145. }
  146. }, [this.$createElement(VIcon, {
  147. props: { size: 18 }
  148. }, this.delimiterIcon)]);
  149. children.push(child);
  150. }
  151. return this.$createElement(ButtonGroup, {
  152. props: {
  153. value: this.internalValue
  154. },
  155. on: {
  156. change: function change(val) {
  157. _this2.internalValue = val;
  158. }
  159. }
  160. }, children);
  161. },
  162. restartTimeout: function restartTimeout() {
  163. this.slideTimeout && clearTimeout(this.slideTimeout);
  164. this.slideTimeout = undefined;
  165. var raf = requestAnimationFrame || setTimeout;
  166. raf(this.startTimeout);
  167. },
  168. startTimeout: function startTimeout() {
  169. if (!this.cycle) return;
  170. this.slideTimeout = window.setTimeout(this.next, +this.interval > 0 ? +this.interval : 6000);
  171. },
  172. updateReverse: function updateReverse(val, oldVal) {
  173. if (this.changedByDelimiters) {
  174. this.changedByDelimiters = false;
  175. return;
  176. }
  177. VWindow.options.methods.updateReverse.call(this, val, oldVal);
  178. }
  179. },
  180. render: function render(h) {
  181. var children = [];
  182. var data = {
  183. staticClass: 'v-window v-carousel',
  184. style: {
  185. height: convertToUnit(this.height)
  186. },
  187. directives: []
  188. };
  189. if (!this.touchless) {
  190. data.directives.push({
  191. name: 'touch',
  192. value: {
  193. left: this.next,
  194. right: this.prev
  195. }
  196. });
  197. }
  198. if (!this.hideControls) {
  199. children.push(this.genIcons());
  200. }
  201. if (!this.hideDelimiters) {
  202. children.push(this.genDelimiters());
  203. }
  204. return h('div', data, [this.genContainer(), children]);
  205. }
  206. });
  207. //# sourceMappingURL=VCarousel.js.map