Mercurial > kallithea
changeset 8252:c7e67b87fd1b
js: cleanup to use named functions instead of vars with anonymous functions
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 16 Feb 2020 02:47:09 +0100 |
parents | fb9550946c26 |
children | f4e158ed49b1 |
files | kallithea/public/js/base.js kallithea/templates/files/files.html kallithea/templates/summary/summary.html |
diffstat | 3 files changed, 52 insertions(+), 52 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/public/js/base.js Mon Feb 17 17:49:45 2020 +0100 +++ b/kallithea/public/js/base.js Sun Feb 16 02:47:09 2020 +0100 @@ -353,7 +353,7 @@ /** * turns objects into GET query string */ -var _toQueryString = function(o) { +function _toQueryString(o) { if(typeof o !== 'object') { return false; } @@ -362,7 +362,7 @@ _qs.push(encodeURIComponent(_p) + '=' + encodeURIComponent(o[_p])); } return _qs.join('&'); -}; +} /** * Load HTML into DOM using Ajax @@ -395,7 +395,7 @@ ; }; -var ajaxGET = function(url, success, failure) { +function ajaxGET(url, success, failure) { if(failure === undefined) { failure = function(jqXHR, textStatus, errorThrown) { if (textStatus != "abort") @@ -405,9 +405,9 @@ 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) { @@ -419,7 +419,7 @@ return $.ajax({url: url, data: postData, type: 'POST', headers: {'X-PARTIAL-XHR': '1'}, cache: false}) .done(success) .fail(failure); -}; +} /** @@ -427,16 +427,16 @@ * 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')) { @@ -456,7 +456,7 @@ } } -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 @@ -465,9 +465,9 @@ _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')){ @@ -479,12 +479,12 @@ }); } 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) { @@ -501,12 +501,12 @@ $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'; @@ -531,7 +531,7 @@ placement: placement }); }); -}; +} /** @@ -799,7 +799,7 @@ /** * 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'))); } @@ -825,7 +825,7 @@ } /* 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; @@ -914,10 +914,10 @@ 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, @@ -943,14 +943,14 @@ }); 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'){ @@ -963,11 +963,11 @@ 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(); @@ -1004,7 +1004,7 @@ $hl_div.hide(); } } -}; +} /** * Autocomplete functionality @@ -1050,7 +1050,7 @@ // 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(); @@ -1059,10 +1059,10 @@ + 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 ''; } @@ -1074,7 +1074,7 @@ '></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>'; @@ -1085,7 +1085,7 @@ } // 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(); @@ -1115,9 +1115,9 @@ } return ''; -}; +} -var SimpleUserAutoComplete = function ($inputElement) { +function SimpleUserAutoComplete($inputElement) { $inputElement.select2({ formatInputTooShort: $inputElement.attr('placeholder'), initSelection : function (element, callback) { @@ -1152,7 +1152,7 @@ }); } -var MembersAutoComplete = function ($inputElement, $typeElement) { +function MembersAutoComplete($inputElement, $typeElement) { $inputElement.select2({ placeholder: $inputElement.attr('placeholder'), @@ -1180,7 +1180,7 @@ }); } -var MentionsAutoComplete = function ($inputElement) { +function MentionsAutoComplete($inputElement) { $inputElement.atwho({ at: "@", callbacks: { @@ -1209,7 +1209,7 @@ }, insertTpl: "${atwho-at}${nname}" }); -}; +} // Set caret at the given position in the input element @@ -1230,7 +1230,7 @@ } -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); @@ -1267,7 +1267,7 @@ } } -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'); @@ -1275,7 +1275,7 @@ } /* activate auto completion of users as PR reviewers */ -var PullRequestAutoComplete = function ($inputElement) { +function PullRequestAutoComplete($inputElement) { $inputElement.select2( { placeholder: $inputElement.attr('placeholder'), @@ -1350,7 +1350,7 @@ /* 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); @@ -1384,7 +1384,7 @@ 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 ...) @@ -1418,9 +1418,9 @@ }); } 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 @@ -1449,23 +1449,23 @@ }); } 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);
--- a/kallithea/templates/files/files.html Mon Feb 17 17:49:45 2020 +0100 +++ b/kallithea/templates/files/files.html Sun Feb 16 02:47:09 2020 +0100 @@ -50,7 +50,7 @@ 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 @@ -88,7 +88,7 @@ }); } -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]; @@ -106,7 +106,7 @@ } } -var post_load_state = function(state) { +function post_load_state(state) { ypjax_links(); tooltip_activate();
--- a/kallithea/templates/summary/summary.html Mon Feb 17 17:49:45 2020 +0100 +++ b/kallithea/templates/summary/summary.html Sun Feb 16 02:47:09 2020 +0100 @@ -28,7 +28,7 @@ <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__'))}