Skip to content

Commit

Permalink
use export function instead of export {}, add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Oct 16, 2021
1 parent b83e577 commit fb14424
Show file tree
Hide file tree
Showing 37 changed files with 86 additions and 203 deletions.
4 changes: 1 addition & 3 deletions web_src/js/components/DashboardRepoList.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ function initVueComponents() {
}


function initDashboardRepoList() {
export function initDashboardRepoList() {
const el = document.getElementById('dashboard-repo-list');
const dashboardRepoListData = pageData.dashboardRepoList || null;
if (!el || !dashboardRepoListData) return;
Expand All @@ -366,5 +366,3 @@ function initDashboardRepoList() {
},
});
}

export {initDashboardRepoList};
5 changes: 2 additions & 3 deletions web_src/js/components/RepoActivityTopAuthors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ const sfc = {
}
};
function initRepoActivityTopAuthorsChart() {
export function initRepoActivityTopAuthorsChart() {
initVueApp('#repo-activity-top-authors-chart', sfc);
}
export default sfc;
export {initRepoActivityTopAuthorsChart};
export default sfc; // this line is necessary to activate the IDE's Vue plugin
</script>
7 changes: 3 additions & 4 deletions web_src/js/components/RepoBranchTagDropdown.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue';
import {vueDelimiters} from './VueComponentLoader.js';

function initRepoBranchTagDropdown(selector) {
export function initRepoBranchTagDropdown(selector) {
$(selector).each(function () {
const $dropdown = $(this);
const $data = $dropdown.find('.data');
Expand All @@ -26,7 +27,7 @@ function initRepoBranchTagDropdown(selector) {
$data.remove();
new Vue({
el: this,
delimiters: ['${', '}'],
delimiters: vueDelimiters,
data,
computed: {
filteredItems() {
Expand Down Expand Up @@ -157,5 +158,3 @@ function initRepoBranchTagDropdown(selector) {
});
});
}

export {initRepoBranchTagDropdown};
11 changes: 4 additions & 7 deletions web_src/js/components/VueComponentLoader.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Vue from 'vue';
import {svgs} from '../svg.js';

const vueDelimiters = ['${', '}'];
export const vueDelimiters = ['${', '}'];

let vueEnvInited = false;
function initVueEnv() {
export function initVueEnv() {
if (vueEnvInited) return;
vueEnvInited = true;

Expand All @@ -14,7 +14,7 @@ function initVueEnv() {
}

let vueSvgInited = false;
function initVueSvg() {
export function initVueSvg() {
if (vueSvgInited) return;
vueSvgInited = true;

Expand All @@ -36,8 +36,7 @@ function initVueSvg() {
}
}


function initVueApp(el, opts = {}) {
export function initVueApp(el, opts = {}) {
if (typeof el === 'string') {
el = document.querySelector(el);
}
Expand All @@ -48,5 +47,3 @@ function initVueApp(el, opts = {}) {
delimiters: vueDelimiters,
}, opts));
}

export {vueDelimiters, initVueEnv, initVueSvg, initVueApp};
4 changes: 1 addition & 3 deletions web_src/js/features/admin-common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {csrf} = window.config;

function initAdminCommon() {
export function initAdminCommon() {
if ($('.admin').length === 0) {
return;
}
Expand Down Expand Up @@ -212,5 +212,3 @@ function initAdminCommon() {
});
}
}

export {initAdminCommon};
4 changes: 1 addition & 3 deletions web_src/js/features/admin-emails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function initAdminEmails() {
export function initAdminEmails() {
function linkEmailAction(e) {
const $this = $(this);
$('#form-uid').val($this.data('uid'));
Expand All @@ -10,5 +10,3 @@ function initAdminEmails() {
}
$('.link-email-action').on('click', linkEmailAction);
}

export {initAdminEmails};
30 changes: 9 additions & 21 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import 'jquery.are-you-sure';

const {csrf} = window.config;

function initGlobalFormDirtyLeaveConfirm() {
export function initGlobalFormDirtyLeaveConfirm() {
// Warn users that try to leave a page after entering data into a form.
// Except on sign-in pages, and for forms marked as 'ignore-dirty'.
if ($('.user.signin').length === 0) {
$('form:not(.ignore-dirty)').areYouSure();
}
}

function initHeadNavbarContentToggle() {
export function initHeadNavbarContentToggle() {
const content = $('#navbar');
const toggle = $('#navbar-expand-toggle');
let isExpanded = false;
Expand All @@ -30,7 +30,7 @@ function initHeadNavbarContentToggle() {
});
}

function initFootLanguageMenu() {
export function initFootLanguageMenu() {
function linkLanguageAction() {
const $this = $(this);
$.post($this.data('url')).always(() => {
Expand All @@ -42,23 +42,23 @@ function initFootLanguageMenu() {
}


function initGlobalEnterQuickSubmit() {
export function initGlobalEnterQuickSubmit() {
$('.js-quick-submit').on('keydown', function (e) {
if (((e.ctrlKey && !e.altKey) || e.metaKey) && (e.keyCode === 13 || e.keyCode === 10)) {
$(this).closest('form').trigger('submit');
}
});
}

function initGlobalButtonClickOnEnter() {
export function initGlobalButtonClickOnEnter() {
$(document).on('keypress', '.ui.button', (e) => {
if (e.keyCode === 13 || e.keyCode === 32) { // enter key or space bar
$(e.target).trigger('click');
}
});
}

function initGlobalCommon() {
export function initGlobalCommon() {
// Show exact time
$('.time-since').each(function () {
$(this)
Expand Down Expand Up @@ -130,7 +130,7 @@ function initGlobalCommon() {
});
}

async function initGlobalDropzone() {
export async function initGlobalDropzone() {
// Dropzone
for (const el of document.querySelectorAll('.dropzone')) {
const $dropzone = $(el);
Expand Down Expand Up @@ -168,7 +168,7 @@ async function initGlobalDropzone() {
}
}

function initGlobalLinkActions() {
export function initGlobalLinkActions() {
function showDeletePopup() {
const $this = $(this);
const dataArray = $this.data();
Expand Down Expand Up @@ -278,7 +278,7 @@ function initGlobalLinkActions() {
});
}

function initGlobalButtons() {
export function initGlobalButtons() {
$('.show-panel.button').on('click', function () {
$($(this).data('panel')).show();
});
Expand All @@ -304,15 +304,3 @@ function initGlobalButtons() {
});
});
}

export {
initHeadNavbarContentToggle,
initFootLanguageMenu,
initGlobalEnterQuickSubmit,
initGlobalFormDirtyLeaveConfirm,
initGlobalButtonClickOnEnter,
initGlobalCommon,
initGlobalDropzone,
initGlobalLinkActions,
initGlobalButtons,
};
4 changes: 1 addition & 3 deletions web_src/js/features/common-issue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {updateIssuesMeta} from './repo-issue.js';

function initCommonIssue() {
export function initCommonIssue() {
$('.issue-checkbox').on('click', () => {
const numChecked = $('.issue-checkbox').children('input:checked').length;
if (numChecked > 0) {
Expand Down Expand Up @@ -38,5 +38,3 @@ function initCommonIssue() {
$(e).trigger('click');
});
}

export {initCommonIssue};
5 changes: 1 addition & 4 deletions web_src/js/features/common-organization.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {initCompLabelEdit} from './comp/LabelEdit.js';

function initCommonOrganization() {
export function initCommonOrganization() {
if ($('.organization').length === 0) {
return;
}

// Options
if ($('.organization.settings.options').length > 0) {
$('#org_name').on('keyup', function () {
const $prompt = $('#org-name-change-prompt');
Expand All @@ -23,5 +22,3 @@ function initCommonOrganization() {
// Labels
initCompLabelEdit('.organization.settings.labels');
}

export {initCommonOrganization};
4 changes: 1 addition & 3 deletions web_src/js/features/comp/ColorPicker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import createColorPicker from '../colorpicker.js';

function initCompColorPicker() {
export function initCompColorPicker() {
createColorPicker($('.color-picker'));

$('.precolors .color').on('click', function () {
Expand All @@ -9,5 +9,3 @@ function initCompColorPicker() {
$('.minicolors-swatch-color').css('background-color', color_hex);
});
}

export {initCompColorPicker};
4 changes: 1 addition & 3 deletions web_src/js/features/comp/CommentSimpleMDE.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import attachTribute from '../tribute.js';

function createCommentSimpleMDE($editArea) {
export function createCommentSimpleMDE($editArea) {
if ($editArea.length === 0) {
return null;
}
Expand Down Expand Up @@ -70,5 +70,3 @@ function createCommentSimpleMDE($editArea) {
$(simplemde.codemirror.getInputField()).data('simplemde', simplemde);
return simplemde;
}

export {createCommentSimpleMDE};
6 changes: 2 additions & 4 deletions web_src/js/features/comp/ImagePaste.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function replaceAndKeepCursor(field, oldval, newval) {
}
}

function initCompImagePaste($target) {
export function initCompImagePaste($target) {
$target.each(function () {
const dropzone = this.querySelector('.dropzone');
if (!dropzone) {
Expand All @@ -76,7 +76,7 @@ function initCompImagePaste($target) {
});
}

function initSimpleMDEImagePaste(simplemde, dropzone, files) {
export function initSimpleMDEImagePaste(simplemde, dropzone, files) {
const uploadUrl = dropzone.dataset.uploadUrl;
simplemde.codemirror.on('paste', async (_, e) => {
for (const img of clipboardPastedImages(e)) {
Expand All @@ -89,5 +89,3 @@ function initSimpleMDEImagePaste(simplemde, dropzone, files) {
}
});
}

export {initCompImagePaste, initSimpleMDEImagePaste};
4 changes: 1 addition & 3 deletions web_src/js/features/comp/LabelEdit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {initCompColorPicker} from './ColorPicker.js';

function initCompLabelEdit(selector) {
export function initCompLabelEdit(selector) {
if (!$(selector).length) return;
// Create label
const $newLabelPanel = $('.new-label.segment');
Expand Down Expand Up @@ -28,5 +28,3 @@ function initCompLabelEdit(selector) {
return false;
});
}

export {initCompLabelEdit};
4 changes: 1 addition & 3 deletions web_src/js/features/comp/MarkupContentPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {initMarkupContent} from '../../markup/content.js';

const {csrf} = window.config;

function initCompMarkupContentPreviewTab($form) {
export function initCompMarkupContentPreviewTab($form) {
const $tabMenu = $form.find('.tabular.menu');
$tabMenu.find('.item').tab();
$tabMenu.find(`.item[data-tab="${$tabMenu.data('preview')}"]`).on('click', function () {
Expand All @@ -19,5 +19,3 @@ function initCompMarkupContentPreviewTab($form) {
});
});
}

export {initCompMarkupContentPreviewTab};
4 changes: 1 addition & 3 deletions web_src/js/features/comp/ReactionSelector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {csrf} = window.config;

function initCompReactionSelector(parent) {
export function initCompReactionSelector(parent) {
let reactions = '';
if (!parent) {
parent = $(document);
Expand Down Expand Up @@ -46,5 +46,3 @@ function initCompReactionSelector(parent) {
});
});
}

export {initCompReactionSelector};
4 changes: 1 addition & 3 deletions web_src/js/features/comp/SearchUserBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {htmlEscape} from 'escape-goat';

const {AppSubUrl} = window.config;

function initSearchUserBox() {
export function initSearchUserBox() {
const $searchUserBox = $('#search-user-box');
$searchUserBox.search({
minCharacters: 2,
Expand Down Expand Up @@ -34,5 +34,3 @@ function initSearchUserBox() {
showNoResults: false
});
}

export {initSearchUserBox};
4 changes: 1 addition & 3 deletions web_src/js/features/comp/WebHookEditor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {csrf} = window.config;

function initWebHookEditor() {
export function initWebHookEditor() {
if ($('.new.webhook').length === 0) {
return;
}
Expand Down Expand Up @@ -38,5 +38,3 @@ function initWebHookEditor() {
);
});
}

export {initWebHookEditor};
5 changes: 1 addition & 4 deletions web_src/js/features/install.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

function initInstall() {
export function initInstall() {
if ($('.install').length === 0) {
return;
}
Expand Down Expand Up @@ -90,5 +89,3 @@ function initInstall() {
}
});
}

export {initInstall};
Loading

0 comments on commit fb14424

Please sign in to comment.