html javascript not working in TW?

196 views
Skip to first unread message

tejjyid

unread,
Jun 30, 2012, 5:34:34 AM6/30/12
to tiddl...@googlegroups.com
I have a couple of functions in the head of an html page, which work fine when called from a script elsewhere on that page. I wanted to implement the same functionality in TW, so I copied the JS which defines the functions to a sysConfig-tagged tiddler, then tried using the functions in another tiddler. This fails with "string.match() is not a function".

This is all extremely new to me, so apologies if this is something blindingly obvious. I will keep nutting away at it, but maybe someone can save me some time? It's a (the jspos2) POS tagger, in case you're interested.

Thanks

PMario

unread,
Jun 30, 2012, 9:58:42 AM6/30/12
to TiddlyWiki
TiddlyWiki is more like an application, than an HTML page.

Everything in TW is stored inside a tiddler. While tiddlers are only
stored inside the HTML file, they are not automatically handeld by the
browsers script engine. They are handled by the TW core program. So
the "handling" is a bit different.

One common html way to acitvate libraries and scripts is similar to
this:

<html>
<head>
<title>Some title text</title>
a) <link rel="stylesheet" href="../lib/externalLibrary.css">
b) <script src="../lib/externalLibrary.js"></script>
...
c)</head>
<body>

d)<script>
externalLib.doSomething = function (externalGlobalVar) {
// do some stuff here.
}
</script>

</body>
</html>

If you copy this snippet into a tiddler it will __not__ work and it
shouldn't, because it doesn't fit TWs structure.

====

In TW terms: (see markers above)

a) is done with StyleSheet tiddlers, that are activated by the TW
core.

b) are library tiddlers tagged systemConfig.

d) is a plugin call

=========
The TW way would be similar to this:

a)
Copy the content of the CSS (only if it is _really_ needed) to a
StyleSheetLibX tiddler. If it says eg: reset.css _don't_ use it. Only
use library specific css.

Call this tiddler from StyleSheet

eg: StyleSheet contains
[[StyleSheetLibX]]

b)
Copy the _content_ of the externalLibrary.js into a tiddler named
externalLibrary.js and tag it systemConfig

c) Go to tiddlytools.com and find InlineJavascriptPlugin [1] and
import it to your test TW. Be sure to read and understand
InlineJavascriptPluginInfo!
tag it systemConfig. IinlineJavascriptPlugin activates the use of
<script></script> tags inside a tiddler. This is super cool for fast
prototyping, since you can use most of externalLibraries
documentation. If you know how things work, you should create TW
plugins.

d) copy something similar to
<script>
externalLib.doSomething = function (externalGlobalVar) {
// do some stuff here.
}
</script>

into a tiddler. __don't__ tag it systemConfig


If the library documentation says something like:

<script src="bla bla">
externalLib.doSomething = function (externalGlobalVar) {
// do some stuff here.
}
</script>

_remove_ the src="bla bla" it is not needed with inline javascript
plugin, if you did step a) to c) right.

====
You can use
<script label="clickMe">
</script>

to create a button. This will make debugging easier.

For debugging you should use FireBug browser AddOn for FireFox or the
built in DevTools in Chrome and IE9+

====

If you would have added a link to your library of desire, the examples
could be more prezise but imo it will give you some hints :)

have fun!
mario

[1] http://www.tiddlytools.com/#InlineJavascriptPlugin

tejjyid

unread,
Jul 1, 2012, 11:22:52 PM7/1/12
to tiddl...@googlegroups.com
I had a feeling it might be something like that - I understand that there is a TW "handler" involved, but it's a bit hairy trying to piece it together from the extant doco. Anyway, I'll work through all this here, and update as I go.
 
Appreciate the scope of the detail in the response.
 
Thanks, Andrew

tejjyid

unread,
Jul 2, 2012, 6:30:15 PM7/2/12
to TiddlyWiki
Hi Mario - I'm working through your suggestions (intalled the
#InlineJavaScript plugin, Firebug, done some debugging) and I've got a
lot more to do, but sadly there was no "easy win". I still get the
same message.

Feel free to ignore this, but if you have the time/inclination, here's
the link to the code I'm trying to implement.

http://code.google.com/p/jspos/

The "string.match is not a function" message comes out of the Lexer.

What I've done is put the POSTagger & Lexer functions, as well as the
"database" variables,
into the systemConfig-tagged tiddler (is its name important, and if
so, in what way?). Then I'm implemeting the "body" code snippet as
inline Javascript.

Thanks, Andrew

PMario

unread,
Jul 2, 2012, 8:10:19 PM7/2/12
to TiddlyWiki
On Jul 3, 12:30 am, tejjyid <andrew.x.w...@gmail.com> wrote:
> http://code.google.com/p/jspos/
>
> The "string.match is not a function" message comes out of the Lexer.
>
> What I've done is put the POSTagger & Lexer functions, as well as the
> "database" variables,
> into the systemConfig-tagged tiddler (is its name important, and if
> so, in what way?). Then I'm implemeting the "body" code snippet as
> inline Javascript.

systemConfig tagged tiddlers are ordered by name and started in that
order by the TW core. So aa.js has higher priority than bb.js.

Did you have a look into sample.html with a text editor?
it's quite similar to my general description.

<script type="text/javascript" src="lexer.js"></script>
<script type="text/javascript" src="lexicon.js_"></script>
<script type="text/javascript" src="POSTagger.js"></script>

