summaryrefslogtreecommitdiff
path: root/externals/bootstrap-3.2/js/bootstrap-cookie-consent.js
blob: 99589c715a09d61a73d91511a4820787f065ef1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Creare's 'Implied Consent' EU Cookie Law Banner v:2.4
// Conceived by Robert Kent, James Bavington & Tom Foyster
// Modified by Simon Freytag for syntax, namespace, jQuery and Bootstrap

C = {
	// Number of days before the cookie expires, and the banner reappears
	cookieDuration: 14,

	// Name of our cookie
	cookieName: 'complianceCookie',

	// Value of cookie
	cookieValue: 'on',

	// Message banner title
	bannerTitle: "Cookies:",

	// Message banner message
	bannerMessage: "This site uses cookies to deliver its services. We do not share your visit with any third party.",

	// Message banner dismiss button
	bannerButton: "OK",

	// Link to your cookie policy.
	bannerLinkURL: "/wiki/Cookies",

	// Link text
	bannerLinkText: "Read more",

	// Text alignment
	alertAlign: "center",

	// Link text
	buttonClass: "btn-success btn-xs",

	createDiv: function() {
		var banner = $(
			'<div class="alert alert-success alert-dismissible text-' +
			this.alertAlign + ' fade in" ' +
			'role="alert" style="position: fixed; bottom: 0; width: 100%; ' +
			'margin-bottom: 0"><strong>' + this.bannerTitle + '</strong> ' +
			this.bannerMessage + ' <a href="' + this.bannerLinkURL + '">' +
			this.bannerLinkText + '</a> <button type="button" class="btn ' +
			this.buttonClass + '" onclick="C.createCookie(C.cookieName, C.cookieValue' +
			', C.cookieDuration)" data-dismiss="alert" aria-label="Close">' +
			this.bannerButton + '</button></div>'
		)
		$("body").append(banner)
	},

	createCookie: function(name, value, days) {
		//console.log("Create cookie")
		var expires = ""
		if (days) {
			var date = new Date()
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000))
			expires = "; expires=" + date.toGMTString()
		}
		document.cookie = name + "=" + value + expires + "; path=/";
	},

	checkCookie: function(name) {
		var nameEQ = name + "="
		var ca = document.cookie.split(';')
		for (var i = 0; i < ca.length; i++) {
			var c = ca[i]
			while (c.charAt(0) == ' ')
				c = c.substring(1, c.length)
			if (c.indexOf(nameEQ) == 0)
				return c.substring(nameEQ.length, c.length)
		}
		return null
	},

	init: function() {
		if (this.checkCookie(this.cookieName) != this.cookieValue)
			this.createDiv()
	}
}

$(document).ready(function() {
	C.init()
})