mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
5e27d6a7a2
to be added. Create inspector elements in the propper document scope. Restore inspector css classnames to camel case for proof that inspectors are being created in the correct document scope. Previously, inspector elements created in the wrong document scope would have css rules applied only if class names were lowercase. Issue only surfaced in Webkit browsers. Though, this implementation is more future proof and will help prevent future inspector bugs. Patch 3) Fixed global variable definition and mistake with inspectorDoc Change-Id: I36c0d078aea10d919689768878004a19f7f89b55
88 lines
1.9 KiB
JavaScript
88 lines
1.9 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
|
|
* @param {ve.ui.Toolbar} toolbar
|
|
* @param {String} name
|
|
*/
|
|
ve.ui.Inspector = function( toolbar, context ) {
|
|
// Inheritance
|
|
ve.EventEmitter.call( this );
|
|
if ( !toolbar || !context ) {
|
|
return;
|
|
}
|
|
|
|
// Properties
|
|
this.toolbar = toolbar;
|
|
this.context = context;
|
|
|
|
this.$ = $( '<div class="es-inspector"></div>', context.inspectorDoc );
|
|
//
|
|
this.$closeButton = $( '<div class="es-inspector-button es-inspector-closeButton"></div>', context.inspectorDoc )
|
|
.appendTo( this.$ );
|
|
this.$acceptButton = $( '<div class="es-inspector-button es-inspector-acceptButton"></div>', context.inspectorDoc )
|
|
.appendTo( this.$ );
|
|
this.$form = $( '<form></form>', context.inspectorDoc ).appendTo( this.$ );
|
|
|
|
// Events
|
|
var _this = this;
|
|
this.$closeButton.click( function() {
|
|
_this.context.closeInspector( false );
|
|
} );
|
|
this.$acceptButton.click( function() {
|
|
if ( !$(this).is( '.es-inspector-button-disabled' ) ) {
|
|
_this.context.closeInspector( true );
|
|
}
|
|
} );
|
|
this.$form.submit( function( e ) {
|
|
_this.context.closeInspector( true );
|
|
e.preventDefault();
|
|
return false;
|
|
} );
|
|
this.$form.keydown( function( e ) {
|
|
// Escape
|
|
if ( e.which === 27 ) {
|
|
_this.context.closeInspector( false );
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
} );
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
ve.ui.Inspector.prototype.open = function() {
|
|
// Prepare to open
|
|
if ( this.prepareOpen ) {
|
|
this.prepareOpen();
|
|
}
|
|
// Show
|
|
this.$.show();
|
|
this.context.closeMenu();
|
|
// 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' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.extendClass( ve.ui.Inspector, ve.EventEmitter );
|