mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 17:36:35 +00:00
c472b2fe4a
ve.ui.Surface.js * Make local overlay a child of ve-ui-surface and a sibling to ve-ce-surface elements. ** This keeps local overlays relative to their surface and eliminates the need for insane z-indexes. ve.ui.PopupWidget.js * PopupWidget boundaries are now relative to ve-ce-surface and no longer protrude out ve.ce.Node.css, ve.ui.Window.css * Removal or replacement of insane z-indexes. ve.ce.FocusableNode.js, ve.ce.ProtectedNode.js, ve.ce.ResizableNode.js, ve.ui.Context.js * Translate offsets from local overlay ve.init.mw.ViewPageTarget-monobook.css, ve.init.mw.ViewPageTarget-vector.css * Skin specific z-indexes for global overlay ve.init.mw.ViewPageTarget.js * Applied direction specific mw class to ce.Surface vs ui.Surface to prevent mw content styles from being applied to ui elements. ve.ui.Dialog.css * Adjustments to surface inside of dialog so that relative offsets for local overlays can be properly calculated. ve.ui.Surface.css * Explicitly force .ve-ui-surface to be relative so that it's children can be relatively positioned. ve.ui.Widget.css * Removal of unnecessary font-size properties now that local overlay is sibling of surface. ve.js * Added get relative position helper method to translate position offsets from target parent Bug: 50241 Change-Id: Ibadce404a2286bc5dcec48f0d9da89004dbbd867
138 lines
3.1 KiB
JavaScript
138 lines
3.1 KiB
JavaScript
/*!
|
|
* VisualEditor ContentEditable RelocatableNode class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* ContentEditable relocatable node.
|
|
*
|
|
* Requires that the node also is Focusable
|
|
*
|
|
* @class
|
|
* @abstract
|
|
*
|
|
* @constructor
|
|
*/
|
|
ve.ce.RelocatableNode = function VeCeRelocatableNode() {
|
|
// Properties
|
|
this.relocatingSurface = null;
|
|
this.$relocatableMarker = this.$$( '<img>' );
|
|
|
|
// Events
|
|
this.connect( this, {
|
|
'focus': 'onRelocatableFocus',
|
|
'blur': 'onRelocatableBlur',
|
|
'resize': 'onRelocatableResize',
|
|
'live': 'onRelocatableLive'
|
|
} );
|
|
|
|
// Initialization
|
|
this.$relocatableMarker
|
|
.addClass( 've-ce-relocatableNode-marker' )
|
|
.attr( 'src', 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' )
|
|
.on( {
|
|
'dragstart': ve.bind( this.onRelocatableDragStart, this ),
|
|
'dragend': ve.bind( this.onRelocatableDragEnd, this )
|
|
} );
|
|
};
|
|
|
|
/* Static Properties */
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle node live.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.RelocatableNode.prototype.onRelocatableLive = function () {
|
|
var surfaceModel = this.root.getSurface().getModel();
|
|
|
|
if ( this.live ) {
|
|
surfaceModel.connect( this, { 'history': 'setRelocatableMarkerSizeAndPosition' } );
|
|
} else {
|
|
surfaceModel.disconnect( this, { 'history': 'setRelocatableMarkerSizeAndPosition' } );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handle node focus.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.RelocatableNode.prototype.onRelocatableFocus = function () {
|
|
this.setRelocatableMarkerSizeAndPosition();
|
|
this.$relocatableMarker.appendTo( this.root.getSurface().getSurface().$localOverlayControls );
|
|
};
|
|
|
|
/**
|
|
* Handle node blur.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.RelocatableNode.prototype.onRelocatableBlur = function () {
|
|
this.$relocatableMarker.detach();
|
|
};
|
|
|
|
/**
|
|
* Handle node resize.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.RelocatableNode.prototype.onRelocatableResize = function () {
|
|
this.setRelocatableMarkerSizeAndPosition();
|
|
};
|
|
|
|
/**
|
|
* Handle element drag start.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.RelocatableNode.prototype.onRelocatableDragStart = function () {
|
|
// Store a copy of the surface, when dragend occurs the node will be detached
|
|
this.relocatingSurface = this.root.getSurface();
|
|
|
|
if ( this.relocatingSurface ) {
|
|
// Allow dragging this node in the surface
|
|
this.relocatingSurface.startRelocation( this );
|
|
}
|
|
this.$relocatableMarker.addClass( 'relocating' );
|
|
|
|
setTimeout( ve.bind( function () {
|
|
this.$relocatableMarker.css( { 'top': -10000, 'left': -10000 } );
|
|
}, this ), 0 );
|
|
};
|
|
|
|
/**
|
|
* Handle element drag end.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.RelocatableNode.prototype.onRelocatableDragEnd = function () {
|
|
if ( this.relocatingSurface ) {
|
|
this.relocatingSurface.endRelocation();
|
|
this.relocatingSurface = null;
|
|
}
|
|
this.$relocatableMarker.removeClass( 'relocating' );
|
|
};
|
|
|
|
/**
|
|
* Set the correct size and position of the relocatable marker.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.RelocatableNode.prototype.setRelocatableMarkerSizeAndPosition = function () {
|
|
var offset = ve.Element.getRelativePosition(
|
|
this.$, this.getRoot().getSurface().getSurface().$
|
|
);
|
|
|
|
this.$relocatableMarker.css( {
|
|
'height': this.$.height(),
|
|
'width': this.$.width(),
|
|
'top': offset.top,
|
|
'left': offset.left
|
|
} );
|
|
};
|