mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-30 00:55:00 +00:00
d208ca9002
* Separated DOM changes from creation of elements * Always using parsing for element creation with known attributes * Always using attr or addClass for variable attributes Change-Id: Id101f56594014786892d382d06c658f416224a9c
102 lines
2.1 KiB
JavaScript
102 lines
2.1 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 ) {
|
|
var inspector = this;
|
|
|
|
// Inheritance
|
|
ve.EventEmitter.call( this );
|
|
if ( !toolbar || !context ) {
|
|
return;
|
|
}
|
|
|
|
// Properties
|
|
this.toolbar = toolbar;
|
|
this.context = context;
|
|
this.$ = $( '<div class="ve-ui-inspector"></div>', context.inspectorDoc );
|
|
this.$closeButton = $(
|
|
'<div class="ve-ui-inspector-button ve-ui-inspector-closeButton"></div>',
|
|
context.inspectorDoc
|
|
);
|
|
this.$acceptButton = $(
|
|
'<div class="ve-ui-inspector-button ve-ui-inspector-acceptButton"></div>',
|
|
context.inspectorDoc
|
|
);
|
|
this.$form = $( '<form>', context.inspectorDoc );
|
|
|
|
// DOM Changes
|
|
this.$.append( this.$closeButton, this.$acceptButton, this.$form );
|
|
|
|
// Events
|
|
this.$closeButton.on( {
|
|
'click': function() {
|
|
context.closeInspector( false );
|
|
}
|
|
} );
|
|
this.$acceptButton.on( {
|
|
'click': function() {
|
|
context.closeInspector ( true );
|
|
}
|
|
} );
|
|
this.$form.on( {
|
|
'submit': ve.bind( this.onSubmit, this ),
|
|
'keydown': ve.bind( this.onKeyDown, this )
|
|
} );
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
ve.ui.Inspector.prototype.onSubmit = function( e ) {
|
|
e.preventDefault();
|
|
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();
|
|
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 );
|