summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2016-10-27 15:32:30 -0500
committerMike Greiling <mike@pixelcog.com>2016-12-02 17:38:58 -0600
commitf6624b5ce433b7148287e898f164476608868433 (patch)
tree791cd2da82da3bef8d7b2cac6d4af5aba734a6ff /app/assets/javascripts
parent825fea63a39aa586b07ba9ffc62252a90435c8ad (diff)
downloadgitlab-ce-f6624b5ce433b7148287e898f164476608868433.tar.gz
fix eslint failures on Diff and MergeRequestTabs
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/diff.js.es619
-rw-r--r--app/assets/javascripts/merge_request_tabs.js.es6108
2 files changed, 63 insertions, 64 deletions
diff --git a/app/assets/javascripts/diff.js.es6 b/app/assets/javascripts/diff.js.es6
index 462658419be..eacf53d1e1b 100644
--- a/app/assets/javascripts/diff.js.es6
+++ b/app/assets/javascripts/diff.js.es6
@@ -1,4 +1,4 @@
-/* eslint-disable */
+/* eslint-disable class-methods-use-this, no-param-reassign */
((global) => {
const UNFOLD_COUNT = 20;
@@ -29,7 +29,8 @@
const newLineNumber = ref[1];
const offset = newLineNumber - oldLineNumber;
const bottom = $target.hasClass('js-unfold-bottom');
- let since, to;
+ let since;
+ let to;
let unfold = true;
if (bottom) {
@@ -54,19 +55,19 @@
const view = file.data('view');
const params = { since, to, bottom, offset, unfold, view };
- $.get(link, params, (response) => $target.parent().replaceWith(response));
+ $.get(link, params, response => $target.parent().replaceWith(response));
}
handleClickLineNum(event) {
const hash = $(event.currentTarget).attr('href');
event.preventDefault();
- if (history.pushState) {
- history.pushState(null, null, hash);
+ if (window.history.pushState) {
+ window.history.pushState(null, null, hash);
} else {
window.location.hash = hash;
}
this.highlighSelectedLine();
- };
+ }
diffViewType() {
return $('.inline-parallel-buttons a.active').data('view-type');
@@ -76,10 +77,7 @@
if (!line.children().length) {
return [0, 0];
}
-
- return line.find('.diff-line-num').map(function() {
- return parseInt($(this).data('linenumber'));
- });
+ return line.find('.diff-line-num').map((i, elm) => parseInt($(elm).data('linenumber'), 10));
}
highlighSelectedLine() {
@@ -96,5 +94,4 @@
}
global.Diff = Diff;
-
})(window.gl || (window.gl = {}));
diff --git a/app/assets/javascripts/merge_request_tabs.js.es6 b/app/assets/javascripts/merge_request_tabs.js.es6
index e45de446e4c..d3248a4757e 100644
--- a/app/assets/javascripts/merge_request_tabs.js.es6
+++ b/app/assets/javascripts/merge_request_tabs.js.es6
@@ -1,12 +1,15 @@
-/* eslint-disable max-len, func-names, space-before-function-paren, no-var, space-before-blocks, prefer-rest-params, wrap-iife, no-use-before-define, no-underscore-dangle, no-undef, one-var, one-var-declaration-per-line, quotes, comma-dangle, consistent-return, prefer-template, no-param-reassign, camelcase, vars-on-top, space-in-parens, curly, prefer-arrow-callback, no-unused-vars, no-return-assign, semi, object-shorthand, operator-assignment, padded-blocks, max-len */
+/* eslint-disable no-new, no-param-reassign, class-methods-use-this */
+/* global Breakpoints, Cookies, DiffNotesApp */
+
+/*= require js.cookie */
+/*= require breakpoints */
+
+/* eslint-disable max-len */
// MergeRequestTabs
//
// Handles persisting and restoring the current tab selection and lazily-loading
// content on the MergeRequests#show page.
//
-/*= require js.cookie */
-
-//
// ### Example Markup
//
// <ul class="nav-links merge-request-tabs">
@@ -45,11 +48,15 @@
// </div>
// </div>
//
+/* eslint-enable max-len */
+
((global) => {
+ // Store the `location` object, allowing for easier stubbing in tests
+ let location = window.location;
class MergeRequestTabs {
- constructor({ action, setUrl, buildsLoaded } = {}) {
+ constructor({ action, setUrl, buildsLoaded, stubLocation } = {}) {
this.diffsLoaded = false;
this.buildsLoaded = false;
this.pipelinesLoaded = false;
@@ -63,8 +70,10 @@
this.tabShown = this.tabShown.bind(this);
this.showTab = this.showTab.bind(this);
- // Store the `location` object, allowing for easier stubbing in tests
- this._location = window.location;
+ if (stubLocation) {
+ location = stubLocation;
+ }
+
this.bindEvents();
this.activateTab(action);
this.initAffix();
@@ -97,15 +106,15 @@
this.resetViewContainer();
} else if (this.isDiffAction(action)) {
this.loadDiff($target.attr('href'));
- if ((typeof bp !== "undefined" && bp !== null) && bp.getBreakpointSize() !== 'lg') {
+ if (Breakpoints.get().getBreakpointSize() !== 'lg') {
this.shrinkView();
}
if (this.diffViewType() === 'parallel') {
this.expandViewContainer();
}
const navBarHeight = $('.navbar-gitlab').outerHeight();
- $.scrollTo(".merge-request-details .merge-request-tabs", {
- offset: -navBarHeight
+ $.scrollTo('.merge-request-details .merge-request-tabs', {
+ offset: -navBarHeight,
});
} else if (action === 'builds') {
this.loadBuilds($target.attr('href'));
@@ -125,13 +134,12 @@
}
scrollToElement(container) {
- if (window.location.hash) {
+ if (location.hash) {
const navBarHeight = $('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight() + document.querySelector('.js-tabs-affix').offsetHeight;
- const navBarHeight = $('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight();
- const $el = $(`${container} ${window.location.hash}:not(.match)`);
+ const $el = $(`${container} ${location.hash}:not(.match)`);
if ($el.length) {
$.scrollTo($el[0], {
- offset: -navBarHeight
+ offset: -navBarHeight,
});
}
}
@@ -139,11 +147,9 @@
// Activate a tab based on the current action
activateTab(action) {
- if (action === 'show') {
- action = 'notes';
- }
+ const activate = action === 'show' ? 'notes' : action;
// important note: the .tab('show') method triggers 'shown.bs.tab' event itself
- $(`.merge-request-tabs a[data-action='${action}']`).tab('show');
+ $(`.merge-request-tabs a[data-action='${activate}']`).tab('show');
}
// Replaces the current Merge Request-specific action in the URL with a new one
@@ -167,33 +173,29 @@
//
// Returns the new URL String
setCurrentAction(action) {
- // Normalize action, just to be safe
- if (action === 'show') {
- action = 'notes';
- }
- this.currentAction = action;
+ this.currentAction = action === 'show' ? 'notes' : action;
// Remove a trailing '/commits' '/diffs' '/builds' '/pipelines' '/new' '/new/diffs'
- let new_state = this._location.pathname.replace(/\/(commits|diffs|builds|pipelines|new|new\/diffs)(\.html)?\/?$/, '');
+ let newState = location.pathname.replace(/\/(commits|diffs|builds|pipelines|new|new\/diffs)(\.html)?\/?$/, '');
// Append the new action if we're on a tab other than 'notes'
- if (action !== 'notes') {
- new_state += `/${action}`;
+ if (this.currentAction !== 'notes') {
+ newState += `/${this.currentAction}`;
}
// Ensure parameters and hash come along for the ride
- new_state += this._location.search + this._location.hash;
+ newState += location.search + location.hash;
// Replace the current history state with the new one without breaking
// Turbolinks' history.
//
// See https://github.com/rails/turbolinks/issues/363
- history.replaceState({
+ window.history.replaceState({
turbolinks: true,
- url: new_state
- }, document.title, new_state);
+ url: newState,
+ }, document.title, newState);
- return new_state;
+ return newState;
}
loadCommits(source) {
@@ -203,11 +205,11 @@
this.ajaxGet({
url: `${source}.json`,
success: (data) => {
- document.querySelector("div#commits").innerHTML = data.html;
+ document.querySelector('div#commits').innerHTML = data.html;
gl.utils.localTimeAgo($('.js-timeago', 'div#commits'));
this.commitsLoaded = true;
- this.scrollToElement("#commits");
- }
+ this.scrollToElement('#commits');
+ },
});
}
@@ -222,7 +224,7 @@
url.href = source;
this.ajaxGet({
- url: `${url.pathname}.json${this._location.search}`,
+ url: `${url.pathname}.json${location.search}`,
success: (data) => {
$('#diffs').html(data.html);
@@ -233,14 +235,14 @@
gl.utils.localTimeAgo($('.js-timeago', 'div#diffs'));
$('#diffs .js-syntax-highlight').syntaxHighlight();
- if (this.diffViewType() === 'parallel' && this.isDiffAction(this.currentAction) ) {
+ if (this.diffViewType() === 'parallel' && this.isDiffAction(this.currentAction)) {
this.expandViewContainer();
}
this.diffsLoaded = true;
- this.scrollToElement("#diffs");
+ this.scrollToElement('#diffs');
new gl.Diff();
- }
+ },
});
}
@@ -251,12 +253,12 @@
this.ajaxGet({
url: `${source}.json`,
success: (data) => {
- document.querySelector("div#builds").innerHTML = data.html;
+ document.querySelector('div#builds').innerHTML = data.html;
gl.utils.localTimeAgo($('.js-timeago', 'div#builds'));
this.buildsLoaded = true;
new gl.Pipelines();
- this.scrollToElement("#builds");
- }
+ this.scrollToElement('#builds');
+ },
});
}
@@ -270,8 +272,8 @@
$('#pipelines').html(data.html);
gl.utils.localTimeAgo($('.js-timeago', '#pipelines'));
this.pipelinesLoaded = true;
- this.scrollToElement("#pipelines");
- }
+ this.scrollToElement('#pipelines');
+ },
});
}
@@ -287,10 +289,9 @@
beforeSend: () => this.toggleLoading(true),
complete: () => this.toggleLoading(false),
dataType: 'json',
- type: 'GET'
+ type: 'GET',
};
- options = $.extend({}, defaults, options);
- $.ajax(options);
+ $.ajax($.extend({}, defaults, options));
}
diffViewType() {
@@ -298,7 +299,7 @@
}
isDiffAction(action) {
- return action === 'diffs' || action === 'new/diffs'
+ return action === 'diffs' || action === 'new/diffs';
}
expandViewContainer() {
@@ -356,11 +357,13 @@
const $layoutNav = $('.layout-nav');
$tabs.off('affix.bs.affix affix-top.bs.affix')
- .affix({ offset: {
- top: () => (
- $diffTabs.offset().top - $tabs.height() - $fixedNav.height() - $layoutNav.height()
- )
- }})
+ .affix({
+ offset: {
+ top: () => (
+ $diffTabs.offset().top - $tabs.height() - $fixedNav.height() - $layoutNav.height()
+ ),
+ },
+ })
.on('affix.bs.affix', () => $diffTabs.css({ marginTop: $tabs.height() }))
.on('affix-top.bs.affix', () => $diffTabs.css({ marginTop: '' }));
@@ -372,5 +375,4 @@
}
global.MergeRequestTabs = MergeRequestTabs;
-
})(window.gl || (window.gl = {}));