Skip to content

Commit 38cee1b

Browse files
DrewMLsindresorhus
authored andcommitted
Swap sprint out for jQuery 3.0 slim build (refined-github#252)
1 parent 9b7f1d0 commit 38cee1b

9 files changed

Lines changed: 41 additions & 94 deletions

File tree

extension/content.js

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,28 @@ function addTrendingMenuItem() {
7979
}
8080

8181
function infinitelyMore() {
82-
const btn = $('.ajax-pagination-btn').get(0);
82+
const $btn = $('.ajax-pagination-btn');
8383

8484
// if there's no more button remove unnecessary event listeners
85-
if (!btn) {
86-
window.removeEventListener('scroll', infinitelyMore);
87-
window.removeEventListener('resize', infinitelyMore);
85+
if (!$btn.length) {
86+
$(window).off('scroll.infinite resize.infinite', infinitelyMore);
8887
return;
8988
}
9089

9190
// grab dimensions to see if we should load
9291
const wHeight = window.innerHeight;
9392
const wScroll = window.pageYOffset || document.scrollTop;
94-
const btnOffset = $('.ajax-pagination-btn').offset().top;
93+
const btnOffset = $btn.offset().top;
9594

9695
// smash the button if it's coming close to being in view
9796
if (wScroll > (btnOffset - wHeight)) {
98-
btn.click();
97+
$btn.click();
9998
}
10099
}
101100

102101
function addReadmeEditButton() {
103-
const readmeContainer = $('#readme');
104-
if (!readmeContainer.length) {
102+
const $readmeContainer = $('#readme');
103+
if (!$readmeContainer.length) {
105104
return;
106105
}
107106

@@ -115,18 +114,18 @@ function addReadmeEditButton() {
115114
</a>
116115
</div>`;
117116

118-
readmeContainer.append(editButtonHtml);
117+
$readmeContainer.append(editButtonHtml);
119118
}
120119

121120
function addDeleteForkLink() {
122-
const postMergeContainer = $('#partial-pull-merging');
121+
const $postMergeContainer = $('#partial-pull-merging');
123122

124-
if (postMergeContainer.length > 0) {
125-
const postMergeDescription = $(postMergeContainer).find('.merge-branch-description').get(0);
126-
const forkPath = $(postMergeContainer).attr('data-channel').split(':')[0];
123+
if ($postMergeContainer.length > 0) {
124+
const $postMergeDescription = $postMergeContainer.find('.merge-branch-description');
125+
const forkPath = $postMergeContainer.attr('data-channel').split(':')[0];
127126

128127
if (forkPath !== repoUrl) {
129-
$(postMergeDescription).append(
128+
$postMergeDescription.append(
130129
`<p id="refined-github-delete-fork-link">
131130
<a href="https://github.com/${forkPath}/settings">
132131
<svg aria-hidden="true" class="octicon octicon-repo-forked" height="16" role="img" version="1.1" viewBox="0 0 10 16" width="10"><path d="M8 1c-1.11 0-2 0.89-2 2 0 0.73 0.41 1.38 1 1.72v1.28L5 8 3 6v-1.28c0.59-0.34 1-0.98 1-1.72 0-1.11-0.89-2-2-2S0 1.89 0 3c0 0.73 0.41 1.38 1 1.72v1.78l3 3v1.78c-0.59 0.34-1 0.98-1 1.72 0 1.11 0.89 2 2 2s2-0.89 2-2c0-0.73-0.41-1.38-1-1.72V9.5l3-3V4.72c0.59-0.34 1-0.98 1-1.72 0-1.11-0.89-2-2-2zM2 4.2c-0.66 0-1.2-0.55-1.2-1.2s0.55-1.2 1.2-1.2 1.2 0.55 1.2 1.2-0.55 1.2-1.2 1.2z m3 10c-0.66 0-1.2-0.55-1.2-1.2s0.55-1.2 1.2-1.2 1.2 0.55 1.2 1.2-0.55 1.2-1.2 1.2z m3-10c-0.66 0-1.2-0.55-1.2-1.2s0.55-1.2 1.2-1.2 1.2 0.55 1.2 1.2-0.55 1.2-1.2 1.2z"></path></svg>
@@ -161,9 +160,9 @@ function addPatchDiffLinks() {
161160
commitUrl = commitUrl.replace(/\/pull\/\d+\/commits/, '/commit');
162161
}
163162

164-
const commitMeta = $('.commit-meta span.right').get(0);
163+
const $commitMeta = $('.commit-meta span.right');
165164

166-
$(commitMeta).append(`
165+
$commitMeta.append(`
167166
<span class="sha-block patch-diff-links">
168167
<a href="${commitUrl}.patch" class="sha">patch</a>
169168
<a href="${commitUrl}.diff" class="sha">diff</a>
@@ -209,15 +208,8 @@ function showRecentlyPushedBranches() {
209208
$('.repository-content').prepend(div);
210209
}
211210

212-
// Support indent with tab key in textarea elements
213-
$(document).on('keydown', event => {
214-
// Check event.target instead of using a delegate, because Sprint doesn't support them
215-
const $target = $(event.target);
216-
// Limit indenting to just the textarea in comments
217-
if (!($target.is('textarea') && $target.hasClass('js-comment-field'))) {
218-
return;
219-
}
220-
211+
// Support indent with tab key in comments
212+
$(document).on('keydown', '.js-comment-field', event => {
221213
if (event.which === 9 && !event.shiftKey) {
222214
// don't indent if the suggester box is active
223215
if ($('.suggester').hasClass('active')) {
@@ -231,12 +223,8 @@ $(document).on('keydown', event => {
231223
});
232224

233225
// Prompt user to confirm erasing a comment with the Cancel button
234-
$(document).on('click', event => {
235-
// Check event.target instead of using a delegate, because Sprint doesn't support them
226+
$(document).on('click', '.js-hide-inline-comment-form', event => {
236227
const $target = $(event.target);
237-
if (!$target.hasClass('js-hide-inline-comment-form')) {
238-
return;
239-
}
240228

241229
// Do not prompt if textarea is empty
242230
const text = $target.closest('.js-inline-comment-form').find('.js-comment-field').val();
@@ -281,9 +269,7 @@ document.addEventListener('DOMContentLoaded', () => {
281269
new MutationObserver(() => hideStarsOwnRepos())
282270
.observe($('#dashboard .news').get(0), {childList: true});
283271

284-
// event binding for infinite scroll
285-
window.addEventListener('scroll', infinitelyMore);
286-
window.addEventListener('resize', infinitelyMore);
272+
$(window).on('scroll.infinite resize.infinite', infinitelyMore);
287273
}
288274

289275
if (pageDetect.isRepo()) {

extension/copy-file.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ window.addFileCopyButton = () => {
1212
const fileUri = $targetSibling.attr('href');
1313
$(`<a href="${fileUri}" class="btn btn-sm copy-btn">Copy</a>`).insertBefore($targetSibling);
1414

15-
$(document).on('click', e => {
16-
if (!e.target.classList.contains('copy-btn')) {
17-
return;
18-
}
19-
15+
$(document).on('click', '.copy-btn', e => {
2016
e.preventDefault();
2117
const fileContents = $('.js-file-line-container').get(0).innerText;
2218
utils.copyToClipboard(fileContents);

extension/diffheader.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,22 @@ window.diffFileHeader = (() => {
4444
};
4545

4646
const updateFileLabel = val => {
47-
const target = $('.diff-toolbar-filename').get(0);
48-
target.classList.add('filename-width-check');
49-
target.textContent = val;
47+
const $target = $('.diff-toolbar-filename');
48+
$target.addClass('filename-width-check').text(val);
5049

5150
const maxPixels = maxPixelsAvailable();
52-
const doesOverflow = () => target.getBoundingClientRect().width > maxPixels;
51+
const doesOverflow = () => $target.get(0).getBoundingClientRect().width > maxPixels;
5352
const {basename, topDir, folderCount} = parseFileDetails(val);
5453

5554
if (doesOverflow() && folderCount > 1) {
56-
target.textContent = `${topDir}/.../${basename}`;
55+
$target.text(`${topDir}/.../${basename}`);
5756
}
5857

5958
if (doesOverflow()) {
60-
target.textContent = basename;
59+
$target.text(basename);
6160
}
6261

63-
target.classList.remove('filename-width-check');
62+
$target.removeClass('filename-width-check');
6463
};
6564

6665
const getDiffToolbarHeight = () => {
@@ -79,8 +78,7 @@ window.diffFileHeader = (() => {
7978
return;
8079
}
8180

82-
// Note: Not using $.each, because Sprint doesn't allow bailing out early
83-
const files = $('.file.js-details-container').dom;
81+
const files = Array.from($('.file.js-details-container'));
8482
return files.find(el => isFilePartlyVisible(el, toolbarHeight));
8583
};
8684

@@ -109,10 +107,9 @@ window.diffFileHeader = (() => {
109107
const setup = () => {
110108
$(window).on('scroll.diffheader', () => diffHeaderFilename());
111109
const onResize = utils.debounce(() => diffHeaderFilename(true), 200);
112-
$(window).on('resize', onResize);
110+
$(window).on('resize.diffheader', onResize);
113111

114-
$(`<span class="diff-toolbar-filename"></span>`)
115-
.insertAfter($('.toc-select'));
112+
$(`<span class="diff-toolbar-filename"></span>`).insertAfter($('.toc-select'));
116113
diffFile.reset();
117114
};
118115

extension/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"custom.css"
2626
],
2727
"js": [
28-
"vendor/sprint.min.js",
28+
"vendor/jquery.slim.min.js",
2929
"vendor/gh-injection.js",
3030
"util.js",
3131
"page-detect.js",

extension/reactions-avatars.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ const addReactionParticipants = {
55
const $reactionButtons = $reactionsContainer.find('.comment-reactions-options .reaction-summary-item[aria-label]');
66

77
$reactionButtons.each((index, element) => {
8-
const participantCount = Number(element.innerHTML.split('/g-emoji>')[1]);
9-
const participants = element.getAttribute('aria-label')
8+
const $element = $(element);
9+
const participantCount = Number($element.html().split('/g-emoji>')[1]);
10+
const participants = $element.attr('aria-label')
1011
.replace(/ reacted with.*/, '')
1112
.replace(/,? and /, ', ')
1213
.replace(/, \d+ more/, '')
@@ -18,8 +19,6 @@ const addReactionParticipants = {
1819
return;
1920
}
2021

21-
const $element = $(element);
22-
2322
// add participant container
2423
if ($element.find('div.participants-container').length === 0) {
2524
$element.append('<div class="participants-container">');
@@ -59,7 +58,7 @@ const addReactionParticipants = {
5958
},
6059

6160
addListener(currentUser) {
62-
document.addEventListener('click', event => {
61+
$(document).on('click', event => {
6362
addReactionParticipants.reapply(event, currentUser);
6463
});
6564
}

extension/show-names.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ window.showRealNames = () => {
1818
};
1919

2020
getCachedUsers((users = {}) => {
21-
const usersOnPage = $('.js-discussion .author').dom.map(el => el.innerText);
21+
const usersOnPage = Array.from($('.js-discussion .author')).map(el => el.innerText);
2222
const uniqueUsers = new Set(usersOnPage);
2323

2424
// Add cached users to DOM first, since the calls for everyone else will be slow
@@ -44,7 +44,7 @@ window.showRealNames = () => {
4444

4545
for (const {username, profile} of profiles) {
4646
const profileDOM = new DOMParser().parseFromString(profile, 'text/html');
47-
const fullname = $(profileDOM.querySelector('h1 strong')).text().slice(1, -1);
47+
const fullname = $(profileDOM).find('h1 strong').text().slice(1, -1);
4848

4949
// Possible for a user to not set a name
5050
if (fullname) {

extension/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
position: 'fixed'
2626
}).appendTo('body').val(value);
2727

28-
$textArea.get(0).select();
28+
$textArea.select();
2929
const success = document.execCommand('copy');
3030
$textArea.remove();
3131

extension/vendor/jquery.slim.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)