Calling JavaScript

16 views
Skip to first unread message

490...@swansea.ac.uk

unread,
May 30, 2012, 9:21:07 AM5/30/12
to Yesod Web Framework
Hi All.

A relatively simple question for you to answer I'm sure but how do you
call a Julius script from the default Hamlet layout? I'm using a
scaffolded site (to mess around before starting my masters project).

I have some experience with web-programming but from a HTML, PHP, C#
perspective and so I'm used to embedding JavaScript directly into the
HTML and it executing on page load (or command).

Any help would be greatly appreciated.

Chris.

Clark Gaebel

unread,
May 30, 2012, 9:28:26 AM5/30/12
to yeso...@googlegroups.com
You could use jquery for this.

Michael Snoyman

unread,
May 30, 2012, 9:41:41 AM5/30/12
to yeso...@googlegroups.com
To expand, I think what you're looking for is registering a callback
for page load. You could do it in jQuery with something like:

$(function(){
alert("Page loaded");
});

geoff

unread,
May 30, 2012, 11:12:17 AM5/30/12
to yeso...@googlegroups.com
Chris, I hesitate to give my advice because I am a haskell newb.

I haven't tested this, but in theory you should just be able to create a deafult-layout.julius and that should be invoked with default-layout.hamlet

What I have done for myself is created a widget inside of Foundation.hs which I then call within my default-layout.

The type synonyms aren't "there yet" in Foundation.hs so the type signature for the widget is


myEverythingWidget :: GWidget sub App ()
myEverythingWidget = do
  addScriptRemote "/static/js/myJsLibrary.js"
  toWidget[julius|  
$(function(){ alert ("page loaded"); {);
]

Then within your default-layout.hamlet

just call your widget normally

^{myEverythingWidget}
Reply all
Reply to author
Forward
0 new messages