Problem can be seen in this file at line 77. This is the relevant part:
$addButton.on("click",function (e) {
$addButton.loadPopup({
url: '/questions/originals/' + questionId + '/find-originals-popup',
target: $('.container')
})
.done(function ($popup) {
StackExchange.vote_closingAndFlagging.close_initDuplicateSubPane();
$popup.asyncLoad({
callback: function() {
StackExchange.vote_closingAndFlagging.close_afterLoadListOriginals($popup.find('.list-container'));
}
});
$('#add-original-form').trigger("submit", function (ev) {
ev.preventDefault();
/* more code here but it's omitted for brevity */
});
// the short story here is that initialization doesn't complete until the "show" event is triggered.
// but we can't trigger that NOW, because the popup isn't actually visible yet
// popup gets faded in after this callback returns...
// so, spin the event loop and listen for animation completed after it has had time to start.
// all this for the sake of re-using the duplicate dialog logic unchanged
setTimeout(function () {
$popup.promise().then(function () { $popup.find(".close-as-duplicate-pane").trigger("show"); });
}, 0);
});
e.preventDefault();
});
in particular look at the line $('#add-original-form').trigger("submit", function (ev) {
. The code before it sets up the dialog for adding duplicate targets. And when it gets to said line it immediately submits. The jQuery .trigger()
method will initiate the event (here "submit"). The function given after it will be passed in as extra parameters for the event handler (which is irrelevant in this case).
I suppose somebody meant to use .on()
to set up an event handler for a submission.
$('#add-original-form').on("submit", function (ev) {
ev.preventDefault();
/* more code here but it's omitted for brevity */
});
would have made sense as it sets the function as the handler and prevents the default behavior if this handler is triggered.