govuk_frontend_toolkit 4.18.3 → 4.18.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/.gitignore +1 -0
- data/app/assets/CHANGELOG.md +5 -0
- data/app/assets/Gruntfile.js +21 -22
- data/app/assets/README.md +4 -0
- data/app/assets/VERSION.txt +1 -1
- data/app/assets/docs/javascript.md +29 -28
- data/app/assets/javascripts/govuk/analytics/analytics.js +37 -37
- data/app/assets/javascripts/govuk/analytics/download-link-tracker.js +21 -21
- data/app/assets/javascripts/govuk/analytics/error-tracking.js +19 -19
- data/app/assets/javascripts/govuk/analytics/external-link-tracker.js +23 -24
- data/app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js +71 -70
- data/app/assets/javascripts/govuk/analytics/mailto-link-tracker.js +20 -21
- data/app/assets/javascripts/govuk/analytics/print-intent.js +19 -20
- data/app/assets/javascripts/govuk/modules.js +33 -32
- data/app/assets/javascripts/govuk/modules/auto-track-event.js +18 -18
- data/app/assets/javascripts/govuk/multivariate-test.js +83 -85
- data/app/assets/javascripts/govuk/primary-links.js +39 -38
- data/app/assets/javascripts/govuk/selection-buttons.js +57 -58
- data/app/assets/javascripts/govuk/shim-links-with-button-role.js +14 -15
- data/app/assets/javascripts/govuk/stick-at-top-when-scrolling.js +70 -70
- data/app/assets/javascripts/govuk/stop-scrolling-at-footer.js +74 -75
- data/app/assets/javascripts/govuk_toolkit.js +1 -1
- data/app/assets/javascripts/stageprompt.js +24 -25
- data/app/assets/javascripts/vendor/jquery/jquery.player.min.js +1 -1
- data/app/assets/package.json +10 -3
- data/app/assets/spec/manifest.js +2 -0
- data/app/assets/spec/support/console-runner.js +0 -1
- data/app/assets/spec/unit/analytics/analytics.spec.js +51 -47
- data/app/assets/spec/unit/analytics/download-link-tracker.spec.js +59 -51
- data/app/assets/spec/unit/analytics/error-tracking.spec.js +35 -30
- data/app/assets/spec/unit/analytics/external-link-tracker.spec.js +69 -61
- data/app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js +129 -122
- data/app/assets/spec/unit/analytics/mailto-link-tracker.spec.js +55 -47
- data/app/assets/spec/unit/modules.spec.js +82 -78
- data/app/assets/spec/unit/modules/auto-track-event.spec.js +45 -40
- data/app/assets/spec/unit/multivariate-test.spec.js +150 -145
- data/app/assets/spec/unit/primary-links.spec.js +53 -47
- data/app/assets/spec/unit/selection-button.spec.js +701 -693
- data/app/assets/spec/unit/shim-links-with-button-role.spec.js +33 -28
- data/app/assets/spec/unit/show-hide-content.spec.js +5 -1
- data/app/assets/spec/unit/stick-at-top-when-scrolling.spec.js +104 -107
- metadata +2 -2
@@ -1,30 +1,30 @@
|
|
1
|
-
(function(global) {
|
2
|
-
|
1
|
+
;(function (global) {
|
2
|
+
'use strict'
|
3
3
|
|
4
|
-
var GOVUK = global.GOVUK || {}
|
5
|
-
GOVUK.Modules = GOVUK.Modules || {}
|
4
|
+
var GOVUK = global.GOVUK || {}
|
5
|
+
GOVUK.Modules = GOVUK.Modules || {}
|
6
6
|
|
7
|
-
GOVUK.Modules.AutoTrackEvent = function() {
|
8
|
-
this.start = function(element) {
|
9
|
-
var options = {nonInteraction: 1}
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
GOVUK.Modules.AutoTrackEvent = function () {
|
8
|
+
this.start = function (element) {
|
9
|
+
var options = { nonInteraction: 1 } // automatic events shouldn't affect bounce rate
|
10
|
+
var category = element.data('track-category')
|
11
|
+
var action = element.data('track-action')
|
12
|
+
var label = element.data('track-label')
|
13
|
+
var value = element.data('track-value')
|
14
14
|
|
15
|
-
if (typeof label ===
|
16
|
-
options.label = label
|
15
|
+
if (typeof label === 'string') {
|
16
|
+
options.label = label
|
17
17
|
}
|
18
18
|
|
19
19
|
if (value || value === 0) {
|
20
|
-
options.value = value
|
20
|
+
options.value = value
|
21
21
|
}
|
22
22
|
|
23
23
|
if (GOVUK.analytics && GOVUK.analytics.trackEvent) {
|
24
|
-
GOVUK.analytics.trackEvent(category, action, options)
|
24
|
+
GOVUK.analytics.trackEvent(category, action, options)
|
25
25
|
}
|
26
26
|
}
|
27
|
-
}
|
27
|
+
}
|
28
28
|
|
29
|
-
global.GOVUK = GOVUK
|
30
|
-
})(window)
|
29
|
+
global.GOVUK = GOVUK
|
30
|
+
})(window)
|
@@ -1,8 +1,8 @@
|
|
1
|
-
(function(global) {
|
2
|
-
|
1
|
+
;(function (global) {
|
2
|
+
'use strict'
|
3
3
|
|
4
|
-
var $ = global.jQuery
|
5
|
-
var GOVUK = global.GOVUK || {}
|
4
|
+
var $ = global.jQuery
|
5
|
+
var GOVUK = global.GOVUK || {}
|
6
6
|
|
7
7
|
// A multivariate test framework
|
8
8
|
//
|
@@ -10,72 +10,70 @@
|
|
10
10
|
//
|
11
11
|
// Full documentation is in README.md.
|
12
12
|
//
|
13
|
-
function MultivariateTest(options) {
|
14
|
-
this.$el = $(options.el)
|
15
|
-
this._loadOption(options, 'name')
|
16
|
-
this._loadOption(options, 'customDimensionIndex', null)
|
17
|
-
this._loadOption(options, 'cohorts')
|
18
|
-
this._loadOption(options, 'runImmediately', true)
|
19
|
-
this._loadOption(options, 'defaultWeight', 1)
|
20
|
-
this._loadOption(options, 'contentExperimentId', null)
|
21
|
-
this._loadOption(options, 'cookieDuration', 30)
|
13
|
+
function MultivariateTest (options) {
|
14
|
+
this.$el = $(options.el)
|
15
|
+
this._loadOption(options, 'name')
|
16
|
+
this._loadOption(options, 'customDimensionIndex', null)
|
17
|
+
this._loadOption(options, 'cohorts')
|
18
|
+
this._loadOption(options, 'runImmediately', true)
|
19
|
+
this._loadOption(options, 'defaultWeight', 1)
|
20
|
+
this._loadOption(options, 'contentExperimentId', null)
|
21
|
+
this._loadOption(options, 'cookieDuration', 30)
|
22
22
|
|
23
23
|
if (this.runImmediately) {
|
24
|
-
this.run()
|
24
|
+
this.run()
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
28
|
-
MultivariateTest.prototype._loadOption = function(options, key, defaultValue) {
|
28
|
+
MultivariateTest.prototype._loadOption = function (options, key, defaultValue) {
|
29
29
|
if (options[key] !== undefined) {
|
30
|
-
this[key] = options[key]
|
30
|
+
this[key] = options[key]
|
31
31
|
}
|
32
32
|
if (this[key] === undefined) {
|
33
33
|
if (defaultValue === undefined) {
|
34
|
-
throw new Error(key+
|
35
|
-
}
|
36
|
-
|
37
|
-
this[key] = defaultValue;
|
34
|
+
throw new Error(key + ' option is required for a multivariate test')
|
35
|
+
} else {
|
36
|
+
this[key] = defaultValue
|
38
37
|
}
|
39
38
|
}
|
40
|
-
}
|
39
|
+
}
|
41
40
|
|
42
|
-
MultivariateTest.prototype.run = function() {
|
43
|
-
var cohort = this.getCohort()
|
41
|
+
MultivariateTest.prototype.run = function () {
|
42
|
+
var cohort = this.getCohort()
|
44
43
|
if (cohort) {
|
45
|
-
this.setUpContentExperiment(cohort)
|
46
|
-
this.setCustomVar(cohort)
|
47
|
-
this.executeCohort(cohort)
|
48
|
-
this.createDummyEvent(cohort)
|
44
|
+
this.setUpContentExperiment(cohort)
|
45
|
+
this.setCustomVar(cohort)
|
46
|
+
this.executeCohort(cohort)
|
47
|
+
this.createDummyEvent(cohort)
|
49
48
|
}
|
50
|
-
}
|
49
|
+
}
|
51
50
|
|
52
|
-
MultivariateTest.prototype.executeCohort = function(cohort) {
|
53
|
-
var cohortObj = this.cohorts[cohort]
|
51
|
+
MultivariateTest.prototype.executeCohort = function (cohort) {
|
52
|
+
var cohortObj = this.cohorts[cohort]
|
54
53
|
if (cohortObj.callback) {
|
55
|
-
if (typeof cohortObj.callback ===
|
56
|
-
this[cohortObj.callback]()
|
57
|
-
}
|
58
|
-
|
59
|
-
cohortObj.callback();
|
54
|
+
if (typeof cohortObj.callback === 'string') {
|
55
|
+
this[cohortObj.callback]()
|
56
|
+
} else {
|
57
|
+
cohortObj.callback()
|
60
58
|
}
|
61
59
|
}
|
62
60
|
if (cohortObj.html) {
|
63
|
-
this.$el.html(cohortObj.html)
|
64
|
-
this.$el.show()
|
61
|
+
this.$el.html(cohortObj.html)
|
62
|
+
this.$el.show()
|
65
63
|
}
|
66
|
-
}
|
64
|
+
}
|
67
65
|
|
68
66
|
// Get the current cohort or assign one if it has not been already
|
69
|
-
MultivariateTest.prototype.getCohort = function() {
|
70
|
-
var cohort = GOVUK.cookie(this.cookieName())
|
67
|
+
MultivariateTest.prototype.getCohort = function () {
|
68
|
+
var cohort = GOVUK.cookie(this.cookieName())
|
71
69
|
if (!cohort || !this.cohorts[cohort]) {
|
72
|
-
cohort = this.chooseRandomCohort()
|
73
|
-
GOVUK.cookie(this.cookieName(), cohort, {days: this.cookieDuration})
|
70
|
+
cohort = this.chooseRandomCohort()
|
71
|
+
GOVUK.cookie(this.cookieName(), cohort, {days: this.cookieDuration})
|
74
72
|
}
|
75
|
-
return cohort
|
76
|
-
}
|
73
|
+
return cohort
|
74
|
+
}
|
77
75
|
|
78
|
-
MultivariateTest.prototype.setCustomVar = function(cohort) {
|
76
|
+
MultivariateTest.prototype.setCustomVar = function (cohort) {
|
79
77
|
if (this.customDimensionIndex &&
|
80
78
|
this.customDimensionIndex.constructor === Array) {
|
81
79
|
for (var index = 0; index < this.customDimensionIndex.length; index++) {
|
@@ -84,64 +82,64 @@
|
|
84
82
|
} else if (this.customDimensionIndex) {
|
85
83
|
this.setDimension(cohort, this.customDimensionIndex)
|
86
84
|
}
|
87
|
-
}
|
85
|
+
}
|
88
86
|
|
89
|
-
MultivariateTest.prototype.setDimension = function(cohort, dimension) {
|
87
|
+
MultivariateTest.prototype.setDimension = function (cohort, dimension) {
|
90
88
|
GOVUK.analytics.setDimension(
|
91
89
|
dimension,
|
92
|
-
this.cookieName() +
|
93
|
-
)
|
94
|
-
}
|
95
|
-
|
96
|
-
MultivariateTest.prototype.setUpContentExperiment = function(cohort) {
|
97
|
-
var contentExperimentId = this.contentExperimentId
|
98
|
-
var cohortVariantId = this.cohorts[cohort]['variantId']
|
99
|
-
if(typeof contentExperimentId !== 'undefined' &&
|
90
|
+
this.cookieName() + '__' + cohort
|
91
|
+
)
|
92
|
+
}
|
93
|
+
|
94
|
+
MultivariateTest.prototype.setUpContentExperiment = function (cohort) {
|
95
|
+
var contentExperimentId = this.contentExperimentId
|
96
|
+
var cohortVariantId = this.cohorts[cohort]['variantId']
|
97
|
+
if (typeof contentExperimentId !== 'undefined' &&
|
100
98
|
typeof cohortVariantId !== 'undefined' &&
|
101
|
-
typeof window.ga ===
|
102
|
-
window.ga('set', 'expId', contentExperimentId)
|
103
|
-
window.ga('set', 'expVar', cohortVariantId)
|
99
|
+
typeof window.ga === 'function') {
|
100
|
+
window.ga('set', 'expId', contentExperimentId)
|
101
|
+
window.ga('set', 'expVar', cohortVariantId)
|
104
102
|
};
|
105
|
-
}
|
103
|
+
}
|
106
104
|
|
107
|
-
MultivariateTest.prototype.createDummyEvent = function(cohort) {
|
105
|
+
MultivariateTest.prototype.createDummyEvent = function (cohort) {
|
108
106
|
// Fire off a dummy event to set the custom var and the content experiment on the page.
|
109
107
|
// Ideally we'd be able to call setCustomVar before trackPageview,
|
110
108
|
// but would need reordering the existing GA code.
|
111
|
-
GOVUK.analytics.trackEvent(this.cookieName(), 'run', {nonInteraction:true})
|
112
|
-
}
|
109
|
+
GOVUK.analytics.trackEvent(this.cookieName(), 'run', {nonInteraction: true})
|
110
|
+
}
|
113
111
|
|
114
|
-
MultivariateTest.prototype.weightedCohortNames = function() {
|
115
|
-
var names = []
|
116
|
-
|
112
|
+
MultivariateTest.prototype.weightedCohortNames = function () {
|
113
|
+
var names = []
|
114
|
+
var defaultWeight = this.defaultWeight
|
117
115
|
|
118
|
-
$.each(this.cohorts, function(key, cohortSettings) {
|
119
|
-
var numberForCohort, i
|
116
|
+
$.each(this.cohorts, function (key, cohortSettings) {
|
117
|
+
var numberForCohort, i
|
120
118
|
|
121
|
-
if (typeof cohortSettings.weight === 'undefined'){
|
122
|
-
numberForCohort = defaultWeight
|
119
|
+
if (typeof cohortSettings.weight === 'undefined') {
|
120
|
+
numberForCohort = defaultWeight
|
123
121
|
} else {
|
124
|
-
numberForCohort = cohortSettings.weight
|
122
|
+
numberForCohort = cohortSettings.weight
|
125
123
|
}
|
126
124
|
|
127
|
-
for(i=0; i<numberForCohort; i++){
|
128
|
-
names.push(key)
|
125
|
+
for (i = 0; i < numberForCohort; i++) {
|
126
|
+
names.push(key)
|
129
127
|
}
|
130
|
-
})
|
128
|
+
})
|
131
129
|
|
132
|
-
return names
|
133
|
-
}
|
130
|
+
return names
|
131
|
+
}
|
134
132
|
|
135
|
-
MultivariateTest.prototype.chooseRandomCohort = function() {
|
136
|
-
var names = this.weightedCohortNames()
|
137
|
-
return names[Math.floor(Math.random() * names.length)]
|
138
|
-
}
|
133
|
+
MultivariateTest.prototype.chooseRandomCohort = function () {
|
134
|
+
var names = this.weightedCohortNames()
|
135
|
+
return names[Math.floor(Math.random() * names.length)]
|
136
|
+
}
|
139
137
|
|
140
|
-
MultivariateTest.prototype.cookieName = function() {
|
141
|
-
return
|
142
|
-
}
|
138
|
+
MultivariateTest.prototype.cookieName = function () {
|
139
|
+
return 'multivariatetest_cohort_' + this.name
|
140
|
+
}
|
143
141
|
|
144
|
-
GOVUK.MultivariateTest = MultivariateTest
|
142
|
+
GOVUK.MultivariateTest = MultivariateTest
|
145
143
|
|
146
|
-
global.GOVUK = GOVUK
|
147
|
-
})(window)
|
144
|
+
global.GOVUK = GOVUK
|
145
|
+
})(window)
|
@@ -1,56 +1,57 @@
|
|
1
|
-
(function(global) {
|
2
|
-
|
1
|
+
;(function (global) {
|
2
|
+
'use strict'
|
3
3
|
|
4
|
-
var $ = global.jQuery
|
5
|
-
var GOVUK = global.GOVUK || {}
|
4
|
+
var $ = global.jQuery
|
5
|
+
var GOVUK = global.GOVUK || {}
|
6
6
|
|
7
7
|
// Only show the first {n} items in a list, documentation is in the README.md
|
8
|
-
var PrimaryList = function(el, selector){
|
9
|
-
this.$el = $(el)
|
10
|
-
this.$extraLinks = this.$el.find('li:not('+selector+')')
|
8
|
+
var PrimaryList = function (el, selector) {
|
9
|
+
this.$el = $(el)
|
10
|
+
this.$extraLinks = this.$el.find('li:not(' + selector + ')')
|
11
11
|
// only hide more than one extra link
|
12
|
-
if(this.$extraLinks.length > 1){
|
13
|
-
this.addToggleLink()
|
14
|
-
this.hideExtraLinks()
|
12
|
+
if (this.$extraLinks.length > 1) {
|
13
|
+
this.addToggleLink()
|
14
|
+
this.hideExtraLinks()
|
15
15
|
}
|
16
|
-
}
|
16
|
+
}
|
17
|
+
|
17
18
|
PrimaryList.prototype = {
|
18
|
-
toggleText: function(){
|
19
|
-
if(this.$extraLinks.length > 1){
|
20
|
-
return '+'+ this.$extraLinks.length +' others'
|
19
|
+
toggleText: function () {
|
20
|
+
if (this.$extraLinks.length > 1) {
|
21
|
+
return '+' + this.$extraLinks.length + ' others'
|
21
22
|
} else {
|
22
|
-
return '+'+ this.$extraLinks.length +' other'
|
23
|
+
return '+' + this.$extraLinks.length + ' other'
|
23
24
|
}
|
24
25
|
},
|
25
|
-
addToggleLink: function(){
|
26
|
-
this.$toggleLink = $('<a href="#">'+ this.toggleText() + '</a>')
|
27
|
-
this.$toggleLink.click($.proxy(this.toggleLinks, this))
|
28
|
-
this.$toggleLink.insertAfter(this.$el)
|
26
|
+
addToggleLink: function () {
|
27
|
+
this.$toggleLink = $('<a href="#">' + this.toggleText() + '</a>')
|
28
|
+
this.$toggleLink.click($.proxy(this.toggleLinks, this))
|
29
|
+
this.$toggleLink.insertAfter(this.$el)
|
29
30
|
},
|
30
|
-
toggleLinks: function(e){
|
31
|
-
e.preventDefault()
|
32
|
-
this.$toggleLink.remove()
|
33
|
-
this.showExtraLinks()
|
31
|
+
toggleLinks: function (e) {
|
32
|
+
e.preventDefault()
|
33
|
+
this.$toggleLink.remove()
|
34
|
+
this.showExtraLinks()
|
34
35
|
},
|
35
|
-
hideExtraLinks: function(){
|
36
|
-
this.$extraLinks.addClass('visuallyhidden')
|
37
|
-
$(window).trigger('govuk.pageSizeChanged')
|
36
|
+
hideExtraLinks: function () {
|
37
|
+
this.$extraLinks.addClass('visuallyhidden')
|
38
|
+
$(window).trigger('govuk.pageSizeChanged')
|
38
39
|
},
|
39
|
-
showExtraLinks: function(){
|
40
|
-
this.$extraLinks.removeClass('visuallyhidden')
|
41
|
-
$(window).trigger('govuk.pageSizeChanged')
|
40
|
+
showExtraLinks: function () {
|
41
|
+
this.$extraLinks.removeClass('visuallyhidden')
|
42
|
+
$(window).trigger('govuk.pageSizeChanged')
|
42
43
|
}
|
43
|
-
}
|
44
|
+
}
|
44
45
|
|
45
|
-
GOVUK.PrimaryList = PrimaryList
|
46
|
+
GOVUK.PrimaryList = PrimaryList
|
46
47
|
|
47
48
|
GOVUK.primaryLinks = {
|
48
|
-
init: function(selector){
|
49
|
-
$(selector).parent().each(function(i, el){
|
50
|
-
new GOVUK.PrimaryList(el, selector)
|
51
|
-
})
|
49
|
+
init: function (selector) {
|
50
|
+
$(selector).parent().each(function (i, el) {
|
51
|
+
new GOVUK.PrimaryList(el, selector) // eslint-disable-line no-new
|
52
|
+
})
|
52
53
|
}
|
53
|
-
}
|
54
|
+
}
|
54
55
|
|
55
|
-
global.GOVUK = GOVUK
|
56
|
-
})(window)
|
56
|
+
global.GOVUK = GOVUK
|
57
|
+
})(window)
|
@@ -1,113 +1,112 @@
|
|
1
|
-
(function (global) {
|
2
|
-
|
1
|
+
;(function (global) {
|
2
|
+
'use strict'
|
3
3
|
|
4
|
-
var $ = global.jQuery
|
5
|
-
var GOVUK = global.GOVUK || {}
|
4
|
+
var $ = global.jQuery
|
5
|
+
var GOVUK = global.GOVUK || {}
|
6
6
|
|
7
7
|
var SelectionButtons = function (elmsOrSelector, opts) {
|
8
|
-
|
9
|
-
this.
|
10
|
-
this.
|
11
|
-
this.
|
12
|
-
this.checkboxClass = 'selection-button-checkbox';
|
8
|
+
this.selectedClass = 'selected'
|
9
|
+
this.focusedClass = 'focused'
|
10
|
+
this.radioClass = 'selection-button-radio'
|
11
|
+
this.checkboxClass = 'selection-button-checkbox'
|
13
12
|
if (opts !== undefined) {
|
14
13
|
$.each(opts, function (optionName, optionObj) {
|
15
|
-
this[optionName] = optionObj
|
16
|
-
}.bind(this))
|
14
|
+
this[optionName] = optionObj
|
15
|
+
}.bind(this))
|
17
16
|
}
|
18
17
|
if (typeof elmsOrSelector === 'string') {
|
19
|
-
this.selector = elmsOrSelector
|
20
|
-
this.setInitialState($(this.selector))
|
18
|
+
this.selector = elmsOrSelector
|
19
|
+
this.setInitialState($(this.selector))
|
21
20
|
} else if (elmsOrSelector !== undefined) {
|
22
|
-
this.$elms = elmsOrSelector
|
23
|
-
this.setInitialState(this.$elms)
|
21
|
+
this.$elms = elmsOrSelector
|
22
|
+
this.setInitialState(this.$elms)
|
24
23
|
}
|
25
|
-
this.addEvents()
|
26
|
-
}
|
24
|
+
this.addEvents()
|
25
|
+
}
|
27
26
|
SelectionButtons.prototype.addEvents = function () {
|
28
27
|
if (typeof this.$elms !== 'undefined') {
|
29
|
-
this.addElementLevelEvents()
|
28
|
+
this.addElementLevelEvents()
|
30
29
|
} else {
|
31
|
-
this.addDocumentLevelEvents()
|
30
|
+
this.addDocumentLevelEvents()
|
32
31
|
}
|
33
|
-
}
|
32
|
+
}
|
34
33
|
SelectionButtons.prototype.setInitialState = function ($elms) {
|
35
34
|
$elms.each(function (idx, elm) {
|
36
|
-
var $elm = $(elm)
|
35
|
+
var $elm = $(elm)
|
37
36
|
|
38
|
-
var labelClass = $elm.attr('type') === 'radio' ? this.radioClass : this.checkboxClass
|
39
|
-
$elm.parent('label').addClass(labelClass)
|
37
|
+
var labelClass = $elm.attr('type') === 'radio' ? this.radioClass : this.checkboxClass
|
38
|
+
$elm.parent('label').addClass(labelClass)
|
40
39
|
if ($elm.is(':checked')) {
|
41
|
-
this.markSelected($elm)
|
40
|
+
this.markSelected($elm)
|
42
41
|
}
|
43
|
-
}.bind(this))
|
44
|
-
}
|
42
|
+
}.bind(this))
|
43
|
+
}
|
45
44
|
SelectionButtons.prototype.markFocused = function ($elm, state) {
|
46
45
|
if (state === 'focused') {
|
47
|
-
$elm.parent('label').addClass(this.focusedClass)
|
46
|
+
$elm.parent('label').addClass(this.focusedClass)
|
48
47
|
} else {
|
49
|
-
$elm.parent('label').removeClass(this.focusedClass)
|
48
|
+
$elm.parent('label').removeClass(this.focusedClass)
|
50
49
|
}
|
51
|
-
}
|
50
|
+
}
|
52
51
|
SelectionButtons.prototype.markSelected = function ($elm) {
|
53
|
-
var radioName
|
52
|
+
var radioName
|
54
53
|
|
55
54
|
if ($elm.attr('type') === 'radio') {
|
56
|
-
radioName = $elm.attr('name')
|
55
|
+
radioName = $elm.attr('name')
|
57
56
|
$($elm[0].form).find('input[name="' + radioName + '"]')
|
58
57
|
.parent('label')
|
59
|
-
.removeClass(this.selectedClass)
|
60
|
-
$elm.parent('label').addClass(this.selectedClass)
|
58
|
+
.removeClass(this.selectedClass)
|
59
|
+
$elm.parent('label').addClass(this.selectedClass)
|
61
60
|
} else { // checkbox
|
62
61
|
if ($elm.is(':checked')) {
|
63
|
-
$elm.parent('label').addClass(this.selectedClass)
|
62
|
+
$elm.parent('label').addClass(this.selectedClass)
|
64
63
|
} else {
|
65
|
-
$elm.parent('label').removeClass(this.selectedClass)
|
64
|
+
$elm.parent('label').removeClass(this.selectedClass)
|
66
65
|
}
|
67
66
|
}
|
68
|
-
}
|
67
|
+
}
|
69
68
|
SelectionButtons.prototype.addElementLevelEvents = function () {
|
70
|
-
this.clickHandler = this.getClickHandler()
|
71
|
-
this.focusHandler = this.getFocusHandler({ 'level'
|
69
|
+
this.clickHandler = this.getClickHandler()
|
70
|
+
this.focusHandler = this.getFocusHandler({ 'level': 'element' })
|
72
71
|
|
73
72
|
this.$elms
|
74
73
|
.on('click', this.clickHandler)
|
75
|
-
.on('focus blur', this.focusHandler)
|
76
|
-
}
|
74
|
+
.on('focus blur', this.focusHandler)
|
75
|
+
}
|
77
76
|
SelectionButtons.prototype.addDocumentLevelEvents = function () {
|
78
|
-
this.clickHandler = this.getClickHandler()
|
79
|
-
this.focusHandler = this.getFocusHandler({ 'level'
|
77
|
+
this.clickHandler = this.getClickHandler()
|
78
|
+
this.focusHandler = this.getFocusHandler({ 'level': 'document' })
|
80
79
|
|
81
80
|
$(document)
|
82
81
|
.on('click', this.selector, this.clickHandler)
|
83
|
-
.on('focus blur', this.selector, this.focusHandler)
|
84
|
-
}
|
82
|
+
.on('focus blur', this.selector, this.focusHandler)
|
83
|
+
}
|
85
84
|
SelectionButtons.prototype.getClickHandler = function () {
|
86
85
|
return function (e) {
|
87
|
-
this.markSelected($(e.target))
|
88
|
-
}.bind(this)
|
89
|
-
}
|
86
|
+
this.markSelected($(e.target))
|
87
|
+
}.bind(this)
|
88
|
+
}
|
90
89
|
SelectionButtons.prototype.getFocusHandler = function (opts) {
|
91
|
-
var focusEvent = (opts.level === 'document') ? 'focusin' : 'focus'
|
90
|
+
var focusEvent = (opts.level === 'document') ? 'focusin' : 'focus'
|
92
91
|
|
93
92
|
return function (e) {
|
94
|
-
var state = (e.type === focusEvent) ? 'focused' : 'blurred'
|
93
|
+
var state = (e.type === focusEvent) ? 'focused' : 'blurred'
|
95
94
|
|
96
|
-
this.markFocused($(e.target), state)
|
97
|
-
}.bind(this)
|
98
|
-
}
|
95
|
+
this.markFocused($(e.target), state)
|
96
|
+
}.bind(this)
|
97
|
+
}
|
99
98
|
SelectionButtons.prototype.destroy = function () {
|
100
99
|
if (typeof this.selector !== 'undefined') {
|
101
100
|
$(document)
|
102
101
|
.off('click', this.selector, this.clickHandler)
|
103
|
-
.off('focus blur', this.selector, this.focusHandler)
|
102
|
+
.off('focus blur', this.selector, this.focusHandler)
|
104
103
|
} else {
|
105
104
|
this.$elms
|
106
105
|
.off('click', this.clickHandler)
|
107
|
-
.off('focus blur', this.focusHandler)
|
106
|
+
.off('focus blur', this.focusHandler)
|
108
107
|
}
|
109
|
-
}
|
108
|
+
}
|
110
109
|
|
111
|
-
GOVUK.SelectionButtons = SelectionButtons
|
112
|
-
global.GOVUK = GOVUK
|
113
|
-
})(window)
|
110
|
+
GOVUK.SelectionButtons = SelectionButtons
|
111
|
+
global.GOVUK = GOVUK
|
112
|
+
})(window)
|