Authored by runner

search update

@@ -29,6 +29,20 @@ var ranToken = writeSearch.getRanToken(); @@ -29,6 +29,20 @@ var ranToken = writeSearch.getRanToken();
29 var chHammer, cHammer; 29 var chHammer, cHammer;
30 30
31 chHammer = new Hammer($clearHistory[0]); 31 chHammer = new Hammer($clearHistory[0]);
  32 +
  33 +function isLocalStorageSupported() {
  34 + var testKey = 'test',
  35 + storage = Window.prototype.localStorage;
  36 +
  37 + try {
  38 + storage.setItem(testKey, 'testValue');
  39 + storage.removeItem(testKey);
  40 + return true;
  41 + } catch (error) {
  42 + return false;
  43 + }
  44 +}
  45 +
32 chHammer.on('tap', function() { 46 chHammer.on('tap', function() {
33 dialog.showDialog({ 47 dialog.showDialog({
34 dialogText: '您确定要删除您的最近搜索吗?', 48 dialogText: '您确定要删除您的最近搜索吗?',
@@ -37,7 +51,9 @@ chHammer.on('tap', function() { @@ -37,7 +51,9 @@ chHammer.on('tap', function() {
37 rightBtnText: '确定' 51 rightBtnText: '确定'
38 } 52 }
39 }, function() { 53 }, function() {
40 - localStorage.removeItem('historys'); 54 + if (isLocalStorageSupported()) {
  55 + localStorage.removeItem('historys');
  56 + }
41 57
42 $history.html(''); 58 $history.html('');
43 $historySearch.hide(); 59 $historySearch.hide();
@@ -126,19 +142,6 @@ $search.on('touchend', function() { @@ -126,19 +142,6 @@ $search.on('touchend', function() {
126 return false; 142 return false;
127 }); 143 });
128 144
129 -function isLocalStorageSupported() {  
130 - var testKey = 'test',  
131 - storage = Window.prototype.localStorage;  
132 -  
133 - try {  
134 - storage.setItem(testKey, 'testValue');  
135 - storage.removeItem(testKey);  
136 - return true;  
137 - } catch (error) {  
138 - return false;  
139 - }  
140 -}  
141 -  
142 //初始化历史搜索的内容 145 //初始化历史搜索的内容
143 (function() { 146 (function() {
144 var html = '', 147 var html = '',
@@ -146,7 +149,9 @@ function isLocalStorageSupported() { @@ -146,7 +149,9 @@ function isLocalStorageSupported() {
146 historys, i, num = 1; 149 historys, i, num = 1;
147 150
148 if (localStorage) { 151 if (localStorage) {
149 - historys = localStorage.getItem('historys'); 152 + if (isLocalStorageSupported()) {
  153 + historys = localStorage.getItem('historys');
  154 + }
150 155
151 if (historys && historys.length > 0) { 156 if (historys && historys.length > 0) {
152 historys = historys.split(ranToken); 157 historys = historys.split(ranToken);
@@ -174,6 +179,6 @@ function isLocalStorageSupported() { @@ -174,6 +179,6 @@ function isLocalStorageSupported() {
174 } 179 }
175 }()); 180 }());
176 181
177 -if (isLocalStorageSupported) { 182 +if (isLocalStorageSupported()) {
178 writeSearch.bindWirteLocal($form); 183 writeSearch.bindWirteLocal($form);
179 } 184 }
@@ -6,6 +6,19 @@ @@ -6,6 +6,19 @@
6 6
7 var ranToken = ' ??++ '; 7 var ranToken = ' ??++ ';
8 8
  9 +function isLocalStorageSupported() {
  10 + var testKey = 'test',
  11 + storage = Window.prototype.localStorage;
  12 +
  13 + try {
  14 + storage.setItem(testKey, 'testValue');
  15 + storage.removeItem(testKey);
  16 + return true;
  17 + } catch (error) {
  18 + return false;
  19 + }
  20 +}
  21 +
9 //获取分隔符 22 //获取分隔符
10 function getRanToken() { 23 function getRanToken() {
11 return ranToken; 24 return ranToken;
@@ -18,7 +31,9 @@ function bindWirteLocal($form) { @@ -18,7 +31,9 @@ function bindWirteLocal($form) {
18 historys; 31 historys;
19 32
20 if (localStorage) { 33 if (localStorage) {
21 - historys = localStorage.getItem('historys'); 34 + if (isLocalStorageSupported()) {
  35 + historys = localStorage.getItem('historys');
  36 + }
22 37
23 historys = historys ? historys : ''; 38 historys = historys ? historys : '';
24 39
@@ -31,8 +46,9 @@ function bindWirteLocal($form) { @@ -31,8 +46,9 @@ function bindWirteLocal($form) {
31 } 46 }
32 47
33 historys += query + ranToken; 48 historys += query + ranToken;
34 -  
35 - localStorage.setItem('historys', historys); 49 + if (isLocalStorageSupported()) {
  50 + localStorage.setItem('historys', historys);
  51 + }
36 } 52 }
37 }); 53 });
38 } 54 }