if (typeof (itsmo) == 'undefined') {
var itsmo = {};
}
if (typeof (itsmo.history) == 'undefined') {
itsmo.history = {};
}
itsmo.history.templateHistoryItem =
"
\
\
\
[historyName]\
\
\
";
itsmo.history.selecting = false;
itsmo.history.setFreewordInputBox = function (idInput, nameClassBox, callbacks) {
var eInput = $('div #' + idInput);
var eSuggestBox = $('div form div.' + nameClassBox);
eInput.bind('focus', function () {
if ($.trim(eInput.val()).length > 0) {
itsmo.suggest.getSuggestion();
} else {
itsmo.history.setHistorySearch(eSuggestBox);
}
}).blur(function () {
if (!itsmo.history.selecting) {
eSuggestBox.fadeOut('fast');
if (null != callbacks && undefined != callbacks && (typeof callbacks.blur != 'undefined')) {
callbacks.blur();
}
}
}).bind('input',function (e) {
if ($.trim(eInput.val()).length > 0) {
if (itsmo.suggest.saveRequestSgt != null) {
itsmo.suggest.saveRequestSgt.abort();
}
itsmo.suggest.getSuggestion();
} else {
itsmo.history.setHistorySearch(eSuggestBox);
}
return false;
}).keydown(function (e){
if(e.keyCode == 40){
itsmo.history.selecting = true;
$('div.suggestion ul').focus();
$('div.suggestion li:first-child').addClass('active');
} else if (e.keyCode == 38){
return false;
}
});
$('div.suggestion').on('keydown', 'ul', function (e) {
if (e.keyCode == 40) {
var lastActive = $(this).find('li.active');
if (lastActive.is(':last-child')){
return false;
}
lastActive.removeClass('active');
lastActive.next().addClass('active');
return false;
} else if (e.keyCode == 38) {
var lastActive = $(this).find('li.active');
if (lastActive.is(':first-child')){
return false;
}
lastActive.removeClass('active');
lastActive.prev().addClass('active');
return false;
}
}).on('keyup', 'ul', function (e) {
if (e.keyCode == 13) {
$(this).find('li.active').find('a').click();
return false;
}
}).on('blur', 'ul', function () {
eSuggestBox.fadeOut('fast');
if (null != callbacks && undefined != callbacks && (typeof callbacks.blur != 'undefined')) {
callbacks.blur();
}
itsmo.history.selecting = false;
});
};
//cookie => localstorage フォーマットも変更
itsmo.history.setHistorySearch = function (eSuggestBox) {
var ulHtml = '';
let ls_history = [];
if(localStorage.getItem("itsmonaviweb:search:history") != null){
ls_history = JSON.parse(localStorage.getItem("itsmonaviweb:search:history"));
}
if(ls_history.length > 0){
for(let i in ls_history){
let text = ls_history[i].text;
let id = ls_history[i].id;//codeも同じ
let type =ls_history[i].type;
var url ;
if (type == undefined){
url = "/search/freeword/" + text;
id ='';
type='';
}else if(type == 'genre'){
url = "/c/" + text + "/" + id + "/";
}else if(type == 'address'){
//暫定対応
url = "/search/freeword/" + text;
}else if(type == 'station'){
url = "/detail/" + ls_history[i]['tag'][1].substr( 8 ) + "-" + id + "/";
}else if(type == 'poi' ){
url = "/detail/" + ls_history[i]['tag'][0].substr( 4 ) + "-" + id + "/";
}
ulHtml += "- "
+ "" + text + "
";
}
ulHtml += "
";
eSuggestBox.html(ulHtml);
if (ls_history.length > 0) {
eSuggestBox.fadeIn('fast');
} else {
eSuggestBox.hide();
}
}else{
eSuggestBox.hide();
}
};
itsmo.history.clickHistory = function(word, url, key, eInput){
$('#' + eInput).val(word);
if(url != ''){
location.href = url;
}else{
location.href = '/search/freeword/' + word ;
}
};