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

✨amp-timeago: Enable datetime to be set with amp-bind #18444

Merged

Conversation

edhollinghurst
Copy link
Contributor

Attempts to fix #18441 and allow the datetime attribute used in amp-timeago to be set with amp-bind.

The example file is also updated and now includes an amp-bind example.

mutatedAttributesCallback(mutations) {
const datetime = mutations['datetime'];
if (datetime !== undefined) {
this.datetime_ = this.element.getAttribute('datetime');
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this can just be datetime cost per above, not need to read it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! I've now updated that.

@@ -44,6 +44,8 @@ tags: { # <amp-timeago>
value_regex: "\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d(:[0-5]\\d(\\.\\d+)?)?(Z|[+-][0-1][0-9]:[0-5][0-9])"
}
attrs: { name: "locale" }
# <amp-bind>
attrs: { name: "[datetime]" }
Copy link
Contributor

Choose a reason for hiding this comment

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

worth updating validator_time-ago.html and .out files as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added some new validator test files for mutations - is this OK?

Copy link
Member

Choose a reason for hiding this comment

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

That's fine.

const datetime = mutations['datetime'];
if (datetime !== undefined) {
this.datetime_ = this.element.getAttribute('datetime');
this.setFuzzyTimestampValue_();
Copy link
Contributor

Choose a reason for hiding this comment

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

should the part that sets this.element.title move to setFuzzyTimestampValue_ as well to keep the title up to date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in #18441, the title attribute value is a bit difficult to resolve. I don't think there's anything we can do in setFuzzyTimestampValue_(). The only solution I can think of is to also allow the title attribute to be mutated with AMP bind.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. sounds good to me.

@aghassemi aghassemi merged commit 8f4b2b4 into ampproject:master Sep 29, 2018
@aghassemi
Copy link
Contributor

merged. Thanks Ed.

twifkak added a commit to twifkak/amphtml that referenced this pull request Oct 1, 2018
@twifkak twifkak mentioned this pull request Oct 1, 2018
twifkak added a commit that referenced this pull request Oct 1, 2018
* cl/215004714 Revision bump for #17162

* cl/215004778 Revision bump for #18415

* cl/215004829 Revision bump for #18439

* cl/215036706 Revision bump for #18444

* cl/215235362 Revision bump for #18438
torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Oct 10, 2018
torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Oct 10, 2018
* cl/215004714 Revision bump for ampproject#17162

* cl/215004778 Revision bump for ampproject#18415

* cl/215004829 Revision bump for ampproject#18439

* cl/215036706 Revision bump for ampproject#18444

* cl/215235362 Revision bump for ampproject#18438
Enriqe pushed a commit to Enriqe/amphtml that referenced this pull request Nov 28, 2018
Enriqe pushed a commit to Enriqe/amphtml that referenced this pull request Nov 28, 2018
* cl/215004714 Revision bump for ampproject#17162

* cl/215004778 Revision bump for ampproject#18415

* cl/215004829 Revision bump for ampproject#18439

* cl/215036706 Revision bump for ampproject#18444

* cl/215235362 Revision bump for ampproject#18438
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

amp-timeago: allow bind on datetime attribute
4 participants