Skip to content

Commit 12c6587

Browse files
authored
Merge pull request #11 from jywarren/submit-form-fix
fix for crossed forms submission
2 parents b89a9d2 + 537af64 commit 12c6587

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

dist/inlineMarkdownEditor.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -10344,8 +10344,8 @@ module.exports = function processSection(markdown, o) {
1034410344
if (o.isEditable(_markdown, o.originalMarkdown)) {
1034510345
var formHtml = o.buildSectionForm(uniqueId, _markdown);
1034610346
el.after(formHtml);
10347-
var form = $('#' + uniqueId);
10348-
o.insertEditLink(uniqueId, el, form, onEdit, false, o);
10347+
var _form = $('#' + uniqueId);
10348+
o.insertEditLink(uniqueId, el, _form, onEdit, false, o);
1034910349
// plan for swappable editors; will need to specify both constructor and onEditorSubmit
1035010350
function onEdit() {
1035110351
var editor;
@@ -10355,42 +10355,45 @@ module.exports = function processSection(markdown, o) {
1035510355
textarea: $('#' + uniqueId + ' textarea')[0]
1035610356
});
1035710357
}
10358-
form.find('.cancel').click(function inlineEditCancelClick(e) {
10358+
_form.find('.cancel').click(function inlineEditCancelClick(e) {
1035910359
e.preventDefault();
10360-
form.hide();
10360+
_form.hide();
1036110361
});
10362-
form.find('button.submit').click(function(e) {
10363-
prepareAndSendSectionForm(e, form, editor, _markdown);
10362+
_form.find('button.submit').click(function(e) {
10363+
prepareAndSendSectionForm(e, _form, editor, _markdown);
1036410364
});
1036510365
}
1036610366
}
1036710367

10368-
function prepareAndSendSectionForm(e, form, _editor, _markdown) {
10368+
function prepareAndSendSectionForm(e, __form, _editor, _markdown) {
1036910369
message.html('<i class="fa fa-spinner fa-spin" style="color:#ccc;"></i>');
1037010370
if (_editor) {
1037110371
changes = _editor.richTextModule.value(); // rich editor
1037210372
} else {
10373-
changes = form.find('textarea').val();
10373+
changes = __form.find('textarea').val();
1037410374
}
10375-
o.submitSectionForm(e, _markdown, changes, o);
10375+
o.submitSectionForm(e, _markdown, changes, o, el, __form);
1037610376
}
1037710377

10378-
// provide overridable default
10379-
o.submitSectionForm = o.submitSectionForm || function submitSectionForm(e, before, after, o) {
10378+
// provide overridable default; though we have to explicitly pass in
10379+
// all this stuff so the section forms don't get crossed
10380+
o.submitSectionForm = o.submitSectionForm || function submitSectionForm(e, before, after, o, _el, __form) {
1038010381
e.preventDefault();
1038110382
$.post(o.replaceUrl, {
1038210383
before: before, // encodeURI(before)
1038310384
after: after // encodeURI(after)
1038410385
})
1038510386
.done(function onComplete(response) {
1038610387
// we should need fewer things here:
10387-
o.onComplete(response, markdown, html, el, uniqueId, form, o);
10388+
o.onComplete(response, after, html, _el, uniqueId, __form, o);
1038810389
}).error(function onFail(response) {
1038910390
o.onFail(response, uniqueId);
1039010391
}).fail(function onFail(response) {
1039110392
o.onFail(response, uniqueId);
1039210393
}); // these don't work?
1039310394
}
10395+
10396+
return _form;
1039410397
}
1039510398
}
1039610399

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "inline-markdown-editor",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "An inline wysiwyg markdown document editor based on replacing string subsections. WYSIWYG possible via woofmark.",
55
"main": "dist/inlineMarkdownEditor.js",
66
"scripts": {

src/processSection.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ module.exports = function processSection(markdown, o) {
2020
if (o.isEditable(_markdown, o.originalMarkdown)) {
2121
var formHtml = o.buildSectionForm(uniqueId, _markdown);
2222
el.after(formHtml);
23-
var form = $('#' + uniqueId);
24-
o.insertEditLink(uniqueId, el, form, onEdit, false, o);
23+
var _form = $('#' + uniqueId);
24+
o.insertEditLink(uniqueId, el, _form, onEdit, false, o);
2525
// plan for swappable editors; will need to specify both constructor and onEditorSubmit
2626
function onEdit() {
2727
var editor;
@@ -31,41 +31,44 @@ module.exports = function processSection(markdown, o) {
3131
textarea: $('#' + uniqueId + ' textarea')[0]
3232
});
3333
}
34-
form.find('.cancel').click(function inlineEditCancelClick(e) {
34+
_form.find('.cancel').click(function inlineEditCancelClick(e) {
3535
e.preventDefault();
36-
form.hide();
36+
_form.hide();
3737
});
38-
form.find('button.submit').click(function(e) {
39-
prepareAndSendSectionForm(e, form, editor, _markdown);
38+
_form.find('button.submit').click(function(e) {
39+
prepareAndSendSectionForm(e, _form, editor, _markdown);
4040
});
4141
}
4242
}
4343

44-
function prepareAndSendSectionForm(e, form, _editor, _markdown) {
44+
function prepareAndSendSectionForm(e, __form, _editor, _markdown) {
4545
message.html('<i class="fa fa-spinner fa-spin" style="color:#ccc;"></i>');
4646
if (_editor) {
4747
changes = _editor.richTextModule.value(); // rich editor
4848
} else {
49-
changes = form.find('textarea').val();
49+
changes = __form.find('textarea').val();
5050
}
51-
o.submitSectionForm(e, _markdown, changes, o);
51+
o.submitSectionForm(e, _markdown, changes, o, el, __form);
5252
}
5353

54-
// provide overridable default
55-
o.submitSectionForm = o.submitSectionForm || function submitSectionForm(e, before, after, o) {
54+
// provide overridable default; though we have to explicitly pass in
55+
// all this stuff so the section forms don't get crossed
56+
o.submitSectionForm = o.submitSectionForm || function submitSectionForm(e, before, after, o, _el, __form) {
5657
e.preventDefault();
5758
$.post(o.replaceUrl, {
5859
before: before, // encodeURI(before)
5960
after: after // encodeURI(after)
6061
})
6162
.done(function onComplete(response) {
6263
// we should need fewer things here:
63-
o.onComplete(response, markdown, html, el, uniqueId, form, o);
64+
o.onComplete(response, after, html, _el, uniqueId, __form, o);
6465
}).error(function onFail(response) {
6566
o.onFail(response, uniqueId);
6667
}).fail(function onFail(response) {
6768
o.onFail(response, uniqueId);
6869
}); // these don't work?
6970
}
71+
72+
return _form;
7073
}
7174
}

0 commit comments

Comments
 (0)