Showing
1 changed file
with
9 additions
and
7 deletions
@@ -10,6 +10,8 @@ var $ = require('jquery'), | @@ -10,6 +10,8 @@ var $ = require('jquery'), | ||
10 | lazyLoad = require('yoho.lazyload'); | 10 | lazyLoad = require('yoho.lazyload'); |
11 | 11 | ||
12 | var swiper, | 12 | var swiper, |
13 | + $brandText, | ||
14 | + $brandHref, | ||
13 | $brandList = $('.brand-list'); | 15 | $brandList = $('.brand-list'); |
14 | 16 | ||
15 | var searchH = $('.newbrand-search').outerHeight(), | 17 | var searchH = $('.newbrand-search').outerHeight(), |
@@ -137,14 +139,15 @@ function searchResult() { | @@ -137,14 +139,15 @@ function searchResult() { | ||
137 | $('.search-result .brand-list p').each(function (index) { | 139 | $('.search-result .brand-list p').each(function (index) { |
138 | searchList = new Hammer($('.search-result .brand-list p').eq(index)[0]); | 140 | searchList = new Hammer($('.search-result .brand-list p').eq(index)[0]); |
139 | searchList.on('tap', function() { | 141 | searchList.on('tap', function() { |
142 | + $brandText = $('.search-result .brand-list p').eq(index).find('a').html(); | ||
143 | + $brandHref = $('.search-result .brand-list p').eq(index).find('a').attr('href'); | ||
140 | if (localStorage.getItem('yohoHistory')) { | 144 | if (localStorage.getItem('yohoHistory')) { |
141 | yohoHistory = localStorage.getItem('yohoHistory'); | 145 | yohoHistory = localStorage.getItem('yohoHistory'); |
142 | - searchArray.push(yohoHistory) | 146 | + searchArray.push(yohoHistory); |
147 | + } | ||
148 | + if (searchArray.toString().split($brandText).length < 2) { | ||
149 | + searchArray.push('{"searchName":"' + $brandText + '","searchHref":"' + $brandText + '"}'); | ||
143 | } | 150 | } |
144 | - searchArray.push('{"searchName":"' + | ||
145 | - $('.search-result .brand-list p').eq(index).find('a').html() + | ||
146 | - '","searchHref":"' + $('.search-result .brand-list p') | ||
147 | - .eq(index).find('a').attr('href') + '"}'); | ||
148 | localStorage.setItem('yohoHistory', searchArray); | 151 | localStorage.setItem('yohoHistory', searchArray); |
149 | }); | 152 | }); |
150 | }); | 153 | }); |
@@ -185,11 +188,10 @@ if ($('.brand-search-page').length) { | @@ -185,11 +188,10 @@ if ($('.brand-search-page').length) { | ||
185 | if (localStorage) { | 188 | if (localStorage) { |
186 | 189 | ||
187 | yohoHistory = $.parseJSON('[' + localStorage.getItem('yohoHistory') + ']'); | 190 | yohoHistory = $.parseJSON('[' + localStorage.getItem('yohoHistory') + ']'); |
188 | - console.log(yohoHistory); | ||
189 | if (yohoHistory) { | 191 | if (yohoHistory) { |
190 | $.each(yohoHistory, function(index, content) { | 192 | $.each(yohoHistory, function(index, content) { |
191 | $('<a href="' + content.searchHref + '">' + content.searchName + '</a>').appendTo('.historyList'); | 193 | $('<a href="' + content.searchHref + '">' + content.searchName + '</a>').appendTo('.historyList'); |
192 | - }) | 194 | + }); |
193 | } | 195 | } |
194 | } | 196 | } |
195 | 197 |
-
Please register or login to post a comment