mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +00:00
a15b2f77f2
Add some missing constructor names and rename the ones with a lowercase 'v'. I previously changed Object.create and others to using hasOwn, but that turned out to be useless. The thought at the time was to only use the native one if it really is a native one (and not a polyfill from another script), however in then hasOwn is only relevant on prototypes and when negated. For static members it would be an own-property either way. Follows-up: * Id6783fcfc35a896db088ff424ff9faaabcaff716 (metanode) * Iab763954fb8cf375900d7a9a92dec1c755d5407e (object-management) Change-Id: Ia6ef597e5e5453277472dfc23f25d2878b68b7f6
79 lines
1.7 KiB
JavaScript
79 lines
1.7 KiB
JavaScript
/**
|
|
* VisualEditor content editable MetaBlockNode class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* ContentEditable node for a list.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @extends {ve.ce.BranchNode}
|
|
* @param model {ve.dm.MetaBlockNode} Model to observe
|
|
*/
|
|
ve.ce.MetaBlockNode = function VeCeMetaBlockNode( model ) {
|
|
// Parent constructor
|
|
ve.ce.BranchNode.call( this, 'metaBlock', model );
|
|
|
|
// DOM Changes
|
|
this.$.addClass( 've-ce-metaBlockNode' );
|
|
this.$.attr( 'contenteditable', false );
|
|
|
|
// Properties
|
|
this.currentKey = null; // Populated by the first onUpdate() call
|
|
this.currentValue = null; // Populated by the first onUpdate() call
|
|
|
|
// Events
|
|
this.model.addListenerMethod( this, 'update', 'onUpdate' );
|
|
|
|
// Intialization
|
|
this.onUpdate();
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ce.MetaBlockNode, ve.ce.BranchNode );
|
|
|
|
/* Static Members */
|
|
|
|
/**
|
|
* Node rules.
|
|
*
|
|
* @see ve.ce.NodeFactory
|
|
* @static
|
|
* @member
|
|
*/
|
|
ve.ce.MetaBlockNode.rules = {
|
|
'canBeSplit': false
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Responds to model update events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.MetaBlockNode.prototype.onUpdate = function () {
|
|
var key = this.model.getAttribute( 'key' ),
|
|
value = this.model.getAttribute( 'value' );
|
|
if ( key !== this.currentKey || value !== this.currentValue ) {
|
|
this.currentKey = key;
|
|
this.currentValue = value;
|
|
if ( key !== null && value !== undefined ) {
|
|
this.$.text( key + '=' + value );
|
|
} else if ( key !== null ) {
|
|
this.$.text( key );
|
|
} else {
|
|
// Most likely <meta typeof="mw:Placeholder"> , we don't know what this is
|
|
this.$.text( 'META' );
|
|
}
|
|
}
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ce.nodeFactory.register( 'metaBlock', ve.ce.MetaBlockNode );
|