2013-03-27 22:56:54 +00:00
|
|
|
/*!
|
2013-07-16 14:06:47 +00:00
|
|
|
* VisualEditor ContentEditable MWInlineImageNode class.
|
2013-03-27 22:56:54 +00:00
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2013-03-27 22:56:54 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ContentEditable MediaWiki image node.
|
|
|
|
*
|
|
|
|
* @class
|
2013-06-07 01:27:07 +00:00
|
|
|
* @extends ve.ce.LeafNode
|
2013-10-15 12:18:11 +00:00
|
|
|
* @mixins ve.ce.MWImageNode
|
ve.Element refactor
Objectives:
* Move ve.ui.Element to ve.Element
* Make CE nodes inherit from ve.Element
Changes:
ve.ui.Element.js, ve.Element.js
* Move and rename
* Move ve.ui.get$$ to ve.Element.static.get$$
* Add static getDocument and getWindow methods
* Add instance getElementDocument and getElementWindow methods
* Add getTagName method, which by default reads the static tagName property, but when overridden can return a tag name based on other factors
*.php
* Updated file link
ve.ce.*Annotation.js, ve.ce.*Node.js, ve.ce.View.js, ve.ce.Document
* Added config options pass through
* Replaced passing elements through constructor with defining static tag names
* Added getTagName overrides where needed that derive tag name from model
* Refactore dom wrapper methods, now consistently using getTagName
ve.ce.Surface.js
* Removed static initialization (not needed)
ve.dm.Model.js, ve.ui.Window.js
* Added missing docs
ve.ui.GroupElement.js, ve.ui.Layout.js, ve.ui.Widget.js,
* Updated class name for elements
ve.ui.Frame.js, ve.ui.LookupInputWidget.js
* Updated location of get$$
ve.ui.js
* Move get$$ to ve.Element
ve.js
* Add auto-init of static properties to mixinClass
Change-Id: I39ae14966456903728e4d9e53f806ddce9ca2b70
2013-05-13 20:52:59 +00:00
|
|
|
*
|
2013-03-27 22:56:54 +00:00
|
|
|
* @constructor
|
2013-04-24 23:46:34 +00:00
|
|
|
* @param {ve.dm.MWInlineImageNode} model Model to observe
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2013-03-27 22:56:54 +00:00
|
|
|
*/
|
2017-06-22 19:55:28 +00:00
|
|
|
ve.ce.MWInlineImageNode = function VeCeMWInlineImageNode( model, config ) {
|
|
|
|
var $image;
|
2022-11-24 13:25:14 +00:00
|
|
|
var hasHref = false;
|
2015-05-24 15:21:04 +00:00
|
|
|
|
2017-06-22 19:55:28 +00:00
|
|
|
if ( model.getAttribute( 'isError' ) ) {
|
2015-05-24 15:21:04 +00:00
|
|
|
this.$element = $( '<a>' )
|
|
|
|
.addClass( 'new' )
|
2023-02-16 02:28:35 +00:00
|
|
|
.text( model.getAttribute( 'errorText' ) );
|
2016-11-06 15:08:23 +00:00
|
|
|
$image = $( [] );
|
2013-06-07 01:27:07 +00:00
|
|
|
} else {
|
2018-06-05 11:41:09 +00:00
|
|
|
if ( model.getAttribute( 'href' ) ) {
|
2022-11-24 13:25:14 +00:00
|
|
|
hasHref = true;
|
2022-03-09 19:33:42 +00:00
|
|
|
this.$element = $( '<a>' );
|
2016-11-06 15:08:23 +00:00
|
|
|
$image = $( '<img>' ).appendTo( this.$element );
|
2015-05-24 15:21:04 +00:00
|
|
|
} else {
|
2018-04-04 19:20:29 +00:00
|
|
|
this.$element = $image = $( '<img>' );
|
2015-05-24 15:21:04 +00:00
|
|
|
}
|
2013-06-07 01:27:07 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 19:55:28 +00:00
|
|
|
// Parent constructor
|
|
|
|
// this.$element has already been created and styled, so pass through as config.$element
|
|
|
|
// The constructor will add more classes to this.$element, such as ve-ce-leafNode
|
|
|
|
ve.ce.MWInlineImageNode.super.call( this, model, ve.extendObject( {}, config, { $element: this.$element } ) );
|
|
|
|
|
2013-06-07 01:27:07 +00:00
|
|
|
// Mixin constructors
|
2016-11-06 15:08:23 +00:00
|
|
|
ve.ce.MWImageNode.call( this, this.$element, $image );
|
2013-06-07 01:27:07 +00:00
|
|
|
|
2016-11-06 15:08:23 +00:00
|
|
|
$image
|
2013-10-21 15:12:54 +00:00
|
|
|
.attr( 'src', this.getResolvedAttribute( 'src' ) )
|
2013-06-07 01:27:07 +00:00
|
|
|
.attr( 'width', this.model.getAttribute( 'width' ) )
|
|
|
|
.attr( 'height', this.model.getAttribute( 'height' ) );
|
|
|
|
|
2022-11-24 13:25:14 +00:00
|
|
|
if ( hasHref ) {
|
|
|
|
// T322704
|
|
|
|
ve.setAttributeSafe( this.$element[ 0 ], 'href', this.getResolvedAttribute( 'href' ) || '', '#' );
|
|
|
|
}
|
|
|
|
|
2021-09-03 07:15:13 +00:00
|
|
|
this.showHandles( [ this.$element.css( 'direction' ) === 'rtl' ? 'sw' : 'se' ] );
|
2014-01-15 22:26:15 +00:00
|
|
|
|
2014-03-25 16:01:04 +00:00
|
|
|
this.updateClasses();
|
|
|
|
|
2013-06-10 22:03:38 +00:00
|
|
|
// DOM changes
|
2013-11-01 19:45:59 +00:00
|
|
|
this.$element.addClass( 've-ce-mwInlineImageNode' );
|
2013-03-27 22:56:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.ce.MWInlineImageNode, ve.ce.LeafNode );
|
2013-06-07 01:27:07 +00:00
|
|
|
|
2017-04-13 10:32:30 +00:00
|
|
|
// Need to mixin base class as well (T92540)
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.mixinClass( ve.ce.MWInlineImageNode, ve.ce.GeneratedContentNode );
|
2013-10-10 12:35:59 +00:00
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.mixinClass( ve.ce.MWInlineImageNode, ve.ce.MWImageNode );
|
2013-10-10 12:35:59 +00:00
|
|
|
|
2013-03-27 22:56:54 +00:00
|
|
|
/* Static Properties */
|
|
|
|
|
2013-05-28 11:31:41 +00:00
|
|
|
ve.ce.MWInlineImageNode.static.name = 'mwInlineImage';
|
2013-03-27 22:56:54 +00:00
|
|
|
|
2013-10-10 12:35:59 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-03-25 16:01:04 +00:00
|
|
|
/**
|
|
|
|
* Update CSS classes based on current attributes
|
|
|
|
*/
|
|
|
|
ve.ce.MWInlineImageNode.prototype.updateClasses = function () {
|
|
|
|
var valign = this.model.getAttribute( 'valign' );
|
|
|
|
|
|
|
|
// Border
|
|
|
|
this.$element.toggleClass( 'mw-image-border', !!this.model.getAttribute( 'borderImage' ) );
|
|
|
|
|
|
|
|
// default size
|
|
|
|
this.$element.toggleClass( 'mw-default-size', !!this.model.getAttribute( 'defaultSize' ) );
|
|
|
|
|
|
|
|
// valign
|
|
|
|
if ( valign !== 'default' ) {
|
|
|
|
this.$image.css( 'vertical-align', valign );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-11 12:33:53 +00:00
|
|
|
/**
|
2014-04-10 00:26:48 +00:00
|
|
|
* @inheritdoc
|
2013-10-11 12:33:53 +00:00
|
|
|
*/
|
2013-10-10 12:35:59 +00:00
|
|
|
ve.ce.MWInlineImageNode.prototype.onAttributeChange = function ( key, from, to ) {
|
2016-11-06 15:08:23 +00:00
|
|
|
// Mixin method
|
|
|
|
ve.ce.MWImageNode.prototype.onAttributeChange.apply( this, arguments );
|
|
|
|
|
2013-10-10 12:35:59 +00:00
|
|
|
if ( key === 'height' || key === 'width' ) {
|
|
|
|
to = parseInt( to, 10 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( from !== to ) {
|
|
|
|
switch ( key ) {
|
|
|
|
// TODO: 'align', 'src', 'valign', 'border'
|
|
|
|
case 'width':
|
|
|
|
this.$image.css( 'width', to );
|
|
|
|
break;
|
|
|
|
case 'height':
|
|
|
|
this.$image.css( 'height', to );
|
|
|
|
break;
|
2020-02-14 01:23:00 +00:00
|
|
|
case 'mediaType':
|
|
|
|
this.updateMediaType();
|
|
|
|
break;
|
2013-10-10 12:35:59 +00:00
|
|
|
}
|
2014-03-25 16:01:04 +00:00
|
|
|
this.updateClasses();
|
2013-10-10 12:35:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-27 22:56:54 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWInlineImageNode );
|