lib/assets/javascripts/attachy.js in attachy-0.1.1 vs lib/assets/javascripts/attachy.js in attachy-0.1.2

- old
+ new

@@ -3,11 +3,11 @@ * * The MIT License * * @author : Washington Botelho * @doc : http://wbotelhos.com/attachy - * @version : 0.1.1 + * @version : 0.1.2 * */ ; (function($) { @@ -107,20 +107,26 @@ var image = that.image(file, json), link = that.link(file, image, json), remove = that.removeButton(); + that.hideEmpty(); + if (that.multiple) { var node = $('<li />', { html: link, 'class': 'attachy__node' }).append(remove); that.content.append(node); } else { that.content.find('li').empty().append(link, remove); } }); }, + hideEmpty: function() { + this.empty.hide(); + }, + image: function(file, json) { var config = this.imageConfig(file), attributes = { alt: config.alt, height: config.height, width: config.width }; @@ -220,13 +226,13 @@ this.files = files; this.updateHidden(); - // if (this.defaultAvatar) { - // this.container.html(this.defaultAvatar.clone()); - // } + if (!this.files.length) { + this.showEmpty(); + } }, onUploading: function() { this.wrapper.addClass('attachy__uploading'); }, @@ -272,12 +278,17 @@ scan: function() { this.wrapper = this.field.closest('.attachy'); this.button = this.wrapper.find('.attachy__button span'); this.content = this.wrapper.find('.attachy__content'); - this.hidden = this.wrapper.find('input[type="hidden"]') + this.empty = this.wrapper.find('.attachy__empty'); + this.hidden = this.wrapper.find('input[type="hidden"]'); this.remove = this.wrapper.find('.attachy__remove'); this.submit = this.wrapper.closest('form').find(':submit'); + }, + + showEmpty: function() { + this.empty.show(); }, updateHidden: function() { this.hidden.val(JSON.stringify(this.files)); }