Hi,

I’ve the following code inside a node.tpl.php. I have access to the variable my_height, but not the function my_readmore when HeadJS is enabled. What's going wrong? I can see the the code of my function wrapped inside the head.ready() function. Maybe I did it wrong.

        drupal_add_js("
        my_height = jQuery('#safe_value').height();
        jQuery('#safe_value').hide();
        jQuery('#safe_summary').show();
        function my_readmore() {
          jQuery('#readmore_block').animate({height:my_height+'px'});
          jQuery('#safe_value').fadeIn(); 
          jQuery('#safe_summary').css('position','absolute').fadeOut()
        };", 'inline');

Comments

alexweber’s picture

Status: Active » Postponed (maintainer needs more info)

When you say you have access to the variable my_height but not the function my_readmore, where and how are you trying to access them?

Wolfgang Reszel’s picture

It's a onclick handler where I call the function.

I solved this problem by moving the function to the js file of the template. But I don't understand why.

alexweber’s picture

I can't say for sure that this was the cause of your problem, but something that causes a lot of headaches is variable and function scope and how it is affected by being called inside head.ready() as opposed to just being normally in the global namespace. I would imagine that to keep the variables global (their expected scope) it should be enough to simply ommit certain "var" declarations.

I still have to test this more to be sure but it might be something to work around and provide more detailed information in the documentation.