Skip to content

Commit

Permalink
spaces to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
jancborchardt committed Jul 8, 2012
1 parent a8bc9a6 commit 84c471e
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions litewrite.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
function $(id){
return document.getElementById(id)
return document.getElementById(id)
}
var id = localStorage.last_id = localStorage.last_id || 0


function show(id) {
$('editor').innerHTML = localStorage.getItem(id + '_html') || ''
$('editor').innerHTML = localStorage.getItem(id + '_html') || ''
}

function select() {
document.createRange().setStart($('editor'), 0)
getSelection().removeAllRanges()
getSelection().addRange(document.createRange())
document.createRange().setStart($('editor'), 0)
getSelection().removeAllRanges()
getSelection().addRange(document.createRange())
}

function create() {
id = ++localStorage.last_id
$('editor').textContent = ''
localStorage.setItem(id, '')
location.hash = '#'+ id
select()
updateList()
id = ++localStorage.last_id
$('editor').textContent = ''
localStorage.setItem(id, '')
location.hash = '#'+ id
select()
updateList()
}

function updateList() {
var l = parseInt(localStorage.last_id) + 1
var r = []
for (var i=0; i<l; ++i) {
var item = localStorage.getItem(i)
// var itemhtml = localStorage.getItem(i+'_html')
if (item) {
r.push('<a id="item_'+ i +'" href="#'+i+'">'+ item.slice(0, 50) +'</a>')
// this makes for a better cut, but does not always work
// r.push('<a id="item_'+ i +'" href="#'+i+'">'+ itemhtml.slice(0, itemhtml.indexOf('<') +'</a>')
}
}
var l = parseInt(localStorage.last_id) + 1
var r = []
for (var i=0; i<l; ++i) {
var item = localStorage.getItem(i)
// var itemhtml = localStorage.getItem(i+'_html')
if (item) {
r.push('<a id="item_'+ i +'" href="#'+i+'">'+ item.slice(0, 50) +'</a>')
// this makes for a better cut, but does not always work
// r.push('<a id="item_'+ i +'" href="#'+i+'">'+ itemhtml.slice(0, itemhtml.indexOf('<') +'</a>')
}
}

$('entries').innerHTML = r.join('')
highlightSelected()
$('entries').innerHTML = r.join('')
highlightSelected()
}

function check() {
var hash = location.hash
if (hash) {
id = hash.slice(1)
if (id in localStorage) {
show(id)
}
} else {
create()
}
updateList()
select()
document.getElementsByTagName('body')[0].className = localStorage.getItem('bgcolor');
$('aside').className = 'visible';
setTimeout( function() { $('aside').className = ''; } , 2000);
var hash = location.hash
if (hash) {
id = hash.slice(1)
if (id in localStorage) {
show(id)
}
} else {
create()
}
updateList()
select()
document.getElementsByTagName('body')[0].className = localStorage.getItem('bgcolor');
$('aside').className = 'visible';
setTimeout( function() { $('aside').className = ''; } , 2000); // maybe only fade out after typing start
}

function setTitle(str) {
if (str.length >= 30) {
var i = str.lastIndexOf(" ") + 1
if (i)
str = str.slice(0, i)
str += '...'
}
document.title = str
if (str.length >= 30) {
var i = str.lastIndexOf(" ") + 1
if (i)
str = str.slice(0, i)
str += '...'
}
document.title = str
}

function highlightSelected(){
var hash = location.hash.slice(1)
if (!hash) return
var element = $('item_'+hash)
if (element) {
element.className += ' selected'
setTitle(element.textContent)
}
var hash = location.hash.slice(1)
if (!hash) return
var element = $('item_'+hash)
if (element) {
element.className += ' selected'
setTitle(element.textContent)
}
}

function colorToggle(){
Expand Down Expand Up @@ -110,13 +110,13 @@ function formatting(){ // this needs to get incredibly optimized …


$('editor').onkeyup = $('editor').onpaste = function(e){
var html = e.target.innerHTML
if (html != localStorage.getItem(id+'_html')) {
localStorage.setItem(id, e.target.textContent)
localStorage.setItem(id+'_html', html)
updateList()
}
formatting();
var html = e.target.innerHTML
if (html != localStorage.getItem(id+'_html')) {
localStorage.setItem(id, e.target.textContent)
localStorage.setItem(id+'_html', html)
updateList()
}
formatting();
}

onload=onhashchange=check

0 comments on commit 84c471e

Please sign in to comment.