mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
3fe30323e5
*.php * Added links to new file ve.ce.ImageNode.js * Added focusable node mixin ve.ce.FocusableNode.js * New class! * Adds isFocused and setFocused methods * When a node is focused or blurred, 'focus' and 'blur' events are emitted * While a node is focused, it will have the 've-ce-node-focused' class added to it's this.$ ve.ce.Surface.js * Add detection of node focusing and setting focus and blur on nodes on change Change-Id: I3f1ad6309571f2bfe568550e2e8f1bd5a0302085
65 lines
1.1 KiB
JavaScript
65 lines
1.1 KiB
JavaScript
/*!
|
|
* VisualEditor ContentEditable FocusableNode class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* ContentEditable resizable node.
|
|
*
|
|
* @class
|
|
* @abstract
|
|
*
|
|
* @constructor
|
|
* @param {jQuery} [$resizable=this.$] Focusable DOM element
|
|
*/
|
|
ve.ce.FocusableNode = function VeCeFocusableNode() {
|
|
// Properties
|
|
this.focused = false;
|
|
};
|
|
|
|
/* Events */
|
|
|
|
/**
|
|
* @event focus
|
|
*/
|
|
|
|
/**
|
|
* @event blur
|
|
*/
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Check if node is focused.
|
|
*
|
|
* @method
|
|
* @returns {boolean} Node is focused
|
|
*/
|
|
ve.ce.FocusableNode.prototype.isFocused = function () {
|
|
return this.focused;
|
|
};
|
|
|
|
/**
|
|
* Set the selected state of the node.
|
|
*
|
|
* @method
|
|
* @param {boolean} value Node is focused
|
|
* @emits focus
|
|
* @emits blur
|
|
*/
|
|
ve.ce.FocusableNode.prototype.setFocused = function ( value ) {
|
|
value = !!value;
|
|
if ( this.focused !== value ) {
|
|
this.focused = value;
|
|
if ( this.focused ) {
|
|
this.emit( 'focus' );
|
|
this.$.addClass( 've-ce-node-focused' );
|
|
} else {
|
|
this.emit( 'blur' );
|
|
this.$.removeClass( 've-ce-node-focused' );
|
|
}
|
|
}
|
|
};
|