Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • applications/etuc/hubl
  • applications/hubl
  • decentral1se/hubl
  • rngadam/hubl
  • jvtrudel/hubl
  • 3wc/hubl
6 results
Show changes
Commits on Source (6)
This diff is collapsed.
......@@ -15,6 +15,9 @@
"cypress:info": "cypress info",
"test": "cypress run"
},
"browserslist": [
"last 2 Chrome versions"
],
"release": {
"branches": [
"master"
......@@ -44,12 +47,22 @@
"@semantic-release/gitlab"
]
},
"cache": {
"strategy": "inject",
"swSrc": "./src/service-worker.js",
"swDest": "service-worker.js",
"globPatterns": [
"**/*.{html,js,map,css,jpg,png,gif,webp,svg,eot,ttf,woff,woff2,json}"
],
"clearDist": false
},
"dependencies": {
"@startinblox/hubl-styling-framework": "^1.8.15",
"cross-env": "^7.0.3",
"fs-extra": "^9.0.1",
"normalize.css": "^8.0.1",
"parcel-bundler": "^1.12.4",
"parcel-bundler": "^1.12.5",
"parcel-plugin-sw-cache": "^0.3.1",
"pug": "^3.0.0",
"rimraf": "^2.7.1",
"sass": "^1.29.0"
......
import {
Workbox,
messageSW
} from 'https://storage.googleapis.com/workbox-cdn/releases/6.1.1/workbox-window.prod.mjs';
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
const wb = new Workbox('/service-worker.js');
let registration;
const showSkipWaitingPrompt = (event) => {
if(hubl.intl.t('serviceWorker.newUpdate') != undefined) {
Swal.fire({
position: 'bottom-end',
backdrop: false,
title: "",
text: hubl.intl.t('serviceWorker.newUpdate') + ". " + hubl.intl.t('serviceWorker.wantToUpdate'),
imageUrl: hubl.client.logo || 'https://cdn.startinblox.com/logos/webp/hubl.webp',
imageAlt: hubl.client.name,
showCancelButton: true,
confirmButtonClass: 'button text-xsmall text-bold text-center reversed color-secondary bordered icon icon-check no-background-image',
cancelButtonClass: 'button text-xsmall text-bold text-center reversed color-primary bordered icon icon-exclamation no-background-image',
confirmButtonText: hubl.intl.t('serviceWorker.yes'),
cancelButtonText: hubl.intl.t('serviceWorker.no')
}).then((result) => {
if (result.isConfirmed) {
wb.addEventListener('controlling', (event) => {
window.location.reload();
});
if (registration && registration.waiting) {
messageSW(registration.waiting, {
type: 'SKIP_WAITING'
});
}
}
});
}
};
wb.addEventListener('waiting', showSkipWaitingPrompt);
wb.addEventListener('externalwaiting', showSkipWaitingPrompt);
wb.register().then((r) => registration = r);
});
}
\ No newline at end of file
......@@ -60,5 +60,5 @@ for component of components
defaultRoute = defaultComponent[0].uniq;
}
- const hublComponents = `window.hubl={};window.hubl.components = ${JSON.stringify(components)};window.hubl.defaultRoute = "${defaultRoute}";`;
- const hublComponents = `window.hubl={};window.hubl.components = ${JSON.stringify(components)};window.hubl.defaultRoute = "${defaultRoute}";window.hubl.client = ${JSON.stringify(client)}`;
script!=hublComponents
\ No newline at end of file
......@@ -32,6 +32,7 @@ html(lang="en")
script(type="module" src="/components/hubl-auto-login.js" defer)
script(type="module" src="/components/hubl-search-users.js" defer)
script(type="module" src="/components/hubl-reactivity.js" defer)
script(type="module" src="/components/sw-toolbox.js" defer)
script(src="index.js" defer)
include dependencies.pug
......
......@@ -32,13 +32,7 @@
"circlesBrowse": "Browse circles",
"circleCreate": "Create circle",
"messages": "Messages",
"search": "Search",
"republiqueESS": {
"home": "Home",
"contribute": "Contribute",
"thematics": "Thematics",
"community": "Community"
}
"search": "Search"
},
"about": {
"title": "About",
......@@ -131,10 +125,7 @@
"subTitle": "Members :"
},
"extensions": {
"associated": "Associated circle",
"republiqueESS": {
"associatedThematic": "Associated thematic"
}
"associated": "Associated circle"
}
},
"communities": {
......@@ -309,5 +300,11 @@
"edit": "Edit",
"back": "Back",
"goButton": "GO"
},
"serviceWorker": {
"newUpdate": "A new version is available",
"wantToUpdate": "Do you want to update?",
"yes": "Yes",
"no": "No"
}
}
......@@ -32,13 +32,7 @@
"circlesBrowse": "Examinar los círculos",
"circleCreate": "Crea un círculo.",
"messages": "Mensajes",
"search": "Buscar",
"republiqueESS": {
"home": "Hogar",
"contribute": "Contribuir",
"thematics": "Temáticas",
"community": "Comunidad"
}
"search": "Buscar"
},
"about": {
"title": "Acerca de",
......@@ -131,10 +125,7 @@
"subTitle": "Miembrxs: "
},
"extensions": {
"associated": "Círculo asociado",
"republiqueESS": {
"associatedThematic": "Temática asociada"
}
"associated": "Círculo asociado"
}
},
"communities": {
......@@ -309,5 +300,11 @@
"edit": "Modificar",
"back": "Atrás",
"goButton": "GO"
},
"serviceWorker": {
"newUpdate": "Una nueva version esta disponible",
"wantToUpdate": "¿Quieres actualizar?",
"yes": "Sí",
"no": "No"
}
}
......@@ -9,9 +9,7 @@
},
"menuLeft": {
"emptyCircleProjectContact": {
"empty": "Il n'y a aucun résultat dans cette section.",
"project": "projet",
"circle": "cercle"
"empty": "Il n'y a aucun résultat dans cette section."
},
"contact": {
"create": "Retrouve tes contacts sur",
......@@ -32,13 +30,7 @@
"circlesBrowse": "Parcourir les cercles",
"circleCreate": "Créer un cercle",
"messages": "Messages",
"search": "Rechercher",
"republiqueESS": {
"home": "Accueil",
"contribute": "Contribuer",
"thematics": "Thématiques",
"community": "Communauté"
}
"search": "Rechercher"
},
"about": {
"title": "A propos",
......@@ -131,10 +123,7 @@
"subTitle": "Membres :"
},
"extensions": {
"associated": "Cercle associé",
"republiqueESS": {
"associatedThematic": "Thématique associée"
}
"associated": "Cercle associé"
}
},
"communities": {
......@@ -309,5 +298,11 @@
"edit": "Editer",
"back": "Retour",
"goButton": "GO"
},
"serviceWorker": {
"newUpdate": "Une nouvelle version est disponible",
"wantToUpdate": "Voulez-vous mettre à jour ?",
"yes": "Oui",
"no": "Non"
}
}
......@@ -6,27 +6,27 @@ class JsI18n {
constructor() {
this.locale = ""; //Current locale
this.locales = new Array(); //Available locales
this.overwrites = new Array();
this.defaultLocale = "fr";
}
/*
Method for automatically detecting the language, does not work in every browser.
*/
detectLanguage() {
async detectLanguage() {
const customLangs = document.querySelectorAll('hubl-lang');
if(customLangs) {
for(let lang of customLangs) {
let name = lang.getAttribute('lang'),
file = lang.getAttribute('file');
if(window.hubl.intl.locales[name.toString()] == undefined) {
return fetch(file).then((result) => {
if (result.ok) {
result.json().then(e => {
window.hubl.intl.addLocale(name, e);
});
}
window.hubl.intl.resumeDetection();
});
if (customLangs) {
for (let lang of customLangs) {
let name = lang.getAttribute('lang'),
file = lang.getAttribute('file');
let result = await fetch(file);
if (result.ok) {
let json = await result.json();
if(this.overwrites[name.toString()] != undefined) {
this.mergeDeep(this.overwrites[name.toString()], json);
} else {
this.overwrites[name.toString()] = json;
}
}
}
}
......@@ -35,10 +35,10 @@ class JsI18n {
resumeDetection() {
const langComponent = document.querySelector('hubl-fallback-lang');
if(langComponent) {
if(langComponent.hasAttribute('lang')) {
if (langComponent) {
if (langComponent.hasAttribute('lang')) {
this.defaultLocale = langComponent.getAttribute('lang');
if(langComponent.hasAttribute('force')) {
if (langComponent.hasAttribute('force')) {
localStorage.setItem('language', this.defaultLocale);
}
}
......@@ -52,6 +52,30 @@ class JsI18n {
}
};
isObject(item) {
return (item && typeof item === 'object' && !Array.isArray(item));
}
mergeDeep(target, ...sources) {
if (!sources.length) return target;
const source = sources.shift();
if (this.isObject(target) && this.isObject(source)) {
for (const key in source) {
if (this.isObject(source[key])) {
if (!target[key]) Object.assign(target, {
[key]: {}
});
this.mergeDeep(target[key], source[key]);
} else {
Object.assign(target, {
[key]: source[key]
});
}
}
}
return this.mergeDeep(target, ...sources);
}
/*
Translates tag contents and
attributes depending on the
......@@ -84,7 +108,7 @@ class JsI18n {
if (placeholder != null) {
this.translateNodeContent(placeholder.attributes['placeholder'], k);
let input = node.querySelector('[name="' + attr.replace("placeholder-", "") + '"] > input');
if(input != null) {
if (input != null) {
this.translateNodeContent(input.attributes['placeholder'], k);
}
}
......@@ -145,21 +169,20 @@ class JsI18n {
if the locale is already defined.
*/
addLocale(locale, translations) {
if (this.overwrites[locale.toString()] != undefined) {
this.mergeDeep(translations, this.overwrites[locale.toString()]);
}
this.locales[locale.toString()] = translations;
}
fetchLocale(locale) {
if(this.locales[locale.toString()] == undefined) {
return fetch(`/locales/${locale}.json`).then((result) => {
if (result.ok) {
result.json().then(e => {
this.addLocale(locale, e);
});
}
});
} else {
return (new Promise()).resolve();
}
return fetch(`/locales/${locale}.json`).then((result) => {
if (result.ok) {
result.json().then(e => {
this.addLocale(locale, e);
});
}
});
}
/*
......@@ -168,7 +191,7 @@ class JsI18n {
setLocale(locale) {
try {
this.fetchLocale(locale).then(() => {
if(this.locale) {
if (this.locale) {
localStorage.setItem('language', this.locale);
}
this.processPage();
......@@ -190,11 +213,11 @@ class JsI18n {
t(key) {
var translations = this.locales[this.locale];
if (translations == undefined) {
if(this.locales.length > 1) {
if (this.locales.length > 1) {
translations = this.locales[this.defaultLocale];
}
}
if(translations != undefined) {
if (translations != undefined) {
let translation = key.toString().split('.').reduce((o, i) => (o ? o[i] : undefined), translations);
if (typeof translation == "string") {
return translation;
......
if ('serviceWorker' in navigator) {
var refreshing;
navigator.serviceWorker.addEventListener('controllerchange', () => {
if (refreshing) {
return;
}
refreshing = true;
window.location.reload();
});
navigator.serviceWorker.register('/sw.js');
}
\ No newline at end of file
importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.1.1/workbox-sw.js');
workbox.precaching.precacheAndRoute([]);
addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
skipWaiting();
}
});
workbox.routing.registerRoute(
({url}) => url.origin === 'https://fonts.gstatic.com',
new workbox.strategies.CacheFirst({
cacheName: 'google-fonts-webfonts',
plugins: [
new workbox.cacheableResponse.CacheableResponsePlugin({
statuses: [0, 200],
}),
new workbox.expiration.ExpirationPlugin({
maxAgeSeconds: 60 * 60 * 24 * 365,
maxEntries: 30,
}),
],
})
);
workbox.routing.registerRoute(
({url}) => [
'https://cdn.jsdelivr.net',
'https://unpkg.com',
'https://cdn.skypack.dev',
'https://jspm.dev',
'https://fonts.googleapis.com',
'https://cdn.startinblox.com'
].includes(url.origin),
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'cdn',
})
);
workbox.routing.registerRoute(
({ request }) => request.destination === 'image',
new workbox.strategies.CacheFirst({
cacheName: 'images',
plugins: [
new workbox.cacheableResponse.CacheableResponsePlugin({
statuses: [200],
}),
new workbox.expiration.ExpirationPlugin({
maxEntries: 300,
maxAgeSeconds: 60 * 60 * 24 * 30,
}),
],
}),
);
workbox.routing.registerRoute(
({ request }) =>
request.destination === 'style' ||
request.destination === 'script',
new workbox.strategies.StaleWhileRevalidate({
cacheName: 'assets',
plugins: [
new workbox.cacheableResponse.CacheableResponsePlugin({
statuses: [200],
}),
],
}),
);
workbox.routing.registerRoute(
({ request }) => request.mode === 'navigate',
new workbox.strategies.NetworkFirst({
cacheName: 'pages',
plugins: [
new workbox.cacheableResponse.CacheableResponsePlugin({
statuses: [200],
}),
],
}),
);
......@@ -2,6 +2,10 @@ main {
height: 100vh;
}
.no-background-image {
background-image: none !important;
}
/* Styles of the right-hand menu + pages with that menu */
.with-sidebar {
flex-grow: 1;
......
......@@ -131,10 +131,10 @@ nav#main__menu {
.menu-admin {
position: absolute;
z-index: 3016;
left: 78px;
left: 15%;
top: 36px;
text-align: end;
width: 64%;
width: 80%;
@media (max-width: 768px) {
width: 100%;
......@@ -242,6 +242,7 @@ nav#main__menu {
solid-set-default[name="message"] {
margin-right: 9px;
width: 74%;
}
hubl-menu-contact-removed {
......
const CACHE_NAME = 'hubl-store-epm9475';
self.addEventListener('install', function (e) {
self.skipWaiting();
e.waitUntil(
caches.open(CACHE_NAME).then(function (cache) {
return cache.addAll([
'/locales/es.json',
'/locales/fr.json',
'/scripts/index.js',
'/syles/index.css',
'/index.html',
'/'
]);
})
);
});
self.addEventListener('activate', function (e) {
// invalidate older versions
e.waitUntil(
caches.keys()
.then(function (keyList) {
return Promise.all(keyList.map(function (key) {
if (key !== CACHE_NAME && key !== (CACHE_NAME + "-cdn") && key !== (CACHE_NAME + "-api")) {
return caches.delete(key);
}
}));
}));
self.clients.claim();
});
if(process.env.NODE_ENV === 'production'){
self.addEventListener('fetch', function (event) {
let requestURL = new URL(event.request.url);
if (requestURL.origin == location.origin) {
// Static asset, cache then network
event.respondWith(
caches.open(CACHE_NAME).then(function (cache) {
return cache.match(event.request).then(function (response) {
var fetchPromise = fetch(event.request).then(function (networkResponse) {
cache.put(event.request, networkResponse.clone());
return networkResponse;
});
return response || fetchPromise;
});
}),
);
} else {
if (
event.request.method == 'POST' ||
event.request.method == 'PUT'
) {
// disabled: lead to cors errors
// // POST/PUT to api, rewrite the cache
// event.respondWith(
// caches.open(CACHE_NAME + '-api').then(function (cache) {
// return fetch(event.request).then(function (response) {
// cache.put(event.request, response.clone());
// return response;
// })
// }));
// api: no cache
event.respondWith(fetch(event.request));
} else if (
/matomo/.test(requestURL.origin) ||
/sentry/.test(requestURL.origin) ||
/jabber/.test(requestURL.origin) ||
/xmpp/.test(requestURL.origin)
) {
// analytics, always distant
event.respondWith(fetch(event.request));
} else {
if (
/unpkg/.test(requestURL.origin) ||
/skypack/.test(requestURL.origin) ||
/jspm/.test(requestURL.origin) ||
/jsdeliver/.test(requestURL.origin) ||
/cdn/.test(requestURL.origin) ||
/googleapis/.test(requestURL.origin)
) {
// cdn: cache then network
event.respondWith(
caches.open(CACHE_NAME + '-cdn').then(function (cache) {
return cache.match(event.request).then(function (response) {
var fetchPromise = fetch(event.request).then(function (networkResponse) {
cache.put(event.request, networkResponse.clone());
return networkResponse;
});
return response || fetchPromise;
});
}),
);
} else {
// disabled: lead to cors errors
// // api: distant then cache
// event.respondWith(
// fetch(event.request)
// .then((response) => {
// caches.open(CACHE_NAME + '-api').then(function (cache) {
// cache.put(event.request, response.clone());
// return response;
// });
// })
// .catch(() => {
// return caches.match(event.request);
// })
// );
// api: no cache
event.respondWith(fetch(event.request));
}
}
}
});
}
\ No newline at end of file