Re: [mnemosyne-proj-users] Minimal example on how to use javascript in a flash card?

110 views
Skip to first unread message

Peter Bienstman

unread,
Oct 19, 2012, 1:35:20 PM10/19/12
to mnemosyne-...@googlegroups.com
It will probably work on Linux, but not Windows. Due to some Qt bugs,
many event handlers don't fire... Hopefully a next version of Qt fixes
this.

Peter

Quoting iBayer <mane...@googlemail.com>:

> Hey,
>
> the title says it all.
> I just tried to copy & paste code
> into the card editor but that didn't seem to work.
>
> Thanks,
> Immanuel
> ----
>
> <script>
>
> function displayDate()
>
> {
>
> document.getElementById("demo").innerHTML=Date();
>
> }
>
> </script>
>
>
>
> <h1>My First JavaScript</h1>
>
> <p id="demo">This is a paragraph.</p>
>
>
> <button type="button" onclick="displayDate()">Display Date</button>
>
> ---
>
> --
> You received this message because you are subscribed to the Google
> Groups "mnemosyne-proj-users" group.
> To post to this group, send email to mnemosyne-...@googlegroups.com.
> To unsubscribe from this group, send email to
> mnemosyne-proj-u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mnemosyne-proj-users/-/ksegK6BxdrsJ.
> For more options, visit https://groups.google.com/groups/opt_out.



iBayer

unread,
Oct 19, 2012, 2:39:43 PM10/19/12
to mnemosyne-...@googlegroups.com
I'm on a Ubuntu 12.04 machine so it should work?
I'm looking for an example that is been conformed to work so that I can
check if the error is on my side.

thanks
Immanuel
> mnemosyne-proj-users+unsub...@googlegroups.com.

Peter Bienstman

unread,
Oct 19, 2012, 2:53:26 PM10/19/12
to mnemosyne-...@googlegroups.com
The only JS I used is this one, to play the media files:

http://bazaar.launchpad.net/~peter-bienstman/mnemosyne-proj/trunk/view/head:/mnemosyne/mnemosyne/libmnemosyne/filters/html5_audio.py

(Note that I don't consider myself to know javascript, so I might not
be the best person to spot issues with your code...)

Peter

Quoting iBayer <mane...@googlemail.com>:

> I'm on a Ubuntu 12.04 machine so it should work?
> I'm looking for an example that is been conformed to work so that I can
> check if the error is on my side.
>
> thanks
> Immanuel
>
> Am Freitag, 19. Oktober 2012 19:35:36 UTC+2 schrieb Peter Bienstman:
>>
>> It will probably work on Linux, but not Windows. Due to some Qt bugs,
>> many event handlers don't fire... Hopefully a next version of Qt fixes
>> this.
>>
>> Peter
>>
>> Quoting iBayer <mane...@googlemail.com <javascript:>>:
>>
>> > Hey,
>> >
>> > the title says it all.
>> > I just tried to copy & paste code
>> > into the card editor but that didn't seem to work.
>> >
>> > Thanks,
>> > Immanuel
>> > ----
>> >
>> > <script>
>> >
>> > function displayDate()
>> >
>> > {
>> >
>> > document.getElementById("demo").innerHTML=Date();
>> >
>> > }
>> >
>> > </script>
>> >
>> >
>> >
>> > <h1>My First JavaScript</h1>
>> >
>> > <p id="demo">This is a paragraph.</p>
>> >
>> >
>> > <button type="button" onclick="displayDate()">Display Date</button>
>> >
>> > ---
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "mnemosyne-proj-users" group.
>> > To post to this group, send email to
>> mnemosyne-...@googlegroups.com<javascript:>.
>>
>> > To unsubscribe from this group, send email to
>> > mnemosyne-proj-u...@googlegroups.com <javascript:>.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/mnemosyne-proj-users/-/ksegK6BxdrsJ.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "mnemosyne-proj-users" group.
> To post to this group, send email to mnemosyne-...@googlegroups.com.
> To unsubscribe from this group, send email to
> mnemosyne-proj-u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mnemosyne-proj-users/-/jMovseme09kJ.

Gnome

unread,
Oct 19, 2012, 2:56:04 PM10/19/12
to mnemosyne-...@googlegroups.com
Your scripts works on windows if you remove all new lines between <script></script> in your script:
On windows some javascripts events don't work however at the moment.

<script>function displayDate(){document.getElementById("demo").innerHTML=Date();}</script>

<h1>My First JavaScript</h1>

<p id="demo">This is a paragraph.</p>

<button type="button" onclick="displayDate()">Display Date</button>


Peter Bienstman

unread,
Oct 19, 2012, 3:02:44 PM10/19/12
to mnemosyne-...@googlegroups.com

Quoting Gnome <jippi...@hotmail.com>:

> Your scripts works on windows if you remove all new lines between <script>
> </script> in your script:

Ah, that's the bug you just reported and I need to fix :-)

Peter


iBayer

unread,
Oct 19, 2012, 3:47:35 PM10/19/12
to mnemosyne-...@googlegroups.com
Hey,

I did the following:

* click on add cards
* paste this code
---

<script>function displayDate(){document.getElementById("demo").innerHTML=Date();}</script>

<h1>My First JavaScript</h1>

<p id="demo">This is a paragraph.</p>

<button type="button" onclick="displayDate()">Display Date</button>

----

into the front field
* click on preview

all I see is this:
-----

<script>function displayDate(){document.getElementById("demo").innerHTML=Date();}</script> <h1>My First JavaScript</h1> <p id="demo">This is a paragraph.</p> <button type="button" onclick="displayDate()">Display Date</button>
----

Immanuel


Gnome

unread,
Oct 19, 2012, 3:50:56 PM10/19/12
to mnemosyne-...@googlegroups.com
Yep :)

This may be antorher QT issue, but I have encounter another small problem when working with javascript in mnemosyne:
If I import a script from a file into the code like this
<SCRIPT LANGUAGE="JavaScript" SRC="javaSciptFile.js"></SCRIPT>
After previewing the card, I may want to make some changes to that code in "javaSciptFile.js" and preview it again. However mnemosyne caches the script so that I need to restart mnemosyne for new changes to occur.

Peter Bienstman

unread,
Oct 20, 2012, 2:02:30 AM10/20/12
to mnemosyne-...@googlegroups.com
I guess Qt caches the external scripts for performance reasons...

Peter

Peter Bienstman

unread,
Oct 20, 2012, 2:09:09 AM10/20/12
to mnemosyne-...@googlegroups.com
I tried pasting your code, but it works for me, I'm afraid.. (Ubuntu
12.04 as well).

Peter
> --
> You received this message because you are subscribed to the Google
> Groups "mnemosyne-proj-users" group.
> To post to this group, send email to mnemosyne-...@googlegroups.com.
> To unsubscribe from this group, send email to
> mnemosyne-proj-u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mnemosyne-proj-users/-/0ol4_dltDKEJ.
Reply all
Reply to author
Forward
0 new messages