SuchetaG has uploaded a new change for review.

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

Change subject: Adding the hightlightQuery method as a general utility
......................................................................

Adding the hightlightQuery method as a general utility

Moving the highlightQuery method from LanguageResultWidget to ve.util.js so 
that it can be used as a general utility from now on.
It can therefore be used in highlighting matching parts of link suggestions as 
well.

Change-Id: Ib711bcc1889882cc4ecad4e3aa248bc3993afe51
---
M src/ui/widgets/ve.ui.LanguageResultWidget.js
M src/ve.utils.js
2 files changed, 25 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/09/208309/1

diff --git a/src/ui/widgets/ve.ui.LanguageResultWidget.js 
b/src/ui/widgets/ve.ui.LanguageResultWidget.js
index c7b8c8a..55ecbf6 100644
--- a/src/ui/widgets/ve.ui.LanguageResultWidget.js
+++ b/src/ui/widgets/ve.ui.LanguageResultWidget.js
@@ -46,7 +46,7 @@
 
        // Highlight where applicable
        if ( matchedProperty ) {
-               $highlighted = this.highlightQuery( data[matchedProperty], 
query );
+               $highlighted = new ve.highlightQuery( data[matchedProperty], 
query );
                if ( matchedProperty === 'name' ) {
                        this.$name.empty().append( $highlighted );
                } else {
@@ -55,28 +55,4 @@
        }
 
        return this;
-};
-
-/**
- * Highlight text where a substring query matches
- *
- * @param {string} text Text
- * @param {string} query Query to find
- * @returns {jQuery} Text with query substring wrapped in highlighted span
- */
-ve.ui.LanguageResultWidget.prototype.highlightQuery = function ( text, query ) 
{
-       var $result = $( '<span>' ),
-               offset = text.toLowerCase().indexOf( query.toLowerCase() );
-
-       if ( !query.length || offset === -1 ) {
-               return $result.text( text );
-       }
-       $result.append(
-               document.createTextNode( text.slice( 0, offset ) ),
-               $( '<span>' )
-                       .addClass( 've-ui-languageResultWidget-highlight' )
-                       .text( text.slice( offset, offset + query.length ) ),
-               document.createTextNode( text.slice( offset + query.length ) )
-       );
-       return $result.contents();
 };
diff --git a/src/ve.utils.js b/src/ve.utils.js
index 017e9fe..815346c 100644
--- a/src/ve.utils.js
+++ b/src/ve.utils.js
@@ -1427,3 +1427,27 @@
 ve.getSystemPlatform = function () {
        return ( ve.init.platform && ve.init.platform.constructor || 
ve.init.Platform ).static.getSystemPlatform();
 };
+
+/**
+ * Highlight text where a substring query matches
+ *
+ * @param {string} text Text
+ * @param {string} query Query to find
+ * @returns {jQuery} Text with query substring wrapped in highlighted span
+ */
+ve.ui.LanguageResultWidget.prototype.highlightQuery = function ( text, query ) 
{
+       var $result = $( '<span>' ),
+               offset = text.toLowerCase().indexOf( query.toLowerCase() );
+
+       if ( !query.length || offset === -1 ) {
+               return $result.text( text );
+       }
+       $result.append(
+               document.createTextNode( text.slice( 0, offset ) ),
+               $( '<span>' )
+                       .addClass( 've-ui-languageResultWidget-highlight' )
+                       .text( text.slice( offset, offset + query.length ) ),
+               document.createTextNode( text.slice( offset + query.length ) )
+       );
+       return $result.contents();
+};

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib711bcc1889882cc4ecad4e3aa248bc3993afe51
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: SuchetaG <sucheta.ghos...@gmail.com>

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

Reply via email to