nopaque/app/static/js/nopaque.js

118 lines
3.5 KiB
JavaScript
Raw Normal View History

var nopaque = {};
2020-01-17 09:42:02 +00:00
// nopaque ressources
nopaque["socket"] = io();
2020-01-17 09:42:02 +00:00
nopaque["corpora"] = undefined;
nopaque["corporaSubscribers"] = [];
nopaque["jobs"] = undefined;
nopaque["jobsSubscribers"] = [];
2020-01-17 09:42:02 +00:00
nopaque["foreignCorpora"] = undefined;
nopaque["foreignCorporaSubscribers"] = [];
nopaque["foreignJobs"] = undefined;
nopaque["foreignJobsSubscribers"] = [];
// nopaque functions
nopaque["navigation"] = {};
nopaque["navigation"]["init"] = function() {
for (let entry of document.querySelectorAll("#slide-out a:not(.subheader)")) {
if (entry.href === window.location.href) {
entry.parentNode.classList.add("active");
}
}
}
nopaque["toast"] = function(message, color="") {
2020-01-17 09:42:02 +00:00
var toast;
var toastActionElement;
2020-01-17 14:10:01 +00:00
toast = M.toast({"classes": color,
"html": `<span>${message}</span>
<button class="btn-flat toast-action white-text" data-action="close">
2020-01-17 09:42:02 +00:00
<i class="material-icons">close</i>
</button>`});
toastActionElement = toast.el.querySelector(`.toast-action[data-action="close"]`);
if (toastActionElement) {
toastActionElement.addEventListener("click", function() {
toast.dismiss();
});
}
}
// socket event handlers
nopaque.socket.on('init-corpora', function(msg) {
nopaque.corpora = JSON.parse(msg);
for (let subscriber of nopaque.corporaSubscribers) {subscriber._init(nopaque.corpora);}
2020-01-17 09:42:02 +00:00
});
nopaque.socket.on('init-jobs', function(msg) {
nopaque.jobs = JSON.parse(msg);
for (let subscriber of nopaque.jobsSubscribers) {subscriber._init(nopaque.jobs);}
2020-01-17 09:42:02 +00:00
});
nopaque.socket.on('update-corpora', function(msg) {
2020-01-17 09:42:02 +00:00
var patch;
patch = JSON.parse(msg);
nopaque.corpora = jsonpatch.apply_patch(nopaque.corpora, patch);
for (let subscriber of nopaque.corporaSubscribers) {subscriber._update(patch);}
2020-01-17 09:42:02 +00:00
});
nopaque.socket.on('update-jobs', function(msg) {
2020-01-17 09:42:02 +00:00
var patch;
patch = JSON.parse(msg);
nopaque.jobs = jsonpatch.apply_patch(nopaque.jobs, patch);
for (let subscriber of nopaque.jobsSubscribers) {subscriber._update(patch);}
2020-01-17 09:42:02 +00:00
});
nopaque.socket.on('init-foreign-corpora', function(msg) {
nopaque.foreignCorpora = JSON.parse(msg);
for (let subscriber of nopaque.foreignCorporaSubscribers) {subscriber._init(nopaque.foreignCorpora);}
2020-01-17 09:42:02 +00:00
});
nopaque.socket.on('init-foreign-jobs', function(msg) {
nopaque.foreignJobs = JSON.parse(msg);
for (let subscriber of nopaque.foreignJobsSubscribers) {subscriber._init(nopaque.foreignJobs);}
2020-01-17 09:42:02 +00:00
});
nopaque.socket.on('update-foreign-corpora', function(msg) {
2020-01-17 09:42:02 +00:00
var patch;
patch = JSON.parse(msg);
nopaque.foreignCorpora = jsonpatch.apply_patch(nopaque.foreignCorpora, patch);
for (let subscriber of nopaque.foreignCorporaSubscribers) {subscriber._update(patch);}
2020-01-17 09:42:02 +00:00
});
nopaque.socket.on('update-foreign-jobs', function(msg) {
2020-01-17 09:42:02 +00:00
var patch;
patch = JSON.parse(msg);
nopaque.foreignJobs = jsonpatch.apply_patch(nopaque.foreignJobs, patch);
for (let subscriber of nopaque.foreignJobsSubscribers) {subscriber._update(patch);}
2020-01-17 09:42:02 +00:00
});
2020-01-17 09:49:04 +00:00
document.addEventListener("DOMContentLoaded", function() {
2020-01-17 09:42:02 +00:00
M.AutoInit();
M.CharacterCounter.init(document.querySelectorAll(`input[data-length][type="text"]`));
M.Dropdown.init(document.getElementById("nav-notifications"),
{"alignment": "right", "constrainWidth": false, "coverTrigger": false});
M.Dropdown.init(document.getElementById("nav-account"),
{"alignment": "right", "constrainWidth": false, "coverTrigger": false});
nopaque.navigation.init();
nopaque.socket.emit("subscribe_user_ressources");
2020-01-17 09:42:02 +00:00
});