Sha256: 46a28415da79db8702d694163981130fff34d29c910c1096079f24b992eec6ce

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

fetch_file = (event) ->
  data_transfer = event.originalEvent.dataTransfer
  return unless data_transfer

  files = data_transfer.files
  if (files.length > 1)
    alert('You dropped multiple files, but only one file is supported.')
    return

  files[0]

find_cms_field = (target) ->
  if $(target).attr('data-scrivito-field-name')
    $(target)
  else
    $(target).parent('[data-scrivito-field-name]')

scrivito.editors._file_drop_zone = (selector, callback, status_indicator_class) ->
  # Disable DnD for all elements by default to prevent the user
  # from accidentally opening an image in browser.
  $('body').on 'dragover', -> false
  $('body').on 'drop', -> false

  status_indicator_class ||= 'scrivito-editor-dragover'

  body_element = $('body')
  body_element.on 'dragover.scrivito-editor', selector, (event) ->
    event.preventDefault()
    $(find_cms_field(event.target)).addClass(status_indicator_class)

  body_element.on 'dragleave.scrivito-editor', selector, (event) ->
    event.preventDefault()
    $(find_cms_field(event.target)).removeClass(status_indicator_class)

  body_element.on 'drop.scrivito-editor', selector, (event) ->
    event.preventDefault()
    cms_field = find_cms_field(event.target)
    file = fetch_file(event)
    $(cms_field).removeClass(status_indicator_class)

    if file
      callback(event, cms_field, file)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scrivito_editors-0.40.0 app/assets/javascripts/scrivito_editors/helpers/file_drop_zone.js.coffee
scrivito_editors-0.40.0.rc2 app/assets/javascripts/scrivito_editors/helpers/file_drop_zone.js.coffee
scrivito_editors-0.40.0.rc1 app/assets/javascripts/scrivito_editors/helpers/file_drop_zone.js.coffee