Changeset - c7e67b87fd1b
[Not reviewed]
default
0 3 0
Mads Kiilerich - 6 years ago 2020-02-16 02:47:09
mads@kiilerich.com
Grafted from: 6fb85c087de2
js: cleanup to use named functions instead of vars with anonymous functions
3 files changed with 52 insertions and 52 deletions:
0 comments (0 inline, 0 general)
kallithea/public/js/base.js
Show inline comments
 
@@ -350,22 +350,22 @@ var _run_callbacks = function(callbacks)
 
    }
 
}
 

	
 
/**
 
 * turns objects into GET query string
 
 */
 
var _toQueryString = function(o) {
 
function _toQueryString(o) {
 
    if(typeof o !== 'object') {
 
        return false;
 
    }
 
    var _p, _qs = [];
 
    for(_p in o) {
 
        _qs.push(encodeURIComponent(_p) + '=' + encodeURIComponent(o[_p]));
 
    }
 
    return _qs.join('&');
 
};
 
}
 

	
 
/**
 
 * Load HTML into DOM using Ajax
 
 *
 
 * @param $target: load html async and place it (or an error message) here
 
 * @param success: success callback function
 
@@ -392,54 +392,54 @@ function asynchtml(url, $target, success
 
                $target.html('<span class="bg-danger">ERROR: {0}</span>'.format(textStatus));
 
                $target.css('opacity','1.0');
 
            })
 
        ;
 
};
 

	
 
var ajaxGET = function(url, success, failure) {
 
function ajaxGET(url, success, failure) {
 
    if(failure === undefined) {
 
        failure = function(jqXHR, textStatus, errorThrown) {
 
                if (textStatus != "abort")
 
                    alert("Ajax GET error: " + textStatus);
 
            };
 
    }
 
    return $.ajax({url: url, headers: {'X-PARTIAL-XHR': '1'}, cache: false})
 
        .done(success)
 
        .fail(failure);
 
};
 
}
 

	
 
var ajaxPOST = function(url, postData, success, failure) {
 
function ajaxPOST(url, postData, success, failure) {
 
    postData['_session_csrf_secret_token'] = _session_csrf_secret_token;
 
    var postData = _toQueryString(postData);
 
    if(failure === undefined) {
 
        failure = function(jqXHR, textStatus, errorThrown) {
 
                if (textStatus != "abort")
 
                    alert("Error posting to server: " + textStatus);
 
            };
 
    }
 
    return $.ajax({url: url, data: postData, type: 'POST', headers: {'X-PARTIAL-XHR': '1'}, cache: false})
 
        .done(success)
 
        .fail(failure);
 
};
 
}
 

	
 

	
 
/**
 
 * activate .show_more links
 
 * the .show_more must have an id that is the the id of an element to hide prefixed with _
 
 * the parentnode will be displayed
 
 */
 
var show_more_event = function(){
 
function show_more_event(){
 
    $('.show_more').click(function(e){
 
        var el = e.currentTarget;
 
        $('#' + el.id.substring(1)).hide();
 
        $(el.parentNode).show();
 
    });
 
};
 
}
 

	
 

	
 
var _onSuccessFollow = function(target){
 
function _onSuccessFollow(target){
 
    var $target = $(target);
 
    var $f_cnt = $('#current_followers_count');
 
    if ($target.hasClass('follow')) {
 
        $target.removeClass('follow').addClass('following');
 
        $target.prop('title', _TM['Stop following this repository']);
 
        if ($f_cnt.html()) {
 
@@ -453,41 +453,41 @@ var _onSuccessFollow = function(target){
 
            var cnt = Number($f_cnt.html())-1;
 
            $f_cnt.html(cnt);
 
        }
 
    }
 
}
 

	
 
var toggleFollowingRepo = function(target, follows_repository_id){
 
function toggleFollowingRepo(target, follows_repository_id){
 
    var args = {
 
        'follows_repository_id': follows_repository_id,
 
        '_session_csrf_secret_token': _session_csrf_secret_token
 
    }
 
    $.post(TOGGLE_FOLLOW_URL, args, function(data){
 
            _onSuccessFollow(target);
 
        });
 
    return false;
 
};
 
}
 

	
 
var showRepoSize = function(target, repo_name){
 
function showRepoSize(target, repo_name){
 
    var args = '_session_csrf_secret_token=' + _session_csrf_secret_token;
 

	
 
    if(!$("#" + target).hasClass('loaded')){
 
        $("#" + target).html(_TM['Loading ...']);
 
        var url = pyroutes.url('repo_size', {"repo_name":repo_name});
 
        $.post(url, args, function(data) {
 
            $("#" + target).html(data);
 
            $("#" + target).addClass('loaded');
 
        });
 
    }
 
    return false;
 
};
 
}
 

	
 
/**
 
 * load tooltips dynamically based on data attributes, used for .lazy-cs changeset links
 
 */
 
var get_changeset_tooltip = function() {
 
function get_changeset_tooltip() {
 
    var $target = $(this);
 
    var tooltip = $target.data('tooltip');
 
    if (!tooltip) {
 
        var raw_id = $target.data('raw_id');
 
        var repo_name = $target.data('repo_name');
 
        var url = pyroutes.url('changeset_info', {"repo_name": repo_name, "revision": raw_id});
 
@@ -498,18 +498,18 @@ var get_changeset_tooltip = function() {
 
                tooltip = data["message"];
 
            }
 
        });
 
        $target.data('tooltip', tooltip);
 
    }
 
    return tooltip;
 
};
 
}
 

	
 
/**
 
 * activate tooltips and popups
 
 */
 
var tooltip_activate = function(){
 
function tooltip_activate(){
 
    function placement(p, e){
 
        if(e.getBoundingClientRect().top > 2*$(window).height()/3){
 
            return 'top';
 
        }else{
 
            return 'bottom';
 
        }
 
@@ -528,13 +528,13 @@ var tooltip_activate = function(){
 
        });
 
        $('.lazy-cs').tooltip({
 
            title: get_changeset_tooltip,
 
            placement: placement
 
        });
 
    });
 
};
 
}
 

	
 

	
 
/**
 
 * Quick filter widget
 
 *
 
 * @param target: filter input target
 
@@ -796,13 +796,13 @@ function deleteComment(comment_id) {
 
}
 

	
 

	
 
/**
 
 * Double link comments
 
 */
 
var linkInlineComments = function($firstlinks, $comments){
 
function linkInlineComments($firstlinks, $comments){
 
    if ($comments.length > 0) {
 
        $firstlinks.html('<a href="#{0}">First comment</a>'.format($comments.prop('id')));
 
    }
 
    if ($comments.length <= 1) {
 
        return;
 
    }
 
@@ -822,13 +822,13 @@ var linkInlineComments = function($first
 
                '<div class="prev-comment">{0}</div>'.format(prev) +
 
                '<div class="next-comment">{0}</div>'.format(next));
 
        });
 
}
 

	
 
/* activate files.html stuff */
 
var fileBrowserListeners = function(node_list_url, url_base){
 
function fileBrowserListeners(node_list_url, url_base){
 
    var $node_filter = $('#node_filter');
 

	
 
    var filterTimeout = null;
 
    var nodes = null;
 

	
 
    var initFilter = function(){
 
@@ -911,16 +911,16 @@ var fileBrowserListeners = function(node
 
            }
 
        });
 
    $node_filter.keyup(function(e){
 
            clearTimeout(filterTimeout);
 
            filterTimeout = setTimeout(updateFilter(e),600);
 
        });
 
};
 
}
 

	
 

	
 
var initCodeMirror = function(textarea_id, baseUrl, resetUrl){
 
function initCodeMirror(textarea_id, baseUrl, resetUrl){
 
    var myCodeMirror = CodeMirror.fromTextArea($('#' + textarea_id)[0], {
 
            mode: "null",
 
            lineNumbers: true,
 
            indentUnit: 4,
 
            autofocus: true
 
        });
 
@@ -940,37 +940,37 @@ var initCodeMirror = function(textarea_i
 
            $('#upload_file_container').show();
 
            $('#filename_container').hide();
 
            $('#body').hide();
 
        });
 

	
 
    return myCodeMirror
 
};
 
}
 

	
 
