mediawiki-extensions-Visual.../modules/ve/ui/ve.ui.Inspector.js
Rob Moen 9563f0880d UI context reorganization, inspector rewrite, iframe refactor, icon generalization
* Only show the inspector if the selected text has an inspectable annotation
* Replace the inline menu with a toolbar containing inspectable annotations
* Change the appearance of the inspector to match new mockups
* Add the trash can icon for removing annotations
* Move iframe handling code into a class that manages all that nonsense

Change-Id: I840f72426f9a9e50054a28de950393f0e9913153
2012-10-26 14:46:11 -07:00

100 lines
2 KiB
JavaScript

/**
* VisualEditor user interface Inspector class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.Inspector object.
*
* @class
* @constructor
* @extends {ve.EventEmitter}
* @param {ve.ui.Context} context
*/
ve.ui.Inspector = function VeUiInspector( context ) {
// Inheritance
ve.EventEmitter.call( this );
if ( !context ) {
return;
}
// Properties
this.context = context;
this.$ = $( '<div class="ve-ui-inspector"></div>', context.frameView.doc );
this.$closeButton = $(
'<div class="ve-ui-inspector-button ve-ui-inspector-closeButton ve-ui-icon-close"></div>',
context.frameView.doc
);
this.$form = $( '<form>', context.frameView.doc );
// DOM Changes
this.$.append(
this.$closeButton,
$( '<div class="ve-ui-inspector-icon ve-ui-icon-' + this.constructor.static.icon + '"></div>' ),
this.$form
);
// Events
this.$closeButton.on( {
'click': function () {
// Close inspector with save.
context.closeInspector( true );
}
} );
this.$form.on( {
'submit': ve.bind( this.onSubmit, this ),
'keydown': ve.bind( this.onKeyDown, this )
} );
};
/* Inheritance */
ve.inheritClass( ve.ui.Inspector, ve.EventEmitter );
ve.ui.Inspector.static.icon = 'button';
/* Methods */
ve.ui.Inspector.prototype.onSubmit = function ( e ) {
e.preventDefault();
if ( this.$.hasClass( 've-ui-inspector-disabled' ) ) {
return;
}
this.context.closeInspector( true );
return false;
};
ve.ui.Inspector.prototype.onKeyDown = function ( e ) {
// Escape
if ( e.which === 27 ) {
this.context.closeInspector( false );
e.preventDefault();
return false;
}
};
ve.ui.Inspector.prototype.open = function () {
// Prepare to open
if ( this.prepareOpen ) {
this.prepareOpen();
}
// Show
this.$.show();
// Open
if ( this.onOpen ) {
this.onOpen();
}
this.emit( 'open' );
};
ve.ui.Inspector.prototype.close = function ( accept ) {
this.$.hide();
if ( this.onClose ) {
this.onClose( accept );
}
this.emit( 'close' );
};