From b1f1c98f9cb029f2bde7e3bc0af7accd75616edf Mon Sep 17 00:00:00 2001 From: Parnic Date: Tue, 26 Apr 2022 10:09:26 -0500 Subject: [PATCH 1/3] Allow commit status popup on /pulls page The /pulls page doesn't contain a "repository" element, so the early-out here was preventing the commit status popup hook from working. However, the only thing the .repository element is being used for here is determining whether the popup should be on the right or on the left, so we don't actually need the element to exist for the hook to work. Pull request #19375 allows the statuses on /pulls pages to appear clickable, but this commit is required to make the popup actually work there. --- web_src/js/features/repo-legacy.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 185a0014fae2d..a8b3ee6145fab 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -418,11 +418,6 @@ async function onEditContent(event) { } export function initRepository() { - if ($('.repository').length === 0) { - return; - } - - // Commit statuses $('.commit-statuses-trigger').each(function () { const positionRight = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0; @@ -434,6 +429,10 @@ export function initRepository() { position: popupPosition, }); }); + + if ($('.repository').length === 0) { + return; + } // File list and commits if ($('.repository.file.list').length > 0 || $('.branch-dropdown').length > 0 || From dfe2239d0d05b266338541a7260632013f531a92 Mon Sep 17 00:00:00 2001 From: Parnic Date: Tue, 26 Apr 2022 10:41:00 -0500 Subject: [PATCH 2/3] Move commit statuses popup hook to dedicated func --- web_src/js/features/repo-commit.js | 13 +++++++++++++ web_src/js/features/repo-legacy.js | 13 +------------ web_src/js/index.js | 2 ++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/web_src/js/features/repo-commit.js b/web_src/js/features/repo-commit.js index 9a8f1a159509b..a911c173929a4 100644 --- a/web_src/js/features/repo-commit.js +++ b/web_src/js/features/repo-commit.js @@ -49,3 +49,16 @@ export function initRepoCommitLastCommitLoader() { }); }); } + +export function initCommitStatuses() { + $('.commit-statuses-trigger').each(function () { + const positionRight = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0; + const popupPosition = positionRight ? 'right center' : 'left center'; + $(this) + .popup({ + on: 'click', + lastResort: popupPosition, // prevent error message "Popup does not fit within the boundaries of the viewport" + position: popupPosition, + }); + }); +} diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index a8b3ee6145fab..b7e6206e53a95 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -418,22 +418,11 @@ async function onEditContent(event) { } export function initRepository() { - // Commit statuses - $('.commit-statuses-trigger').each(function () { - const positionRight = $('.repository.file.list').length > 0 || $('.repository.diff').length > 0; - const popupPosition = positionRight ? 'right center' : 'left center'; - $(this) - .popup({ - on: 'click', - lastResort: popupPosition, // prevent error message "Popup does not fit within the boundaries of the viewport" - position: popupPosition, - }); - }); - if ($('.repository').length === 0) { return; } + // File list and commits if ($('.repository.file.list').length > 0 || $('.branch-dropdown').length > 0 || $('.repository.commits').length > 0 || $('.repository.release').length > 0) { diff --git a/web_src/js/index.js b/web_src/js/index.js index 18b949e4e62f7..9828222790327 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -165,6 +165,8 @@ $(document).ready(() => { initRepoWikiForm(); initRepository(); + initCommitStatuses(); + initUserAuthLinkAccountView(); initUserAuthOauth2(); initUserAuthWebAuthn(); From 6805b1c8032844cca95a567369f2553ddbed539c Mon Sep 17 00:00:00 2001 From: Parnic Date: Tue, 26 Apr 2022 10:48:16 -0500 Subject: [PATCH 3/3] Add missing import --- web_src/js/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index 9828222790327..f5d72aff93d4d 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -38,7 +38,11 @@ import { initRepoPullRequestMergeInstruction, initRepoPullRequestReview, } from './features/repo-issue.js'; -import {initRepoEllipsisButton, initRepoCommitLastCommitLoader} from './features/repo-commit.js'; +import { + initRepoEllipsisButton, + initRepoCommitLastCommitLoader, + initCommitStatuses, +} from './features/repo-commit.js'; import { checkAppUrl, initFootLanguageMenu,