Prtksxna has uploaded a new change for review.
https://gerrit.wikimedia.org/r/268076
Change subject: CapsuleWidgets: Edit on click and remove on Ctrl+Backspace
......................................................................
CapsuleWidgets: Edit on click and remove on Ctrl+Backspace
This will sort of break the CategorySelector in core as those capsules
have clickable links inside them.
Bug: T119046
Change-Id: Iefb41fd8ee22be2160079b7ada79186e2b2cbc4d
---
M src/widgets/CapsuleItemWidget.js
M src/widgets/CapsuleMultiSelectWidget.js
2 files changed, 20 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/76/268076/1
diff --git a/src/widgets/CapsuleItemWidget.js b/src/widgets/CapsuleItemWidget.js
index 628bed2..9cab5ef 100644
--- a/src/widgets/CapsuleItemWidget.js
+++ b/src/widgets/CapsuleItemWidget.js
@@ -35,6 +35,7 @@
// Initialization
this.$element
+ .on( 'click', this.onClick.bind( this ) )
.addClass( 'oo-ui-capsuleItemWidget' )
.append( this.$label, this.closeButton.$element );
};
@@ -59,3 +60,14 @@
element.focus();
}
};
+
+/**
+ * Handle click event for the entire capsule
+ */
+OO.ui.CapsuleItemWidget.prototype.onClick = function () {
+ var element = this.getElementGroup();
+
+ if ( !this.isDisabled() && element && $.isFunction( element.editItem )
) {
+ element.editItem( this );
+ }
+};
diff --git a/src/widgets/CapsuleMultiSelectWidget.js
b/src/widgets/CapsuleMultiSelectWidget.js
index a1f09e0..13d8238 100644
--- a/src/widgets/CapsuleMultiSelectWidget.js
+++ b/src/widgets/CapsuleMultiSelectWidget.js
@@ -514,8 +514,14 @@
OO.ui.CapsuleMultiSelectWidget.prototype.onKeyDown = function ( e ) {
if ( !this.isDisabled() ) {
// 'keypress' event is not triggered for Backspace
- if ( e.keyCode === OO.ui.Keys.BACKSPACE && this.$input.val()
=== '' ) {
- if ( this.items.length ) {
+ if (
+ e.keyCode === OO.ui.Keys.BACKSPACE &&
+ this.$input.val() === '' &&
+ this.items.length
+ ) {
+ if ( e.metaKey || e.ctrlKey ) {
+ this.removeItems( this.items.slice( -1 ) );
+ } else {
this.editItem( this.items[ this.items.length -
1 ] );
}
return false;
--
To view, visit https://gerrit.wikimedia.org/r/268076
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iefb41fd8ee22be2160079b7ada79186e2b2cbc4d
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Prtksxna <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits