Newer
Older
gitbucket_jkp / src / main / twirl / helper / attached.scala.html
@shimamoto shimamoto on 29 Apr 2014 1 KB (refs #12) Add acceptedFiles options.
@(owner: String, repository: String)(textarea: Html)(implicit context: app.Context)
@import context._
<div class="muted">
  @textarea
  Attach images by dragging &amp; dropping, or selecting them.
</div>
@defining("(id=\")([\\w\\-]*)(\")".r.findFirstMatchIn(textarea.body).map(_.group(2))){ textareaId =>
<script>
$(function(){
  $('#@textareaId').closest('div').dropzone({
    url: '@path/upload/image/@owner/@repository',
    maxFilesize: 10,
    acceptedFiles: 'image/*',
    dictInvalidFileType: 'Unfortunately, we don\'t support that file type. Try again with a PNG, GIF, or JPG.',
    previewTemplate: "<div class=\"dz-preview\">\n  <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress>Uploading your images...</span></div>\n  <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>",
    success: function(file, id) {
      var images = '\n![' + file.name.split('.')[0] + '](@baseURL/@owner/@repository/_attached/' + id + ')';
      $('#@textareaId').val($('#@textareaId').val() + images);
      $(file.previewElement).prevAll('div.dz-preview').addBack().remove();
    }
  });
});
</script>
}