[PATCH 04 of 19] autocomplete: factor out highlightMatch function
Thomas De Schampheleire
patrickdepinguin at gmail.com
Tue Jun 30 16:43:14 EDT 2015
# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1435259401 -7200
# Thu Jun 25 21:10:01 2015 +0200
# Node ID e929bdac2f7c78849cb649279dfe93ae4761f52c
# Parent fca74929123428f02ade6d63c3f368368128619d
autocomplete: factor out highlightMatch function
diff --git a/kallithea/public/js/base.js b/kallithea/public/js/base.js
--- a/kallithea/public/js/base.js
+++ b/kallithea/public/js/base.js
@@ -1143,6 +1143,14 @@ var autocompleteMatchGroups = function (
return matches;
};
+// Helper highlight function for the formatter
+var autocompleteHighlightMatch = function (full, snippet, matchindex) {
+ return full.substring(0, matchindex)
+ + "<span class='match'>"
+ + full.substr(matchindex, snippet.length)
+ + "</span>" + full.substring(matchindex + snippet.length);
+};
+
var _MembersAutoComplete = function (divid, cont, users_list, groups_list) {
var matchUsers = function (sQuery) {
@@ -1185,14 +1193,6 @@ var _MembersAutoComplete = function (div
ownerAC.animHoriz = false;
ownerAC.animSpeed = 0.1;
- // Helper highlight function for the formatter
- var highlightMatch = function (full, snippet, matchindex) {
- return full.substring(0, matchindex)
- + "<span class='match'>"
- + full.substr(matchindex, snippet.length)
- + "</span>" + full.substring(matchindex + snippet.length);
- };
-
// Custom formatter to highlight the matching letters
var custom_formatter = function (oResultData, sQuery, sResultMatch) {
var query = sQuery.toLowerCase();
@@ -1217,7 +1217,7 @@ var _MembersAutoComplete = function (div
var grsuffix = " ({0} {1})".format(grmembers, _TM['members']);
if (grnameMatchIndex > -1) {
- return _gravatar(grprefix + highlightMatch(grname, query, grnameMatchIndex) + grsuffix,null,null,true);
+ return _gravatar(grprefix + autocompleteHighlightMatch(grname, query, grnameMatchIndex) + grsuffix,null,null,true);
}
return _gravatar(grprefix + oResultData.grname + grsuffix, null, null, true);
// Users
@@ -1233,19 +1233,19 @@ var _MembersAutoComplete = function (div
displayfname, displaylname, displaynname;
if (fnameMatchIndex > -1) {
- displayfname = highlightMatch(fname, query, fnameMatchIndex);
+ displayfname = autocompleteHighlightMatch(fname, query, fnameMatchIndex);
} else {
displayfname = fname;
}
if (lnameMatchIndex > -1) {
- displaylname = highlightMatch(lname, query, lnameMatchIndex);
+ displaylname = autocompleteHighlightMatch(lname, query, lnameMatchIndex);
} else {
displaylname = lname;
}
if (nnameMatchIndex > -1) {
- displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")";
+ displaynname = "(" + autocompleteHighlightMatch(nname, query, nnameMatchIndex) + ")";
} else {
displaynname = nname ? "(" + nname + ")" : "";
}
@@ -1315,14 +1315,6 @@ var MentionsAutoComplete = function (div
ownerAC.animHoriz = false;
ownerAC.animSpeed = 0.1;
- // Helper highlight function for the formatter
- var highlightMatch = function (full, snippet, matchindex) {
- return full.substring(0, matchindex)
- + "<span class='match'>"
- + full.substr(matchindex, snippet.length)
- + "</span>" + full.substring(matchindex + snippet.length);
- };
-
// Custom formatter to highlight the matching letters
ownerAC.formatResult = function (oResultData, sQuery, sResultMatch) {
var org_sQuery = sQuery;
@@ -1354,19 +1346,19 @@ var MentionsAutoComplete = function (div
displayfname, displaylname, displaynname;
if (fnameMatchIndex > -1) {
- displayfname = highlightMatch(fname, query, fnameMatchIndex);
+ displayfname = autocompleteHighlightMatch(fname, query, fnameMatchIndex);
} else {
displayfname = fname;
}
if (lnameMatchIndex > -1) {
- displaylname = highlightMatch(lname, query, lnameMatchIndex);
+ displaylname = autocompleteHighlightMatch(lname, query, lnameMatchIndex);
} else {
displaylname = lname;
}
if (nnameMatchIndex > -1) {
- displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")";
+ displaynname = "(" + autocompleteHighlightMatch(nname, query, nnameMatchIndex) + ")";
} else {
displaynname = nname ? "(" + nname + ")" : "";
}
@@ -1514,14 +1506,6 @@ var PullRequestAutoComplete = function (
reviewerAC.animHoriz = false;
reviewerAC.animSpeed = 0.1;
- // Helper highlight function for the formatter
- var highlightMatch = function (full, snippet, matchindex) {
- return full.substring(0, matchindex)
- + "<span class='match'>"
- + full.substr(matchindex, snippet.length)
- + "</span>" + full.substring(matchindex + snippet.length);
- };
-
// Custom formatter to highlight the matching letters
reviewerAC.formatResult = function (oResultData, sQuery, sResultMatch) {
var org_sQuery = sQuery;
@@ -1553,19 +1537,19 @@ var PullRequestAutoComplete = function (
displayfname, displaylname, displaynname;
if (fnameMatchIndex > -1) {
- displayfname = highlightMatch(fname, query, fnameMatchIndex);
+ displayfname = autocompleteHighlightMatch(fname, query, fnameMatchIndex);
} else {
displayfname = fname;
}
if (lnameMatchIndex > -1) {
- displaylname = highlightMatch(lname, query, lnameMatchIndex);
+ displaylname = autocompleteHighlightMatch(lname, query, lnameMatchIndex);
} else {
displaylname = lname;
}
if (nnameMatchIndex > -1) {
- displaynname = "(" + highlightMatch(nname, query, nnameMatchIndex) + ")";
+ displaynname = "(" + autocompleteHighlightMatch(nname, query, nnameMatchIndex) + ")";
} else {
displaynname = nname ? "(" + nname + ")" : "";
}
More information about the kallithea-general
mailing list