Skip to content

Commit

Permalink
Bug AOEpeople#4, add support for data-cookie-notice attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
nfreear committed May 30, 2018
1 parent 9c17763 commit 9422b8a
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/cookie.notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
'buttonTextColor': '#fff',
'noticeBgColor': '#000',
'noticeTextColor': '#fff',
'linkColor': '#009fdd'
'linkColor': '#009fdd',
'debug': false
};

/**
Expand Down Expand Up @@ -78,8 +79,22 @@
return;
}

// 'data-' attribute - data-cookie-notice='{ "key": "value", ... }'
var elemCfg = document.querySelector('script[ data-cookie-notice ]');
var config;
try {
config = elemCfg ? JSON.parse(elemCfg.getAttribute('data-cookie-notice')) : {};
} catch (ex) {
console.error('data-cookie-notice JSON error:', elemCfg, ex);
config = {};
}

// Extend default params
var params = extendDefaults(defaults, arguments[0] || {});
var params = extendDefaults(defaults, arguments[0] || config || {});

if (params.debug) {
console.warn('cookie-notice:', params);
}

// Get current locale for notice text
var noticeText = getStringForCurrentLocale(params.messageLocales);
Expand Down Expand Up @@ -313,4 +328,4 @@
};
/* end-test-code */

}());
}());

0 comments on commit 9422b8a

Please sign in to comment.