jenkins-bot has submitted this change and it was merged.

Change subject: Add href and target API to OO.ui.ButtonWidget
......................................................................


Add href and target API to OO.ui.ButtonWidget

Changes:
* Support changing the href and target of a button through methods

Change-Id: I8b9d73fd0e8d217068d78d760343e25bcdcec96e
---
M src/widgets/ButtonWidget.js
1 file changed, 66 insertions(+), 5 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/widgets/ButtonWidget.js b/src/widgets/ButtonWidget.js
index 8a14a53..0d94944 100644
--- a/src/widgets/ButtonWidget.js
+++ b/src/widgets/ButtonWidget.js
@@ -12,7 +12,6 @@
  *
  * @constructor
  * @param {Object} [config] Configuration options
- * @cfg {string} [title=''] Title text
  * @cfg {string} [href] Hyperlink to visit when clicked
  * @cfg {string} [target] Target to open hyperlink in
  */
@@ -32,7 +31,9 @@
        OO.ui.FlaggableElement.call( this, config );
 
        // Properties
-       this.isHyperlink = typeof config.href === 'string';
+       this.href = null;
+       this.target = null;
+       this.isHyperlink = false;
 
        // Events
        this.$button.on( {
@@ -41,12 +42,12 @@
        } );
 
        // Initialization
-       this.$button
-               .append( this.$icon, this.$label, this.$indicator )
-               .attr( { 'href': config.href, 'target': config.target } );
+       this.$button.append( this.$icon, this.$label, this.$indicator );
        this.$element
                .addClass( 'oo-ui-buttonWidget' )
                .append( this.$button );
+       this.setHref( config.href );
+       this.setTarget( config.target );
 };
 
 /* Setup */
@@ -98,3 +99,63 @@
        }
        return false;
 };
+
+/**
+ * Get hyperlink location.
+ *
+ * @return {string} Hyperlink location
+ */
+OO.ui.ButtonWidget.prototype.getHref = function () {
+       return this.href;
+};
+
+/**
+ * Get hyperlink target.
+ *
+ * @return {string} Hyperlink target
+ */
+OO.ui.ButtonWidget.prototype.getTarget = function () {
+       return this.target;
+};
+
+/**
+ * Set hyperlink location.
+ *
+ * @param {string|null} href Hyperlink location, null to remove
+ */
+OO.ui.ButtonWidget.prototype.setHref = function ( href ) {
+       href = typeof href === 'string' ? href : null;
+
+       if ( href !== this.href ) {
+               this.href = href;
+               if ( href !== null ) {
+                       this.$button.attr( 'href', href );
+                       this.isHyperlink = true;
+               } else {
+                       this.$button.removeAttr( 'href' );
+                       this.isHyperlink = false;
+               }
+       }
+
+       return this;
+};
+
+/**
+ * Set hyperlink target.
+ *
+ * @param {string|null} target Hyperlink target, null to remove
+ */
+OO.ui.ButtonWidget.prototype.setTarget = function ( target ) {
+       target = typeof target === 'string' ? target : null;
+
+       if ( target !== this.target ) {
+               this.target = target;
+               if ( target !== null ) {
+                       this.$button.attr( 'target', target );
+               } else {
+                       this.$button.removeAttr( 'target' );
+               }
+       }
+
+       return this;
+};

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8b9d73fd0e8d217068d78d760343e25bcdcec96e
Gerrit-PatchSet: 8
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Trevor Parscal <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to