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
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @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-07-16 14:06:47 +00:00
|
|
|
* @mixins ve.ce.ProtectedNode
|
|
|
|
* @mixins ve.ce.FocusableNode
|
|
|
|
* @mixins ve.ce.RelocatableNode
|
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
|
|
|
*/
|
2013-06-07 01:27:07 +00:00
|
|
|
ve.ce.MWInlineImageNode = function VeCeMWInlineImageNode( model, config ) {
|
|
|
|
var valign;
|
|
|
|
|
2013-03-27 22:56:54 +00:00
|
|
|
// Parent constructor
|
2013-06-07 01:27:07 +00:00
|
|
|
ve.ce.LeafNode.call( this, model, config );
|
|
|
|
|
|
|
|
if ( this.model.getAttribute( 'isLinked' ) ) {
|
|
|
|
this.$ = this.$$( '<a>' ).addClass( 'image' );
|
|
|
|
this.$image = this.$$( '<img>' ).appendTo( this.$ );
|
|
|
|
} else {
|
2013-06-10 22:29:12 +00:00
|
|
|
// For inline images that are not linked (empty linkto=) we intentionally don't match output
|
|
|
|
// of MW Parser, instead we wrap those images in span so selection and hover (based on
|
|
|
|
// shields) can work well. It might change in the future when we improve our selection.
|
|
|
|
this.$ = this.$$( '<span>' );
|
|
|
|
this.$image = this.$$( '<img>' ).appendTo( this.$ );
|
2013-06-07 01:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
ve.ce.ProtectedNode.call( this );
|
|
|
|
ve.ce.FocusableNode.call( this );
|
2013-06-18 05:04:56 +00:00
|
|
|
ve.ce.RelocatableNode.call( this );
|
2013-06-07 01:27:07 +00:00
|
|
|
|
|
|
|
this.$image
|
|
|
|
.attr( 'src', this.model.getAttribute( 'src' ) )
|
|
|
|
.attr( 'width', this.model.getAttribute( 'width' ) )
|
|
|
|
.attr( 'height', this.model.getAttribute( 'height' ) );
|
|
|
|
|
|
|
|
if ( this.model.getAttribute( 'border' ) ) {
|
|
|
|
this.$image.addClass( 'thumbborder' );
|
|
|
|
}
|
|
|
|
|
|
|
|
valign = this.model.getAttribute( 'valign' );
|
|
|
|
if ( valign !== 'default' ) {
|
|
|
|
this.$image.css( 'vertical-align', valign );
|
|
|
|
}
|
2013-06-10 22:03:38 +00:00
|
|
|
|
|
|
|
// DOM changes
|
|
|
|
this.$.addClass( 've-ce-mwInlineImageNode' );
|
2013-03-27 22:56:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-06-07 01:27:07 +00:00
|
|
|
ve.inheritClass( ve.ce.MWInlineImageNode, ve.ce.LeafNode );
|
|
|
|
|
|
|
|
ve.mixinClass( ve.ce.MWInlineImageNode, ve.ce.ProtectedNode );
|
|
|
|
|
|
|
|
ve.mixinClass( ve.ce.MWInlineImageNode, ve.ce.FocusableNode );
|
2013-03-27 22:56:54 +00:00
|
|
|
|
2013-06-18 05:04:56 +00:00
|
|
|
ve.mixinClass( ve.ce.MWInlineImageNode, ve.ce.RelocatableNode );
|
|
|
|
|
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-05-15 00:36:04 +00:00
|
|
|
ve.ce.MWInlineImageNode.static.tagName = 'img';
|
2013-03-27 22:56:54 +00:00
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
2013-04-24 23:46:34 +00:00
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWInlineImageNode );
|