Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace jQuery.timeago #3123

Merged
merged 4 commits into from Sep 20, 2016
Merged

Replace jQuery.timeago #3123

merged 4 commits into from Sep 20, 2016

Conversation

shaneog
Copy link
Contributor

@shaneog shaneog commented Sep 2, 2016

Replace the heavy jQuery.timeago plugin with a smaller library.

  • remove jQuery.timeago
  • add timeago.js
  • update with new translations (PR open on source library)
  • use timeago.js build with all locales included - waiting on this issue
  • set JS locale based on Rails locale

The list of included locales can be found here.

@shaneog shaneog mentioned this pull request Sep 2, 2016
3 tasks
@mperham
Copy link
Collaborator

mperham commented Sep 2, 2016

I had assumed the JS locale is provided by the browser on the client-side?

@hustcc
Copy link

hustcc commented Sep 5, 2016

Use register to load new locales, then you can use the locales translation~

How many locales do you want to supported, may be I can help?

@shaneog
Copy link
Contributor Author

shaneog commented Sep 5, 2016

@mperham I could use the navigator.language API but I figured that it would be better to align fully with Rails/web app.

@mperham
Copy link
Collaborator

mperham commented Sep 6, 2016

Good call. Being consistent is more important than being right.

@@ -29,5 +28,10 @@
</div>
<%= erb :_footer %>
<%= erb :_poll_js %>
<script type="text/javascript">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use inline scripts, this'd make enforcing Content Security Policies a lot more difficult.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any suggestions as to how I can pass the value to JavaScript without using an inline script?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why adding this exact code to the application.js (or equivalent) doesn't work?

Copy link
Contributor Author

@shaneog shaneog Sep 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pass a variable from Rails to the JavaScript app to load the correct locale (<%= locale %>).
I don't see how we can have the JS app use the same locale as Rails without passing this through.

Previously this was done by loading a specific file by name, but the idea of this PR is to reduce the overhead of multiple JS files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it's worth noting that _poll_js already uses inline JavaScript.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just add a data attribute to the body element and get the locale from that?

e.g. <body class="admin" data-locale="<%= locale %>"> and then

var locale = $('body').data('locale');
window.addEventListener('load', function() {
  timeago().setLocale(locale);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect - I'll do that, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone wants to send a PR changing the poll_js logic in the same manner, I'd love it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I open an issue to make sure it doesn't get forgotten in the mean time? :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, that's what it's there for!

This library is ~2KB, has no dependencies and includes several built-in locales.
It also updates the timestamp on the page in realtime.
The localepassed by Rails/browser "Accept-Language" header needs to be
manipulated before being used by timeago.js
@shaneog
Copy link
Contributor Author

shaneog commented Sep 20, 2016

OK, this PR is ready for review now. Sorry it took so long!

@mperham mperham merged commit 9950655 into sidekiq:master Sep 20, 2016
@mperham
Copy link
Collaborator

mperham commented Sep 20, 2016

I don't like the "live update" at all. Can we turn it off? It will lead to bug reports: "Next retry: 10 seconds ago".

@mperham
Copy link
Collaborator

mperham commented Sep 20, 2016

hustcc/timeago.js#73

@shaneog
Copy link
Contributor Author

shaneog commented Sep 20, 2016

Absolutely. PR incoming

On Sep 20, 2016 14:19, "Mike Perham" notifications@github.com wrote:

I don't like the "live update" at all. Can we turn it off? It will lead to
bug reports: "Next retry: 10 seconds ago".


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#3123 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAH9b3uksRAZBAhNR7Z9JN9p94WKehyGks5qsBWigaJpZM4J0J6I
.

mperham added a commit that referenced this pull request Sep 20, 2016
@mperham
Copy link
Collaborator

mperham commented Sep 20, 2016

Just did it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants