 
         getUrl = ->
           # "Живой" префикс
-          prefix = settings.prefix or $uploader.data('prefix')
-          throw "prefix isn't defined" unless prefix?
+          prefix = settings.prefix ? $uploader.data('prefix')
+          throw "prefix isn't defined" unless prefix
 
-          multiselect = settings.multiselect or $uploader.data('multiselect')
-          type = settings.type or $uploader.data('type')
+          multiselect = settings.multiselect ? $uploader.data('multiselect')
+          type = settings.type ? $uploader.data('type')
 
           "#{settings.host}/#
             tenant/#{settings.tenant}/

            prefix/#{prefix}
          ".replace /\ /g, ''

        openUploader = ->
          if settings.open
            $uploaderIframes = $("##{settings.open}").find('.js-uploader-iframe:first')
          else
            $uploaderIframes = $uploader.find('.js-uploader-iframe:first')
          
          if $uploaderIframes.length
            iframeTemplate = _.template '''
              <iframe width='<%= width %>' height='<%= height %>' src='<%= src %>' frameborder='0'></iframe>
            '''

            $uploaderIframes.each ->
              $iframe = $ @
              iframeData = $iframe.data()
              $iframe.html iframeTemplate
                src: getUrl()
                width: iframeData.width or '100%'
                height: iframeData.height or 500

            $uploaderIframes.closest('div.modal').modal('show') if $.fn.modal?
          else
            popupWindow = open getUrl(), 'NMD Media Lib', 'scrollbars=1, width=800, height=500'
            popupWindow.focus()

        if settings.open
          openUploader()
        else
          $uploader.find('.js-uploader-open').on 'click', (e) ->

$ ->
  methods =
    init: (options) ->
      settings = $.extend true,
        {}
      , options

      throw "host isn't defined" unless settings.host
      throw "tenant isn't defined" unless settings.tenant

      @each ->
        $uploader = $ @
        uploader = $uploader.data()

        uploaderId = $.md5(Math.random())[0..3]
