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;
|
2012-07-17 18:53:42 +00:00
|
|
|
|
|
|
|
this.$ = $( '<div class="es-inspector"></div>', context.inspectorDoc );
|
2012-06-20 01:20:28 +00:00
|
|
|
//
|
2012-07-17 18:53:42 +00:00
|
|
|
this.$closeButton = $( '<div class="es-inspector-button es-inspector-closeButton"></div>', context.inspectorDoc )
|
2011-12-09 23:04:55 +00:00
|
|
|
.appendTo( this.$ );
|
2012-07-17 18:53:42 +00:00
|
|
|
this.$acceptButton = $( '<div class="es-inspector-button es-inspector-acceptButton"></div>', context.inspectorDoc )
|
2011-12-09 23:04:55 +00:00
|
|
|
.appendTo( this.$ );
|
2012-07-17 18:53:42 +00:00
|
|
|
this.$form = $( '<form></form>', context.inspectorDoc ).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() {
|
2012-07-03 20:28:10 +00:00
|
|
|
// Prepare to open
|
|
|
|
if ( this.prepareOpen ) {
|
|
|
|
this.prepareOpen();
|
|
|
|
}
|
|
|
|
// Show
|
2011-12-09 01:28:44 +00:00
|
|
|
this.$.show();
|
|
|
|
this.context.closeMenu();
|
2012-07-03 20:28:10 +00:00
|
|
|
// Open
|
2011-12-09 01:28:44 +00:00
|
|
|
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 );
|