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+ velocity = require ( 'velocity-animate' ) ,
7+ loadTemplate = require ( '../utils/loadTemplate' ) ,
88 baseVw = require ( './baseVw' ) ,
99 itemShortView = require ( './itemShortVw' ) ,
1010 itemShortModel = require ( '../models/itemShortMd' ) ,
@@ -27,7 +27,8 @@ module.exports = baseVw.extend({
2727 'focus .js-homeSearchItems' : 'searchItemsFocus' ,
2828 'blur .js-homeSearchItems' : 'searchItemsBlur' ,
2929 'click .js-homeListingsFollowed' : 'clickListingsFollowed' ,
30- 'click .js-homeListingsAll' : 'clickListingsAll'
30+ 'click .js-homeListingsAll' : 'clickListingsAll' ,
31+ 'click .backToTop' : 'clickBackToTop'
3132 } ,
3233
3334 initialize : function ( options ) {
@@ -150,46 +151,50 @@ module.exports = baseVw.extend({
150151 render : function ( ) {
151152 var self = this ;
152153 $ ( '#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- }
164-
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- }
176-
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 ) ;
183-
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- }
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+ }
190169
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+ }
191181
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+ }
192195
196+ self . $backToTop = self . $ ( '.backToTop' ) ;
197+ } ) ;
193198 } ) ;
194199 } ,
195200
@@ -397,7 +402,16 @@ module.exports = baseVw.extend({
397402
398403 unblockUserClick : function ( e ) {
399404 this . userModel . unblockUser ( e . view . model . get ( 'guid' ) ) ;
400- } ,
405+ } ,
406+
407+ clickBackToTop : function ( ) {
408+ this . obContainer . velocity ( 'scroll' , {
409+ offset : 0 ,
410+ complete : ( ) => {
411+ this . $backToTop . removeClass ( 'slideUp' ) ;
412+ }
413+ } ) ;
414+ } ,
401415
402416 onScroll : function ( ) {
403417 if ( this . obContainer [ 0 ] . scrollTop + this . obContainer [ 0 ] . clientHeight + 200 > this . obContainer [ 0 ] . scrollHeight && ! this . searchItemsText ) {
@@ -411,6 +425,15 @@ module.exports = baseVw.extend({
411425 this . socketView . getVendors ( this . socketUsersID ) ;
412426 }
413427 }
428+
429+ if (
430+ this . state === "products" && this . obContainer [ 0 ] . scrollTop > 180 ||
431+ this . state === "vendors" && this . obContainer [ 0 ] . scrollTop > 140
432+ ) {
433+ this . $backToTop . addClass ( 'slideUp' ) ;
434+ } else {
435+ this . $backToTop . removeClass ( 'slideUp' ) ;
436+ }
414437 } ,
415438
416439 clearItems : function ( ) {
0 commit comments