Skip to content

Commit

Permalink
Cache re-used DOM elements
Browse files Browse the repository at this point in the history
  • Loading branch information
sgarrity committed Jan 26, 2015
1 parent dddc1ec commit 5886336
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions media/js/privacy/privacy-day.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ $(function() {
'use strict';

var pager = Mozilla.Pager.pagers[0];
var documentRoot = $(document);

This comment has been minimized.

Copy link
@alexgibson

alexgibson Jan 26, 2015

Member

Nit: reference jQuery objects with a $ prefix, e.g. var $documentRoot = $(document);

var firstPager = $('.pager').first();

// scroll to top of pager when switching tabs so all
// tab content is visible after switching tabs
Expand All @@ -15,12 +17,12 @@ $(function() {
var scrollPos = $(document).scrollTop();

// Get the offset of the top of the pager section
var pagerTopPos = $('.pager').first().offset().top;
var pagerTopPos = $(firstPager).offset().top;

// If we're scrolled passed the header, jump back up
// to the tabs when the tab is switched
if (scrollPos > pagerTopPos) {
$('html, body').scrollTop($('.pager').first().offset().top);
$(documentRoot).scrollTop($(firstPager).offset().top);

This comment has been minimized.

Copy link
@alexgibson

alexgibson Jan 26, 2015

Member

$(documentRoot) can be simplified to $documentRoot. No need to use the $() selector each time.

}
});

Expand Down

0 comments on commit 5886336

Please sign in to comment.