2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor content editable ImageNode class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2012-05-01 00:36:22 +00:00
|
|
|
/**
|
|
|
|
* ContentEditable node for an image.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-01 00:36:22 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.ce.LeafNode}
|
|
|
|
* @param model {ve.dm.ImageNode} Model to observe
|
|
|
|
*/
|
|
|
|
ve.ce.ImageNode = function( model ) {
|
|
|
|
// Inheritance
|
2012-05-05 00:50:54 +00:00
|
|
|
ve.ce.LeafNode.call( this, 'image', model, $( '<img>' ) );
|
2012-05-02 18:29:44 +00:00
|
|
|
|
2012-05-25 03:50:36 +00:00
|
|
|
// DOM Changes
|
|
|
|
this.$.addClass( 've-ce-imageNode' );
|
|
|
|
|
2012-05-02 18:29:44 +00:00
|
|
|
// Properties
|
2012-05-04 00:19:01 +00:00
|
|
|
this.currentSource = null;
|
|
|
|
|
2012-05-02 18:29:44 +00:00
|
|
|
// Events
|
2012-05-02 20:58:50 +00:00
|
|
|
this.model.addListenerMethod( this, 'update', 'onUpdate' );
|
2012-05-25 03:50:36 +00:00
|
|
|
/*
|
2012-05-24 22:10:16 +00:00
|
|
|
this.$.on('mousedown', function() {
|
2012-07-19 03:40:49 +00:00
|
|
|
return false;
|
2012-05-24 22:10:16 +00:00
|
|
|
});
|
2012-05-25 03:50:36 +00:00
|
|
|
*/
|
2012-05-04 00:19:01 +00:00
|
|
|
|
|
|
|
// Intialization
|
|
|
|
this.onUpdate();
|
2012-05-01 00:36:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
/**
|
2012-05-02 18:29:44 +00:00
|
|
|
* Node rules.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-01 00:36:22 +00:00
|
|
|
* @see ve.ce.NodeFactory
|
2012-05-02 18:29:44 +00:00
|
|
|
* @static
|
|
|
|
* @member
|
2012-05-01 00:36:22 +00:00
|
|
|
*/
|
|
|
|
ve.ce.ImageNode.rules = {
|
|
|
|
'canBeSplit': false
|
|
|
|
};
|
|
|
|
|
2012-05-02 18:29:44 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Responds to model update events.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-02 18:29:44 +00:00
|
|
|
* If the source changed since last update the image's src attribute will be updated accordingly.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-02 18:29:44 +00:00
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ce.ImageNode.prototype.onUpdate = function() {
|
2012-06-15 06:54:30 +00:00
|
|
|
// TODO needs to support height/width
|
2012-05-02 18:29:44 +00:00
|
|
|
var source = this.model.getAttribute( 'html/src' );
|
|
|
|
if ( source !== this.currentSource ) {
|
|
|
|
this.currentSource = source;
|
|
|
|
this.$.attr( 'src', source );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-01 00:36:22 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2012-05-31 22:20:58 +00:00
|
|
|
ve.ce.nodeFactory.register( 'image', ve.ce.ImageNode );
|
2012-05-01 00:36:22 +00:00
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.ce.ImageNode, ve.ce.LeafNode );
|