Code Monkey home page Code Monkey logo

livestampjs's People

Contributors

brunowinck avatar dandv avatar fabslab avatar mattbradley avatar robertmain avatar sidfarkus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

livestampjs's Issues

List of livestamps contains duplicates

Element is added to the $livestamps variable twice when I initialize livestamp twice

Code to reproduce the problem:
$('#birth').livestamp(new Date('June 18, 1987'));
$('#birth').livestamp(new Date('Febuary 18, 1987')); //change the date

$livestamps variable now contains the #birth element twice

moment locale

it would be great if we can set locale inside livestamp.

destroy doesn't remove the element causing memory leak

Memory is not freed when I call the destroy function

Root cause is this line:
$livestamps = $livestamps.not($el);

basically, with .not(), the element isn't removed from the array. $livestamps still holds a reference to the element.

Code to reproduce the problem:
$('#birth').livestamp(new Date('June 18, 1987'));
$('#birth').livestamp('destroy');
$('#birth').livestamp(new Date('June 18, 1987'));
$('#birth').livestamp('destroy');
$('#birth').livestamp(new Date('June 18, 1987'));
$('#birth').livestamp('destroy');

You will notice that value of $livestamps.selector becomes longer and longer
.not().not().not([object Object])
.not().not().not([object Object]).not().not([object Object])
.not().not().not([object Object]).not().not([object Object]).not().not([object Object])

Memory leak caused by repeated application of jQuery's not function

The offending code can be found here:

https://github.com/mattbradley/livestampjs/blob/1.1.2/livestamp.js#L62

Calling livestampGlobal.update() repeatedly causes unbounded growth of the $livestamps jQuery object. This happens because jQuery retains a reference to the previous selection in the return value of not.

A hacky workaround might be something like this:

$livestamps = $livestamps.not(toRemove);
delete $livestamps.prevObject;

I found this bug by investigating a memory leak in http://jabbr.net that causes the tab running JabbR to consume gigabytes of memory after running for days/weeks. This issue seems to be the primary cause.

Using moment.js calendar function to display time

Hi !
I found this plugin because I wanted to display time as in moment calendar function. For example : Today at 15:00. I was using timeago.js but it's only displaying "in 15 hours".
So as this plugin is based on moment.js I want to knox if there is a way to use calendar function to display the time.

Thanks !

Livestamp on Chrome

Hello,
I recently tried to implement Livestamp on my site (the simplest task) and it didn't appear to work when testing it. After debugging it and using different browsers I noticed it worked on Safari and not Chrome.
Chrome:
screen shot 2014-04-19 at 10 57 53 am
Safari:
screen shot 2014-04-19 at 10 56 18 am

I thought this was weird because your github.io site worked fine with it. I also was able to have someone replicate the same result. Am I doing something wrong? Thanks,
Julien.

Issue with "on change"

Everything works as it should until I implement the listener.

$('#Timestamp').on('change.livestamp', function(event, from, to) {
            event.preventDefault(); // Stop the text from changing automatically
            console.log(from,to);
            if(to.indexOf("ago")){
                $(this).removeClass("label-success label-warning").addClass("label-danger").html(to);
            } else {
                $(this).html(to);
            }
        }).livestamp();

It goes from saying 3 hours ago to saying a few seconds ago on load. Like it's just using the current time instead of the data attribute time provided.

Time ago is off for me?

I am working with this
date: 2015-12-23 01:30:23.
seconds: 1450834223

Using Carbon in php I get 1 month ago
<? $user->created_at->diffForHumans() ?>

Using livestamp I get 2 months ago
<span data-livestamp="1450834223"></span>

I may be doing something worng. I made this test and it all came out ass backwards.
Codepen

long waiting time

Hello,
I parse every 5 seconds an li via

setInterval(function () {
    $.get('lib/includes/ayax_load_notifications.php', function( data ) {
        $('.notification_list').html(data);
    });
}, 5000)

