Commit Graph

158 Commits

Author SHA1 Message Date
Katie Smith
83c10149bd Rename 'email-branding-preview' CSS styles to 'branding-preview'
Renamed since the same styling will be used for previewing letters.
2019-02-19 10:44:51 +00:00
Tom Byers
994c9397fe Fix the logic handling spacing between stickys 2019-02-13 14:49:42 +00:00
Tom Byers
30844143ec Fix bugs around operations happening between modes
The `release` method is meant to clean up a sticky
element before removal from the store.

The part of this that cleared CSS added due to
being in dialog mode was only run if still in that
mode.

In the template folder JS, we set the mode before
running `recalculate` so elements can be cleaned
in a different mode to that they were last in.
This meant some CSS wasn't being cleaned up.

This sometimes caused an effect where elements
that were added back to the DOM but not stuck
would still have CSS used when they were last
stuck.

This commit also includes the addition of some
missing code that adds back CSS to offset an
element when in a dialog stack.
2019-02-11 17:50:47 +00:00
Tom Byers
09848009c1 Correct reference to 'self' variable
It doesn't exist in this scope so the 'self' in
the scope above was being referenced instead,
preventing it from erroring.
2019-02-11 16:10:29 +00:00
Tom Byers
4c477d08a6 Put shift in focus after change to state
Moving focus before letting the sticky JS set the
position of sticky elements means focus is shifted
to them when they are still in the page. This
causes the browser to scroll so the focused
elements are visible.

This moves when focus is set to after the sticky
JS has set position therefore avoiding the issue.
2019-02-11 15:24:09 +00:00
Tom Byers
693ddadbc4 Deal with focus state following cancelation
Follows pattern from dialogs whereby focus returns
to the button/link that fired the dialog when it
closes.
2019-02-11 15:24:09 +00:00
Tom Byers
d633bdbb6d Tidy up JS code for focusing & associated html
Makes sure the tabindex we add for focusing is
removed.

Also removes the outer fieldset from the radios
for new templates. We don't wrap form buttons in
fieldsets anywhere else and it doesn't add any
useful semantics to the form.
2019-02-11 15:24:09 +00:00
Tom Byers
2b2641b039 Use JS for applying focus & add styling for it
Adds some extra styles so <fieldset>'s show as
focused when they are.

Also includes replacement of `overflow: hidden` on
sticky elements with a clearfix. hiding overflow
clips the outline and the clearfix can be used for
containing any floats instead. (I'm assuming that's
why it was set here.)
2019-02-11 15:24:09 +00:00
Chris Hill-Scott
ca6529dcdb Update app/assets/javascripts/templateFolderForm.js
Use native `Array.indexOf` instead.

Co-Authored-By: tombye <tombaromba@gmail.com>
2019-02-04 15:17:27 +00:00
Tom Byers
0e55521d8f $.inArray returns the same value as Array.indexOf 2019-02-04 14:56:18 +00:00
Tom Byers
7ef32a6bd9 Replace native Array.includes with jQuery version
This was failing with a 'Object doesn't have
method' error on IE11. Assume Babel wasn't
polyfilling Array.includes so reverting to jQuery
version for now.
2019-02-04 11:23:41 +00:00
Chris Hill-Scott
5597e63d44 Recalculate stickyness after API keys have rendered 2019-02-01 15:45:38 +00:00
Tom Byers
fd3ca31e44 Add adjustment for padding missed from previous
The work done to stack sticky elements closer
together only effected the stack when stuck to the
top/bottom edge:

707c426b9a

It should have included the same for when a stack
of sticky elements is stopped at the end of it's
scroll area. This adds code to deal with that.
2019-01-31 15:56:16 +00:00
Tom Byers
c89ad9635b Fix switch between modes and scrolling on adjust
The templateFolderForm JS was setting the mode to
'dialog' but not back when the state was changed
back to a normal sticky element. This caused
adjustments and scrolling when no adjustment
needed to be accommodated.

There were also problems with adjustForResize. It
was manipulating the same flag that resizing the
window did and returned a value never used.
2019-01-30 19:12:14 +00:00
Tom Byers
707c426b9a Remove padding between stickys when stacked 2019-01-30 14:59:30 +00:00
Tom Byers
f4d9c37940 Move setting of sticky mode out of recalculate
The `recalculate` method currently does three
things:
1. sync's the internal store with the DOM
2. updates the saved positional and dimensional
data from the new DOM
3. allows the mode to be set

The problem with using it as the way to set the
mode is that, every call to it is effectively
setting the mode but this isn't always the
intention.

This splits off setting the mode so other modules
have to explicity set it and those that don't
intend to can just call `recalculate` to notify of
DOM changes.
2019-01-30 11:45:24 +00:00
Tom Byers
177f30248e Fix bug with DOM sync'ing
If a sticky element was already in the store, the
code for adding it would return early. This meant
dimensions and positions for it were not being
recalculated.
2019-01-30 11:35:31 +00:00
Leo Hemsted
d5e95af446 make classes in folder dialog states consistent
make sure the class is applied to a child element, so that `$el.find`
will always find something for `js-will-stick-at-bottom-when-scrolling`.

