Merge "Clickable inline images"

This commit is contained in:
jenkins-bot 2013-04-09 23:46:45 +00:00 committed by Gerrit Code Review
commit 906f4cf21d
2 changed files with 23 additions and 5 deletions

View file

@ -59,8 +59,20 @@ ve.ce.MWImageNode.prototype.onUpdate = function () {
* @param {jQuery.Event} e Click event * @param {jQuery.Event} e Click event
*/ */
ve.ce.MWImageNode.prototype.onClick = function ( e ) { ve.ce.MWImageNode.prototype.onClick = function ( e ) {
e.preventDefault(); var range,
return false; surfaceModel = this.getRoot().getSurface().getModel(),
selection = surfaceModel.getSelection();
range = new ve.Range(
this.model.getOffset(),
this.model.getOffset() + this.model.getOuterLength()
);
if ( e.shiftKey ) {
range = ve.Range.newCoveringRange( [ selection, range ], selection.from > range.from );
}
this.getRoot().getSurface().getModel().change( null, range );
}; };
/** /**

View file

@ -43,10 +43,11 @@ ve.Range.newFromTranslatedRange = function ( range, distance ) {
* *
* @method * @method
* @param {Array} ranges Array of ve.Range objects (at least one) * @param {Array} ranges Array of ve.Range objects (at least one)
* @param {boolean} backwards Return a backwards range
* @returns {ve.Range} Range that spans all of the given ranges * @returns {ve.Range} Range that spans all of the given ranges
*/ */
ve.Range.newCoveringRange = function ( ranges ) { ve.Range.newCoveringRange = function ( ranges, backwards ) {
var minStart, maxEnd, i; var minStart, maxEnd, i, range;
if ( !ranges || ranges.length === 0 ) { if ( !ranges || ranges.length === 0 ) {
throw new Error( 'newCoveringRange() requires at least one range' ); throw new Error( 'newCoveringRange() requires at least one range' );
} }
@ -60,7 +61,12 @@ ve.Range.newCoveringRange = function ( ranges ) {
maxEnd = ranges[i].end; maxEnd = ranges[i].end;
} }
} }
return new ve.Range( minStart, maxEnd ); if ( backwards ) {
range = new ve.Range( maxEnd, minStart );
} else {
range = new ve.Range( minStart, maxEnd );
}
return range;
}; };
/* Methods */ /* Methods */