-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Added prettified JSON preview of the initialisation object
- Loading branch information
1 parent
26ca0f2
commit 7ddba1a
Showing
9 changed files
with
127 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!-- | ||
******************************************************************** | ||
* | ||
* Setup a modal window to preview the API initialisation JSON | ||
* | ||
******************************************************************** | ||
--> | ||
<div class="modal fade" id="initialisation-preview"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | ||
<h4 class="modal-title">API Initialisation Preview</h4> | ||
</div> | ||
<div class="modal-body"> | ||
<pre><code id="preview-body"></code></pre> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<?php | ||
if (!isset($signedRequest)) { | ||
die('Make sure you call your PHP var $signedRequest for initialisation preview to work'); | ||
} | ||
$previewObject = json_decode($signedRequest, true); | ||
if (is_array($previewObject)) { | ||
if (array_key_exists('security', $previewObject)) { | ||
$previewBody = '{"security": ' . json_encode($previewObject['security']) . ', "request": ' . json_encode($previewObject['request']) . '}'; | ||
} else { | ||
$previewBody = json_encode($previewObject); | ||
} | ||
} else { | ||
$previewBody = $previewObject; | ||
} | ||
?> | ||
|
||
<script> | ||
$('#preview-body').html(library.json.prettyPrint(<?php echo $previewBody; ?>)); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
if (!library) { | ||
var library = {}; | ||
} | ||
|
||
library.json = { | ||
replacer: function(match, pIndent, pKey, pVal, pEnd) { | ||
var key = '<span class=json-key>'; | ||
var val = '<span class=json-value>'; | ||
var str = '<span class=json-string>'; | ||
var r = pIndent || ''; | ||
if (pKey) { | ||
r = r + key + pKey.replace(/[": ]/g, '') + '</span>: '; | ||
} | ||
if (pVal) { | ||
r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>'; | ||
} | ||
return r + (pEnd || ''); | ||
}, | ||
prettyPrint: function(obj) { | ||
var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg; | ||
return JSON.stringify(obj, null, 3) | ||
.replace(/&/g, '&').replace(/\\"/g, '"') | ||
.replace(/</g, '<').replace(/>/g, '>') | ||
.replace(jsonLine, library.json.replacer); | ||
} | ||
}; |