Also, clean up code by treating all stickies on the template folder
form as dialogs - they all are after all all dialogs - modals that
expect your attention on top of the main page content.
2019-01-25 16:47:49 +00:00
Tom Byers
05c455250c Fix calculation of in-page position
When the screen resizes, the dimensions of our
elements may change so we run
`setElementDimensions` again to update our store
of those values.

This caused a bug with the stored position of
stuck elements. When stuck, elements are
'fixed' so their position is relative to the
window position. We need the value stored to be
from the position in the document flow, not the
'fixed' value.

This change means, when an element is stuck, we
check its shim for the position instead. The shim
occupies the space the element would do in the
page so it makes sense to use it for this.
2019-01-23 16:55:18 +00:00
Tom Byers
59b02e0fe0 Change when folder controls become sticky
The controls for the template folders are all
present in the page when it loads. The
templateFolderForm JS filters them so you only see
the one you need to for the thing you're trying to
do.

This changes when the controls are made sticky so
it happens after the templateFolderForm JS has
performed its filtering.
2019-01-23 16:55:18 +00:00
Tom Byers
98789c98c8 Reset onload flag when recalculate called
This ensures sticky elements don't fade in if
in a sticky position when the page loads.

The fade is there to show when an element is
becoming sticky. This has no use if it was already
sticky the first time you see it.

Because the same situation applies when
recalculate is called, we also want the flag to be
reset before this happens.
2019-01-23 16:55:18 +00:00
Tom Byers
a9b7a0d887 Add box shadow by JS
When mode === 'dialog', sticky elements are
stacked so we need to apply the box shadow to the
top (when sticking to the bottom edge) and bottom
(when sticking to the top edge) elements in the
stack.

From what I can see, we need the version of
`nth-child` that supports targeting by selector.
As of this date, support for this is only in
Safari:

https://caniuse.com/#feat=css-nth-child-of

Until we can use this version of `nth-child`, we
need to use JS to apply the styles.
2019-01-23 16:55:18 +00:00
Tom Byers
4e845c3125 Move setting of events into separate method 2019-01-23 16:55:18 +00:00
Tom Byers
1e8e8908ee Move sync'ing this._els with DOM into own method
We'll need to run this whenever recalculate runs
to ensure `this._els` matches the present state of
the DOM.
2019-01-23 16:55:18 +00:00
Tom Byers
a6a7057d64 Deal with elements no longer in the DOM
Instead of keeping references to nodes detached
from the DOM, remove them from the store.
Likewise, add node appended to the DOM.

This includes code to 'clean' DOM nodes when
removed. This is important because nodes can
retain classes and styles. If they are re-attached
in future this can cause problems with how the
state of the element is determined.
2019-01-23 16:55:18 +00:00
Tom Byers
03e38dfdef Add mode for grouping sticky elements as a dialog
We want a mode for when a single task is shared
between all sticky elements on the page and that
task has the highest priority on the page. In that
case:
- they should stack together into a single block,
  attached to the top/bottom of the viewport
- that block should adjust to the vertical space
  available

This should also adjust to the height of the
viewport, dropping whatever elements that don't
fit back into the page flow. When this happens, we
scroll the page so all the parts of the dialog are
seen together at the start of the task.
2019-01-23 16:55:12 +00:00
Tom Byers
ea675f45da Make the sticky states more robust
If the screen resizes, sticky elements can end up
moving from one part of the screen to another,
sometimes without passing through their different
states (in-page, stuck, stopped) in the normal
order.

This makes the methods that change their states
better at dealing with those state changes.
2019-01-23 16:33:32 +00:00
Tom Byers
c0706b9cef Split move_to forms into separate sticky elements 2019-01-23 15:30:28 +00:00
Tom Byers
7b3ac55103 Add method for adding a sticky element 2019-01-23 15:30:28 +00:00
Chris Hill-Scott
509a9e861d Use sticky footer on edit template page
If you have a long template it’s annoying to have to scroll all the
way to the bottom to click save, when you’ve only changed a small thing
near the staert of the content.
2019-01-14 15:05:04 +00:00
Chris Hill-Scott
a9baa36005 Hide ‘nothing selected’ if nothing to select
It’s doesn’t make sense to show the state if the state can’t change.
This is especially true when you’re in a brand new, empty service.
2019-01-03 11:16:56 +00:00
Chris Hill-Scott
6487273ced Fix sticky with find as you type
It was losing its position because filtering the list of templates with
find as you type was causing the height of the page to change.
2018-12-21 14:37:01 +00:00
Leo Hemsted
1bcee4c1b0 render if currentState is defined
(this fixes bug where on error, it would show all states)
2018-12-19 15:25:43 +00:00
Tom Byers
f6a6de41aa Merge pull request #2590 from alphagov/fix-sticky-init
Fix issues with JS for sticky elements
2018-12-17 13:29:19 +00:00
Chris Hill-Scott
c30af92050 Merge pull request #2574 from alphagov/selected-template-counter
Add counter of selected templates and folders
2018-12-17 10:34:45 +00:00
Tom Byers
573d2d1d65 Fix code for sticky JS when window resizes
Includes:
- change .stopped method to .isStopped() for
  consistency
