govuk_publishing_components 9.4.0 → 9.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/admin_scripts.js +4 -0
  3. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +57 -86
  4. data/app/assets/stylesheets/component_guide/application.scss +0 -10
  5. data/app/assets/stylesheets/govuk_publishing_components/admin_styles.scss +3 -2
  6. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss +30 -0
  7. data/app/assets/stylesheets/govuk_publishing_components/components/_previous-and-next-navigation.scss +11 -31
  8. data/app/assets/stylesheets/govuk_publishing_components/components/_skip-link.scss +1 -0
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +1 -70
  10. data/app/views/govuk_publishing_components/component_guide/show.html.erb +3 -6
  11. data/app/views/govuk_publishing_components/components/_contextual_breadcrumbs.html.erb +23 -21
  12. data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +22 -20
  13. data/app/views/govuk_publishing_components/components/_government_navigation.html.erb +1 -1
  14. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +1 -1
  15. data/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb +5 -2
  16. data/app/views/govuk_publishing_components/components/_layout_header.html.erb +48 -0
  17. data/app/views/govuk_publishing_components/components/_notice.html.erb +2 -2
  18. data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +6 -2
  19. data/app/views/govuk_publishing_components/components/_skip_link.html.erb +4 -0
  20. data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +0 -7
  21. data/app/views/govuk_publishing_components/components/docs/layout_for_admin.yml +1 -0
  22. data/app/views/govuk_publishing_components/components/docs/layout_header.yml +57 -0
  23. data/app/views/govuk_publishing_components/components/docs/notice.yml +4 -0
  24. data/app/views/govuk_publishing_components/components/docs/skip_link.yml +16 -0
  25. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml +1 -190
  26. data/app/views/layouts/govuk_publishing_components/application.html.erb +3 -0
  27. data/config/initializers/assets.rb +2 -0
  28. data/lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb +0 -26
  29. data/lib/govuk_publishing_components/version.rb +1 -1
  30. metadata +9 -3
  31. data/app/assets/javascripts/govuk_publishing_components/lib/history-support.js +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17673b0fafadbf9937d4a6df90dfe194a19c8a83a7a0a8c2dbe65be551402f64
4
- data.tar.gz: 5146a665a20166d526cb1a6b4f78dc333800d0e421a847515e3f1574d7f43784
3
+ metadata.gz: ed9cfca2bbf3caf1dca0acaac01d1aed13fcf8e5037af8291e001fa40ee71fc8
4
+ data.tar.gz: 72dde8c41cf29d1d10a4639a38403badb66e2ad6d3e15151790add92506901ac
5
5
  SHA512:
6
- metadata.gz: a95e67dc05e77c76c2d537330a94884fc5feced188d3e0fefac35c2e130fa6a239ec7235cc6374be4907e84bed6cf2e8006b2ace9fd4f4e06ba24ccfb0a58a09
7
- data.tar.gz: f1ae0591b02e3a4ddca6ee7a45e47cb44c62322eabe5ca9292162cd73db19368fdc81d7ccf225628b9396512933261a127b1bb2af8bf47bb20c9e7c050e8dd18
6
+ metadata.gz: f558e44d99267415e7cd3cb42a00584bc45152d88bdf0f4772b15fea2f50d60ca96a8b967dab8589f54c7fe2c6b371ea02cdcc63b0b831cdc5199dce0c0aab9d
7
+ data.tar.gz: 1a500eaf9859acc22d0030e05e9082fbdc272e1a698e54029cf432520374139f7570a60d8df9ac347390d646bdc62f93403c0258fedc3c23b26014976f9c2e1b
@@ -0,0 +1,4 @@
1
+ //= require all.js
2
+
3
+ // Initialise all GOVUKFrontend components
4
+ window.GOVUKFrontend.initAll()
@@ -10,27 +10,25 @@
10
10
  var sessionStoreLink = 'govuk-step-nav-active-link';
