From 57573dd1cfe87c148a9acabcd7211263dd755f95 Mon Sep 17 00:00:00 2001 From: Marcos Moura Date: Mon, 24 Oct 2016 19:43:55 -0200 Subject: [PATCH 1/5] Keep menu content inside viewport --- docs/src/pages/components/Menu.vue | 10 --- src/components/mdMenu/mdMenu.vue | 107 +++++++++++++++-------------- 2 files changed, 55 insertions(+), 62 deletions(-) diff --git a/docs/src/pages/components/Menu.vue b/docs/src/pages/components/Menu.vue index 20bdf9e..4cc4237 100644 --- a/docs/src/pages/components/Menu.vue +++ b/docs/src/pages/components/Menu.vue @@ -49,16 +49,6 @@ My Item 3 - - - Options - - - My Item 1 - My Item 2 - My Item 3 - - diff --git a/src/components/mdMenu/mdMenu.vue b/src/components/mdMenu/mdMenu.vue index 7025afa..7f09967 100644 --- a/src/components/mdMenu/mdMenu.vue +++ b/src/components/mdMenu/mdMenu.vue @@ -59,6 +59,57 @@ this.close(); } }, + isAboveOfViewport(pos) { + return pos.top <= this.margin; + }, + isBelowOfViewport(pos) { + return pos.top + this.menuContent.offsetHeight + this.margin >= window.innerHeight; + }, + isOnTheLeftOfViewport(pos) { + return pos.left <= this.margin; + }, + isOnTheRightOfViewport(pos) { + return pos.left + this.menuContent.offsetWidth + this.margin >= window.innerWidth; + }, + getInViewPosition(position) { + if (this.isAboveOfViewport(position)) { + position.top = this.margin; + position.origin = 'center top'; + + if (this.isOnTheLeftOfViewport(position)) { + position.origin = 'left top'; + } + + if (this.isOnTheRightOfViewport(position)) { + position.origin = 'right top'; + } + } + + if (this.isOnTheLeftOfViewport(position)) { + position.left = this.margin; + position.origin = 'left'; + } + + if (this.isOnTheRightOfViewport(position)) { + position.left = window.innerWidth - this.margin - this.menuContent.offsetWidth; + position.origin = 'right'; + } + + if (this.isBelowOfViewport(position)) { + position.top = window.innerHeight - this.margin - this.menuContent.offsetHeight; + position.origin = 'center bottom'; + + if (this.isOnTheLeftOfViewport(position)) { + position.origin = 'left bottom'; + } + + if (this.isOnTheRightOfViewport(position)) { + position.origin = 'right bottom'; + } + } + + return position; + }, getBottomRightPos() { let menuTriggerRect = this.menuTrigger.getBoundingClientRect(); let position = { @@ -67,19 +118,7 @@ origin: 'left top' }; - if (position.left <= this.margin) { - position.left = this.margin; - position.origin = 'center top'; - } - - if (position.top <= this.margin) { - position.top = this.margin; - position.origin = 'left center'; - } - - if (position.left <= this.margin && position.top <= this.margin) { - position.origin = 'center'; - } + this.getInViewPosition(position); return position; }, @@ -91,19 +130,7 @@ origin: 'right top' }; - if (position.left <= this.margin) { - position.left = this.margin; - position.origin = 'center top'; - } - - if (top <= this.margin) { - position.top = this.margin; - position.origin = 'right center'; - } - - if (position.left <= this.margin && top <= this.margin) { - position.origin = 'center'; - } + this.getInViewPosition(position); return position; }, @@ -115,19 +142,7 @@ origin: 'left bottom' }; - if (position.left <= this.margin) { - position.left = this.margin; - position.origin = 'center bottom'; - } - - if (top <= this.margin) { - top = this.margin; - position.origin = 'left center'; - } - - if (position.left <= this.margin && position.top <= this.margin) { - position.origin = 'center'; - } + this.getInViewPosition(position); return position; }, @@ -139,19 +154,7 @@ origin: 'right bottom' }; - if (position.left <= this.margin) { - position.left = this.margin; - position.origin = 'center bottom'; - } - - if (position.top <= this.margin) { - position.top = this.margin; - position.origin = 'right center'; - } - - if (position.left <= this.margin && position.top <= this.margin) { - position.origin = 'center'; - } + this.getInViewPosition(position); return position; }, From 208a47f11e30ba864681ed2afdeab04b5adbfba3 Mon Sep 17 00:00:00 2001 From: Marcos Moura Date: Mon, 24 Oct 2016 21:26:07 -0200 Subject: [PATCH 2/5] Drop transitionend dependency --- package.json | 1 - src/components/mdMenu/mdMenu.scss | 8 +++---- src/components/mdMenu/mdMenu.vue | 29 ++++++++++++++---------- src/core/utils/transitionEndEventName.js | 17 ++++++++++++++ 4 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 src/core/utils/transitionEndEventName.js diff --git a/package.json b/package.json index 7fb5159..9fa3f99 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "autosize": "^3.0.17", "element.scrollintoviewifneeded-polyfill": "^1.0.1", "scopedQuerySelectorShim": "github:lazd/scopedQuerySelectorShim", - "transitionEnd": "^1.0.2", "vue": "^2.0.2" }, "devDependencies": { diff --git a/src/components/mdMenu/mdMenu.scss b/src/components/mdMenu/mdMenu.scss index 83cc92b..bad5934 100644 --- a/src/components/mdMenu/mdMenu.scss +++ b/src/components/mdMenu/mdMenu.scss @@ -30,8 +30,8 @@ $menu-base-width: 56px; opacity: 0; transform: scale3D(.85, .85, 1); transition: width $swift-ease-out-duration $swift-ease-out-timing-function, - opacity .2s $swift-ease-in-timing-function, - transform .15s .1s $swift-ease-in-timing-function; + opacity .25s $swift-ease-in-timing-function, + transform .1s .12s $swift-ease-in-timing-function; color: rgba(#212121, .87); &.md-active { @@ -40,8 +40,8 @@ $menu-base-width: 56px; transform: scale3D(1, 1, 1); transform-origin: center; transition: width $swift-ease-out-duration $swift-ease-out-timing-function, - opacity .2s $swift-ease-out-timing-function, - transform .15s .1s $swift-ease-out-timing-function; + opacity .3s $swift-ease-out-timing-function, + transform .2s .073s $swift-ease-out-timing-function; > * { opacity: 1; diff --git a/src/components/mdMenu/mdMenu.vue b/src/components/mdMenu/mdMenu.vue index 7f09967..fb21951 100644 --- a/src/components/mdMenu/mdMenu.vue +++ b/src/components/mdMenu/mdMenu.vue @@ -7,9 +7,7 @@ diff --git a/src/components/mdMenu/mdMenuItem.vue b/src/components/mdMenu/mdMenuItem.vue index 48cef02..754f3fe 100644 --- a/src/components/mdMenu/mdMenuItem.vue +++ b/src/components/mdMenu/mdMenuItem.vue @@ -1,5 +1,5 @@