diff --git a/askbot/media/wmd/wmd.js b/askbot/media/wmd/wmd.js index 5d77c51c2c..dd378393eb 100644 --- a/askbot/media/wmd/wmd.js +++ b/askbot/media/wmd/wmd.js @@ -301,7 +301,11 @@ var WmdUploadDialog = function (opts) { this._makeLinkMarkdown = opts.makeLinkMarkdown; this.setFileType(opts.dialogType === 'file' ? 'attachment' : 'image'); - this.setInputId(util.makeId('file-upload')); + // Counter ensures each dialog instance gets a unique file-input ID. + // Never decremented: monotonic growth guarantees no ID collisions, + // even if the modal:after-close DOM cleanup hasn't fired yet. + WmdUploadDialog._counter += 1; + this.setInputId(util.makeId('file-upload-' + WmdUploadDialog._counter)); this._headerEnabled = true; this.setHeadingText(opts.headingText); @@ -310,6 +314,7 @@ var WmdUploadDialog = function (opts) { } }; inherits(WmdUploadDialog, FileUploadDialog); +WmdUploadDialog._counter = 0; WmdUploadDialog.prototype.createDom = function () { var me = this; @@ -326,6 +331,10 @@ WmdUploadDialog.prototype.createDom = function () { WmdUploadDialog.superClass_.createDom.call(this); + this._element.on('modal:after-close', function () { + me._element.remove(); + }); + // Override reject handler to also notify makeLinkMarkdown. // Must rebind the button because super createDom() already bound the original. var originalReject = me._reject_handler;