Sha256: 8cfd5d24e34bc766d9bf8242b88602a2beb3e84e253c6af35fd8f5467f34ef38

Contents?: true

Size: 1.94 KB

Versions: 31

Compression:

Stored size: 1.94 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')
    $element
      .find('> .element-header .icon[class*="element_"]')
      .addClass('element_dirty')
    window.onbeforeunload = @pageUnload

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

  setElementClean: (element) ->
    $element = $(element)
    $element.removeClass('dirty')
    $element.find('> .element-header .icon').removeClass('element_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"
        $form.submit()
    else if $(element).is("a")
      callback = ->
        window.location.href = 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
          Alchemy.pleaseWaitOverlay()
          callback()
      false
    else
      true

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

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
alchemy_cms-4.0.6 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.6.7 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.6.6 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.0.5 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.0.4 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.0.3 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.6.5 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.0.2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.0.1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.6.4 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.0.0 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.6.3 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.6.2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.0.0.rc2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.0.0.rc1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.6.1 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-4.0.0.beta app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.6.0 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.5.0 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee
alchemy_cms-3.4.2 app/assets/javascripts/alchemy/alchemy.dirty.js.coffee