Skip to content

Commit 648b90a

Browse files
committed
on paste, render right away
1 parent fe1946c commit 648b90a

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

index.html

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
var url;
3535
var lastSaved;
3636

37-
function log(msg) {
38-
return $(".console").removeClass("error").html(msg);
39-
}
37+
// function log(msg) {
38+
// return $(".console").removeClass("error").html(msg);
39+
// }
4040

41-
function error(msg) {
42-
return log(msg).addClass("error");
43-
}
41+
// function error(msg) {
42+
// return log(msg).addClass("error");
43+
// }
4444

4545
function doJSON() {
4646
// get input JSON, try to parse it
@@ -54,6 +54,8 @@
5454
return;
5555
}
5656

57+
console.log("ordered to parse JSON...");
58+
5759
var json = jsonFrom(input);
5860

5961
// if succeeded, prettify and highlight it
@@ -73,8 +75,10 @@
7375

7476
// show rendered JSON
7577
function showJSON(rendered) {
78+
console.log("ordered to show JSON: " + rendered);
7679
if (rendered) {
7780
if ($(".json code").html()) {
81+
console.log("there's code to show, showing...");
7882
$(".json .rendered").show();
7983
$(".json .editing").hide();
8084
}
@@ -151,11 +155,13 @@
151155
renderCSV(outArray.slice(0, excerptRows));
152156
showCSV(true);
153157

158+
// show raw data if people really want it
159+
$(".csv textarea").val(csv);
160+
161+
// download link to entire CSV as data
154162
// thanks to http://jsfiddle.net/terryyounghk/KPEGU/
155163
// and http://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side
156164
var uri = "data:text/csv;charset=utf-8," + encodeURIComponent(csv);
157-
158-
$(".csv textarea").val(csv);
159165
$(".csv a.download").attr("href", uri);
160166
}
161167

@@ -214,7 +220,7 @@
214220
if (history && history.pushState)
215221
history.pushState({id: id}, null, "?id=" + id);
216222

217-
log("Permalink created! (Copy from the location bar.)")
223+
// log("Permalink created! (Copy from the location bar.)")
218224
}
219225

220226
// check query string for gist ID
@@ -254,7 +260,16 @@
254260
$(".save a").click(saveJSON);
255261

256262
// transform the JSON whenever it's pasted/edited
257-
$(".json textarea").keyup(doJSON);
263+
$(".json textarea")
264+
.on('paste', function() {
265+
// delay the showing so the paste is pasted by then
266+
setTimeout(function() {
267+
doJSON();
268+
// showJSON(true);
269+
$(".json textarea").blur();
270+
}, 1);
271+
})
272+
.keyup(doJSON); // harmless to repeat doJSON
258273

259274
// highlight CSV on click
260275
$(".csv textarea").click(function() {

0 commit comments

Comments
 (0)