forked from Shiloh/githaven
Misc JS linting and naming tweaks (#10652)
- lowercase all js filenames except Vue components - enable new lint rules, mostly focused on shorter code - autofix new lint violations - apply misc transformations indexOf -> includes and onevent-> addEventListener Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
This commit is contained in:
parent
984b85c1a7
commit
e03d627769
11
.eslintrc
11
.eslintrc
@ -5,7 +5,7 @@ extends:
|
|||||||
- eslint:recommended
|
- eslint:recommended
|
||||||
|
|
||||||
ignorePatterns:
|
ignorePatterns:
|
||||||
- /web_src/js/vendor
|
- /web_src/js/vendor
|
||||||
|
|
||||||
parserOptions:
|
parserOptions:
|
||||||
ecmaVersion: 2020
|
ecmaVersion: 2020
|
||||||
@ -26,19 +26,22 @@ globals:
|
|||||||
|
|
||||||
rules:
|
rules:
|
||||||
arrow-body-style: [0]
|
arrow-body-style: [0]
|
||||||
|
arrow-parens: [2, always]
|
||||||
camelcase: [0]
|
camelcase: [0]
|
||||||
comma-dangle: [2, only-multiline]
|
comma-dangle: [2, only-multiline]
|
||||||
consistent-return: [0]
|
consistent-return: [0]
|
||||||
default-case: [0]
|
default-case: [0]
|
||||||
func-names: [0]
|
func-names: [0]
|
||||||
import/extensions: [0]
|
import/extensions: [2, always, {ignorePackages: true}]
|
||||||
import/prefer-default-export: [0]
|
import/prefer-default-export: [0]
|
||||||
max-len: [0]
|
max-len: [0]
|
||||||
|
multiline-comment-style: [2, separate-lines]
|
||||||
newline-per-chained-call: [0]
|
newline-per-chained-call: [0]
|
||||||
no-alert: [0]
|
no-alert: [0]
|
||||||
no-cond-assign: [2, except-parens]
|
no-cond-assign: [2, except-parens]
|
||||||
no-console: [1, {allow: [info, warn, error]}]
|
no-console: [1, {allow: [info, warn, error]}]
|
||||||
no-continue: [0]
|
no-continue: [0]
|
||||||
|
no-eq-null: [2]
|
||||||
no-mixed-operators: [0]
|
no-mixed-operators: [0]
|
||||||
no-multi-assign: [0]
|
no-multi-assign: [0]
|
||||||
no-new: [0]
|
no-new: [0]
|
||||||
@ -49,8 +52,12 @@ rules:
|
|||||||
no-unused-vars: [2, {args: all, argsIgnorePattern: ^_, varsIgnorePattern: ^_, ignoreRestSiblings: true}]
|
no-unused-vars: [2, {args: all, argsIgnorePattern: ^_, varsIgnorePattern: ^_, ignoreRestSiblings: true}]
|
||||||
no-use-before-define: [0]
|
no-use-before-define: [0]
|
||||||
no-var: [2]
|
no-var: [2]
|
||||||
|
object-curly-spacing: [2, never]
|
||||||
one-var-declaration-per-line: [0]
|
one-var-declaration-per-line: [0]
|
||||||
one-var: [0]
|
one-var: [0]
|
||||||
|
operator-linebreak: [2, after]
|
||||||
prefer-const: [2, {destructuring: all}]
|
prefer-const: [2, {destructuring: all}]
|
||||||
prefer-destructuring: [0]
|
prefer-destructuring: [0]
|
||||||
|
quotes: [2, single, {avoidEscape: true, allowTemplateLiterals: true}]
|
||||||
radix: [2, as-needed]
|
radix: [2, as-needed]
|
||||||
|
semi: [2, always, {omitLastInOneLineBlock: true}]
|
||||||
|
@ -2,7 +2,7 @@ export default async function initClipboard() {
|
|||||||
const els = document.querySelectorAll('.clipboard');
|
const els = document.querySelectorAll('.clipboard');
|
||||||
if (!els || !els.length) return;
|
if (!els || !els.length) return;
|
||||||
|
|
||||||
const { default: ClipboardJS } = await import(/* webpackChunkName: "clipboard" */'clipboard');
|
const {default: ClipboardJS} = await import(/* webpackChunkName: "clipboard" */'clipboard');
|
||||||
|
|
||||||
const clipboard = new ClipboardJS(els);
|
const clipboard = new ClipboardJS(els);
|
||||||
clipboard.on('success', (e) => {
|
clipboard.on('success', (e) => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { svg } from '../utils.js';
|
import {svg} from '../utils.js';
|
||||||
|
|
||||||
const { AppSubUrl } = window.config;
|
const {AppSubUrl} = window.config;
|
||||||
|
|
||||||
export default function initContextPopups() {
|
export default function initContextPopups() {
|
||||||
const refIssues = $('.ref-issue');
|
const refIssues = $('.ref-issue');
|
||||||
@ -14,7 +14,7 @@ export default function initContextPopups() {
|
|||||||
|
|
||||||
function issuePopup(owner, repo, index, $element) {
|
function issuePopup(owner, repo, index, $element) {
|
||||||
$.get(`${AppSubUrl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => {
|
$.get(`${AppSubUrl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => {
|
||||||
const createdAt = new Date(issue.created_at).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });
|
const createdAt = new Date(issue.created_at).toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'});
|
||||||
|
|
||||||
let body = issue.body.replace(/\n+/g, ' ');
|
let body = issue.body.replace(/\n+/g, ' ');
|
||||||
if (body.length > 85) {
|
if (body.length > 85) {
|
@ -1,5 +1,5 @@
|
|||||||
export default async function createDropzone(el, opts) {
|
export default async function createDropzone(el, opts) {
|
||||||
const [{ default: Dropzone }] = await Promise.all([
|
const [{default: Dropzone}] = await Promise.all([
|
||||||
import(/* webpackChunkName: "dropzone" */'dropzone'),
|
import(/* webpackChunkName: "dropzone" */'dropzone'),
|
||||||
import(/* webpackChunkName: "dropzone" */'dropzone/dist/dropzone.css'),
|
import(/* webpackChunkName: "dropzone" */'dropzone/dist/dropzone.css'),
|
||||||
]);
|
]);
|
||||||
|
@ -2,7 +2,7 @@ export default async function initGitGraph() {
|
|||||||
const graphCanvas = document.getElementById('graph-canvas');
|
const graphCanvas = document.getElementById('graph-canvas');
|
||||||
if (!graphCanvas) return;
|
if (!graphCanvas) return;
|
||||||
|
|
||||||
const { default: gitGraph } = await import(/* webpackChunkName: "gitgraph" */'../vendor/gitGraph.js');
|
const {default: gitGraph} = await import(/* webpackChunkName: "gitgraph" */'../vendor/gitgraph.js');
|
||||||
|
|
||||||
const graphList = [];
|
const graphList = [];
|
||||||
$('#graph-raw-list li span.node-relation').each(function () {
|
$('#graph-raw-list li span.node-relation').each(function () {
|
@ -1,12 +1,12 @@
|
|||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
|
|
||||||
const { AppSubUrl, heatmapUser } = window.config;
|
const {AppSubUrl, heatmapUser} = window.config;
|
||||||
|
|
||||||
export default async function initHeatmap() {
|
export default async function initHeatmap() {
|
||||||
const el = document.getElementById('user-heatmap');
|
const el = document.getElementById('user-heatmap');
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
|
|
||||||
const { CalendarHeatmap } = await import(/* webpackChunkName: "userheatmap" */'vue-calendar-heatmap');
|
const {CalendarHeatmap} = await import(/* webpackChunkName: "userheatmap" */'vue-calendar-heatmap');
|
||||||
Vue.component('calendarHeatmap', CalendarHeatmap);
|
Vue.component('calendarHeatmap', CalendarHeatmap);
|
||||||
|
|
||||||
const vueDelimeters = ['${', '}'];
|
const vueDelimeters = ['${', '}'];
|
||||||
@ -59,7 +59,7 @@ export default async function initHeatmap() {
|
|||||||
const chartData = [];
|
const chartData = [];
|
||||||
for (let i = 0; i < chartRawData.length; i++) {
|
for (let i = 0; i < chartRawData.length; i++) {
|
||||||
self.totalContributions += chartRawData[i].contributions;
|
self.totalContributions += chartRawData[i].contributions;
|
||||||
chartData[i] = { date: new Date(chartRawData[i].timestamp * 1000), count: chartRawData[i].contributions };
|
chartData[i] = {date: new Date(chartRawData[i].timestamp * 1000), count: chartRawData[i].contributions};
|
||||||
}
|
}
|
||||||
self.values = chartData;
|
self.values = chartData;
|
||||||
self.isLoading = false;
|
self.isLoading = false;
|
@ -2,24 +2,23 @@
|
|||||||
/* exported timeAddManual, toggleStopwatch, cancelStopwatch */
|
/* exported timeAddManual, toggleStopwatch, cancelStopwatch */
|
||||||
/* exported toggleDeadlineForm, setDeadline, updateDeadline, deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */
|
/* exported toggleDeadlineForm, setDeadline, updateDeadline, deleteDependencyModal, cancelCodeComment, onOAuthLoginClick */
|
||||||
|
|
||||||
import './publicPath.js';
|
import './publicpath.js';
|
||||||
import './polyfills.js';
|
import './polyfills.js';
|
||||||
|
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import 'jquery.are-you-sure';
|
import 'jquery.are-you-sure';
|
||||||
import './vendor/semanticDropdown.js';
|
import './vendor/semanticdropdown.js';
|
||||||
import { svg } from './utils.js';
|
import {svg} from './utils.js';
|
||||||
|
|
||||||
import initContextPopups from './features/contextPopup.js';
|
import initContextPopups from './features/contextpopup.js';
|
||||||
import initHighlight from './features/highlight.js';
|
import initHighlight from './features/highlight.js';
|
||||||
import initGitGraph from './features/gitGraph.js';
|
import initGitGraph from './features/gitgraph.js';
|
||||||
import initClipboard from './features/clipboard.js';
|
import initClipboard from './features/clipboard.js';
|
||||||
import initUserHeatmap from './features/userHeatmap.js';
|
import initUserHeatmap from './features/userheatmap.js';
|
||||||
import createDropzone from './features/dropzone.js';
|
import createDropzone from './features/dropzone.js';
|
||||||
|
|
||||||
import ActivityTopAuthors from './components/ActivityTopAuthors.vue';
|
import ActivityTopAuthors from './components/ActivityTopAuthors.vue';
|
||||||
|
|
||||||
const { AppSubUrl, StaticUrlPrefix, csrf } = window.config;
|
const {AppSubUrl, StaticUrlPrefix, csrf} = window.config;
|
||||||
|
|
||||||
function htmlEncode(text) {
|
function htmlEncode(text) {
|
||||||
return jQuery('<div />').text(text).html();
|
return jQuery('<div />').text(text).html();
|
||||||
@ -99,7 +98,6 @@ function initEditDiffTab($form) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function initEditForm() {
|
function initEditForm() {
|
||||||
if ($('.edit.form').length === 0) {
|
if ($('.edit.form').length === 0) {
|
||||||
return;
|
return;
|
||||||
@ -184,7 +182,7 @@ function initReactionSelector(parent) {
|
|||||||
reactions = '.reactions > ';
|
reactions = '.reactions > ';
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.find(`${reactions}a.label`).popup({ position: 'bottom left', metadata: { content: 'title', title: 'none' } });
|
parent.find(`${reactions}a.label`).popup({position: 'bottom left', metadata: {content: 'title', title: 'none'}});
|
||||||
|
|
||||||
parent.find(`.select-reaction > .menu > .item, ${reactions}a.label`).on('click', function (e) {
|
parent.find(`.select-reaction > .menu > .item, ${reactions}a.label`).on('click', function (e) {
|
||||||
const vm = this;
|
const vm = this;
|
||||||
@ -192,9 +190,7 @@ function initReactionSelector(parent) {
|
|||||||
|
|
||||||
if ($(this).hasClass('disabled')) return;
|
if ($(this).hasClass('disabled')) return;
|
||||||
|
|
||||||
const actionURL = $(this).hasClass('item')
|
const actionURL = $(this).hasClass('item') ? $(this).closest('.select-reaction').data('action-url') : $(this).data('action-url');
|
||||||
? $(this).closest('.select-reaction').data('action-url')
|
|
||||||
: $(this).data('action-url');
|
|
||||||
const url = `${actionURL}/${$(this).hasClass('blue') ? 'unreact' : 'react'}`;
|
const url = `${actionURL}/${$(this).hasClass('blue') ? 'unreact' : 'react'}`;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -235,9 +231,7 @@ function insertAtCursor(field, value) {
|
|||||||
if (field.selectionStart || field.selectionStart === 0) {
|
if (field.selectionStart || field.selectionStart === 0) {
|
||||||
const startPos = field.selectionStart;
|
const startPos = field.selectionStart;
|
||||||
const endPos = field.selectionEnd;
|
const endPos = field.selectionEnd;
|
||||||
field.value = field.value.substring(0, startPos)
|
field.value = field.value.substring(0, startPos) + value + field.value.substring(endPos, field.value.length);
|
||||||
+ value
|
|
||||||
+ field.value.substring(endPos, field.value.length);
|
|
||||||
field.selectionStart = startPos + value.length;
|
field.selectionStart = startPos + value.length;
|
||||||
field.selectionEnd = startPos + value.length;
|
field.selectionEnd = startPos + value.length;
|
||||||
} else {
|
} else {
|
||||||
@ -262,13 +256,13 @@ function retrieveImageFromClipboardAsBlob(pasteEvent, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { items } = pasteEvent.clipboardData;
|
const {items} = pasteEvent.clipboardData;
|
||||||
if (typeof items === 'undefined') {
|
if (typeof items === 'undefined') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
if (items[i].type.indexOf('image') === -1) continue;
|
if (!items[i].type.includes('image')) continue;
|
||||||
const blob = items[i].getAsFile();
|
const blob = items[i].getAsFile();
|
||||||
|
|
||||||
if (typeof (callback) === 'function') {
|
if (typeof (callback) === 'function') {
|
||||||
@ -282,11 +276,11 @@ function retrieveImageFromClipboardAsBlob(pasteEvent, callback) {
|
|||||||
function uploadFile(file, callback) {
|
function uploadFile(file, callback) {
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
xhr.onload = function () {
|
xhr.addEventListener('load', () => {
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
callback(xhr.responseText);
|
callback(xhr.responseText);
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
xhr.open('post', `${AppSubUrl}/attachments`, true);
|
xhr.open('post', `${AppSubUrl}/attachments`, true);
|
||||||
xhr.setRequestHeader('X-Csrf-Token', csrf);
|
xhr.setRequestHeader('X-Csrf-Token', csrf);
|
||||||
@ -493,8 +487,8 @@ function initCommentForm() {
|
|||||||
htmlEncode($(this).text())}</a>`);
|
htmlEncode($(this).text())}</a>`);
|
||||||
break;
|
break;
|
||||||
case '#assignee_id':
|
case '#assignee_id':
|
||||||
$list.find('.selected').html(`<a class="item" href=${$(this).data('href')}>`
|
$list.find('.selected').html(`<a class="item" href=${$(this).data('href')}>` +
|
||||||
+ `<img class="ui avatar image" src=${$(this).data('avatar')}>${
|
`<img class="ui avatar image" src=${$(this).data('avatar')}>${
|
||||||
htmlEncode($(this).text())}</a>`);
|
htmlEncode($(this).text())}</a>`);
|
||||||
}
|
}
|
||||||
$(`.ui${select_id}.list .no-select`).addClass('hide');
|
$(`.ui${select_id}.list .no-select`).addClass('hide');
|
||||||
@ -654,7 +648,7 @@ function initRepository() {
|
|||||||
window.location.href = $choice.data('url');
|
window.location.href = $choice.data('url');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
message: { noResults: $dropdown.data('no-results') }
|
message: {noResults: $dropdown.data('no-results')}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -797,13 +791,11 @@ function initRepository() {
|
|||||||
$.post(update_url, {
|
$.post(update_url, {
|
||||||
_csrf: csrf,
|
_csrf: csrf,
|
||||||
target_branch: targetBranch
|
target_branch: targetBranch
|
||||||
})
|
}).success((data) => {
|
||||||
.success((data) => {
|
$branchTarget.text(data.base_branch);
|
||||||
$branchTarget.text(data.base_branch);
|
}).always(() => {
|
||||||
})
|
reload();
|
||||||
.always(() => {
|
});
|
||||||
reload();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const pullrequest_target_update_url = $(this).data('target-update-url');
|
const pullrequest_target_update_url = $(this).data('target-update-url');
|
||||||
@ -814,8 +806,7 @@ function initRepository() {
|
|||||||
$.post($(this).data('update-url'), {
|
$.post($(this).data('update-url'), {
|
||||||
_csrf: csrf,
|
_csrf: csrf,
|
||||||
title: $editInput.val()
|
title: $editInput.val()
|
||||||
},
|
}, (data) => {
|
||||||
(data) => {
|
|
||||||
$editInput.val(data.title);
|
$editInput.val(data.title);
|
||||||
$issueTitle.text(data.title);
|
$issueTitle.text(data.title);
|
||||||
pullrequest_targetbranch_change(pullrequest_target_update_url);
|
pullrequest_targetbranch_change(pullrequest_target_update_url);
|
||||||
@ -887,7 +878,7 @@ function initRepository() {
|
|||||||
const filenameDict = {};
|
const filenameDict = {};
|
||||||
dz = await createDropzone($dropzone[0], {
|
dz = await createDropzone($dropzone[0], {
|
||||||
url: $dropzone.data('upload-url'),
|
url: $dropzone.data('upload-url'),
|
||||||
headers: { 'X-Csrf-Token': csrf },
|
headers: {'X-Csrf-Token': csrf},
|
||||||
maxFiles: $dropzone.data('max-file'),
|
maxFiles: $dropzone.data('max-file'),
|
||||||
maxFilesize: $dropzone.data('max-size'),
|
maxFilesize: $dropzone.data('max-size'),
|
||||||
acceptedFiles: ($dropzone.data('accepts') === '*/*') ? null : $dropzone.data('accepts'),
|
acceptedFiles: ($dropzone.data('accepts') === '*/*') ? null : $dropzone.data('accepts'),
|
||||||
@ -1142,8 +1133,8 @@ function initMigration() {
|
|||||||
const toggleMigrations = function () {
|
const toggleMigrations = function () {
|
||||||
const authUserName = $('#auth_username').val();
|
const authUserName = $('#auth_username').val();
|
||||||
const cloneAddr = $('#clone_addr').val();
|
const cloneAddr = $('#clone_addr').val();
|
||||||
if (!$('#mirror').is(':checked') && (authUserName && authUserName.length > 0)
|
if (!$('#mirror').is(':checked') && (authUserName && authUserName.length > 0) &&
|
||||||
&& (cloneAddr !== undefined && (cloneAddr.startsWith('https://github.com') || cloneAddr.startsWith('http://github.com')))) {
|
(cloneAddr !== undefined && (cloneAddr.startsWith('https://github.com') || cloneAddr.startsWith('http://github.com')))) {
|
||||||
$('#migrate_items').show();
|
$('#migrate_items').show();
|
||||||
} else {
|
} else {
|
||||||
$('#migrate_items').hide();
|
$('#migrate_items').hide();
|
||||||
@ -1203,8 +1194,7 @@ function initPullRequestReview() {
|
|||||||
.on('mouseenter', function () {
|
.on('mouseenter', function () {
|
||||||
const parent = $(this).closest('td');
|
const parent = $(this).closest('td');
|
||||||
$(this).closest('tr').addClass(
|
$(this).closest('tr').addClass(
|
||||||
parent.hasClass('lines-num-old') || parent.hasClass('lines-code-old')
|
parent.hasClass('lines-num-old') || parent.hasClass('lines-code-old') ? 'focus-lines-old' : 'focus-lines-new'
|
||||||
? 'focus-lines-old' : 'focus-lines-new'
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.on('mouseleave', function () {
|
.on('mouseleave', function () {
|
||||||
@ -1225,8 +1215,8 @@ function initPullRequestReview() {
|
|||||||
let ntr = tr.next();
|
let ntr = tr.next();
|
||||||
if (!ntr.hasClass('add-comment')) {
|
if (!ntr.hasClass('add-comment')) {
|
||||||
ntr = $(`<tr class="add-comment">${
|
ntr = $(`<tr class="add-comment">${
|
||||||
isSplit ? '<td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-left"></td><td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-right"></td>'
|
isSplit ? '<td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-left"></td><td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-right"></td>' :
|
||||||
: '<td class="lines-num"></td><td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-left add-comment-right"></td>'
|
'<td class="lines-num"></td><td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-left add-comment-right"></td>'
|
||||||
}</tr>`);
|
}</tr>`);
|
||||||
tr.after(ntr);
|
tr.after(ntr);
|
||||||
}
|
}
|
||||||
@ -1297,7 +1287,7 @@ function initWikiForm() {
|
|||||||
// FIXME: still send render request when return back to edit mode
|
// FIXME: still send render request when return back to edit mode
|
||||||
const render = function () {
|
const render = function () {
|
||||||
sideBySideChanges = 0;
|
sideBySideChanges = 0;
|
||||||
if (sideBySideTimeout != null) {
|
if (sideBySideTimeout !== null) {
|
||||||
clearTimeout(sideBySideTimeout);
|
clearTimeout(sideBySideTimeout);
|
||||||
sideBySideTimeout = null;
|
sideBySideTimeout = null;
|
||||||
}
|
}
|
||||||
@ -1306,8 +1296,7 @@ function initWikiForm() {
|
|||||||
mode: 'gfm',
|
mode: 'gfm',
|
||||||
context: $editArea.data('context'),
|
context: $editArea.data('context'),
|
||||||
text: plainText
|
text: plainText
|
||||||
},
|
}, (data) => {
|
||||||
(data) => {
|
|
||||||
preview.innerHTML = `<div class="markdown ui segment">${data}</div>`;
|
preview.innerHTML = `<div class="markdown ui segment">${data}</div>`;
|
||||||
emojify.run($('.editor-preview')[0]);
|
emojify.run($('.editor-preview')[0]);
|
||||||
$(preview).find('pre code').each((_, e) => {
|
$(preview).find('pre code').each((_, e) => {
|
||||||
@ -1324,7 +1313,7 @@ function initWikiForm() {
|
|||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
// or delay preview by timeout
|
// or delay preview by timeout
|
||||||
if (sideBySideTimeout != null) {
|
if (sideBySideTimeout !== null) {
|
||||||
clearTimeout(sideBySideTimeout);
|
clearTimeout(sideBySideTimeout);
|
||||||
sideBySideTimeout = null;
|
sideBySideTimeout = null;
|
||||||
}
|
}
|
||||||
@ -1479,8 +1468,7 @@ function setSimpleMDE($editArea) {
|
|||||||
mode: 'gfm',
|
mode: 'gfm',
|
||||||
context: $editArea.data('context'),
|
context: $editArea.data('context'),
|
||||||
text: plainText
|
text: plainText
|
||||||
},
|
}, (data) => {
|
||||||
(data) => {
|
|
||||||
preview.innerHTML = `<div class="markdown ui segment">${data}</div>`;
|
preview.innerHTML = `<div class="markdown ui segment">${data}</div>`;
|
||||||
emojify.run($('.editor-preview')[0]);
|
emojify.run($('.editor-preview')[0]);
|
||||||
});
|
});
|
||||||
@ -1658,7 +1646,7 @@ function initEditor() {
|
|||||||
apiCall = extension;
|
apiCall = extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previewLink.length && apiCall && previewFileModes && previewFileModes.length && previewFileModes.indexOf(apiCall) >= 0) {
|
if (previewLink.length && apiCall && previewFileModes && previewFileModes.length && previewFileModes.includes(apiCall)) {
|
||||||
dataUrl = previewLink.data('url');
|
dataUrl = previewLink.data('url');
|
||||||
previewLink.data('url', dataUrl.replace(/(.*)\/.*/i, `$1/${mode}`));
|
previewLink.data('url', dataUrl.replace(/(.*)\/.*/i, `$1/${mode}`));
|
||||||
previewLink.show();
|
previewLink.show();
|
||||||
@ -1667,7 +1655,7 @@ function initEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If this file is a Markdown extensions, we will load that editor and return
|
// If this file is a Markdown extensions, we will load that editor and return
|
||||||
if (markdownFileExts.indexOf(extWithDot) >= 0) {
|
if (markdownFileExts.includes(extWithDot)) {
|
||||||
if (setSimpleMDE($editArea)) {
|
if (setSimpleMDE($editArea)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1683,7 +1671,7 @@ function initEditor() {
|
|||||||
CodeMirror.autoLoadMode(codeMirrorEditor, mode);
|
CodeMirror.autoLoadMode(codeMirrorEditor, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lineWrapExtensions.indexOf(extWithDot) >= 0) {
|
if (lineWrapExtensions.includes(extWithDot)) {
|
||||||
codeMirrorEditor.setOption('lineWrapping', true);
|
codeMirrorEditor.setOption('lineWrapping', true);
|
||||||
} else {
|
} else {
|
||||||
codeMirrorEditor.setOption('lineWrapping', false);
|
codeMirrorEditor.setOption('lineWrapping', false);
|
||||||
@ -1708,7 +1696,7 @@ function initEditor() {
|
|||||||
// - https://codemirror.net/doc/manual.html#keymaps
|
// - https://codemirror.net/doc/manual.html#keymaps
|
||||||
codeMirrorEditor.setOption('extraKeys', {
|
codeMirrorEditor.setOption('extraKeys', {
|
||||||
Tab(cm) {
|
Tab(cm) {
|
||||||
const spaces = Array(parseInt(cm.getOption('indentUnit')) + 1).join(' ');
|
const spaces = new Array(parseInt(cm.getOption('indentUnit')) + 1).join(' ');
|
||||||
cm.replaceSelection(spaces);
|
cm.replaceSelection(spaces);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -2071,7 +2059,7 @@ function searchUsers() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return { results: items };
|
return {results: items};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
searchFields: ['login', 'full_name'],
|
searchFields: ['login', 'full_name'],
|
||||||
@ -2085,7 +2073,7 @@ function searchTeams() {
|
|||||||
minCharacters: 2,
|
minCharacters: 2,
|
||||||
apiSettings: {
|
apiSettings: {
|
||||||
url: `${AppSubUrl}/api/v1/orgs/${$searchTeamBox.data('org')}/teams/search?q={query}`,
|
url: `${AppSubUrl}/api/v1/orgs/${$searchTeamBox.data('org')}/teams/search?q={query}`,
|
||||||
headers: { 'X-Csrf-Token': csrf },
|
headers: {'X-Csrf-Token': csrf},
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
const items = [];
|
const items = [];
|
||||||
$.each(response.data, (_i, item) => {
|
$.each(response.data, (_i, item) => {
|
||||||
@ -2095,7 +2083,7 @@ function searchTeams() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return { results: items };
|
return {results: items};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
searchFields: ['name', 'description'],
|
searchFields: ['name', 'description'],
|
||||||
@ -2118,7 +2106,7 @@ function searchRepositories() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return { results: items };
|
return {results: items};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
searchFields: ['full_name'],
|
searchFields: ['full_name'],
|
||||||
@ -2153,7 +2141,7 @@ function initCodeView() {
|
|||||||
}
|
}
|
||||||
}).trigger('hashchange');
|
}).trigger('hashchange');
|
||||||
}
|
}
|
||||||
$('.fold-code').on('click', ({ target }) => {
|
$('.fold-code').on('click', ({target}) => {
|
||||||
const box = target.closest('.file-content');
|
const box = target.closest('.file-content');
|
||||||
const folded = box.dataset.folded !== 'true';
|
const folded = box.dataset.folded !== 'true';
|
||||||
target.classList.add(`fa-chevron-${folded ? 'right' : 'down'}`);
|
target.classList.add(`fa-chevron-${folded ? 'right' : 'down'}`);
|
||||||
@ -2165,11 +2153,11 @@ function initCodeView() {
|
|||||||
const $row = $blob.parent().parent();
|
const $row = $blob.parent().parent();
|
||||||
$.get(`${$blob.data('url')}?${$blob.data('query')}&anchor=${$blob.data('anchor')}`, (blob) => {
|
$.get(`${$blob.data('url')}?${$blob.data('query')}&anchor=${$blob.data('anchor')}`, (blob) => {
|
||||||
$row.replaceWith(blob);
|
$row.replaceWith(blob);
|
||||||
$(`[data-anchor="${$blob.data('anchor')}"]`).on('click', (e) => { insertBlobExcerpt(e); });
|
$(`[data-anchor="${$blob.data('anchor')}"]`).on('click', (e) => { insertBlobExcerpt(e) });
|
||||||
$('.diff-detail-box.ui.sticky').sticky();
|
$('.diff-detail-box.ui.sticky').sticky();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$('.ui.blob-excerpt').on('click', (e) => { insertBlobExcerpt(e); });
|
$('.ui.blob-excerpt').on('click', (e) => { insertBlobExcerpt(e) });
|
||||||
}
|
}
|
||||||
|
|
||||||
function initU2FAuth() {
|
function initU2FAuth() {
|
||||||
@ -2198,7 +2186,7 @@ function u2fSigned(resp) {
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: `${AppSubUrl}/user/u2f/sign`,
|
url: `${AppSubUrl}/user/u2f/sign`,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
headers: { 'X-Csrf-Token': csrf },
|
headers: {'X-Csrf-Token': csrf},
|
||||||
data: JSON.stringify(resp),
|
data: JSON.stringify(resp),
|
||||||
contentType: 'application/json; charset=utf-8',
|
contentType: 'application/json; charset=utf-8',
|
||||||
}).done((res) => {
|
}).done((res) => {
|
||||||
@ -2215,7 +2203,7 @@ function u2fRegistered(resp) {
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: `${AppSubUrl}/user/settings/security/u2f/register`,
|
url: `${AppSubUrl}/user/settings/security/u2f/register`,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
headers: { 'X-Csrf-Token': csrf },
|
headers: {'X-Csrf-Token': csrf},
|
||||||
data: JSON.stringify(resp),
|
data: JSON.stringify(resp),
|
||||||
contentType: 'application/json; charset=utf-8',
|
contentType: 'application/json; charset=utf-8',
|
||||||
success() {
|
success() {
|
||||||
@ -2238,7 +2226,6 @@ function checkError(resp) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function u2fError(errorType) {
|
function u2fError(errorType) {
|
||||||
const u2fErrors = {
|
const u2fErrors = {
|
||||||
browser: $('#unsupported-browser'),
|
browser: $('#unsupported-browser'),
|
||||||
@ -2259,8 +2246,8 @@ function u2fError(errorType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initU2FRegister() {
|
function initU2FRegister() {
|
||||||
$('#register-device').modal({ allowMultiple: false });
|
$('#register-device').modal({allowMultiple: false});
|
||||||
$('#u2f-error').modal({ allowMultiple: false });
|
$('#u2f-error').modal({allowMultiple: false});
|
||||||
$('#register-security-key').on('click', (e) => {
|
$('#register-security-key').on('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
u2fApi.ensureSupport()
|
u2fApi.ensureSupport()
|
||||||
@ -2337,7 +2324,7 @@ function initTemplateSearch() {
|
|||||||
apiSettings: {
|
apiSettings: {
|
||||||
url: `${AppSubUrl}/api/v1/repos/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
|
url: `${AppSubUrl}/api/v1/repos/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
const filteredResponse = { success: true, results: [] };
|
const filteredResponse = {success: true, results: []};
|
||||||
filteredResponse.results.push({
|
filteredResponse.results.push({
|
||||||
name: '',
|
name: '',
|
||||||
value: ''
|
value: ''
|
||||||
@ -2417,7 +2404,7 @@ $(document).ready(async () => {
|
|||||||
|
|
||||||
await createDropzone('#dropzone', {
|
await createDropzone('#dropzone', {
|
||||||
url: $dropzone.data('upload-url'),
|
url: $dropzone.data('upload-url'),
|
||||||
headers: { 'X-Csrf-Token': csrf },
|
headers: {'X-Csrf-Token': csrf},
|
||||||
maxFiles: $dropzone.data('max-file'),
|
maxFiles: $dropzone.data('max-file'),
|
||||||
maxFilesize: $dropzone.data('max-size'),
|
maxFilesize: $dropzone.data('max-size'),
|
||||||
acceptedFiles: ($dropzone.data('accepts') === '*/*') ? null : $dropzone.data('accepts'),
|
acceptedFiles: ($dropzone.data('accepts') === '*/*') ? null : $dropzone.data('accepts'),
|
||||||
@ -2515,12 +2502,12 @@ $(document).ready(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('.issue-action').click(function () {
|
$('.issue-action').click(function () {
|
||||||
let { action } = this.dataset;
|
let {action} = this.dataset;
|
||||||
let { elementId } = this.dataset;
|
let {elementId} = this.dataset;
|
||||||
const issueIDs = $('.issue-checkbox').children('input:checked').map(function () {
|
const issueIDs = $('.issue-checkbox').children('input:checked').map(function () {
|
||||||
return this.dataset.issueId;
|
return this.dataset.issueId;
|
||||||
}).get().join();
|
}).get().join();
|
||||||
const { url } = this.dataset;
|
const {url} = this.dataset;
|
||||||
if (elementId === '0' && url.substr(-9) === '/assignee') {
|
if (elementId === '0' && url.substr(-9) === '/assignee') {
|
||||||
elementId = '';
|
elementId = '';
|
||||||
action = 'clear';
|
action = 'clear';
|
||||||
@ -2529,7 +2516,7 @@ $(document).ready(async () => {
|
|||||||
// NOTICE: This reset of checkbox state targets Firefox caching behaviour, as the checkboxes stay checked after reload
|
// NOTICE: This reset of checkbox state targets Firefox caching behaviour, as the checkboxes stay checked after reload
|
||||||
if (action === 'close' || action === 'open') {
|
if (action === 'close' || action === 'open') {
|
||||||
// uncheck all checkboxes
|
// uncheck all checkboxes
|
||||||
$('.issue-checkbox input[type="checkbox"]').each((_, e) => { e.checked = false; });
|
$('.issue-checkbox input[type="checkbox"]').each((_, e) => { e.checked = false });
|
||||||
}
|
}
|
||||||
reload();
|
reload();
|
||||||
});
|
});
|
||||||
@ -3031,8 +3018,8 @@ function initFilterBranchTagDropdown(selector) {
|
|||||||
const vm = this;
|
const vm = this;
|
||||||
|
|
||||||
const items = vm.items.filter((item) => {
|
const items = vm.items.filter((item) => {
|
||||||
return ((vm.mode === 'branches' && item.branch) || (vm.mode === 'tags' && item.tag))
|
return ((vm.mode === 'branches' && item.branch) || (vm.mode === 'tags' && item.tag)) &&
|
||||||
&& (!vm.searchTerm || item.name.toLowerCase().indexOf(vm.searchTerm.toLowerCase()) >= 0);
|
(!vm.searchTerm || item.name.toLowerCase().includes(vm.searchTerm.toLowerCase()));
|
||||||
});
|
});
|
||||||
|
|
||||||
vm.active = (items.length === 0 && vm.showCreateNewBranch ? 0 : -1);
|
vm.active = (items.length === 0 && vm.showCreateNewBranch ? 0 : -1);
|
||||||
@ -3226,7 +3213,7 @@ function initTopicbar() {
|
|||||||
if (xhr.responseJSON.invalidTopics.length > 0) {
|
if (xhr.responseJSON.invalidTopics.length > 0) {
|
||||||
topicPrompts.formatPrompt = xhr.responseJSON.message;
|
topicPrompts.formatPrompt = xhr.responseJSON.message;
|
||||||
|
|
||||||
const { invalidTopics } = xhr.responseJSON;
|
const {invalidTopics} = xhr.responseJSON;
|
||||||
const topicLables = topicDropdown.children('a.ui.label');
|
const topicLables = topicDropdown.children('a.ui.label');
|
||||||
|
|
||||||
topics.split(',').forEach((value, index) => {
|
topics.split(',').forEach((value, index) => {
|
||||||
@ -3248,7 +3235,7 @@ function initTopicbar() {
|
|||||||
topicDropdown.dropdown({
|
topicDropdown.dropdown({
|
||||||
allowAdditions: true,
|
allowAdditions: true,
|
||||||
forceSelection: false,
|
forceSelection: false,
|
||||||
fields: { name: 'description', value: 'data-value' },
|
fields: {name: 'description', value: 'data-value'},
|
||||||
saveRemoteData: false,
|
saveRemoteData: false,
|
||||||
label: {
|
label: {
|
||||||
transition: 'horizontal flip',
|
transition: 'horizontal flip',
|
||||||
@ -3276,20 +3263,20 @@ function initTopicbar() {
|
|||||||
const query = stripTags(this.urlData.query.trim());
|
const query = stripTags(this.urlData.query.trim());
|
||||||
let found_query = false;
|
let found_query = false;
|
||||||
const current_topics = [];
|
const current_topics = [];
|
||||||
topicDropdown.find('div.label.visible.topic,a.label.visible').each((_, e) => { current_topics.push(e.dataset.value); });
|
topicDropdown.find('div.label.visible.topic,a.label.visible').each((_, e) => { current_topics.push(e.dataset.value) });
|
||||||
|
|
||||||
if (res.topics) {
|
if (res.topics) {
|
||||||
let found = false;
|
let found = false;
|
||||||
for (let i = 0; i < res.topics.length; i++) {
|
for (let i = 0; i < res.topics.length; i++) {
|
||||||
// skip currently added tags
|
// skip currently added tags
|
||||||
if (current_topics.indexOf(res.topics[i].topic_name) !== -1) {
|
if (current_topics.includes(res.topics[i].topic_name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.topics[i].topic_name.toLowerCase() === query.toLowerCase()) {
|
if (res.topics[i].topic_name.toLowerCase() === query.toLowerCase()) {
|
||||||
found_query = true;
|
found_query = true;
|
||||||
}
|
}
|
||||||
formattedResponse.results.push({ description: res.topics[i].topic_name, 'data-value': res.topics[i].topic_name });
|
formattedResponse.results.push({description: res.topics[i].topic_name, 'data-value': res.topics[i].topic_name});
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
formattedResponse.success = found;
|
formattedResponse.success = found;
|
||||||
@ -3297,7 +3284,7 @@ function initTopicbar() {
|
|||||||
|
|
||||||
if (query.length > 0 && !found_query) {
|
if (query.length > 0 && !found_query) {
|
||||||
formattedResponse.success = true;
|
formattedResponse.success = true;
|
||||||
formattedResponse.results.unshift({ description: query, 'data-value': query });
|
formattedResponse.results.unshift({description: query, 'data-value': query});
|
||||||
} else if (query.length > 0 && found_query) {
|
} else if (query.length > 0 && found_query) {
|
||||||
formattedResponse.results.sort((a, b) => {
|
formattedResponse.results.sort((a, b) => {
|
||||||
if (a.description.toLowerCase() === query.toLowerCase()) return -1;
|
if (a.description.toLowerCase() === query.toLowerCase()) return -1;
|
||||||
@ -3308,7 +3295,6 @@ function initTopicbar() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return formattedResponse;
|
return formattedResponse;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3427,7 +3413,7 @@ function initIssueList() {
|
|||||||
apiSettings: {
|
apiSettings: {
|
||||||
url: issueSearchUrl,
|
url: issueSearchUrl,
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
const filteredResponse = { success: true, results: [] };
|
const filteredResponse = {success: true, results: []};
|
||||||
const currIssueId = $('#new-dependency-drop-list').data('issue-id');
|
const currIssueId = $('#new-dependency-drop-list').data('issue-id');
|
||||||
// Parse the response from the api to work with our dropdown
|
// Parse the response from the api to work with our dropdown
|
||||||
$.each(response, (_i, issue) => {
|
$.each(response, (_i, issue) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* This sets up webpack's chunk loading to load resources from the 'public'
|
// This sets up webpack's chunk loading to load resources from the 'public'
|
||||||
directory. This file must be imported before any lazy-loading is being attempted. */
|
// directory. This file must be imported before any lazy-loading is being attempted.
|
||||||
|
|
||||||
if (document.currentScript && document.currentScript.src) {
|
if (document.currentScript && document.currentScript.src) {
|
||||||
const url = new URL(document.currentScript.src);
|
const url = new URL(document.currentScript.src);
|
@ -9,11 +9,11 @@ const PostCSSSafeParser = require('postcss-safe-parser');
|
|||||||
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
|
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
|
||||||
const TerserPlugin = require('terser-webpack-plugin');
|
const TerserPlugin = require('terser-webpack-plugin');
|
||||||
const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
const VueLoaderPlugin = require('vue-loader/lib/plugin');
|
||||||
const { statSync } = require('fs');
|
const {statSync} = require('fs');
|
||||||
const { resolve, parse } = require('path');
|
const {resolve, parse} = require('path');
|
||||||
const { SourceMapDevToolPlugin } = require('webpack');
|
const {SourceMapDevToolPlugin} = require('webpack');
|
||||||
|
|
||||||
const glob = (pattern) => fastGlob.sync(pattern, { cwd: __dirname, absolute: true });
|
const glob = (pattern) => fastGlob.sync(pattern, {cwd: __dirname, absolute: true});
|
||||||
|
|
||||||
const themes = {};
|
const themes = {};
|
||||||
for (const path of glob('web_src/less/themes/*.less')) {
|
for (const path of glob('web_src/less/themes/*.less')) {
|
||||||
@ -157,7 +157,7 @@ module.exports = {
|
|||||||
extract: true,
|
extract: true,
|
||||||
spriteFilename: 'img/svg/icons.svg',
|
spriteFilename: 'img/svg/icons.svg',
|
||||||
symbolId: (path) => {
|
symbolId: (path) => {
|
||||||
const { name } = parse(path);
|
const {name} = parse(path);
|
||||||
if (/@primer[/\\]octicons/.test(path)) {
|
if (/@primer[/\\]octicons/.test(path)) {
|
||||||
return `octicon-${name}`;
|
return `octicon-${name}`;
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ module.exports = {
|
|||||||
}),
|
}),
|
||||||
new CopyPlugin([
|
new CopyPlugin([
|
||||||
// workaround for https://github.com/go-gitea/gitea/issues/10653
|
// workaround for https://github.com/go-gitea/gitea/issues/10653
|
||||||
{ from: 'node_modules/fomantic-ui/dist/semantic.min.css', to: 'fomantic/semantic.min.css' },
|
{from: 'node_modules/fomantic-ui/dist/semantic.min.css', to: 'fomantic/semantic.min.css'},
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
performance: {
|
performance: {
|
||||||
|
Loading…
Reference in New Issue
Block a user