Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit d890b32

Browse files
committed
Merge pull request #1554 from rmisio/1536
Adds a Back To Top button to the Discover and User pages
2 parents ced8836 + fe5c1d7 commit d890b32

File tree

7 files changed

+189
-115
lines changed

7 files changed

+189
-115
lines changed

css/obBase.css

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,11 @@ h6, .h6 {
451451
#sideBar {
452452
position: fixed;
453453
right: -183px;
454-
top: 78px;
454+
top: 75px;
455455
width:230px;
456456
background-color: #252525;
457457
border-left: 0;
458-
height: calc(100% - 50px);
458+
height: calc(100% - 71px);
459459
z-index: 0;
460460
transition: right 0.5s ease;
461461
color: #DDD;
@@ -6218,3 +6218,23 @@ input[type="checkbox"].fieldItem:checked + label .togLabelOff {
62186218
background-color: #eeeae1;
62196219
height: 100%;
62206220
}
6221+
6222+
.backToTop {
6223+
position: fixed;
6224+
bottom: 15px;
6225+
right: 73px;
6226+
padding: 10px;
6227+
background-color: #252525;
6228+
transform: translateY(100%);
6229+
opacity: 0;
6230+
transition: transform 300ms ease, right 0.5s ease;
6231+
}
6232+
6233+
.backToTop.slideUp {
6234+
opacity: 1;
6235+
transform: translateY(0);
6236+
}
6237+
6238+
#ov1.chatOpen .backToTop {
6239+
right: 303px;
6240+
}

js/start.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ var loadProfile = function(landingRoute, onboarded) {
406406
});
407407

408408
$('#sideBar').html(app.chatVw.render().el);
409-
$('html').addClass('chatLoaded');
410409

411410
app.router = new router({userModel: user, userProfile: userProfile, socketView: newSocketView});
412411

js/templates/backToTop.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="backToTop clickable zIndex1 <% ob.className && print(ob.className) %>"><span class="icon ion-chevron-up"></span> Back To Top</div>

js/templates/home.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ <h1 class="fancy-heading fontSize20 vCentered js-discoverHeading"><%= polyglot.t
9898
</div>
9999
</div>
100100
</div>
101+
<%= ob.backToTopTmpl() %>
101102
<div class="js-feed minHeight650 rowTop30 hide alignCenter fontSize14">
102103
<h1 class="fancy-heading width100 fontweight500"><%= polyglot.t('ComingSoon') %></h1>
103104
<div class="row20">

js/templates/userPage.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ <h1 class="page-userNameLarge floatLeft fancy-heading fontSize20 colorWhiteForce
588588
</div>
589589
</div>
590590

591+
<%= ob.backToTopTmpl({ className: 'custCol-secondary' }) %>
592+
591593
<div class="overlay overlayObscurring hide js-blockedWarning">
592594
<div class="modalHolder">
593595
<div class="modal">

js/views/homeVw.js

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict';
22

