[Bese-devel] Help injecting literal javascript code into parenscript code

Anthony Fairchild fairchild.anthony at gmail.com
Fri Mar 30 23:34:44 UTC 2007


Hello, I have a parenscript question, not really relating to UCW.  What I
want to do is include some literal javascript into a block of parenscript
code.  The goal is to keep this deliverable to a single html file, so
including a .js file isnt really an option.  Here's an example of what I
want to do, using a fictional JS:LITERAL-JS function to inject the
javascript.

(js:js-script

   (js:literal-js "function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf(\"Mac\") != -1 &&
        typeof document.body.leftMargin != \"undefined\") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}")

   (defun my-fun1 ()
     ;; ...
     )

   (defun my-fun2 ()
     ;; ...
     ))

I could always convert the javascript code to parenscript code, but that
could be time consuming and I'm lazy in my old age.  I dont know enough
about extending parenscript to figure this out.  There must be an easy way
to do this, any ideas?

Thanks in advance,

Anthony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/bese-devel/attachments/20070330/3d32e256/attachment.html>


More information about the bese-devel mailing list