11
11
  var activeLinkClass = 'gem-c-step-nav__list-item--active';
12
12
  var activeLinkHref = '#content';
13
+ var uniqueId;
13
14
 
14
15
  this.start = function ($element) {
15
16
 
16
- $(window).unload(storeScrollPosition);
17
-
18
17
  // Indicate that js has worked
19
18
  $element.addClass('gem-c-step-nav--active');
20
19
 
21
20
  // Prevent FOUC, remove class hiding content
22
21
  $element.removeClass('js-hidden');
23
22
 
24
- rememberShownStep = !!$element.filter('[data-remember]').length;
25
23
  stepNavSize = $element.hasClass('gem-c-step-nav--large') ? 'Big' : 'Small';
24
+ rememberShownStep = !!$element.filter('[data-remember]').length && stepNavSize == 'Big';
26
25
  var $steps = $element.find('.js-step');
27
26
  var $stepHeaders = $element.find('.js-toggle-panel');
28
27
  var totalSteps = $element.find('.js-panel').length;
29
28
  var totalLinks = $element.find('.gem-c-step-nav__link').length;
30
-
31
29
  var $showOrHideAllButton;
32
30
 
33
- var uniqueId = $element.data('id') || false;
31
+ uniqueId = $element.data('id') || false;
34
32
  var stepNavTracker = new StepNavTracker(totalSteps, totalLinks, uniqueId);
35
33
 
36
34
  getTextForInsertedElements();
@@ -39,8 +37,7 @@
39
37
  addShowHideToggle();
40
38
  addAriaControlsAttrForShowHideAllButton();
41
39
 
42
- hideAllSteps();
43
- showLinkedStep();
40
+ showPreviouslyOpenedSteps();
44
41
  ensureOnlyOneActiveLink();
45
42
 
46
43
  bindToggleForSteps(stepNavTracker);
@@ -54,24 +51,6 @@
54
51
  actions.hideAllText = $element.attr('data-hide-all-text');
55
52
  }
56
53
 
57
- // When navigating back in browser history to the step nav, the browser will try to be "clever" and return
58
- // the user to their previous scroll position. However, since we collapse all but the currently-anchored
59
- // step, the content length changes and the user is returned to the wrong position (often the footer).
60
- // In order to correct this behaviour, as the user leaves the page, we anticipate the correct height we wish the
61
- // user to return to by forcibly scrolling them to that height, which becomes the height the browser will return
62
- // them to.
63
- // If we can't find an element to return them to, then reset the scroll to the top of the page. This handles
64
- // the case where the user has expanded all steps, so they are not returned to a particular step, but
65
- // still could have scrolled a long way down the page.
66
- function storeScrollPosition() {
67
- hideAllSteps();
68
- var $step = getStepForAnchor();
69
-
70
- document.body.scrollTop = $step && $step.length
71
- ? $step.offset().top
72
- : 0;
73
- }
74
-
75
54
  function addShowHideAllButton() {
76
55
  $element.prepend('<div class="gem-c-step-nav__controls"><button aria-expanded="false" class="gem-c-step-nav__button gem-c-step-nav__button--controls js-step-controls-button">' + actions.showAllText + '</button></div>');
77
56
  }
@@ -83,6 +62,7 @@
83
62
  if (headerIsOpen($(this))) {
84
63
  linkText = actions.hideText;
85
64
  }
65
+
86
66
  if (!$(this).find('.js-toggle-link').length) {
87
67
  $(this).find('.js-step-title-button').append('<span class="gem-c-step-nav__toggle-link js-toggle-link" aria-hidden="true">' + linkText + '</span>');
88
68
  }
@@ -100,42 +80,46 @@
100
80
  $showOrHideAllButton.attr('aria-controls', ariaControlsValue);
101
81
  }
102
82
 
103
- function hideAllSteps() {
104
- setAllStepsShownState(false);
105
- }
106
-
83
+ // called by show all/hide all, sets all steps accordingly
107
84
  function setAllStepsShownState(isShown) {
85
+ var data = [];
86
+
108
87
  $.each($steps, function () {
109
88
  var stepView = new StepView($(this));
110
- stepView.preventHashUpdate();
111
89
  stepView.setIsShown(isShown);
90
+
91
+ if (isShown) {
92
+ data.push($(this).attr('id'));
93
+ }
112
94
  });
113
- }
114
95
 
115
- function showLinkedStep() {
116
- var $step;
117
- if (rememberShownStep) {
118
- $step = getStepForAnchor();
96
+ if (isShown) {
97
+ saveToSessionStorage(uniqueId, JSON.stringify(data));
119
98
  } else {
120
- $step = $steps.filter('[data-show]');
121
- }
122
-
123
- if ($step && $step.length) {
124
- var stepView = new StepView($step);
125
- stepView.show();
99
+ removeFromSessionStorage(uniqueId);
126
100
  }
127
101
  }
128
102
 
129
- function getStepForAnchor() {
130
- var anchor = getActiveAnchor();
103
+ // called on load, determines whether each step should be open or closed
104
+ function showPreviouslyOpenedSteps() {
105
+ var data = loadFromSessionStorage(uniqueId) || [];
131
106
 
132
- return anchor.length
133
- ? $element.find('#' + escapeSelector(anchor.substr(1)))
134
- : null;
135
- }
107
+ $.each($steps, function() {
108
+ var id = $(this).attr('id');
109
+ var stepView = new StepView($(this));
110
+
111
+ // show the step if it has been remembered or if it has the 'data-show' attribute
112
+ if ((rememberShownStep && data.indexOf(id) > -1) || typeof $(this).attr('data-show') !== "undefined") {
113
+ stepView.setIsShown(true);
114
+ } else {
115
+ stepView.setIsShown(false);
116
+ }
117
+ });
136
118
 
137
- function getActiveAnchor() {
138
- return GOVUK.getCurrentLocation().hash;
119
+ if (data.length > 0) {
120
+ $showOrHideAllButton.attr('aria-expanded', true);
121
+ setShowHideAllText();
122
+ }
139
123
  }
140
124
 
141
125
  function addButtonstoSteps() {
@@ -169,9 +153,30 @@
169
153
  toggleClick.track();
170
154
 
171
155
  setShowHideAllText();
156
+ rememberStepState($step);
172
157
  });
173
158
  }
174
159
 
160
+ // if the step is open, store its id in session store
161
+ // if the step is closed, remove its id from session store
162
+ function rememberStepState($step) {
163
+ if (rememberShownStep) {
164
+ var data = JSON.parse(loadFromSessionStorage(uniqueId)) || [];
165
+ var thisstep = $step.attr('id');
166
+ var shown = $step.hasClass('step-is-shown');
167
+
168
+ if (shown) {
169
+ data.push(thisstep);
170
+ } else {
171
+ var i = data.indexOf(thisstep);
172
+ if (i > -1) {
173
+ data.splice(i, 1);
174
+ }
175
+ }
176
+ saveToSessionStorage(uniqueId, JSON.stringify(data));
177
+ }
178
+ }
179
+
175
180
  // tracking click events on links in step content
176
181
  function bindComponentLinkClicks(stepNavTracker) {
177
182
  $element.find('.js-link').click(function (event) {
@@ -245,7 +250,7 @@
245
250
 
246
251
  if ($showOrHideAllButton.text() == actions.showAllText) {
247
252
  $showOrHideAllButton.text(actions.hideAllText);
248
- $element.find('.js-toggle-link').text(actions.hideText)
253
+ $element.find('.js-toggle-link').text(actions.hideText);
249
254
  shouldshowAll = true;
250
255
 
251
256
  stepNavTracker.track('pageElementInteraction', 'stepNavAllShown', {
@@ -264,7 +269,6 @@
264
269
  setAllStepsShownState(shouldshowAll);
265
270
  $showOrHideAllButton.attr('aria-expanded', shouldshowAll);
266
271
  setShowHideAllText();
267
- setHash(null);
268
272
 
269
273
  return false;
270
274
  });
@@ -279,19 +283,11 @@
279
283
  $showOrHideAllButton.text(actions.showAllText);
280
284
  }
281
285
  }
282
-
283
- // Ideally we'd use jQuery.escapeSelector, but this is only available from v3
284
- // See https://github.com/jquery/jquery/blob/2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce/src/selector-native.js#L46
285
- function escapeSelector(s) {
286
- var cssMatcher = /([\x00-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g;
287
- return s.replace(cssMatcher, "\\$&");
288
- }
289
286
  };
290
287
 
291
288
  function StepView($stepElement) {
292
289
  var $titleLink = $stepElement.find('.js-step-title-button');
293
290
  var $stepContent = $stepElement.find('.js-panel');
294
- var shouldUpdateHash = rememberShownStep;
295
291
 
296
292
  this.title = $stepElement.find('.js-step-title-text').text().trim();
297
293
  this.element = $stepElement;
@@ -302,7 +298,6 @@
302
298
  this.setIsShown = setIsShown;
303
299
  this.isShown = isShown;
304
300
  this.isHidden = isHidden;
305
- this.preventHashUpdate = preventHashUpdate;
306
301
  this.numberOfContentItems = numberOfContentItems;
307
302
 
308
303
  function show() {
@@ -322,10 +317,6 @@
322
317
  $stepContent.toggleClass('js-hidden', !isShown);
323
318
  $titleLink.attr("aria-expanded", isShown);
324
319
  $stepElement.find('.js-toggle-link').text(isShown ? actions.hideText : actions.showText);
325
-
326
- if (shouldUpdateHash) {
327
- updateHash($stepElement);
328
- }
329
320
  }
330
321
 
331
322
  function isShown() {
@@ -336,37 +327,17 @@
336
327
  return !isShown();
337
328
  }
338
329
 
339
- function preventHashUpdate() {
340
- shouldUpdateHash = false;
341
- }
342
-
343
330
  function numberOfContentItems() {
344
331
  return $stepContent.find('.js-link').length;
345
332
  }
346
333
  }
347
334
 
348
- function updateHash($stepElement) {
349
- var stepView = new StepView($stepElement);
350
- var hash = stepView.isShown() && '#' + $stepElement.attr('id');
351
- setHash(hash)
352
- }
353
-
354
- // Sets the hash for the page. If a falsy value is provided, the hash is cleared.
355
- function setHash(hash) {
356
- if (!GOVUK.support.history()) {
357
- return;
358
- }
359
-
360
- var newLocation = hash || GOVUK.getCurrentLocation().pathname;
361
- history.replaceState({}, '', newLocation);
362
- }
363
-
364
335
  function StepToggleClick(event, stepView, $steps, stepNavTracker, stepIsOptional) {
365
336
  this.track = trackClick;
366
337
  var $target = $(event.target);
367
338
 
368
339
  function trackClick() {
369
- var tracking_options = {label: trackingLabel(), dimension28: stepView.numberOfContentItems().toString()}
340
+ var tracking_options = {label: trackingLabel(), dimension28: stepView.numberOfContentItems().toString()};
370
341
  stepNavTracker.track('pageElementInteraction', trackingAction(), tracking_options);
371
342
  }
372
343
 
@@ -439,7 +410,7 @@
439
410
  options["dimension96"] = options["dimension96"] || uniqueId;
440
411
  GOVUK.analytics.trackEvent(category, action, options);
441
412
  }
442
- }
413
+ };
443
414
  }
444
415
  };
445
416
  })(window.GOVUK.Modules);
@@ -50,16 +50,6 @@ $border-color: #ccc;
50
50
  }
51
51
  }
52
52
 
53
- .component-warning {
54
- border: 3px solid $orange;
55
- margin: 0 0 $gutter;
56
- padding: $gutter $gutter 0 $gutter;
57
-
58
- .component-warning__title {
59
- @include bold-24;
60
- }
61
- }
62
-
63
53
  .component-doc-h2 {
64
54
  @include bold-27;
65
55
  margin: ($gutter * 1.5) 0 $gutter;
@@ -1,8 +1,8 @@
1
1
  // Include all of the GOV.UK Frontend styles. This includes global styles, fonts,
2
2
  // and individual components.
3
3
  $govuk-global-styles: true;
4
- $govuk-image-url-function: 'image-url';
5
- $govuk-font-url-function: 'font-url';
4
+ $govuk-image-url-function: "image-url";
5
+ $govuk-font-url-function: "font-url";
6
6
 
7
7
  @import "../../../node_modules/govuk-frontend/all";
8
8
 
@@ -11,3 +11,4 @@ $govuk-font-url-function: 'font-url';
11
11
 
12
12
  // Components that are only available inside the admin layout
13
13
  @import "govuk_publishing_components/components/layout-footer";
14
+ @import "govuk_publishing_components/components/layout-header";
@@ -0,0 +1,30 @@
1
+ // This component relies on styles from GOV.UK Frontend
2
+
3
+ .gem-c-layout-header--integration .govuk-header__container,
4
+ .gem-c-layout-header--staging .govuk-header__container {
5
+ border-bottom-color: govuk-colour("yellow");
6
+ }
7
+
8
+ .gem-c-layout-header--development .govuk-header__container {
9
+ border-bottom-color: govuk-colour("grey-1");
10
+ }
11
+
12
+ // Fix header component's reliance on markup whitespace
13
+ // https://github.com/alphagov/govuk-frontend/pull/884/files
14
+ //
15
+ // Remove this fix after updating to GOV.UK Frontend 1.1.0
16
+ .govuk-header__container {
17
+ @include govuk-clearfix;
18
+ }
19
+
20
+ .govuk-header__logo {
21
+ @include mq ($from: desktop) {
22
+ float: left;
23
+ }
24
+ }
25
+
26
+ .govuk-header__content {
27
+ @include mq ($from: desktop) {
28
+ float: left;
29
+ }
30
+ }
@@ -6,23 +6,9 @@
6
6
  margin-right: -$gutter-half;
7
7
  }
8
8
 
9
- .gem-c-pagination__list {
10
- margin: 0;
11
- padding: 0;
12
-
13
- &:after {
14
- content: "";
15
- display: block;
16
- clear: both;
17
- }
18
- }
19
-
20
9
  .gem-c-pagination__item {
21
10
  @include core-16($line-height: (20 / 16));
22
11
  list-style: none;
23
- text-align: right;
24
- margin: 0;
25
- padding: 0;
26
12
  }
27
13
 
28
14
  .gem-c-pagination__link {
@@ -30,6 +16,8 @@
30
16
  padding: $gutter-half;
31
17
  text-decoration: none;
32
18
 
19
+ &:hover,
20
+ &:active,
33
21
  &:visited {
34
22
  color: $link-colour;
35
23
  }
@@ -41,29 +29,16 @@
41
29
  }
42
30
 
43
31
  .gem-c-pagination__link-title {
44
- @include core-27($line-height: (33.75 / 27));
45
32
  display: block;
46
33
  }
47
34
 
48
- .gem-c-pagination__item--previous {
49
- text-align: left;
50
-
51
- @include media(tablet) {
52
- float: left;
53
- width: 50%;
54
- }
55
- }
56
-
57
- .gem-c-pagination__item--next {
58
- text-align: right;
59
-
60
- @include media(tablet) {
61
- float: right;
62
- width: 50%;
63
- }
35
+ .gem-c-pagination__link-text {
36
+ @include bold-19;
37
+ margin-left: $gutter / 3;
64
38
  }
65
39
 
66
40
  .gem-c-pagination__link-icon {
41
+ @include core-24($line-height: (33.75 / 27));
67
42
  display: inline-block;
68
43
  margin-bottom: 1px;
69
44
  height: .482em;
@@ -74,4 +49,9 @@
74
49
  display: inline-block;
75
50
  margin-top: 0.1em;
76
51
  text-decoration: underline;
52
+ margin-left: $gutter;
53
+
54
+ @include media(mobile) {
55
+ margin-left: $gutter-half + 9;
56
+ }
77
57
  }
@@ -0,0 +1 @@
1
+ // This component relies on styles from GOV.UK Frontend
@@ -159,7 +159,6 @@ $top-border: solid 2px $grey-3;
159
159
  &:last-child:before,
160
160
  .gem-c-step-nav__circle--number,
161
161
  &:after,
162
- .gem-c-step-nav__substep:after,
163
162
  .gem-c-step-nav__help:after {
164
163
  border-color: $black;
165
164
  }
@@ -280,8 +279,7 @@ $top-border: solid 2px $grey-3;
280
279
 
281
280
  // contents of the steps, such as paragraphs and links
282
281
 
283
- .gem-c-step-nav__paragraph,
284
- .gem-c-step-nav__heading {
282
+ .gem-c-step-nav__paragraph {
285
283
  padding-bottom: $gutter-half;
286
284
  margin: 0;
287
285
  font-size: inherit;
@@ -303,10 +301,6 @@ $top-border: solid 2px $grey-3;
303
301
  }
304
302
  }
305
303
 
306
- .gem-c-step-nav__heading {
307
- font-weight: bold;
308
- }
309
-
310
304
  .gem-c-step-nav__list {
311
305
  padding: 0;
312
306
  padding-bottom: 10px;
@@ -390,66 +384,3 @@ $top-border: solid 2px $grey-3;
390
384
  content: " \2013\00a0"; // dash followed by &nbsp;
391
385
  }
392
386
  }
393
-
394
- .gem-c-step-nav__help {
395
- position: relative;
396
- padding: $gutter-half 0;
397
- border-top: $top-border;
398
-
399
- &:after {
400
- @include step-nav-vertical-line(dotted);
401
- @include step-nav-line-position;
402
- z-index: 3;
403
- top: 0;
404
- left: -($gutter + $gutter-half);
405
- height: calc(100% + #{$gutter});
406
- }
407
-
408
- .gem-c-step-nav--large & {
409
- @include media(tablet) {
410
- &:after {
411
- @include step-nav-line-position-large;
412
- left: -($gutter * 2);
413
- height: calc(100% + #{$gutter} + #{$gutter-half});
414
- }
415
- }
416
- }
417
- }
418
-
419
- .gem-c-step-nav__help-link {
420
- text-decoration: none;
421
- font-weight: bold;
422
-
423
- &:hover {
424
- text-decoration: underline;
425
- }
426
- }
427
-
428
- .gem-c-step-nav__substep {
429
- position: relative;
430
- padding-top: $gutter-half;
431
- border-top: $top-border;
432
-
433
- &:after {
434
- @include step-nav-vertical-line;
435
- @include step-nav-line-position;
436
- z-index: 3;
437
- top: 0;
438
- left: -($gutter + $gutter-half);
439
- }
440
-
441
- .gem-c-step-nav--large & {
442
- @include media(tablet) {
443
- padding-top: $gutter;
444
-
445
- &:after {
446
- @include step-nav-line-position-large;
447
- left: -($gutter * 2);
448
- }
449
- }
450
- }
451
- }
452
-
453
- .gem-c-step-nav__substep--optional:after {
454
- border-left-style: dotted;
455
- }