Sha256: 9eccc6d9b1f80751684f67c74849a1d49467d47c31a3498ce1a85ca34b971893

Contents?: true

Size: 1.72 KB

Versions: 117

Compression:

Stored size: 1.72 KB

Contents

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

$.extend Alchemy,

  ElementDirtyObserver: (selector) ->
    $(selector).find('input[type="text"], select').change (e) =>
      $content = $(e.target)
      $content.addClass('dirty')
      @setElementDirty $content.closest(".element-editor")
      return

  setElementDirty: (element) ->
    $element = $(element)
    $element.addClass('dirty')
    window.onbeforeunload = @pageUnload

  pageUnload: ->
    Alchemy.t('page_dirty_notice')

  setElementClean: (element) ->
    $element = $(element)
    $element.removeClass('dirty')
    $element.find('> .element-content .dirty').removeClass('dirty')
    window.onbeforeunload = undefined

  isPageDirty: ->
    $('#element_area').find('.element-editor.dirty').length > 0

  isElementDirty: (element) ->
    $(element).hasClass('dirty')

  checkPageDirtyness: (element) ->
    callback = undefined
    if $(element).is("form")
      callback = ->
        $form = $("<form action=\"#{element.action}\" method=\"POST\" style=\"display: none\" />")
        $form.append $(element).find("input")
        $form.appendTo "body"
        Alchemy.pleaseWaitOverlay()
        $form.submit()
    else if $(element).is("a")
      callback = ->
        Turbolinks.visit(element.pathname)
    if Alchemy.isPageDirty()
      Alchemy.openConfirmDialog Alchemy.t('page_dirty_notice'),
        title: Alchemy.t('warning')
        ok_label: Alchemy.t('ok')
        cancel_label: Alchemy.t('cancel')
        on_ok: ->
          window.onbeforeunload = undefined
          callback()
      false
    else
      true

  PageLeaveObserver: ->
    $('#main_navi a').click (event) ->
      unless Alchemy.checkPageDirtyness(event.currentTarget)
        event.preventDefault()

Version data entries

117 entries across 117 versions & 1 rubygems

Version Path
alchemy_cms-5.3.6 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.7 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.6 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.5 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.4 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.3 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-5.3.5 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.0 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-5.3.4 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.0.pre.rc7 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-5.3.3 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-5.3.2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-5.3.1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-5.3.0 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-6.0.0.pre.rc6 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-5.2.7 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-5.2.6 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-5.1.10 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee