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&hellip;</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

Version Path
gollum-site-0.1.12 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.11 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.10 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.9 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.8 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-1.1.1 lib/gollum/frontend/public/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.7 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.6 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.5 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.4 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.3 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.2 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.1 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.1.0 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.0.6 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.0.5 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.0.4 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-1.1.0 lib/gollum/frontend/public/javascript/jquery.previewable_comment_form.js
gollum-site-0.0.3 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js
gollum-site-0.0.2 lib/gollum-site/layout/javascript/jquery.previewable_comment_form.js