Skip to content

Commit b19e455

Browse files
committed
Changed the default viewTypeContainerTemp
1 parent b382d34 commit b19e455

File tree

3 files changed

+54
-60
lines changed

3 files changed

+54
-60
lines changed

README.md

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -219,61 +219,31 @@ It can also contain multiple templates to include different view types(grid view
219219
,searchResultSetTemp:
220220
{
221221
"grid":
222-
'{{#products}}'+
223-
'{{{every_three}}}'+
224-
'<div class="product-container {{{nth_item}}}">'+
225-
'<div class="product-item item-template-0 alternative">'+
226-
'<div class="img">'+
227-
'<a href="{{productUrl}}" >'+
228-
'<img src="{{imageUrl}}" alt="" onerror="this.style.display=\'none\';">'+
229-
'</a>'+
230-
'</div>'+
231-
'<div class="name">'+
232-
'<a href="{{productUrl}}" > {{title}}'+
233-
'</a>'+
234-
'</div>'+
235-
'<div class="stars">'+
236-
'</div>'+
237-
'<div class="price">'+
238-
'{{#if_on_sale this}}'+
239-
'<div class="on-sale">Sale</div>'+
240-
'<del class="price2">${{format_price retail_price}}&nbsp;</del>'+
241-
'{{/if_on_sale}}'+
242-
'<span class="hidden">&nbsp;</span> ${{format_price price}}'+
243-
'</div>'+
244-
'</div>'+
245-
'</div>'+
246-
'{{/products}}',
222+
['{{#products}}<li class="grid_view"><a href="product.html?pid={{uniqueId}}" id="pdt-{{uniqueId}}" class="result-item" unbxdParam_sku="{{uniqueId}}" unbxdParam_pRank="{{unbxdprank}}" unbxdAttr="product">'
223+
,'<div class="result-image-container">'
224+
,'<span class="result-image-horizontal-holder">'
225+
,'<img src="{{{image_url}}}" alt="{{{title}}}">'
226+
,'</span>'
227+
,'</div>'
228+
,'<div class="result-brand">{{{brand}}}</div>'
229+
,'<div class="result-title">{{{title}}}</div>'
230+
,'<div class="result-price">'
231+
,'${{price}}'
232+
,'</div>'
233+
,'</a></li>{{/products}}'].join(''),
247234
"list":
248-
'<ul class="nxt-product-list nxt-view-list clearfix">'
249-
+'{{#products}}'
250-
+'<li class="nxt-product-item product-item">'
251-
+'<div class="nxt-product-item-wrap">'
252-
+'<div class="nxt-image-wrapper">'
253-
+'<a href="{{productUrl}}" >'
254-
+'<img class="nxt-product-image" width="150" height="150" src="{{imageUrl}}" alt="" onerror="this.style.display=\'none\';">'
255-
+'{{#if_on_sale this}}<div class="on-sale">Sale</div>{{/if_on_sale}}'
256-
+'</a>'
257-
+'</div>'
258-
+'<div class="nxt-product-details">'
259-
+'<div class="nxt-product-col1">'
260-
+'<div class="nxt-product-name">'
261-
+'<a href="{{productUrl}}" >{{title}}</a>'
262-
+'</div>'
263-
+'<div class="nxt-product-description">After more than 14,000 live fittings with lady golfers, Bridgestone Golf has developed a ladies specific model engineered for moderate swing speeds. The new Lady Precept is designed to produce higher launch ...</div>'
264-
+'</div>'
265-
+'<div class="nxt-product-col2">'
266-
+'{{#if_on_sale this}}<del class="price2">${{format_price retail_price}}&nbsp;</del>{{/if_on_sale}}'
267-
+'<span class="hidden">&nbsp;</span> ${{format_price price}} '
268-
+'<div class="nxt-product-buttons">'
269-
+'<input type="button" class="nxt-btn-primary" onclick="top.location.href=\'{{productUrl}}\'" value="More Info">'
270-
+'</div>'
271-
+'</div>'
272-
+'</div>'
273-
+'</div>'
274-
+'</li>'
275-
+'{{/products}}'
276-
+'</ul>'
235+
['{{#products}}<li class="list_view"><a href="product.html?pid={{uniqueId}}" id="pdt-{{uniqueId}}" class="result-item" unbxdParam_sku="{{uniqueId}}" unbxdParam_pRank="{{unbxdprank}}" unbxdAttr="product">'
236+
,'<div class="result-image-container">'
237+
,'<span class="result-image-horizontal-holder">'
238+
,'<img src="{{{image_url}}}" alt="{{{title}}}">'
239+
,'</span>'
240+
,'</div>'
241+
,'<div class="result-brand">{{{brand}}}</div>'
242+
,'<div class="result-title">{{{title}}}</div>'
243+
,'<div class="result-price">'
244+
,'${{price}}'
245+
,'</div>'
246+
,'</a></li>{{/products}}'].join('')
277247
}
278248
```
279249

@@ -295,14 +265,29 @@ In this case, we need to also mention the different view types under 'viewTypes'
295265
,viewTypeContainerTemp:
296266
'{{#options}}'
297267
+'<li class="nxt-{{#if selected}}current{{/if}}">'
298-
+'<a title="{{value}} View" class="nxt-{{value}}view-button" unbxdviewtype="{{value}}">'
268+
+'<a title="{{value}} View" class="nxt-{{value}}view-button" {{#unless selected}}unbxdviewtype="{{value}}"{{/unless}}>'
299269
+'<span class="icon-{{value}}view">'
300270
+'</span>'
301271
+'</a>'
302272
+'</li>'
303273
+'{{/options}}'
304274
```
305275

276+
JSON used for this template:
277+
278+
```
279+
{
280+
0: {
281+
"selected": true,
282+
"value": "grid"
283+
},
284+
1: {
285+
"selected": false,
286+
"value": "list"
287+
}
288+
}
289+
```
290+
306291
- **searchResultContainer** : The jQuery selector of DOM element to append the HTML generated from **searchResultSetTemp** (*#results_container* in the first image).
307292
- **isClickNScroll** : Set it to **true** if you want users to click an element to fetch the next page.
308293
- **clickNScrollSelector** : The jQuery selector of the DOM element that can be clicked for displaying the next page.(PS. in this case the new results will be appended to the **searchResultContainer**.)

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ <h3 class="result-title-count" id="search_title">
220220
,onPageLoad : function(){
221221
console.log('onPageLoad', arguments, this);
222222
}
223-
,deferInitRender: ['search']
223+
,deferInitRender: []
224224
,bannerSelector: '.banner'
225225
,sortContainerSelector: '.result-sort-options'
226226
,pageSizeContainerSelector: '.result-page-size-options'

unbxdSearch.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,16 @@ var unbxdSearchInit = function(jQuery, Handlebars){
465465
'{{/if}}',
466466
'{{/options}}',
467467
'</select>'
468-
].join('')
468+
].join(''),
469+
viewTypeContainerTemp:
470+
'{{#options}}'
471+
+'<li class="nxt-{{#if selected}}current{{/if}}">'
472+
+'<a title="{{value}} View" class="nxt-{{value}}view-button" {{#unless selected}}unbxdviewtype="{{value}}"{{/unless}}>'
473+
+'<span class="icon-{{value}}view">'
474+
+'</span>'
475+
+'</a>'
476+
+'</li>'
477+
+'{{/options}}'
469478
};
470479

471480
jQuery.extend(Unbxd.setSearch.prototype,{
@@ -609,10 +618,10 @@ var unbxdSearchInit = function(jQuery, Handlebars){
609618
e.preventDefault();
610619
var $t = jQuery(this);
611620
var selected = $t.attr("unbxdviewtype");
612-
613621
self.setViewType(selected);
614-
615-
self.callResults(self.paintResultSet, true);
622+
if(selected && self.options.viewTypes.indexOf(selected) > -1) {
623+
self.callResults(self.paintResultSet, true);
624+
}
616625
};
617626

618627
var changeSort = function(e){

0 commit comments

Comments
 (0)