Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit e030cc6

Browse files
committed
Revert "Merge pull request #833 from cvan/nav-tweax-scroll"
This reverts commit 64ff8a3, reversing changes made to dca5f72.
1 parent 2aa6c43 commit e030cc6

File tree

3 files changed

+152
-92
lines changed

3 files changed

+152
-92
lines changed

src/media/css/navbar.styl

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@
66
background-image: url(../img/pretty/gear.svg);
77
}
88

9-
.navbar {
10-
disable-user-select();
11-
display: inline-block;
12-
13-
a {
14-
text-decoration: none;
15-
}
9+
.navbar a {
10+
text-decoration: none;
1611
}
1712

1813
.tab-item {
1914
display: inline-block;
2015
font-size: 15px;
21-
height: $header-height;
22-
line-height: 50px;
2316
position: relative;
2417
text-align: center;
2518
text-transform: uppercase;
@@ -41,7 +34,6 @@
4134
border-bottom: 3px solid transparent;
4235
color: $navbar-text;
4336
display: block;
44-
height: $header-height;
4537

4638
&:hover {
4739
border-bottom-color: $bg-gray;
@@ -69,14 +61,18 @@
6961
}
7062

7163
@media $narrower-than-desktop {
72-
// Feed navigation (mobile only).
73-
header .act-tray,
74-
body[data-page-type~=settings] .back {
64+
// New feed navigation (mobile only).
65+
header .act-tray {
7566
display: none;
7667
}
77-
body[data-page-type~=settings] .site {
78-
display: block;
79-
width: 35px;
68+
body[data-page-type~=settings] {
69+
.back {
70+
display: none;
71+
}
72+
.site {
73+
display: block;
74+
width: 35px;
75+
}
8076
}
8177
body[data-page-type~=leaf],
8278
body[data-page-type~=search] {
@@ -89,11 +85,10 @@
8985
.site-nav {
9086
background: $navbar-gray;
9187
bottom: 0;
92-
height: 49px;
88+
height: 50px;
9389
overflow: hidden;
9490
position: relative;
95-
transition(unquote('bottom .2s, margin-bottom .2s'));
96-
transform(unquote('translate3d(0,0,0)'));
91+
transition(unquote('bottom .5s, margin-bottom .5s'));
9792

9893
// act-tray is link to Settings tabs (e.g., Settings, Purchases).
9994
// mkt-tray is link to Marketplace tabs (e.g., Home, New, Popular).
@@ -102,13 +97,13 @@
10297
background-color: $cloud-gray;
10398
border: 1px solid $cement-gray;
10499
height: 51px;
105-
transition(right .2s);
100+
transition(right .4s);
106101
width: 56px;
107102
z-index: 2;
108103

109104
&.active {
110105
right: 0;
111-
transition(right .2s .4s);
106+
transition(right .2s .6s);
112107
}
113108
.header-button {
114109
background-size: 30px auto;
@@ -121,7 +116,7 @@
121116
border-radius: 0 80px 80px 0;
122117
bottom: 2px;
123118
position: relative;
124-
right: 56px;
119+
right: 55px;
125120

126121
&.active .header-button.settings {
127122
background-image: url(../img/pretty/gear.svg);
@@ -132,7 +127,7 @@
132127
}
133128
.mkt-tray {
134129
border-radius: 80px 0 0 80px;
135-
bottom: -1px;
130+
bottom: 0;
136131
position: absolute;
137132
right: -60px;
138133

@@ -150,41 +145,45 @@
150145
}
151146
}
152147

153-
.navbar-container {
148+
.navbar {
149+
disable-user-select();
154150
display: inline-block;
155-
left: 0;
156-
-moz-overflow-scrolling: touch;
157-
-webkit-overflow-scrolling: touch;
158-
overflow-scrolling: touch;
159-
overflow-x: scroll;
160-
overflow-y: hidden;
151+
opacity: 1;
152+
padding: 8px 0;
161153
position: absolute;
162154
top: 0;
155+
transition(unquote('right .5s ease-out, left .3s ease-in'));
163156
white-space: nowrap;
164157
width: 100%;
165-
}
166158

167-
.navbar {
168-
display: none;
169-
padding-bottom: 60px;
159+
&.nav-mkt {
160+
visibility: hidden;
161+
right: -100%;
170162

171-
&.active {
172-
display: block;
163+
&.active {
164+
right: -65px;
165+
visibility: visible;
166+
}
173167
}
168+
&.nav-settings {
169+
visibility: hidden;
170+
right: 100%;
174171

175-
// Account for "Settings" icon.
176-
&.nav-mkt.active .tab-item:first-child {
177-
padding-left: 65px;
172+
&.active {
173+
right: 0;
174+
visibility: visible;
175+
}
178176
}
177+
}
179178

180-
// Account for "Back to Marketplace" icon.
181-
&.nav-settings.active .tab-item:last-child {
182-
padding-right: 65px;
183-
}
179+
.tab-item {
180+
top: 2px;
184181
}
185182

186183
.tab-link {
187184
color: $navbar-text;
185+
height: 38px;
186+
line-height: 32px;
188187
padding: 0 10px;
189188
}
190189

@@ -200,16 +199,19 @@
200199
display: none;
201200
}
202201
.site-nav {
203-
background-color: $navbar-gray;
202+
background-color: #E0E0E0;
204203
margin: 0 auto;
205204
z-index: 25;
206205
}
207-
208206
.navbar {
207+
disable-user-select();
208+
display: inline-block;
209209
margin: 0 auto;
210210
left: 0;
211+
height: 100%;
212+
opacity: 1;
211213
position: absolute;
212-
right: 0;
214+
right: 0 !important; // navbar.js sets rule on `style`, so override.
213215
top: 0;
214216
white-space: nowrap;
215217
width: -moz-fit-content;
@@ -218,13 +220,15 @@
218220
}
219221

220222
.tab-item {
223+
line-height: 50px;
221224
padding: 0 60px;
222225

223226
&.active > .tab-link {
224227
color: $breezy-blue;
225228
}
226229
}
227230
.tab-link {
231+
display: block;
228232
outline: 0;
229233
height: $header-height;
230234
}
@@ -235,7 +239,6 @@
235239

236240
.desktop-cat-link {
237241
display: inline;
238-
pointer-events: none;
239242

240243
&:after {
241244
border: 4px solid transparent;

src/media/js/navbar.js

Lines changed: 82 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
define('navbar',
2-
['capabilities', 'categories', 'jquery', 'log', 'navigation', 'nunjucks',
3-
'settings', 'underscore', 'user', 'z'],
4-
function(capabilities, cats, $, log, navigation, nunjucks, settings, _,
5-
user, z) {
2+
['categories', 'jquery', 'log', 'navigation', 'nunjucks', 'settings',
3+
'underscore', 'urls', 'user', 'z'],
4+
function(cats, $, log, navigation, nunjucks, settings, _, urls, user, z) {
65
'use strict';
76
var logger = log('navbar');
87

8+
var DESKTOP_WIDTH = 710;
9+
var NAV_MKT_BASE_OFFSET = -65;
10+
var NAV_SETTINGS_BASE_OFFSET = 0;
911
var NAV_LINK_VISIBLE_WIDTH = 50;
1012

1113
function initNavbarButtons() {
1214
// Navbar settings + Marketplace buttons.
13-
var $navContainer = $('.navbar-container');
1415
var $mktNav = $('.nav-mkt');
1516
var $settingsNav = $('.nav-settings');
1617
var $mktNavGroup = $mktNav.add('.act-tray-mobile');
@@ -19,15 +20,14 @@ define('navbar',
1920
function toggleNavbar($on, $off) {
2021
$on.addClass('active');
2122
$off.removeClass('active');
22-
$navContainer[0].scrollLeft = 0;
2323
}
2424

2525
function fitNavbarOnSwitch($navbar, $item) {
2626
// Switching between navbars makes it difficult to do initial
2727
// line-fitting since the navbar is in a transitioning state. So
2828
// we do a timeout. But for navbars that have already been fitted,
2929
// don't do a timeout delay.
30-
var waitForTransition = 200;
30+
var waitForTransition = 500;
3131
if ($navbar.data('fitted')) {
3232
waitForTransition = 0;
3333
}
@@ -41,6 +41,7 @@ define('navbar',
4141
z.body.on('click', '.act-tray-mobile', function(e) {
4242
// Activate Settings page navbar.
4343
e.preventDefault();
44+
$mktNav.css('right', ''); // Reset the offset for transition effect.
4445
toggleNavbar($settingsNavGroup, $mktNavGroup);
4546

4647
var $firstLink = $settingsNavGroup.find('[data-tab]:first-child a');
@@ -52,6 +53,7 @@ define('navbar',
5253
.on('click', '.mkt-tray', function(e) {
5354
// Activate Marketplace pages navbar.
5455
e.preventDefault();
56+
$('.nav-settings').css('right', ''); // Reset the offset for transition effect.
5557
toggleNavbar($mktNavGroup, $settingsNavGroup);
5658

5759
var $firstLink = $mktNavGroup.find('[data-tab]:first-child a');
@@ -63,23 +65,77 @@ define('navbar',
6365
.on('click', '.site a', function() {
6466
// Activate Marketplace pages navbar.
6567
toggleNavbar($mktNavGroup, $settingsNavGroup);
66-
})
67-
.on('click', '.tab-link', function(e) {
68-
if (capabilities.widescreen()) {
69-
return;
70-
}
71-
72-
// Jump to the beginning when user clicks on the first link.
73-
if ($(this).closest('.tab-item').is(':first-child')) {
74-
$navContainer[0].scrollLeft = 0;
75-
} else {
76-
$navContainer[0].scrollLeft = this.getBoundingClientRect().left;
77-
}
78-
this.blur();
7968
});
8069
}
8170
z.body.one('loaded', initNavbarButtons);
8271

72+
z.body.on('click', '.navbar li > a', function() {
73+
var $this = $(this);
74+
if ($this.hasClass('desktop-cat-link')) {
75+
// Don't allow click of category tab on desktop.
76+
return;
77+
}
78+
79+
calcNavbarOffset($this.closest('li'));
80+
});
81+
82+
function calcNavbarOffset($item) {
83+
// Calculate appropriate offsets for the navbar so that it slides well
84+
// for any language. Good luck understanding what's going on.
85+
var $navbar = $item.closest('.navbar');
86+
if (!$navbar.length) {
87+
return;
88+
}
89+
90+
var currentNavbarOffset = $navbar.offset().left * -1;
91+
var padding = 10;
92+
var right = currentNavbarOffset;
93+
var rightEdgeOffset = $item.offset().left + $item.width();
94+
95+
var baseOffset = NAV_MKT_BASE_OFFSET;
96+
var windowWidth = z.win.width();
97+
if ($navbar.hasClass('nav-settings')) {
98+
baseOffset = NAV_SETTINGS_BASE_OFFSET;
99+
windowWidth -= $('.mkt-tray').width();
100+
}
101+
102+
if (rightEdgeOffset > windowWidth) {
103+
// Sliding forwards.
104+
// If the link is overflowing off the right edge of the page,
105+
// slide the navbar enough so the link is fully visible.
106+
right = (currentNavbarOffset +
107+
(rightEdgeOffset - windowWidth) + padding);
108+
109+
// If there is another link after the current link, move the navbar
110+
// some more such that the next link is clickable (50px target).
111+
if ($item.next().length) {
112+
right += NAV_LINK_VISIBLE_WIDTH;
113+
}
114+
} else if (currentNavbarOffset !== NAV_MKT_BASE_OFFSET) {
115+
// Sliding backwards.
116+
// If the next link to the one clicked is in full view, slide it
117+
// so it becomes visible by only 50px and thus clickable.
118+
var $next = $item.next();
119+
if ($next.length) {
120+
var nextLeftEdgeOffset = $next.offset().left;
121+
var nextRightEdgeOffset = nextLeftEdgeOffset + $next.width();
122+
if (nextRightEdgeOffset < windowWidth) {
123+
right = (currentNavbarOffset -
124+
(windowWidth + NAV_LINK_VISIBLE_WIDTH - nextRightEdgeOffset) +
125+
padding);
126+
}
127+
}
128+
}
129+
130+
if (right < baseOffset) {
131+
// Don't scroll past the base starting point.
132+
right = baseOffset;
133+
}
134+
135+
$item.closest('.navbar').css('right', right + 'px');
136+
return right;
137+
}
138+
83139
function linefitNavbarMobile($navbar) {
84140
// Linefits the navbar on mobile such that the nav element flowing
85141
// off the screen is clickable by 50px.
@@ -127,17 +183,20 @@ define('navbar',
127183
}
128184

129185
function fitNavbarMobile($item) {
130-
// Does line-fitting for the navbar.
186+
// Does both line-fitting and offset calculations for the navbar.
187+
// Note that line-fitting must be done first since the offset affects
188+
// its calculations.
131189
linefitNavbarMobile($item.closest('.navbar'));
190+
calcNavbarOffset($item);
132191
}
133192

134193
function fitNavbarDesktop() {
135194
// Shrinks the font-size and padding of the nav elements until it
136195
// all fits within the window.
137-
if (!capabilities.widescreen()) {
196+
var windowWidth = z.win.width();
197+
if (windowWidth < DESKTOP_WIDTH) {
138198
return;
139199
}
140-
var windowWidth = z.win.width();
141200
var $navbar = $('.nav-mkt');
142201
var $navbarItems = $navbar.find('li');
143202
var navbarWidth = $navbar.width();

0 commit comments

Comments
 (0)