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.
This commit is contained in:
Tom Byers
2019-01-30 11:45:24 +00:00
parent 177f30248e
commit f4d9c37940
2 changed files with 11 additions and 7 deletions

View File

@@ -144,9 +144,12 @@
state => (state.key === this.currentState ? this.$stickyBottom.append(state.$el) : state.$el.detach())
);
// make sticky JS recalculate its cache of the element's position
// use dialog mode for states which contain more than one form control
GOVUK.stickAtBottomWhenScrolling.recalculate({ 'mode': 'dialog' });
if (['move-to-existing-folder', 'add-new-template'].includes(this.currentState)) {
GOVUK.stickAtBottomWhenScrolling.setMode('dialog');
}
// make sticky JS recalculate its cache of the element's position
GOVUK.stickAtBottomWhenScrolling.recalculate();
};
this.nothingSelectedButtons = $(`