Skip to content

Instantly share code, notes, and snippets.

@Scuilion
Created October 2, 2015 19:11
Show Gist options
  • Save Scuilion/ba7597c4b9b5f8e5d653 to your computer and use it in GitHub Desktop.
Save Scuilion/ba7597c4b9b5f8e5d653 to your computer and use it in GitHub Desktop.
Standup Notes
<html>
<head>
<title>Daily Standup</title>
<style type="text/css">
#dailyStatus {
width: 100%; height: 100%; left: 0; top: 0; z-index: 10; padding: 4rem; font-size:2rem; font-family:Helvetica; line-height:1.4; margin:0 auto;white-space: pre;overflow: auto
}
</style>
<script>
var idbSupported = false; var db; var dbversion = 4; var data = ''; var dailyStatusDiv;
var addStatus = function(name, dStatus, order) {
var store = db.transaction(["attendee"],"readwrite").objectStore("attendee");
var ob = store.get(name);
var attendee = {
name:name,
dailyStatus:dStatus,
order:order,
created:new Date()
}
ob.onsuccess = function(e) {
if (e.target.result) {
store.put(attendee);
} else {
store.add(attendee);
}
}
}
var paint = function() {
var request = db.transaction(["attendee"],"readwrite").objectStore("attendee").openCursor();
request.onsuccess = function(e) {
var aCur = e.target.result;
if (aCur) {
data += aCur.value['name'] + ': ' + aCur.value['dailyStatus'] + "\n"; //&#13;&#10;
aCur.continue();
} else {
dailyStatusDiv.value = data;
data = '';
}
}
}
document.addEventListener("DOMContentLoaded", function(){
dailyStatusDiv = document.getElementById("dailyStatus");
if("indexedDB" in window) {
idbSupported = true;
}
if(idbSupported) {
var openRequest = indexedDB.open("standup", dbversion);
openRequest.onupgradeneeded = function(e) {
var thisDB = e.target.result;
thisDB.deleteObjectStore("attendee");
thisDB.createObjectStore("attendee", { keyPath: "name" });
}
openRequest.onsuccess = function(e) {
db = e.target.result;
paint();
}
}
dailyStatusDiv.focus();
dailyStatusDiv.select();
}, false);
function storeStatus(element, index, array) {
if (!element || !element.trim()) return;
var dayStatus = element.split(':')
var name = dayStatus[0].trim();
var status = dayStatus[1].trim();
if (dayStatus.length >= 1 && dayStatus.length <= 2) {
addStatus(name, status, index);
}
}
function getLines() {
return dailyStatusDiv.value.split("\n");
}
function getLineNum() {
return dailyStatusDiv.value.substr(0, dailyStatusDiv.selectionStart).split("\n").length;
}
function countCharInLines(tillLine) {
var lines = getLines();
var startPos = 0;
for(var i = 0; i < tillLine; i++) {
startPos += lines[i].length;
}
return startPos;
}
function seperatorPosition(lineNumber) {
var startPos = countCharInLines(lineNumber);
startPos += getLines()[lineNumber].split(':')[0].length + 3;
return startPos + lineNumber - 1;
}
function endOfLine(lineNumber) {
var startPos = countCharInLines(lineNumber);
var endPos = getLines()[lineNumber].length ;
return startPos + endPos + lineNumber;
}
function clearSelection() {
var end = dailyStatusDiv.selectionEnd;
window.getSelection().removeAllRanges();
dailyStatusDiv.selectionStart = end;
}
function enter(e){
if (e.keyCode === 13){
dailyStatusDiv.value.split("\n").forEach(storeStatus);
var lineNumber = getLineNum();
if (e.shiftKey) {
if (lineNumber <= 1) {
e.preventDefault();
return;
}
lineNumber -= 2;
}
if (e.altKey) {
clearSelection();
return;
}
var start = seperatorPosition(lineNumber);
var end = endOfLine(lineNumber);
dailyStatusDiv.setSelectionRange(start, end);
e.preventDefault();
}
return false;
}
</script>
</head>
<body>
<textarea id="dailyStatus" onkeypress="enter(event)" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment