UNPKG

ccs-frontend

Version:
1 lines 10.4 kB
{"version":3,"file":"all.bundle.mjs","sources":["../../src/ccs/common/ccs-frontend-version.ts","../../src/ccs/components/header/header.ts","../../src/ccs/components/password-strength/password-strength.ts","../../src/ccs/init.ts"],"sourcesContent":["/*\n * This variable is automatically overwritten during builds and releases.\n * It doesn't need to be updated manually.\n */\n\n/**\n * CCS Frontend release version\n *\n * {@link https://github.com/Crown-Commercial-Service/ccs-frontend-project/releases}\n */\nexport const version = 'development'\n","import { CCSFrontendComponent } from '../../ccs-frontend-component'\n\nclass Header implements CCSFrontendComponent {\n static moduleName = 'ccs-header'\n $menuButton: JQuery<HTMLButtonElement>\n $menu: JQuery<HTMLElement>\n\n constructor ($header: JQuery<HTMLElement>) {\n this.$menuButton = $header.find<HTMLButtonElement>('.ccs-js-header-toggle')\n this.$menu = $header.find<HTMLElement>(`#${this.$menuButton.attr('aria-controls')}`)\n }\n\n init () {\n this.syncState(this.$menu.hasClass('ccs-header__navigation-lists--open'))\n this.setEventListeners()\n this.$menuButton.removeAttr('hidden')\n }\n\n syncState (isVisible: boolean) {\n this.$menuButton.toggleClass('ccs-header__menu-button--open', isVisible)\n this.$menuButton.attr('aria-expanded', String(isVisible))\n }\n\n setEventListeners () {\n this.$menuButton.on('click', () => {\n this.$menu.toggleClass('ccs-header__navigation-lists--open')\n\n this.syncState(this.$menu.hasClass('ccs-header__navigation-lists--open'))\n })\n }\n}\n\nexport { Header }\n","import { CCSFrontendComponent } from '../../ccs-frontend-component'\n\nabstract class PasswordStrengthTest {\n abstract test: RegExp\n $passwordStrengthTest: JQuery<HTMLLIElement>\n\n constructor ($passwordStrengthTest: JQuery<HTMLLIElement>) {\n this.$passwordStrengthTest = $passwordStrengthTest\n }\n\n init () {\n this.$passwordStrengthTest.addClass('ccs-password-strength-tests__wrong')\n }\n\n testPasswordInput (passwordInputText: string) {\n const testPassed: boolean = this.test.test(passwordInputText)\n\n this.$passwordStrengthTest.toggleClass('ccs-password-strength-tests__wrong', !testPassed)\n this.$passwordStrengthTest.toggleClass('ccs-password-strength-tests__correct', testPassed)\n }\n}\n\nclass PasswordStrengthTestLength extends PasswordStrengthTest {\n test: RegExp\n\n constructor ($passwordStrengthTest: JQuery<HTMLLIElement>, value: string) {\n super($passwordStrengthTest)\n this.test = new RegExp(`^.{${value},}`)\n }\n}\n\nclass PasswordStrengthTestSymbol extends PasswordStrengthTest {\n test: RegExp\n\n constructor ($passwordStrengthTest: JQuery<HTMLLIElement>, value: string) {\n super($passwordStrengthTest)\n this.test = new RegExp(`^(?=.*?[${value}])`)\n }\n}\n\nclass PasswordStrengthTestNumber extends PasswordStrengthTest {\n test: RegExp\n\n constructor ($passwordStrengthTest: JQuery<HTMLLIElement>) {\n super($passwordStrengthTest)\n this.test = new RegExp('^(?=.*[0-9])')\n }\n}\n\nclass PasswordStrengthTestUppercase extends PasswordStrengthTest {\n test: RegExp\n\n constructor ($passwordStrengthTest: JQuery<HTMLLIElement>) {\n super($passwordStrengthTest)\n this.test = new RegExp('^(?=.*[A-Z])')\n }\n}\n\nclass PasswordStrengthTestLowercase extends PasswordStrengthTest {\n test: RegExp\n\n constructor ($passwordStrengthTest: JQuery<HTMLLIElement>) {\n super($passwordStrengthTest)\n this.test = new RegExp('^(?=.*[a-z])')\n }\n}\n\nconst passwordStrengthTestFactory = ($passwordStrengthTest: JQuery<HTMLLIElement>): PasswordStrengthTest | undefined => {\n const testType = $passwordStrengthTest.data('testType')\n const value = $passwordStrengthTest.data('testValue')\n\n switch (testType) {\n case 'length':\n return new PasswordStrengthTestLength($passwordStrengthTest, value)\n case 'symbol':\n return new PasswordStrengthTestSymbol($passwordStrengthTest, value)\n case 'number':\n return new PasswordStrengthTestNumber($passwordStrengthTest)\n case 'uppercase':\n return new PasswordStrengthTestUppercase($passwordStrengthTest)\n case 'lowercase':\n return new PasswordStrengthTestLowercase($passwordStrengthTest)\n }\n}\n\nclass PasswordStrength implements CCSFrontendComponent {\n static moduleName = 'ccs-password-strength'\n $passwordStrength: JQuery<HTMLUListElement>\n $passwordInput: JQuery<HTMLInputElement>\n passwordStrengthTests: PasswordStrengthTest[]\n\n constructor ($passwordStrength: JQuery<HTMLElement>) {\n this.$passwordStrength = $passwordStrength as JQuery<HTMLUListElement>\n this.$passwordInput = $<HTMLInputElement>(`#${$passwordStrength.data('target')}`)\n this.passwordStrengthTests = this.$passwordStrength.find<HTMLLIElement>('.ccs-password-strength-test').get().map((passwordStrengthTest) => passwordStrengthTestFactory($(passwordStrengthTest)) as PasswordStrengthTest)\n }\n\n init () {\n if (this.$passwordInput.length) {\n this.$passwordStrength.addClass('ccs-password-strength-tests')\n this.passwordStrengthTests.forEach((passwordStrengthTest) => passwordStrengthTest.init())\n\n this.$passwordInput.on('keyup', () => { this.testPasswordInput() })\n }\n }\n\n private testPasswordInput () {\n const passwordInputText = String(this.$passwordInput.val())\n\n this.passwordStrengthTests.forEach((passwordStrengthTest) => passwordStrengthTest.testPasswordInput(passwordInputText))\n }\n}\n\nexport { PasswordStrength }\n","import { CCSFrontendComponent } from './ccs-frontend-component'\nimport { Header } from './components/header/header'\nimport { PasswordStrength } from './components/password-strength/password-strength'\n\nconst createAll = (Component: typeof CCSFrontendComponent) => {\n $(`[data-module=\"${Component.moduleName}\"]`).each((_index, componentElement) => {\n new Component($(componentElement)).init()\n })\n}\n\nconst initAll = () => {\n const components: Array<typeof CCSFrontendComponent> = [\n Header,\n PasswordStrength,\n ]\n\n components.forEach((Component) => {\n createAll(Component)\n })\n}\n\nexport { initAll, createAll }\n"],"names":[],"mappings":"AAAA;;;AAGG;AAEH;;;;AAIG;AACI,MAAM,OAAO,GAAG;;ACRvB,MAAM,MAAM,CAAA;AACV,IAAA,OAAO,UAAU,GAAG,YAAY;AAChC,IAAA,WAAW;AACX,IAAA,KAAK;AAEL,IAAA,WAAA,CAAa,OAA4B,EAAA;QACvC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAoB,uBAAuB,CAAC;AAC3E,QAAA,IAAI,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