33
var __ = require('underscore'),
4+
$ = require('jquery'),
45
Backbone = require('backbone'),
5-
$ = require('jquery');
6-
Backbone.$ = $;
7-
var loadTemplate = require('../utils/loadTemplate'),
6+
loadTemplate = require('../utils/loadTemplate'),
87
baseVw = require('./baseVw'),
98
itemShortView = require('./itemShortVw'),
109
itemShortModel = require('../models/itemShortMd'),
@@ -27,7 +26,8 @@ module.exports = baseVw.extend({
2726
'focus .js-homeSearchItems': 'searchItemsFocus',
2827
'blur .js-homeSearchItems': 'searchItemsBlur',
2928
'click .js-homeListingsFollowed': 'clickListingsFollowed',
30-
'click .js-homeListingsAll': 'clickListingsAll'
29+
'click .js-homeListingsAll': 'clickListingsAll',
30+
'click .backToTop': 'clickBackToTop'
3131
},
3232

3333
initialize: function(options){
@@ -150,43 +150,51 @@ module.exports = baseVw.extend({
150150
render: function(){
151151
var self = this;
152152
$('#content').html(this.$el);
153-
loadTemplate('./js/templates/home.html', function(loadedTemplate) {
154-
self.$el.html(loadedTemplate());
155-
self.setState(self.state, self.searchItemsText);
156-
if (self.model.get('page').profile.vendor == true) {
157-
self.$el.find('.js-homeCreateStore').addClass('hide');
158-
self.$el.find('.js-homeMyPage').addClass('show');
159-
self.$el.find('.js-homeCreateListing').addClass('show');
160-
} else {
161-
self.$el.find('.js-homeCreateStore').addClass('show');
162-
self.$el.find('.js-homeCreateListing').addClass('hide');
163-
}
164153

165-
//get vendors and items
166-
self.loadingVendors = true;
167-
self.socketView.getVendors(self.socketUsersID);
168-
//set the filter
169-
if (localStorage.getItem('homeShowAll') == "yes"){
170-
self.setListingsAll();
171-
self.loadAllItems();
172-
} else {
173-
self.setListingsFollowed();
174-
self.loadFollowedItems();
175-
}
154+
loadTemplate('./js/templates/backToTop.html', function(backToTopTmpl) {
155+
loadTemplate('./js/templates/home.html', function(loadedTemplate) {
156+
self.$el.html(loadedTemplate({
157+
backToTopTmpl: backToTopTmpl
158+
}));
159+
160+
self.setState(self.state, self.searchItemsText);
161+
if(self.model.get('page').profile.vendor == true) {
162+
self.$el.find('.js-homeCreateStore').addClass('hide');
163+
self.$el.find('.js-homeMyPage').addClass('show');
164+
self.$el.find('.js-homeCreateListing').addClass('show');
165+
}else{
166+
self.$el.find('.js-homeCreateStore').addClass('show');
167+
self.$el.find('.js-homeCreateListing').addClass('hide');
168+
}
176169

177-
//listen to scrolling on container
178-
self.scrollHandler = __.bind(
179-
__.throttle(self.onScroll, 100),
180-
self
181-
);
182-
self.obContainer.on('scroll', self.scrollHandler);
170+
//get vendors and items
171+
self.loadingVendors = true;
172+
self.socketView.getVendors(self.socketUsersID);
173+
//set the filter
174+
if(localStorage.getItem('homeShowAll') == "yes"){
175+
self.setListingsAll();
176+
self.loadAllItems();
177+
} else {
178+
self.setListingsFollowed();
179+
self.loadFollowedItems();
180+
}
183181

184-
//populate search field
185-
if (self.searchItemsText){
186-
self.$el.find('.js-homeSearchItems').val("#" + self.searchItemsText);
187-
self.$el.find('.js-homeListingToggle').addClass('hide');
188-
$('#obContainer').scrollTop(0);
189-
}
182+
//listen to scrolling on container
183+
self.scrollHandler = __.bind(
184+
__.throttle(self.onScroll, 100),
185+
self
186+
);
187+
self.obContainer.on('scroll', self.scrollHandler);
188+
189+
//populate search field
190+
if(self.searchItemsText){
191+
self.$el.find('.js-homeSearchItems').val("#" + self.searchItemsText);
192+
self.$el.find('.js-homeListingToggle').addClass('hide');
193+
$('#obContainer').scrollTop(0);
194+
}
195+
196+
self.$backToTop = self.$('.backToTop');
197+
});
190198
});
191199
},
192200

@@ -393,7 +401,15 @@ module.exports = baseVw.extend({
393401

394402
unblockUserClick: function(e) {
395403
this.userModel.unblockUser(e.view.model.get('guid'));
396-
},
404+
},
405+
406+
clickBackToTop: function() {
407+
this.obContainer.animate({ scrollTop: 0 }, {
408+
complete: () => {
409+
this.$backToTop.removeClass('slideUp');
410+
}
411+
});
412+
},
397413

398414
onScroll: function(){
399415
if (this.obContainer[0].scrollTop + this.obContainer[0].clientHeight + 200 > this.obContainer[0].scrollHeight && !this.searchItemsText){
@@ -407,6 +423,15 @@ module.exports = baseVw.extend({
407423
this.socketView.getVendors(this.socketUsersID);
408424
}
409425
}
426+
427+
if (
428+
this.state === "products" && this.obContainer[0].scrollTop > 180 ||
429+
this.state === "vendors" && this.obContainer[0].scrollTop > 140
430+
) {
431+
this.$backToTop.addClass('slideUp');
432+
} else {
433+
this.$backToTop.removeClass('slideUp');
434+
}
410435
},
411436

412437
clearItems: function(){

0 commit comments

Comments
 (0)