 
         $scope.$on "$destroy", () ->
             if mediumInstance
+                $(editorMedium[0]).off() if editorMedium.length
                 mediumInstance.destroy()
 
     return {

            $scope.$applyAsync () ->
                wysiwygCodeHightlighterService.addHightlighter(mediumInstance.elements[0])
                refreshCodeBlocks(mediumInstance)

        $(editorMedium[0]).on 'dblclick', 'pre', (e) ->
            $scope.$applyAsync () ->

                e.stopPropagation()

                if e.target.href
                    window.open(e.target.href)                                                 

            mediumInstance.subscribe 'editableDrop', (event) ->
                $scope.onUploadFile({files: event.dataTransfer.files, cb: uploadEnd})
