Trevor Parscal has uploaded a new change for review.
https://gerrit.wikimedia.org/r/197799
Change subject: Move click blocking from links to content branches
......................................................................
Move click blocking from links to content branches
The click handlers bound in the constructor of ve.ce.LinkAnnotation objects
were never being unbound because there is no explicit destroy call for
Annotation nodes.
By handling the click events at the ContentBranchNode level we can unbind them
easily.
Bug: T91336
Change-Id: Iaca462499fc50860b8c2bddf43339cc29e2c966d
---
M src/ce/annotations/ve.ce.LinkAnnotation.js
M src/ce/ve.ce.ContentBranchNode.js
2 files changed, 28 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor
refs/changes/99/197799/1
diff --git a/src/ce/annotations/ve.ce.LinkAnnotation.js
b/src/ce/annotations/ve.ce.LinkAnnotation.js
index d7a0ac4..53c1eac 100644
--- a/src/ce/annotations/ve.ce.LinkAnnotation.js
+++ b/src/ce/annotations/ve.ce.LinkAnnotation.js
@@ -18,20 +18,12 @@
// Parent constructor
ve.ce.LinkAnnotation.super.apply( this, arguments );
- // DOM changes
+ // Initialization
this.$element
.addClass( 've-ce-linkAnnotation' )
.prop( {
href: ve.resolveUrl( this.model.getHref(),
this.getModelHtmlDocument() ),
title: this.constructor.static.getDescription(
this.model )
- } )
- // Some browsers will try to let links do their thing
- // (e.g. iOS Safari when the keyboard is closed)
- .on( 'click', function ( e ) {
- // Don't prevent a modified click which in some
browsers deliberately opens the link
- if ( !e.altKey && !e.ctrlKey && !e.metaKey &&
!e.shiftKey ) {
- e.preventDefault();
- }
} );
};
diff --git a/src/ce/ve.ce.ContentBranchNode.js
b/src/ce/ve.ce.ContentBranchNode.js
index 766bae9..6712a73 100644
--- a/src/ce/ve.ce.ContentBranchNode.js
+++ b/src/ce/ve.ce.ContentBranchNode.js
@@ -24,9 +24,13 @@
this.rendered = false;
this.unicornAnnotations = null;
this.unicorns = null;
+ this.onClickHandler = this.onClick.bind( this );
// Events
this.connect( this, { childUpdate: 'onChildUpdate' } );
+ // Some browsers allow clicking links inside contenteditable, such as
in iOS Safari when the
+ // keyboard is closed
+ this.$element.on( 'click', this.onClickHandler );
};
/* Inheritance */
@@ -75,6 +79,22 @@
};
/* Methods */
+
+/**
+ * Handle click events.
+ *
+ * @param {Event} e Click event
+ */
+ve.ce.ContentBranchNode.prototype.onClick = function ( e ) {
+ if (
+ // Only block clicks on links
+ ( e.target !== this.$element[0] &&
e.target.nodeName.toUpperCase() === 'A' ) &&
+ // Don't prevent a modified click, which in some browsers
deliberately opens the link
+ ( !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey )
+ ) {
+ e.preventDefault();
+ }
+};
/**
* Handle splice events.
@@ -414,3 +434,10 @@
ceSurface.setNotUnicorning( this );
};
+
+/**
+ * @inheritdoc
+ */
+ve.ce.ContentBranchNode.prototype.destroy = function () {
+ this.$element.off( 'click', this.onClickHandler );
+};
--
To view, visit https://gerrit.wikimedia.org/r/197799
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaca462499fc50860b8c2bddf43339cc29e2c966d
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits