https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113674
Revision: 113674
Author: rmoen
Date: 2012-03-12 21:50:22 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
port over select event listener, and updateSelection methods for setting and
removing context icon, add getSelectionRect method for context icon position
Modified Paths:
--------------
trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js
trunk/extensions/VisualEditor/modules/ve/ui/ve.ui.Context.js
Modified: trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js
2012-03-12 21:46:36 UTC (rev 113673)
+++ trunk/extensions/VisualEditor/modules/ve/ce/ve.ce.Surface.js
2012-03-12 21:50:22 UTC (rev 113674)
@@ -17,6 +17,7 @@
// Properties
this.model = model;
+ this.currentSelection = new ve.Range();
this.documentView = new ve.ce.DocumentNode( this.model.getDocument(),
this );
this.contextView = null;
this.$ = $container
@@ -79,6 +80,18 @@
'compositionStart': null,
'compositionEnd': null
};
+
+ this.model.on( 'select', function( selection ) {
+ // Keep a copy of the current selection on hand
+ _this.currentSelection = selection.clone();
+ // Respond to selection changes
+ _this.updateSelection();
+ if ( selection.getLength() ) {
+ _this.clearInsertionAnnotations();
+ } else {
+ _this.loadInsertionAnnotations();
+ }
+ } );
};
/* Methods */
@@ -242,6 +255,31 @@
return this.model;
};
+ve.ce.Surface.prototype.updateSelection = function( delay ) {
+ var _this = this;
+ function update() {
+ if ( _this.currentSelection.getLength() ) {
+ _this.clearInsertionAnnotations();
+ }
+ if ( _this.contextView ) {
+ if ( _this.currentSelection.getLength() ) {
+ _this.contextView.set();
+ } else {
+ _this.contextView.clear();
+ }
+ }
+ _this.updateSelectionTimeout = undefined;
+ }
+ if ( delay ) {
+ if ( this.updateSelectionTimeout !== undefined ) {
+ return;
+ }
+ this.updateSelectionTimeout = setTimeout( update, delay );
+ } else {
+ update();
+ }
+};
+
ve.ce.Surface.prototype.documentOnFocus = function() {
this.startPolling();
};
@@ -517,6 +555,11 @@
}
};
+ve.ce.Surface.prototype.getSelectionRect = function() {
+ var sel = rangy.getSelection();
+ return sel.getBoundingClientRect();
+};
+
ve.ce.Surface.prototype.getDOMNodeAndOffset = function( offset ) {
var $node = this.documentView.getNodeFromOffset( offset ).$,
nodeOffset = this.documentView.getOffsetFromNode(
$node.data('view') ) + 1,
@@ -579,6 +622,8 @@
range.setStart( start.node, start.offset );
range.setEnd( stop.node, stop.offset );
sel.setSingleRange( range );
+ // Trigger select event
+ this.model.select( this.getSelectionRange() );
};
ve.ce.Surface.prototype.getLeafNode = function( elem ) {
Modified: trunk/extensions/VisualEditor/modules/ve/ui/ve.ui.Context.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ui/ve.ui.Context.js
2012-03-12 21:46:36 UTC (rev 113673)
+++ trunk/extensions/VisualEditor/modules/ve/ui/ve.ui.Context.js
2012-03-12 21:50:22 UTC (rev 113674)
@@ -95,6 +95,9 @@
var selection = this.surfaceView.getModel().getSelection(),
offset;
this.position = null;
+
+ console.log( this.surfaceView.getSelectionRect() );
+
if ( selection.from < selection.to ) {
var $lastRange = this.surfaceView.$.find(
'.es-contentView-range:visible:last' );
if ( $lastRange.length ) {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs