/* global $ CKEDITOR */

$(function () {
  let submitted = false
  const changeHandler = function () {
    $(window).on('beforeunload', function () {
      if (!submitted) {
        return false
      }
    })
  }
  for (let key in CKEDITOR.instances) {
    if (CKEDITOR.instances.hasOwnProperty(key)) {
      CKEDITOR.instances[key].on('change', changeHandler)
    }
  }

  $(document).one('change', changeHandler)
    .on('submit', function () {
      submitted = true
    })
})

@@ -211,52 +211,31 @@
   %7D%0A
+%0A
   
-for (let key in CKEDITOR.instances
+if (CKEDITOR
 ) %7B%0A    
 if (
@@ -230,20 +230,16 @@
 ) %7B%0A    
-if (
 CKEDITOR
@@ -239,24 +239,28 @@
 KEDITOR.
+on('
 instance
 s.hasOwn
@@ -255,62 +255,45 @@
 ance
-s.hasOwnProperty(key)) %7B%0A      CKEDITOR.instances%5Bkey%5D
+Ready', function (e) %7B%0A      e.editor
 .on(
@@ -322,16 +322,17 @@
 r)%0A    %7D
+)
 %0A  %7D%0A%0A  

add unload warning for ckeditor