﻿$(document).ready(function() {
        
    restoreContents();
    
    var editButton = $('#edit');
    var clearButton = $('#clear');
    
    editButton.bind('click', toggleEditContent);
    clearButton.bind('click', resetContent);
    
    function saveContents() {
        var todoList = $('#todolist').html();
        localStorage['todoList'] = todoList;
    }
    
    function restoreContents() {
        var myTodoList = localStorage['todoList'];
        if (myTodoList != undefined) {
            $('#todolist').html(myTodoList);
        }
    }
    
    function toggleEditContent(e) {
        if ($('#todolist').attr('contenteditable') == 'false') {
            $('#todolist').attr('contenteditable', 'true');
            editButton.val('Speichern');
            $('#todolist').focus();
        } else {
            $('#todolist').attr('contenteditable', 'false');
            editButton.val('Bearbeiten');
            saveContents();
        }
    }
    
    function resetContent(e) {
        localStorage.clear();
        window.location.reload();
    }
    
});

