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

when download data is clicked on term table, highlight the term #14535

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

Conversation

davewhiteland
Copy link
Contributor

Closes #14427

This code replaces the existing JavaScript (deployed but not being used because the download button is not currently passing term (and house) as query variables) with neater code.

It's solving the problem of clicking download from a term table page, and not being able to see that term amongst the terms listed on the download page in the case where there are too many: the solution is to reduce the number of terms displayed, and highlight the specific term.

The business of displaying only a few terms on the download page is now better handled by a collapseDisplayedItems function in main.js. The code is cleaned up with suggestions and review from @zarino and @tmtmtmtm in previous PR #12987, which this PR supersedes.

The collapseDisplayedItems function hides all but maxDisplayItems terms, if there are more than minThresholdItems. If there's a selected term (i.e., after a click on Download data from a term page) it is included in the displayed items.

Both term and house (as slugs) are passed from the term download button; if either is lacking (no term is selected) then multiple terms are still collapsed on the download page, but no specific term is hidden. By default, most recent terms are shown.

The highlighted term is given CSS class download-terms__highlighted.

Dave Whiteland added 6 commits August 12, 2016 17:11
added to static page so that JS can pick them up and add them as
query vars on click
So can hang a click event off it (to add term data to the URL)
Caused a long line, so moved attribs onto separate lines.
Core of this should be in main.js, with much less here.
wrapped in a general function that's run from main.js at the end of
all other document-ready code, to avoid race conditions.
@tmtmtmtm tmtmtmtm requested a deployment to everypolitician-viewe-pr-14535 August 15, 2016 00:36 Pending
@tmtmtmtm tmtmtmtm requested a deployment to everypolitician-viewe-pr-14535 August 15, 2016 00:37 Pending
@@ -479,3 +479,8 @@ $(function(){

}
});

function getQueryParam(key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this something you wrote yourself, or is it taken from somewhere else? (and if the latter should it have attribution?)

@tmtmtmtm
Copy link
Contributor

Some comments in-place. I'm a little wary of diminishing returns here, so 'TODO' comments in-place are also plausible options for some of these things…

Dave Whiteland added 4 commits August 15, 2016 08:43
code now more obviously checks for hash (fragment identifier in URL)
and simply adds the query vars on the end of the URL if there isn't
one there.

We don't anticipate there being an anchor tag there any more, but
it's a sneaky gotcha that would break this behaviour should one
ever be added.
Turns out modifying the request on click has a race condition on the
click tracking: depends which code fires first, because both are
modifying the location, and the first one to execute wins.

So modifying the href (by adding anchor tags) before click is simpler.
no longer handling query vars, passing them in the fragment identifier (after the
hash) in the URL instead, so removing these functions
Use the .next() sibling selector instead, since the toggle button is being
injected directly above the list it relates to: so can assume that the list
is its next sibling (instead of using ID).
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-14535 August 15, 2016 11:05 Inactive
This is just in set-up of the list: an alternative approach would be to
have the hidden class have `display:none` in the stylesheet. I haven't
done it that way simply because hiding the elements dynamically like this
means any class can be used. Since this is only dynamically controlled,
I've added the prefix `js-` to the hidden class name being used.
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-14535 August 15, 2016 11:14 Inactive
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-14535 August 15, 2016 11:27 Inactive
@davewhiteland davewhiteland force-pushed the issues/14427-highlight-download-term branch from 213dd3e to a34d512 Compare August 15, 2016 11:54
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-14535 August 15, 2016 11:54 Inactive
makes it a teeny bit clearer what's going on.
I think the function itself is a little clunky because of the problem of
the targetIndex being at (or close to) either end of the list, so there's
some explicit checking for that.

Also it makes it clearer that this code is adding the hidden class to
everything, then removing it from the innerList... would be nicer to
invert this to add the class just to things not in the innerList, which
might be possible for cleanliness.
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-14535 August 15, 2016 12:45 Inactive
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-14535 August 15, 2016 14:20 Inactive
@davewhiteland
Copy link
Contributor Author

invitation for review @tmtmtmtm

@davewhiteland
Copy link
Contributor Author

It's worth mentioning perhaps that now it's neatly encapsulated, it becomes clear that the implementation I ought to want is outerList not innerList... because really this is just to add the CSS class to the items that's are not in the inner list (because those are the ones that need to respond to show/hide toggling).

@tmtmtmtm tmtmtmtm assigned davewhiteland and unassigned tmtmtmtm Sep 23, 2016
@tmtmtmtm
Copy link
Contributor

Reverting back to @davewhiteland to work out what should happen now that this page has been split into per-legislature rather than per-country.

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.

3 participants