Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <head>
- <meta charset="utf-8">
- <link rel="shortcut icon" href="http://g.etfv.co/http://www.sublimetext.com"/><!-- Add favicon from sublimetext -->
- </head>
- <title>Local Text Editor</title>
- <style>
- body { background:#E8E8E8 }
- .note { background:#FFF; border:1px solid #DADADA; box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.1),inset 0 -1px 0 rgba(0, 0, 0, 0.07); color:#666; font-family:helvetica; font-size:1rem; line-height:1.4; margin:3rem auto; padding:0.4rem 2.5rem 2rem; position:relative; width:45rem; }
- .note span { background:#E8E8E8; color:#fff; cursor:pointer; display:inline-block; font-weight:bold; height:25px; left:0; position:absolute; text-align:center; top:0; width:25px; }
- .note span + span { bottom:0px; top:auto; }
- .note span + span + span { bottom:auto; left:auto; right:0; top:0px; }
- </style>
- <script>
- var noteHTML = '<div class="note"><span onClick="addNewNoteBefore(this)">+</span><span onClick="addNewNoteAfter(this)">+</span><span onClick="deleteNote(this)">x</span><h2 contenteditable spellcheck="false">New note</h2><div contenteditable spellcheck="false">Your note</div></div>';
- // Load notes from localstorage on load
- window.onload=function(){
- a=window.localStorage['notes'];
- if(a) document.body.innerHTML=a;
- // localStorage.clear();
- };
- document.addEventListener("keydown", function(e) {
- if(e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) { // Change page title and body background color on CTRL+S (CMD + S on mac) and save the text to local storage
- e.preventDefault();
- window.localStorage['notes']=document.body.innerHTML;
- document.title = 'Saved';
- document.body.style.backgroundColor = "#E8E8E8";
- }
- else { // Change page title and body background color on key pres
- document.title = 'Unsaved';
- document.body.style.backgroundColor = "#F6E8E8";
- }
- }, false);
- function deleteNote(e) {
- e.parentNode.parentNode.removeChild(e.parentNode);
- }
- function addNewNoteBefore(e) {
- var div = e.parentNode;
- div.insertAdjacentHTML('beforeBegin', noteHTML);
- }
- function addNewNoteAfter(e) {
- var div = e.parentNode;
- div.insertAdjacentHTML('afterEnd', noteHTML);
- }
- </script>
- <body>
- <div class="note">
- <span onClick="addNewNoteBefore(this)">+</span>
- <span onClick="addNewNoteAfter(this)">+</span>
- <span onClick="deleteNote(this)">x</span>
- <h2 contenteditable spellcheck="false">Note Title</h2>
- <div contenteditable spellcheck="false">
- Your note... <br /><br />
- (Press CTRL+S or CMD+S on mac to save to localstorage)
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement