* removed duplicated code (#2375)

* give the search field focus on page load for faster interaction
This commit is contained in:
Beat 2017-04-03 20:42:38 +02:00 committed by Fabian Affolter
parent c74ab2cb5c
commit 8c65fd0c47

View File

@ -124,6 +124,11 @@ allComponents.pop(); // remove placeholder element at the end
// set default value in search from URL // set default value in search from URL
jQuery('.component-search input').val(decodeURIComponent(location.hash).substring(8)); jQuery('.component-search input').val(decodeURIComponent(location.hash).substring(8));
} }
// add focus to the search field - even on IE
setTimeout(function () {
jQuery('.component-search input').focus();
}, 1);
} }
init(); init();
@ -223,36 +228,6 @@ allComponents.pop(); // remove placeholder element at the end
return false; return false;
}); });
/**
* Simple debounce implementation, based on http://davidwalsh.name/javascript-debounce-function
*/
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
};
};
// update view by search text
$('.component-search input').keyup(debounce(function() {
var text = $(this).val();
// sanitize input
text = text.replace(/[(\?|\&\{\}\(\))]/gi, '');
updateHash('#search/' + text);
applyFilter();
}, 500));
/** /**
* Simple debounce implementation, based on http://davidwalsh.name/javascript-debounce-function * Simple debounce implementation, based on http://davidwalsh.name/javascript-debounce-function
*/ */
@ -286,6 +261,5 @@ allComponents.pop(); // remove placeholder element at the end
window.addEventListener('hashchange', applyFilter); window.addEventListener('hashchange', applyFilter);
applyFilter(); applyFilter();
})(); })();
</script> </script>