Skip to content

Instantly share code, notes, and snippets.

@markhillard
Created March 12, 2017 05:25
Show Gist options
  • Save markhillard/2e08cd8901a40f9c103c27f838c8a5bb to your computer and use it in GitHub Desktop.
Save markhillard/2e08cd8901a40f9c103c27f838c8a5bb to your computer and use it in GitHub Desktop.
Chalkboard

Chalkboard

This is a lightly styled textarea that remembers what you type even if you reload the page or close your browser. Behold the power of HTML5 Local Storage!

A Pen by Mark Hillard on CodePen.

License.

<textarea id="edit" placeholder='Place your cursor in here and type away! Any changes you make will be saved on "change", "keyup", "focusout", "input" and "paste" events. Your previous edits will persist even if you reload the page or close your browser.'></textarea>
/*! HTML5 Local Storage Functions */
$(document).ready(function () {
if (typeof (localStorage) === 'undefined') {
alert('Your browser does not support HTML5 Local Storage. Your changes will not be saved.');
} else {
$('#edit').each(function () {
var save = $(this).attr('name');
var content = localStorage.getItem(save);
if (content !== null) {
$(this).val(content);
}
// save value in <textarea> on "change", "keyup", "focusout", "input" and "paste" events...
$(this).bind('change keyup focusout input paste', function () {
localStorage[save] = $(this).val();
});
});
}
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
@import url("//fonts.googleapis.com/css?family=Architects+Daughter");
html,body {
background-color:#333;
font-size:16px;
height:100%;
margin:0;
padding:15px;
}
*,::before,::after { box-sizing:border-box; }
textarea { appearance:none; background:none; }
textarea:focus { outline:none }
#edit {
background-color:#333;
border:none;
color:#fff;
display:block;
font-family:"Architects Daughter", arial, sans-serif;
font-size:150%;
height:100%;
margin:0;
overflow:auto;
padding:0;
resize:none;
width:100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment