Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import sortablejs only once #25936

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions web_src/js/features/repo-issue-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import $ from 'jquery';
import {updateIssuesMeta} from './repo-issue.js';
import {toggleElem} from '../utils/dom.js';
import {htmlEscape} from 'escape-goat';
import {Sortable} from 'sortablejs';
import {confirmModal} from './comp/ConfirmModal.js';
import {showErrorToast} from '../modules/toast.js';
import {createSortable} from '../modules/sortable.js';

function initRepoIssueListCheckboxes() {
const $issueSelectAll = $('.issue-checkbox-all');
Expand Down Expand Up @@ -176,7 +176,7 @@ async function pinMoveEnd(e) {
});
}

function initIssuePinSort() {
async function initIssuePinSort() {
const pinDiv = document.getElementById('issue-pins');

if (pinDiv === null) return;
Expand All @@ -189,7 +189,7 @@ function initIssuePinSort() {
// If only one issue pinned, we don't need to make this Sortable
if (pinDiv.children.length < 2) return;

new Sortable(pinDiv, {
createSortable(pinDiv, {
group: 'shared',
animation: 150,
ghostClass: 'card-ghost',
Expand Down
7 changes: 3 additions & 4 deletions web_src/js/features/repo-projects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import $ from 'jquery';
import {useLightTextOnBackground} from '../utils/color.js';
import tinycolor from 'tinycolor2';
import {createSortable} from '../modules/sortable.js';

const {csrfToken} = window.config;

Expand Down Expand Up @@ -55,12 +56,10 @@ async function initRepoProjectSortable() {
const els = document.querySelectorAll('#project-board > .board.sortable');
if (!els.length) return;

const {Sortable} = await import(/* webpackChunkName: "sortable" */'sortablejs');

// the HTML layout is: #project-board > .board > .board-column .board.cards > .board-card.card .content
const mainBoard = els[0];
let boardColumns = mainBoard.getElementsByClassName('board-column');
new Sortable(mainBoard, {
createSortable(mainBoard, {
group: 'board-column',
draggable: '.board-column',
filter: '[data-id="0"]',
Expand Down Expand Up @@ -89,7 +88,7 @@ async function initRepoProjectSortable() {

for (const boardColumn of boardColumns) {
const boardCardList = boardColumn.getElementsByClassName('board')[0];
new Sortable(boardCardList, {
createSortable(boardCardList, {
group: 'shared',
animation: 150,
ghostClass: 'card-ghost',
Expand Down
4 changes: 4 additions & 0 deletions web_src/js/modules/sortable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export async function createSortable(...args) {
const {Sortable} = await import(/* webpackChunkName: "sortablejs" */'sortablejs');
return new Sortable(...args);
}