x First time here? Check out the FAQ
  • Avatar10posts30karma

    Cufon+Ajax

    FONQI started this topic More than a year ago , this topic was edited at: Saturday, March 19, 2011 1:32 AM

    Hi guys

    Well, not excatly an umbraco question, but the solution i'm making it in is umbraco, and i can't seem to find out what causeing the error.
    Let's get into it.

    I have a simple ajax script there loads in childnodes of a page, the childnodes have got a cufon header, issue is i can't get the cufon to "refresh" after the content is loaded into the div - well it works in ie, but ff, chrome & opera don't register the refesh, iv'e googled everything about this issue but haven't found anything i can use.

    My Ajax

     

    <script type="text/javascript">

    function geturl(myurl, containerdiv)
    {
    $.ajax({
    type: "GET",
    url: myurl,
    success: function(html)
    {
    $("#"+containerdiv).html("");
    $("#"+containerdiv).html(html);
    }
    });

    }

    </script>

    I've tried following solutions but none of the work

    $("#"+containerdiv).load(myurl, function() {
    if (typeof (Cufon) != "undefined" && Cufon != null) {
    Cufon.replace('em', { fontFamily: 'NeoSansLight' });
    }

    });

    $("#"+containerdiv).load(myurl, Cufon.refresh);

    $("#"+containerdiv).load(myurl, function() {
    Cufon.refresh('em');
    });

    Hope somebody can help me find an solution for this.


  • Replies

  • Avatar548posts275karma
    Comment with ID: 22906
    Thomas Kahn posted this reply More than a year ago

    Hi!

    I think there might be a problem with the order of things. If the Cufon font replacement is run after the AJAX load it won't work. I usually solve these problems using a callback on the AJAX load that is triggered via a callback function after the new AJAX content has been loaded. But I can see you have already tried this.

    Is the function where you load the AJAX content (geturl) inside or outside the document ready scriptblock? If it's outside it's probably run after the Cufon replacements. Difficult to tell what is happening just by looking at the code snippets.

    If you have FireBug installed, try inserting some console.log statements in the different functions to see when they are triggered.

    Regards,
    Thomas Kahn


  • Avatar190posts189karma
    Comment with ID: 22918
    Stephan Kvart posted this reply More than a year ago

    I've had problems with this as well in the past, I've solved it exactly as Thomas has, by using a callback function, than calls Cufon.replace() on the elements that are refreshed. Be careful though, calling Cufon.replace() on items that are already replaced can cause some funkyness, so make sure to only update those elements that are affected by your ajax call.


  • Avatar628posts827karma
    Comment with ID: 22921
    Dan posted this reply More than a year ago

    If you're using jQuery (it looks like you are) you might also want to check out liveQuery.  It can be used to bind jQuery methods to elements generated through AJAX calls.


  • FONQI posted this reply More than a year ago

    Thank you for your response everybody, i'll try inserting some console.log, and also checking out the liveQuery.


  • FONQI posted this reply More than a year ago

    Oh and if anybody would get the crasy thought of looking further into it the problem can be viewed here

    bonesupport.fserver.dk/.../management.aspx

    Any help is appreciated :)


  • FONQI posted this reply More than a year ago

    I'm on the top of the world :)

    After trying everything there is to try with cufon, ajax & jquery i finnaly found the solution. If anybody get's this problem in the future i fixed it by

            $("#"+containerdiv).load(myurl, function() {
                Cufon.replace('.who', { fontFamily: 'NeoSansLight' });
            });

    in umbraco i load childnodes into the topnode so in the childnode template i need to acivate cufón when the childnode is loaded.

    simply add this to the bottom of your page/html being loaded into your div

             <script type="text/javascript">Cufon.now(); </script>  

  • Q8Dev posted this reply More than a year ago

    my solutions

    first go to  Cufon

    second :  in <head> add for example for Museo font:

     <!-- Custom Font Museo -->
        <script type="text/javascript" src="scripts/jquery-1.4.2.js"></script>  
        
        <script type="text/javascript" src="/scripts/cufon-yui.js"></script>
       
        <script type="text/javascript" src="/scripts/Museo_500_400.font.js"></script>
                <script type="text/javascript">
                  Cufon.replace('#slogen p,#main h2,#main h4,#main_navigation a,#sub_navigation a,#main_navigation .selected,#sub_navigation .selected', { fontFamily: 'Museo 500' });
       
                </script>
        <!-- Custom Font Museo -->

    and before closing BODY TAG </body> add that line :

    <script type="text/javascript"> Cufon.now(); </script>

    i hope it will work for you

     

    Regards


Please login or Sign up To post replies