DLynch has uploaded a new change for review.

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

Change subject: AnnotationContextItem: refactor applying a change to the 
annotation
......................................................................

AnnotationContextItem: refactor applying a change to the annotation

Allows for easier extension of the context item, since lots of possible
actions boil down to "do X to the related annotation".

Change-Id: Ia868ffc44096ec808c7443c40784eee8783fcbbb
---
M src/ui/contextitems/ve.ui.AnnotationContextItem.js
1 file changed, 12 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/17/276517/1

diff --git a/src/ui/contextitems/ve.ui.AnnotationContextItem.js 
b/src/ui/contextitems/ve.ui.AnnotationContextItem.js
index ff8c75e..1734750 100644
--- a/src/ui/contextitems/ve.ui.AnnotationContextItem.js
+++ b/src/ui/contextitems/ve.ui.AnnotationContextItem.js
@@ -70,6 +70,17 @@
  * @protected
  */
 ve.ui.AnnotationContextItem.prototype.onClearButtonClick = function () {
+       this.applyToAnnotations( function ( fragment, annotation ) {
+               fragment.annotateContent( 'clear', annotation );
+       } );
+};
+
+/**
+ * Apply a callback to every modelClass annotation in the current fragment
+ *
+ * @param  {Function} callback Callback, will be passed fragment and annotation
+ */
+ve.ui.AnnotationContextItem.prototype.applyToAnnotations = function ( callback 
) {
        var i, len,
                modelClasses = this.constructor.static.modelClasses,
                fragment = this.getFragment(),
@@ -89,6 +100,6 @@
                } ).get();
        }
        for ( i = 0, len = annotations.length; i < len; i++ ) {
-               fragment.expandLinearSelection( 'annotation', annotations[ i ] 
).annotateContent( 'clear', annotations[ i ] );
+               callback( fragment.expandLinearSelection( 'annotation', 
annotations[ i ] ), annotations[ i ] );
        }
 };

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia868ffc44096ec808c7443c40784eee8783fcbbb
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: DLynch <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to