From: Moriel Schottlender Date: Wed, 20 Jul 2016 21:15:01 +0000 (-0700) Subject: Allow 'data-*' attributes in personal tools links X-Git-Tag: 1.31.0-rc.0~6301^2 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=88f4eca6d8e6f86764ae9685b9e02ddc9843af12;p=lhc%2Fweb%2Fwiklou.git Allow 'data-*' attributes in personal tools links We are limiting the attributes that are read and rendered for the personal toolbar, but there are cases -- especially as tools get more and more complex -- for needing to supply and read more information. The use case that led to this change is the need to style Notification badges with values in ::before and ::after pseudo-elements; these elements need to display some prefixed content, and the best (only) way to do that in no-js mode, is to set it up in CSS to be read out of an attribute (using attr( xxx ); ). This means that we need to read a specific attribute from the element, but the only attributes allowed were insufficient. Allowing for data-* attributes seemed not only a good solution for this specific case, but a good idea in general for future tools that are added and manipulate the personal toolbar links - allowing for storing information without polluting the DOM. Bug: T115845 Change-Id: Ic666540d70de52f337f839da0518cb83a990f5fd --- diff --git a/includes/skins/BaseTemplate.php b/includes/skins/BaseTemplate.php index 13db176958..71ca57bf09 100644 --- a/includes/skins/BaseTemplate.php +++ b/includes/skins/BaseTemplate.php @@ -140,7 +140,7 @@ abstract class BaseTemplate extends QuickTemplate { if ( isset( $plink['active'] ) ) { $ptool['active'] = $plink['active']; } - foreach ( [ 'href', 'class', 'text', 'dir' ] as $k ) { + foreach ( [ 'href', 'class', 'text', 'dir', 'data' ] as $k ) { if ( isset( $plink[$k] ) ) { $ptool['links'][0][$k] = $plink[$k]; } @@ -318,6 +318,15 @@ abstract class BaseTemplate extends QuickTemplate { * * If you don't want an accesskey, set $item['tooltiponly'] = true; * + * If a "data" key is present, it must be an array, where the keys represent + * the data-xxx properties with their provided values. For example, + * $item['data'] = array( + * 'foo' => 1, + * 'bar' => 'baz', + * ); + * will render as element properties: + * data-foo='1' data-bar='baz' + * * @param array $options Can be used to affect the output of a link. * Possible options are: * - 'text-wrapper' key to specify a list of elements to wrap the text of @@ -363,6 +372,13 @@ abstract class BaseTemplate extends QuickTemplate { unset( $attrs[$k] ); } + if ( isset( $attrs['data'] ) ) { + foreach ( $attrs['data'] as $key => $value ) { + $attrs[ 'data-' . $key ] = $value; + } + unset( $attrs[ 'data' ] ); + } + if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) { $item['single-id'] = $item['id']; }