thelounge/client/js/vue.js

94 lines
2.2 KiB
JavaScript
Raw Normal View History

"use strict";
const Vue = require("vue").default;
const App = require("../components/App.vue").default;
const roundBadgeNumber = require("./libs/handlebars/roundBadgeNumber");
const localetime = require("./libs/handlebars/localetime");
2018-07-10 13:57:11 +02:00
const friendlysize = require("./libs/handlebars/friendlysize");
const colorClass = require("./libs/handlebars/colorClass");
Vue.filter("localetime", localetime);
2018-07-10 13:57:11 +02:00
Vue.filter("friendlysize", friendlysize);
Vue.filter("colorClass", colorClass);
Vue.filter("roundBadgeNumber", roundBadgeNumber);
const vueApp = new Vue({
el: "#viewport",
data: {
2018-09-09 15:09:19 +02:00
activeChannel: null,
appName: document.title,
currentUserVisibleError: null,
2018-07-15 22:23:49 +02:00
initialized: false,
isAutoCompleting: false,
2018-09-09 15:09:19 +02:00
isConnected: false,
isFileUploadEnabled: false,
isNotified: false,
networks: [],
2018-07-08 16:57:02 +02:00
settings: {
syncSettings: false,
advanced: false,
autocomplete: true,
nickPostfix: "",
coloredNicks: true,
desktopNotifications: false,
2019-01-16 10:23:12 +01:00
highlights: "",
2018-07-08 16:57:02 +02:00
links: true,
motd: true,
notification: true,
notifyAllMessages: false,
showSeconds: false,
statusMessages: "condensed",
theme: document.getElementById("theme").dataset.serverTheme,
media: true,
userStyles: "",
},
},
2018-07-10 11:40:55 +02:00
mounted() {
Vue.nextTick(() => window.vueMounted());
},
render(createElement) {
return createElement(App, {
props: this,
});
},
});
2018-09-14 17:44:26 +02:00
Vue.config.errorHandler = function(e) {
console.error(e); // eslint-disable-line
vueApp.currentUserVisibleError = `Vue error: ${e.message}. Please check devtools and report it in #thelounge`;
};
function findChannel(id) {
for (const network of vueApp.networks) {
for (const channel of network.channels) {
if (channel.id === id) {
return {network, channel};
}
}
}
return null;
}
function initChannel(channel) {
2018-09-09 14:23:12 +02:00
channel.pendingMessage = "";
channel.inputHistoryPosition = 0;
channel.inputHistory = [""];
channel.historyLoading = false;
channel.scrolledToBottom = true;
channel.editTopic = false;
channel.moreHistoryAvailable = channel.totalMessages > channel.messages.length;
delete channel.totalMessages;
if (channel.type === "channel") {
channel.usersOutdated = true;
}
}
module.exports = {
vueApp,
findChannel,
initChannel,
};