mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 01:16:30 +00:00
Clickable inline images
Clicking an inline image will select it, or expand the selection. Change-Id: I505665f2dac2e52140cc049e63e3355190dcbfec
This commit is contained in:
parent
4c1934b19d
commit
23ac4b79bb
|
@ -59,8 +59,20 @@ ve.ce.MWImageNode.prototype.onUpdate = function () {
|
|||
* @param {jQuery.Event} e Click event
|
||||
*/
|
||||
ve.ce.MWImageNode.prototype.onClick = function ( e ) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
var range,
|
||||
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 );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,10 +43,11 @@ ve.Range.newFromTranslatedRange = function ( range, distance ) {
|
|||
*
|
||||
* @method
|
||||
* @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
|
||||
*/
|
||||
ve.Range.newCoveringRange = function ( ranges ) {
|
||||
var minStart, maxEnd, i;
|
||||
ve.Range.newCoveringRange = function ( ranges, backwards ) {
|
||||
var minStart, maxEnd, i, range;
|
||||
if ( !ranges || ranges.length === 0 ) {
|
||||
throw new Error( 'newCoveringRange() requires at least one range' );
|
||||
}
|
||||
|
@ -60,7 +61,12 @@ ve.Range.newCoveringRange = function ( ranges ) {
|
|||
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 */
|
||||
|
|
Loading…
Reference in a new issue