Sha256: 6790c634861941634c26eb453aff0352a21d52e801dffefb8afbe3c606d0dd58

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

#= require jquery-fileupload/basic
#= require spin

$ ->
  request_url = $("#attachable_url").val()
  editor = $("#insertable").data("wysihtml5").editor

  spinner = new Spinner().spin()
  $('#fileupload').fileupload
    method: "PUT"
    send: ->
      spinner.spin $("#attachments-controls")[0]
      $("#attachments *").attr disabled: true
      $("#fileupload").attr disabled: true
      $("#attachments-controls").css opacity: 0.5

    done: (e, data) ->
      $.get request_url, (attachments_view) ->
        $('#attachments').html attachments_view
        spinner.stop()
        $("#fileupload").attr disabled: false
        $("#attachments-controls").css opacity: 1

  $("#attachments").on "click", ".insert-image", (e) ->
    e.preventDefault()
    editor.composer.commands.exec "insertImage",
      src: $(this).attr "href"

  $("#attachments").on "click", ".insert-link", (e) ->
    e.preventDefault()
    editor.composer.commands.exec "createLink",
      href: $(this).attr "href"
      target: "_blank"
      rel: "nofollow"
      text: $(this).data("name")

  $("#attachments").on "click", ".delete", (e) ->
    el = $(this).parents(".attachment")
    spinner.spin el[0]
    el.css opacity: 0.5
    el.find("*").attr disabled: true
    $.ajax
      method: "DELETE"
      url: $(this).attr "href"
      success: -> el.remove()
    false

  $("#attachments").sortable
    axis: "y"
    cancel: "input,textarea,button,select,option,a"
    distance: 5
    update: ->
      $.post "#{request_url}/reposition", positions: ($("#attachments > *").map -> $(this).data "attachment-id").toArray()

  $("#attachments").disableSelection()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
brightcontent-attachments-2.3.1 app/assets/javascripts/brightcontent/attachments.js.coffee