Sha256: 81d5c0c8ce4ae2281beb033d24ea30badc2c2d379fb862cf371376dcbbe57ac9

Contents?: true

Size: 1.51 KB

Versions: 31

Compression:

Stored size: 1.51 KB

Contents

window.Alchemy = {} if typeof(window.Alchemy) is 'undefined'

Alchemy.PreviewWindow =
  MIN_WIDTH: 240
  HEIGHT: 75 # Top menu height

  init: (url) ->
    $iframe = $("<iframe name=\"alchemy_preview_window\" src=\"#{url}\" id=\"alchemy_preview_window\" frameborder=\"0\"/>")
    $reload = $('#reload_preview_button')
    @_showSpinner()
    $iframe.load =>
      @_hideSpinner()
    $('body').append($iframe)
    @currentWindow = $iframe
    @_bindReloadButton()

  resize: (width) ->
    width = @MIN_WIDTH if width < @MIN_WIDTH
    @currentWidth = width
    @currentWindow.css
      width: width

  refresh: (callback) ->
    $iframe = $('#alchemy_preview_window')
    @_showSpinner()
    # We need to be sure that no load event is binded on the preview frame.
    $iframe.off('load')
    $iframe.load (e) =>
      @_hideSpinner()
      if callback
        callback.call(e, $iframe)
    $iframe.attr 'src', $iframe.attr('src')
    true

  postMessage: (data) ->
    frameWindow = @currentWindow[0].contentWindow
    frameWindow.postMessage(data, window.location.origin)

  _showSpinner: ->
    @reload = $('#reload_preview_button')
    @spinner = new Alchemy.Spinner('small')
    @reload.html @spinner.spin().el

  _hideSpinner: ->
    @spinner.stop()
    @reload.html('<i class="icon fas fa-redo fa-fw"></i>')

  _bindReloadButton: ->
    $reload = $('#reload_preview_button')
    key 'alt+r', =>
      @refresh()
    $reload.click (e) =>
      e.preventDefault()
      @refresh()

Alchemy.reloadPreview = ->
  Alchemy.PreviewWindow.refresh()

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
alchemy_cms-5.0.10 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-4.6.7 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.9 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-4.6.6 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.8 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-4.6.5 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-4.5.1 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-4.4.5 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-4.6.4 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.7 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.6 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.5 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-4.6.3 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.4 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.3 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.2 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.1.0.beta1 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.1 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-4.6.2 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee
alchemy_cms-5.0.0 app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee