Skip to content

Commit

Permalink
Merge pull request #1430 from MacKLess/language
Browse files Browse the repository at this point in the history
Add language selector
  • Loading branch information
bitwiseman authored Jun 29, 2018
2 parents 5374db4 + 1a9104b commit fa3bb10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ <h1>Online JavaScript beautifier</h1>
</table>

<div style="line-height: 0">
<select name="language" id="language">
<option value="auto">Auto Detect</option>
<option value="css">CSS</option>
<option value="html">HTML</option>
<option value="js">JavaScript</option>
</select>
<button class="submit"><strong>Beautify JavaScript or HTML</strong> <em>(ctrl-enter)</em>
</button>
<textarea id="source" rows="30" cols="160"></textarea>
Expand Down
25 changes: 18 additions & 7 deletions web/common-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function read_settings_from_cookie() {
$('#indent-inner-html').prop('checked', $.cookie('indent-inner-html') === 'on');
$('#comma-first').prop('checked', $.cookie('comma-first') === 'on');
$('#e4x').prop('checked', $.cookie('e4x') === 'on');
$('#language').val(any($.cookie('language'), 'auto'));
}

function store_settings_to_cookie() {
Expand All @@ -68,6 +69,7 @@ function store_settings_to_cookie() {
$.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);
$.cookie('language', $('#language').val(), opts);

}

Expand Down Expand Up @@ -121,6 +123,9 @@ function beautify() {

var additional_options = $('#additional-options').val();

var language = $('#language').val();
the.language = $('#language option:selected').text();

opts.indent_size = $('#tabsize').val();
opts.indent_char = opts.indent_size == 1 ? '\t' : ' ';
opts.max_preserve_newlines = $('#max-preserve-newlines').val();
Expand All @@ -142,25 +147,28 @@ function beautify() {
$('#open-issue').hide();

if (additional_options && additional_options !== '{}') {
try {
additional_options = JSON.parse(additional_options);
opts = mergeObjects(opts, additional_options);
} catch {
$('#additional-options-error').show();
}
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)) {
if (language === 'html' || (language === 'auto' && looks_like_html(source))) {
output = html_beautify(source, opts);
} else if (language === 'css') {
output = css_beautify(source, opts);
} else {
if ($('#detect-packers').prop('checked')) {
source = unpacker_filter(source);
}
output = js_beautify(source, opts);
}

if (the.editor) {
the.editor.setValue(output);
} else {
Expand Down Expand Up @@ -224,6 +232,9 @@ ${the.lastInput}
Browser User Agent:
${navigator.userAgent}
Language Selected:
${the.language}
## Settings
Example:
\`\`\`json
Expand Down

0 comments on commit fa3bb10

Please sign in to comment.