jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/379778 )

Change subject: Support locale comparison in LabelElement#highlightQuery
......................................................................


Support locale comparison in LabelElement#highlightQuery

Change-Id: I576f31759a84d221d6be8dedbb7660d7a194cce2
---
M src/mixins/LabelElement.js
1 file changed, 18 insertions(+), 4 deletions(-)

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



diff --git a/src/mixins/LabelElement.js b/src/mixins/LabelElement.js
index 8d5f98a..0991d3d 100644
--- a/src/mixins/LabelElement.js
+++ b/src/mixins/LabelElement.js
@@ -61,12 +61,25 @@
  *
  * @param {string} text Text
  * @param {string} query Query to find
+ * @param {Function} [compare] Optional string comparator, e.g. 
Intl.Collator().compare
  * @return {jQuery} Text with the first match of the query
  *  sub-string wrapped in highlighted span
  */
-OO.ui.mixin.LabelElement.static.highlightQuery = function ( text, query ) {
-       var $result = $( '<span>' ),
+OO.ui.mixin.LabelElement.static.highlightQuery = function ( text, query, 
compare ) {
+       var i, offset, tLen, qLen,
+               $result = $( '<span>' );
+
+       if ( compare ) {
+               tLen = text.length;
+               qLen = query.length;
+               for ( i = 0; offset === undefined && i <= tLen - qLen; i++ ) {
+                       if ( compare( query, text.slice( i, i + qLen ) ) === 0 
) {
+                               offset = i;
+                       }
+               }
+       } else {
                offset = text.toLowerCase().indexOf( query.toLowerCase() );
+       }
 
        if ( !query.length || offset === -1 ) {
                return $result.text( text );
@@ -131,10 +144,11 @@
  *
  * @param {string} text Text label to set
  * @param {string} query Substring of text to highlight
+ * @param {Function} [compare] Optional string comparator, e.g. 
Intl.Collator().compare
  * @chainable
  */
-OO.ui.mixin.LabelElement.prototype.setHighlightedQuery = function ( text, 
query ) {
-       return this.setLabel( this.constructor.static.highlightQuery( text, 
query ) );
+OO.ui.mixin.LabelElement.prototype.setHighlightedQuery = function ( text, 
query, compare ) {
+       return this.setLabel( this.constructor.static.highlightQuery( text, 
query, compare ) );
 };
 
 /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I576f31759a84d221d6be8dedbb7660d7a194cce2
Gerrit-PatchSet: 2
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Esanders <esand...@wikimedia.org>
Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org>
Gerrit-Reviewer: VolkerE <volke...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to