diff options
author | Alfredo Sumaran <alfredo@gitlab.com> | 2016-12-02 16:03:18 +0000 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-12-02 16:03:18 +0000 |
commit | 2f91c0eef45e9501ba90976a64886aee56b90b46 (patch) | |
tree | ce4fb0261b7844e7b99e03c23d15f78ca953baa5 /app | |
parent | af19d56f5e20383a142f07545757352b341fcda9 (diff) | |
parent | f90b6200e450f6b87cc310ab5734a09719d891d3 (diff) | |
download | gitlab-ce-2f91c0eef45e9501ba90976a64886aee56b90b46.tar.gz |
Merge branch 'cleanup-common_utils.js' into 'master'
Clean up common_utils.js
## What does this MR do?
- Remove unused functions from `common_utils.js`.
- Move functions which are used from only one file to that file.
## Why was this MR needed?
Because some utils weren't that common (anymore).
See merge request !7318
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/application.js | 18 | ||||
-rw-r--r-- | app/assets/javascripts/gfm_auto_complete.js.es6 | 18 | ||||
-rw-r--r-- | app/assets/javascripts/lib/utils/common_utils.js | 54 | ||||
-rw-r--r-- | app/assets/javascripts/merge_request_tabs.js | 3 |
4 files changed, 29 insertions, 64 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index cfab4721f4b..b7c4673c8e3 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -56,7 +56,13 @@ /*= require es6-promise.auto */ (function () { - document.addEventListener('page:fetch', gl.utils.cleanupBeforeFetch); + document.addEventListener('page:fetch', function () { + // Unbind scroll events + $(document).off('scroll'); + // Close any open tooltips + $('.has-tooltip, [data-toggle="tooltip"]').tooltip('destroy'); + }); + window.addEventListener('hashchange', gl.utils.handleLocationHash); window.addEventListener('load', function onLoad() { window.removeEventListener('load', onLoad, false); @@ -76,7 +82,15 @@ // Set the default path for all cookies to GitLab's root directory Cookies.defaults.path = gon.relative_url_root || '/'; - gl.utils.preventDisabledButtons(); + // prevent default action for disabled buttons + $('.btn').click(function(e) { + if ($(this).hasClass('disabled')) { + e.preventDefault(); + e.stopImmediatePropagation(); + return false; + } + }); + $('.nav-sidebar').niceScroll({ cursoropacitymax: '0.4', cursorcolor: '#FFF', diff --git a/app/assets/javascripts/gfm_auto_complete.js.es6 b/app/assets/javascripts/gfm_auto_complete.js.es6 index 10769b7fd4f..6f9d6283071 100644 --- a/app/assets/javascripts/gfm_auto_complete.js.es6 +++ b/app/assets/javascripts/gfm_auto_complete.js.es6 @@ -5,6 +5,10 @@ window.GitLab = {}; } + function sanitize(str) { + return str.replace(/<(?:.|\n)*?>/gm, ''); + } + GitLab.GfmAutoComplete = { dataLoading: false, dataLoaded: false, @@ -160,8 +164,8 @@ return { username: m.username, avatarTag: autoCompleteAvatar.length === 1 ? txtAvatar : imgAvatar, - title: gl.utils.sanitize(title), - search: gl.utils.sanitize(m.username + " " + m.name) + title: sanitize(title), + search: sanitize(m.username + " " + m.name) }; }); } @@ -195,7 +199,7 @@ } return { id: i.iid, - title: gl.utils.sanitize(i.title), + title: sanitize(i.title), search: i.iid + " " + i.title }; }); @@ -228,7 +232,7 @@ } return { id: m.iid, - title: gl.utils.sanitize(m.title), + title: sanitize(m.title), search: "" + m.title }; }); @@ -263,7 +267,7 @@ } return { id: m.iid, - title: gl.utils.sanitize(m.title), + title: sanitize(m.title), search: m.iid + " " + m.title }; }); @@ -284,9 +288,9 @@ var sanitizeLabelTitle; sanitizeLabelTitle = function(title) { if (/[\w\?&]+\s+[\w\?&]+/g.test(title)) { - return "\"" + (gl.utils.sanitize(title)) + "\""; + return "\"" + (sanitize(title)) + "\""; } else { - return gl.utils.sanitize(title); + return sanitize(title); } }; return $.map(merges, function(m) { diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index c5846068b07..29cba1a49dd 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -33,10 +33,6 @@ }); }; - w.gl.utils.split = function(val) { - return val.split(/,\s*/); - }; - w.gl.utils.extractLast = function(term) { return this.split(term).pop(); }; @@ -67,33 +63,6 @@ }); }; - w.gl.utils.disableButtonIfAnyEmptyField = function(form, form_selector, button_selector) { - var closest_submit, updateButtons; - closest_submit = form.find(button_selector); - updateButtons = function() { - var filled; - filled = true; - form.find('input').filter(form_selector).each(function() { - return filled = this.rstrip($(this).val()) !== "" || !$(this).attr('required'); - }); - if (filled) { - return closest_submit.enable(); - } else { - return closest_submit.disable(); - } - }; - updateButtons(); - return form.keyup(updateButtons); - }; - - w.gl.utils.sanitize = function(str) { - return str.replace(/<(?:.|\n)*?>/gm, ''); - }; - - w.gl.utils.unbindEvents = function() { - return $(document).off('scroll'); - }; - // automatically adjust scroll position for hash urls taking the height of the navbar into account // https://github.com/twitter/bootstrap/issues/1768 w.gl.utils.handleLocationHash = function() { @@ -124,32 +93,9 @@ } }; - gl.utils.updateTooltipTitle = function($tooltipEl, newTitle) { - return $tooltipEl.tooltip('destroy').attr('title', newTitle).tooltip('fixTitle'); - }; - gl.utils.preventDisabledButtons = function() { - return $('.btn').click(function(e) { - if ($(this).hasClass('disabled')) { - e.preventDefault(); - e.stopImmediatePropagation(); - return false; - } - }); - }; gl.utils.getPagePath = function() { return $('body').data('page').split(':')[0]; }; - gl.utils.parseUrl = function (url) { - var parser = document.createElement('a'); - parser.href = url; - return parser; - }; - gl.utils.cleanupBeforeFetch = function() { - // Unbind scroll events - $(document).off('scroll'); - // Close any open tooltips - $('.has-tooltip, [data-toggle="tooltip"]').tooltip('destroy'); - }; gl.utils.isMetaKey = function(e) { return e.metaKey || e.ctrlKey || e.altKey || e.shiftKey; diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js index b1928f8d279..4a192ca5796 100644 --- a/app/assets/javascripts/merge_request_tabs.js +++ b/app/assets/javascripts/merge_request_tabs.js @@ -220,7 +220,8 @@ // We extract pathname for the current Changes tab anchor href // some pages like MergeRequestsController#new has query parameters on that anchor - var url = gl.utils.parseUrl(source); + var url = document.createElement('a'); + url.href = source; return this._get({ url: (url.pathname + ".json") + this._location.search, |