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-4.4.2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.4.1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.4.0 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.3.2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.2.4 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.3.1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.2.3 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.3.0 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.2.2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.1.2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.1.1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.2.1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.2.0 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.2.0.rc1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.1.0 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.1.0.rc1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.1.0.beta app/assets/javascripts/alchemy/alchemy.dirty.js.coffee