Sha256: c10d0c478e3597ffb913dd173ab73a1914ada4d1776fd9f234b0bff55f94b4a9

Contents?: true

Size: 1.11 KB

Versions: 15

Compression:

Stored size: 1.11 KB

Contents

class PostPreview
  # @param buttonId [String] id of preview button
  # @param formId [String]
  # @param modalId [String] id of modal with iframe
  # @param postUrl [String] URL to send post request for preview
  constructor: (@buttonId, @formId, @postUrl, @modalId) ->
    @button = $("##{@buttonId}")
    @form   = $("##{@formId}")
    @modal  = $("##{@modalId}")
    @iframe = @modal.find('iframe')

  # Add onclick handler to the button
  init: ->
    url      = @postUrl
    callback = @previewPost

    @button.on 'click', (event) =>
      @updateCKeditor()
      event.preventDefault()
      $.ajax(
        type: "POST",
        url:  url,
        data: @form.serialize(),
        success: (data)=>
          @previewPost(data)
      )

  # Display response data(HTML) in the iframe. And open the modal.
  previewPost: (data) ->
    @iframe.contents().find('html').html(data)
    document.location.hash = @modalId

  # Make CKeditor set value so it can be sent.
  updateCKeditor: ->
    if CKEDITOR?
      for name, instance of CKEDITOR.instances
        instance.updateElement();


# Export
window.PostPreview = PostPreview

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
blogo-0.1.4 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.1.3 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.1.2 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.1.1 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.1.0 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.10 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.9 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.8 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.7 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.6 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.5 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.4 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.3 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.2 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee
blogo-0.0.1 app/assets/javascripts/blogo/admin/helpers/post_preview.js.coffee