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

Refactoring footer-button and removing jQuery #2115

Merged
merged 1 commit into from Jul 29, 2016

Conversation

sebworks
Copy link
Contributor

@sebworks sebworks commented May 20, 2016

Refactoring footer-button and removing jQuery

Changes

  • Refactored footer-button.js to remove jQuery and use requestAnimationFrame for smooth scrolling to the top of page.

Testing

  • Visit localhost:8000 on mobile an click the Back to Top button. It should smoothly scroll you back to the top of the page.
  • Run 'gulp test:unit:scripts`

Review

Todos

  • Need to write further acceptance and unit tests.

Checklist

  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows the standards laid out in the front end playbook
  • Passes all existing automated tests
  • New functions include new tests
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged
  • Visually tested in supported browsers and devices
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)

Back to top <span class="cf-icon cf-icon-arrow-up"></span>
data-js-hook="behavior_return-to-top"
href="#">
Back to top <span clasbs="cf-icon cf-icon-arrow-up"></span>
Copy link
Member

Choose a reason for hiding this comment

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

clasbs --> class

Choose a reason for hiding this comment

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

seems legit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6d1c6ac

@jimmynotjim
Copy link
Contributor

Need to write further acceptance and unit tests.

Can you add a Jira task specifically for this file if the tests won't be added in this PR. Thanks.


$( '.js-return-to-top' ).click( function( event ) {
// Disable Google Tag Manager tracking on this link.
behaviorElement.setAttribute( 'data-gtm_ignore', 'true' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add this attribute in the markup? Seems like we're crossing some streams here.

Copy link
Member

Choose a reason for hiding this comment

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

The rationale for keeping it in the JS elsewhere is that (a) GTM lives only in JavaScript and (b) in some cases if the default link behavior is being prevented by a particular script, if that script were to be disabled/removed the links should not continue ignoring GTM. In that case it makes sense to set data-gtm_ignore where event.preventDefault() is set.

Copy link
Contributor

Choose a reason for hiding this comment

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

The default behavior of an empty anchor link is still to move the user to the top of the page. If for some reason GTM loaded but this script didn't, we should still ignore the interaction in GTM.

Copy link
Member

Choose a reason for hiding this comment

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

May mean the link should be injected with JS since it doesn't do anything if this script isn't here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The button still functions without JS. I'm still trying to figure out if GTM works without JS.

Copy link
Contributor

Choose a reason for hiding this comment

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

The link doesn't need to be injected, the jump instead of scroll fallback is perfectly fine. I'm just not convinced we should be injecting metric tracking manipulation into a script that's simply adjusting the button unless that adjustment were to fundamentally change the behavior, which this doesn't. With or without the scrolling action, we don't want this button tracked in GTM. Writing the attr to the markup separates the concerns and ensures GTM isn't tracking the button clicks if this file were to fail in some way.

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 moved the GTM code to the markup because you will never want to track the event.

@richaagarwal
Copy link
Contributor

should this be merged or closed?

@jimmynotjim
Copy link
Contributor

@sebworks if you need a second hand getting this through let me know

@sebworks sebworks force-pushed the footer_button_refactor branch 3 times, most recently from 427c696 to 6d1c6ac Compare July 28, 2016 12:30
@sebworks
Copy link
Contributor Author

@jimmynotjim, @anselmbradford please give it look when you get a chance.

@jimmynotjim
Copy link
Contributor

👍 Can someone on Platform run the tests? I'm so far back I can't get things running correctly.

@chosak
Copy link
Member

chosak commented Jul 29, 2016

Can confirm that browser tests pass for me. 👍

} );
}

/**
* @param {integer} scrollDuration
Copy link
Member

Choose a reason for hiding this comment

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

param is not in implementation.

@anselmbradford
Copy link
Member

👍

@sebworks sebworks merged commit 9582dcc into flapjack Jul 29, 2016
@sebworks sebworks deleted the footer_button_refactor branch July 29, 2016 18:17
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

7 participants