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

add anchor tag to URL and send house+term as query vars into download page #12987

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

davewhiteland
Copy link
Contributor

Anchor tag added for jumping to the right legislature.

Intercept clicks with a specific term to target using Javascript, so it works fine but not when we're running wget.

Closes #11911

@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-12987 July 12, 2016 17:41 Inactive
@wfdd
Copy link
Contributor

wfdd commented Jul 13, 2016

Intercept clicks with a specific term to target using Javascript, so it works fine but not when we're running wget.

wget doesn't execute JS, if wget using the parametrised URL is what you were trying to avoid. You could do this on load and not have to worry about race conditions (which you might get on old smartphones, like mine...).

@davewhiteland
Copy link
Contributor Author

Yes, the JS interception is because the only reason for passing the term+house parameters are so that JS on the subsequent page can make client-side changes: specifically if that page has many terms, it hides all but three (and makes sure the "current" term is one of those (ideally in the middle)).

And yes, we don't want wget to pick up these query variables, which is why it's being done in JS this way.

And yes I agree the JS should be moved into a document-ready section, will do.

@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-12987 July 18, 2016 10:46 Inactive
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-12987 July 19, 2016 11:04 Inactive
@davewhiteland
Copy link
Contributor Author

@tmtmtmtm @chrismytton invitation to review please (some squashing necessary afterwards perhaps, but showing my working)

})
});

$("a.download-with-term").on("click", function(e){
Copy link
Member

Choose a reason for hiding this comment

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

Such a minor thing, but not sure you need a the a in $("a.download-with-term")

Copy link
Member

Choose a reason for hiding this comment

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

Also, if this a class that’s only used to hook JS behaviour onto, it’s good practice to prepend it with js-, so that it’s more obvious what the class is for, when people are refactoring code. So that’d make the selector look like: $('.js-download-with-term').

@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-12987 July 25, 2016 11:12 Inactive
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-12987 July 25, 2016 11:22 Inactive
@zarino
Copy link
Member

zarino commented Jul 25, 2016

Looks good to me. As discussed in Slack, having a download page for each legislature probably makes most sense in the long run, for a number of reasons. I've created a new ticket for that at #13599.

But this is fine for making the existing download page a little better in the meantime.

@tmtmtmtm
Copy link
Contributor

@davewhiteland if it's good enough for Zarino, it's good enough for me :) :shipit:

I know it's not new to this PR, but I'm a little scared by that whole max_visible_terms logic. That all seems like it should be lot simpler (or at least more encapsulated somewhere). What was the story with that?

@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-12987 August 1, 2016 10:35 Inactive
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-12987 August 1, 2016 11:04 Inactive
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-12987 August 1, 2016 14:26 Inactive
Dave Whiteland added 24 commits August 8, 2016 12:36
intercept clicks on the download button that are for specific terms, and update
the href to include the house and term query variables.

I'm updating the href in place and then letting the click bubble through (that is,
not using $(e.target).preventDefault() here, which seems to work OK.
Implemented by proposing a `page_init_function` variable that `main.js` executes if it contains a function.
There "should" never be query variables in the href in the link to the download page
(because we know that causes problems for wget elsewhere) but actually when going
_back_ to an existing page (after the JS has injected them) this results in the
query vars being added _again_ which breaks them. (Safari browser does this).

So simply checking that there's no "?" in the href is the safety-check on this:
don't add query vars if the URL already has a ? in it.
even if all the terms are being displayed, so move this check out of the conditional
behaviour that hides the terms
updating the href was silly because it introduced the problem with old pages
(i.e., after back button) having JS-changed href attributes, when all we
want to do is jump to the new location.
because that's the convention in other names in this project to date
thanks @zarino for pointing this out :-)
thanks @zarino for pointing this out
(also dropped superfluous `a` selector).
needed to send a jQuery element in, not a selector which only looks at
the first element.
Thanks @tmtmtmtm for help with this!
don't need to check for non-null value of wanted_house since it
won't match house_slug if it's empty because house_slug is always
non-empty since a house always has a name.
fixed the sloppy bounds calculations, so slice can be used
since this isn't just about terms: moved core function into main.js
so it can be called from wherever it's needed (currently just
download page's terms).
This makes things a lot clearer, and the single case that's being
generalised here is such a list.
Also change button from anchor tag (since we don't need an href) to button.
Simplify click handler by attaching it directly to the button, no need to
pass target <ul> id via a data attribute.
Fix some comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants