Skip to content

Instantly share code, notes, and snippets.

@lewis-carson
Created December 19, 2017 17:09
Show Gist options
  • Save lewis-carson/12ae89b87f0ebddb1ca095be4ee16ebc to your computer and use it in GitHub Desktop.
Save lewis-carson/12ae89b87f0ebddb1ca095be4ee16ebc to your computer and use it in GitHub Desktop.
$(document).delegate('#textbox', 'keydown', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
e.preventDefault();
var start = this.selectionStart;
var end = this.selectionEnd;
// set textarea value to: text before caret + tab + text after caret
$(this).val($(this).val().substring(0, start) +
"\t" +
$(this).val().substring(end));
// put caret at right position again
this.selectionStart =
this.selectionEnd = start + 1;
}
if (keyCode == '223') {
document.getElementById('textbox').value += ' -';
}
});
function start() {
window.setInterval(function() {
updatetime();
}, 200);
}
function updatetime() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
var today = dd + '/' + mm + '/' + yyyy;
document.getElementById("time").innerHTML = today;
var d = new Date();
var mins = String(d.getMinutes());
var hours = String(d.getHours());
if (hours.length == 1) {
hours = '0' + hours;
}
if (mins.length == 1) {
mins = '0' + mins;
}
var time = hours + ':' + mins;
document.getElementById("time").innerHTML += ' @ ' + time;
}
$('textarea').keydown(function(e){
var ingnore_key_codes = [223];
if ($.inArray(e.keyCode, ingnore_key_codes) >= 0){
e.preventDefault();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment