Search code examples
jqueryjquery-mobiletimeago

using timeago with jquery mobile


Anyone try this yet? I am having a tough time getting it to work.

I tried initializing it in the head of my template using both(one or the other) the following:

<script>
$('div:jqmData(role="page")').live('pagebeforeshow',function(){
   jQuery("abbr.timeago").timeago();
});
</script>

<script>
jQuery(document).ready(function() {
  jQuery("abbr.timeago").timeago();
});
</script>

Then in the content section, I try implementing it with :

<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>

Just as the timeago documentation suggests.

Though I only see July 17, 2008 and no dynamic time changes.

Anyone know how to do this?


Solution

  • It works, as you can see in this example: http://jsfiddle.net/Gajotres/KXHBj/

    HTML :

    <!DOCTYPE html>
    <html>
    <head>
        <title>jQM Complex Demo</title>
        <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0"/>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
        <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>    
    </head>
    <body>
        <div data-role="page" id="index">
            <div data-theme="a" data-role="header">
                <h3>
                    First Page
                </h3>
                <a href="#second" class="ui-btn-right">Next</a>
            </div>
    
            <div data-role="content">
                <abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
            </div>
    
            <div data-theme="a" data-role="footer" data-position="fixed">
    
            </div>
        </div>  
    </body>
    </html>   
    

    JS :

    $(document).on('pagebeforeshow', '#index', function(){       
        $(".timeago").timeago();
    });