Skip to content

Commit

Permalink
Merge branch 'main' into accessibility-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asakthivel1810 authored Oct 21, 2024
2 parents 66463fe + 1e792b0 commit 92337db
Show file tree
Hide file tree
Showing 33 changed files with 2,789 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"plugins": ["prettier", "jest", "jest-formatting"],
"rules": {
"prettier/prettier": "error",
"no-console": "error"
"no-console": "error",
"no-new": 0
},
"ignorePatterns": [
".server",
Expand Down
57 changes: 49 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@
"lodash": "4.17.21",
"node-fetch": "3.3.2",
"nunjucks": "3.2.4",
"path-browserify": "1.0.1",
"pino": "8.20.0",
"supertest": "7.0.0",
"undici": "6.12.0"
"undici": "6.12.0",
"util": "0.12.5"
},
"devDependencies": {
"@babel/cli": "7.24.1",
Expand Down
68 changes: 68 additions & 0 deletions src/client/assets/javascripts/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// @ts-nocheck
export default function loadAnalytics() {
if (!window.ga || !window.ga.loaded) {
window.dataLayer = window.dataLayer || []
if (localStorage.getItem('consentMode') === null) {
window.dataLayer.push('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
personalization_storage: 'denied',
functionality_storage: 'denied',
security_storage: 'denied'
})
} else {
window.dataLayer.push(
'consent',
'default',
JSON.parse(localStorage.getItem('consentMode'))
)
}
// prettier-ignore
;(function (w, d, s, l, i) {
w[l] = w[l] || []
w[l].push({
'gtm.start': new Date().getTime(),
event: 'gtm.js'
})
///
const noscript = document.createElement('noscript')
const iframe = document.createElement('iframe')
iframe.setAttribute("height", "0")
iframe.setAttribute("width", "0")
iframe.setAttribute("style", "display:none;visibility:hidden")
iframe.async = true
iframe.src = "https://www.googletagmanager.com/ns.html?id=G-HVF94VF4NZ"
noscript.appendChild(iframe)
document.body.appendChild(noscript)
///
const k = d.createElement(s)
k.async = true
k.src = "https://www.googletagmanager.com/gtag/js?id=G-HVF94VF4NZ"
document.body.appendChild(k)
// const urlParams = new URLSearchParams(window.location.search);
// const userId = urlParams.get('userId');
// const utm_source = urlParams.get('utm_source');
// const utm_campaign = urlParams.get('utm_campaign');
// const utm_medium = urlParams.get('utm_medium');


const f = d.getElementsByTagName(s)[0];
const j = d.createElement(s);
// const dl = l != 'dataLayer' ? '&l=' + l : ''
j.async = true;
j.src = 'https://www.googletagmanager.com/gtag/js?id=G-HVF94VF4NZ'
f.parentNode.insertBefore(j, f)
window.dataLayer.push('js', new Date())
// window.dataLayer.push('config', 'G-HVF94VF4NZ',{
// 'user_id': utm_source
// })

})(window, document, 'script', 'dataLayer', 'G-HVF94VF4NZ')
}
}
// window.dataLayer = window.dataLayer || [];
// function gtag(){
// dataLayer.push(arguments);
// }
// gtag('js', new Date());
// gtag('config', 'G-HVF94VF4NZ');
30 changes: 30 additions & 0 deletions src/client/assets/javascripts/analytics_p.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @ts-nocheck
export default function loadAnalytics() {
if (!window.ga || !window.ga.loaded) {
// Load gtm script
// Script based on snippet at https://developers.google.com/tag-manager/quickstart
// prettier-ignore
;(function (w, d, s, l, i) {
w[l] = w[l] || []
w[l].push({
'gtm.start': new Date().getTime(),
event: 'gtm.js'
})

const j = d.createElement(s)
const dl = l !== 'dataLayer' ? `&l=${l}` : ''

j.async = true
j.src = 'https://www.googletagmanager.com/gtag/js?id=G-HVF94VF4NZ'
document.head.appendChild(j)
window.dataLayer = window.dataLayer || []
function gtag() {
window.dataLayer.push(arguments)
}
gtag('js', new Date())
gtag('config', 'G-8CMZBTDQBC')
j.src = `https://www.googletagmanager.com/gtm.js?id=${i}${dl}`
document.head.appendChild(j)
})(window, document, 'script', 'dataLayer', 'G-HVF94VF4NZ')
}
}
86 changes: 86 additions & 0 deletions src/client/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,90 @@ import './plant-search.js'
import './pest-search.js'
import './country-search.js'

import CookieBanner from './cookie-banner'
import Analytics from './analytics'
// import config from '~/src/config'
import {
getConsentCookie,
isValidConsentCookie,
removeUACookies
} from './cookie-functions.js'
import CookiesPage from './cookies-page.js'
const $cookieBanner = document.querySelector(
'[data-module="govuk-cookie-banner"]'
)

if ($cookieBanner) {
new CookieBanner($cookieBanner)
}

// Initialise analytics if consent is given
const userConsent = getConsentCookie()
if (userConsent && isValidConsentCookie(userConsent) && userConsent.analytics) {
Analytics()

// Remove UA cookies if the user previously had them set or Google attempts
// to set them
removeUACookies()
}

// Initialise cookie page
const $cookiesPage = document.querySelector('[data-module="app-cookies-page"]')
if ($cookiesPage) {
new CookiesPage($cookiesPage)
}

function compareNames(a, b) {
if (a.text < b.text) {
return -1
}
if (a.text > b.text) {
return 1
}
return 0
}

export function timerFunction(query, finalArray, populateResults) {
return setTimeout(async () => {
try {
if (query.length > 2) {
return populateResults(finalArray.sort(compareNames))
}
} catch (error) {
// TypeError: Failed to fetch
// console.log('Error fetching suggestions:', error)
}
}, 1000)
}

export function inputValueTemplate(asd) {
return asd?.text
}

export function suggestionTemplate(asd, regexValue) {
const inputElementCustom =
document.getElementsByClassName('custom-hint-class')
inputElementCustom[0]?.setAttribute('aria-label', 'autocomplete__hint')
inputElementCustom[0]?.setAttribute('id', 'autocomplete__hint')
let template
if (regexValue?.length > 0) {
template =
'<div class="suggestions"><span class="name" id="resultName">' +
asd?.text?.replace(
new RegExp(regexValue, 'gi'),
(match) => `<strong>${match}</strong>`
) +
'</span></div>'
} else {
template =
'<div class="suggestions"><span class="name" id="resultName">' +
asd?.replace(
new RegExp(asd, 'gi'),
(match) => `<strong>${match}</strong>`
) +
'</span></div>'
}
return template
}

initAll()
Loading

0 comments on commit 92337db

Please sign in to comment.