From 9e98d30612cb1445a7665c4c5c7474cf7b220fd1 Mon Sep 17 00:00:00 2001 From: Naoki Takezoe Date: Tue, 6 Sep 2016 02:05:23 +0900 Subject: [PATCH] (refs #1288)Dropping files is also available in textarea, not only in the bottom bar. --- .../gitbucket/core/helper/attached.scala.html | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/twirl/gitbucket/core/helper/attached.scala.html b/src/main/twirl/gitbucket/core/helper/attached.scala.html index 9bea4f14d..02624f2a4 100644 --- a/src/main/twirl/gitbucket/core/helper/attached.scala.html +++ b/src/main/twirl/gitbucket/core/helper/attached.scala.html @@ -46,18 +46,11 @@ $(function(){ @if(generateScript){ try { + $([$('#@textareaId')[0]]).dropzone({ + @dropzone(false, textareaId) + }); $([$('#@textareaId').closest('div')[0], $('#@textareaId').next('div')[0]]).dropzone({ - url: '@context.path/upload/file/@repository.owner/@repository.name', - maxFilesize: 10, - acceptedFiles: @Html(FileUtil.mimeTypeWhiteList.mkString("'", ",", "'")), - dictInvalidFileType: 'Unfortunately, we don\'t support that file type. Try again with a PNG, GIF, JPG, DOCX, PPTX, XLSX, TXT, or PDF.', - previewTemplate: "
\n
Uploading your files...
\n
\n
", - success: function(file, id) { - var attachFile = (file.type.match(/image\/.*/) ? '\n![' + file.name.split('.')[0] : '\n[' + file.name) + - '](@context.baseUrl/@repository.owner/@repository.name/_attached/' + id + ')'; - $('#@textareaId').val($('#@textareaId').val() + attachFile); - $(file.previewElement).prevAll('div.dz-preview').addBack().remove(); - } + @dropzone(true, textareaId) }); } catch(e) { if (e.message !== "Dropzone already attached.") { @@ -68,3 +61,17 @@ $(function(){ }); } +@dropzone(clickable: Boolean, textareaId: Option[String]) = { + url: '@context.path/upload/file/@repository.owner/@repository.name', + maxFilesize: 10, + clickable: false, + acceptedFiles: @Html(FileUtil.mimeTypeWhiteList.mkString("'", ",", "'")), + dictInvalidFileType: 'Unfortunately, we don\'t support that file type. Try again with a PNG, GIF, JPG, DOCX, PPTX, XLSX, TXT, or PDF.', + previewTemplate: "
\n
Uploading your files...
\n
\n
", + success: function(file, id) { + var attachFile = (file.type.match(/image\/.*/) ? '\n![' + file.name.split('.')[0] : '\n[' + file.name) + + '](@context.baseUrl/@repository.owner/@repository.name/_attached/' + id + ')'; + $('#@textareaId').val($('#@textareaId').val() + attachFile); + $(file.previewElement).prevAll('div.dz-preview').addBack().remove(); + } +}