govuk_frontend_toolkit 0.41.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. data/.gitignore +3 -0
  2. data/.gitmodules +3 -0
  3. data/CONTRIBUTING.md +13 -0
  4. data/Gemfile +4 -0
  5. data/LICENCE +20 -0
  6. data/README.md +46 -0
  7. data/Rakefile +16 -0
  8. data/app/assets/.gitignore +1 -0
  9. data/app/assets/.travis.yml +3 -0
  10. data/app/assets/CONTRIBUTING.md +18 -0
  11. data/app/assets/Gruntfile.js +19 -0
  12. data/app/assets/LICENCE +20 -0
  13. data/app/assets/README.md +675 -0
  14. data/app/assets/images/crests/bis_crest_13px.png +0 -0
  15. data/app/assets/images/crests/bis_crest_13px_x2.png +0 -0
  16. data/app/assets/images/crests/bis_crest_18px.png +0 -0
  17. data/app/assets/images/crests/bis_crest_18px_x2.png +0 -0
  18. data/app/assets/images/crests/bis_crest_27px.png +0 -0
  19. data/app/assets/images/crests/bis_crest_27px_x2.png +0 -0
  20. data/app/assets/images/crests/coastguard_13px.png +0 -0
  21. data/app/assets/images/crests/coastguard_13px_x2.png +0 -0
  22. data/app/assets/images/crests/coastguard_18px.png +0 -0
  23. data/app/assets/images/crests/coastguard_18px_x2.png +0 -0
  24. data/app/assets/images/crests/coastguard_27px.png +0 -0
  25. data/app/assets/images/crests/coastguard_27px_x2.png +0 -0
  26. data/app/assets/images/crests/hmrc_crest_13px.png +0 -0
  27. data/app/assets/images/crests/hmrc_crest_13px_x2.png +0 -0
  28. data/app/assets/images/crests/hmrc_crest_18px.png +0 -0
  29. data/app/assets/images/crests/hmrc_crest_18px_x2.png +0 -0
  30. data/app/assets/images/crests/hmrc_crest_27px.png +0 -0
  31. data/app/assets/images/crests/hmrc_crest_27px_x2.png +0 -0
  32. data/app/assets/images/crests/ho_crest_13px.png +0 -0
  33. data/app/assets/images/crests/ho_crest_13px_x2.png +0 -0
  34. data/app/assets/images/crests/ho_crest_18px.png +0 -0
  35. data/app/assets/images/crests/ho_crest_18px_x2.png +0 -0
  36. data/app/assets/images/crests/ho_crest_27px.png +0 -0
  37. data/app/assets/images/crests/ho_crest_27px_x2.png +0 -0
  38. data/app/assets/images/crests/mod_crest_13px.png +0 -0
  39. data/app/assets/images/crests/mod_crest_13px_x2.png +0 -0
  40. data/app/assets/images/crests/mod_crest_18px.png +0 -0
  41. data/app/assets/images/crests/mod_crest_18px_x2.png +0 -0
  42. data/app/assets/images/crests/mod_crest_27px.png +0 -0
  43. data/app/assets/images/crests/mod_crest_27px_x2.png +0 -0
  44. data/app/assets/images/crests/org_crest_13px.png +0 -0
  45. data/app/assets/images/crests/org_crest_13px_x2.png +0 -0
  46. data/app/assets/images/crests/org_crest_18px.png +0 -0
  47. data/app/assets/images/crests/org_crest_18px_x2.png +0 -0
  48. data/app/assets/images/crests/org_crest_27px.png +0 -0
  49. data/app/assets/images/crests/org_crest_27px_x2.png +0 -0
  50. data/app/assets/images/crests/portcullis_13px.png +0 -0
  51. data/app/assets/images/crests/portcullis_13px_x2.png +0 -0
  52. data/app/assets/images/crests/portcullis_18px.png +0 -0
  53. data/app/assets/images/crests/portcullis_18px_x2.png +0 -0
  54. data/app/assets/images/crests/portcullis_27px.png +0 -0
  55. data/app/assets/images/crests/portcullis_27px_x2.png +0 -0
  56. data/app/assets/images/crests/so_crest_13px.png +0 -0
  57. data/app/assets/images/crests/so_crest_13px_x2.png +0 -0
  58. data/app/assets/images/crests/so_crest_18px.png +0 -0
  59. data/app/assets/images/crests/so_crest_18px_x2.png +0 -0
  60. data/app/assets/images/crests/so_crest_27px.png +0 -0
  61. data/app/assets/images/crests/so_crest_27px_x2.png +0 -0
  62. data/app/assets/images/crests/ukaea_crest_13px.png +0 -0
  63. data/app/assets/images/crests/ukaea_crest_13px_x2.png +0 -0
  64. data/app/assets/images/crests/ukaea_crest_18px.png +0 -0
  65. data/app/assets/images/crests/ukaea_crest_18px_x2.png +0 -0
  66. data/app/assets/images/crests/ukaea_crest_27px.png +0 -0
  67. data/app/assets/images/crests/ukaea_crest_27px_x2.png +0 -0
  68. data/app/assets/images/crests/ukho_13px.png +0 -0
  69. data/app/assets/images/crests/ukho_13px_x2.png +0 -0
  70. data/app/assets/images/crests/ukho_18px.png +0 -0
  71. data/app/assets/images/crests/ukho_18px_x2.png +0 -0
  72. data/app/assets/images/crests/ukho_27px.png +0 -0
  73. data/app/assets/images/crests/ukho_27px_x2.png +0 -0
  74. data/app/assets/images/crests/wales_crest_13px.png +0 -0
  75. data/app/assets/images/crests/wales_crest_13px_x2.png +0 -0
  76. data/app/assets/images/crests/wales_crest_18px.png +0 -0
  77. data/app/assets/images/crests/wales_crest_18px_x2.png +0 -0
  78. data/app/assets/images/crests/wales_crest_27px.png +0 -0
  79. data/app/assets/images/crests/wales_crest_27px_x2.png +0 -0
  80. data/app/assets/images/external-links/external-link-24x24.png +0 -0
  81. data/app/assets/images/external-links/external-link-black-12x12.png +0 -0
  82. data/app/assets/images/external-links/external-link-black-24x24.png +0 -0
  83. data/app/assets/images/external-links/external-link.png +0 -0
  84. data/app/assets/images/icon-steps/icon-step-1-2x.png +0 -0
  85. data/app/assets/images/icon-steps/icon-step-1.png +0 -0
  86. data/app/assets/images/icon-steps/icon-step-10-2x.png +0 -0
  87. data/app/assets/images/icon-steps/icon-step-10.png +0 -0
  88. data/app/assets/images/icon-steps/icon-step-11-2x.png +0 -0
  89. data/app/assets/images/icon-steps/icon-step-11.png +0 -0
  90. data/app/assets/images/icon-steps/icon-step-12-2x.png +0 -0
  91. data/app/assets/images/icon-steps/icon-step-12.png +0 -0
  92. data/app/assets/images/icon-steps/icon-step-13-2x.png +0 -0
  93. data/app/assets/images/icon-steps/icon-step-13.png +0 -0
  94. data/app/assets/images/icon-steps/icon-step-14-2x.png +0 -0
  95. data/app/assets/images/icon-steps/icon-step-14.png +0 -0
  96. data/app/assets/images/icon-steps/icon-step-2-2x.png +0 -0
  97. data/app/assets/images/icon-steps/icon-step-2.png +0 -0
  98. data/app/assets/images/icon-steps/icon-step-3-2x.png +0 -0
  99. data/app/assets/images/icon-steps/icon-step-3.png +0 -0
  100. data/app/assets/images/icon-steps/icon-step-4-2x.png +0 -0
  101. data/app/assets/images/icon-steps/icon-step-4.png +0 -0
  102. data/app/assets/images/icon-steps/icon-step-5-2x.png +0 -0
  103. data/app/assets/images/icon-steps/icon-step-5.png +0 -0
  104. data/app/assets/images/icon-steps/icon-step-6-2x.png +0 -0
  105. data/app/assets/images/icon-steps/icon-step-6.png +0 -0
  106. data/app/assets/images/icon-steps/icon-step-7-2x.png +0 -0
  107. data/app/assets/images/icon-steps/icon-step-7.png +0 -0
  108. data/app/assets/images/icon-steps/icon-step-8-2x.png +0 -0
  109. data/app/assets/images/icon-steps/icon-step-8.png +0 -0
  110. data/app/assets/images/icon-steps/icon-step-9-2x.png +0 -0
  111. data/app/assets/images/icon-steps/icon-step-9.png +0 -0
  112. data/app/assets/images/player-icon-forward.png +0 -0
  113. data/app/assets/images/player-icon-pause.png +0 -0
  114. data/app/assets/images/player-icon-play.png +0 -0
  115. data/app/assets/images/player-icon-rewind.png +0 -0
  116. data/app/assets/images/player-icon-volume.png +0 -0
  117. data/app/assets/javascripts/govuk/multivariate-test.js +101 -0
  118. data/app/assets/javascripts/govuk/stop-scrolling-at-footer.js +138 -0
  119. data/app/assets/javascripts/govuk_toolkit.js +1 -0
  120. data/app/assets/javascripts/stageprompt.js +63 -0
  121. data/app/assets/javascripts/vendor/jquery/jquery.player.min.js +25 -0
  122. data/app/assets/jenkins.sh +5 -0
  123. data/app/assets/package.json +14 -0
  124. data/app/assets/spec/MultivariateTestSpec.js +166 -0
  125. data/app/assets/stylesheets/.gitkeep +0 -0
  126. data/app/assets/stylesheets/_colours.scss +104 -0
  127. data/app/assets/stylesheets/_conditionals.scss +85 -0
  128. data/app/assets/stylesheets/_css3.scss +61 -0
  129. data/app/assets/stylesheets/_device-pixels.scss +11 -0
  130. data/app/assets/stylesheets/_font_stack.scss +40 -0
  131. data/app/assets/stylesheets/_measurements.scss +7 -0
  132. data/app/assets/stylesheets/_shims.scss +57 -0
  133. data/app/assets/stylesheets/_typography.scss +400 -0
  134. data/app/assets/stylesheets/design-patterns/_alpha-beta.scss +49 -0
  135. data/app/assets/stylesheets/design-patterns/_buttons.scss +142 -0
  136. data/app/assets/stylesheets/design-patterns/_media-player.scss +232 -0
  137. data/govuk_frontend_toolkit.gemspec +50 -0
  138. data/jenkins.sh +8 -0
  139. data/lib/govuk_frontend_toolkit.rb +4 -0
  140. data/lib/govuk_frontend_toolkit/engine.rb +4 -0
  141. data/lib/govuk_frontend_toolkit/version.rb +3 -0
  142. metadata +273 -0
@@ -0,0 +1,101 @@
1
+ (function() {
2
+ "use strict";
3
+ window.GOVUK = window.GOVUK || {};
4
+ var $ = window.$;
5
+
6
+ // A multivariate test framework
7
+ //
8
+ // Based loosely on https://github.com/jamesyu/cohorts
9
+ //
10
+ // Full documentation is in README.md.
11
+ //
12
+ function MultivariateTest(options) {
13
+ this.$el = $(options.el);
14
+ this._loadOption(options, 'name');
15
+ this._loadOption(options, 'customVarIndex');
16
+ this._loadOption(options, 'cohorts');
17
+ this._loadOption(options, 'runImmediately', true);
18
+
19
+ if (this.runImmediately) {
20
+ this.run();
21
+ }
22
+ }
23
+
24
+ MultivariateTest.prototype._loadOption = function(options, key, defaultValue) {
25
+ if (options[key] !== undefined) {
26
+ this[key] = options[key];
27
+ }
28
+ if (this[key] === undefined) {
29
+ if (defaultValue === undefined) {
30
+ throw new Error(key+" option is required for a multivariate test");
31
+ }
32
+ else {
33
+ this[key] = defaultValue;
34
+ }
35
+ }
36
+ };
37
+
38
+ MultivariateTest.prototype.run = function() {
39
+ var cohort = this.getCohort();
40
+ if (cohort) {
41
+ this.setCustomVar(cohort);
42
+ this.executeCohort(cohort);
43
+ }
44
+ };
45
+
46
+ MultivariateTest.prototype.executeCohort = function(cohort) {
47
+ var cohortObj = this.cohorts[cohort];
48
+ if (cohortObj.callback) {
49
+ if (typeof cohortObj.callback === "string") {
50
+ this[cohortObj.callback]();
51
+ }
52
+ else {
53
+ cohortObj.callback();
54
+ }
55
+ }
56
+ if (cohortObj.html) {
57
+ this.$el.html(cohortObj.html);
58
+ this.$el.show();
59
+ }
60
+ };
61
+
62
+ // Get the current cohort or assign one if it has not been already
63
+ MultivariateTest.prototype.getCohort = function() {
64
+ var cohort = GOVUK.cookie(this.cookieName());
65
+ if (!cohort || !this.cohorts[cohort]) {
66
+ cohort = this.chooseRandomCohort();
67
+ GOVUK.cookie(this.cookieName(), cohort, {days: 30});
68
+ }
69
+ return cohort;
70
+ };
71
+
72
+ MultivariateTest.prototype.setCustomVar = function(cohort) {
73
+ window._gaq = window._gaq || [];
74
+ window._gaq.push([
75
+ '_setCustomVar',
76
+ this.customVarIndex,
77
+ this.cookieName(),
78
+ cohort,
79
+ 2 // session level
80
+ ]);
81
+ // Fire off a dummy event to set the custom var on the page.
82
+ // Ideally we'd be able to call setCustomVar before trackPageview,
83
+ // but would need reordering the existing GA code.
84
+ window._gaq.push(['_trackEvent', this.cookieName(), 'run', '-', 0, true]);
85
+ };
86
+
87
+ MultivariateTest.prototype.cohortNames = function() {
88
+ return $.map(this.cohorts, function(v, i) { return i; });
89
+ };
90
+
91
+ MultivariateTest.prototype.chooseRandomCohort = function() {
92
+ var names = this.cohortNames();
93
+ return names[Math.floor(Math.random() * names.length)];
94
+ };
95
+
96
+ MultivariateTest.prototype.cookieName = function() {
97
+ return "multivariatetest_cohort_" + this.name;
98
+ };
99
+
100
+ window.GOVUK.MultivariateTest = MultivariateTest;
101
+ }());
@@ -0,0 +1,138 @@
1
+ // Stop scrolling at footer.
2
+ //
3
+ // This can be added to elements with `position: fixed` to stop them from
4
+ // overflowing on the footer.
5
+ //
6
+ // Usage:
7
+ //
8
+ // GOVUK.stopScrollingAtFooter.addEl($(node), $(node).height());
9
+ //
10
+ // Height is passed in separatly incase the scrolling element has no height
11
+ // itself.
12
+
13
+
14
+ (function () {
15
+ "use strict"
16
+ var root = this,
17
+ $ = root.jQuery;
18
+ if(typeof root.GOVUK === 'undefined') { root.GOVUK = {}; }
19
+
20
+ var stopScrollingAtFooter = {
21
+ _pollingId: null,
22
+ _isPolling: false,
23
+ _hasScrollEvt: false,
24
+ _els: [],
25
+
26
+ addEl: function($fixedEl, height){
27
+ var fixedOffset;
28
+
29
+ if(!$fixedEl.length) { return; }
30
+
31
+ fixedOffset = parseInt($fixedEl.css('top'), 10);
32
+ fixedOffset = isNaN(fixedOffset) ? 0 : fixedOffset;
33
+
34
+ stopScrollingAtFooter.updateFooterTop();
35
+ $(root).on('govuk.pageSizeChanged', stopScrollingAtFooter.updateFooterTop);
36
+
37
+ var $siblingEl = $('<div></div>');
38
+ $siblingEl.insertBefore($fixedEl);
39
+ var fixedTop = $siblingEl.offset().top - $siblingEl.position().top;
40
+ $siblingEl.remove();
41
+
42
+ var el = {
43
+ $fixedEl: $fixedEl,
44
+ height: height + fixedOffset,
45
+ fixedTop: height + fixedTop,
46
+ state: 'fixed'
47
+ };
48
+ stopScrollingAtFooter._els.push(el);
49
+
50
+ stopScrollingAtFooter.initTimeout();
51
+ },
52
+ updateFooterTop: function(){
53
+ var footer = $('.js-footer:eq(0)');
54
+ if (footer.length === 0) {
55
+ return 0;
56
+ }
57
+ stopScrollingAtFooter.footerTop = footer.offset().top - 10;
58
+ },
59
+ initTimeout: function(){
60
+ if(stopScrollingAtFooter._hasScrollEvt === false) {
61
+ $(window).scroll(stopScrollingAtFooter.onScroll);
62
+ stopScrollingAtFooter._hasScrollEvt = true;
63
+ }
64
+ },
65
+ onScroll: function(){
66
+ if (stopScrollingAtFooter._isPolling === false) {
67
+ stopScrollingAtFooter.startPolling();
68
+ }
69
+ },
70
+ startPolling: (function(){
71
+ if (window.requestAnimationFrame) {
72
+ return (function(){
73
+ var callback = function(){
74
+ stopScrollingAtFooter.checkScroll();
75
+ if (stopScrollingAtFooter._isPolling === true) {
76
+ stopScrollingAtFooter.startPolling();
77
+ }
78
+ };
79
+ stopScrollingAtFooter._pollingId = window.requestAnimationFrame(callback);
80
+ stopScrollingAtFooter._isPolling = true;
81
+ });
82
+ } else {
83
+ return (function(){
84
+ stopScrollingAtFooter._pollingId = window.setInterval(stopScrollingAtFooter.checkScroll, 16);
85
+ stopScrollingAtFooter._isPolling = true;
86
+ });
87
+ }
88
+ }()),
89
+ stopPolling: (function(){
90
+ if (window.requestAnimationFrame) {
91
+ return (function(){
92
+ window.cancelAnimationFrame(stopScrollingAtFooter._pollingId);
93
+ stopScrollingAtFooter._isPolling = false;
94
+ });
95
+ } else {
96
+ return (function(){
97
+ window.clearInterval(stopScrollingAtFooter._pollingId);
98
+ stopScrollingAtFooter._isPolling = false;
99
+ });
100
+ }
101
+ }()),
102
+ checkScroll: function(){
103
+ var cachedScrollTop = $(window).scrollTop();
104
+ if ((cachedScrollTop < (stopScrollingAtFooter.cachedScrollTop + 2)) && (cachedScrollTop > (stopScrollingAtFooter.cachedScrollTop - 2))) {
105
+ stopScrollingAtFooter.stopPolling();
106
+ return;
107
+ } else {
108
+ stopScrollingAtFooter.cachedScrollTop = cachedScrollTop;
109
+ }
110
+
111
+ $.each(stopScrollingAtFooter._els, function(i, el){
112
+ var bottomOfEl = cachedScrollTop + el.height;
113
+
114
+ if (bottomOfEl > stopScrollingAtFooter.footerTop){
115
+ stopScrollingAtFooter.stick(el);
116
+ } else {
117
+ stopScrollingAtFooter.unstick(el);
118
+ }
119
+ });
120
+ },
121
+ stick: function(el){
122
+ if(el.state === 'fixed' && el.$fixedEl.css('position') === 'fixed'){
123
+ el.$fixedEl.css({ 'position': 'absolute', 'top': stopScrollingAtFooter.footerTop - el.fixedTop });
124
+ el.state = 'absolute';
125
+ }
126
+ },
127
+ unstick: function(el){
128
+ if(el.state === 'absolute'){
129
+ el.$fixedEl.css({ 'position': '', 'top': '' });
130
+ el.state = 'fixed';
131
+ }
132
+ }
133
+ };
134
+
135
+ root.GOVUK.stopScrollingAtFooter = stopScrollingAtFooter;
136
+
137
+ $(root).load(function(){ $(root).trigger('govuk.pageSizeChanged'); });
138
+ }).call(this);