var pris = null;
var img = "";
function submitForm(formname) {
$('#' + formname).removeAttr('onsubmit')
$('#' + formname).attr('action', "" + baseurl + "/search_result_page.php").submit();
}
function truncate( str, n, useWordBoundary ){
if (str.length <= n) { return str; }
const subString = str.substr(0, n-1); // the original check
return (useWordBoundary
? subString.substr(0, subString.lastIndexOf(" "))
: subString) + "…";
};
$('#searchdefault').on('keydown', function(e) {
if (e.which == 13 && !$('.autocomplete-suggestion').hasClass('selected')) {
$('#search-form').removeAttr('onsubmit')
$('#search-form').attr('action', "" + baseurl + "/search_result_page.php").submit();
}
});
$('#searchdefault').autoComplete({
delay: 1000,
source: function(term) {
var tmphtml = "
";
resultdiv = $('#searchdefault').data('resultdiv');
$.getJSON(baseurl + '/live_search_result.php', { q: term }, function(data) {
var displayItem = '';
$.each(data.items,
function(key, item) {
if (item.thumb.length > 40) {
img = "
";
} else {
img = "
";
}
if (!item.price) {
item.price = "";
item.description=truncate(item.description,200,true);
displayItem = `
`;
displayItem += `
${img}
`;
displayItem += `
${item.title}
`;
displayItem += `${item.description}
`;
} else {
item.description=truncate(item.description,150,true);
displayItem = `
`;
displayItem += `
${img}
`;
displayItem += `
${item.title}
`;
displayItem += `${item.description}
`;
displayItem += `
${item.price}
`;
}
tmphtml = tmphtml + displayItem;
})
topmessage = "
Du søgte på \"" + term + "\"
";
bottommessage = "
SE ALLE RESULTATER HER
";
$('.submenu').fadeOut(100);
$('#' + resultdiv).show(200);
$('#' + resultdiv).html('' + topmessage + '' + tmphtml + '
' + '' + bottommessage + '');
})
},
});
$('#mobilesearchdefault').autoComplete({
delay: 1500,
source: function(term) {
var tmphtml = "";
resultdiv = $('#mobilesearchdefault').data('resultdiv');
$.getJSON(baseurl + '/live_search_result.php', { q: term }, function(data) {
var displayItem = '';
$.each(data.items,
function(key, item) {
if (item.thumb.length > 40) {
img = "