forum

Home / DeveloperSection / Forums / TimeAgo functionality using jquery.timeago plugin not working in IE & Mozilla

TimeAgo functionality using jquery.timeago plugin not working in IE & Mozilla

Anonymous User427030-Oct-2014

I am trying to add a functionality of timeago in my application by using jquery.timeago plugin. I am using knockout binding to display the list of times.

It is working fine in chrome but it is not able to display data in other browsers.

Here is my script code:

    <scriptsrc="Scripts/jquery-2.1.1.min.js"></script>
    <scriptsrc="Scripts/knockout-3.2.0.js"></script>
    <scriptsrc="Scripts/jquery.timeago.js"></script>
 
    <script>
 
        $(function () {
 
            var viewModel = {
 
                arr: [{
                    msgdate: new Date()
                }, {
                    msgdate: new Date()
                }]
            };
 
            ko.bindingHandlers.timeago = {
                update: function (element, valueAccessor) {
                    var value = ko.utils.unwrapObservable(valueAccessor());
 
                    var $this = $(element);
 
                    $this.attr('title', value);
 
                    if ($this.data('timeago')) {
                        var datetime = $.timeago.datetime($this);
                        var distance = (new Date().getTime() - datetime.getTime());
                        var inWords = $.timeago.inWords(distance);
 
                        $this.data('timeago', { 'datetime': datetime });
                        $this.text(inWords);
                    } else {
                        $this.timeago();
                    }
                }
            };
 
            ko.applyBindings(viewModel);
        });
 
    </script>

  

Html part is given below: 

<divdata-bind="foreach: arr">
        <divclass="timeago"data-bind="timeago: msgdate"></div>
</div>

 

Example is here is fiddle also:

http://jsfiddle.net/ugqkd60p/ 

Please help me to solve it.

Thanks.


Updated on 30-Oct-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By