2013-04-25 00:47:17 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor ContentEditable MWBlockImageNode class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ContentEditable MediaWiki image node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ce.BranchNode
|
2013-05-15 17:01:19 +00:00
|
|
|
* @mixins ve.ce.ProtectedNode
|
2013-07-16 14:06:47 +00:00
|
|
|
* @mixins ve.ce.FocusableNode
|
|
|
|
* @mixins ve.ce.RelocatableNode
|
|
|
|
* @mixins ve.ce.MWResizableNode
|
2013-05-15 17:01:19 +00:00
|
|
|
*
|
2013-04-25 00:47:17 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {ve.dm.MWBlockImageNode} model Model to observe
|
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
|
|
|
* @param {Object} [config] Config options
|
2013-04-25 00:47:17 +00:00
|
|
|
*/
|
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
|
|
|
ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode( model, config ) {
|
2013-06-19 22:58:13 +00:00
|
|
|
var captionModel, captionView, type;
|
2013-05-17 19:40:12 +00:00
|
|
|
|
2013-04-25 00:47:17 +00:00
|
|
|
// Parent constructor
|
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
|
|
|
ve.ce.BranchNode.call( this, model, config );
|
2013-04-25 00:47:17 +00:00
|
|
|
|
2013-05-15 17:01:19 +00:00
|
|
|
// Mixin constructors
|
|
|
|
ve.ce.ProtectedNode.call( this );
|
2013-06-01 04:53:33 +00:00
|
|
|
ve.ce.FocusableNode.call( this );
|
2013-06-18 05:04:56 +00:00
|
|
|
ve.ce.RelocatableNode.call( this );
|
2013-07-16 14:06:47 +00:00
|
|
|
ve.ce.MWResizableNode.call( this );
|
2013-05-15 17:01:19 +00:00
|
|
|
|
2013-06-19 22:58:13 +00:00
|
|
|
type = this.model.getAttribute( 'type' );
|
|
|
|
|
2013-05-14 23:39:13 +00:00
|
|
|
if ( this.model.getAttribute( 'align' ) === 'center' ) {
|
|
|
|
this.$.addClass( 'center' );
|
|
|
|
this.$thumb = this.$$( '<div>' ).appendTo( this.$ );
|
|
|
|
} else {
|
|
|
|
this.$thumb = this.$;
|
|
|
|
}
|
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-05-14 23:39:13 +00:00
|
|
|
this.$thumbInner = this.$$( '<div>' )
|
|
|
|
.addClass( 'thumbinner' )
|
2013-06-19 22:58:13 +00:00
|
|
|
.css( 'width', parseInt( this.model.getAttribute( 'width' ), 10 ) + 2 );
|
2013-05-14 23:39:13 +00:00
|
|
|
|
2013-05-17 18:42:27 +00:00
|
|
|
this.$a = this.$$( '<a>' )
|
|
|
|
.addClass( 'image' )
|
2013-06-19 22:58:13 +00:00
|
|
|
.attr( 'src', this.model.getAttribute( 'href' ) );
|
2013-05-17 18:42:27 +00:00
|
|
|
|
2013-05-14 23:39:13 +00:00
|
|
|
this.$image = this.$$( '<img>' )
|
|
|
|
.attr( 'src', this.model.getAttribute( 'src' ) )
|
|
|
|
.attr( 'width', this.model.getAttribute( 'width' ) )
|
|
|
|
.attr( 'height', this.model.getAttribute( 'height' ) )
|
2013-05-17 18:42:27 +00:00
|
|
|
.appendTo( this.$a );
|
2013-05-17 19:40:12 +00:00
|
|
|
|
2013-06-25 00:47:03 +00:00
|
|
|
if ( type === 'none' || type ==='frameless' ) {
|
2013-06-19 22:58:13 +00:00
|
|
|
this.$thumb.addClass(
|
2013-07-24 21:20:40 +00:00
|
|
|
this.constructor.static.cssClasses.none[ this.model.getAttribute( 'align' ) ]
|
2013-06-19 22:58:13 +00:00
|
|
|
);
|
|
|
|
this.$a.appendTo( this.$thumb );
|
|
|
|
} else {
|
|
|
|
// Type "frame", "thumb" and the default
|
|
|
|
this.$image.addClass( 'thumbimage' );
|
|
|
|
this.$thumb
|
|
|
|
.addClass( 'thumb' );
|
|
|
|
this.$a.appendTo( this.$thumbInner );
|
2013-06-21 19:19:38 +00:00
|
|
|
this.$thumbInner.appendTo( this.$thumb );
|
2013-06-19 22:58:13 +00:00
|
|
|
}
|
|
|
|
|
2013-06-07 00:51:00 +00:00
|
|
|
this.$resizable = this.$image;
|
|
|
|
|
2013-05-17 19:40:12 +00:00
|
|
|
// I smell a caption!
|
2013-06-25 00:47:03 +00:00
|
|
|
if ( type !== 'none' && type !== 'frameless' && this.model.children.length === 1 ) {
|
2013-05-17 19:40:12 +00:00
|
|
|
captionModel = this.model.children[0];
|
|
|
|
captionView = ve.ce.nodeFactory.create( captionModel.getType(), captionModel );
|
|
|
|
captionModel.connect( this, { 'update': 'onModelUpdate' } );
|
|
|
|
this.children.push( captionView );
|
|
|
|
captionView.attach( this );
|
|
|
|
captionView.$.appendTo( this.$thumbInner );
|
|
|
|
if ( this.live !== captionView.isLive() ) {
|
|
|
|
captionView.setLive( this.live );
|
|
|
|
}
|
|
|
|
}
|
2013-04-25 00:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ce.MWBlockImageNode, ve.ce.BranchNode );
|
|
|
|
|
2013-05-15 17:01:19 +00:00
|
|
|
ve.mixinClass( ve.ce.MWBlockImageNode, ve.ce.ProtectedNode );
|
|
|
|
|
2013-06-01 04:53:33 +00:00
|
|
|
ve.mixinClass( ve.ce.MWBlockImageNode, ve.ce.FocusableNode );
|
|
|
|
|
2013-06-18 05:04:56 +00:00
|
|
|
ve.mixinClass( ve.ce.MWBlockImageNode, ve.ce.RelocatableNode );
|
|
|
|
|
2013-07-16 14:06:47 +00:00
|
|
|
// Need to mixin base class as well
|
2013-06-27 18:24:26 +00:00
|
|
|
ve.mixinClass( ve.ce.MWBlockImageNode, ve.ce.ResizableNode );
|
|
|
|
|
2013-07-16 14:06:47 +00:00
|
|
|
ve.mixinClass( ve.ce.MWBlockImageNode, ve.ce.MWResizableNode );
|
|
|
|
|
2013-04-25 00:47:17 +00:00
|
|
|
/* Static Properties */
|
|
|
|
|
2013-05-28 11:31:41 +00:00
|
|
|
ve.ce.MWBlockImageNode.static.name = 'mwBlockImage';
|
2013-04-25 00:47:17 +00:00
|
|
|
|
2013-05-14 23:39:13 +00:00
|
|
|
ve.ce.MWBlockImageNode.static.tagName = 'div';
|
|
|
|
|
|
|
|
ve.ce.MWBlockImageNode.static.renderHtmlAttributes = false;
|
|
|
|
|
2013-06-07 00:51:00 +00:00
|
|
|
ve.ce.MWBlockImageNode.static.transition = false;
|
|
|
|
|
2013-06-19 22:58:13 +00:00
|
|
|
ve.ce.MWBlockImageNode.static.cssClasses = {
|
|
|
|
'default': {
|
|
|
|
'left': 'tleft',
|
|
|
|
'right': 'tright',
|
|
|
|
'center' : 'tnone',
|
|
|
|
'none' : 'tnone',
|
2013-07-23 23:13:28 +00:00
|
|
|
// Default is different between RTL and LTR wikis:
|
|
|
|
'default': ['tright', 'tleft']
|
2013-06-19 22:58:13 +00:00
|
|
|
},
|
|
|
|
'none': {
|
|
|
|
'left': 'floatleft',
|
|
|
|
'right': 'floatright',
|
|
|
|
'center' : 'floatnone',
|
|
|
|
'none' : 'floatnone'
|
|
|
|
}
|
2013-05-14 23:39:13 +00:00
|
|
|
};
|
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-04-25 00:47:17 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2013-07-23 23:13:28 +00:00
|
|
|
/**
|
|
|
|
* Override the default onSetup to add direction-dependent
|
|
|
|
* classes to the image thumbnail.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ce.MWBlockImageNode.prototype.onSetup = function ( ) {
|
|
|
|
var type = this.model.getAttribute( 'type' ),
|
|
|
|
isRTL;
|
|
|
|
|
2013-07-24 21:02:08 +00:00
|
|
|
ve.ce.BranchNode.prototype.onSetup.call( this );
|
|
|
|
|
2013-07-23 23:13:28 +00:00
|
|
|
if ( type !== 'none' && type !=='frameless' ) {
|
|
|
|
// get the proper alignment for the image inside the editor
|
|
|
|
isRTL = ( this.$.css( 'direction' ) === 'rtl' ) ? 1 : 0;
|
|
|
|
this.$thumb
|
|
|
|
.addClass(
|
2013-07-24 21:20:40 +00:00
|
|
|
this.constructor.static.cssClasses[ 'default' ][ this.model.getAttribute( 'align' ) ][ isRTL ]
|
2013-07-23 23:13:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-05-14 23:39:13 +00:00
|
|
|
ve.ce.MWBlockImageNode.prototype.onAttributeChange = function ( key, from, to ) {
|
2013-06-25 00:47:03 +00:00
|
|
|
var $element, type;
|
2013-07-01 20:23:51 +00:00
|
|
|
|
|
|
|
if ( key === 'height' || key === 'width' ) {
|
|
|
|
to = parseInt( to, 10 );
|
|
|
|
}
|
|
|
|
|
2013-06-07 00:51:00 +00:00
|
|
|
if ( from !== to ) {
|
2013-06-19 02:31:01 +00:00
|
|
|
switch ( key ) {
|
|
|
|
case 'align':
|
|
|
|
if ( to === 'center' || from === 'center' ) {
|
|
|
|
this.emit( 'teardown' );
|
|
|
|
if ( to === 'center' ) {
|
|
|
|
$element = this.$$( '<div>' ).addClass( 'center' );
|
|
|
|
this.$thumb = this.$;
|
|
|
|
this.$.replaceWith( $element );
|
|
|
|
this.$ = $element;
|
|
|
|
this.$.append( this.$thumb );
|
|
|
|
} else {
|
|
|
|
this.$.replaceWith( this.$thumb );
|
|
|
|
this.$ = this.$thumb;
|
|
|
|
}
|
|
|
|
this.emit( 'setup' );
|
|
|
|
}
|
2013-06-25 00:47:03 +00:00
|
|
|
type = this.model.getAttribute( 'type' );
|
|
|
|
if ( type === 'none' || type === 'frameless' ) {
|
2013-07-24 21:20:40 +00:00
|
|
|
this.$thumb.removeClass( this.constructor.static.cssClasses.none[ from ] );
|
|
|
|
this.$thumb.addClass( this.constructor.static.cssClasses.none[ to ] );
|
2013-06-19 22:58:13 +00:00
|
|
|
} else {
|
2013-07-24 21:20:40 +00:00
|
|
|
this.$thumb.removeClass( this.constructor.static.cssClasses[ 'default' ][ from ] );
|
|
|
|
this.$thumb.addClass( this.constructor.static.cssClasses[ 'default' ][ to ] );
|
2013-06-19 22:58:13 +00:00
|
|
|
}
|
2013-06-19 02:31:01 +00:00
|
|
|
break;
|
|
|
|
case 'src':
|
|
|
|
this.$image.attr( 'src', to );
|
|
|
|
break;
|
|
|
|
case 'width':
|
|
|
|
this.$thumbInner.css( 'width', to + 2 );
|
2013-06-30 04:53:50 +00:00
|
|
|
this.$image.css( 'width', to );
|
|
|
|
break;
|
|
|
|
case 'height':
|
|
|
|
this.$image.css( 'height', to );
|
2013-06-19 02:31:01 +00:00
|
|
|
break;
|
2013-06-07 00:51:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-25 00:47:17 +00:00
|
|
|
ve.ce.MWBlockImageNode.prototype.setupSlugs = function () {
|
2013-05-14 23:39:13 +00:00
|
|
|
// Intentionally empty
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.ce.MWBlockImageNode.prototype.onSplice = function () {
|
|
|
|
// Intentionally empty
|
2013-04-25 00:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWBlockImageNode );
|