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-10-15 12:18:11 +00:00
|
|
|
* @mixins ve.ce.MWImageNode
|
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
|
2013-09-25 10:21:09 +00:00
|
|
|
* @param {Object} [config] Configuration 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-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-08-30 21:04:29 +00:00
|
|
|
this.$inner = this.$$( '<div>' ).addClass( 've-ce-mwBlockImageNode-inner' );
|
|
|
|
|
|
|
|
if ( type === 'none' || type === 'frameless' ) {
|
2013-06-19 22:58:13 +00:00
|
|
|
this.$thumb.addClass(
|
2013-07-24 22:31:46 +00:00
|
|
|
this.getCssClass( 'none', this.model.getAttribute( 'align' ) )
|
2013-06-19 22:58:13 +00:00
|
|
|
);
|
|
|
|
this.$a.appendTo( this.$thumb );
|
2013-08-30 21:04:29 +00:00
|
|
|
|
|
|
|
// For centered images, this.$thumb is full width, so wrap
|
|
|
|
// this.$image in another div and use that for selection
|
|
|
|
this.$inner
|
|
|
|
.append( this.$image )
|
|
|
|
.appendTo( this.$a );
|
2013-06-19 22:58:13 +00:00
|
|
|
} 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-08-30 21:04:29 +00:00
|
|
|
|
|
|
|
// For centered images, this.$thumb is full width, so wrap
|
|
|
|
// this.$thumbInner in another div and use that for selection
|
|
|
|
this.$inner
|
|
|
|
.append( this.$thumbInner )
|
|
|
|
.appendTo( this.$thumb );
|
2013-06-19 22:58:13 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 21:04:29 +00:00
|
|
|
// Mixin constructors
|
2013-10-15 12:18:11 +00:00
|
|
|
ve.ce.MWImageNode.call( this, this.$inner, this.$image );
|
2013-06-07 00:51:00 +00:00
|
|
|
|
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-10-11 12:33:53 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.model.connect( this, { 'attributeChange': 'onAttributeChange' } );
|
2013-04-25 00:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.ce.MWBlockImageNode, ve.ce.BranchNode );
|
2013-04-25 00:47:17 +00:00
|
|
|
|
2013-07-16 14:06:47 +00:00
|
|
|
// Need to mixin base class as well
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.mixinClass( ve.ce.MWBlockImageNode, ve.ce.GeneratedContentNode );
|
2013-06-27 18:24:26 +00:00
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.mixinClass( ve.ce.MWBlockImageNode, ve.ce.MWImageNode );
|
2013-07-16 14:06:47 +00:00
|
|
|
|
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',
|
2013-07-24 22:31:46 +00:00
|
|
|
'none' : 'tnone'
|
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-24 22:31:46 +00:00
|
|
|
/**
|
|
|
|
* Get the right CSS class to use for alignment
|
|
|
|
* @param {string} type 'none' or 'default'
|
|
|
|
* @param {string} alignment 'left', 'right', 'center', 'none' or 'default'
|
|
|
|
*/
|
|
|
|
ve.ce.MWBlockImageNode.prototype.getCssClass = function ( type, alignment ) {
|
|
|
|
// TODO use this.model.getAttribute( 'type' ) etc., see bug 52065
|
|
|
|
// Default is different between RTL and LTR wikis:
|
|
|
|
if ( type === 'default' && alignment === 'default' ) {
|
|
|
|
if ( this.$.css( 'direction' ) === 'rtl' ) {
|
|
|
|
return 'tleft';
|
|
|
|
} else {
|
|
|
|
return 'tright';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return this.constructor.static.cssClasses[type][alignment];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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 ( ) {
|
2013-07-24 22:31:46 +00:00
|
|
|
var type = this.model.getAttribute( 'type' );
|
2013-07-23 23:13:28 +00:00
|
|
|
|
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' ) {
|
2013-07-24 22:31:46 +00:00
|
|
|
this.$thumb.addClass( this.getCssClass( 'default', this.model.getAttribute( 'align' ) ) );
|
2013-07-23 23:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-10-11 12:33:53 +00:00
|
|
|
/**
|
|
|
|
* Update the rendering of the 'align', src', 'width' and 'height' attributes when they change
|
|
|
|
* in the model.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} key Attribute key
|
|
|
|
* @param {string} from Old value
|
|
|
|
* @param {string} to New value
|
|
|
|
* @emits setup
|
|
|
|
*/
|
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 22:31:46 +00:00
|
|
|
this.$thumb.removeClass( this.getCssClass( 'none', from ) );
|
|
|
|
this.$thumb.addClass( this.getCssClass( 'none', to ) );
|
2013-06-19 22:58:13 +00:00
|
|
|
} else {
|
2013-07-24 22:31:46 +00:00
|
|
|
this.$thumb.removeClass( this.getCssClass( 'default', from ) );
|
|
|
|
this.$thumb.addClass( this.getCssClass( '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-10-14 11:44:26 +00:00
|
|
|
/** */
|
|
|
|
ve.ce.MWBlockImageNode.prototype.onResizableResizing = function ( dimensions ) {
|
|
|
|
if ( !this.outline ) {
|
|
|
|
ve.ce.ResizableNode.prototype.onResizableResizing.call( this, dimensions );
|
|
|
|
this.$thumbInner.css( 'width', dimensions.width + 2 );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-31 22:53:29 +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
|
|
|
|
};
|
|
|
|
|
2013-07-31 22:53:29 +00:00
|
|
|
/** */
|
2013-05-14 23:39:13 +00:00
|
|
|
ve.ce.MWBlockImageNode.prototype.onSplice = function () {
|
|
|
|
// Intentionally empty
|
2013-04-25 00:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.MWBlockImageNode );
|