Skip to content

Commit

Permalink
Merge pull request #16 from rafspiny/testing
Browse files Browse the repository at this point in the history
Format json
  • Loading branch information
rafspiny committed Dec 6, 2015
2 parents 41349b2 + 3e3d266 commit a6a61d0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
8 changes: 8 additions & 0 deletions data/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,12 @@ margin: 0;

.button {
padding: 0.3em;
}

.formatsrc {
margin-right: 20%
}

.formatdst {
margin-left: 20%
}
2 changes: 2 additions & 0 deletions data/html/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ <h3 class="darkblue">Second version</h3>
</div>
</div>
<div class="centered padded">
<a href="#" class="ui-state-default ui-corner-all button formatsrc" id="format1">Format</a>
<a href="#" class="ui-state-default ui-corner-all button" id="checkdiff">Check diff</a>
<a href="#" class="ui-state-default ui-corner-all button formatdst" id="format2">Format</a>
</div>
</div>
<div id='result'>
Expand Down
30 changes: 30 additions & 0 deletions data/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,36 @@ function printSingleDiff(diff, div) {
$(function() {
$( "#resizable" ).resizable();
});
function formatJsonInTextArea(node) {
var text1 = node.val();
// Remove newlines
var text1 = text1.replace("\n", "");
try{
value = JSON.parse(text1);
indendent_text = JSON.stringify(value, null, " ");
node.val(indendent_text);

}catch(e){
$('#primary').addClass("invalidJson");
alert('The input is not valid JSON. Please check the checkboes.');
}
};
$(function() {
$( "#format1" ).click(function( event ) {
event.preventDefault();
node = $('textarea#primary');
$('#primary').removeClass("invalidJson");
formatJsonInTextArea(node);
});
});
$(function() {
$( "#format2" ).click(function( event ) {
event.preventDefault();
node = $('textarea#secondary');
$('#secondary').removeClass("invalidJson");
formatJsonInTextArea(node);
});
});
$(function() {
$( "#checkdiff" ).click(function( event ) {
event.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "JSON Diff View",
"name": "jsondiff",
"version": "0.1.2",
"version": "0.1.3",
"description": "Easily view JSON object diffs. Source code can be found at https://github.com/rafspiny/jsondiff/",
"main": "index.js",
"author": "Raffaele Spinelli",
Expand Down

0 comments on commit a6a61d0

Please sign in to comment.