Automatically bind and unbind context's window event bindings on documentNode focus and blur

Change-Id: Ie43165da49a36a7d0d13a52318d9c5438dad9605
This commit is contained in:
Trevor Parscal 2012-06-20 12:20:22 -07:00 committed by Catrope
parent 7a1d74fd18
commit bcf93eb695
2 changed files with 16 additions and 1 deletions

View file

@ -892,6 +892,10 @@ ve.ce.Surface.prototype.getModel = function() {
return this.model;
};
ve.ce.Surface.prototype.getDocument = function() {
return this.documentView;
};
/* Inheritance */
ve.extendClass( ve.ce.Surface, ve.EventEmitter );

View file

@ -45,7 +45,10 @@ ve.ui.Context = function( surfaceView, $overlay ) {
'mousedown': ve.proxy( this.onMouseDown, this ),
'mouseup': ve.proxy( this.onMouseUp, this )
} );
$( window ).bind( 'resize scroll', ve.proxy( this.set, this ) );
this.surfaceView.getDocument().getDocumentNode().$.on( {
'focus': ve.proxy( this.onDocumentFocus, this ),
'blur': ve.proxy( this.onDocumentBlur, this )
} );
// Intitialization
this.addInspector( 'link', new ve.ui.LinkInspector( this.toolbarView, this ) );
@ -53,6 +56,14 @@ ve.ui.Context = function( surfaceView, $overlay ) {
/* Methods */
ve.ui.Context.prototype.onDocumentFocus = function( event ) {
$( window ).bind( 'resize.ve-ui-context scroll.ve-ui-context', ve.proxy( this.set, this ) );
};
ve.ui.Context.prototype.onDocumentBlur = function( event ) {
$( window ).unbind( 'resize.ve-ui-context scroll.ve-ui-context' );
};
ve.ui.Context.prototype.onMouseDown = function( event ) {
this.clicking = true;
event.preventDefault();