2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor user interface Inspector class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2011-12-09 01:28:44 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.ui.Inspector object.
|
2012-06-20 01:20:28 +00:00
|
|
|
*
|
2011-12-09 01:28:44 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-02-06 23:50:56 +00:00
|
|
|
* @param {ve.ui.Toolbar} toolbar
|
2011-12-09 01:28:44 +00:00
|
|
|
* @param {String} name
|
|
|
|
*/
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.Inspector = function( toolbar, context ) {
|
2011-12-09 01:28:44 +00:00
|
|
|
// Inheritance
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.EventEmitter.call( this );
|
2011-12-09 01:28:44 +00:00
|
|
|
if ( !toolbar || !context ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.toolbar = toolbar;
|
|
|
|
this.context = context;
|
|
|
|
this.$ = $( '<div class="es-inspector"></div>' );
|
2012-06-20 01:20:28 +00:00
|
|
|
//
|
2012-07-06 21:50:19 +00:00
|
|
|
this.$closeButton = $( '<div class="es-inspector-button es-inspector-close-button"></div>' )
|
2011-12-09 23:04:55 +00:00
|
|
|
.appendTo( this.$ );
|
2012-07-06 21:50:19 +00:00
|
|
|
this.$acceptButton = $( '<div class="es-inspector-button es-inspector-accept-button"></div>' )
|
2011-12-09 23:04:55 +00:00
|
|
|
.appendTo( this.$ );
|
2011-12-09 19:01:05 +00:00
|
|
|
this.$form = $( '<form></form>' ).appendTo( this.$ );
|
2011-12-09 01:28:44 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
var _this = this;
|
|
|
|
this.$closeButton.click( function() {
|
2011-12-09 23:04:55 +00:00
|
|
|
_this.context.closeInspector( false );
|
|
|
|
} );
|
|
|
|
this.$acceptButton.click( function() {
|
2011-12-09 23:11:49 +00:00
|
|
|
if ( !$(this).is( '.es-inspector-button-disabled' ) ) {
|
|
|
|
_this.context.closeInspector( true );
|
|
|
|
}
|
2011-12-09 01:28:44 +00:00
|
|
|
} );
|
2011-12-09 19:01:05 +00:00
|
|
|
this.$form.submit( function( e ) {
|
2011-12-09 23:04:55 +00:00
|
|
|
_this.context.closeInspector( true );
|
2011-12-09 19:01:05 +00:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
} );
|
2011-12-09 23:13:46 +00:00
|
|
|
this.$form.keydown( function( e ) {
|
|
|
|
// Escape
|
|
|
|
if ( e.which === 27 ) {
|
|
|
|
_this.context.closeInspector( false );
|
2011-12-09 23:15:27 +00:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
2011-12-09 23:13:46 +00:00
|
|
|
}
|
|
|
|
} );
|
2011-12-09 01:28:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.Inspector.prototype.open = function() {
|
2011-12-09 01:28:44 +00:00
|
|
|
this.$.show();
|
|
|
|
this.context.closeMenu();
|
|
|
|
if ( this.onOpen ) {
|
|
|
|
this.onOpen();
|
|
|
|
}
|
|
|
|
this.emit( 'open' );
|
|
|
|
};
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.Inspector.prototype.close = function( accept ) {
|
2011-12-09 01:28:44 +00:00
|
|
|
this.$.hide();
|
|
|
|
if ( this.onClose ) {
|
2011-12-09 23:04:55 +00:00
|
|
|
this.onClose( accept );
|
2011-12-09 01:28:44 +00:00
|
|
|
}
|
|
|
|
this.emit( 'close' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.extendClass( ve.ui.Inspector, ve.EventEmitter );
|