playing with kboard shortcts
by pj_js15
HTML
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.3/mousetrap.min.js"></script>
</head>
<body>
Press Alt + X
<div class="placeholder_input">
<input type="text" id="username" maxlength="100" />
<div class="placeholder_container">
<div class="placeholder">username</div>
</div>
</div>
<div class="placeholder_input">
<input type="text" id="category" maxlength="100" />
<div class="placeholder_container">
<div class="placeholder">category</div>
</div>
</div>
<button id="btnOrder">
Order
</button>
</body>
</html>
JavaScript
$().ready(function(){
Mousetrap.bind(['alt+x'], function() {
console.log('Alt + X pressed!');
$("#username").focus();
return false;
});
Mousetrap.bind(['shift+c'], function() {
console.log('Alt + f + u pressed!');
$("#username").focus();
return false;
});
Mousetrap.bind(['shift+a'], function() {
console.log('Alt + f + c pressed!');
$("#category").focus();
return false;
});
Mousetrap.bind(['ctrl+g+o'], function() {
console.log('redirecting page!');
location.href='www.google.com';
return false;
});
Mousetrap.bind(['ctrl+shift+o+k'], function() {
console.log('OK!');
return false;
});
Mousetrap.bind(['shift+o'], function() {
console.log('order button!');
$('#btnOrder').click();
return false;
});
/*
$("#username").focus(function() {
$(this).next().hide();
});
$(".placeholder_input").mouseup(function() {
$(this).children(":first").focus();
});
*/
var test = '(test) Sample title';
function removeBrackets(input) {
return input
.replace(/{.*?}/g, "")
.replace(/\[.*?\]/g, "")
.replace(/<.*?>/g, "")
.replace(/\(.*?\)/g, "");
}
console.log(test);
console.log(removeBrackets(test));
$('#btnOrder').click(function(){
console.log('order button clicked');
})
});