1class CookiesCheckboxCreate { 2 3 constructor(settings) { 4 // Merge the default settings with the use settings 5 const defaultSettings = { 6 formSelector : '.wpcf7', 7 clientNodeSelector : '.wpcf7-checkbox .wpcf7-list-item', 8 cookiesSpanId : 'span-axeptio', 9 cookiesService : 'processings', 10 cookiesIdentifier : '', 11 cookiesConsentCheckboxClass : '.AxeptioConsentCheckbox', 12 cookiesCheckboxDetailsText : 'En savoir plus', 13 cookiesCheckboxText : 'J\'accepte de recevoir la newsletter', 14 cookiesConsentDetailsTextClass : '.AxeptioConsentDetailsText', 15 cookiesConsentDetailsLinkClass : '.AxeptioConsentDetailsLink', 16 cookiesConsentRequired : true, 17 cookiesHideConsentDetailsLink: true, 18 } 19 this.settings = { ...defaultSettings, ...settings }; 20 21 // Check if settings are correct 22 if( !this.settings.formSelector || !this.settings.cookiesIdentifier ) return console.log( 'Missing formSelector or cookies manager ID'); 23 24 // Check if the wrapper exist 25 if( !document.querySelector( this.settings.formSelector ) ) return; 26 27 // Node element where axeptio span will be created 28 this.clientNode = document.querySelector( this.settings.formSelector + ' ' + this.settings.clientNodeSelector ); 29 30 if( !this.clientNode ) return console.log( 'clientNode is missing' ); 31 32 // If everything is ok, then create the checkbox 33 this.create(); 34 } 35 36 create() { 37 // We hide the submit button when submit is launched 38 void 0 === window._axcb && (window._axcb = []); 39 window._axcb.push( ( axeptio ) => { 40 // Add the span placeholder 41 this.addPlaceholder(); 42 // Add the checkbox 43 this.addCheckbox( axeptio ); 44 45 } ); 46 } 47 48 addPlaceholder() { 49 const axeptioSpanContact = document.createElement( 'span' ); 50 axeptioSpanContact.id = this.settings.cookiesSpanId; 51 52 this.clientNode.appendChild( axeptioSpanContact ); 53 } 54 55 addCheckbox( axeptio ) { 56 // Add the checkbox with the axeptio API 57 const checkboxArgs = { 58 service: this.settings.cookiesService, 59 identifier: this.settings.cookiesIdentifier, 60 node: document.getElementById( this.settings.cookiesSpanId ), 61 embed: { 62 checkboxDetailsText: this.settings.cookiesCheckboxDetailsText, 63 checkboxText: this.settings.cookiesCheckboxText 64 } 65 }; 66 67 axeptio.createConsentCheckbox( checkboxArgs ); 68 69 // Update required attribute 70 const requiredInput = document.querySelector( '#' + this.settings.cookiesSpanId + ' > div > label > input' ); 71 if( this.settings.cookiesConsentRequired && requiredInput ) { 72 requiredInput.setAttribute( 'required', 'required' ); 73 } 74 75 // Remove the see more links in axeptio created checkbox 76 if( this.settings.cookiesHideConsentDetailsLink ) { 77 const detailsLink = document.querySelector( this.settings.formSelector + ' ' + this.settings.cookiesConsentDetailsLinkClass ); 78 79 if( detailsLink ) detailsLink.remove(); 80 } 81 } 82}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.