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

16 lines (14 loc) 11.9 kB
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports,require("@angular/core"),require("rxjs"),require("@angular/common")):"function"==typeof define&&define.amd?define("cookie-service-banner",["exports","@angular/core","rxjs","@angular/common"],o):o((e=e||self)["cookie-service-banner"]={},e.ng.core,e.rxjs,e.ng.common)}(this,(function(e,o,t,n){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */function i(e,o,t,n){var i,r=arguments.length,c=r<3?o:null===n?n=Object.getOwnPropertyDescriptor(o,t):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,o,t,n);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(c=(r<3?i(c):r>3?i(o,t,c):i(o,t))||c);return r>3&&c&&Object.defineProperty(o,t,c),c}function r(e,o){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,o)}var c=new o.InjectionToken("CookieConfig"),s=function(){function e(){this.GA_COOKIE_NAMES=["__utma","__utmb","__utmc","__utmz","_ga","_gid","_gat","_gat_gtag"]}return e.prototype.setCookie=function(e,o,t){var n=new Date,i=o;n.setTime(n.getTime()+34128e6),document.cookie=e+" = "+i+"; expires="+n.toUTCString()+"; path=/"},e.prototype.setCookieWithString=function(e,o,t){var n=new Date,i=o;n.setTime(n.getTime()+34128e6),document.cookie=e+" = "+i+"; expires="+n.toUTCString()+"; path=/"},e.prototype.getCookie=function(e){var o=("; "+document.cookie).split("; "+e+"=");if(2===o.length)return o.pop().split(";").shift()},e.prototype.deleteCookie=function(e){var o=new Date;o.setTime(o.getTime()+-864e5),document.cookie=e+"=; expires="+o.toUTCString()+"; path=/"},e.prototype.rejectCookie=function(e){var o=this;this.deleteCookie("ga-disable-"+e),this.deleteCookie("consent"),window["ga-disable-"+e]=!0,window["_gat_gtag_"+e]=!1,this.GA_COOKIE_NAMES.forEach((function(e){o.deleteCookie(e)}))},e.prototype.isAnalytics=function(e){return/^ua-\d{4,9}-\d{1,4}$/i.test(e.toString())},e.ɵprov=o.ɵɵdefineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e=i([o.Injectable({providedIn:"root"}),r("design:paramtypes",[])],e)}(),a=function(){function e(e){this.config=e}var n,s;return e.prototype.getConfig=function(){return t.of(this.config)},e.prototype.getHeader=function(){return t.of(this.config.header.title)},e.prototype.getHeaderColor=function(){return t.of(this.config.header.color)},e.prototype.getHeaderBackgroundColor=function(){return t.of(this.config.header.bcolor)},e.prototype.getDomain=function(){return t.of(this.config.header.domain)},e.prototype.getGA_id=function(){return t.of(this.config.header.ga_id)},e.prototype.getMessage=function(){return t.of(this.config.header.message)},e.prototype.getAcceptEnable=function(){return t.of(this.config.acceptButton.enable)},e.prototype.getAcceptMessage=function(){return t.of(this.config.acceptButton.accept)},e.prototype.getAcceptColor=function(){return t.of(this.config.acceptButton.color)},e.prototype.getAcceptBackgroundColor=function(){return t.of(this.config.acceptButton.bcolor)},e.prototype.getDenyEnable=function(){return t.of(this.config.declineButton.enable)},e.prototype.getDenyMessage=function(){return t.of(this.config.declineButton.deny)},e.prototype.getDenyColor=function(){return t.of(this.config.declineButton.color)},e.prototype.getDenyBackgroundColor=function(){return t.of(this.config.declineButton.bcolor)},e.prototype.getAllowEnable=function(){return t.of(this.config.allowButton.enable)},e.prototype.getAllowMessage=function(){return t.of(this.config.allowButton.allow)},e.prototype.getAllowColor=function(){return t.of(this.config.allowButton.color)},e.prototype.getAllowBackgroundColor=function(){return t.of(this.config.allowButton.bcolor)},e.prototype.getLinkButton=function(){return t.of(this.config.learnMoreLink)},e.prototype.getLinkMessage=function(){return t.of(this.config.learnMoreLink.learnMore)},e.prototype.getLinkLink=function(){return t.of(this.config.learnMoreLink.link)},e.prototype.getLinkEnable=function(){return t.of(this.config.learnMoreLink.enable)},e.prototype.getLinkColor=function(){return t.of(this.config.learnMoreLink.color)},e.prototype.getReviewEnable=function(){return t.of(this.config.review.enable)},e.prototype.getReviewMessage=function(){return t.of(this.config.review.message)},e.prototype.getReviewColor=function(){return t.of(this.config.review.color)},e.prototype.getReviewBackgroundColor=function(){return t.of(this.config.review.bcolor)},e.ctorParameters=function(){return[{type:void 0,decorators:[{type:o.Inject,args:[c]}]}]},e=i([o.Injectable(),(n=0,s=o.Inject(c),function(e,o){s(e,o,n)}),r("design:paramtypes",[Object])],e)}(),l=function(){function e(e,t){this.cookiemanager=e,this.cookieconfig=t,this.isOpened=new o.EventEmitter}return e.prototype.ngOnInit=function(){if(this.getValues(),this.getColors(),!this.cookiemanager.isAnalytics(this.GA_ID))return this.GA_ID="0000",void console.log("Your Google Analytics ID seems to have a problem");if(this.cookiemanager.getCookie("consent")||(this.showAlertCookie=!0,this.isOpened.emit(this.showAlertCookie)),this.cookiemanager.getCookie("consent")&&!this.showAlertCookie){var e=navigator.doNotTrack;if("1"===e||"yes"===e)return this.cookiemanager.rejectCookie(this.GA_ID),this.showAlertCookie=!1,void this.isOpened.emit(!1);if("false"===this.cookiemanager.getCookie("consent")&&("1"===e||"yes"===e))return this.cookiemanager.rejectCookie(this.GA_ID),this.showAlertCookie=!1,void this.isOpened.emit(this.showAlertCookie);if("false"===this.cookiemanager.getCookie("consent"))return this.cookiemanager.rejectCookie(this.GA_ID),this.showAlertCookie=!1,void this.isOpened.emit(this.showAlertCookie)}},e.prototype.getValues=function(){var e=this;this.cookieconfig.getHeader().subscribe((function(o){return e.header=o})),this.cookieconfig.getMessage().subscribe((function(o){return e.message=o})),this.cookieconfig.getAcceptMessage().subscribe((function(o){return e.AcceptMessage=o})),this.cookieconfig.getAcceptEnable().subscribe((function(o){return e.AcceptEnable=o})),this.cookieconfig.getLinkMessage().subscribe((function(o){return e.LearnMoreMessage=o})),this.cookieconfig.getLinkEnable().subscribe((function(o){return e.LearnMoreEnable=o})),this.cookieconfig.getLinkLink().subscribe((function(o){return e.LearnMoreLink=o})),this.cookieconfig.getDenyMessage().subscribe((function(o){return e.DenyMessage=o})),this.cookieconfig.getDenyEnable().subscribe((function(o){return e.DenyEnable=o})),this.cookieconfig.getAllowMessage().subscribe((function(o){return e.AllowMessage=o})),this.cookieconfig.getAllowEnable().subscribe((function(o){return e.AllowEnable=o})),this.cookieconfig.getDomain().subscribe((function(o){return e.domain=o})),this.cookieconfig.getGA_id().subscribe((function(o){return e.GA_ID=o})),this.cookieconfig.getReviewEnable().subscribe((function(o){return e.ReviewEnable=o})),this.cookieconfig.getReviewMessage().subscribe((function(o){return e.Review=o}))},e.prototype.getColors=function(){var e=this;this.cookieconfig.getHeaderColor().subscribe((function(o){return e.HeaderColor=o})),this.cookieconfig.getHeaderBackgroundColor().subscribe((function(o){return e.HeaderBackgroundColor=o})),this.cookieconfig.getAcceptColor().subscribe((function(o){return e.AcceptColor=o})),this.cookieconfig.getAcceptBackgroundColor().subscribe((function(o){return e.AcceptBackgroundColor=o})),this.cookieconfig.getDenyColor().subscribe((function(o){return e.DenyColor=o})),this.cookieconfig.getDenyBackgroundColor().subscribe((function(o){return e.DenyBackgroundColor=o})),this.cookieconfig.getAllowColor().subscribe((function(o){return e.AllowColor=o})),this.cookieconfig.getAllowBackgroundColor().subscribe((function(o){return e.AllowBackgroundColor=o})),this.cookieconfig.getLinkColor().subscribe((function(o){return e.LearnMoreColor=o})),this.cookieconfig.getReviewColor().subscribe((function(o){return e.ReviewColor=o})),this.cookieconfig.getReviewBackgroundColor().subscribe((function(o){return e.ReviewBcolor=o}))},e.prototype.cssClass=function(e,o){return{color:e,"background-color":o,"border-color":o}},e.prototype.deny=function(){this.cookiemanager.rejectCookie(this.GA_ID),this.cookiemanager.setCookie("consent",!0,this.domain),this.showAlertCookie=!1,this.isOpened.emit(this.showAlertCookie)},e.prototype.allow=function(){this.cookiemanager.setCookie("consent",!0,this.domain),this.showAlertCookie=!1,this.isOpened.emit(this.showAlertCookie)},e.prototype.review=function(){this.cookiemanager.rejectCookie(this.GA_ID),location.reload()},e.ctorParameters=function(){return[{type:s},{type:a}]},i([o.Output(),r("design:type",o.EventEmitter)],e.prototype,"isOpened",void 0),e=i([o.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:[s,a],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}"]}),r("design:paramtypes",[s,a])],e)}(),u=function(){function e(){}var t;return t=e,e.forRoot=function(e){return{ngModule:t,providers:[s,{provide:c,useValue:e}]}},e=t=i([o.NgModule({imports:[n.CommonModule],declarations:[l],exports:[l]})],e)}();e.CookieConfigService=c,e.CookieServiceComponent=l,e.CookieServiceModule=u,e.ɵa=s,e.ɵb=a,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=cookie-service-banner.umd.min.js.map