From c39577a06c7e71759034f96a08da5c161e7ad49c Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Tue, 19 Jun 2012 15:26:37 -0700 Subject: [PATCH] Made context menu not open after selection ends over top of it Also fixed some of the positioning to stay correct while scrolling and resizing a window Change-Id: I40d57b4fb035aea0b43b998251a93a83a46b9735 --- modules/ve2/ui/styles/ve.ui.Context.css | 2 +- modules/ve2/ui/ve.ui.Context.js | 53 +++++++++++++++---------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/modules/ve2/ui/styles/ve.ui.Context.css b/modules/ve2/ui/styles/ve.ui.Context.css index 7fbfdd0b68..31ec62b44e 100644 --- a/modules/ve2/ui/styles/ve.ui.Context.css +++ b/modules/ve2/ui/styles/ve.ui.Context.css @@ -47,7 +47,7 @@ } .es-contextView-position-above .es-menuView { - bottom: -4px; + bottom: 2px; } .es-contextView-position-below .es-menuView { diff --git a/modules/ve2/ui/ve.ui.Context.js b/modules/ve2/ui/ve.ui.Context.js index 657696b499..90d5cb3ddc 100644 --- a/modules/ve2/ui/ve.ui.Context.js +++ b/modules/ve2/ui/ve.ui.Context.js @@ -16,6 +16,7 @@ ve.ui.Context = function( surfaceView, $overlay ) { this.inspectors = {}; this.inspector = null; this.position = null; + this.clicking = false; this.$ = $( '
' ).appendTo( $overlay || $( 'body' ) ); this.$toolbar = $( '
' ); this.$inspectors = @@ -40,28 +41,11 @@ ve.ui.Context = function( surfaceView, $overlay ) { ); // Events - var _this = this; this.$icon.bind( { - 'mousedown': function( e ) { - if ( e.which === 1 ) { - e.preventDefault(); - return false; - } - }, - 'mouseup': function( e ) { - if ( e.which === 1 ) { - if ( _this.inspector ) { - _this.closeInspector(); - } else { - if ( _this.isMenuOpen() ) { - _this.closeMenu(); - } else { - _this.openMenu(); - } - } - } - } + 'mousedown': ve.proxy( this.onMouseDown, this ), + 'mouseup': ve.proxy( this.onMouseUp, this ) } ); + $( window ).bind( 'resize scroll', ve.proxy( this.set, this ) ); // Intitialization this.addInspector( 'link', new ve.ui.LinkInspector( this.toolbarView, this ) ); @@ -69,6 +53,27 @@ ve.ui.Context = function( surfaceView, $overlay ) { /* Methods */ +ve.ui.Context.prototype.onMouseDown = function( event ) { + this.clicking = true; + event.preventDefault(); + return false; +}; + +ve.ui.Context.prototype.onMouseUp = function( event ) { + if ( this.clicking && event.which === 1 ) { + if ( this.inspector ) { + this.closeInspector(); + } else { + if ( this.isMenuOpen() ) { + this.closeMenu(); + } else { + this.openMenu(); + } + } + } + this.clicking = false; +}; + ve.ui.Context.prototype.getSurfaceView = function() { return this.surfaceView; }; @@ -121,7 +126,8 @@ ve.ui.Context.prototype.positionOverlay = function( $overlay ) { $window = $( window ), windowWidth = $window.width(), windowHeight = $window.height(), - windowScrollTop = $window.scrollTop(); + windowScrollTop = $window.scrollTop(), + selection = this.surfaceView.model.getSelection(); // Center align overlay var overlayLeft = -Math.round( overlayWidth / 2 ); @@ -138,7 +144,10 @@ ve.ui.Context.prototype.positionOverlay = function( $overlay ) { $overlay.css( 'left', overlayLeft ); // Position overlay on top or bottom depending on viewport - if ( this.position.top + overlayHeight + ( overlayMargin * 2 ) < windowHeight + windowScrollTop ) { + if ( + selection.from < selection.to && + this.position.top + overlayHeight + ( overlayMargin * 2 ) < windowHeight + windowScrollTop + ) { this.$.addClass( 'es-contextView-position-below' ); } else { this.$.addClass( 'es-contextView-position-above' );