Sha256: c782f7824ec6427dafd1d017eda103a94bb85d9f6f82b12608a0160aac4cfcbc

Contents?: true

Size: 1008 Bytes

Versions: 8

Compression:

Stored size: 1008 Bytes

Contents

function unloadEvents(){

    var dispatchUnloadEvent = function(e) {

          var event = document.createEvent("Events")
          event.initEvent("turbolinks:unload", true, false)
          document.dispatchEvent(event)

          if ( ($('.changed').length > 0) && !( $('.unload').length > 0 ) ) {

              msg = 'You have unsaved changes.';
              (e || window.event).returnValue = msg;
              return msg;
          }
    }

    $(':submit').on('click', function(){
      $('html').addClass('unload');
    })

    $("form input, form textarea").on('change', function (event) {
      if (!event.target.classList.contains("tab_controller")) {
        $('.change_waiter').addClass('changed');
      }
    })

    $('form').on('submit', function(){
        console.log("JH")
        window.removeEventListener('beforeunload', dispatchUnloadEvent)
    })

    addEventListener("beforeunload", dispatchUnloadEvent)
    addEventListener("turbolinks:before-render", dispatchUnloadEvent)

}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cd2_catton_cms-1.1.35 app/assets/javascripts/c/unloadevent.js
cd2_catton_cms-1.1.34 app/assets/javascripts/c/unloadevent.js
cd2_catton_cms-1.1.33 app/assets/javascripts/c/unloadevent.js
cd2_catton_cms-1.1.32 app/assets/javascripts/c/unloadevent.js
cd2_catton_cms-1.1.31 app/assets/javascripts/c/unloadevent.js
cd2_catton_cms-1.1.30 app/assets/javascripts/c/unloadevent.js
cd2_catton_cms-1.1.20 app/assets/javascripts/c/unloadevent.js
cd2_catton_cms-1.1.10 app/assets/javascripts/c/unloadevent.js