Page 1 of 1

Javascript onload

PostPosted: Thu Jan 24, 2013 2:41 pm
by Gershy
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

Re: Javascript onload

PostPosted: Mon Jan 28, 2013 9:35 am
by shannah
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

Re: Javascript onload

PostPosted: Tue Jan 29, 2013 9:43 am
by Gershy
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.