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
This commit is contained in:
Trevor Parscal 2012-06-19 15:26:37 -07:00
parent 89df02cdb6
commit c39577a06c
2 changed files with 32 additions and 23 deletions

View file

@ -47,7 +47,7 @@
}
.es-contextView-position-above .es-menuView {
bottom: -4px;
bottom: 2px;
}
.es-contextView-position-below .es-menuView {

View file

@ -16,6 +16,7 @@ ve.ui.Context = function( surfaceView, $overlay ) {
this.inspectors = {};
this.inspector = null;
this.position = null;
this.clicking = false;
this.$ = $( '<div class="es-contextView"></div>' ).appendTo( $overlay || $( 'body' ) );
this.$toolbar = $( '<div class="es-contextView-toolbar"></div>' );
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' );