hardlounge/client/js/vue.js

136 lines
3.2 KiB
JavaScript
Raw Normal View History

"use strict";
const Vue = require("vue").default;
const store = require("./store").default;
const App = require("../components/App.vue").default;
const roundBadgeNumber = require("./libs/handlebars/roundBadgeNumber");
const localetime = require("./libs/handlebars/localetime");
2018-07-10 07:57:11 -04:00
const friendlysize = require("./libs/handlebars/friendlysize");
const colorClass = require("./libs/handlebars/colorClass");
const storage = require("./localStorage");
Vue.filter("localetime", localetime);
2018-07-10 07:57:11 -04:00
Vue.filter("friendlysize", friendlysize);
Vue.filter("colorClass", colorClass);
Vue.filter("roundBadgeNumber", roundBadgeNumber);
const vueApp = new Vue({
el: "#viewport",
data: {
2018-09-09 09:09:19 -04:00
activeChannel: null,
appName: document.title,
currentUserVisibleError: null,
2018-07-15 16:23:49 -04:00
initialized: false,
isAutoCompleting: false,
2018-09-09 09:09:19 -04:00
isFileUploadEnabled: false,
networks: [],
2019-02-20 04:10:18 -05:00
pushNotificationState: "unsupported",
desktopNotificationState: "unsupported",
serverConfiguration: {},
2018-07-08 10:57:02 -04:00
settings: {
syncSettings: false,
advanced: false,
autocomplete: true,
nickPostfix: "",
coloredNicks: true,
desktopNotifications: false,
2019-01-16 04:23:12 -05:00
highlights: "",
2018-07-08 10:57:02 -04: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 05:40:55 -04:00
mounted() {
Vue.nextTick(() => window.vueMounted());
2019-10-17 11:32:59 -04:00
if (navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)) {
document.body.classList.add("is-apple");
}
2018-07-10 05:40:55 -04:00
},
methods: {
onSocketInit() {
this.initialized = true;
this.$store.commit("isConnected", true);
},
setSidebar(state) {
const utils = require("./utils");
this.$store.commit("sidebarOpen", state);
if (window.outerWidth > utils.mobileViewportPixels) {
storage.set("thelounge.state.sidebar", state);
}
this.$emit("resize");
},
toggleSidebar() {
this.setSidebar(!this.$store.state.sidebarOpen);
},
setUserlist(state) {
storage.set("thelounge.state.userlist", state);
this.$store.commit("userlistOpen", state);
this.$emit("resize");
},
toggleUserlist() {
this.setUserlist(!this.$store.state.userlistOpen);
},
},
render(createElement) {
return createElement(App, {
2019-02-18 04:18:32 -05:00
ref: "app",
props: this,
});
},
store,
});
2018-09-14 11:44:26 -04: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 08:23:12 -04: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;
}
}
2019-02-18 04:18:32 -05:00
function getActiveWindowComponent() {
return vueApp.$refs.app.$refs.window;
}
module.exports = {
vueApp,
findChannel,
initChannel,
2019-02-18 04:18:32 -05:00
getActiveWindowComponent,
};