Sha256: ece0fd3a049516cf7fb2a3c34443099e19e7b4dde489249210c610a8d7b00396
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
$(function() { // onload var comment_form = $('#new_comment'); var input_elements = comment_form.find(':text, textarea'); var fetch_comment_preview = function() { var dest = window.location.href; dest = dest.split('#')[0]; dest = dest.split('?')[0]; if (!dest.endsWith('comments')) { dest += '/comments'; } jQuery.ajax({ data: comment_form.serialize(), url: dest + '/new', dataType: 'html', timeout: 2000, error: function() { if ($('#comment-preview').length === 0) { comment_form.after('<div id="comment-preview"></div>'); } $('#comment-preview').text("Failed to submit"); }, success: function(r) { if ($('#comment-preview').length === 0) { comment_form.after('<h2>Your comment will look like this:</h2><div id="comment-preview"></div>'); } $('#comment-preview').html(r); } }); }; input_elements.keyup(function () { fetch_comment_preview.only_every(1000); }); if (input_elements.any(function() { return $(this).val().length > 0; })) { fetch_comment_preview(); } });
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
enki-engine-0.0.5 | app/assets/javascripts/live-comment-preview.js |