Changeset - bfde3237d6ad
[Not reviewed]
default
0 2 0
Takumi IINO - 10 years ago 2015-11-12 16:22:35
trot.thunder@gmail.com
select2: show prefix matches first in #repo-switcher

Do as 4f4d2e899a02 introduced for the PR/changelog branch select2 boxes.
2 files changed with 32 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/public/js/base.js
Show inline comments
 
@@ -1879,12 +1879,43 @@ var branchSort = function(results, conta
 
            return 0;
 
        });
 
    }
 
    return results;
 
};
 

	
 
var prefixFirstSort = function(results, container, query) {
 
    if (query.term) {
 
        return results.sort(function (a, b) {
 
            // if parent node, no sorting
 
            if (a.children != undefined || b.children != undefined) {
 
                return 0;
 
            }
 

	
 
            // Put prefix matches before matches in the line
 
            var aPos = a.text.toLowerCase().indexOf(query.term.toLowerCase()),
 
                bPos = b.text.toLowerCase().indexOf(query.term.toLowerCase());
 
            if (aPos === 0 && bPos !== 0) {
 
                return -1;
 
            }
 
            if (bPos === 0 && aPos !== 0) {
 
                return 1;
 
            }
 

	
 
            // Default sorting
 
            if (a.text > b.text) {
 
                return 1;
 
            }
 
            if (a.text < b.text) {
 
                return -1;
 
            }
 
            return 0;
 
        });
 
    }
 
    return results;
 
};
 

	
 
// global hooks after DOM is loaded
 

	
 
$(document).ready(function(){
 
    $('.diff-collapse-button').click(function(e) {
 
        var $button = $(e.currentTarget);
 
        var $target = $('#' + $button.prop('target'));
kallithea/templates/base/base.html
Show inline comments
 
@@ -387,12 +387,13 @@
 
                return tmpl;
 
            }
 

	
 
            $("#repo_switcher").select2({
 
                placeholder: '<i class="icon-database"></i> ${_('Repositories')}',
 
                dropdownAutoWidth: true,
 
                sortResults: prefixFirstSort,
 
                formatResult: format,
 
                formatSelection: format,
 
                formatNoMatches: function(term){
 
                    return "${_('No matches found')}";
 
                },
 
                containerCssClass: "repo-switcher",
0 comments (0 inline, 0 general)