views:

87

answers:

3

Hi all -- I am working on a site using the Squarespace CMS system, and have added some simple jQuery to remove some automatically added text that comes up when filtering content (specifically "Entries in" text).

This worked smoothly without any problem until I added Google Translate script into the footer. Now the removal of the "Entries in" text is not smooth -- the "Entries in" text shows up first when the page is loaded and then gets removed, so the it feels a bit jumpy. It seems like the Google Translate script in the footer is causing the interference and I'm worried that it could interfere with any additional jQuery I might add to the site as the project progresses. I'm curious what I can do better to make sure these sorts of customizations load smoothly?

The site I'm working on (in progress) can be viewed at wohf.squarespace.com

the code I have so far is the following in the :

<script src="/storage/Scripts/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
<!--

$(function(){ 

//***************************************
// Remove "Entries In" text
//***************************************
$('.journal-filter-header h2:contains(Entries in)').each(function(){ 
   var str = $(this).html(); 
   $(this).html(str.replace('Entries in','')); 
});


});
-->
</script>

... and the following for Google Translate in the footer:

<div id="footerRight">
<div id="google_translate_element"></div>
<script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en'
  }, 'google_translate_element');
}
</script>
<script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"&gt;&lt;/script&gt;
</div>

Again, any help is greatly appreciated!!

+1  A: 

You really should try to work out how to change this in your CMS (server side). JavaScript is only intended to help you with dynamic content, not static content.

Tobias Cohen
How hard is it to invoke Google translation APIs from the server?
Pointy
I am using a hosted CMS (squarespace.com) for this website so the only way I know how to remove this "Entries in" text is by using jQuery. I also cannot run anything from the server since it is a hosted CMS and I do not have access to the server.
VUELA
A: 

You could try running your fix-up function directly in a script tag towards the end of the page, and not in a jQuery "ready" context. In other words, have your code run before the page load completes. (This may or may not completely help, of course.)

Pointy
I tried moving that bit out of the <head> and into an area post-canvas at the bottom of the page, without the ready function, but the script no longer worked.I tried running the script outside the ready function from the <head> but it didnt work either, seems to only work inside the $(function(){ }.
VUELA
A: 

Have you tried jQuery.getScript() ? You should be able to delay loading the translate script until your 'replace' is done.

http://api.jquery.com/jQuery.getScript/

patrick dw
Sounds promising! I'll have to try this. Is this a common problem? I thought it was more likely that I was just making a simple mistake -- I'm fairly new to using jquery.
VUELA
Things usually run pretty smoothly in jQuery. I don't know Google Translate, but I imagine your 'replace' and Translate were butting heads. I figured there must be a way to delay loading a script, and getScript() looked promising. Would love to hear how it pans out.
patrick dw