2014-06-03 03:56:40 -04:00
|
|
|
formatLink = (str) ->
|
|
|
|
"![" + str.alt + "](" + str.url + ")"
|
|
|
|
|
2014-05-23 04:22:00 -04:00
|
|
|
$(document).ready ->
|
|
|
|
alertClass = "alert alert-danger alert-dismissable div-dropzone-alert"
|
|
|
|
alertAttr = "class=\"close\" data-dismiss=\"alert\"" + "aria-hidden=\"true\""
|
|
|
|
divHover = "<div class=\"div-dropzone-hover\"></div>"
|
|
|
|
divSpinner = "<div class=\"div-dropzone-spinner\"></div>"
|
|
|
|
divAlert = "<div class=\"" + alertClass + "\"></div>"
|
|
|
|
iconPicture = "<i class=\"icon-picture div-dropzone-icon\"></i>"
|
|
|
|
iconSpinner = "<i class=\"icon-spinner icon-spin div-dropzone-icon\"></i>"
|
|
|
|
btnAlert = "<button type=\"button\"" + alertAttr + ">×</button>"
|
|
|
|
project_image_path_upload = window.project_image_path_upload or null
|
|
|
|
|
|
|
|
$("textarea.markdown-area").wrap "<div class=\"div-dropzone\"></div>"
|
2014-06-03 03:56:40 -04:00
|
|
|
|
2014-05-23 04:22:00 -04:00
|
|
|
$(".div-dropzone").parent().addClass "div-dropzone-wrapper"
|
2014-06-03 03:56:40 -04:00
|
|
|
|
2014-05-23 04:22:00 -04:00
|
|
|
$(".div-dropzone").append divHover
|
|
|
|
$(".div-dropzone-hover").append iconPicture
|
|
|
|
$(".div-dropzone").append divSpinner
|
|
|
|
$(".div-dropzone-spinner").append iconSpinner
|
|
|
|
|
2014-06-03 03:56:40 -04:00
|
|
|
|
2014-05-23 04:22:00 -04:00
|
|
|
dropzone = $(".div-dropzone").dropzone(
|
|
|
|
url: project_image_path_upload
|
|
|
|
dictDefaultMessage: ""
|
|
|
|
clickable: true
|
|
|
|
paramName: "markdown_img"
|
|
|
|
maxFilesize: 10
|
|
|
|
uploadMultiple: false
|
|
|
|
acceptedFiles: "image/jpg,image/jpeg,image/gif,image/png"
|
|
|
|
headers:
|
|
|
|
"X-CSRF-Token": $("meta[name=\"csrf-token\"]").attr("content")
|
|
|
|
|
|
|
|
previewContainer: false
|
|
|
|
|
|
|
|
processing: ->
|
2014-06-03 03:56:40 -04:00
|
|
|
$(".div-dropzone-alert").alert "close"
|
2014-05-23 04:22:00 -04:00
|
|
|
|
|
|
|
dragover: ->
|
|
|
|
$(".div-dropzone > textarea").addClass "div-dropzone-focus"
|
|
|
|
$(".div-dropzone-hover").css "opacity", 0.7
|
|
|
|
return
|
|
|
|
|
|
|
|
dragleave: ->
|
|
|
|
$(".div-dropzone > textarea").removeClass "div-dropzone-focus"
|
|
|
|
$(".div-dropzone-hover").css "opacity", 0
|
|
|
|
return
|
|
|
|
|
|
|
|
drop: ->
|
|
|
|
$(".div-dropzone > textarea").removeClass "div-dropzone-focus"
|
|
|
|
$(".div-dropzone-hover").css "opacity", 0
|
|
|
|
$(".div-dropzone > textarea").focus()
|
|
|
|
return
|
|
|
|
|
|
|
|
success: (header, response) ->
|
2014-06-03 03:56:40 -04:00
|
|
|
child = $(dropzone[0]).children("textarea")
|
|
|
|
$(child).val $(child).val() + formatLink(response.link) + "\n"
|
2014-05-23 04:22:00 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
error: (temp, errorMessage) ->
|
2014-06-03 03:56:40 -04:00
|
|
|
checkIfMsgExists = $(".error-alert").children().length
|
|
|
|
if checkIfMsgExists is 0
|
|
|
|
$(".error-alert").append divAlert
|
|
|
|
$(".div-dropzone-alert").append btnAlert + errorMessage
|
2014-05-23 04:22:00 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
sending: ->
|
2014-06-03 03:56:40 -04:00
|
|
|
$(".div-dropzone-spinner").css "opacity", 0.7
|
2014-05-23 04:22:00 -04:00
|
|
|
return
|
|
|
|
|
|
|
|
complete: ->
|
|
|
|
$(".dz-preview").remove()
|
|
|
|
$(".markdown-area").trigger "input"
|
2014-06-03 03:56:40 -04:00
|
|
|
$(".div-dropzone-spinner").css "opacity", 0
|
2014-05-23 04:22:00 -04:00
|
|
|
return
|
|
|
|
)
|
|
|
|
|
|
|
|
$(".markdown-selector").click (e) ->
|
|
|
|
e.preventDefault()
|
|
|
|
$(".div-dropzone").click()
|
|
|
|
return
|
|
|
|
|
|
|
|
return
|