11'use strict' ;
22
33var __ = 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