Skip to content

Commit

Permalink
Merge pull request #4 from pixelant/fix_cache_issue
Browse files Browse the repository at this point in the history
[FIX] ajax cache issue closing cookie bar
  • Loading branch information
phathoang committed Apr 7, 2017
2 parents 0d3ed66 + 6972e9a commit 625dbbd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
49 changes: 29 additions & 20 deletions Resources/Public/Js/pxa_cookie_warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ function PxaCookieWarning() {
/* url for ajax request of close cookie bar*/
self.cookieCloseUrl = '';

self.init = function() {
if(typeof PxaCookieWarningHelper === 'undefined') return false;
self.cookieName = 'pxa_cookie_warning';

self.init = function () {
if (typeof PxaCookieWarningHelper === 'undefined') return false;

self.isActiveConsent = PxaCookieWarningHelper['isActiveConsent'];
self.cookieBarUrl = PxaCookieWarningHelper['cookieBarUrl'];
self.cookieCloseUrl = PxaCookieWarningHelper['cookieCloseUrl'];


if(self.isVisibleCookieBar()) {
if(PxaCookieWarningHelper['disableAjaxLoading']) {
if(!self.isActiveConsent) {
self.sendRequestCloseCookieBar();
if (self.isVisibleCookieBar()) {
if (PxaCookieWarningHelper['disableAjaxLoading']) {
if (!self.isActiveConsent) {
self.setCookie(self.cookieName, 1, 365);
}
self.initCookieBarClick();
} else {
Expand All @@ -30,12 +32,12 @@ function PxaCookieWarning() {
}
};

self.showCookieBar = function(response) {
self.showCookieBar = function (response) {
var cookieBar = self.create(response);
document.body.insertBefore(cookieBar, document.body.childNodes[0]);
};

self.create = function(htmlStr) {
self.create = function (htmlStr) {
var frag = document.createDocumentFragment(),
temp = document.createElement('div');
temp.innerHTML = htmlStr;
Expand All @@ -45,21 +47,25 @@ function PxaCookieWarning() {
return frag;
};

self.isVisibleCookieBar = function() {
self.isVisibleCookieBar = function () {
/* it is set in header.*/
return !PxaCookieWarningHelper['cookieIsSet'];
};

self.hideCookieBar = function() {
self.hideCookieBar = function () {
var e = document.getElementById('pxa-cookie-mess');
e.style.cssText = 'display:none';
};

self.initCookieBarClick = function() {
var clickHandler = function() {
self.initCookieBarClick = function () {
var clickHandler = function () {
var attribute = this.getAttribute('id');
if(attribute == 'accept-cookie') {
self.sendRequestCloseCookieBar();
if (attribute === 'accept-cookie') {
if (PxaCookieWarningHelper['disableAjaxLoading']) {
self.setCookie(self.cookieName, 1, 365);
} else {
self.sendRequestCloseCookieBar();
}
}

self.hideCookieBar();
Expand All @@ -83,7 +89,7 @@ function PxaCookieWarning() {
}

xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
self.showCookieBar(xmlHttp.responseText);
self.initCookieBarClick();
}
Expand All @@ -105,10 +111,13 @@ function PxaCookieWarning() {
xmlHttp.open('GET', self.cookieCloseUrl, true);
xmlHttp.send();
};
}

function initPxaCookie() {
var pxaCookieWarning = new PxaCookieWarning();
pxaCookieWarning.init();
self.setCookie = function (cName, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var cValue = encodeURI(value) + ((exdays === null) ? '' : '; expires=' + exdate.toUTCString()) + '; path=/';
document.cookie = cName + '=' + cValue;
};
}
initPxaCookie();

new PxaCookieWarning().init();
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'modify_tables' => '',
'clearCacheOnLoad' => 1,
'lockType' => '',
'version' => '1.0.5',
'version' => '1.0.6',
'constraints' => [
'depends' => [
'typo3' => '6.1.0-8.9.99'
Expand Down
3 changes: 3 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
'Pxacookiebar',
[
'Cookiewarning' => 'warning, closeWarning'
],
[
'Cookiewarning' => 'closeWarning'
]
);

Expand Down

0 comments on commit 625dbbd

Please sign in to comment.