[PATCH 05 of 19] autocomplete: factor out _gravatar function

Thomas De Schampheleire patrickdepinguin at gmail.com
Tue Jun 30 16:43:15 EDT 2015


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1435259746 -7200
#      Thu Jun 25 21:15:46 2015 +0200
# Node ID c3e99ca8affe70759f62658cdbc248eda297ae8f
# Parent  e929bdac2f7c78849cb649279dfe93ae4761f52c
autocomplete: factor out _gravatar function

(including rename of input arguments, and simpler return)

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
@@ -1151,6 +1151,17 @@ var autocompleteHighlightMatch = functio
     + "</span>" + full.substring(matchindex + snippet.length);
 };
 
+var autocompleteGravatar = function(res, link, size, group) {
+    var elem = '<img alt="gravatar" class="perm-gravatar-ac" style="width: {0}px; height: {0}px" src="{1}"/>'.format(size, link);
+    if (!link) {
+        elem = '<i class="icon-user perm-gravatar-ac" style="font-size: {0}px;"></i>'.format(size);
+    }
+    if (group !== undefined) {
+        elem = '<i class="perm-gravatar-ac icon-users"></i>';
+    }
+    return '<div class="ac-container-wrap">{0}{1}</div>'.format(elem, res);
+}
+
 var _MembersAutoComplete = function (divid, cont, users_list, groups_list) {
 
     var matchUsers = function (sQuery) {
@@ -1196,17 +1207,6 @@ var _MembersAutoComplete = function (div
     // Custom formatter to highlight the matching letters
     var custom_formatter = function (oResultData, sQuery, sResultMatch) {
             var query = sQuery.toLowerCase();
-            var _gravatar = function(res, em, size, group){
-                var elem = '<img alt="gravatar" class="perm-gravatar-ac" style="width: {0}px; height: {0}px" src="{1}"/>'.format(size, em);
-                if (!em) {
-                    elem = '<i class="icon-user perm-gravatar-ac" style="font-size: {0}px;"></i>'.format(size);
-                }
-                if (group !== undefined){
-                    elem = '<i class="perm-gravatar-ac icon-users"></i>'
-                }
-                var tmpl = '<div class="ac-container-wrap">{0}{1}</div>'
-                return tmpl.format(elem,res)
-            }
             // group
             if (oResultData.grname != undefined) {
                 var grname = oResultData.grname;
@@ -1217,9 +1217,9 @@ var _MembersAutoComplete = function (div
                 var grsuffix = " ({0}  {1})".format(grmembers, _TM['members']);
 
                 if (grnameMatchIndex > -1) {
-                    return _gravatar(grprefix + autocompleteHighlightMatch(grname, query, grnameMatchIndex) + grsuffix,null,null,true);
+                    return autocompleteGravatar(grprefix + autocompleteHighlightMatch(grname, query, grnameMatchIndex) + grsuffix, null, null, true);
                 }
-                return _gravatar(grprefix + oResultData.grname + grsuffix, null, null, true);
+                return autocompleteGravatar(grprefix + oResultData.grname + grsuffix, null, null, true);
             // Users
             } else if (oResultData.nname != undefined) {
                 var fname = oResultData.fname || "";
@@ -1250,7 +1250,7 @@ var _MembersAutoComplete = function (div
                     displaynname = nname ? "(" + nname + ")" : "";
                 }
 
-                return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk, oResultData.gravatar_size);
+                return autocompleteGravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk, oResultData.gravatar_size);
             } else {
                 return '';
             }
@@ -1323,17 +1323,6 @@ var MentionsAutoComplete = function (div
             }
 
             var query = sQuery.toLowerCase();
-            var _gravatar = function(res, em, size, group){
-                var elem = '<img alt="gravatar" class="perm-gravatar-ac" style="width: {0}px; height: {0}px" src="{1}"/>'.format(size, em);
-                if (!em) {
-                    elem = '<i class="icon-user perm-gravatar-ac" style="font-size: {0}px;"></i>'.format(size);
-                }
-                if (group !== undefined){
-                    elem = '<i class="perm-gravatar-ac icon-users"></i>'
-                }
-                var tmpl = '<div class="ac-container-wrap">{0}{1}</div>'
-                return tmpl.format(elem,res)
-            }
             if (oResultData.nname != undefined) {
                 var fname = oResultData.fname || "";
                 var lname = oResultData.lname || "";
@@ -1363,7 +1352,7 @@ var MentionsAutoComplete = function (div
                     displaynname = nname ? "(" + nname + ")" : "";
                 }
 
-                return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk, oResultData.gravatar_size);
+                return autocompleteGravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk, oResultData.gravatar_size);
             } else {
                 return '';
             }
@@ -1514,17 +1503,6 @@ var PullRequestAutoComplete = function (
             }
 
             var query = sQuery.toLowerCase();
-            var _gravatar = function(res, em, size, group){
-                var elem = '<img alt="gravatar" class="perm-gravatar-ac" style="width: {0}px; height: {0}px" src="{1}"/>'.format(size, em);
-                if (!em) {
-                    elem = '<i class="icon-user perm-gravatar-ac" style="font-size: {0}px;"></i>'.format(size);
-                }
-                if (group !== undefined){
-                    elem = '<i class="perm-gravatar-ac icon-users"></i>'
-                }
-                var tmpl = '<div class="ac-container-wrap">{0}{1}</div>'
-                return tmpl.format(elem,res)
-            }
             if (oResultData.nname != undefined) {
                 var fname = oResultData.fname || "";
                 var lname = oResultData.lname || "";
@@ -1554,7 +1532,7 @@ var PullRequestAutoComplete = function (
                     displaynname = nname ? "(" + nname + ")" : "";
                 }
 
-                return _gravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk, oResultData.gravatar_size);
+                return autocompleteGravatar(displayfname + " " + displaylname + " " + displaynname, oResultData.gravatar_lnk, oResultData.gravatar_size);
             } else {
                 return '';
             }


More information about the kallithea-general mailing list