If you name your tiddlers Lexer.js, Lexicon.js_ and POSTagger.js they
will be started in the right order. Uppercase has higher priority than
lowercase.

I'll have a closer look but not now :)
-m

tejjyid

unread,
Jul 3, 2012, 6:18:25 AM7/3/12
to tiddl...@googlegroups.com
Thanks again. I did check the supplied snippet and was struck by the similarity - standards,eh :-)
Anyway, I've got the three tiddlers setup as you suggest - I assume the fact that the error comes from Lexer.js
means that the function has at least been found.

I'll play around with a few things, but I do appreciate your assistance. I'm an ESL teacher: my students probably feel about English
the way I feel about TW -powerful, but a bit tricky!

PMario

unread,
Jul 3, 2012, 9:24:33 AM7/3/12
to TiddlyWiki
Andrew,
Do you need this stuff with a file TiddlyWiki or as a TiddlySpace
space?

Where did you start from?

http://tiddlywiki.com or
http://tiddlyspace.com

On 3 Jul., 12:18, tejjyid <andrew.x.w...@gmail.com> wrote:
> Thanks again. I did check the supplied snippet and was struck by the
> similarity - standards,eh :-)
q:-)

> I'm an ESL teacher: my students probably feel about English
> the way I feel about TW -powerful, but a bit tricky!
ESL?
It seems TW is quite attractive for any type of teaching ...

-m

tejjyid

unread,
Jul 3, 2012, 11:21:57 PM7/3/12
to tiddl...@googlegroups.com
It's hard to choose; I've been developing a space (for which I've written some simple macros) but this I thought I'd develop this in a file (in case it went pear-shaped).

I guess that a Space is not strictly speaking required, unless I get my staffroom involved in a collaborative project. The flexibility of TW makes it perfect for teachers, sort of. Although with freedom comes responsibility...

Andrew

PMario

unread,
Jul 4, 2012, 3:59:19 AM7/4/12
to TiddlyWiki
I got it working yesterday. You are right, there is a problem with the
lexer.js and the TW core program. So it didn't work out of the box. I
try to get in contact with the original author now, about the patches,
I did.

I didn't make a test (yet), if the modified library has the same
results, as the unmodified. So it's not sure, if it does work at all.
But there is no error message any more :)

TiddlySpace is much easier to handle and distribute (at least for me)
than a file TW. That's why the question.

There are some other questions left:
Do you plan to use it, or did you just want to "play" with the library
and see what's possible? As I wrote, I got it working without this
nasty error message you encountered. But the whole stuff imo isn't
usefull in a TiddlyWiki context. IOM there will be some work to do, to
make it usefull. see [a]

I also found some info about ESL teachers [1]. Is this, what you do?

[a]
So if ESL stands for "English as a second language", and me as an ELL
"English Language Learner", I'd find it diffucult to work with such
stuff, since the tagger uses MLA's (Multi letter acronyms) to discribe
a tagged sentence. I as a user, would want to have some more
description about: /DT /VBZ /NN.... on mouse over.

Does this make sense?

regards
mario

[1] http://www.wisegeek.com/what-does-an-esl-teacher-do.htm

tejjyid

unread,
Jul 4, 2012, 4:25:35 AM7/4/12
to tiddl...@googlegroups.com
Hi Mario - with the amount of help you are providing, you can work anywhere you like. I reckon I 
can 'port' anything you do in Tiddlyspace back to Tiddlywiki file if necessary.

I'll certainly be playing around with it a LOT before using it as a teaching aid. You are absolutely right, all those MLAs would kill
most students (my most high level student today admitted he doesn't really understand the difference between a noun and a verb - 
a big lesson for me to learn! - And in fact he is right, the distinction is not 100% simple).

Initially I think I will use it to color-code certain classes of words; for example, all finite verbs vs all non-finite verbs, an important distinction. Or perhaps,
all determiners in RED for the eastern Europeans (Actually I did this already, since DTs are easy to identify). I want to use authentic materials as source, but mark them up automatically to assist students with reading, or to illustrate features so students can postulate their own rules. I imagine a situation where a student can copy/paste a text they are interested in, and it turns into a kind of lesson.

I think illustration is more important than rules. (so in the case of NOUN vs VERB, I can use this tool - modded slightly - to paint the picture. Then the student can make his own rule, just like a native speaker has to)

So, anyway, it's a starting point. (mouse-over's are a good idea)

It will also help me prepare lessons - a student asked me about modal verbs, and I know they are interested in Italian art. So I can quickly identify sample sentences to illustrate a class on modals. Plus, in experimenting, ideas come.

Is there a principled reason why the code doesn't function? My next plan was to re-write in MY code, because
a.) Javascript lesson
b.) my code is so simple it wouldn't challenge a kindergarten student.

Yes, that is my job, pretty much. You might be interested that the most acceptable term these days is TESOL - Speakers of Other Languages, because let's be honest, many people already speak 2/3/4 languages before starting on English. 

I mainly teach students who are competent how to reach a standard suitable for university - newspapers, blogs, journal articles are the main texts we work with.

I'll polish my Tiddlyspace up a bit, and invite you to join it.

Thanks again for your time/interest.

Andrew

PMario

unread,
Jul 5, 2012, 5:24:16 PM7/5/12
to TiddlyWiki
Hi Andrew,
It's up for testing :)

INTRO post:
http://groups.google.com/group/tiddlywiki/browse_thread/thread/8b7705e9545ef63a

For feedback you can use the INTRO thread

have fun!
mario
Reply all
Reply to author
Forward
0 new messages