mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[mujs] history
This commit is contained in:
parent
1f09c7c2df
commit
5f18359a6f
@ -25,6 +25,7 @@
|
|||||||
#include "document/view.h"
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
#include "ecmascript/mujs.h"
|
#include "ecmascript/mujs.h"
|
||||||
|
#include "ecmascript/mujs/history.h"
|
||||||
#include "ecmascript/mujs/navigator.h"
|
#include "ecmascript/mujs/navigator.h"
|
||||||
#include "ecmascript/mujs/screen.h"
|
#include "ecmascript/mujs/screen.h"
|
||||||
#include "ecmascript/mujs/unibar.h"
|
#include "ecmascript/mujs/unibar.h"
|
||||||
@ -82,6 +83,7 @@ mujs_get_interpreter(struct ecmascript_interpreter *interpreter)
|
|||||||
mjs_screen_init(interpreter, J);
|
mjs_screen_init(interpreter, J);
|
||||||
mjs_unibar_init(interpreter, J);
|
mjs_unibar_init(interpreter, J);
|
||||||
mjs_navigator_init(interpreter, J);
|
mjs_navigator_init(interpreter, J);
|
||||||
|
mjs_history_init(interpreter, J);
|
||||||
|
|
||||||
return J;
|
return J;
|
||||||
#if 0
|
#if 0
|
||||||
|
144
src/ecmascript/mujs/history.cpp
Normal file
144
src/ecmascript/mujs/history.cpp
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/* The QuickJS history object implementation. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "elinks.h"
|
||||||
|
|
||||||
|
#include "bfu/dialog.h"
|
||||||
|
#include "cache/cache.h"
|
||||||
|
#include "cookies/cookies.h"
|
||||||
|
#include "dialogs/menu.h"
|
||||||
|
#include "dialogs/status.h"
|
||||||
|
#include "document/html/frames.h"
|
||||||
|
#include "document/document.h"
|
||||||
|
#include "document/forms.h"
|
||||||
|
#include "document/view.h"
|
||||||
|
#include "ecmascript/ecmascript.h"
|
||||||
|
#include "ecmascript/mujs.h"
|
||||||
|
#include "ecmascript/mujs/history.h"
|
||||||
|
#include "ecmascript/mujs/window.h"
|
||||||
|
#include "intl/libintl.h"
|
||||||
|
#include "main/select.h"
|
||||||
|
#include "osdep/newwin.h"
|
||||||
|
#include "osdep/sysname.h"
|
||||||
|
#include "protocol/http/http.h"
|
||||||
|
#include "protocol/uri.h"
|
||||||
|
#include "session/history.h"
|
||||||
|
#include "session/location.h"
|
||||||
|
#include "session/session.h"
|
||||||
|
#include "session/task.h"
|
||||||
|
#include "terminal/tab.h"
|
||||||
|
#include "terminal/terminal.h"
|
||||||
|
#include "util/conv.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
#include "util/string.h"
|
||||||
|
#include "viewer/text/draw.h"
|
||||||
|
#include "viewer/text/form.h"
|
||||||
|
#include "viewer/text/link.h"
|
||||||
|
#include "viewer/text/vs.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_history_back(js_State *J)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "history");
|
||||||
|
|
||||||
|
assert(interpreter);
|
||||||
|
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||||
|
struct session *ses = doc_view->session;
|
||||||
|
|
||||||
|
go_back(ses);
|
||||||
|
|
||||||
|
/* history_back() must return 0 for onClick to cause displaying previous page
|
||||||
|
* and return non zero for <a href="javascript:history.back()"> to prevent
|
||||||
|
* "calculating" new link. Returned value 2 is changed to 0 in function
|
||||||
|
* spidermonkey_eval_boolback */
|
||||||
|
js_pushnull(J);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_history_forward(js_State *J)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "history");
|
||||||
|
|
||||||
|
assert(interpreter);
|
||||||
|
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||||
|
struct session *ses = doc_view->session;
|
||||||
|
|
||||||
|
go_unback(ses);
|
||||||
|
|
||||||
|
js_pushnull(J);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_history_go(js_State *J)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
struct ecmascript_interpreter *interpreter = (struct ecmascript_interpreter *)js_touserdata(J, 0, "history");
|
||||||
|
|
||||||
|
assert(interpreter);
|
||||||
|
struct document_view *doc_view = interpreter->vs->doc_view;
|
||||||
|
struct session *ses = doc_view->session;
|
||||||
|
struct location *loc;
|
||||||
|
|
||||||
|
int index = js_tointeger(J, 1);
|
||||||
|
|
||||||
|
for (loc = cur_loc(ses);
|
||||||
|
loc != (struct location *) &ses->history.history;
|
||||||
|
loc = index > 0 ? loc->next : loc->prev) {
|
||||||
|
if (!index) {
|
||||||
|
go_history(ses, loc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
index += index > 0 ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
js_pushnull(J);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mjs_history_toString(js_State *J)
|
||||||
|
{
|
||||||
|
#ifdef ECMASCRIPT_DEBUG
|
||||||
|
fprintf(stderr, "%s:%s\n", __FILE__, __FUNCTION__);
|
||||||
|
#endif
|
||||||
|
js_pushstring(J, "[history object]");
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
mjs_history_init(struct ecmascript_interpreter *interpreter, js_State *J)
|
||||||
|
{
|
||||||
|
js_getglobal(J, "Object");
|
||||||
|
js_getproperty(J, -1, "prototype");
|
||||||
|
js_newuserdata(J, "history", interpreter, NULL);
|
||||||
|
|
||||||
|
js_newcfunction(J, mjs_history_back, "history.prototype.back", 0);
|
||||||
|
js_defproperty(J, -2, "back", JS_DONTENUM);
|
||||||
|
|
||||||
|
js_newcfunction(J, mjs_history_forward, "history.prototype.forward", 0);
|
||||||
|
js_defproperty(J, -2, "forward", JS_DONTENUM);
|
||||||
|
|
||||||
|
js_newcfunction(J, mjs_history_go, "history.prototype.go", 1);
|
||||||
|
js_defproperty(J, -2, "go", JS_DONTENUM);
|
||||||
|
|
||||||
|
js_newcfunction(J, mjs_history_toString, "history.prototype.toString", 0);
|
||||||
|
js_defproperty(J, -2, "toString", JS_DONTENUM);
|
||||||
|
|
||||||
|
js_defglobal(J, "history", JS_DONTENUM);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
10
src/ecmascript/mujs/history.h
Normal file
10
src/ecmascript/mujs/history.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef EL__ECMASCRIPT_MUJS_HISTORY_H
|
||||||
|
#define EL__ECMASCRIPT_MUJS_HISTORY_H
|
||||||
|
|
||||||
|
#include <mujs.h>
|
||||||
|
|
||||||
|
struct ecmascript_interpreter;
|
||||||
|
|
||||||
|
int mjs_history_init(struct ecmascript_interpreter *interpreter, js_State *J);
|
||||||
|
|
||||||
|
#endif
|
@ -1,3 +1,3 @@
|
|||||||
#srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp',
|
#srcs += files('attr.cpp', 'attributes.cpp', 'collection.cpp', 'console.cpp', 'document.cpp', 'element.cpp', 'form.cpp', 'forms.cpp', 'heartbeat.cpp', 'history.cpp', 'implementation.cpp',
|
||||||
#'input.cpp', 'localstorage.cpp', 'location.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')
|
#'input.cpp', 'localstorage.cpp', 'location.cpp', 'navigator.cpp', 'nodelist.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')
|
||||||
srcs += files('navigator.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')
|
srcs += files('history.cpp', 'navigator.cpp', 'screen.cpp', 'unibar.cpp', 'window.cpp')
|
||||||
|
Loading…
Reference in New Issue
Block a user