diff --git a/4chan_x.user.js b/4chan_x.user.js
index f6dc1cc4b..00dc035e8 100644
--- a/4chan_x.user.js
+++ b/4chan_x.user.js
@@ -1333,6 +1333,10 @@
$.on(this.el, 'click', function() {
return _this.select();
});
+ $.on($('.remove', this.el), 'click', function(e) {
+ e.stopPropagation();
+ return _this.rm();
+ });
if (file) this.setFile(file);
$.before($('#addReply', qr.el), this.el);
qr.replies.push(this);
@@ -1367,9 +1371,18 @@
};
_Class.prototype.rm = function() {
- var url;
+ var index, url;
+ $.rm(this.el);
+ index = qr.replies.indexOf(this);
+ if (qr.replies.length === 1) {
+ new qr.reply().select();
+ } else if (this.el.id === 'selected') {
+ (qr.replies[index - 1] || qr.replies[index + 1]).select();
+ }
+ qr.replies.splice(index, 1);
url = window.URL || window.webkitURL;
- return url.revokeObjectURL(this.url);
+ url.revokeObjectURL(this.url);
+ return delete this;
};
return _Class;
diff --git a/script.coffee b/script.coffee
index e1e80c773..b1471e7da 100644
--- a/script.coffee
+++ b/script.coffee
@@ -1000,6 +1000,9 @@ qr =
href: 'javascript:;'
innerHTML: 'x'
$.on @el, 'click', => @select()
+ $.on $('.remove', @el), 'click', (e) =>
+ e.stopPropagation()
+ @rm()
@setFile file if file
$.before $('#addReply', qr.el), @el
qr.replies.push @
@@ -1019,9 +1022,16 @@ qr =
for data in ['name', 'email', 'sub', 'com']
$("[name=#{data}]", qr.el).value = @[data]
rm: ->
- # rm reply from qr.replies and the UI
+ $.rm @el
+ index = qr.replies.indexOf @
+ if qr.replies.length is 1
+ new qr.reply().select()
+ else if @el.id is 'selected'
+ (qr.replies[index-1] or qr.replies[index+1]).select()
+ qr.replies.splice index, 1
url = window.URL or window.webkitURL
url.revokeObjectURL @url
+ delete @
dialog: ->