Skip to content

Combine "dateFunction": momentDateFormatter" and"customCallback": populateTpl #77

@saturday1

Description

@saturday1

I am trying to use the template version (Example 8) combined with moment (Example 6, I think). But then I get problems with the moment js. It does not run the function at all and it does not catch the language moment.locale('sv_SE');. The code looks like this:

    <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>

    <script type="text/javascript" src="js/twitterFetcher_min.js"></script>
<script>

moment.locale('sv_SE');

var config = {
    "id": '573452057987973120',
    "dataOnly": true,
    "maxTweets": 3,
    "dateFunction": momentDateFormatter,
    "customCallback": populateTpl
};

function momentDateFormatter(date, dateString) {
    return moment(dateString).fromNow();
}

twitterFetcher.fetch(config);

function populateTpl(tweets){
    var html = '<ul>';
    for (var i = 0, lgth = tweets.length; i < lgth ; i++) {
        var tweetObject = tweets[i];

        html += '<li>'
        + (tweetObject.image ? '<div class="tweet-img"><img src="'+tweetObject.image+'" /></div>' : '')
        + '<p class="tweet-content">' + tweetObject.tweet + '</p>'
        + '<p class="tweet-infos">Posted on the ' + tweetObject.time + ', by ' + tweetObject.author + '</p>'
        + '<p class="tweet-link"><a href="' + tweetObject.permalinkURL + '">Link</a></p>'
        + '</li>';
    }
    html += '</ul>';

    $('#twitter-feed').append(html);
}
</script>

You can see all HTML as well over here: https://cdn.axiell.com/dev/twitter/test/index.html

How do I run moment before the template function is running?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions