Bartosz Dziewoński has uploaded a new change for review.

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

Change subject: Element: Add support for 'id' config option
......................................................................

Element: Add support for 'id' config option

I am not sure if this is a good idea. Probably isn't. Still, throwing
it out there. Has its use cases.

Change-Id: Iccbfb5ff18180961406828a39f3097eed7c963c1
---
M php/Element.php
M src/Element.js
2 files changed, 8 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/oojs/ui refs/changes/44/183744/1

diff --git a/php/Element.php b/php/Element.php
index be094f4..35ab53a 100644
--- a/php/Element.php
+++ b/php/Element.php
@@ -43,6 +43,7 @@
        /**
         * @param array $config Configuration options
         * @param string[] $config['classes'] CSS class names to add
+        * @param string $config['id'] HTML id attribute
         * @param array $config['content'] Content to append, strings or 
Element objects. Strings will
         *   be HTML-escaped for output, use a HtmlSnippet instance to prevent 
that.
         */
@@ -54,6 +55,9 @@
                if ( isset( $config['classes'] ) && is_array( 
$config['classes'] ) ) {
                        $this->addClasses( $config['classes'] );
                }
+               if ( isset( $config['id'] ) ) {
+                       $this->setAttributes( array( 'id' => $config['id'] ) );
+               }
                if ( isset( $config['content'] ) ) {
                        $this->appendContent( $config['content'] );
                }
diff --git a/src/Element.js b/src/Element.js
index e766b54..02f7127 100644
--- a/src/Element.js
+++ b/src/Element.js
@@ -8,6 +8,7 @@
  * @param {Object} [config] Configuration options
  * @cfg {Function} [$] jQuery for the frame the widget is in
  * @cfg {string[]} [classes] CSS class names to add
+ * @cfg {string} [id] HTML id attribute
  * @cfg {string} [text] Text to insert
  * @cfg {jQuery} [$content] Content elements to append (after text)
  * @cfg {Mixed} [data] Element data
@@ -28,6 +29,9 @@
        if ( $.isArray( config.classes ) ) {
                this.$element.addClass( config.classes.join( ' ' ) );
        }
+       if ( config.id ) {
+               this.$element.attr( 'id', config.id );
+       }
        if ( config.text ) {
                this.$element.text( config.text );
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iccbfb5ff18180961406828a39f3097eed7c963c1
Gerrit-PatchSet: 1
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

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

Reply via email to