[PATCH 14 of 19] autocomplete: misc cleanup

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


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1435692456 -7200
#      Tue Jun 30 21:27:36 2015 +0200
# Node ID 88065e9e70e233fc2232ffeeaafadaee2698b766
# Parent  f1d674589538cbf1c6d066b203016009d7c679b2
autocomplete: misc cleanup

Some miscellaneous changes that didn't really fit in the previous patches:
- clarification of variable names
- removal of unnecessary underscore in MembersAutoComplete
- avoid hardcoded div specifications

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
@@ -1236,13 +1236,13 @@ var autocompleteCreate = function (input
     return autocomplete;
 }
 
-var SimpleUserAutoComplete = function (divid, cont, users_list) {
+var SimpleUserAutoComplete = function (inputElement, container, users_list) {
 
     var matchUsers = function (sQuery) {
         return autocompleteMatchUsers(sQuery, users_list);
     }
 
-    var userAC = autocompleteCreate(divid, cont, matchUsers);
+    var userAC = autocompleteCreate(inputElement, container, matchUsers);
 
     // Handler for selection of an entry
     var itemSelectHandler = function (sType, aArgs) {
@@ -1254,7 +1254,7 @@ var SimpleUserAutoComplete = function (d
     userAC.itemSelectEvent.subscribe(itemSelectHandler);
 }
 
-var _MembersAutoComplete = function (divid, cont, users_list, groups_list) {
+var MembersAutoComplete = function (inputElement, container, users_list, groups_list) {
 
     var matchAll = function (sQuery) {
         var u = autocompleteMatchUsers(sQuery, users_list);
@@ -1262,11 +1262,11 @@ var _MembersAutoComplete = function (div
         return u.concat(g);
     };
 
-    var membersAC = autocompleteCreate(divid, cont, matchAll);
+    var membersAC = autocompleteCreate(inputElement, container, matchAll);
 
     // Handler for selection of an entry
     var itemSelectHandler = function (sType, aArgs) {
-        var nextId = divid.split('perm_new_member_name_')[1];
+        var nextId = inputElement.split('perm_new_member_name_')[1];
         var myAC = aArgs[0]; // reference back to the AC instance
         var elLI = aArgs[1]; // reference to the selected LI element
         var oData = aArgs[2]; // object literal of selected item's result data
@@ -1284,7 +1284,7 @@ var _MembersAutoComplete = function (div
     membersAC.itemSelectEvent.subscribe(itemSelectHandler);
 }
 
-var MentionsAutoComplete = function (divid, cont, users_list) {
+var MentionsAutoComplete = function (inputElement, container, users_list) {
 
     var matchUsers = function (sQuery) {
             var org_sQuery = sQuery;
@@ -1295,7 +1295,7 @@ var MentionsAutoComplete = function (div
             return autocompleteMatchUsers(sQuery, users_list);
     }
 
-    var mentionsAC = autocompleteCreate(divid, cont, matchUsers);
+    var mentionsAC = autocompleteCreate(inputElement, container, matchUsers);
     mentionsAC.suppressInputUpdate = true;
     // Overwrite formatResult to take into account mentionQuery
     mentionsAC.formatResult = function (oResultData, sQuery, sResultMatch) {
@@ -1354,10 +1354,10 @@ var MentionsAutoComplete = function (div
         return [null, null];
     };
 
-    var $divid = $('#'+divid);
-    $divid.keyup(function(e){
-            var currentMessage = $divid.val();
-            var currentCaretPosition = $divid[0].selectionStart;
+    var $inputElement = $('#'+inputElement);
+    $inputElement.keyup(function(e){
+            var currentMessage = $inputElement.val();
+            var currentCaretPosition = $inputElement[0].selectionStart;
 
             var unam = mentionsAC.get_mention(currentMessage, currentCaretPosition);
             var curr_search = null;
@@ -1410,13 +1410,13 @@ var removeReviewMember = function(review
 }
 
 /* activate auto completion of users as PR reviewers */
-var PullRequestAutoComplete = function (divid, cont, users_list) {
+var PullRequestAutoComplete = function (inputElement, container, users_list) {
 
     var matchUsers = function (sQuery) {
         return autocompleteMatchUsers(sQuery, users_list);
     };
 
-    var reviewerAC = autocompleteCreate(divid, cont, matchUsers);
+    var reviewerAC = autocompleteCreate(inputElement, container, matchUsers);
     reviewerAC.suppressInputUpdate = true;
 
     // Handler for selection of an entry
@@ -1427,7 +1427,7 @@ var PullRequestAutoComplete = function (
 
         addReviewMember(oData.id, oData.fname, oData.lname, oData.nname,
                         oData.gravatar_lnk, oData.gravatar_size);
-        $('#user').val('');
+        myAC.getInputEl().value = '';
     });
 }
 
@@ -1496,7 +1496,7 @@ var addPermAction = function(_html, user
     var $last_node = $('.last_new_member').last(); // empty tr between last and add
     var next_id = $('.new_members').length;
     $last_node.before($('<tr class="new_members">').append(_html.format(next_id)));
-    _MembersAutoComplete("perm_new_member_name_"+next_id,
+    MembersAutoComplete("perm_new_member_name_"+next_id,
             "perm_container_"+next_id, users_list, groups_list);
 }
 


More information about the kallithea-general mailing list