Use attr() instead of data()

This commit is contained in:
Pavel Djundik 2018-07-19 13:46:30 +03:00 committed by Pavel Djundik
parent ae56191b9f
commit 104692007f
7 changed files with 23 additions and 36 deletions

View File

@ -58,7 +58,7 @@ function addWhoisItem() {
} }
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: Number($("#chat").attr("data-id")),
text: "/whois " + itemData, text: "/whois " + itemData,
}); });
} }
@ -93,7 +93,7 @@ function addQueryItem() {
} }
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: Number($("#chat").attr("data-id")),
text: "/query " + itemData, text: "/query " + itemData,
}); });
} }
@ -139,7 +139,7 @@ function addConnectItem() {
check: (target) => target.hasClass("lobby") && target.parent().hasClass("not-connected"), check: (target) => target.hasClass("lobby") && target.parent().hasClass("not-connected"),
className: "connect", className: "connect",
displayName: "Connect", displayName: "Connect",
data: (target) => target.data("id"), data: (target) => target.attr("data-id"),
callback: connect, callback: connect,
}); });
} }
@ -156,7 +156,7 @@ function addDisconnectItem() {
check: (target) => target.hasClass("lobby") && !target.parent().hasClass("not-connected"), check: (target) => target.hasClass("lobby") && !target.parent().hasClass("not-connected"),
className: "disconnect", className: "disconnect",
displayName: "Disconnect", displayName: "Disconnect",
data: (target) => target.data("id"), data: (target) => target.attr("data-id"),
callback: disconnect, callback: disconnect,
}); });
} }
@ -164,13 +164,13 @@ function addDisconnectItem() {
function addKickItem() { function addKickItem() {
function kick(itemData) { function kick(itemData) {
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: Number($("#chat").attr("data-id")),
text: "/kick " + itemData, text: "/kick " + itemData,
}); });
} }
addContextMenuItem({ addContextMenuItem({
check: (target) => utils.hasRoleInChannel(target.closest(".chan"), ["op"]) && target.closest(".chan").data("type") === "channel", check: (target) => utils.hasRoleInChannel(target.closest(".chan"), ["op"]) && target.closest(".chan").attr("data-type") === "channel",
className: "action-kick", className: "action-kick",
displayName: "Kick", displayName: "Kick",
data: (target) => target.attr("data-name"), data: (target) => target.attr("data-name"),
@ -181,7 +181,7 @@ function addKickItem() {
function addOpItem() { function addOpItem() {
function op(itemData) { function op(itemData) {
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: Number($("#chat").attr("data-id")),
text: "/op " + itemData, text: "/op " + itemData,
}); });
} }
@ -200,7 +200,7 @@ function addOpItem() {
function addDeopItem() { function addDeopItem() {
function deop(itemData) { function deop(itemData) {
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: Number($("#chat").attr("data-id")),
text: "/deop " + itemData, text: "/deop " + itemData,
}); });
} }
@ -219,7 +219,7 @@ function addDeopItem() {
function addVoiceItem() { function addVoiceItem() {
function voice(itemData) { function voice(itemData) {
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: Number($("#chat").attr("data-id")),
text: "/voice " + itemData, text: "/voice " + itemData,
}); });
} }
@ -238,7 +238,7 @@ function addVoiceItem() {
function addDevoiceItem() { function addDevoiceItem() {
function devoice(itemData) { function devoice(itemData) {
socket.emit("input", { socket.emit("input", {
target: $("#chat").data("id"), target: Number($("#chat").attr("data-id")),
text: "/devoice " + itemData, text: "/devoice " + itemData,
}); });
} }
@ -292,7 +292,7 @@ function addEditNetworkItem() {
check: (target) => target.hasClass("lobby"), check: (target) => target.hasClass("lobby"),
className: "edit", className: "edit",
displayName: "Edit this network…", displayName: "Edit this network…",
data: (target) => target.closest(".network").data("uuid"), data: (target) => target.closest(".network").attr("data-uuid"),
callback: edit, callback: edit,
}); });
} }
@ -309,7 +309,7 @@ function addChannelListItem() {
check: (target) => target.hasClass("lobby"), check: (target) => target.hasClass("lobby"),
className: "list", className: "list",
displayName: "List all channels", displayName: "List all channels",
data: (target) => target.data("id"), data: (target) => target.attr("data-id"),
callback: list, callback: list,
}); });
} }
@ -326,7 +326,7 @@ function addBanListItem() {
check: (target) => target.hasClass("channel"), check: (target) => target.hasClass("channel"),
className: "list", className: "list",
displayName: "List banned users", displayName: "List banned users",
data: (target) => target.data("id"), data: (target) => target.attr("data-id"),
callback: banlist, callback: banlist,
}); });
} }
@ -340,7 +340,7 @@ function addJoinItem() {
check: (target) => target.hasClass("lobby"), check: (target) => target.hasClass("lobby"),
className: "join", className: "join",
displayName: "Join a channel…", displayName: "Join a channel…",
data: (target) => target.data("id"), data: (target) => target.attr("data-id"),
callback: openJoinForm, callback: openJoinForm,
}); });
} }
@ -357,7 +357,7 @@ function addIgnoreListItem() {
check: (target) => target.hasClass("lobby"), check: (target) => target.hasClass("lobby"),
className: "list", className: "list",
displayName: "List ignored users", displayName: "List ignored users",
data: (target) => target.data("id"), data: (target) => target.attr("data-id"),
callback: ignorelist, callback: ignorelist,
}); });
} }

View File