but the string "5 minutes ago" loads 3-4secs later than the li :(

Any solutions?

Annoying moment.js deprecation warning

The moment library is moving away from accepting constructors of the form moment(timestamp). A time format must be passed. There are three lines of code that use the old syntax:

https://github.com/mattbradley/livestampjs/blob/master/livestamp.js#L27
https://github.com/mattbradley/livestampjs/blob/master/livestamp.js#L30
https://github.com/mattbradley/livestampjs/blob/master/livestamp.js#L94

timestamp is a string at that point in code, e.g. Tue Aug 05 2014 15:50:37 GMT-0700 (Pacific Daylight Time)", which seems brittle. Could it be the UNIX timetamp in seconds instead, or a Date object?

unit tests

I may write some unit tests. Does anyone prefer a particular framework? I'm thinking QUnit makes sense here.

Suggestion: Relative until x time

I would set the livestamp relative format until to 2 days ago, but i don't know how make it with momentjs or livestamp setting.
Anyone have idea?

Formatting timestamp

Thanks for this great plugin. Is there a way to change how a timestamp is formatted? I'd like to display "10h ago" instead of "10 hours ago" as an example, if possible. Perhaps the docs can be updated. Thanks a lot.

change the output text

how can one change the outputted text?
For instance, instead of "3 minutes ago", be "3m ago", or just "3m"?...

bower.json becomes .bower.json after installing.

Hey!

I use karma-bower package which tries to retrieve bower_components/livestampjs/bower.json, but there is bower_components/livestampjs/.bower.json. A dot is prepending to bower.json after installation, so I have .bower.json, so karma-bower can't find this file.

What's happened?

No livestamp when used together with Angular?

I've the following HTML:

<span data-livestamp="{{summaryItem.created}}"></span>

Created is a number in seconds, e.g. '1412451961'. However, the resulting span is just empty?

If I put this hardcoded in the template:

<span data-livestamp="1412451961"></span>

It works...
Not sure why this is not working?

data-livestamp attribute can't be written to by Knockout JS

Here's the issue I submitted to the Knockout repository:

knockout/knockout#697

Basically, Knockout uses a data-bind attribute but looks for it using a regex that finds all attributes beginning with data-. This causes a conflict when trying to have knockout generate a data-livestamp attribute on an element.

I worked around it by creating what's known as a custom binding that has access to the raw element and can apply the attributes and livestamp() directly.

This might be a good reason to allow a attribute name option in to be specified when calling livestamp to avoid conflicts.

Be smart about timestamps provided in milliseconds vs seconds

Currently Livestamp only accepts timestamps in seconds, even though the native JS Date object provides Unix timestamps in milliseconds. I don't think it would be too difficult to accept both seconds or milliseconds in the data-livestamp attribute and dynamically determine the unit based on how high the number is. No one is making Livestamps for dates thousands of years in the future, so those big numbers can obviously be assumed to be in milliseconds instead of seconds.

Add customizable interval

Once a minute is a sensible default, but I'd like it to be customizable as well—so we could update every five seconds on more "time-sensitive" data, for example.

Support for Zepto.js

Hi!

I've been playing with the library and it's really simple and something I was planning to make before!

As I'm developing for mobile (iPhone/Android), the cost of including jQuery is prohibitive, so instead I'm using Zepto.js, so I would like to ask just support for it! Shouldn't really be that difficult ;)

http://zeptojs.com/

Thank you!
Gunther

Set the "From" date to compare with (instead of the current time)

Sorry if I'm not saying this right, but it would fix the problem when the client's time is set differently than the server time. Let's say it's 10am, and I change my computer's clock time to 8am. Something I have done a few seconds ago will display as "In two hours".

I checked moment.js quickly, and apparently the solution would be to set moment.max or moment.min (the doc is a bit confusing).

http://momentjs.com/docs/#/manipulating/max/

Add [title] attribute to elements with datetime

It'd be helpful to add a title attribute to the elements that you are being updated based on the data-livestamp attribute. The idea is that then a user can hover over the span and see the real datetime value rather than just the time-ago feature.

I don't see potential harm this should cause any existing users, but possibly have it as an option that needs to be enabled.

Since I'm using backbone, it was easy enough for me to add an event binding prior to the new elements with the data-livestamp being injected, so I could do something like this:

$('[data-livestamp]').one('change.livestamp', function () {
  $(this).attr('title', $(this).data('data-livestamp')...);
});

But I think it'd be a useful addition to the library.

CDN

Probably will help gain some popularity and also be useful if you added this.

http://cdnjs.com/

showing time in futur (Bug)

Hello,

I just downloaded the plugin and it works fine. However, getting the time from my server and showing it using gives me the time as (in an hour). while it is in the past.

how can I fix that please ?

Thank you in advance.

Setting data-livestamp to null should remove it?

Hi,

This is an enhancement that may have other uses in other libraries.

We are currently using timestamp with Backbone.Modelbinder, and it's working better than expected with a converter we have written. It looks something like this:

livestamp = function (direction, value, attribute, model) {
        var field = $(this.boundEls[0]).attr('data-model-field');
        var modelField = model.get(field);
        if(modelField && typeof modelField.toISOString === 'function'){
            return modelField.toISOString();
        } else {
            $(this.boundEls[0]).livestamp('destroy');
        }
    };

It would be nice if livestamp could destroy itself if the data-livestamp attribute was set to null or something similar. Instead of having $(this.boundEls[0]).livestamp('destroy');.

Multi Lingual version

Hi Sir,

Can you help me on how to convert this into Multi lingual languages

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.