summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/application.js.coffee1
-rw-r--r--app/assets/javascripts/behaviors/toggler_behavior.coffee2
-rw-r--r--app/assets/javascripts/markdown_area.js.coffee85
3 files changed, 87 insertions, 1 deletions
diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee
index 587e51a7a83..35e43554661 100644
--- a/app/assets/javascripts/application.js.coffee
+++ b/app/assets/javascripts/application.js.coffee
@@ -29,6 +29,7 @@
#= require underscore
#= require nprogress
#= require nprogress-turbolinks
+#= require dropzone
#= require_tree .
window.slugify = (text) ->
diff --git a/app/assets/javascripts/behaviors/toggler_behavior.coffee b/app/assets/javascripts/behaviors/toggler_behavior.coffee
index d06cb116dfe..8ac5bfe95d8 100644
--- a/app/assets/javascripts/behaviors/toggler_behavior.coffee
+++ b/app/assets/javascripts/behaviors/toggler_behavior.coffee
@@ -1,6 +1,6 @@
$ ->
$("body").on "click", ".js-toggler-target", ->
- container = $(@).closest(".js-toggler-container")
+ container = $(".notes-container")
container.toggleClass("on")
# Toggle button. Show/hide content inside parent container.
diff --git a/app/assets/javascripts/markdown_area.js.coffee b/app/assets/javascripts/markdown_area.js.coffee
new file mode 100644
index 00000000000..def5d12a820
--- /dev/null
+++ b/app/assets/javascripts/markdown_area.js.coffee
@@ -0,0 +1,85 @@
+formatLink = (str) ->
+ "![" + str.alt + "](" + str.url + ")"
+
+$(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 + ">&times;</button>"
+ project_image_path_upload = window.project_image_path_upload or null
+
+ $("textarea.markdown-area").wrap "<div class=\"div-dropzone\"></div>"
+
+ $(".div-dropzone").parent().addClass "div-dropzone-wrapper"
+
+ $(".div-dropzone").append divHover
+ $(".div-dropzone-hover").append iconPicture
+ $(".div-dropzone").append divSpinner
+ $(".div-dropzone-spinner").append iconSpinner
+
+
+ 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: ->
+ $(".div-dropzone-alert").alert "close"
+
+ 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) ->
+ child = $(dropzone[0]).children("textarea")
+ $(child).val $(child).val() + formatLink(response.link) + "\n"
+ return
+
+ error: (temp, errorMessage) ->
+ checkIfMsgExists = $(".error-alert").children().length
+ if checkIfMsgExists is 0
+ $(".error-alert").append divAlert
+ $(".div-dropzone-alert").append btnAlert + errorMessage
+ return
+
+ sending: ->
+ $(".div-dropzone-spinner").css "opacity", 0.7
+ return
+
+ complete: ->
+ $(".dz-preview").remove()
+ $(".markdown-area").trigger "input"
+ $(".div-dropzone-spinner").css "opacity", 0
+ return
+ )
+
+ $(".markdown-selector").click (e) ->
+ e.preventDefault()
+ $(".div-dropzone").click()
+ return
+
+ return \ No newline at end of file