@ -163,15 +163,13 @@ window.vueMounted = () => {
utils.updateTitle(); utils.updateTitle();
const type = chan.data("type");
if (self.hasClass("chan")) { if (self.hasClass("chan")) {
vueApp.$nextTick(() => $("#chat-container").addClass("active")); vueApp.$nextTick(() => $("#chat-container").addClass("active"));
} }
const chanChat = chan.find(".chat"); const chanChat = chan.find(".chat");
if (chanChat.length > 0 && type !== "special") { if (chanChat.length > 0 && channel.type !== "special") {
// On touch devices unfocus (blur) the input to correctly close the virtual keyboard // On touch devices unfocus (blur) the input to correctly close the virtual keyboard
// An explicit blur is required, as the keyboard may open back up if the focus remains // An explicit blur is required, as the keyboard may open back up if the focus remains
// See https://github.com/thelounge/thelounge/issues/2257 // See https://github.com/thelounge/thelounge/issues/2257
@ -200,7 +198,7 @@ window.vueMounted = () => {
if (self.prop("id")) { if (self.prop("id")) {
state.clickTarget = `#${self.prop("id")}`; state.clickTarget = `#${self.prop("id")}`;
} else if (self.hasClass("chan")) { } else if (self.hasClass("chan")) {
state.clickTarget = `#sidebar .chan[data-id="${self.data("id")}"]`; state.clickTarget = `#sidebar .chan[data-id="${self.attr("data-id")}"]`;
} else { } else {
state.clickTarget = `#footer button[data-target="${target}"]`; state.clickTarget = `#footer button[data-target="${target}"]`;
} }

View File

@ -9,7 +9,6 @@ const {vueApp} = require("./vue");
require("../js/autocompletion"); require("../js/autocompletion");
const $windows = $("#windows"); const $windows = $("#windows");
const $chat = $("#chat");
const $settings = $("#settings"); const $settings = $("#settings");
const $theme = $("#theme"); const $theme = $("#theme");
const $userStyles = $("#user-specified-css"); const $userStyles = $("#user-specified-css");
@ -125,10 +124,6 @@ function applySetting(name, value) {
} else { } else {
module.exports.highlightsRE = null; module.exports.highlightsRE = null;
} }
} else if (name === "showSeconds") {
$chat.find(".msg > .time").each(function() {
$(this).text(tz($(this).parent().data("time")));
});
} else if (name === "desktopNotifications") { } else if (name === "desktopNotifications") {
if (("Notification" in window) && value && Notification.permission !== "granted") { if (("Notification" in window) && value && Notification.permission !== "granted") {
Notification.requestPermission(updateDesktopNotificationStatus); Notification.requestPermission(updateDesktopNotificationStatus);

View File

@ -126,7 +126,7 @@ function closeImageViewer({pushState = true} = {}) {
if (pushState) { if (pushState) {
const clickTarget = const clickTarget =
"#sidebar " + "#sidebar " +
`.chan[data-id="${$("#sidebar .chan.active").data("id")}"]`; `.chan[data-id="${$("#sidebar .chan.active").attr("data-id")}"]`;
history.pushState({clickTarget}, null, null); history.pushState({clickTarget}, null, null);
} }
} }

View File

@ -2,7 +2,6 @@
const $ = require("jquery"); const $ = require("jquery");
const socket = require("../socket"); const socket = require("../socket");
const sidebar = $("#sidebar");
const {vueApp, initChannel} = require("../vue"); const {vueApp, initChannel} = require("../vue");
socket.on("join", function(data) { socket.on("join", function(data) {
@ -17,11 +16,6 @@ socket.on("join", function(data) {
} }
vueApp.$nextTick(() => { vueApp.$nextTick(() => {
sidebar.find(".chan") $(`#sidebar .chan[data-id="${data.chan.id}"]`).trigger("click");
.sort(function(a, b) {
return $(a).data("id") - $(b).data("id");
})
.last()
.trigger("click");
}); });
}); });

View File

@ -13,7 +13,7 @@ socket.on("sync_sort", function(data) {
$.each(order, function(index, value) { $.each(order, function(index, value) {
const position = $(container.children(".network")[index]); const position = $(container.children(".network")[index]);
if (position.data("id") === value) { // Network in correct place if (Number(position.attr("data-id")) === value) { // Network in correct place
return true; // No point in continuing return true; // No point in continuing
} }
@ -27,7 +27,7 @@ socket.on("sync_sort", function(data) {
const position = $(network.children(".chan")[index]); // Target channel at position const position = $(network.children(".chan")[index]); // Target channel at position
if (position.data("id") === value) { // Channel in correct place if (Number(position.attr("data-id")) === value) { // Channel in correct place
return true; // No point in continuing return true; // No point in continuing
} }

View File

@ -36,7 +36,7 @@ function hasRoleInChannel(channel, roles, nick) {
return false; return false;
} }
const channelID = channel.data("id"); const channelID = channel.attr("data-id");
const network = $("#sidebar .network").has(`.chan[data-id="${channelID}"]`); const network = $("#sidebar .network").has(`.chan[data-id="${channelID}"]`);
const target = nick || network.attr("data-nick"); const target = nick || network.attr("data-nick");
const user = channel.find(`.names-original .user[data-name="${escape(target)}"]`).first(); const user = channel.find(`.names-original .user[data-name="${escape(target)}"]`).first();
@ -142,7 +142,7 @@ function closeChan(chan) {
} }
socket.emit("input", { socket.emit("input", {
target: chan.data("id"), target: Number(chan.attr("data-id")),
text: cmd, text: cmd,
}); });
chan.css({ chan.css({