Skip to content

Commit bf58f39

Browse files
committed
added hash
1 parent ea2f894 commit bf58f39

1 file changed

Lines changed: 52 additions & 6 deletions

File tree

‎index.html‎

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
.search-result{
2323
padding-top: 10px;
2424
}
25+
.search-result .bd{
26+
overflow-x: scroll;
27+
-webkit-overflow-scrolling: touch;
28+
}
2529
.search-result .label-warp{
2630
display: inline-block;
2731
}
@@ -40,6 +44,9 @@
4044
.main-title{
4145
padding: 0 50px;
4246
}
47+
.search-result .bd{
48+
overflow-x: auto;
49+
}
4350
}
4451
</style>
4552
</head>
@@ -79,6 +86,31 @@ <h5 class="label-warp"><span class="label label-{type}" data-toggle="tooltip" d
7986
<script src="src/lib/bootstrap.min.js"></script>
8087
<script>
8188
$(function () {
89+
var HashHandler = (function () {
90+
var lc = window.location;
91+
92+
function getByURL(url) {
93+
var hash;
94+
url && decodeURIComponent(url).replace(new RegExp('#(.*)', 'g'), function ($1, $2) {
95+
hash = $2;
96+
});
97+
return hash;
98+
}
99+
100+
function get() {
101+
return getByURL(lc.hash);
102+
}
103+
104+
function set(hash) {
105+
lc.hash = hash;
106+
}
107+
108+
return {
109+
get: get,
110+
set: set,
111+
getByURL: getByURL
112+
}
113+
})();
82114
function randomColor() {
83115
var letters = '0123456789ABCDEF'.split('');
84116
var color = '#';
@@ -169,8 +201,11 @@ <h5 class="label-warp"><span class="label label-{type}" data-toggle="tooltip" d
169201
searchObj;
170202

171203
function bindEvent(){
204+
window.addEventListener('hashchange', onLocationHashChanged, false);
172205
els.searchInput.on('keyup',renderSearchBtn);
173-
els.searchBtn.on('click',onSearch);
206+
els.searchBtn.on('click',function(){
207+
onSearch();
208+
});
174209
els.searchInput.keypress(function (e) {
175210
if (e.which == 13) {
176211
onSearch();
@@ -181,12 +216,23 @@ <h5 class="label-warp"><span class="label label-{type}" data-toggle="tooltip" d
181216
function init(){
182217
bindEvent();
183218
searchObj = new searchPage(renderSearchResult);
219+
onLocationHashChanged();
184220
renderAnalytics();
185221
}
186222

187-
function onSearch(){
188-
var val = els.searchInput.val().trim();
223+
function onLocationHashChanged(e){
224+
e && e.preventDefault();
225+
var hash = HashHandler.get();
226+
hash && onSearch(decodeURIComponent(hash));
227+
}
228+
function onSearch(val){
229+
if(val==els.lastVal){return;}
230+
val = val || els.searchInput.val().trim();
231+
els.searchInput.val(val);
189232
if(val.length){
233+
if(val != els.lastVal){
234+
HashHandler.set(encodeURIComponent(val));
235+
}
190236
els.lastVal = val;
191237
els.valRegs = [];
192238
els.lastVal.replace(/\s+/ig,'+').split('+').forEach(function(key){
@@ -233,10 +279,10 @@ <h5 class="label-warp"><span class="label label-{type}" data-toggle="tooltip" d
233279
els.searchBtn.html((val.length && val==els.lastVal)?'Next Group':'Search');
234280
}
235281

236-
function renderAnalytics(){
282+
function renderAnalytics(param){
237283
setTimeout(function(){
238-
els.body.append('<iframe src="http://www.mihtool.com/analytics.html?codelf" style="display: none;width: 0;height: 0;border: 0;"></iframe>');
239-
},3000);
284+
els.body.append('<iframe src="http://www.mihtool.com/analytics.html?codelf'+(param?('&s='+param):'')+'" style="display: none;width: 0;height: 0;border: 0;"></iframe>');
285+
},param?500:3000);
240286
}
241287

242288
function getRandomLabelType(){

0 commit comments

Comments
 (0)