### File

`projects/commons/src/lib/elements/cookie/services/cookie.service.ts`

### Index

###### Properties
Public element
###### Methods
Private eventClickAccept Public existCookie Public init Public setElement Private setStyleNotification

### Constructor

`constructor(toastService: ToastService, document: any)`
Defined in projects/commons/src/lib/elements/cookie/services/cookie.service.ts:13
Parameters :
Name | Type | Optional
toastService | `ToastService` | No
document | `any` | No

### Methods

Private eventClickAccept
`eventClickAccept()`
Decorators : `@autobind()`
Defined in projects/commons/src/lib/elements/cookie/services/cookie.service.ts:56
Returns : `void`

Public existCookie
`existCookie(name)`
Defined in projects/commons/src/lib/elements/cookie/services/cookie.service.ts:38
Parameters :
Name | Optional
name | No
Returns : `boolean`

Public init
`init(message: string)`
Defined in projects/commons/src/lib/elements/cookie/services/cookie.service.ts:20
Parameters :
Name | Type | Optional | Default value
message | `string` | No | `COOKIE_MESSAGE`
Returns : `void`

Public setElement
`setElement(name, data)`
Defined in projects/commons/src/lib/elements/cookie/services/cookie.service.ts:34
Parameters :
Name | Optional
name | No
data | No
Returns : `void`

Private setStyleNotification
`setStyleNotification()`
Defined in projects/commons/src/lib/elements/cookie/services/cookie.service.ts:42
Returns : `void`

### Properties

Public element
Defined in projects/commons/src/lib/elements/cookie/services/cookie.service.ts:13

    import autobind from 'autobind-decorator';

    import { Inject, Injectable } from '@angular/core';

    import { COOKIE_MESSAGE } from '../constants';
    import { colorsEnum } from '../../../shared/enums';
    import { ToastService } from '../../toast/services';
    import { toastPositionEnum } from '../../toast/enums';
    import { IToastConfig } from '../../toast/interfaces';

    @Injectable()
    export class CookieService {
        public element;

        constructor(
            private readonly toastService: ToastService,
            @Inject('DOCUMENT') private readonly document: any,
        ) {}

        public init(message: string = COOKIE_MESSAGE) {
            if (!this.existCookie('terms')) {
                this.toastService.open({
                    message,
                    dismissible: true,
                    duration: 20000000,
                    position: toastPositionEnum.bottomCenter,
                    type: `${ colorsEnum.dark } cookie-notification`,
                } as  IToastConfig);

                this.setStyleNotification();
            }
        }

        public setElement(name, data) {
            this.document.cookie = `${ name }=${ data }`;
        }

        public existCookie(name) {
            return this.document.cookie.split('=').findIndex((element) => element === name) >= 0;
        }

        private setStyleNotification() {
            const button = this.document.getElementsByClassName('cookie-accept')[0] as any;

            this.element = this.document.getElementsByClassName('cookie-notification')[0] as any;

            this.element.style.bottom = '0';
            this.element.style.width = '100%';
            this.element.style.position = 'absolute';
            this.element.style['border-radius'] = '0';

            button.addEventListener('click', this.eventClickAccept);
        }

        @autobind
        private eventClickAccept() {
            this.setElement('terms', 'accepted');

            this.element.style.display = 'none';
        }
    }

# result-matching ""

# No results matching ""