mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-30 00:55:00 +00:00
7bf15b4377
Switch sandbox demo to use new ui modules Update VisualEditor.php to use ve2 modules SpecialPageSandbox working Change-Id: I8261d6bf6ceb6ae7b7bfa5f61aec6a0121906765
64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
/**
|
|
* Creates an ve.ui.DropdownTool object.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @param {ve.ui.Toolbar} toolbar
|
|
* @param {String} name
|
|
* @param {Object[]} items
|
|
*/
|
|
ve.ui.DropdownTool = function( toolbar, name, title, items ) {
|
|
// Inheritance
|
|
ve.ui.Tool.call( this, toolbar, name, title );
|
|
if ( !name ) {
|
|
return;
|
|
}
|
|
|
|
// Properties
|
|
var _this = this;
|
|
this.menuView = new ve.ui.Menu( items, function( item ) {
|
|
_this.onSelect( item );
|
|
_this.$label.text( item.label );
|
|
}, this.$ );
|
|
this.$label = $( '<div class="es-toolbarDropdownTool-label"> </div>' ).appendTo( this.$ );
|
|
|
|
// Events
|
|
$( document )
|
|
.add( this.toolbar.surfaceView.$ )
|
|
.mousedown( function( e ) {
|
|
if ( e.which === 1 ) {
|
|
_this.menuView.close();
|
|
}
|
|
} );
|
|
this.$.bind( {
|
|
'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( '.es-menuView' );
|
|
if ( e.which === 1 && $item.length === 0 ) {
|
|
_this.menuView.open();
|
|
} else {
|
|
_this.menuView.close();
|
|
}
|
|
}
|
|
} );
|
|
|
|
// DOM Changes
|
|
this.$.addClass( 'es-toolbarDropdownTool' ).addClass( 'es-toolbarDropdownTool-' + name );
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
ve.ui.DropdownTool.prototype.onSelect = function( item ) {
|
|
throw 'DropdownTool.onSelect not implemented in this subclass:' + this.constructor;
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.extendClass( ve.ui.DropdownTool, ve.ui.Tool );
|