diff --git a/app/assets/javascripts/discourse/components/utilities.js b/app/assets/javascripts/discourse/components/utilities.js index e16eb48f3e4..9b010113c46 100644 --- a/app/assets/javascripts/discourse/components/utilities.js +++ b/app/assets/javascripts/discourse/components/utilities.js @@ -212,6 +212,30 @@ Discourse.Utilities = { if (!extensions) return false; var regexp = new RegExp("\\.(" + extensions.replace(/\./g, "") + ")$", "i"); return file && file.name ? file.name.match(regexp) : false; + }, + + /** + Get the markdown template for an upload (either an image or an attachment) + + @method getUploadMarkdown + @param {Upload} upload The upload we want the markdown from + **/ + getUploadMarkdown: function(upload) { + if (this.isAnImage(upload.original_filename)) { + return ''; + } else { + return '' + upload.original_filename + ''; + } + }, + + /** + Check whether the path is refering to an image + + @method isAnImage + @param {String} path The path + **/ + isAnImage: function(path) { + return path && path.match(/\.(png|jpg|jpeg|gif|bmp|tif)$/i); } }; diff --git a/app/assets/javascripts/discourse/views/composer_view.js b/app/assets/javascripts/discourse/views/composer_view.js index 395ff20a9a3..465c8d9c92d 100644 --- a/app/assets/javascripts/discourse/views/composer_view.js +++ b/app/assets/javascripts/discourse/views/composer_view.js @@ -285,9 +285,9 @@ Discourse.ComposerView = Discourse.View.extend({ // done $uploadTarget.on('fileuploaddone', function (e, data) { - var upload = data.result; - var html = ""; - composerView.addMarkdown(html); + var markdown = Discourse.Utilities.getUploadMarkdown(data.result); + // appends a space at the end of the inserted markdown + composerView.addMarkdown(markdown + " "); composerView.set('isUploading', false); }); diff --git a/app/assets/stylesheets/application/topic.css.scss b/app/assets/stylesheets/application/topic.css.scss index c55d097a3c8..d5ce90ad081 100644 --- a/app/assets/stylesheets/application/topic.css.scss +++ b/app/assets/stylesheets/application/topic.css.scss @@ -175,6 +175,16 @@ } } + a.attachment:before { + display: inline-block; + margin-right: 4px; + font-family: "FontAwesome"; + content: "\f019"; + } + .attachment + .size { + margin: 0 5px; + } + // When we are quoting something aside.quote { border-left: 5px solid #d7d7d7; diff --git a/app/serializers/upload_serializer.rb b/app/serializers/upload_serializer.rb index 8971e9a3d50..9a0a7753b89 100644 --- a/app/serializers/upload_serializer.rb +++ b/app/serializers/upload_serializer.rb @@ -1,5 +1,5 @@ class UploadSerializer < ApplicationSerializer - attributes :url, :filesize, :original_filename, :width, :height + attributes :url, :original_filename, :width, :height end