customhead.tpl jquery doc ready

Customhead.tpl jquery doc ready, a forum discussion on Jojo CMS. Join us for more discussions on Customhead.tpl jquery doc ready on our Themes Support forum.

Back to Forum Index : Back to Themes Support   RSS
synfield

15 Jul 2008
Posts: 43

I've got a few jquery functions in the jquery doc ready wrap in the header, which are ported from my another xhtml site template, so I put them into the jojo header via cutomhead.tpl.

However i noticed that the doc ready code is there but the rest of the functions get stripped???

Why? and how do i work around this.

Cheers
synfield

15 Jul 2008
Posts: 43

Correction, it seems to be caching an old vers of customhead.tpl, i've tried deleting the cache in admin & browser, seem to recall that I also have to do somwthing else?
synfield

15 Jul 2008
Posts: 43

Ok, I'm back to the concerns I have in my original post.

The jquery stuff is getting stripped out, i have renamed my customhead.tpl and reset it back to check if the changes are registering in the page source view.

My customhead.tpl has the following jquery code

$(document).ready(function(){

$('#s2').cycle({
fx: 'fade',
speed: 2500
});

$('.btn').each(function(){
var b = $(this);
var tt = b.text() || b.val();
if ($(':submit,:button',this)) {
//the following line is the culprit
//b = $('<a>').insertAfter(this).addClass(this.className).attr('id',this.id);
//$(this).remove();
b.replaceWith("<a style='cursor: pointer;' class='" + b.attr("class") + "' href='" + $(".btnp").attr("href") + "'><i></i><span><span></span><i></i>" + tt + "</span></a>");
}
//b.text('').css({cursor:'pointer'}). prepend('<i></i>').append($('<span>').text(tt).append('<i></i><span></span>'));
//b.text('').css({cursor:'pointer'}).prepend('<i></i><span><span></span><i></i>' + tt).append('</span>');
//format required
//<a style="cursor: pointer;" id="" class="btnp orange"><i></i><span><span></span><i></i>Apply Now</span></a>
});
});

But in source view I get;

$(document).ready(function());

$('.btn').each(function()
//b.text('').css(). prepend('<i></i>').append($('<span>').text(tt).append('<i></i><span></span>'));
//b.text('').css().prepend('<i></i><span><span></span><i></i>' + tt).append('</span>');
//format required
//<a style="cursor: pointer;" id="" class="btnp orange"><i></i><span><span></span><i></i>Apply Now</span></a>
});
});

Can someone explain?
Harvey

Core Developer

Harvey

15 Jul 2008
Posts: 327

I haven't looked into your post in too much detail, but it could be to do with escaping the braces (curly brackets).

In any Smarty template, you need to wrap {literal}{/literal} around any code that includes braces. Alternatively, you can use {ldelim} and {rdelim} instead of braces (see the Smarty manual).

Try that and let me know if that's not the issue.
synfield

16 Jul 2008
Posts: 43

Thanks Harvey. I just put the code into it's own external js file which is probably what I should've be doing anyway.

Cheers
Harvey

Core Developer

Harvey

16 Jul 2008
Posts: 327

Depends what you need to do - using customhead allows you to use dynamic Javascript code - using all the power that Smarty has available, which can be quite handy. But escaping braces is definitely a hassle.

An external js file introduces a slight overhead as it's included / executed on every page, but also means it gets cached by the browser and is nicely out of the way.
synfield

16 Jul 2008
Posts: 43

I copied my files accross form my laptop (vista premium) to my work environment (win xp).

As I have the exact same folder structure on both, however the customhead.tpl is not being included at all;

the customhead.tpl only contains

<script type="text/javascript" src="{cycle values=$NEXTASSET}external/jquery/jquery.cycle.all.js"></script>
<script type="text/javascript" src="{cycle values=$NEXTASSET}external/jquery/jquery_functions.js"></script>


As an aside what is in the variable/array $NEXTASSET ?

Have deleted cache & checked permissions but to no avail, the source code is missing the customhead.tpl file?
Harvey

Core Developer

Harvey

16 Jul 2008
Posts: 327

Probably what you will neen to do is delete the Smarty compiled templates - in mysite/cache/smarty/templates_c/ - delete everything in here.

Smarty caches compiled templates and largely does a good job of this. But sometimes when you move the files between systems, the timestamps get all mucked up and Smarty doesn't recompile the files. Anyway, delete these, it should start working again.

$NEXTASSET is a Jojo-generated variable that you can prefix to CSS / JS / Image files. It does nothing unless the assetdomains option is enabled. This option is for spreading attached files across several domains or subdomains - the theory is that browsers will only download 2 files at a time per domain - so by spreading the attached js / css / image files across 2 or 3 domains, there should be more parallel downloading of content for the user, and faster performance.

That's the theory - in practice, I haven't really noticed much difference in performance by having the option enabled, so we never really use this option. A shame, it took a while to program, and I thought myself very clever while I was doing it.
synfield

17 Jul 2008
Posts: 43

Excellent! Thanks again!
Back to Forum Index : Back to Themes Support   RSS
You must be logged in to post a reply



You need to Register or Log In before posting on these forums.