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.

VNavigationDrawer.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; // Styles
  6. // Mixins
  7. // Directives
  8. // Utilities
  9. require('../../../src/stylus/components/_navigation-drawer.styl');
  10. var _applicationable = require('../../mixins/applicationable');
  11. var _applicationable2 = _interopRequireDefault(_applicationable);
  12. var _dependent = require('../../mixins/dependent');
  13. var _dependent2 = _interopRequireDefault(_dependent);
  14. var _overlayable = require('../../mixins/overlayable');
  15. var _overlayable2 = _interopRequireDefault(_overlayable);
  16. var _ssrBootable = require('../../mixins/ssr-bootable');
  17. var _ssrBootable2 = _interopRequireDefault(_ssrBootable);
  18. var _themeable = require('../../mixins/themeable');
  19. var _themeable2 = _interopRequireDefault(_themeable);
  20. var _clickOutside = require('../../directives/click-outside');
  21. var _clickOutside2 = _interopRequireDefault(_clickOutside);
  22. var _resize = require('../../directives/resize');
  23. var _resize2 = _interopRequireDefault(_resize);
  24. var _touch = require('../../directives/touch');
  25. var _touch2 = _interopRequireDefault(_touch);
  26. var _helpers = require('../../util/helpers');
  27. var _mixins = require('../../util/mixins');
  28. var _mixins2 = _interopRequireDefault(_mixins);
  29. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  30. exports.default = (0, _mixins2.default)((0, _applicationable2.default)('left', ['miniVariant', 'right', 'width']), _dependent2.default, _overlayable2.default, _ssrBootable2.default, _themeable2.default
  31. /* @vue/component */
  32. ).extend({
  33. name: 'v-navigation-drawer',
  34. directives: {
  35. ClickOutside: _clickOutside2.default,
  36. Resize: _resize2.default,
  37. Touch: _touch2.default
  38. },
  39. props: {
  40. clipped: Boolean,
  41. disableRouteWatcher: Boolean,
  42. disableResizeWatcher: Boolean,
  43. height: {
  44. type: [Number, String],
  45. default: '100%'
  46. },
  47. floating: Boolean,
  48. miniVariant: Boolean,
  49. miniVariantWidth: {
  50. type: [Number, String],
  51. default: 80
  52. },
  53. mobileBreakPoint: {
  54. type: [Number, String],
  55. default: 1264
  56. },
  57. permanent: Boolean,
  58. right: Boolean,
  59. stateless: Boolean,
  60. temporary: Boolean,
  61. touchless: Boolean,
  62. width: {
  63. type: [Number, String],
  64. default: 300
  65. },
  66. value: { required: false }
  67. },
  68. data: function data() {
  69. return {
  70. isActive: false,
  71. touchArea: {
  72. left: 0,
  73. right: 0
  74. }
  75. };
  76. },
  77. computed: {
  78. /**
  79. * Used for setting an app value from a dynamic
  80. * property. Called from applicationable.js
  81. */
  82. applicationProperty: function applicationProperty() {
  83. return this.right ? 'right' : 'left';
  84. },
  85. calculatedTransform: function calculatedTransform() {
  86. if (this.isActive) return 0;
  87. return this.right ? this.calculatedWidth : -this.calculatedWidth;
  88. },
  89. calculatedWidth: function calculatedWidth() {
  90. return parseInt(this.miniVariant ? this.miniVariantWidth : this.width);
  91. },
  92. classes: function classes() {
  93. return _extends({
  94. 'v-navigation-drawer': true,
  95. 'v-navigation-drawer--absolute': this.absolute,
  96. 'v-navigation-drawer--clipped': this.clipped,
  97. 'v-navigation-drawer--close': !this.isActive,
  98. 'v-navigation-drawer--fixed': !this.absolute && (this.app || this.fixed),
  99. 'v-navigation-drawer--floating': this.floating,
  100. 'v-navigation-drawer--is-mobile': this.isMobile,
  101. 'v-navigation-drawer--mini-variant': this.miniVariant,
  102. 'v-navigation-drawer--open': this.isActive,
  103. 'v-navigation-drawer--right': this.right,
  104. 'v-navigation-drawer--temporary': this.temporary
  105. }, this.themeClasses);
  106. },
  107. hasApp: function hasApp() {
  108. return this.app && !this.isMobile && !this.temporary;
  109. },
  110. isMobile: function isMobile() {
  111. return !this.stateless && !this.permanent && !this.temporary && this.$vuetify.breakpoint.width < parseInt(this.mobileBreakPoint, 10);
  112. },
  113. marginTop: function marginTop() {
  114. if (!this.hasApp) return 0;
  115. var marginTop = this.$vuetify.application.bar;
  116. marginTop += this.clipped ? this.$vuetify.application.top : 0;
  117. return marginTop;
  118. },
  119. maxHeight: function maxHeight() {
  120. if (!this.hasApp) return null;
  121. var maxHeight = this.$vuetify.application.bottom + this.$vuetify.application.footer + this.$vuetify.application.bar;
  122. if (!this.clipped) return maxHeight;
  123. return maxHeight + this.$vuetify.application.top;
  124. },
  125. reactsToClick: function reactsToClick() {
  126. return !this.stateless && !this.permanent && (this.isMobile || this.temporary);
  127. },
  128. reactsToMobile: function reactsToMobile() {
  129. return !this.disableResizeWatcher && !this.stateless && !this.permanent && !this.temporary;
  130. },
  131. reactsToRoute: function reactsToRoute() {
  132. return !this.disableRouteWatcher && !this.stateless && (this.temporary || this.isMobile);
  133. },
  134. resizeIsDisabled: function resizeIsDisabled() {
  135. return this.disableResizeWatcher || this.stateless;
  136. },
  137. showOverlay: function showOverlay() {
  138. return this.isActive && (this.isMobile || this.temporary);
  139. },
  140. styles: function styles() {
  141. var styles = {
  142. height: (0, _helpers.convertToUnit)(this.height),
  143. marginTop: this.marginTop + 'px',
  144. maxHeight: this.maxHeight != null ? 'calc(100% - ' + +this.maxHeight + 'px)' : undefined,
  145. transform: 'translateX(' + this.calculatedTransform + 'px)',
  146. width: this.calculatedWidth + 'px'
  147. };
  148. return styles;
  149. }
  150. },
  151. watch: {
  152. $route: function $route() {
  153. if (this.reactsToRoute && this.closeConditional()) {
  154. this.isActive = false;
  155. }
  156. },
  157. isActive: function isActive(val) {
  158. this.$emit('input', val);
  159. this.callUpdate();
  160. },
  161. /**
  162. * When mobile changes, adjust the active state
  163. * only when there has been a previous value
  164. */
  165. isMobile: function isMobile(val, prev) {
  166. !val && this.isActive && !this.temporary && this.removeOverlay();
  167. if (prev == null || this.resizeIsDisabled || !this.reactsToMobile) return;
  168. this.isActive = !val;
  169. this.callUpdate();
  170. },
  171. permanent: function permanent(val) {
  172. // If enabling prop enable the drawer
  173. if (val) {
  174. this.isActive = true;
  175. }
  176. this.callUpdate();
  177. },
  178. showOverlay: function showOverlay(val) {
  179. if (val) this.genOverlay();else this.removeOverlay();
  180. },
  181. temporary: function temporary() {
  182. this.callUpdate();
  183. },
  184. value: function value(val) {
  185. if (this.permanent) return;
  186. // TODO: referring to this directly causes type errors
  187. // all over the place for some reason
  188. var _this = this;
  189. if (val == null) return _this.init();
  190. if (val !== this.isActive) this.isActive = val;
  191. }
  192. },
  193. beforeMount: function beforeMount() {
  194. this.init();
  195. },
  196. methods: {
  197. calculateTouchArea: function calculateTouchArea() {
  198. if (!this.$el.parentNode) return;
  199. var parentRect = this.$el.parentNode.getBoundingClientRect();
  200. this.touchArea = {
  201. left: parentRect.left + 50,
  202. right: parentRect.right - 50
  203. };
  204. },
  205. closeConditional: function closeConditional() {
  206. return this.isActive && this.reactsToClick;
  207. },
  208. genDirectives: function genDirectives() {
  209. var _this2 = this;
  210. var directives = [{
  211. name: 'click-outside',
  212. value: function value() {
  213. return _this2.isActive = false;
  214. },
  215. args: {
  216. closeConditional: this.closeConditional,
  217. include: this.getOpenDependentElements
  218. }
  219. }];
  220. !this.touchless && directives.push({
  221. name: 'touch',
  222. value: {
  223. parent: true,
  224. left: this.swipeLeft,
  225. right: this.swipeRight
  226. }
  227. });
  228. return directives;
  229. },
  230. /**
  231. * Sets state before mount to avoid
  232. * entry transitions in SSR
  233. */
  234. init: function init() {
  235. if (this.permanent) {
  236. this.isActive = true;
  237. } else if (this.stateless || this.value != null) {
  238. this.isActive = this.value;
  239. } else if (!this.temporary) {
  240. this.isActive = !this.isMobile;
  241. }
  242. },
  243. swipeRight: function swipeRight(e) {
  244. if (this.isActive && !this.right) return;
  245. this.calculateTouchArea();
  246. if (Math.abs(e.touchendX - e.touchstartX) < 100) return;
  247. if (!this.right && e.touchstartX <= this.touchArea.left) this.isActive = true;else if (this.right && this.isActive) this.isActive = false;
  248. },
  249. swipeLeft: function swipeLeft(e) {
  250. if (this.isActive && this.right) return;
  251. this.calculateTouchArea();
  252. if (Math.abs(e.touchendX - e.touchstartX) < 100) return;
  253. if (this.right && e.touchstartX >= this.touchArea.right) this.isActive = true;else if (!this.right && this.isActive) this.isActive = false;
  254. },
  255. /**
  256. * Update the application layout
  257. */
  258. updateApplication: function updateApplication() {
  259. return !this.isActive || this.temporary || this.isMobile ? 0 : this.calculatedWidth;
  260. }
  261. },
  262. render: function render(h) {
  263. var _this3 = this;
  264. var data = {
  265. 'class': this.classes,
  266. style: this.styles,
  267. directives: this.genDirectives(),
  268. on: {
  269. click: function click() {
  270. if (!_this3.miniVariant) return;
  271. _this3.$emit('update:miniVariant', false);
  272. },
  273. transitionend: function transitionend(e) {
  274. if (e.target !== e.currentTarget) return;
  275. _this3.$emit('transitionend', e);
  276. // IE11 does not support new Event('resize')
  277. var resizeEvent = document.createEvent('UIEvents');
  278. resizeEvent.initUIEvent('resize', true, false, window, 0);
  279. window.dispatchEvent(resizeEvent);
  280. }
  281. }
  282. };
  283. return h('aside', data, [this.$slots.default, h('div', { 'class': 'v-navigation-drawer__border' })]);
  284. }
  285. });
  286. //# sourceMappingURL=VNavigationDrawer.js.map