/** * 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.Toolbar} toolbar * @param {ve.ui.Context} context */ ve.ui.Inspector = function VeUiInspector( toolbar, context ) { // Inheritance ve.EventEmitter.call( this ); if ( !toolbar || !context ) { return; } // Properties this.toolbar = toolbar; this.context = context; this.$ = $( '
', context.inspectorDoc ); this.$closeButton = $( '
', context.inspectorDoc ); this.$acceptButton = $( '
', context.inspectorDoc ); this.$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 () { if ( $( this ).hasClass( 've-ui-inspector-button-disabled' ) ) { return; } 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 ); /* Methods */ ve.ui.Inspector.prototype.onSubmit = function ( e ) { e.preventDefault(); if ( this.$acceptButton.hasClass( 've-ui-inspector-button-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(); 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' ); };