var setCodeMirrorMode = function(codeMirrorInstance, mode) {
 
function setCodeMirrorMode(codeMirrorInstance, mode) {
 
    CodeMirror.autoLoadMode(codeMirrorInstance, mode);
 
}
 

	
 

	
 
var _getIdentNode = function(n){
 
function _getIdentNode(n){
 
    //iterate thrugh nodes until matching interesting node
 

	
 
    if (typeof n == 'undefined'){
 
        return -1
 
    }
 

	
 
    if(typeof n.id != "undefined" && n.id.match('L[0-9]+')){
 
        return n
 
    }
 
    else{
 
        return _getIdentNode(n.parentNode);
 
    }
 
};
 
}
 

	
 
/* generate links for multi line selects that can be shown by files.html page_highlights.
 
 * This is a mouseup handler for hlcode from CodeHtmlFormatter and pygmentize */
 
var getSelectionLink = function(e) {
 
function getSelectionLink(e) {
 
    //get selection from start/to nodes
 
    if (typeof window.getSelection != "undefined") {
 
        var s = window.getSelection();
 

	
 
        var from = _getIdentNode(s.anchorNode);
 
        var till = _getIdentNode(s.focusNode);
 
@@ -1001,13 +1001,13 @@ var getSelectionLink = function(e) {
 
            $hl_div.show();
 
        }
 
        else{
 
            $hl_div.hide();
 
        }
 
    }
 
};
 
}
 

	
 
/**
 
 * Autocomplete functionality
 
 */
 

	
 
// Custom search function for the DataSource of users
 
@@ -1047,48 +1047,48 @@ var autocompleteMatchGroups = function (
 
    }
 
    return matches;
 
};
 

	
 
// Highlight the snippet if it is found in the full text, while escaping any existing markup.
 
// Snippet must be lowercased already.
 
var autocompleteHighlightMatch = function (full, snippet) {
 
function autocompleteHighlightMatch(full, snippet) {
 
    var matchindex = full.toLowerCase().indexOf(snippet);
 
    if (matchindex <0)
 
        return full.html_escape();
 
    return full.substring(0, matchindex).html_escape()
 
        + '<span class="select2-match">'
 
        + full.substr(matchindex, snippet.length).html_escape()
 
        + '</span>'
 
        + full.substring(matchindex + snippet.length).html_escape();
 
};
 
}
 

	
 
// Return html snippet for showing the provided gravatar url
 
