Merge pull request from MacKLess/serve_instructions

Serve instructions
This commit is contained in:
Liam Newman 2018-06-21 17:35:35 -07:00 committed by GitHub
commit afa2d3849a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 2 deletions

@ -15,10 +15,9 @@ While developing, you may locally build and test the JavaScript or Python (or bo
* Make changes to the implementation of your choice.
* If working in the JavaScript implementation:
* Run `./build js`
* Run `./build static` to see changes served locally
* Run `./build static` to see changes served locally at `http://localhost:8080`
* If working in the Python implementation:
* Run `./build py`
* Run `./build static` to see changes served locally
* Add tests to `/test/data/*/test.js`.
* Run `./build jstest` or `./build pytest` to run style checks, and to generate and run tests.
* Include all changed files in your commit - The generated test files are checked in along with changes to the test data files.

@ -54,6 +54,8 @@
<script src="web/common-function.js"></script>
</head>
<h1>Online JavaScript beautifier</h1>
<body>
<div id="about">
@ -114,6 +116,11 @@
<option value="separate">Separate indentation</option>
</select>
<p style="margin:6px 0 0 0">Additional Settings (JSON):</p>
<textarea id="additional-options" rows="5" cols="32">{}</textarea>
<p id ="additional-options-error" hidden style="margin:6px 0 0 0; color:red ">Could Not Parse JSON!</p>
</td>
<td>
<input class="checkbox" type="checkbox" id="end-with-newline">
@ -163,6 +170,13 @@
</button>
</div>
<p style="margin:6px 0 0 0">Your Selected Options (JSON):</p>
<div style="line-height: 0">
<textarea readonly id="options-selected" rows="10" cols="40"></textarea>
</div>
<div class="blurb">
<h2>Browser extensions and other uses</h2>

@ -36,6 +36,7 @@ function read_settings_from_cookie() {
$('#keep-array-indentation').prop('checked', $.cookie('keep-array-indentation') === 'on');
$('#break-chained-methods').prop('checked', $.cookie('break-chained-methods') === 'on');
$('#indent-scripts').val(any($.cookie('indent-scripts'), 'normal'));
$('#additional-options').val(any($.cookie('additional-options'), '{}'));
$('#space-before-conditional').prop('checked', $.cookie('space-before-conditional') !== 'off');
$('#wrap-line-length').val(any($.cookie('wrap-line-length'), '0'));
$('#unescape-strings').prop('checked', $.cookie('unescape-strings') === 'on');
@ -63,6 +64,7 @@ function store_settings_to_cookie() {
$.cookie('end-with-newline', $('#end-with-newline').prop('checked') ? 'on' : 'off', opts);
$.cookie('wrap-line-length', $('#wrap-line-length').val(), opts);
$.cookie('indent-scripts', $('#indent-scripts').val(), opts);
$.cookie('additional-options', $('#additional-options').val(), opts);
$.cookie('indent-inner-html', $('#indent-inner-html').prop('checked') ? 'on' : 'off', opts);
$.cookie('comma-first', $('#comma-first').prop('checked') ? 'on' : 'off', opts);
$.cookie('e4x', $('#e4x').prop('checked') ? 'on' : 'off', opts);
@ -116,6 +118,8 @@ function beautify() {
output,
opts = {};
var additional_options = $('#additional-options').val();
opts.indent_size = $('#tabsize').val();
opts.indent_char = opts.indent_size == 1 ? '\t' : ' ';
opts.max_preserve_newlines = $('#max-preserve-newlines').val();
@ -133,6 +137,20 @@ function beautify() {
opts.comma_first = $('#comma-first').prop('checked');
opts.e4x = $('#e4x').prop('checked');
$('#additional-options-error').hide();
if (additional_options && additional_options !== '{}') {
try {
additional_options = JSON.parse(additional_options);
opts = mergeObjects(opts, additional_options);
} catch {
$('#additional-options-error').show();
}
}
var selectedOptions = JSON.stringify(opts, null, 2);
$('#options-selected').val(selectedOptions);
if (looks_like_html(source)) {
output = html_beautify(source, opts);
} else {
@ -155,3 +173,16 @@ function looks_like_html(source) {
var trimmed = source.replace(/^[ \t\n\r]+/, '');
return trimmed && (trimmed.substring(0, 1) === '<');
}
function mergeObjects(allOptions, additionalOptions) {
var finalOpts = {};
var name;
for (name in allOptions) {
finalOpts[name] = allOptions[name];
}
for (name in additionalOptions) {
finalOpts[name] = additionalOptions[name];
}
return finalOpts;
}

@ -39,6 +39,8 @@ $(function () {
})
$('.submit').click(beautify);
$('select').change(beautify);
$(':checkbox').change(beautify);
$('#additional-options').change(beautify);
});