whoami.update();
//whoami.settings2();
- document.querySelector(
- "button#settings"
- ).onclick = function() {
+ document.querySelector("button#settings").onclick = function() {
//window.whoami.settings();
//window.whoami.update();
whoami.settings2();
* @param {string} storageKey string local Storage key
*/
window.notepad = function(selector, storageKey) {
- //console.log("window.notepad(\""+selector+"\", \""+storageKey+"\")")
-
let elem = document.querySelector(selector);
-
+
+ /**
+ * Load content from localStorage if possible
+ */
if (localStorage.getItem(storageKey) !== null) {
console.debug("window.notepad(): Loading from LocalStorage")
elem.innerHTML = localStorage.getItem("notepad");
}
-
+
+ /**
+ * Save to localStorage after loosing focus
+ */
elem.addEventListener("focusout", function() {
console.debug("window.notepad(): Focus lost. Storing on LocalStorage");
localStorage.setItem(storageKey, document.querySelector(selector).innerHTML);
-
});
+
+ /**
+ * Allow inserting Tabs
+ *
+ * @see https://jsfiddle.net/2wAzx/13/
+ */
+ elem.onkeydown = function(e) {
+ if (e.keyCode === 9) { // tab was pressed
+ // get caret position/selection
+ var val = this.value,
+ start = this.selectionStart,
+ end = this.selectionEnd;
+ // set textarea value to: text before caret + tab + text after caret
+ this.value = val.substring(0, start) + '\t' + val.substring(end);
+ // put caret at right position again
+ this.selectionStart = this.selectionEnd = start + 1;
+ // prevent the focus lose
+ return false;
+ }
+ };
};