mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-16 02:51:50 +00:00
c40174b60c
This license change is aimed at maximizing the reusability of this code in other projects. VisualEditor is more than just an awesome editor for MediaWiki, it's the new editor for the entire internet. Added license and author files, plus mentions of the license to all VisualEditor PHP, JavaScript and CSS files. Parser files have not been modified but are effectively re-licensed since there's no overriding license information. 3rd party libraries are not changed, but are all already MIT licensed. Change-Id: I895b256325db7c8689756edab34523de4418b0f2
71 lines
1.6 KiB
JavaScript
71 lines
1.6 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
|
|
* @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 );
|