- replace code in checkResize that adjusts
  dimensions for setElementDimensions
- add code that deals with the window size being
  too small to run whenever positions are calculated
- add reset method for when screen is too small
  for sticking behaviour
- move guard out of methods for stopping and
  sticking (it hid info that was useful at the
  point they were called)
2018-12-14 16:33:00 +00:00
Tom Byers
b55acc4981 Add comments 2018-12-14 16:33:00 +00:00
Tom Byers
108cec7938 Remove fixedTop property from sticky elements
It's no longer used by this code.
2018-12-14 16:33:00 +00:00
Tom Byers
030701ab1b Make folder controls update sticky JS on change
Also removes a call the `render` method which
duplicates one already made by the
`selectActionButtons` method on load.
2018-12-14 16:33:00 +00:00
Tom Byers
9823ff831f Add publich recalculate method
Allows other JS to tell sticky elements to
recalculate their dimensions and then position
(and then check to see if their state needs
changing).

We need this because we change the content of our
element so its dimensions change.

The recalculation code also updates the shim for
elements that are 'stuck' so the horizontal space
the element would occupy in the flow of the page
is correct.
2018-12-14 16:30:07 +00:00
Tom Byers
6fb2d14cc3 Move shim handling to StickyElement
Includes other code that splits the height
StickyElement stores into two properties:
1. `verticalSpace`
2. `height`

`verticalSpace` is the vertical space the element
occupies in the document flow when not stuck.

`height` is the visual space of the element,
including padding and border.
2018-12-14 16:16:40 +00:00
Pea (Malgorzata Tyczynska)
1e3be7d640 Merge pull request #2577 from alphagov/disable_ajax_if_inactive
Page stops auto-refreshing when it's not active
2018-12-12 12:32:52 +00:00
Pea Tyczynska
b65f5abf92 Page stops auto-refreshing when it's not active 2018-12-12 11:42:54 +00:00
Chris Hill-Scott
ce86604a49 Only trigger clear/cancel buttons on certain keys
It’s annoying having these buttons triggered by the tab or command keys.
2018-12-10 17:32:36 +00:00
Chris Hill-Scott
0c71ca0f0e Move cancel buttons alongside submit buttons
This is better because it saves vertical space for the contents of the
pop-up menu.

This commit also adds some padding to the cancel and clear buttons, to
make them easier targets to hit.
2018-12-10 17:11:01 +00:00
Chris Hill-Scott
4b305376f7 Add counter of selected templates and folders
Being able to see how many things you have selected gives you positive
feedback that reinforces that what you’ve done has been recognised. It
helps you understand the implications of your actions (ie you see ‘3
selected’ before you press the ‘Move’ button). And it gives you an
escape hatch the get out of the state you’re in by providing the ‘Clear’
button.

We also found in prototyping that having a ‘Nothing selected’ message
helps draws people’s attention to the checkboxes when they first
encounter the folders feature.

This commit implements the counter and the cancel button. It tries to
follow the existing patterns for this module.
2018-12-10 16:53:12 +00:00
Chris Hill-Scott
cac2ce661b Fix sticky shim having zero height
We ‘shim’ the sticky element so that its space in the page is reserved
while it is sticky.

This means the shim have have the same height as the sticky element.
It’s height was not getting set because of a missing semicolon in the
shim element’s `style` attribute.
2018-12-10 16:03:37 +00:00
Chris Hill-Scott
b0f89f7fe9 Style cancel link and make it keyboard navigable
So that it looks and behaves like a normal link.
2018-12-05 16:47:45 +00:00
Chris Hill-Scott
224630a790 Merge pull request #2561 from alphagov/always-show-checked-search
Always show checked items in live search
2018-12-05 16:36:22 +00:00
Leo Hemsted
827b58e7ac remove the unknown button in js
When you hit enter while an input in a form is in focus, your browser
finds the first button in the form, and carries out that action. So,
for non-js users, we added a hidden submit button with a value of
"unknown" to reflect that we don't know the intention of the user.

However, with JS enabled, this ambiguity doesn't exist - there's only
submit button and forms to fill in at a time, and non-visible fields
aren't even submitted at all. We can remove the unknown button,
supporting enter as submit properly. If the user is on one of the grey
button states, with no submit, it'll press the first button, and go to
the new template / move to existing folder dialog. That's fine enough.
2018-12-05 13:48:07 +00:00