-
Notifications
You must be signed in to change notification settings - Fork 16
Created both localStorage and FileReader apps #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f142978
6f74076
b1929fd
ae10a03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Hey grandma, I'm going to the store to get some bananas. I love bananas. A banana is all that I need for all my fruity needs. Would you like a banana too? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
| <title>FileReader Example</title> | ||
| <meta name="description" content=""> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <style type="text/css"> | ||
| body { | ||
| background:#584f44; | ||
| font-family:"Monaco"; | ||
| color:white; | ||
| text-align:center; | ||
| } | ||
| h1 { | ||
| text-align:center; | ||
| } | ||
| .block { | ||
| width:50%; | ||
| padding:50px; | ||
| margin:50px auto 0 auto; | ||
| background:rgba(0,0,0,0.1); | ||
| border:4px solid #e1871c; | ||
| text-align:left; | ||
| font-size:22px; | ||
| } | ||
| .block table { | ||
| width:100%; | ||
| } | ||
| .block table thead { | ||
| opacity:0.5; | ||
| } | ||
| th, td { | ||
| width:50%; | ||
| vertical-align:top; | ||
| } | ||
| .block em { | ||
| color:#44ce19; | ||
| } | ||
| input[type=text]{ | ||
| font-size:18px; | ||
| border:2px solid #44ce19; | ||
| padding:5px; | ||
| background:transparent; | ||
| color:white; | ||
| } | ||
| input[type=text]:focus{ | ||
| background:rgba(0,0,0,0.1); | ||
| } | ||
| section { | ||
| margin:15px 0; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <main> | ||
| <h1>Apples and Bananas</h1> | ||
| <section class="block"> | ||
| <form action="#" id="upload"> | ||
| <section> | ||
| <label> | ||
| Find: <input type="text" id="find"> | ||
| </label> | ||
| <label> | ||
| Replace: <input type="text" id="replace"> | ||
| </label> | ||
| </section> | ||
| <label> | ||
| File: <input type="file" id="file"> | ||
| </label> | ||
| </form> | ||
| <hr> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hr tags are semantically meaningless. Please remove. |
||
| <table> | ||
| <thead> | ||
| <tr> | ||
| <td>Before</td> | ||
| <td>After</td> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr> | ||
| <td id="input"></td> | ||
| <td id="output"></td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| </section> | ||
|
|
||
| </main> | ||
| <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | ||
| <script> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make scripts external |
||
| $(document).ready(function(){ | ||
|
|
||
| $('#file').change(function(){ | ||
|
|
||
| // Create a new file reader | ||
| var reader = new FileReader(); | ||
|
|
||
| // Read the file as text | ||
| reader.readAsText(this.files[0]); | ||
|
|
||
| // When the file loads, find and replace text | ||
| reader.onload = function() { | ||
| $('#input').html(this.result); | ||
|
|
||
| var find = $('#find').val(); | ||
| var replace = $('#replace').val(); | ||
|
|
||
| // Find global, case insensitive terms | ||
| var PATTERN = new RegExp(find, 'gi'); | ||
| var result = this.result.replace(PATTERN, function(input){ | ||
| var letter1 = input[0]; | ||
|
|
||
| // Maintain capitalized words | ||
| if(letter1 === letter1.toUpperCase()){ | ||
| replace = " " + replace[0].toUpperCase() + replace.slice(1); | ||
| } | ||
|
|
||
| // Return an HTML string | ||
| return "<em>" + replace + "</em>"; | ||
| }); | ||
|
|
||
| // Set the output text | ||
| $('#output').html(result); | ||
| } | ||
|
|
||
| // Updated automatically as we type | ||
| $('#find, #replace').keyup(function(){ | ||
| reader.onload(); | ||
| }); | ||
|
|
||
| }); | ||
| }); | ||
|
|
||
| </script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| Queen: And because you've been so good to poor old Granny, I'll share a secret with you. This is no ordinary apple, it's a magic wishing apple. | ||
| Snow White: A wishing apple? | ||
| Queen: Yes! One bite, and all your dreams will come true. | ||
| Snow White: Really? | ||
| Queen: Yes, girlie. Now, make a wish, and take a bite. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Local Storage Demo</title> | ||
| <style type="text/css"> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make CSS external |
||
| body { | ||
| margin:0; | ||
| font-family:Monaco; | ||
| } | ||
| .circle { | ||
| height:100px; | ||
| width:100px; | ||
| border-radius:100px; | ||
| position:absolute; | ||
| background:rgb(162, 207, 81); | ||
| border:5px solid rgb(120, 147, 73); | ||
| cursor:move; | ||
| } | ||
| main { | ||
| position:fixed; | ||
| height:100%; | ||
| width:100%; | ||
| } | ||
| main h1 { | ||
| text-align:center; | ||
| font-size:20px; | ||
| color:gray; | ||
| } | ||
| </style> | ||
| <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> | ||
| <script type="text/javascript" src="js/jquery-ui.min.js"></script> | ||
| </head> | ||
| <body> | ||
| <main> | ||
| <header> | ||
| <h1></h1> | ||
| </header> | ||
| <div class="circle" role="button"></div> | ||
| </main> | ||
| <script type="text/javascript"> | ||
| $(document).ready(function(){ | ||
|
|
||
| // Get the element | ||
| var elem = $('.circle'); | ||
|
|
||
| // Set heading data | ||
| var heading = $('header h1'); | ||
|
|
||
| function setHeading(offset){ | ||
| heading.text("Left: " + Math.round(offset.left) + "px" + " Top: " + Math.round(offset.top) + "px"); | ||
| } | ||
|
|
||
| // Saves the data to local storage | ||
| function saveLocation(offset){ | ||
| localStorage.setItem("circleX", offset.left); | ||
| localStorage.setItem("circleY", offset.top); | ||
| } | ||
|
|
||
| // Set an event to act on drag | ||
| elem.draggable({ | ||
| containment: 'main', | ||
| drag: function(){ | ||
| var offset = $(this).offset(); | ||
| setHeading(offset); | ||
| saveLocation(offset); | ||
| } | ||
| }); | ||
|
|
||
| // Sets element from the data | ||
| elem.setPosition = function(){ | ||
| var x = localStorage["circleX"]; | ||
| var y = localStorage["circleY"]; | ||
| setHeading({top:y, left:x}); | ||
|
|
||
| elem.offset({ | ||
| left: x, | ||
| top: y | ||
| }); | ||
| } | ||
|
|
||
| // Initially render | ||
| elem.setPosition(); | ||
|
|
||
| // Set an interval to check for changes | ||
| var relayEnabled; | ||
|
|
||
| // Don't run stuff while focused | ||
| $(window).blur(function(){ | ||
| relayEnabled = setInterval(elem.setPosition, 1); | ||
| }).focus(function(){ | ||
| clearInterval(relayEnabled); | ||
| }); | ||
|
|
||
| }); | ||
| </script> | ||
| </body> | ||
| </html> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs an additional blank line at the bottom |
||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Styles should be in a separate file. Please make external.