mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
ab7d6bf082
* Commands for Sublime: Find*: "(\* @[a-z]+) ([^{].*) \{(.*)\}" Replace: "$1 {$3} $2" Save all && Close all Find: " function(" Replace: " function (" Save all && Close all Find: "Intialization" Replace: "Initialization" Save all && Close all * Consistent use of types (documented in CODING.rm): - Merged {Integer} into {Number}. - Merged {DOM Node} into {DOMElement}. * Remove work-around /*jshint newcap: false */ from ve.js Calling Object() as a function to to use the internal toObject no longer throws a newcap warning in JSHint. It only does that normal functions now . (e.g. var a = Cap(); or var a = new uncap();) * Add missing annotations (@static, @method, ..). * Remove unused variables * Remove null-assignments to variables that should just be undefined. There's a few variables explicitly set to null whereas they are set a few lines under and not used otherwise (e.g. 'tx' in ve.ce.Surface.prototype.onPaste) Change-Id: I0721a08f8ecd93c25595aedaa1aadb0e08b83799
80 lines
1.9 KiB
JavaScript
80 lines
1.9 KiB
JavaScript
/**
|
|
* VisualEditor user interface DropdownTool class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.DropdownTool object.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @extends {ve.ui.Tool}
|
|
* @param {ve.ui.Toolbar} toolbar
|
|
* @param {String} name
|
|
* @param title
|
|
* @param {Object[]} items
|
|
*/
|
|
ve.ui.DropdownTool = function VeUiDropdownTool( toolbar, name, title, items ) {
|
|
// Parent constructor
|
|
ve.ui.Tool.call( this, toolbar, name, title );
|
|
|
|
if ( !name ) {
|
|
return;
|
|
}
|
|
|
|
// Properties
|
|
var tool = this;
|
|
this.menuView = new ve.ui.Menu( items, function ( item ) {
|
|
tool.onSelect( item );
|
|
tool.$labelText.text( item.label );
|
|
}, this.$ );
|
|
this.$icon = $( '<div class="ve-ui-toolbarDropdownTool-icon"></div>' );
|
|
this.$label = $( '<div class="ve-ui-toolbarDropdownTool-label"></div>' );
|
|
this.$labelText = $( '<span> </span>' );
|
|
|
|
// Events
|
|
$( document )
|
|
.add( this.toolbar.surfaceView.$ )
|
|
.mousedown( function ( e ) {
|
|
if ( e.which === 1 ) {
|
|
tool.menuView.close();
|
|
}
|
|
} );
|
|
|
|
this.$.on( {
|
|
'mousedown': function ( e ) {
|
|
if ( e.which === 1 ) {
|
|
e.preventDefault();
|
|
return false;
|
|
}
|
|
},
|
|
'mouseup': function ( e ) {
|
|
// Don't respond to menu clicks
|
|
var $item = $( e.target ).closest( '.ve-ui-menu' );
|
|
if ( e.which === 1 && $item.length === 0 ) {
|
|
tool.menuView.open();
|
|
} else {
|
|
tool.menuView.close();
|
|
}
|
|
}
|
|
} );
|
|
|
|
// DOM Changes
|
|
this.$
|
|
.append( this.$icon, this.$label )
|
|
.addClass( 've-ui-toolbarDropdownTool ve-ui-toolbarDropdownTool-' + name );
|
|
this.$label.append( this.$labelText );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ui.DropdownTool, ve.ui.Tool );
|
|
|
|
/* Methods */
|
|
|
|
ve.ui.DropdownTool.prototype.onSelect = function () {
|
|
throw new Error( 'DropdownTool.onSelect not implemented in this subclass:' + this.constructor );
|
|
};
|