var gravatar = function(gravatar_lnk, size, cssclass) {
 
function gravatar(gravatar_lnk, size, cssclass) {
 
    if (!gravatar_lnk) {
 
        return '';
 
    }
 
    if (gravatar_lnk == 'default') {
 
        return '<i class="icon-user {1}" style="font-size: {0}px;"></i>'.format(size, cssclass);
 
    }
 
    return ('<i class="icon-gravatar {2}"' +
 
            ' style="font-size: {0}px;background-image: url(\'{1}\'); background-size: {0}px"' +
 
            '></i>').format(size, gravatar_lnk, cssclass);
 
}
 

	
 
var autocompleteGravatar = function(res, gravatar_lnk, size, group) {
 
function autocompleteGravatar(res, gravatar_lnk, size, group) {
 
    var elem;
 
    if (group !== undefined) {
 
        elem = '<i class="perm-gravatar-ac icon-users"></i>';
 
    } else {
 
        elem = gravatar(gravatar_lnk, size, "perm-gravatar-ac");
 
    }
 
    return '<div class="ac-container-wrap">{0}{1}</div>'.format(elem, res);
 
}
 

	
 
// Custom formatter to highlight the matching letters and do HTML escaping
 
var autocompleteFormatter = function (oResultData, sQuery, sResultMatch) {
 
function autocompleteFormatter(oResultData, sQuery, sResultMatch) {
 
    var query;
 
    if (sQuery && sQuery.toLowerCase) // YAHOO AutoComplete
 
        query = sQuery.toLowerCase();
 
    else if (sResultMatch && sResultMatch.term) // select2 - parameter names doesn't match
 
        query = sResultMatch.term.toLowerCase();
 

	
 
@@ -1112,15 +1112,15 @@ var autocompleteFormatter = function (oR
 
        }
 

	
 
        return autocompleteGravatar(displayname, oResultData.gravatar_lnk, oResultData.gravatar_size);
 
    }
 

	
 
    return '';
 
};
 
}
 

	
 
var SimpleUserAutoComplete = function ($inputElement) {
 
function SimpleUserAutoComplete($inputElement) {
 
    $inputElement.select2({
 
        formatInputTooShort: $inputElement.attr('placeholder'),
 
        initSelection : function (element, callback) {
 
            $.ajax({
 
                url: pyroutes.url('users_and_groups_data'),
 
                dataType: 'json',
 
@@ -1149,13 +1149,13 @@ var SimpleUserAutoComplete = function ($
 
        formatSelection: autocompleteFormatter,
 
        formatResult: autocompleteFormatter,
 
        id: function(item) { return item.nname; },
 
    });
 
}
 

	
 
var MembersAutoComplete = function ($inputElement, $typeElement) {
 
function MembersAutoComplete($inputElement, $typeElement) {
 

	
 
    $inputElement.select2({
 
        placeholder: $inputElement.attr('placeholder'),
 
        minimumInputLength: 1,
 
        ajax: {
 
            url: pyroutes.url('users_and_groups_data'),
 
@@ -1177,13 +1177,13 @@ var MembersAutoComplete = function ($inp
 
    }).on("select2-selecting", function(e) {
 
        // e.choice.id is automatically used as selection value - just set the type of the selection
 
        $typeElement.val(e.choice.type);
 
    });
 
}
 

	
 
var MentionsAutoComplete = function ($inputElement) {
 
function MentionsAutoComplete($inputElement) {
 
  $inputElement.atwho({
 
    at: "@",
 
    callbacks: {
 
      remoteFilter: function(query, callback) {
 
        $.getJSON(
 
          pyroutes.url('users_and_groups_data'),
 
@@ -1206,13 +1206,13 @@ var MentionsAutoComplete = function ($in
 
                "{0} {1} ({2})".format(item.fname, item.lname, item.nname).html_escape(),
 
                '${gravatar_lnk}', 16) +
 
            "</li>";
 
    },
 
    insertTpl: "${atwho-at}${nname}"
 
  });
 
};
 
}
 

	
 

	
 
// Set caret at the given position in the input element
 
function _setCaretPosition($inputElement, caretPos) {
 
    $inputElement.each(function(){
 
        if(this.createTextRange) { // IE
 
@@ -1227,13 +1227,13 @@ function _setCaretPosition($inputElement
 
        else // last resort - very old browser
 
            this.focus();
 
    });
 
}
 

	
 

	
 
var addReviewMember = function(id,fname,lname,nname,gravatar_link,gravatar_size){
 
function addReviewMember(id,fname,lname,nname,gravatar_link,gravatar_size){
 
    var displayname = nname;
 
    if ((fname != "") && (lname != "")) {
 
        displayname = "{0} {1} ({2})".format(fname, lname, nname);
 
    }
 
    var gravatarelm = gravatar(gravatar_link, gravatar_size, "");
 
    // WARNING: the HTML below is duplicate with
 
@@ -1264,21 +1264,21 @@ var addReviewMember = function(id,fname,
 
    if(ids.indexOf('reviewer_'+id) == -1){
 
        //only add if it's not there
 
        $('#review_members').append(element);
 
    }
 
}
 

	
 
var removeReviewMember = function(reviewer_id, repo_name, pull_request_id){
 
function removeReviewMember(reviewer_id, repo_name, pull_request_id){
 
    var $li = $('#reviewer_{0}'.format(reviewer_id));
 
    $li.find('div div').css("text-decoration", "line-through");
 
    $li.find('input').prop('name', 'review_members_removed');
 
    $li.find('.reviewer_member_remove').replaceWith('&nbsp;(remove not saved)');
 
}
 

	
 
/* activate auto completion of users as PR reviewers */
 
var PullRequestAutoComplete = function ($inputElement) {
 
function PullRequestAutoComplete($inputElement) {
 
    $inputElement.select2(
 
    {
 
        placeholder: $inputElement.attr('placeholder'),
 
        minimumInputLength: 1,
 
        ajax: {
 
            url: pyroutes.url('users_and_groups_data'),
 
@@ -1347,13 +1347,13 @@ function ajaxActionRevokePermission(url,
 

	
 
    ajaxPOST(url, query_params, success, failure);
 
};
 

	
 
/* Multi selectors */
 

	
 
var MultiSelectWidget = function(selected_id, available_id, form_id){
 
function MultiSelectWidget(selected_id, available_id, form_id){
 
    var $availableselect = $('#' + available_id);
 
    var $selectedselect = $('#' + selected_id);
 

	
 
    //fill available only with those not in selected
 
    var $selectedoptions = $selectedselect.children('option');
 
    $availableselect.children('option').filter(function(i, e){
 
@@ -1381,13 +1381,13 @@ var MultiSelectWidget = function(selecte
 

	
 

	
 
/**
 
 Branch Sorting callback for select2, modifying the filtered result so prefix
 
 matches come before matches in the line.
 
 **/
 
var branchSort = function(results, container, query) {
 
function branchSort(results, container, query) {
 
    if (query.term) {
 
        return results.sort(function (a, b) {
 
            // Put closed branches after open ones (a bit of a hack ...)
 
            var aClosed = a.text.indexOf("(closed)") > -1,
 
                bClosed = b.text.indexOf("(closed)") > -1;
 
            if (aClosed && !bClosed) {
 
@@ -1415,15 +1415,15 @@ var branchSort = function(results, conta
 
                return -1;
 
            }
 
            return 0;
 
        });
 
    }
 
    return results;
 
};
 
}
 

	
 
var prefixFirstSort = function(results, container, query) {
 
function prefixFirstSort(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;
 
            }
 
@@ -1446,29 +1446,29 @@ var prefixFirstSort = function(results, 
 
                return -1;
 
            }
 
            return 0;
 
        });
 
    }
 
    return results;
 
};
 
}
 

	
 
/* Helper for jQuery DataTables */
 

	
 
var updateRowCountCallback = function updateRowCountCallback($elem, onlyDisplayed) {
 
function updateRowCountCallback($elem, onlyDisplayed) {
 
    return function drawCallback() {
 
        var info = this.api().page.info(),
 
            count = onlyDisplayed === true ? info.recordsDisplay : info.recordsTotal;
 
        $elem.html(count);
 
    }
 
};
 
}
 

	
 

	
 
/**
 
 * activate changeset parent/child navigation links
 
 */
 
var activate_parent_child_links = function(){
 
function activate_parent_child_links(){
 

	
 
    $('.parent-child-link').on('click', function(e){
 
        var $this = $(this);
 
        //fetch via ajax what is going to be the next link, if we have
 
        //>1 links show them to user to choose
 
        if(!$this.hasClass('disabled')){
kallithea/templates/files/files.html
Show inline comments
 
@@ -47,13 +47,13 @@ var node_list_url = ${h.js(h.url("files_
 

	
 
## new pyroutes URLs
 
pyroutes.register('files_nodelist_home', ${h.js(h.url('files_nodelist_home', repo_name=c.repo_name,revision='%(revision)s',f_path='%(f_path)s'))}, ['revision', 'f_path']);
 
pyroutes.register('files_history_home', ${h.js(h.url('files_history_home', repo_name=c.repo_name,revision='%(revision)s',f_path='%(f_path)s'))}, ['revision', 'f_path']);
 
pyroutes.register('files_authors_home', ${h.js(h.url('files_authors_home', repo_name=c.repo_name,revision='%(revision)s',f_path='%(f_path)s'))}, ['revision', 'f_path']);
 

	
 
var ypjax_links = function(){
 
function ypjax_links(){
 
    $('.ypjax-link').click(function(e){
 

	
 
        //don't do ypjax on middle click
 
        if (e.which == 2) {
 
            return true;
 
        }
 
@@ -85,13 +85,13 @@ var ypjax_links = function(){
 
        //now we're sure that we can do ypjax things
 
        e.preventDefault();
 
        return false;
 
    });
 
}
 

	
 
var load_state = function(state) {
 
function load_state(state) {
 
    var $files_data = $('#files_data');
 
    var cache_key = state.url;
 
    var _cache_obj = CACHE[cache_key];
 
    var _cur_time = new Date().getTime();
 
    if (_cache_obj !== undefined && _cache_obj[0] > _cur_time) {
 
        $files_data.html(_cache_obj[1]);
 
@@ -103,13 +103,13 @@ var load_state = function(state) {
 
                  var expire_on = new Date().getTime() + CACHE_EXPIRE;
 
                  CACHE[cache_key] = [expire_on, $files_data.html()];
 
            });
 
    }
 
}
 

	
 
var post_load_state = function(state) {
 
function post_load_state(state) {
 
    ypjax_links();
 
    tooltip_activate();
 

	
 
    if(state !== undefined) {
 
        document.title = state.title;
 

	
kallithea/templates/summary/summary.html
Show inline comments
 
@@ -25,13 +25,13 @@
 

	
 
<%block name="head_extra">
 
  <link href="${h.url('atom_feed_home',repo_name=c.db_repo.repo_name,api_key=request.authuser.api_key)}" rel="alternate" title="${_('%s ATOM feed') % c.repo_name}" type="application/atom+xml" />
 
  <link href="${h.url('rss_feed_home',repo_name=c.db_repo.repo_name,api_key=request.authuser.api_key)}" rel="alternate" title="${_('%s RSS feed') % c.repo_name}" type="application/rss+xml" />
 

	
 
  <script>'use strict';
 
  redirect_hash_branch = function(){
 
  function redirect_hash_branch(){
 
    var branch = window.location.hash.replace(/^#(.*)/, '$1');
 
    if (branch){
 
      window.location = ${h.js(h.url('changelog_home',repo_name=c.repo_name,branch='__BRANCH__'))}
 
        .replace('__BRANCH__',branch);
 
    }
 
  }
0 comments (0 inline, 0 general)