 $(window).onbeforeunload = -> return "You haven't saved your changes." if window.$isDirty
 $(document).ready(initialLoadReady)
 $(document)
-  .on('turbolinks:load', turbolinksReady)
-  .on('turbolinks:before-visit', (event) ->
+  .on("turbolinks:load", turbolinksReady)
+  .on("turbolinks:before-visit", (event) ->
     event.preventDefault() if window.$isDirty and !confirm("You haven't saved your changes.")
   )
-  .on('click', '[data-object~="suppress-click"]', -> false)
-  .on('click', '[data-object~="remove-self"]', ->
-    $(this).remove()
+  .on("click", "[data-object~=suppress-click]", -> false)
+  .on("click", "[data-object~=remove-closest]", ->
+    $(this).closest($(this).data("target")).remove()
     false
   )
-  .on('click', '[data-object~="remove-closest"]', ->
-    $(this).closest($(this).data('target')).remove()
+  .on("click", "[data-object~=remove]", ->
+    $($(this).data("target")).remove()
     false
   )
-  .on('click', '[data-object~="remove"]', ->
-    $($(this).data('target')).remove()
+  .on("click", "[data-object~=modal-show]", ->
+    $($(this).data("target")).modal({ dynamic: true })
     false
   )
-  .on('click', '[data-object~="modal-show"]', ->
-    $($(this).data('target')).modal({ dynamic: true })
+  .on("click", "[data-object~=modal-hide]", ->
+    $($(this).data("target")).modal("hide")
     false
   )
-  .on('click', '[data-object~="modal-hide"]', ->
-    $($(this).data('target')).modal('hide')
-    false
-  )
-  .on('click', '[data-object~="submit"]', ->
-    $($(this).data('target')).submit()
+  .on("click", "[data-object~=submit]", ->
+    $($(this).data("target")).submit()
     false
   )
   .on("click", "[data-object~=submit-and-disable]", ->


@fadeAndRemove = (element) ->
  $(element).fadeOut(500, -> $(element).remove())

@setFocusToField = (element_id) ->
  val = $(element_id).val()
  $(element_id).focus().val('').val(val)

@componentsReady = ->
  themesReady()

  window.$isDirty = false
  componentsReady()
  extensionsReady()
  $("[data-object~=form-load]").submit()

# These functions get called on initial page visit and on turbolink page changes
@turbolinksReady = ->
