Mooeypoo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/95560


Change subject: [WIP] Add direction classes to Toolbar based on context
......................................................................

[WIP] Add direction classes to Toolbar based on context

Add rtl/ltr-related classes to the toolbar based on cursor context, so
certain icons can change based on inline and block directions.

Change-Id: I1b6e450226bf8da820fb622f28c1c3062c534bb0
---
M modules/ve/ui/ve.ui.Toolbar.js
1 file changed, 47 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor 
refs/changes/60/95560/1

diff --git a/modules/ve/ui/ve.ui.Toolbar.js b/modules/ve/ui/ve.ui.Toolbar.js
index b97ed85..3a7296f 100644
--- a/modules/ve/ui/ve.ui.Toolbar.js
+++ b/modules/ve/ui/ve.ui.Toolbar.js
@@ -49,7 +49,11 @@
                        return toolbar.onSurfaceViewKeyUp.apply( toolbar, 
arguments );
                }
        };
-
+       // default directions:
+       this.contextDirection = { 'inline': 'ltr', 'block': 'ltr' };
+       this.$element
+               .addClass( 've-ui-dir-inline-' + this.contextDirection.inline )
+               .addClass( 've-ui-dir-block-' + this.contextDirection.block );
        // Events
        this.surface.getModel().connect( this, { 'contextChange': 
'onContextChange' } );
        this.surface.connect( this, { 'addCommand': 'onSurfaceAddCommand' } );
@@ -152,8 +156,15 @@
  * @fires updateState
  */
 ve.ui.Toolbar.prototype.onContextChange = function () {
-       var i, len, leafNodes,
+       var i, len, leafNodes, dirInline, dirBlock, fragmentAnnotation,
+               currentNodes = {
+                       fragNodes: null,
+                       fragAnnotations: null,
+                       'dm': {},
+                       'ce': {}
+               },
                fragment = this.surface.getModel().getFragment( null, false ),
+               doc = this.surface.getView().getDocument(),
                nodes = [];
 
        leafNodes = fragment.getLeafNodes();
@@ -162,6 +173,40 @@
                        nodes.push( leafNodes[i].node );
                }
        }
+       // Update context direction for button icons UI:
+
+       // block direction (direction of the current node)
+       currentNodes.fragNodes = fragment.getCoveredNodes();
+       if ( currentNodes.fragNodes.length > 1 ) {
+               // selection of multiple nodes
+               currentNodes.dm.block = 
fragment.getSiblingNodes()[0].node.parent;
+       } else {
+               // selection of a single node
+               currentNodes.dm.block = currentNodes.fragNodes[0].node;
+       }
+       // get the direction of the block:
+       currentNodes.ce.block = doc.getNodeFromOffset( 
currentNodes.dm.block.getOffset() );
+       dirBlock = currentNodes.ce.block.$element.css( 'direction' );
+
+       // 'inline' direction is set by language annotation:
+       fragmentAnnotation = fragment.getAnnotations();
+       if ( fragmentAnnotation.hasAnnotationWithName( 'meta/language' ) ) {
+               dirInline = fragmentAnnotation.getAnnotationsByName( 
'meta/language' ).get()[0].getAttribute( 'dir' );
+       } else {
+               dirInline = dirBlock;
+       }
+
+       if ( dirInline !== this.contextDirection.inline ) {
+               // remove previous class:
+               this.$element.removeClass( 've-ui-dir-inline-rtl 
ve-ui-dir-inline-ltr' );
+               this.$element.addClass( 've-ui-dir-inline-' + dirInline );
+               this.contextDirection.inline = dirInline;
+       }
+       if ( dirBlock !== this.contextDirection.block ) {
+               this.$element.removeClass( 've-ui-dir-block-rtl 
ve-ui-dir-block-ltr' );
+               this.$element.addClass( 've-ui-dir-block-' + dirBlock );
+               this.contextDirection.block = dirBlock;
+       }
        this.emit( 'updateState', nodes, fragment.getAnnotations(), 
fragment.getAnnotations( true ) );
 };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/95560
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1b6e450226bf8da820fb622f28c1c3062c534bb0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Mooeypoo <mor...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to