Commit 0792471d authored by  JosephK's avatar JosephK

Eval data conditions only once + function to list tags and banner id

parent 3009a3b8
......@@ -19,7 +19,7 @@
<script type="text/javascript" src="/sense3/sense3.js" data-sense3="728x90;;;wikipedia"></script>
<pre><code>&lt;script type="text/javascript" src="sense3.js" data-sense3="728x90"&gt;&lt;/script&gt;</code></pre>
</div>
<!--
<h3>Medium rectangle (350 x 200)</h3>
<div class="text-center">
<script type="text/javascript" src="sense3.js" data-sense3="300x250;;;vangogh"></script>
......
......@@ -2,10 +2,6 @@
(function sense3() {
let sense3Baseurl = '';
const avalaibleTags = [];
const avalaibleId = [];
const i18n = {
en: {
close: 'Close',
......@@ -26,12 +22,12 @@
referrer: 'Référent',
},
};
let d = {};
const s = {
/** Banners ***************************************************** */
data() {
return {
d = {
/**
<id>: {
condition: <boolean function>,
......@@ -234,7 +230,7 @@
en: ['Contribute to Wikipedia', 'The free encyclopedia that anyone can edit'],
fr: ['Contribuez à Wikipédia', 'L’encyclopédie libre que chacun peut améliorer'],
},
tags: ['wikipedia', 'encyclopedia'],
tags: ['generic', 'wikipedia', 'encyclopedia'],
},
};
},
......@@ -243,6 +239,7 @@
init() {
if (s.is.inframe()) {
document.addEventListener('DOMContentLoaded', () => {
s.data();
s.selectBanner();
});
} else {
......@@ -290,13 +287,9 @@
document.getElementsByTagName('html')[0].setAttribute('lang', lg);
if (id !== 'showInfos') {
const d = s.data();
// List contextual banners
const banner = []; let i = 0;
Object.keys(d).forEach((k) => {
avalaibleTags.push(d[k].tags);
avalaibleId.push(k);
if (d[k].condition &&
d[k].format.indexOf(`${w}x${h}`) !== -1
&& s.is.inTags(d[k].tags, tags.split(','))) {
......@@ -320,7 +313,6 @@
},
showBanner(id, lg, w, h) {
const d = s.data();
if (d[id] !== undefined) {
const type = d[id].format[0];
const llg = (d[id].link.xx !== undefined) ? 'xx' : lg;
......@@ -458,6 +450,31 @@
document.getElementsByTagName('head')[0].appendChild(style);
},
list(type) {
let list = []; const count = {};
switch (type) {
case 'tags':
Object.keys(d).forEach((k) => {
for (let i = 0; i < d[k].tags.length; i += 1) {
list.push(d[k].tags[i]);
}
});
list.forEach((x) => { count[x] = (count[x] || 0) + 1; });
list = [];
list.push(count);
break;
case 'id':
Object.keys(d).forEach((k) => {
list.push(k);
});
break;
default:
// no default
break;
}
return list;
},
/** Generic fonctions ******************************************* */
l(href) {
const link = document.createElement('a');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment