mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[ecmascript] Added keydown and keyup code for eventListeners.
TODO: KeyEvent (keycode etc.)
This commit is contained in:
parent
d7f4f94a62
commit
56ab960cce
@ -5,6 +5,6 @@ INCLUDES += $(TRE_CFLAGS)
|
||||
|
||||
OBJS-$(CONFIG_MARKS) += marks.o
|
||||
|
||||
OBJS = draw.o form.obj link.obj search.o textarea.o view.o vs.obj
|
||||
OBJS = draw.o form.obj link.obj search.o textarea.o view.obj vs.obj
|
||||
|
||||
include $(top_srcdir)/Makefile.lib
|
||||
|
@ -24,6 +24,7 @@
|
||||
#ifdef CONFIG_ECMASCRIPT_SMJS
|
||||
#include "ecmascript/spidermonkey/element.h"
|
||||
#include <libxml++/libxml++.h>
|
||||
#include <map>
|
||||
#endif
|
||||
|
||||
#include "intl/libintl.h"
|
||||
@ -50,7 +51,6 @@
|
||||
#include "viewer/text/view.h"
|
||||
#include "viewer/text/vs.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
/* Perhaps some of these would be more fun to have in viewer/common/, dunno.
|
||||
* --pasky */
|
||||
|
@ -4,4 +4,4 @@ if conf_data.get('CONFIG_MARKS')
|
||||
srcs += files('marks.c')
|
||||
endif
|
||||
|
||||
srcs += files('draw.c', 'form.cpp', 'link.cpp', 'search.c', 'textarea.c', 'view.c', 'vs.cpp')
|
||||
srcs += files('draw.c', 'form.cpp', 'link.cpp', 'search.c', 'textarea.c', 'view.cpp', 'vs.cpp')
|
||||
|
@ -27,6 +27,11 @@
|
||||
#include "document/options.h"
|
||||
#include "document/renderer.h"
|
||||
#include "document/view.h"
|
||||
#ifdef CONFIG_ECMASCRIPT_SMJS
|
||||
#include "ecmascript/spidermonkey/element.h"
|
||||
#include <libxml++/libxml++.h>
|
||||
#include <map>
|
||||
#endif
|
||||
#include "intl/charsets.h"
|
||||
#include "intl/libintl.h"
|
||||
#include "main/event.h"
|
||||
@ -1277,19 +1282,38 @@ static enum frame_event_status
|
||||
try_form_action(struct session *ses, struct document_view *doc_view,
|
||||
struct link *link, struct term_event *ev)
|
||||
{
|
||||
enum frame_event_status status;
|
||||
enum frame_event_status status = FRAME_EVENT_OK;
|
||||
|
||||
assert(link);
|
||||
|
||||
if (!link_is_textinput(link))
|
||||
return FRAME_EVENT_IGNORED;
|
||||
|
||||
if (!current_link_evhook(doc_view, SEVHOOK_ONKEYDOWN)
|
||||
|| !current_link_evhook(doc_view, SEVHOOK_ONKEYUP)) {
|
||||
return FRAME_EVENT_IGNORED;
|
||||
#ifdef CONFIG_ECMASCRIPT
|
||||
std::map<int, xmlpp::Element *> *mapa = (std::map<int, xmlpp::Element *> *)doc_view->document->element_map;
|
||||
|
||||
if (mapa) {
|
||||
auto element = (*mapa).find(link->element_offset);
|
||||
|
||||
if (element != (*mapa).end()) {
|
||||
const char *event_name = script_event_hook_name[SEVHOOK_ONKEYDOWN];
|
||||
|
||||
check_element_event(element->second, event_name);
|
||||
event_name = script_event_hook_name[SEVHOOK_ONKEYUP];
|
||||
check_element_event(element->second, event_name);
|
||||
}
|
||||
}
|
||||
|
||||
status = field_op(ses, doc_view, link, ev);
|
||||
if (!current_link_evhook(doc_view, SEVHOOK_ONKEYDOWN)) {
|
||||
status = FRAME_EVENT_IGNORED;
|
||||
}
|
||||
if (status != FRAME_EVENT_IGNORED && !current_link_evhook(doc_view, SEVHOOK_ONKEYUP)) {
|
||||
status = FRAME_EVENT_IGNORED;
|
||||
}
|
||||
#endif
|
||||
if (status != FRAME_EVENT_IGNORED) {
|
||||
status = field_op(ses, doc_view, link, ev);
|
||||
}
|
||||
|
||||
if (status != FRAME_EVENT_IGNORED
|
||||
&& ses->insert_mode == INSERT_MODE_ON) {
|
20
test/ecmascript/keyListener.html
Normal file
20
test/ecmascript/keyListener.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<p>A function is triggered when the user is pressing a key in the input field.</p>
|
||||
|
||||
<form action="/">
|
||||
<input id="k" type="text">
|
||||
<input type="submit">
|
||||
</form>
|
||||
<script>
|
||||
function myFunction(event)
|
||||
{
|
||||
alert("You pressed a key inside the input field");
|
||||
}
|
||||
|
||||
document.getElementById('k').addEventListener('keydown', myFunction);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user