Javascript onload

A place for users and developers of the Xataface to discuss and receive support.

Javascript onload

Postby Gershy » Thu Jan 24, 2013 2:41 pm

Hey everyone. I've modified the create account action by overriding the Dataface_Create_Account.html template. I'm interested in performing some javascript actions when the page loads, however none of the typical methods of signing up for the onload event are working for me.

My javascript is simply in the head of the file, is surrounded by the {literal}{/literal} tags to protect it from smarty, and my other javascript functions are working so I'm sure it's not an error in the file. It's more likely the context that xataface has already set up for the page to be loaded in.

Can anyone possibly explain to me how to sign up for the onload event from within a xataface overriden template?

Thanks!
-Gersh
Gershy
 
Posts: 25
Joined: Wed Nov 14, 2012 12:28 pm

Re: Javascript onload

Postby shannah » Mon Jan 28, 2013 9:35 am

There are a few ways to do this. If you're using Xataface 2.0 with the G2 theme, then jQuery is included by default so you can use:
Code: Select all
jQuery(document).ready(function(){
   // put your code here
});


If you're using 1.3 or higher (including 2.0), you can use the registerXatafaceDecorator() function that is set to run on page or fragment load.

Code: Select all
registerXatafaceDecorator(function(root){
     // put your code here
});


-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Javascript onload

Postby Gershy » Tue Jan 29, 2013 9:43 am

JQuery did the trick! Thanks very much.

To anyone else reading this answer, just make sure you've linked to jquery with
Code: Select all
<script src="{$ENV.DATAFACE_URL}/js/jquery.packed.js"></script>
<script>
jQuery(document).ready(function(){
   // put your code here
});
</script>


and you should be set to use this method.
Gershy
 
Posts: 25
Joined: Wed Nov 14, 2012 12:28 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved