2018-11-01 20:33:00 +00:00
|
|
|
;(function (global) {
|
2018-11-08 15:04:15 +00:00
|
|
|
'use strict';
|
2018-11-01 20:33:00 +00:00
|
|
|
|
2018-11-08 15:04:15 +00:00
|
|
|
var $ = global.jQuery;
|
|
|
|
|
var GOVUK = global.GOVUK || {};
|
2018-11-01 20:33:00 +00:00
|
|
|
|
2018-12-13 18:59:34 +00:00
|
|
|
// Constructor for objects holding data for each element to have sticky behaviour
|
2018-11-13 14:08:06 +00:00
|
|
|
var StickyElement = function ($el, sticky) {
|
|
|
|
|
this._sticky = sticky;
|
|
|
|
|
this.$fixedEl = $el;
|
|
|
|
|
this._initialFixedClass = 'content-fixed-onload';
|
|
|
|
|
this._fixedClass = 'content-fixed';
|
|
|
|
|
this._appliedClass = null;
|
2018-12-11 15:53:54 +00:00
|
|
|
this._$shim = null;
|
2018-11-13 14:08:06 +00:00
|
|
|
this._stopped = false;
|
|
|
|
|
};
|
|
|
|
|
StickyElement.prototype.stickyClass = function () {
|
|
|
|
|
return (this._sticky._initialPositionsSet) ? this._fixedClass : this._initialFixedClass;
|
|
|
|
|
};
|
|
|
|
|
StickyElement.prototype.appliedClass = function () {
|
|
|
|
|
return this._appliedClass;
|
|
|
|
|
};
|
|
|
|
|
StickyElement.prototype.isStuck = function () {
|
|
|
|
|
return this._appliedClass !== null;
|
|
|
|
|
};
|
|
|
|
|
StickyElement.prototype.stick = function () {
|
|
|
|
|
this._appliedClass = this.stickyClass();
|
|
|
|
|
this._hasBeenCalled = true;
|
|
|
|
|
};
|
|
|
|
|
StickyElement.prototype.release = function () {
|
|
|
|
|
this._appliedClass = null;
|
|
|
|
|
this._hasBeenCalled = true;
|
|
|
|
|
};
|
2018-12-13 18:59:34 +00:00
|
|
|
// When a sticky element is moved into the 'stuck' state, a shim is inserted into the
|
|
|
|
|
// page to preserve the space the element occupies in the flow.
|
2018-12-11 15:53:54 +00:00
|
|
|
StickyElement.prototype.addShim = function (position) {
|
|
|
|
|
this._$shim = $('<div class="shim" style="width: ' + this.horizontalSpace + 'px; height: ' + this.verticalSpace + 'px"> </div>');
|
|
|
|
|
this.$fixedEl[position](this._$shim);
|
|
|
|
|
};
|
|
|
|
|
StickyElement.prototype.removeShim = function () {
|
|
|
|
|
this._$shim.remove();
|
|
|
|
|
this._$shim = null;
|
|
|
|
|
};
|
2018-12-13 18:59:34 +00:00
|
|
|
// Changes to the dimensions of a sticky element with a shim need to be passed on to the shim
|
2018-12-13 14:21:51 +00:00
|
|
|
StickyElement.prototype.updateShim = function () {
|
|
|
|
|
if (this._$shim) {
|
|
|
|
|
this._$shim.css({
|
|
|
|
|
'height': this.verticalSpace,
|
|
|
|
|
'width': this.horizontalSpace
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-11-13 14:08:06 +00:00
|
|
|
StickyElement.prototype.stop = function () {
|
2018-12-14 16:07:06 +00:00
|
|
|
this._isStopped = true;
|
2018-11-13 14:08:06 +00:00
|
|
|
};
|
|
|
|
|
StickyElement.prototype.unstop = function () {
|
2018-12-14 16:07:06 +00:00
|
|
|
this._isStopped = false;
|
2018-11-13 14:08:06 +00:00
|
|
|
};
|
2018-12-14 16:07:06 +00:00
|
|
|
StickyElement.prototype.isStopped = function () {
|
|
|
|
|
return this._isStopped;
|
2018-11-14 16:42:52 +00:00
|
|
|
};
|
2018-11-13 14:08:06 +00:00
|
|
|
|
2018-12-13 18:59:34 +00:00
|
|
|
// Constructor for objects collecting together all generic behaviour for controlling the state of
|
|
|
|
|
// sticky elements
|
2018-11-05 17:47:25 +00:00
|
|
|
var Sticky = function (selector) {
|
2018-11-08 15:04:15 +00:00
|
|
|
this._hasScrolled = false;
|
|
|
|
|
this._scrollTimeout = false;
|
|
|
|
|
this._hasResized = false;
|
|
|
|
|
this._resizeTimeout = false;
|
|
|
|
|
this._elsLoaded = false;
|
2018-11-13 14:08:06 +00:00
|
|
|
this._initialPositionsSet = false;
|
2018-11-08 15:04:15 +00:00
|
|
|
this._els = [];
|
2018-11-08 12:41:00 +00:00
|
|
|
|
2018-11-08 15:04:15 +00:00
|
|
|
this.CSS_SELECTOR = selector;
|
|
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
Sticky.prototype.getWindowDimensions = function () {
|
|
|
|
|
return {
|
|
|
|
|
height: $(global).height(),
|
|
|
|
|
width: $(global).width()
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
|
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
Sticky.prototype.getWindowPositions = function () {
|
|
|
|
|
return {
|
|
|
|
|
scrollTop: $(global).scrollTop()
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
|
|
|
|
};
|
2018-12-13 18:59:34 +00:00
|
|
|
// Change state of sticky elements based on their position relative to the window
|
2018-11-13 14:08:06 +00:00
|
|
|
Sticky.prototype.setElementPositions = function () {
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
$.each(self._els, function (i, el) {
|
2018-12-14 16:07:06 +00:00
|
|
|
var $el = el.$fixedEl,
|
|
|
|
|
windowDimensions = self.getWindowDimensions();
|
2018-11-13 14:08:06 +00:00
|
|
|
|
2018-12-14 16:07:06 +00:00
|
|
|
if (self.viewportIsWideEnough(windowDimensions.width)) {
|
2018-11-13 14:08:06 +00:00
|
|
|
|
2018-12-14 16:07:06 +00:00
|
|
|
if (self.windowNotPastScrolledFrom(el.scrolledFrom)) {
|
|
|
|
|
self.release(el);
|
|
|
|
|
} else {
|
|
|
|
|
if (self.windowNotPastScrolledTo(el, windowDimensions.height)) {
|
|
|
|
|
self.stick(el);
|
|
|
|
|
if (el.isStopped()) {
|
|
|
|
|
self.unstop(el);
|
|
|
|
|
}
|
|
|
|
|
} else { // window past scrolledTo position
|
|
|
|
|
if (!el.isStopped()) {
|
|
|
|
|
self.stop(el);
|
|
|
|
|
}
|
2018-11-13 14:08:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-12-14 16:07:06 +00:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
self.reset(el);
|
|
|
|
|
|
2018-11-13 14:08:06 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (self._initialPositionsSet === false) { self._initialPositionsSet = true; }
|
|
|
|
|
};
|
2018-12-13 18:59:34 +00:00
|
|
|
// Store all the dimensions for a sticky element to limit DOM queries
|
2018-12-11 15:53:54 +00:00
|
|
|
Sticky.prototype.setElementDimensions = function (el, callback) {
|
|
|
|
|
var self = this;
|
2018-12-13 14:25:22 +00:00
|
|
|
var $el = el.$fixedEl;
|
2018-12-11 15:53:54 +00:00
|
|
|
var onHeightSet = function () {
|
|
|
|
|
el.scrolledTo = self.getScrollingTo(el);
|
2018-12-13 14:25:22 +00:00
|
|
|
// if element is shim'ed, pass changes in dimension on to the shim
|
|
|
|
|
if (el._$shim) {
|
|
|
|
|
el.updateShim();
|
|
|
|
|
$el = el._$shim;
|
|
|
|
|
}
|
|
|
|
|
el.scrolledFrom = self.getScrolledFrom($el);
|
2018-12-11 15:53:54 +00:00
|
|
|
if (callback !== undefined) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.setElWidth(el);
|
|
|
|
|
this.setElHeight(el, onHeightSet);
|
|
|
|
|
};
|
2018-12-14 16:07:06 +00:00
|
|
|
// Reset element to original state in the page
|
|
|
|
|
Sticky.prototype.reset = function (el) {
|
|
|
|
|
if (el.isStuck()) {
|
|
|
|
|
this.release(el);
|
|
|
|
|
}
|
|
|
|
|
if (el.isStopped()) {
|
|
|
|
|
this.unstop(el);
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-12-13 18:59:34 +00:00
|
|
|
// Recalculate stored dimensions for all sticky elements
|
2018-12-13 14:21:51 +00:00
|
|
|
Sticky.prototype.recalculate = function () {
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
$.each(self._els, function (i, el) {
|
|
|
|
|
self.setElementDimensions(el);
|
|
|
|
|
});
|
|
|
|
|
self.setElementPositions();
|
|
|
|
|
};
|
2018-12-11 15:53:54 +00:00
|
|
|
Sticky.prototype.setElWidth = function (el) {
|
2018-12-14 16:07:06 +00:00
|
|
|
var $el = el.$fixedEl;
|
|
|
|
|
var width = $el.parent().width();
|
|
|
|
|
|
|
|
|
|
el.horizontalSpace = width;
|
|
|
|
|
// if stuck, element won't inherit width from parent so set explicitly
|
|
|
|
|
if (el._$shim) {
|
|
|
|
|
$el.width(width);
|
|
|
|
|
}
|
2018-12-11 15:53:54 +00:00
|
|
|
};
|
|
|
|
|
Sticky.prototype.setElHeight = function (el, callback) {
|
2018-11-08 15:04:15 +00:00
|
|
|
var self = this;
|
|
|
|
|
var $el = el.$fixedEl;
|
|
|
|
|
var $img = $el.find('img');
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-11-08 12:41:00 +00:00
|
|
|
if ((!self._elsLoaded) && ($img.length > 0)) {
|
2018-11-08 15:04:15 +00:00
|
|
|
var image = new global.Image();
|
2018-11-05 17:47:25 +00:00
|
|
|
image.onload = function () {
|
2018-12-13 14:21:51 +00:00
|
|
|
el.verticalSpace = $el.outerHeight(true);
|
2018-12-11 15:53:54 +00:00
|
|
|
el.height = $el.outerHeight();
|
|
|
|
|
callback();
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
|
|
|
|
image.src = $img.attr('src');
|
2018-11-05 17:47:25 +00:00
|
|
|
} else {
|
2018-12-13 14:21:51 +00:00
|
|
|
el.verticalSpace = $el.outerHeight(true);
|
2018-12-11 15:53:54 +00:00
|
|
|
el.height = $el.outerHeight();
|
|
|
|
|
callback();
|
2018-11-05 17:47:25 +00:00
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-12-11 15:53:54 +00:00
|
|
|
Sticky.prototype.allElementsLoaded = function (totalEls) {
|
|
|
|
|
return this._els.length === totalEls;
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
Sticky.prototype.init = function () {
|
2018-11-08 15:04:15 +00:00
|
|
|
var self = this;
|
|
|
|
|
var $els = $(self.CSS_SELECTOR);
|
2018-12-11 15:53:54 +00:00
|
|
|
var numOfEls = $els.length;
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-12-11 15:53:54 +00:00
|
|
|
if (numOfEls > 0) {
|
2018-11-05 17:47:25 +00:00
|
|
|
$els.each(function (i, el) {
|
2018-11-08 15:04:15 +00:00
|
|
|
var $el = $(el);
|
2018-11-13 14:08:06 +00:00
|
|
|
var elObj = new StickyElement($el, self);
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-12-11 15:53:54 +00:00
|
|
|
self.setElementDimensions(elObj, function () {
|
|
|
|
|
self._els.push(elObj);
|
|
|
|
|
// set positions based on initial scroll positionu
|
|
|
|
|
if (self._els.length === numOfEls) {
|
|
|
|
|
self._elsLoaded = true;
|
|
|
|
|
self.setElementPositions();
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-11-08 15:04:15 +00:00
|
|
|
});
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-12-13 18:59:34 +00:00
|
|
|
// flag when scrolling takes place and check (and re-position) sticky elements relative to
|
|
|
|
|
// window position
|
2018-11-05 17:47:25 +00:00
|
|
|
if (self._scrollTimeout === false) {
|
2018-11-08 15:04:15 +00:00
|
|
|
$(global).scroll(function (e) { self.onScroll(); });
|
|
|
|
|
self._scrollTimeout = global.setInterval(function (e) { self.checkScroll(); }, 50);
|
2018-11-04 21:10:02 +00:00
|
|
|
}
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-12-13 18:59:34 +00:00
|
|
|
// Recalculate all dimensions when the window resizes
|
2018-11-05 17:47:25 +00:00
|
|
|
if (self._resizeTimeout === false) {
|
2018-11-08 15:04:15 +00:00
|
|
|
$(global).resize(function (e) { self.onResize(); });
|
|
|
|
|
self._resizeTimeout = global.setInterval(function (e) { self.checkResize(); }, 50);
|
2018-11-05 17:47:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-12-14 16:07:06 +00:00
|
|
|
Sticky.prototype.viewportIsWideEnough = function (windowWidth) {
|
|
|
|
|
return windowWidth > 768;
|
|
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
Sticky.prototype.onScroll = function () {
|
2018-11-08 15:04:15 +00:00
|
|
|
this._hasScrolled = true;
|
|
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
Sticky.prototype.onResize = function () {
|
2018-11-08 15:04:15 +00:00
|
|
|
this._hasResized = true;
|
|
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
Sticky.prototype.checkScroll = function () {
|
2018-11-08 15:04:15 +00:00
|
|
|
var self = this;
|
2018-11-05 17:47:25 +00:00
|
|
|
|
|
|
|
|
if (self._hasScrolled === true) {
|
2018-11-08 15:04:15 +00:00
|
|
|
self._hasScrolled = false;
|
2018-11-13 14:08:06 +00:00
|
|
|
self.setElementPositions(true);
|
2018-11-05 17:47:25 +00:00
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
Sticky.prototype.checkResize = function () {
|
2018-12-14 16:07:06 +00:00
|
|
|
var self = this,
|
|
|
|
|
windowWidth = self.getWindowDimensions().width;
|
2018-11-05 17:47:25 +00:00
|
|
|
|
|
|
|
|
if (self._hasResized === true) {
|
2018-11-08 15:04:15 +00:00
|
|
|
self._hasResized = false;
|
2018-11-04 21:10:02 +00:00
|
|
|
|
2018-11-05 17:47:25 +00:00
|
|
|
$.each(self._els, function (i, el) {
|
2018-12-14 16:07:06 +00:00
|
|
|
if (!self.viewportIsWideEnough(windowWidth)) {
|
|
|
|
|
self.reset(el);
|
|
|
|
|
} else {
|
|
|
|
|
self.setElementDimensions(el);
|
2018-11-01 20:33:00 +00:00
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
});
|
2018-12-14 16:07:06 +00:00
|
|
|
|
|
|
|
|
if (self.viewportIsWideEnough(windowWidth)) {
|
|
|
|
|
self.setElementPositions();
|
|
|
|
|
}
|
2018-11-05 17:47:25 +00:00
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-13 14:08:06 +00:00
|
|
|
Sticky.prototype.release = function (el) {
|
|
|
|
|
if (el.isStuck()) {
|
|
|
|
|
var $el = el.$fixedEl;
|
|
|
|
|
|
|
|
|
|
$el.removeClass(el.appliedClass()).css('width', '');
|
2018-12-11 15:53:54 +00:00
|
|
|
el.removeShim();
|
2018-11-13 14:08:06 +00:00
|
|
|
el.release();
|
2018-11-05 17:47:25 +00:00
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-12-13 18:59:34 +00:00
|
|
|
// Extension of sticky object to add behaviours specific to sticking to top of window
|
2018-11-08 15:04:15 +00:00
|
|
|
var stickAtTop = new Sticky('.js-stick-at-top-when-scrolling');
|
2018-12-13 18:59:34 +00:00
|
|
|
// Store top of sticky elements while unstuck
|
2018-11-05 17:47:25 +00:00
|
|
|
stickAtTop.getScrolledFrom = function ($el) {
|
2018-11-08 15:04:15 +00:00
|
|
|
return $el.offset().top;
|
|
|
|
|
};
|
2018-12-13 18:59:34 +00:00
|
|
|
// Store furthest point top of sticky element is allowed
|
2018-11-05 17:47:25 +00:00
|
|
|
stickAtTop.getScrollingTo = function (el) {
|
2018-11-08 15:04:15 +00:00
|
|
|
var footer = $('.js-footer:eq(0)');
|
2018-11-05 17:47:25 +00:00
|
|
|
if (footer.length === 0) {
|
2018-11-08 15:04:15 +00:00
|
|
|
return 0;
|
2018-11-05 17:47:25 +00:00
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
return (footer.offset().top - 10) - el.height;
|
|
|
|
|
};
|
2018-12-14 16:07:06 +00:00
|
|
|
stickAtTop.windowNotPastScrolledFrom = function (scrolledFrom) {
|
2018-11-08 15:04:15 +00:00
|
|
|
var windowTop = this.getWindowPositions().scrollTop;
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-11-08 15:04:15 +00:00
|
|
|
return scrolledFrom > windowTop;
|
|
|
|
|
};
|
2018-12-14 16:07:06 +00:00
|
|
|
stickAtTop.windowNotPastScrolledTo = function (el, windowHeight) {
|
2018-11-08 15:04:15 +00:00
|
|
|
var windowTop = this.getWindowPositions().scrollTop;
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-12-14 16:07:06 +00:00
|
|
|
return windowTop < el.scrolledTo;
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-12-11 15:53:54 +00:00
|
|
|
stickAtTop.stick = function (el) {
|
|
|
|
|
if (!el.isStuck()) {
|
|
|
|
|
var $el = el.$fixedEl;
|
|
|
|
|
|
|
|
|
|
el.addShim('before');
|
|
|
|
|
// element will be absolutely positioned so cannot rely on parent element for width
|
|
|
|
|
$el.css('width', $el.width() + 'px').addClass(el.stickyClass());
|
|
|
|
|
el.stick();
|
|
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
stickAtTop.stop = function (el) {
|
2018-12-14 16:07:06 +00:00
|
|
|
el.$fixedEl.css({ 'position': 'absolute', 'top': el.scrolledTo });
|
|
|
|
|
el.stop();
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
stickAtTop.unstop = function (el) {
|
2018-12-14 16:07:06 +00:00
|
|
|
el.$fixedEl.css({ 'position': '', 'top': '' });
|
|
|
|
|
el.unstop();
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-12-13 18:59:34 +00:00
|
|
|
// Extension of sticky object to add behaviours specific to sticking to bottom of window
|
2018-11-08 15:04:15 +00:00
|
|
|
var stickAtBottom = new Sticky('.js-stick-at-bottom-when-scrolling');
|
2018-12-13 18:59:34 +00:00
|
|
|
// Store bottom of sticky elements while unstuck
|
2018-11-05 17:47:25 +00:00
|
|
|
stickAtBottom.getScrolledFrom = function ($el) {
|
2018-11-08 15:04:15 +00:00
|
|
|
return $el.offset().top + $el.outerHeight();
|
|
|
|
|
};
|
2018-12-13 18:59:34 +00:00
|
|
|
// Store furthest point bottom of sticky element is allowed
|
2018-11-05 17:47:25 +00:00
|
|
|
stickAtBottom.getScrollingTo = function (el) {
|
2018-11-08 15:04:15 +00:00
|
|
|
var header = $('.js-header:eq(0)');
|
2018-11-05 17:47:25 +00:00
|
|
|
if (header.length === 0) {
|
2018-11-08 15:04:15 +00:00
|
|
|
return 0;
|
2018-11-05 17:47:25 +00:00
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
return (header.offset().top + header.outerHeight() + 10) + el.height;
|
|
|
|
|
};
|
2018-12-14 16:07:06 +00:00
|
|
|
stickAtBottom.windowNotPastScrolledFrom = function (scrolledFrom) {
|
2018-11-08 15:04:15 +00:00
|
|
|
var windowBottom = this.getWindowPositions().scrollTop + this.getWindowDimensions().height;
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-11-08 15:04:15 +00:00
|
|
|
return scrolledFrom < windowBottom;
|
|
|
|
|
};
|
2018-12-14 16:07:06 +00:00
|
|
|
stickAtBottom.windowNotPastScrolledTo = function (el, windowHeight) {
|
2018-11-08 15:04:15 +00:00
|
|
|
var windowBottom = this.getWindowPositions().scrollTop + this.getWindowDimensions().height;
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-12-14 16:07:06 +00:00
|
|
|
return windowBottom > el.scrolledTo;
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-12-11 15:53:54 +00:00
|
|
|
stickAtBottom.stick = function (el) {
|
|
|
|
|
if (!el.isStuck()) {
|
|
|
|
|
var $el = el.$fixedEl;
|
|
|
|
|
|
|
|
|
|
el.addShim('after');
|
|
|
|
|
// element will be absolutely positioned so cannot rely on parent element for width
|
|
|
|
|
el.$fixedEl.css('width', $el.width() + 'px').addClass(el.stickyClass());
|
|
|
|
|
el.stick();
|
|
|
|
|
}
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
stickAtBottom.stop = function (el) {
|
2018-12-14 16:07:06 +00:00
|
|
|
el.$fixedEl.css({
|
|
|
|
|
'position': 'absolute',
|
|
|
|
|
'top': (el.scrolledTo - el.height),
|
|
|
|
|
'bottom': 'auto'
|
|
|
|
|
});
|
|
|
|
|
el.stop();
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
stickAtBottom.unstop = function (el) {
|
2018-12-14 16:07:06 +00:00
|
|
|
el.$fixedEl.css({
|
|
|
|
|
'position': '',
|
|
|
|
|
'top': '',
|
|
|
|
|
'bottom': ''
|
|
|
|
|
});
|
|
|
|
|
el.unstop();
|
2018-11-08 15:04:15 +00:00
|
|
|
};
|
2018-11-05 17:47:25 +00:00
|
|
|
|
2018-11-08 15:04:15 +00:00
|
|
|
GOVUK.stickAtTopWhenScrolling = stickAtTop;
|
|
|
|
|
GOVUK.stickAtBottomWhenScrolling = stickAtBottom;
|
|
|
|
|
global.GOVUK = GOVUK;
|
|
|
|
|
})(window);
|