Skip to content

Commit e87ec50

Browse files
authored
Merge pull request #4 from arsors/road-to-npm
ES6 compatible and ready for npm
2 parents 8b0b797 + 97795f5 commit e87ec50

10 files changed

+265
-299
lines changed

Diff for: README.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ If you only want to set one single cookie which blocks content and loads/blocks
7575
```html
7676
<script src="https://cdn.jsdelivr.net/gh/arsors/arsorscookie/dist/arsors.cookie.min.js"></script>
7777
<script>
78-
var myCookie = new arsorsCookie({
78+
var myCookie = new ArsorsCookie({
7979
c : {
8080
type: 'opt-in'
8181
},
@@ -120,7 +120,7 @@ Arsors.Cookie configuration is segmented into two sections: one for the global s
120120
### Change Privacy Policy
121121
There are three different types of privacy policies: `opt-in`, `opt-out` & `info`. All you have to change is the `type` property in `c`.
122122
```js
123-
var myCookie = new arsorsCookie({
123+
var myCookie = new ArsorsCookie({
124124
c : {
125125
type: 'opt-in'
126126
}
@@ -132,7 +132,7 @@ With dynamic allow the blocked content is displayed without reloading the page c
132132

133133
The cookie message itself can also allow content dynamically, but once a cookie is allowed in any way, dynamic loading is disabled for the cookie message. The reason for this is that already loaded JavaScript files cannot be reliably removed. So in this case the page will be reloaded completely. To disable the "allow dynamic loading" function you can use the following code.
134134
```js
135-
var myCookie = new arsorsCookie({
135+
var myCookie = new ArsorsCookie({
136136
c : {
137137
dynamicAllow: false
138138
}
@@ -145,7 +145,7 @@ You can adjust the complete HTML markup as you like and work with template varia
145145
#### Cookie Notice
146146
Create your custom cookie notice HTML with nested template variables.
147147
```js
148-
var myCookie = new arsorsCookie({
148+
var myCookie = new ArsorsCookie({
149149
c : {
150150
html: '<div class="arsorsCookie"><div class="arsorsCookie_text">{{myCustomText}}</div><div class="arsorsCookie_btnWrapper">{{deny}}{{allow}}</div></div>',
151151
myCustomText: 'This website uses cookies. Some of these cookies require your explicit consent. Please agree to the use of cookies in order to use all functions of the website. Detailed information on the use of cookies can be found in our {{learnMore}}. Here you can also revoke your consent to the use of cookies.',
@@ -165,7 +165,7 @@ As you can see we start with the required `html` property and insert the content
165165
When the user accepts or denies the cookies the cookie notice disappears. If you want to provide the possibility to display the cookie notice again, you could use a floating button. You decide how you want to implement it.
166166
Arsors.Cookie generates a Click EventHandler for the class `btn-toggleCookie` by default. Just add this class to a button anywhere you want **or** add it as template variable and include it to your custom cookie notice HTML. For example:
167167
```js
168-
var myCookie = new arsorsCookie({
168+
var myCookie = new ArsorsCookie({
169169
c : {
170170
html: '{{floatingHtml}}<div class="arsorsCookie">[...]</div>',
171171
floatingHtml: '<a class="btn-toggleCookie arsorsCookie_floatingBtn" href="#">{{floatingHtmlText}}</a>',
@@ -182,7 +182,7 @@ If you want to render only a single checkbox you can append the key of the cooki
182182
### Cookie Lifetime
183183
You can change the global cookie lifetime with the property `lifetime` in `c`. This property must be set as an integer. The integer will be counted as days.
184184
```js
185-
var myCookie = new arsorsCookie({
185+
var myCookie = new ArsorsCookie({
186186
c : {
187187
lifetime: 365
188188
}
@@ -192,7 +192,7 @@ var myCookie = new arsorsCookie({
192192
### Global Error Message
193193
If you don't set up a custom error message for a custom cookie the default global error message will appear. Here is an example of how you can change it:
194194
```js
195-
var myCookie = new arsorsCookie({
195+
var myCookie = new ArsorsCookie({
196196
c : {
197197
globalErrorMsg: '<div class="ac_error"><p>You must accept cookies to view this content. <a class="btn-allowCookie-all" href="#">Accept Cookies</a></p></div>'
198198
}
@@ -209,7 +209,7 @@ If you want a checkbox to allow or deny each cookie then just [activate the chec
209209
To initialize a new custom cookie just add a new object to the `e` property with the minimum of these three required values: `Class/ID Name` as object key (and as HTML Class or ID for the [custom error message](#custom-error-message)), `title` as the title of the cookie and `cookieName` for the name of the cookie that shall be created.
210210
Please keep in mind that Arsors.Cookie has already one predefined cookie `.arsorsCookie_main`. The first cookie key **has** to be `.arsorsCookie_main` otherwise you will recieve an error. Of course you can overwrite all properties of the predefined cookie.
211211
```js
212-
var myCookie = new arsorsCookie({
212+
var myCookie = new ArsorsCookie({
213213
e : {
214214
'.arsorsCookie_main': { // this key is predefined and must exist
215215
title: "Required",
@@ -230,7 +230,7 @@ var myCookie = new arsorsCookie({
230230
### Event Handler
231231
Every custom cookie can have its own Click EventHandler. It can be initialized by the property `btnClasses`. The property will create classes which you have to add to a HTML-Tag (such as button or a). You can also use the href-property, just place a # before the classname. See the examples below. That way you can place the button everywhere you want it in the frontend and enable the user to edit the custom cookie preferences afterwards. To allow or deny all cookies at a time there's a [predefined EventHandler](#predefined-click-eventHandler).
232232
```js
233-
var myCookie = new arsorsCookie({
233+
var myCookie = new ArsorsCookie({
234234
e : {
235235
'.arsorsCookie_main': { // this key is predefined and must exist
236236
title: "Required",
@@ -249,7 +249,7 @@ Then you can add the following HTML where you want it:
249249
### Blocking Scripts
250250
Each custom cookie can block multiple JavaScript files. Therefore you need to reference these JavaScript files under the property `scripts` as an array. You can also add the same JavaScript file to multiple custom cookies. Arsors.Cookie will handle this and load the specific JavaScript file only once. The order in which you specify the scripts in the array also determines the order in which the scripts are loaded. When you initialize several cookies in a row the scripts will be loaded top to button.
251251
```js
252-
var myCookie = new arsorsCookie({
252+
var myCookie = new ArsorsCookie({
253253
e : {
254254
'.arsorsCookie_main': { // this key is predefined and must exist
255255
title: "Required",
@@ -273,7 +273,7 @@ When you want to combine the property `script` and `scripts` it could happen tha
273273
### Blocking iFrames or any Content
274274
The key of each custom cookie object needs to initialize as an ID `#name` or as a class `.name`. Then Arsors.Cookie creates for you the specific ID or Class as blocking container. All you have to do is wrap an element with the ID or Class around the content you want to block and change the `src`-Attribute of the iFrames or Images to `data-src` or `data-ac-src`. When the container gets blocked the global error message or the custom cookie error message will appear instead.
275275
```js
276-
var myCookie = new arsorsCookie({
276+
var myCookie = new ArsorsCookie({
277277
e : {
278278
'.arsorsCookie_main': { // this key is predefined and must exist
279279
title: "Required",
@@ -294,11 +294,11 @@ var myCookie = new arsorsCookie({
294294
### Custom Error Message
295295
When you [block iFrames or any content](#blocking-iframes-or-any-content) you can also show a custom error message. Each custom cookie can be provided with a custom error message. Just add the property `errorMsg`. If you also added the `btnClasses` ([Event Handler](#event-handler)) you can directly provide a link to accept the specific cookie in the custom error message.
296296
```js
297-
var myCookie = new arsorsCookie({
297+
var myCookie = new ArsorsCookie({
298298
e : {
299299
'.arsorsCookie_main': { // this key is predefined and must exist
300300
title: "Required",
301-
cookieName: "arsorsCookie_main"
301+
cookieName: "arsorsCookie_main",
302302
btnClasses: {allow: 'btn-allowCookie', deny: "btn-denyCookie"},
303303
errorMsg: '<div class="ac_error"><p>CUSTOM: You must accept cookies to view this content. <a class="btn-allowCookie" href="#">Accept Cookies</a></p></div>'
304304
}
@@ -310,7 +310,7 @@ If you don't need a custom error message then just set the property `errorMsg` t
310310
### Required
311311
Using the [checkbox function](#checkbox-function) each custom cookie can be marked as `required`. Thus the user can't uncheck this one and only gets the two options to accept or deny all cookies.
312312
```js
313-
var myCookie = new arsorsCookie({
313+
var myCookie = new ArsorsCookie({
314314
e : {
315315
'.arsorsCookie_main': { // this key is predefined and must exist
316316
title: "Required",
@@ -324,7 +324,7 @@ var myCookie = new arsorsCookie({
324324
### forceUnchecked
325325
Using the [checkbox function](#checkbox-function) each custom cookie can forced to be unchecked.
326326
```js
327-
var myCookie = new arsorsCookie({
327+
var myCookie = new ArsorsCookie({
328328
e : {
329329
'.arsorsCookie_custom': {
330330
title: "Custom",
@@ -372,8 +372,8 @@ if (lang == "de") {
372372
};
373373
}
374374

375-
var mergeConfig = arsorsCookie.prototype.merge(true, globalConfig, langConfig);
376-
var myCookie = new arsorsCookie(mergeConfig);
375+
var mergeConfig = ArsorsCookie.prototype.merge(true, globalConfig, langConfig);
376+
var myCookie = new ArsorsCookie(mergeConfig);
377377
```
378378
**Other possibilities:** For Wordpress, Neos or any other content management system you could also use PHP to generate the JavaScript configuration with the appropriate texts in the desired language. You could also use i18n for the integration of the correct texts or you could write your own JavaScript function which returns the correct text via IDs. Be creative! There are lots of possibilities.
379379

@@ -396,7 +396,7 @@ This function called `getTypeByCountryCode()` inside and return like `getTypeByC
396396
```js
397397
// setCountryCode()
398398
// IF WE DON'T KNOW THE COUNTRY CODE WE HAVE TO USE A SERVICE
399-
var locationType = arsorsCookie.prototype.setCountryCode(function() {
399+
var locationType = ArsorsCookie.prototype.setCountryCode(function() {
400400
// get content of api
401401
var xmlhttp = new XMLHttpRequest();
402402
var url = 'http://api.ipinfodb.com/v3/ip-country/?format=json&key=KEY&ip=IP';
@@ -405,15 +405,15 @@ var locationType = arsorsCookie.prototype.setCountryCode(function() {
405405
if (this.readyState == 4 && this.status == 200) {
406406
var json = JSON.parse(this.responseText);
407407
if (json.statusCode == "OK") {
408-
arsorsCookie.prototype.setCookie("arsorsCookie_countryCode", json.countryCode, 365);
408+
ArsorsCookie.prototype.setCookie("arsorsCookie_countryCode", json.countryCode, 365);
409409
location.reload();
410410
} else {
411-
arsorsCookie.prototype.setCookie("arsorsCookie_countryCode", "false", 365);
411+
ArsorsCookie.prototype.setCookie("arsorsCookie_countryCode", "false", 365);
412412
location.reload();
413413
}
414414
}
415415
if (this.readyState == 4 && this.status == 0) {
416-
arsorsCookie.prototype.setCookie("arsorsCookie_countryCode", "false", 365);
416+
ArsorsCookie.prototype.setCookie("arsorsCookie_countryCode", "false", 365);
417417
location.reload();
418418
}
419419
};
@@ -433,7 +433,7 @@ var globalConfig = {
433433
};
434434

435435
// Activate Arsors.Cookie if country code is set
436-
if (locationType != false) var myCookie = new arsorsCookie(mergeConfig); // locationType != false prevent loading the cookie notice while searching for the country code by a external service
436+
if (locationType != false) var myCookie = new ArsorsCookie(mergeConfig); // locationType != false prevent loading the cookie notice while searching for the country code by a external service
437437
```
438438
**Tip** Here is a wonderful list of services to get the the country code from IPs: https://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript
439439

@@ -442,7 +442,7 @@ if (locationType != false) var myCookie = new arsorsCookie(mergeConfig); // loca
442442
### getTypeByCountryCode()
443443
If you know already the country code of your customer then you can use the `getTypeByCountryCode()` method. The method will return the `type` of the cookie notice behavior. Simply set the country code as parameter and Arsors.Cookie will return you the law of the country code.
444444
```js
445-
var locationType = arsorsCookie.prototype.getTypeByCountryCode("DE");
445+
var locationType = ArsorsCookie.prototype.getTypeByCountryCode("DE");
446446
```
447447
**Tip** If Arsors.Cookie didn't reply the correct law of the country code you can customize the law settings by setting the `c.optInArray` and `c.optOutArray`.
448448
```js
@@ -456,7 +456,7 @@ var locationType = arsorsCookie.prototype.getTypeByCountryCode("DE");
456456
#### Example
457457
```js
458458
// getTypeByCountryCode()
459-
var locationType = arsorsCookie.prototype.getTypeByCountryCode("DE");
459+
var locationType = ArsorsCookie.prototype.getTypeByCountryCode("DE");
460460

461461
// Set global cookie config
462462
var globalConfig = {
@@ -470,7 +470,7 @@ var globalConfig = {
470470
};
471471

472472
// Activate Arsors.Cookie if country code is set
473-
var myCookie = new arsorsCookie(mergeConfig);
473+
var myCookie = new ArsorsCookie(mergeConfig);
474474
```
475475

476476
---

Diff for: demonstration/index.html

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Arsors Cookie Plugin Demonstration</title>
66
<meta charset="UTF-8">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
8-
<link rel="stylesheet" type="text/css" href="../dist/arsors.cookie.css">
8+
<link rel="stylesheet" type="text/css" href="../dist/arsors.cookie.min.css">
99
<script src="../dist/arsors.cookie.min.js"></script>
1010
<style>
1111
/*
@@ -111,7 +111,7 @@ <h2>Event Handler</h2>
111111

112112
/*
113113
// IF WE DON'T KNOW THE COUNTRY CODE WE HAVE TO USE A SERVICE
114-
var locationType = arsorsCookie.prototype.setCountryCode(function() {
114+
var locationType = ArsorsCookie.prototype.setCountryCode(function() {
115115
// get content of api
116116
var xmlhttp = new XMLHttpRequest();
117117
var url = 'http://api.ipinfodb.com/v3/ip-country/?format=json&key=YOUR-KEY&ip=YOUR-IP';
@@ -120,15 +120,15 @@ <h2>Event Handler</h2>
120120
if (this.readyState == 4 && this.status == 200) {
121121
var json = JSON.parse(this.responseText);
122122
if (json.statusCode == "OK") {
123-
arsorsCookie.prototype.setCookie("arsorsCookie_countryCode", json.countryCode, 365);
123+
ArsorsCookie.prototype.setCookie("arsorsCookie_countryCode", json.countryCode, 365);
124124
location.reload();
125125
} else {
126-
arsorsCookie.prototype.setCookie("arsorsCookie_countryCode", "false", 365);
126+
ArsorsCookie.prototype.setCookie("arsorsCookie_countryCode", "false", 365);
127127
location.reload();
128128
}
129129
}
130130
if (this.readyState == 4 && this.status == 0) {
131-
arsorsCookie.prototype.setCookie("arsorsCookie_countryCode", "false", 365);
131+
ArsorsCookie.prototype.setCookie("arsorsCookie_countryCode", "false", 365);
132132
location.reload();
133133
}
134134
};
@@ -138,7 +138,7 @@ <h2>Event Handler</h2>
138138
*/
139139

140140
// IF WE NOW THE COUNTRY CODE WE CAN JUST CHECK FOR CORRECT PRIVACY POLICY
141-
//var locationType = arsorsCookie.prototype.getTypeByCountryCode("DE");
141+
//var locationType = ArsorsCookie.prototype.getTypeByCountryCode("DE");
142142

143143
var lang = "en";
144144

@@ -204,9 +204,9 @@ <h2>Event Handler</h2>
204204
};
205205
}
206206

207-
var mergeConfig = arsorsCookie.prototype.merge(true, globalConfig, langConfig);
208-
//if (locationType != false) var myCookie = new arsorsCookie(mergeConfig); // locationType != false prevent loading the cookie notice while searching for the country code by a external service
209-
var myCookie = new arsorsCookie(mergeConfig);
207+
var mergeConfig = ArsorsCookie.prototype.merge(true, globalConfig, langConfig);
208+
//if (locationType != false) var myCookie = new ArsorsCookie(mergeConfig); // locationType != false prevent loading the cookie notice while searching for the country code by a external service
209+
var myCookie = new ArsorsCookie(mergeConfig);
210210
</script>
211211
</body>
212212
</html>

0 commit comments

Comments
 (0)