Skip to content

Commit f699ef8

Browse files
committed
Rename variables to clarify their intent
This change renames: 'el' to 'wrapper', and 'element' to 'stickyElement'. 'root' is removed as we can now reference the global 'window' object instead. Clarify the intent and concept of the variables - remove an unrequired variable.
1 parent d662dd4 commit f699ef8

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

app/assets/javascripts/modules/sticky-element-container.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77
Use 'data-module="sticky-element-container"' to instantiate, and add
88
`[data-sticky-element]` to the child you want to position.
99
*/
10-
(function (Modules, root) {
10+
(function (Modules) {
1111
'use strict'
1212

1313
Modules.StickyElementContainer = function () {
1414
var self = this
1515

1616
self.getWindowDimensions = function () {
1717
return {
18-
height: root.innerHeight,
19-
width: root.innerWidth
18+
height: window.innerHeight,
19+
width: window.innerWidth
2020
}
2121
}
2222

2323
self.getWindowPositions = function () {
2424
return {
25-
scrollTop: root.scrollY
25+
scrollTop: window.scrollY
2626
}
2727
}
2828

2929
self.start = function ($el) {
30-
var el = $el[0]
31-
var element = el.querySelector('[data-sticky-element]')
30+
var wrapper = $el[0]
31+
var stickyElement = wrapper.querySelector('[data-sticky-element]')
3232

3333
var hasResized = true
3434
var hasScrolled = true
@@ -39,13 +39,13 @@
3939
initialise()
4040

4141
function initialise () {
42-
root.onresize = onResize
43-
root.onscroll = onScroll
42+
window.onresize = onResize
43+
window.onscroll = onScroll
4444
setInterval(checkResize, interval)
4545
setInterval(checkScroll, interval)
4646
checkResize()
4747
checkScroll()
48-
element.classList.add('sticky-element--enabled')
48+
stickyElement.classList.add('sticky-element--enabled')
4949
}
5050

5151
function onResize () {
@@ -62,9 +62,9 @@
6262
hasScrolled = true
6363

6464
var windowDimensions = self.getWindowDimensions()
65-
var elementHeight = el.offsetHeight || parseFloat(el.style.height.replace('px', ''))
66-
startPosition = el.offsetTop
67-
stopPosition = el.offsetTop + elementHeight - windowDimensions.height
65+
var elementHeight = wrapper.offsetHeight || parseFloat(wrapper.style.height.replace('px', ''))
66+
startPosition = wrapper.offsetTop
67+
stopPosition = wrapper.offsetTop + elementHeight - windowDimensions.height
6868
}
6969
}
7070

@@ -98,20 +98,20 @@
9898
}
9999

100100
function stickToWindow () {
101-
element.classList.add('sticky-element--stuck-to-window')
101+
stickyElement.classList.add('sticky-element--stuck-to-window')
102102
}
103103

104104
function stickToParent () {
105-
element.classList.remove('sticky-element--stuck-to-window')
105+
stickyElement.classList.remove('sticky-element--stuck-to-window')
106106
}
107107

108108
function show () {
109-
element.classList.remove('sticky-element--hidden')
109+
stickyElement.classList.remove('sticky-element--hidden')
110110
}
111111

112112
function hide () {
113-
element.classList.add('sticky-element--hidden')
113+
stickyElement.classList.add('sticky-element--hidden')
114114
}
115115
}
116116
}
117-
})(window.GOVUK.Modules, window)
117+
})(window.GOVUK.Modules)

0 commit comments

Comments
 (0)