@@ -79,29 +79,28 @@ function addTrendingMenuItem() {
7979}
8080
8181function 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
102101function 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
121120function 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 ( / \/ p u l l \/ \d + \/ c o m m i t s / , '/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 ( ) ) {
0 commit comments