 
     saved: =>
       @dirty = false
-      #$window.onBeforeUnload = null 
+      $(window).unbind "beforeunload"
 
     unsaved: =>
       @dirty = true
-      window.onBeforeUnload = ->
-        "Your order hasn't been saved yet! Are you sure you want to leave this page?"
+      $(window).bind "beforeunload", ->
+        "Your order hasn't been saved yet. Give us a few seconds to finish!"
 
     line_items_present: =>
       @line_items.filter (li)->

Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, $window)->
  # Handles syncing of current cart/order state to server
  new class Cart
    dirty: false


    orderChanged: =>
      @unsaved()
      if @promise
        $timeout.cancel(@promise)
      @promise = $timeout @update, 1000

    update: =>
      $http.post('/orders/populate', @data()).success (data, status)=>
        @saved()
      .error (response, status)=>
