$(document).ready(function(){
$(document).on('change focus blur click keydown keyup', '#ta_source', function(e){
update();
});
$(document).on('change','input[type=checkbox]', function(e){
update();
});
update();
$(document).on('change keyup focus blur','#link_rename', function(e){
$('#ta_link').text(this.value || 'link');
});
$('[data-demoinput]').click(function(e){
var d = e.currentTarget.getAttribute('data-demoinput');
var s = demo_input[d] || d || '';
$('#ta_source').val(s);
update();
});
});
function update() {
var s = $('#ta_source').val();
$('#ta_nocomments').val(parseJavascript(s, false));
var s_bookmarklet = scriptToBookmarklet(s);
$('#ta_1line').val(s_bookmarklet);
// $('#ta_1linehref').val(htmlescapeforlink(s_bookmarklet));
$('#ta_1linehref').val(htmlescape_optional(s_bookmarklet));
$('#ta_link').attr('href', s_bookmarklet);
$('#parse_log').empty();
var m = detect_possible_missing_semicolons(s);
if(m) {
var ta = document.createElement('textarea');
ta.setAttribute('readonly', true);
ta.value = m.join('\n');
$('#parse_log').append('<b style="color:#f00;">Possible missing EOL semicolon errors:</b><br>');
$('#parse_log').append(ta);
}
}
function parseJavascript(str, compact) {
// basic javascript parser, and return given javascript string:
// - strip comments,
// - if compact==true: remove double code whitespace (not inside strings).
// NB: code might break if:
// - ; (semicolon) is missing after a statement before a newline.
// - regex using slashes is used, e.g. "/123/g"
// (but using: "new RegExp('...', '...')" is fine though).
// Note on trying to parse regex, which is hard to implement:
// Determining if / is a RegExp delimiter or a division character is hard.
// e.g. "re = /123/g" vs "2 / 3"
// We can work around this by (manually) replacing "/123/g" with:
// "new RegExp('123', 'g')".
// see:
//...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.