     evt.preventDefault()
     $("button[data-target=#modal-passwd]").trigger 'click'
 
+readImage = (file, callback) ->
+  fr = new FileReader()
+  fr.addEventListener "load", (e) ->
+    callback e.target.result
+  fr.readAsBinaryString file
+
+freeURL = () ->
+
+if window.URL? or window.webkitURL?
+  readImage = (file, callback) ->
+    callback (window.URL || window.webkitURL).createObjectURL file
+  freeURL = (url) ->
+    URL.revokeObjectURL url
+
 
 # Profile pic
 ($ document).on 'change', 'input#user_profile_picture[type=file]', ->
-  input = ($ this)[0]
+  input = this
 
   ($ '#profile-picture-crop-controls').slideUp 400, ->
     if input.files and input.files[0]
-      fr = new FileReader()
-      ($ fr).on 'load', (e) ->
+      readImage input.files[0], (src) ->
         cropper = ($ '#profile-picture-cropper')
         preview = ($ '#profile-picture-preview')
 

#            marginTop: '-' + Math.round(ry * data.y) + 'px'

        cropper.on 'load', ->
          side = if cropper[0].naturalWidth > cropper[0].naturalHeight
            cropper[0].naturalHeight
          else

            ($ '#profile-picture-crop-controls')[0].dataset.bound = true
          ($ '#profile-picture-crop-controls').slideDown()

        cropper.attr 'src', src

($ document).on 'change', 'input#user_profile_header[type=file]', ->
  input = this

  ($ '#profile-header-crop-controls').slideUp 400, ->
    if input.files and input.files[0]
      readImage input.files[0], (src) ->
        cropper = ($ '#profile-header-cropper')
        preview = ($ '#profile-header-preview')

