Patch to make Javascript writeln() work (attempt 3)
by Dave Higton
This patch to Document/bnd makes the Javascript writeln() function
work as well as write(). This version inserts "\n", which seems
to be what the language requires. <br> was wrong.
It duplicates code from write(), but I'm really not keen on Daniel's
alternative suggestion. Sorry. (Re. the earlier thread: I think
it pays a third price, that of being less clear than duplicating
code.)
Hope this helps.
Dave
diff --git a/javascript/duktape/Document.bnd b/javascript/duktape/Document.bnd
index 6d11ea9..a97f30e 100644
--- a/javascript/duktape/Document.bnd
+++ b/javascript/duktape/Document.bnd
@@ -13,6 +13,7 @@ class Document {
#include "utils/corestrings.h"
#include "render/html_internal.h"
#include "utils/libdom.h"
+#include "utils/utils.h"
%};
}
@@ -37,6 +38,27 @@ method Document::write()
return 0;
%}
+method Document::writeln()
+%{
+ const char nl[] = "\n";
+ struct html_content *htmlc;
+ duk_size_t text_len;
+ for (int i = 0; i < duk_get_top(ctx); ++i)
+ duk_safe_to_string(ctx, i);
+ duk_concat(ctx, duk_get_top(ctx));
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+ LOG("Writeln %*s", (int)text_len, text);
+ dom_exception err;
+ err = dom_node_get_user_data(priv->parent.node,
+ corestring_dom___ns_key_html_content_data,
+ &htmlc);
+ if (err == DOM_NO_ERR && htmlc->parser != NULL) {
+ dom_hubbub_parser_insert_chunk(htmlc->parser, (uint8_t *)text, text_len);
+ dom_hubbub_parser_insert_chunk(htmlc->parser, (uint8_t *)nl, SLEN(nl));
+ }
+ return 0;
+%}
+
method Document::createTextNode()
%{
dom_node *newnode;
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth
8 years
href targets and Javascript functions
by Dave Higton
I was just looking around some simple Javascript examples, and I
saw some more basic stuff that isn't there yet.
There were two lines with links calling Javascript functions that
had been defined:
<a href="javascript:confirmLeave('jsindex.htm')">Link text</a>
<a href="javascript:calcVAT()">Link text</a>
Clicking the first line's link text changes the window to a 404
complaining that "jsindex.htm" (prepended with the full local path,
of course) is missing.
Clicking the second line's link text opens a "Warning from NetSurf"
box with "BadType", which presumably starts off as the same wrong
action but fails differently because the "file name" is null.
This means that no Javascript function or command can be called
from an HTML href link.
I searched for "href" in the source code, hoping to find where
its arguments are parsed, but there are many references.
So can anyone give me any quick start on this:
1) Am I trying to jump to functionality that is much to far away
to be implemented now?
2) If it is within reach, where should I be looking for code that
should be parsing for link targets that begin with "javascript:"?
Dave
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth
8 years
Patch to correct Javascript date() result
by Dave Higton
This patch removes the 3600 second error in the date/time returned by
the Javascript date() function in RISC OS.
The error is in duktape.c and, as discussed on Monday, I don't think
the code can ever be right - but I've made the deliberate error apply
only to platforms other than RISC OS.
There may be a better solution than this, which I'd like to research,
but this fixes the problem today.
Dave
diff --git a/javascript/duktape/duktape.c b/javascript/duktape/duktape.c
index 5ee88ad..9cd1b10 100644
--- a/javascript/duktape/duktape.c
+++ b/javascript/duktape/duktape.c
@@ -27893,7 +27893,9 @@ DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_gmtime(duk_double_t d) {
goto error;
}
if (tms[1].tm_isdst > 0) {
+#if !defined(riscos)
t2 += 3600;
+#endif
} else if (tms[1].tm_isdst < 0) {
DUK_D(DUK_DPRINT("tm_isdst is negative: %d", (int) tms[1].tm_isdst));
}
____________________________________________________________
Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.
Check it out at http://mysecurelogon.com/manager
8 years
Patch to make Javascript writeln() work
by Dave Higton
This patch to Document/bnd makes the Javascript writeln() function
work as well as write().
diff --git a/javascript/duktape/Document.bnd b/javascript/duktape/Document.bnd
index 6d11ea9..ee5d7af 100644
--- a/javascript/duktape/Document.bnd
+++ b/javascript/duktape/Document.bnd
@@ -37,6 +37,27 @@ method Document::write()
return 0;
%}
+method Document::writeln()
+%{
+ const char br[] = "<br>";
+ struct html_content *htmlc;
+ duk_size_t text_len;
+ for (int i = 0; i < duk_get_top(ctx); ++i)
+ duk_safe_to_string(ctx, i);
+ duk_concat(ctx, duk_get_top(ctx));
+ const char *text = duk_safe_to_lstring(ctx, 0, &text_len);
+ LOG("Writeln %*s", (int)text_len, text);
+ dom_exception err;
+ err = dom_node_get_user_data(priv->parent.node,
+ corestring_dom___ns_key_html_content_data,
+ &htmlc);
+ if (err == DOM_NO_ERR && htmlc->parser != NULL) {
+ dom_hubbub_parser_insert_chunk(htmlc->parser, (uint8_t *)text, text_len);
+ dom_hubbub_parser_insert_chunk(htmlc->parser, (uint8_t *)br, strlen(br));
+ }
+ return 0;
+%}
+
method Document::createTextNode()
%{
dom_node *newnode;
Hope this helps.
Dave
____________________________________________________________
Share photos & screenshots in seconds...
TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if1
Works in all emails, instant messengers, blogs, forums and social networks.
8 years
Javascript date function
by Dave Higton
I don't know whether this is relevant at this stage.
I've been putting together a few noddy Javascript examples. I noticed
tonight that the date function shows the time zone as being +02:00 and
shows the time as being 2 hours later than UTC. I'm wondering if it
is adding DST to a time that already has DST. My Iyonix is completely
set up for the UK. AFAIK it's the settings you'd expect anyone in the
UK to have.
NS #2953.
Dave
____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!
8 years
Building for RISC OS
by Dave Higton
All of us on the NS users ML were reminded recently that there is no
maintainer of the RISC OS port of NS.
I have looked a couple of times at the docs for building the various
ports of NS, but, unless I've missed something, there don't seem to
be any instructions for building for RISC OS.
I understand that it's a cross compilation on a Linux machine (or a
very long wait for every build!). I really have very little idea
what I have to install on my Ubuntu box to build NS, nor what to do
when I have the build tools.
So, have I missed something?
If not, I would suggest that putting the relevant docs up is a vital
step towards getting a RISC OS maintainer.
Dave
____________________________________________________________
Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.
Check it out at http://mysecurelogon.com/manager
8 years