Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Open and Save file now works

  • Loading branch information...
commit e95bddc1b22bf5ab3b9c2f05860fa1922190dccb 1 parent ad39dec
@swaroopch authored
Showing with 53 additions and 5 deletions.
  1. +18 −0 index.html
  2. +35 −5 index.js
View
18 index.html
@@ -16,10 +16,22 @@
</head>
<body>
<div class="row">
+ <div id="choose-file-section" class="twelve columns">
+ <div class="panel">
+ <h2>Choose File</h2>
+ <input id="choose-file" type="file"/>
+ </div>
+ </div>
+ </div>
+ <div class="row">
<div id="text-section" class="six columns">
<h2>Pandoc text</h2>
<div class="panel">
+ <button class="button save-to-file">Save</button>
+ <br/>
+ <br/>
<textarea id="source-text" rows="50"></textarea>
+ <button class="button save-to-file">Save</button>
</div>
</div>
<div id="preview-section" class="six columns">
@@ -31,6 +43,12 @@
</div>
</div>
+ <div id="save-success-dialog" class="reveal-modal">
+ <p>
+ Saved!
+ </p>
+ </div>
+
<!-- Included JS Files (Compressed) -->
<script src="foundation/javascripts/jquery.js"></script>
<script src="foundation/javascripts/foundation.min.js"></script>
View
40 index.js
@@ -3,29 +3,59 @@ $(function() {
var fs = require("fs");
var exec = require("exec");
- var tmp_source_file = os.tmpDir() + "kalam.txt";
+ var tmpSourceFile = os.tmpDir() + "kalam.txt";
function render() {
var text = $("#source-text").val();
- fs.writeFile(tmp_source_file, text, function(err) {
+ fs.writeFile(tmpSourceFile, text, function(err) {
if (err) {
alert(err);
return;
}
- var pandoc_command = ["pandoc",
+ var pandocCommand = ["pandoc",
"-f",
"markdown",
"-t",
"html5",
"-i",
- tmp_source_file];
- exec(pandoc_command, function(err, out, code) {
+ tmpSourceFile];
+ exec(pandocCommand, function(err, out, code) {
$("#preview-html").html(out);
});
});
}
window.setInterval(render, 3000);
+
+ function readFile(filename) {
+ fs.readFile(filename, function(err, data) {
+ if (err) {
+ alert(err);
+ return;
+ }
+
+ $("#source-text").val(data);
+ });
+ }
+
+ function writeFile(filename, content) {
+ fs.writeFile(filename, content, "utf8", function() {
+ $("#save-success-dialog").reveal();
+ });
+ }
+
+ $("#choose-file").on("change", function(eventData) {
+ var filename = $("#choose-file").val();
+ readFile(filename);
+ });
+
+ $(".save-to-file").on("click", function() {
+ var filename = $("#choose-file").val();
+ if (!filename || filename === "") {
+ return;
+ }
+ writeFile(filename, $("#source-text").val());
+ });
});
Please sign in to comment.
Something went wrong with that request. Please try again.