Quick add signature and date
Background
Interpreters often add multiple signatures per interpretation, at specific places in the free text comment fields. It would be nice to have a function that allows easy addition of this, e.g. via button or keyboard shortcut. Users also format these signatures with "blue" when adding.
Note: Should be evaluated against #101 (closed), but that is a much larger issue, so this can anyway be a nice interim solution.
Implementation
Add a button to WYSIWYG editor or keyboard shortcut, or both (button most important), to insert current user (preferentially short form / login name) and date at cursor in any comment field.
Use the icon "User" from https://github.com/danklammer/bytesize-icons, place to the far right on the WYSIWYG button row.
If possible, format the inserted text with text colour "blue" (#0000ff
).
Ideas:
- Keyboard shortcuts can be added using the html attribute accesskey, suggest using
accesskey="s"
for "Alt+S" shortcut (Chrome on Windows/Linux). - Inserting text at cursor can be achieved with simple js (see e.g. stackoverflow)
Proof of concept:
<!DOCTYPE HTML>
<html>
<head>
<title>Add signature</title>
</head>
<body>
<p>
Press button or "ALT+S" to add signature at cursor:
</p>
<input type="button" accesskey="s" id="sign" value="Add signature"></br>
<textarea id="text"></textarea>
</body>
<script>
function typeInTextarea(el, newText) {
var start = el.selectionStart
var end = el.selectionEnd
var text = el.value
var before = text.substring(0, start)
var after = text.substring(end, text.length)
el.value = (before + newText + after)
el.selectionStart = el.selectionEnd = start + newText.length
el.focus()
}
document.getElementById('sign').onclick = function() {
typeInTextarea(document.getElementById('text'), " [username] [current date]");
}
</script>
</html>