           @_setField(fieldWrapperScope.fieldScope)
           @_setPreviewElement(fieldWrapperScope.previewElementScope)
           $scope.iframeScope.beforeShowingIframe(fieldWrapperScope.iframeSrc)
-          $scope.mainWindow.bind 'resize', $scope.onWindowResize
+          djangoCradminWindowDimensions.register $scope
           $scope.show()
 
         @onIframeLoadBegin = ->



.directive('djangoCradminModelChoiceFieldIframeWrapper', [
  '$window', '$timeout', 'djangoCradminModelChoiceFieldCoordinator'
  ($window, $timeout, djangoCradminModelChoiceFieldCoordinator) ->
    return {
      restrict: 'A'
      scope: {}

      controller: ($scope) ->
        $scope.origin = "#{window.location.protocol}//#{window.location.host}"
        $scope.mainWindow = angular.element($window)
        $scope.bodyElement = angular.element($window.document.body)
        $scope.windowDimensions = null
        djangoCradminModelChoiceFieldCoordinator.registerModeChoiceFieldIframeWrapper(this)

        @setIframe = (iframeScope) ->

            return
          $scope.fieldScope.setValue(data.value)
          $scope.previewElementScope.setPreviewHtml(data.preview)
          djangoCradminWindowDimensions.unregister $scope
          $scope.hide()
          $scope.iframeScope.afterFieldValueChange()

        $window.addEventListener('message', $scope.onChangeValue, false)

        $scope.onWindowResize = (newWindowDimensions) ->
          $scope.iframeScope.setIframeSize()

        $scope.show = ->
          $scope.iframeWrapperElement.addClass('django-cradmin-floating-fullsize-iframe-wrapper-show')
