Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any Angular directive for handling cookie law compliance?

I have recently decided to start trying to make a site compliant with EU cookie laws. I am using AngularJS as my front end framework. I have been looking at these jquery plugins:

https://silktide.com/tools/cookie-consent/

http://cookiesdirective.com/

However I would prefer to use an angular first solution if that is at all possible. Does anyone know of any angular directive that would be able to handle this?

like image 945
BobDoleForPresident Avatar asked Jul 09 '15 11:07

BobDoleForPresident


1 Answers

Easy as that.

angular.module('consent', ['ngCookies'])
.directive('consent', function ($cookies) {
  return {
    scope: {},
    template:
      '<div style="position: relative; z-index: 1000">' +
      '<div style="background: #ccc; position: fixed; bottom: 0; left: 0; right: 0" ng-hide="consent()">' +
      ' <a href="" ng-click="consent(true)">I\'m cookie consent</a>' +
      '</div>' +
      '</div>',
    controller: function ($scope) {
      var _consent = $cookies.get('consent');
      $scope.consent = function (consent) {
        if (consent === undefined) {
          return _consent;
        } else if (consent) {
          $cookies.put('consent', true);
          _consent = true;        
        }
      };
    }
  };
});

Add style and animation to taste.

like image 127
Estus Flask Avatar answered Nov 22 '22 17:11

Estus Flask