Merge "Create MWResizeableNode mixin to control defaultSize flag"

This commit is contained in:
jenkins-bot 2013-07-16 22:51:24 +00:00 committed by Gerrit Code Review
commit 3675ca4cc8
7 changed files with 78 additions and 12 deletions

View file

@ -413,6 +413,8 @@ $wgResourceModules += array(
've/ce/nodes/ve.ce.TableSectionNode.js',
've/ce/nodes/ve.ce.TextNode.js',
've-mw/ce/ve.ce.MWResizableNode.js',
've-mw/ce/nodes/ve.ce.MWEntityNode.js',
've-mw/ce/nodes/ve.ce.MWHeadingNode.js',
've-mw/ce/nodes/ve.ce.MWPreformattedNode.js',

View file

@ -11,6 +11,9 @@
* @class
* @extends ve.ce.BranchNode
* @mixins ve.ce.ProtectedNode
* @mixins ve.ce.FocusableNode
* @mixins ve.ce.RelocatableNode
* @mixins ve.ce.MWResizableNode
*
* @constructor
* @param {ve.dm.MWBlockImageNode} model Model to observe
@ -26,7 +29,7 @@ ve.ce.MWBlockImageNode = function VeCeMWBlockImageNode( model, config ) {
ve.ce.ProtectedNode.call( this );
ve.ce.FocusableNode.call( this );
ve.ce.RelocatableNode.call( this );
ve.ce.ResizableNode.call( this );
ve.ce.MWResizableNode.call( this );
type = this.model.getAttribute( 'type' );
@ -94,8 +97,11 @@ ve.mixinClass( ve.ce.MWBlockImageNode, ve.ce.FocusableNode );
ve.mixinClass( ve.ce.MWBlockImageNode, ve.ce.RelocatableNode );
// Need to mixin base class as well
ve.mixinClass( ve.ce.MWBlockImageNode, ve.ce.ResizableNode );
ve.mixinClass( ve.ce.MWBlockImageNode, ve.ce.MWResizableNode );
/* Static Properties */
ve.ce.MWBlockImageNode.static.name = 'mwBlockImage';

View file

@ -1,5 +1,5 @@
/*!
* VisualEditor ContentEditable MWEntityNode class.
* VisualEditor ContentEditable MWInlineImageNode class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
@ -10,6 +10,9 @@
*
* @class
* @extends ve.ce.LeafNode
* @mixins ve.ce.ProtectedNode
* @mixins ve.ce.FocusableNode
* @mixins ve.ce.RelocatableNode
*
* @constructor
* @param {ve.dm.MWInlineImageNode} model Model to observe

View file

@ -0,0 +1,41 @@
/*!
* VisualEditor ContentEditable MWResizableNode class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* ContentEditable MediaWiki resizable node.
*
* @class
* @abstract
* @extends {ve.ce.ResizableNode}
*
* @constructor
* @param {jQuery} [$resizable=this.$] Resizable DOM element
*/
ve.ce.MWResizableNode = function VeCeMwResizableNode( $resizable ) {
ve.ce.ResizableNode.call( this, $resizable );
};
/* Inheritance */
ve.inheritClass( ve.ce.MWResizableNode, ve.ce.ResizableNode );
/**
* Generate an object of attributes changes from the new width and height.
*
* If either property changes, clear the defaultSize flag.
*
* @param {number} width New image width
* @param {number} height New image height
* @returns {Object} Attribute changes
*/
ve.ce.MWResizableNode.prototype.getAttributeChanges = function ( width, height ) {
var attrChanges = ve.ce.ResizableNode.prototype.getAttributeChanges.call( this, width, height );
if ( !ve.isEmptyObject( attrChanges ) ) {
attrChanges.defaultSize = false;
}
return attrChanges;
};

View file

@ -1,5 +1,5 @@
/*!
* VisualEditor DataModel MWEntityNode class.
* VisualEditor DataModel MWInlineImage class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt

View file

@ -180,6 +180,7 @@
<script src="../../ve/ce/nodes/ve.ce.TableRowNode.js"></script>
<script src="../../ve/ce/nodes/ve.ce.TableSectionNode.js"></script>
<script src="../../ve/ce/nodes/ve.ce.TextNode.js"></script>
<script src="../../ve-mw/ce/ve.ce.MWResizableNode.js"></script>
<script src="../../ve-mw/ce/nodes/ve.ce.MWEntityNode.js"></script>
<script src="../../ve-mw/ce/nodes/ve.ce.MWHeadingNode.js"></script>
<script src="../../ve-mw/ce/nodes/ve.ce.MWPreformattedNode.js"></script>

View file

@ -258,25 +258,20 @@ ve.ce.ResizableNode.prototype.onDocumentMouseMove = function ( e ) {
* @method
*/
ve.ce.ResizableNode.prototype.onDocumentMouseUp = function () {
var offset = this.model.getOffset(),
var attrChanges,
offset = this.model.getOffset(),
width = this.$resizeHandles.outerWidth(),
height = this.$resizeHandles.outerHeight(),
surfaceModel = this.getRoot().getSurface().getModel(),
documentModel = surfaceModel.getDocument(),
selection = surfaceModel.getSelection(),
attrChanges = {};
selection = surfaceModel.getSelection();
this.$resizeHandles.removeClass( 've-ui-resizableNode-handles-resizing' );
$( this.getElementDocument() ).off( '.ve-ce-resizableNode' );
this.resizing = false;
// Apply changes to the model
if ( this.model.getAttribute( 'width' ) !== width ) {
attrChanges.width = width;
}
if ( this.model.getAttribute( 'height' ) !== height ) {
attrChanges.height = height;
}
attrChanges = this.getAttributeChanges( width, height );
if ( !ve.isEmptyObject( attrChanges ) ) {
surfaceModel.change(
ve.dm.Transaction.newFromAttributeChanges( documentModel, offset, attrChanges ),
@ -286,3 +281,21 @@ ve.ce.ResizableNode.prototype.onDocumentMouseUp = function () {
this.emit( 'resize' );
};
/**
* Generate an object of attributes changes from the new width and height.
*
* @param {number} width New image width
* @param {number} height New image height
* @returns {Object} Attribute changes
*/
ve.ce.ResizableNode.prototype.getAttributeChanges = function ( width, height ) {
var attrChanges = {};
if ( this.model.getAttribute( 'width' ) !== width ) {
attrChanges.width = width;
}
if ( this.model.getAttribute( 'height' ) !== height ) {
attrChanges.height = height;
}
return attrChanges;
};