mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
This commit is contained in:
commit
99000b1f2e
@ -860,18 +860,28 @@ get_link_uri(struct session *ses, struct document_view *doc_view,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
try_submit_given_form(struct session *ses, struct document_view *doc_view,
|
call_onsubmit_and_submit(struct session *ses, struct document_view *doc_view,
|
||||||
struct form *form, int do_reload)
|
struct form_control *fc, int do_reload)
|
||||||
{
|
{
|
||||||
|
struct uri *uri = NULL;
|
||||||
|
enum cache_mode mode = do_reload ? CACHE_MODE_FORCE_RELOAD : CACHE_MODE_NORMAL;
|
||||||
|
|
||||||
|
assert(fc->form); /* regardless of whether there is a FORM element */
|
||||||
|
if_assert_failed return 0;
|
||||||
|
|
||||||
#ifdef CONFIG_ECMASCRIPT
|
#ifdef CONFIG_ECMASCRIPT
|
||||||
if (form->onsubmit) {
|
/* If the form has multiple submit buttons, this does not
|
||||||
|
* explicitly tell the ECMAScript code which of them was
|
||||||
|
* pressed. W3C DOM Level 3 doesn't seem to include such a
|
||||||
|
* feature. */
|
||||||
|
if (fc->form->onsubmit) {
|
||||||
struct string code;
|
struct string code;
|
||||||
|
|
||||||
if (init_string(&code)) {
|
if (init_string(&code)) {
|
||||||
struct view_state *vs = doc_view->vs;
|
struct view_state *vs = doc_view->vs;
|
||||||
struct ecmascript_interpreter *interpreter;
|
struct ecmascript_interpreter *interpreter;
|
||||||
unsigned char *ret = form->onsubmit;
|
unsigned char *ret = fc->form->onsubmit;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (vs->ecmascript_fragile)
|
if (vs->ecmascript_fragile)
|
||||||
@ -883,14 +893,24 @@ try_submit_given_form(struct session *ses, struct document_view *doc_view,
|
|||||||
while ((ret = strstr(ret, "return ")))
|
while ((ret = strstr(ret, "return ")))
|
||||||
while (*ret != ' ') *ret++ = ' ';
|
while (*ret != ' ') *ret++ = ' ';
|
||||||
|
|
||||||
add_to_string(&code, form->onsubmit);
|
add_to_string(&code, fc->form->onsubmit);
|
||||||
res = ecmascript_eval_boolback(interpreter, &code);
|
res = ecmascript_eval_boolback(interpreter, &code);
|
||||||
done_string(&code);
|
done_string(&code);
|
||||||
if (!res) return;
|
/* If the user presses Enter in a text field,
|
||||||
|
* and document.browse.forms.auto_submit is
|
||||||
|
* true, and the form has an onsubmit script
|
||||||
|
* that returns false, then insert mode should
|
||||||
|
* end, so return 1 here rather than 0. */
|
||||||
|
if (!res) return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* CONFIG_ECMASCRIPT */
|
||||||
submit_given_form(ses, doc_view, form, do_reload);
|
|
||||||
|
uri = get_form_uri(ses, doc_view, fc);
|
||||||
|
if (!uri) return 0;
|
||||||
|
goto_uri_frame(ses, uri, fc->form->target, mode);
|
||||||
|
done_uri(uri);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct link *
|
struct link *
|
||||||
@ -907,10 +927,11 @@ goto_current_link(struct session *ses, struct document_view *doc_view, int do_re
|
|||||||
|
|
||||||
if (link_is_form(link)) {
|
if (link_is_form(link)) {
|
||||||
struct form_control *fc = link->data.form_control;
|
struct form_control *fc = link->data.form_control;
|
||||||
struct form *form = fc->form;
|
|
||||||
|
|
||||||
try_submit_given_form(ses, doc_view, form, do_reload);
|
if (!call_onsubmit_and_submit(ses, doc_view, fc, do_reload))
|
||||||
return link;
|
return NULL;
|
||||||
|
else
|
||||||
|
return link;
|
||||||
} else
|
} else
|
||||||
uri = get_link_uri(ses, doc_view, link);
|
uri = get_link_uri(ses, doc_view, link);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user