Sha256: b5c39dbe9c111348a9f9c0511e228cf731efe172bf126ec0eef99a58af9f62fa
Contents?: true
Size: 1.63 KB
Versions: 24
Compression:
Stored size: 1.63 KB
Contents
(function($){ $.fn.previewableCommentForm = function(options){ var opts = $.extend({}, $.fn.previewableCommentForm.defaults, options); return this.each(function(){ var wrapper = $(this) var input = wrapper.find('textarea') var output = wrapper.find('.content-body') var error = wrapper.prev('.comment-form-error') var button = wrapper.find('.form-actions button') var text = input.val() var dirty = false var request = null dirtyInputs = $.merge(wrapper.find('.preview-dirty'), input) dirtyInputs.blur(function(){ if (text != input.val()){ dirty = true text = input.val() } updatePreview() }) var updatePreview = function(force){ if (!dirty && !force) return if ($.trim(text) == ""){ // empty input output.html("<p>Nothing to preview</p>") return } output.html("<p>Loading preview…</p>") if (request) request.abort() var params = $.extend({"text": text}, opts.previewOptions) request = $.post(opts.previewUrl, params, function(data) { output.html(data) opts.onSuccess.call(output) }) } updatePreview(true) // Custom validation wrapper.closest('form').submit(function(){ error.hide() if ( $.trim(input.val()) == "" ){ error.show() return false } button.attr('disabled', 'disabled') }) }) } $.fn.previewableCommentForm.defaults = { previewUrl: "/preview", previewOptions: {}, onSuccess: function() { } } })(jQuery);
Version data entries
24 entries across 24 versions & 3 rubygems