UNPKG

cookie-service-banner

Version:

[![npm version](https://badge.fury.io/js/cookie-service-banner.svg)](https://badge.fury.io/js/cookie-service-banner) [![Build Status](https://travis-ci.org/liyokuna/cookie-consent.svg?branch=master)](https://travis-ci.org/liyokuna/cookie-consent) [![depen

315 lines (306 loc) 15.9 kB
import { InjectionToken, ɵɵdefineInjectable, Injectable, Inject, EventEmitter, Output, Component, NgModule } from '@angular/core'; import { __decorate, __metadata, __param } from 'tslib'; import { of } from 'rxjs'; import { CommonModule } from '@angular/common'; var CookieConfigService = new InjectionToken('CookieConfig'); var CookieServiceService = /** @class */ (function () { function CookieServiceService() { this.GA_COOKIE_NAMES = ['__utma', '__utmb', '__utmc', '__utmz', '_ga', '_gid', '_gat', '_gat_gtag']; } CookieServiceService.prototype.setCookie = function (name, val, domain) { var date = new Date(); var value = val; // Set it expire in 395 days, compliance with Cookie Laws in EU date.setTime(date.getTime() + (395 * 24 * 60 * 60 * 1000)); document.cookie = name + ' = ' + value + '; expires=' + date.toUTCString() + '; path=/'; }; CookieServiceService.prototype.setCookieWithString = function (name, val, domain) { var date = new Date(); var value = val; // Set it expire in 395 days, compliance with Cookie Laws in EU date.setTime(date.getTime() + (395 * 24 * 60 * 60 * 1000)); document.cookie = name + ' = ' + value + '; expires=' + date.toUTCString() + '; path=/'; }; CookieServiceService.prototype.getCookie = function (name) { var value = '; ' + document.cookie; var parts = value.split('; ' + name + '='); if (parts.length === 2) { return parts.pop().split(';').shift(); } }; CookieServiceService.prototype.deleteCookie = function (name) { var date = new Date(); date.setTime(date.getTime() + (-1 * 24 * 60 * 60 * 1000)); document.cookie = name + '=; expires=' + date.toUTCString() + '; path=/'; }; CookieServiceService.prototype.rejectCookie = function (gaId) { var _this = this; // disable GA this.deleteCookie("ga-disable-" + gaId); this.deleteCookie('consent'); window["ga-disable-" + gaId] = true; window["_gat_gtag_" + gaId] = false; this.GA_COOKIE_NAMES.forEach(function (cookieName) { _this.deleteCookie(cookieName); }); }; CookieServiceService.prototype.isAnalytics = function (str) { return (/^ua-\d{4,9}-\d{1,4}$/i).test(str.toString()); }; CookieServiceService.ɵprov = ɵɵdefineInjectable({ factory: function CookieServiceService_Factory() { return new CookieServiceService(); }, token: CookieServiceService, providedIn: "root" }); CookieServiceService = __decorate([ Injectable({ providedIn: 'root' }), __metadata("design:paramtypes", []) ], CookieServiceService); return CookieServiceService; }()); var ConfigService = /** @class */ (function () { function ConfigService(config) { this.config = config; } ConfigService.prototype.getConfig = function () { return of(this.config); }; ConfigService.prototype.getHeader = function () { return of(this.config.header.title); }; ConfigService.prototype.getHeaderColor = function () { return of(this.config.header.color); }; ConfigService.prototype.getHeaderBackgroundColor = function () { return of(this.config.header.bcolor); }; ConfigService.prototype.getDomain = function () { return of(this.config.header.domain); }; ConfigService.prototype.getGA_id = function () { return of(this.config.header.ga_id); }; ConfigService.prototype.getMessage = function () { return of(this.config.header.message); }; ConfigService.prototype.getAcceptEnable = function () { return of(this.config.acceptButton.enable); }; ConfigService.prototype.getAcceptMessage = function () { return of(this.config.acceptButton.accept); }; ConfigService.prototype.getAcceptColor = function () { return of(this.config.acceptButton.color); }; ConfigService.prototype.getAcceptBackgroundColor = function () { return of(this.config.acceptButton.bcolor); }; ConfigService.prototype.getDenyEnable = function () { return of(this.config.declineButton.enable); }; ConfigService.prototype.getDenyMessage = function () { return of(this.config.declineButton.deny); }; ConfigService.prototype.getDenyColor = function () { return of(this.config.declineButton.color); }; ConfigService.prototype.getDenyBackgroundColor = function () { return of(this.config.declineButton.bcolor); }; ConfigService.prototype.getAllowEnable = function () { return of(this.config.allowButton.enable); }; ConfigService.prototype.getAllowMessage = function () { return of(this.config.allowButton.allow); }; ConfigService.prototype.getAllowColor = function () { return of(this.config.allowButton.color); }; ConfigService.prototype.getAllowBackgroundColor = function () { return of(this.config.allowButton.bcolor); }; ConfigService.prototype.getLinkButton = function () { return of(this.config.learnMoreLink); }; ConfigService.prototype.getLinkMessage = function () { return of(this.config.learnMoreLink.learnMore); }; ConfigService.prototype.getLinkLink = function () { return of(this.config.learnMoreLink.link); }; ConfigService.prototype.getLinkEnable = function () { return of(this.config.learnMoreLink.enable); }; ConfigService.prototype.getLinkColor = function () { return of(this.config.learnMoreLink.color); }; ConfigService.prototype.getReviewEnable = function () { return of(this.config.review.enable); }; ConfigService.prototype.getReviewMessage = function () { return of(this.config.review.message); }; ConfigService.prototype.getReviewColor = function () { return of(this.config.review.color); }; ConfigService.prototype.getReviewBackgroundColor = function () { return of(this.config.review.bcolor); }; ConfigService.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: Inject, args: [CookieConfigService,] }] } ]; }; ConfigService = __decorate([ Injectable(), __param(0, Inject(CookieConfigService)), __metadata("design:paramtypes", [Object]) ], ConfigService); return ConfigService; }()); var CookieServiceComponent = /** @class */ (function () { function CookieServiceComponent(cookiemanager, cookieconfig) { this.cookiemanager = cookiemanager; this.cookieconfig = cookieconfig; this.isOpened = new EventEmitter(); } CookieServiceComponent.prototype.ngOnInit = function () { this.getValues(); this.getColors(); if (!this.cookiemanager.isAnalytics(this.GA_ID)) { this.GA_ID = '0000'; console.log('Your Google Analytics ID seems to have a problem'); return; } if (!this.cookiemanager.getCookie('consent')) { this.showAlertCookie = true; this.isOpened.emit(this.showAlertCookie); } if (this.cookiemanager.getCookie('consent') && !this.showAlertCookie) { var TrackNavigator = navigator.doNotTrack; if ((TrackNavigator === '1' || TrackNavigator === 'yes')) { this.cookiemanager.rejectCookie(this.GA_ID); this.showAlertCookie = false; this.isOpened.emit(false); return; } if (this.cookiemanager.getCookie('consent') === 'false' && ((TrackNavigator === '1' || TrackNavigator === 'yes'))) { this.cookiemanager.rejectCookie(this.GA_ID); this.showAlertCookie = false; this.isOpened.emit(this.showAlertCookie); return; } if (this.cookiemanager.getCookie('consent') === 'false') { this.cookiemanager.rejectCookie(this.GA_ID); this.showAlertCookie = false; this.isOpened.emit(this.showAlertCookie); return; } } }; CookieServiceComponent.prototype.getValues = function () { var _this = this; this.cookieconfig.getHeader().subscribe(function (val) { return _this.header = val; }); this.cookieconfig.getMessage().subscribe(function (val) { return _this.message = val; }); this.cookieconfig.getAcceptMessage().subscribe(function (val) { return _this.AcceptMessage = val; }); this.cookieconfig.getAcceptEnable().subscribe(function (val) { return _this.AcceptEnable = val; }); this.cookieconfig.getLinkMessage().subscribe(function (val) { return _this.LearnMoreMessage = val; }); this.cookieconfig.getLinkEnable().subscribe(function (val) { return _this.LearnMoreEnable = val; }); this.cookieconfig.getLinkLink().subscribe(function (val) { return _this.LearnMoreLink = val; }); this.cookieconfig.getDenyMessage().subscribe(function (val) { return _this.DenyMessage = val; }); this.cookieconfig.getDenyEnable().subscribe(function (val) { return _this.DenyEnable = val; }); this.cookieconfig.getAllowMessage().subscribe(function (val) { return _this.AllowMessage = val; }); this.cookieconfig.getAllowEnable().subscribe(function (val) { return _this.AllowEnable = val; }); this.cookieconfig.getDomain().subscribe(function (val) { return _this.domain = val; }); this.cookieconfig.getGA_id().subscribe(function (val) { return _this.GA_ID = val; }); this.cookieconfig.getReviewEnable().subscribe(function (val) { return _this.ReviewEnable = val; }); this.cookieconfig.getReviewMessage().subscribe(function (val) { return _this.Review = val; }); }; CookieServiceComponent.prototype.getColors = function () { var _this = this; this.cookieconfig.getHeaderColor().subscribe(function (val) { return _this.HeaderColor = val; }); this.cookieconfig.getHeaderBackgroundColor().subscribe(function (val) { return _this.HeaderBackgroundColor = val; }); this.cookieconfig.getAcceptColor().subscribe(function (val) { return _this.AcceptColor = val; }); this.cookieconfig.getAcceptBackgroundColor().subscribe(function (val) { return _this.AcceptBackgroundColor = val; }); this.cookieconfig.getDenyColor().subscribe(function (val) { return _this.DenyColor = val; }); this.cookieconfig.getDenyBackgroundColor().subscribe(function (val) { return _this.DenyBackgroundColor = val; }); this.cookieconfig.getAllowColor().subscribe(function (val) { return _this.AllowColor = val; }); this.cookieconfig.getAllowBackgroundColor().subscribe(function (val) { return _this.AllowBackgroundColor = val; }); this.cookieconfig.getLinkColor().subscribe(function (val) { return _this.LearnMoreColor = val; }); this.cookieconfig.getReviewColor().subscribe(function (val) { return _this.ReviewColor = val; }); this.cookieconfig.getReviewBackgroundColor().subscribe(function (val) { return _this.ReviewBcolor = val; }); }; CookieServiceComponent.prototype.cssClass = function (color, bcolor) { return { 'color': color, 'background-color': bcolor, 'border-color': bcolor, }; }; CookieServiceComponent.prototype.deny = function () { this.cookiemanager.rejectCookie(this.GA_ID); this.cookiemanager.setCookie('consent', true, this.domain); this.showAlertCookie = false; this.isOpened.emit(this.showAlertCookie); return; }; CookieServiceComponent.prototype.allow = function () { this.cookiemanager.setCookie('consent', true, this.domain); this.showAlertCookie = false; this.isOpened.emit(this.showAlertCookie); return; }; CookieServiceComponent.prototype.review = function () { this.cookiemanager.rejectCookie(this.GA_ID); location.reload(); }; CookieServiceComponent.ctorParameters = function () { return [ { type: CookieServiceService }, { type: ConfigService } ]; }; __decorate([ Output(), __metadata("design:type", EventEmitter) ], CookieServiceComponent.prototype, "isOpened", void 0); CookieServiceComponent = __decorate([ Component({ selector: 'lib-cookie-service', template: "<section id=\"cookie-alert\">\n <div class=\"alert-cookie bottom\" *ngIf=\"showAlertCookie\" attr.aria-label=\"{{ header }}\" attr.title= \"{{ header }}\" [ngStyle]=\"cssClass(HeaderColor, HeaderBackgroundColor )\">\n <div class=\"row\">\n <div class=\"col-sm-10\">\n <p>\n <b>{{ message }}</b>\n <a *ngIf=\"LearnMoreEnable \" href=\"{{ LearnMoreLink }}\" attr.aria-label=\"{{ LearnMoreMessage }}\" attr.title= \"{{ LearnMoreMessage }}\" >{{ LearnMoreMessage }}</a>\n </p>\n </div>\n <div class=\"col-sm-2\">\n <button *ngIf=\"DenyEnable \" type=\"button\" class=\"cbtn\" (click)=\"this.deny()\" attr.aria-label=\"{{ DenyMessage }}\" attr.title= \"{{ DenyMessage }}\" [ngStyle]=\"cssClass(AcceptColor, 'transparent' )\">{{ DenyMessage }}</button>\n <button *ngIf=\"AllowEnable \" type=\"button\" class=\"cbtn\" (click)=\"this.allow()\" attr.aria-label=\"{{ AllowMessage }}\" attr.title= \"{{ AllowMessage }}\" [ngStyle]=\"cssClass(AllowColor, AllowBackgroundColor)\">{{ AllowMessage }}</button>\n <button *ngIf=\"AcceptEnable \" type=\"button\" class=\"cbtn\" (click)=\"this.allow()\" attr.aria-label=\"{{ AcceptMessage }}\" attr.title= \"{{ AcceptMessage }}\" [ngStyle]=\"cssClass(AcceptColor, AcceptBackgroundColor)\">{{ AcceptMessage }}</button>\n </div>\n </div>\n </div>\n\n <div class=\"bottom\" *ngIf=\"!showAlertCookie && ReviewEnable\">\n <button class=\"btn btn-dark btn-sm\" (click)=\"this.review()\" href=\"#\" [ngStyle]=\"cssClass(ReviewColor, ReviewBcolor )\" attr.aria-label=\"{{ Review }}\" attr.title= \"{{ Review }}\" >{{Review}}</button>\n </div>\n</section>", providers: [CookieServiceService, ConfigService], styles: [".alert-cookie{position:fixed;width:100%;padding:.75rem 1.25rem}.bottom{bottom:0;left:0;position:fixed;right:0}.cbtn{border:1px solid transparent;padding:.375rem .75rem;font-size:1rem;line-height:1.5;border-radius:.25rem}"] }), __metadata("design:paramtypes", [CookieServiceService, ConfigService]) ], CookieServiceComponent); return CookieServiceComponent; }()); var CookieServiceModule = /** @class */ (function () { function CookieServiceModule() { } CookieServiceModule_1 = CookieServiceModule; CookieServiceModule.forRoot = function (config) { return { ngModule: CookieServiceModule_1, providers: [ CookieServiceService, { provide: CookieConfigService, useValue: config } ] }; }; var CookieServiceModule_1; CookieServiceModule = CookieServiceModule_1 = __decorate([ NgModule({ imports: [CommonModule ], declarations: [CookieServiceComponent], exports: [CookieServiceComponent] }) ], CookieServiceModule); return CookieServiceModule; }()); /* * Public API Surface of cookie-service */ /** * Generated bundle index. Do not edit. */ export { CookieConfigService, CookieServiceComponent, CookieServiceModule, CookieServiceService as ɵa, ConfigService as ɵb }; //# sourceMappingURL=cookie-service-banner.js.map