<@ if (recommends) { @> Teleflora Recommends <@ } else if (rating) { @> <@ } @> <@= title @>
$<@= price.standard @>
The product grid grabs all of its styles from m-product-mini
All js files used to render the product grid are inside of the folder: /javascripts/backbone/
Backbone is initialized via subcategory.js -
var app = app || {}; var subcategoryView; $(function() { // upon page ready initialize the product grid main view subcategoryView = new app.subCategoryView(); });
This starts the main view: subCategoryView
which is in charge of listening to any events on the subcategory page -
//checkbox click event "click .custom-checkbox :checkbox" : "filterProductGrid", // sort select change event "change #selectSort" : "sortProductGrid", // quickview click event "click #quickview" : "showQuickview", // enter delivery info click event "click #enterDeliveryInfoSubmit" : "updateGrid"
Each event calls a specific function that modifies the product grid -
fiterProductGrid
- returns a filtered collection depending on the selected filters.sortProductGrid
- sorts the current collection depending on the chosen option in the sort dropdown.showQuickview
- gets the corresponding product information and displays the quickview underneath it.updateGrid
- an example function of how the recipient delivery module will update the current collection to display a different set of models.The subcategoryView also initializes the productGridView
which is the one responsible for initializing a productGrid collection composed of product models based off of an example json fetch (refer to product_grid.json file).
In order to do this it grabs the underscore template located inside the subcategory index file with id of productGridTemplate
and loops through each available model in the json response and populates that template with the right information.
The collection is then appended to the page via the render
function -
render: function() { var gridView = this; // empty out element of any previous items this.$el.empty(); // fade out container and wait for it to finish this.$el.fadeOut(250, function() { // loop through collection, get all items up to limit var currentCollection = new Backbone.Collection(gridView.collection.first(gridView.limit)); // set up lazy load of grid gridView.lazyLoadGrid(currentCollection, gridView.collection, gridView, gridView.limit); // update filter numbers in product sidebar gridView.renderFilterNumbers(gridView.collection); }); gridView.$el.promise().done(function(){ // fade container back in after everything is loaded gridView.$el.fadeIn(300); }); },
lazyLoadGrid
is used in conjunction with waypoints.js to lazy load additional items into the grid if the collection exceeds the limit. The function that actually appends the product to the page is the renderProduct
function inside lazyLoadGrid -
renderProduct: function(model) { // set data to individual Product view var productView = new app.ProductView({ model: model }); // set product to the render var product = productView.render().el; // append product model in container this.$el.append(product); // jquery binding for quickview is done here as elements are dynamic $(product).find('#productImage').bind({mouseenter: function(){ $(this).find('#quickview').filter(':not(:animated)').animate({ opacity: 1 }, 200); }, mouseleave: function() { $(this).find('#quickview').animate({ opacity: 0 }, 0); } }); },
This calls the view called: productView
which creates the final model template and appends it to the page as well as sets the jQuery binding for the quickview button.
.m-product-quickview
- Sets top bottom margins and hides the quickview.m-product-quickview-container
- Sets the border outline and internal width..arrow-up-fore, .arrow-up-back
- CSS3 arrow icons, need 2 in order to fake an arrow with a border..position-1, .position-2, etc.
- used to set the position of the arrow to its respective product..m-product-mini-stars, .m-pdp-header, .m-pdp-main-img-container, #pdpForm
- unique override styles for use in the quickview.