Remove deprecated jQuery calls

Fixes #2011
This commit is contained in:
Pavel Djundik 2018-01-30 11:38:33 +02:00
parent 1904e9b0ab
commit 6d6b5cb2a9
18 changed files with 69 additions and 66 deletions

View file

@ -14,8 +14,8 @@ let textcomplete;
module.exports = { module.exports = {
enable: enableAutocomplete, enable: enableAutocomplete,
disable: () => { disable: () => {
input.unbind("input.tabcomplete"); input.off("input.tabcomplete");
Mousetrap(input.get(0)).unbind("tab", "keydown"); Mousetrap(input.get(0)).off("tab", "keydown");
if (textcomplete) { if (textcomplete) {
textcomplete.destroy(); textcomplete.destroy();

View file

@ -20,8 +20,8 @@ function toggleButton(network) {
// Toggle content of tooltip // Toggle content of tooltip
const tooltip = network.find(".add-channel-tooltip"); const tooltip = network.find(".add-channel-tooltip");
const altLabel = tooltip.data("alt-label"); const altLabel = tooltip.data("alt-label");
tooltip.data("alt-label", tooltip.attr("aria-label")); tooltip.data("alt-label", tooltip.prop("aria-label"));
tooltip.attr("aria-label", altLabel); tooltip.prop("aria-label", altLabel);
} }
function closeForm(network) { function closeForm(network) {
@ -44,7 +44,7 @@ function openForm(network) {
} }
// Focus the "Channel" field even if the form was already open // Focus the "Channel" field even if the form was already open
form.find(".input[name='channel']").focus(); form.find(".input[name='channel']").trigger("focus");
} }
sidebar.on("click", ".add-channel", function(e) { sidebar.on("click", ".add-channel", function(e) {
@ -69,7 +69,7 @@ sidebar.on("submit", ".join-form", function() {
const keyString = key.val(); const keyString = key.val();
const chan = utils.findCurrentNetworkChan(channelString); const chan = utils.findCurrentNetworkChan(channelString);
if (chan.length) { if (chan.length) {
chan.click(); chan.trigger("click");
} else { } else {
socket.emit("input", { socket.emit("input", {
text: `/join ${channelString} ${keyString}`, text: `/join ${channelString} ${keyString}`,

View file

@ -14,7 +14,7 @@ Mousetrap.bind([
let container = windows.find(".window.active"); let container = windows.find(".window.active");
// Chat windows scroll message container // Chat windows scroll message container
if (container.attr("id") === "chat-container") { if (container.prop("id") === "chat-container") {
container = container.find(".chan.active .chat"); container = container.find(".chan.active .chat");
} }

View file

@ -2,7 +2,7 @@ import jQuery from "jquery";
(function($) { (function($) {
$.fn.unsticky = function() { $.fn.unsticky = function() {
return this.trigger("unstick.sticky").unbind(".sticky"); return this.trigger("unstick.sticky").off(".sticky");
}; };
$.fn.sticky = function() { $.fn.sticky = function() {

View file

@ -44,7 +44,7 @@ $(function() {
viewport.on("click", ".rt", function(e) { viewport.on("click", ".rt", function(e) {
var self = $(this); var self = $(this);
viewport.toggleClass(self.attr("class")); viewport.toggleClass(self.prop("class"));
e.stopPropagation(); e.stopPropagation();
chat.find(".chan.active .chat").trigger("msg.sticky"); chat.find(".chan.active .chat").trigger("msg.sticky");
}); });
@ -216,7 +216,7 @@ $(function() {
if (!("ontouchstart" in window || navigator.maxTouchPoints > 0)) { if (!("ontouchstart" in window || navigator.maxTouchPoints > 0)) {
focus = function() { focus = function() {
if (chat.find(".active").hasClass("chan")) { if (chat.find(".active").hasClass("chan")) {
input.focus(); input.trigger("focus");
} }
}; };
@ -297,14 +297,14 @@ $(function() {
utils.setNick(sidebar.find(".chan.active").closest(".network").data("nick")); utils.setNick(sidebar.find(".chan.active").closest(".network").data("nick"));
} }
$("#nick-value").keypress(function(e) { $("#nick-value").on("keypress", function(e) {
switch (e.keyCode ? e.keyCode : e.which) { switch (e.keyCode ? e.keyCode : e.which) {
case 13: // Enter case 13: // Enter
// Ensures a new line is not added when pressing Enter // Ensures a new line is not added when pressing Enter
e.preventDefault(); e.preventDefault();
break; break;
} }
}).keyup(function(e) { }).on("keyup", function(e) {
switch (e.keyCode ? e.keyCode : e.which) { switch (e.keyCode ? e.keyCode : e.which) {
case 13: // Enter case 13: // Enter
submitNick(); submitNick();
@ -320,7 +320,7 @@ $(function() {
var chan = utils.findCurrentNetworkChan(name); var chan = utils.findCurrentNetworkChan(name);
if (chan.length) { if (chan.length) {
chan.click(); chan.trigger("click");
} else { } else {
socket.emit("input", { socket.emit("input", {
target: chat.data("id"), target: chat.data("id"),
@ -402,7 +402,7 @@ $(function() {
if (type === "channel" || type === "query") { if (type === "channel" || type === "query") {
placeholder = `Write to ${chan.data("title")}`; placeholder = `Write to ${chan.data("title")}`;
} }
input.attr("placeholder", placeholder).attr("aria-label", placeholder); input.prop("placeholder", placeholder).prop("aria-label", placeholder);
if (self.hasClass("chan")) { if (self.hasClass("chan")) {
$("#chat-container").addClass("active"); $("#chat-container").addClass("active");
@ -440,8 +440,8 @@ $(function() {
} }
const state = {}; const state = {};
if (self.attr("id")) { if (self.prop("id")) {
state.clickTarget = `#${self.attr("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.data("id")}"]`;
} else { } else {
@ -506,7 +506,7 @@ $(function() {
closeChan($(`.networks .chan[data-target="${itemData}"]`)); closeChan($(`.networks .chan[data-target="${itemData}"]`));
}, },
focusChan: function(itemData) { focusChan: function(itemData) {
$(`.networks .chan[data-target="${itemData}"]`).click(); $(`.networks .chan[data-target="${itemData}"]`).trigger("click");
}, },
list: function(itemData) { list: function(itemData) {
socket.emit("input", { socket.emit("input", {
@ -524,7 +524,7 @@ $(function() {
const chan = utils.findCurrentNetworkChan(itemData); const chan = utils.findCurrentNetworkChan(itemData);
if (chan.length) { if (chan.length) {
chan.click(); chan.trigger("click");
} }
socket.emit("input", { socket.emit("input", {
@ -532,13 +532,13 @@ $(function() {
text: "/whois " + itemData, text: "/whois " + itemData,
}); });
$(`.channel.active .users .user[data-name="${itemData}"]`).click(); $(`.channel.active .users .user[data-name="${itemData}"]`).trigger("click");
}, },
query: function(itemData) { query: function(itemData) {
const chan = utils.findCurrentNetworkChan(itemData); const chan = utils.findCurrentNetworkChan(itemData);
if (chan.length) { if (chan.length) {
chan.click(); chan.trigger("click");
} }
socket.emit("input", { socket.emit("input", {

View file

@ -22,7 +22,7 @@ const options = {
notifyAllMessages: false, notifyAllMessages: false,
showSeconds: false, showSeconds: false,
statusMessages: "condensed", statusMessages: "condensed",
theme: $("#theme").attr("href").replace(/^themes\/(.*).css$/, "$1"), // Extracts default theme name, set on the server configuration theme: $("#theme").prop("href").replace(/^themes\/(.*).css$/, "$1"), // Extracts default theme name, set on the server configuration
media: true, media: true,
userStyles: userStyles.text(), userStyles: userStyles.text(),
}; };
@ -66,7 +66,7 @@ module.exports.initialize = () => {
settings.find(`input[name=${i}][value=${options[i]}]`) settings.find(`input[name=${i}][value=${options[i]}]`)
.prop("checked", true); .prop("checked", true);
} else if (i === "theme") { } else if (i === "theme") {
$("#theme").attr("href", "themes/" + options[i] + ".css"); $("#theme").prop("href", "themes/" + options[i] + ".css");
settings.find("select[name=" + i + "]").val(options[i]); settings.find("select[name=" + i + "]").val(options[i]);
} else if (options[i]) { } else if (options[i]) {
settings.find("input[name=" + i + "]").prop("checked", true); settings.find("input[name=" + i + "]").prop("checked", true);
@ -83,14 +83,14 @@ module.exports.initialize = () => {
// checkbox state can not be changed). // checkbox state can not be changed).
const updateDesktopNotificationStatus = function() { const updateDesktopNotificationStatus = function() {
if (Notification.permission === "denied") { if (Notification.permission === "denied") {
desktopNotificationsCheckbox.attr("disabled", true); desktopNotificationsCheckbox.prop("disabled", true);
desktopNotificationsCheckbox.attr("checked", false); desktopNotificationsCheckbox.prop("checked", false);
warningBlocked.show(); warningBlocked.show();
} else { } else {
if (Notification.permission === "default" && desktopNotificationsCheckbox.prop("checked")) { if (Notification.permission === "default" && desktopNotificationsCheckbox.prop("checked")) {
desktopNotificationsCheckbox.attr("checked", false); desktopNotificationsCheckbox.prop("checked", false);
} }
desktopNotificationsCheckbox.attr("disabled", false); desktopNotificationsCheckbox.prop("disabled", false);
warningBlocked.hide(); warningBlocked.hide();
} }
}; };
@ -102,14 +102,14 @@ module.exports.initialize = () => {
windows.on("show", "#settings", updateDesktopNotificationStatus); windows.on("show", "#settings", updateDesktopNotificationStatus);
} else { } else {
options.desktopNotifications = false; options.desktopNotifications = false;
desktopNotificationsCheckbox.attr("disabled", true); desktopNotificationsCheckbox.prop("disabled", true);
desktopNotificationsCheckbox.attr("checked", false); desktopNotificationsCheckbox.prop("checked", false);
} }
settings.on("change", "input, select, textarea", function() { settings.on("change", "input, select, textarea", function() {
const self = $(this); const self = $(this);
const type = self.attr("type"); const type = self.prop("type");
const name = self.attr("name"); const name = self.prop("name");
if (type === "password") { if (type === "password") {
return; return;
@ -133,7 +133,7 @@ module.exports.initialize = () => {
} else if (name === "coloredNicks") { } else if (name === "coloredNicks") {
chat.toggleClass("colored-nicks", self.prop("checked")); chat.toggleClass("colored-nicks", self.prop("checked"));
} else if (name === "theme") { } else if (name === "theme") {
$("#theme").attr("href", "themes/" + options[name] + ".css"); $("#theme").prop("href", "themes/" + options[name] + ".css");
} else if (name === "userStyles") { } else if (name === "userStyles") {
userStyles.html(options[name]); userStyles.html(options[name]);
} else if (name === "highlights") { } else if (name === "highlights") {

View file

@ -163,7 +163,7 @@ function renderChannelUsers(data) {
const search = users const search = users
.find(".search") .find(".search")
.attr("placeholder", nicks.length + " " + (nicks.length === 1 ? "user" : "users")); .prop("placeholder", nicks.length + " " + (nicks.length === 1 ? "user" : "users"));
users users
.data("nicks", nicks) .data("nicks", nicks)
@ -204,7 +204,7 @@ function renderNetworks(data, singleNetwork) {
.data("needsNamesRefresh", true) .data("needsNamesRefresh", true)
.find(".header .topic") .find(".header .topic")
.html(helpers_parse(channel.topic)) .html(helpers_parse(channel.topic))
.attr("title", channel.topic); .prop("title", channel.topic);
} }
if (channel.messages.length > 0) { if (channel.messages.length > 0) {
@ -277,10 +277,10 @@ function loadMoreHistory(entries) {
var target = $(entry.target).find(".show-more-button"); var target = $(entry.target).find(".show-more-button");
if (target.attr("disabled")) { if (target.prop("disabled")) {
return; return;
} }
target.click(); target.trigger("click");
}); });
} }

View file

@ -72,7 +72,7 @@ $("#chat").on("click", ".text .toggle-button", function() {
// See https://github.com/thelounge/lounge/issues/1377 // See https://github.com/thelounge/lounge/issues/1377
socket.emit("msg:preview:toggle", { socket.emit("msg:preview:toggle", {
target: parseInt(self.closest(".chan").data("id"), 10), target: parseInt(self.closest(".chan").data("id"), 10),
msgId: parseInt(self.closest(".msg").attr("id").replace("msg-", ""), 10), msgId: parseInt(self.closest(".msg").prop("id").replace("msg-", ""), 10),
link: self.data("url"), link: self.data("url"),
shown: content.hasClass("show"), shown: content.hasClass("show"),
}); });
@ -111,7 +111,7 @@ Mousetrap.bind("esc", () => closeImageViewer());
Mousetrap.bind(["left", "right"], (e, key) => { Mousetrap.bind(["left", "right"], (e, key) => {
if (imageViewer.hasClass("opened")) { if (imageViewer.hasClass("opened")) {
const direction = key === "left" ? "previous" : "next"; const direction = key === "left" ? "previous" : "next";
imageViewer.find(`.${direction}-image-btn`).click(); imageViewer.find(`.${direction}-image-btn`).trigger("click");
} }
}); });
@ -144,8 +144,8 @@ function openImageViewer(link, {pushState = true} = {}) {
nextImage.addClass("next-image"); nextImage.addClass("next-image");
imageViewer.html(templates.image_viewer({ imageViewer.html(templates.image_viewer({
image: link.find("img").attr("src"), image: link.find("img").prop("src"),
link: link.attr("href"), link: link.prop("href"),
type: link.parent().hasClass("toggle-type-link") ? "link" : "image", type: link.parent().hasClass("toggle-type-link") ? "link" : "image",
hasPreviousImage: previousImage.length > 0, hasPreviousImage: previousImage.length > 0,
hasNextImage: nextImage.length > 0, hasNextImage: nextImage.length > 0,
@ -164,20 +164,20 @@ function openImageViewer(link, {pushState = true} = {}) {
// preview, e.g. changelog). This is sub-optimal and needs improvement to // preview, e.g. changelog). This is sub-optimal and needs improvement to
// make image preview more generic and not specific for channel previews. // make image preview more generic and not specific for channel previews.
if (link.closest(".msg").length > 0) { if (link.closest(".msg").length > 0) {
clickTarget = `#${link.closest(".msg").attr("id")} `; clickTarget = `#${link.closest(".msg").prop("id")} `;
} }
clickTarget += `a.toggle-thumbnail[href="${link.attr("href")}"] img`; clickTarget += `a.toggle-thumbnail[href="${link.prop("href")}"] img`;
history.pushState({clickTarget}, null, null); history.pushState({clickTarget}, null, null);
} }
} }
imageViewer.on("click", ".previous-image-btn", function() { imageViewer.on("click", ".previous-image-btn", function() {
$(".previous-image").click(); $(".previous-image").trigger("click");
return false; return false;
}); });
imageViewer.on("click", ".next-image-btn", function() { imageViewer.on("click", ".next-image-btn", function() {
$(".next-image").click(); $(".next-image").trigger("click");
return false; return false;
}); });
@ -188,7 +188,7 @@ function closeImageViewer({pushState = true} = {}) {
imageViewer.empty(); imageViewer.empty();
}); });
input.focus(); input.trigger("focus");
// History management // History management
if (pushState) { if (pushState) {

View file

@ -26,7 +26,7 @@ socket.on("auth", function(data) {
login.find("form").on("submit", function() { login.find("form").on("submit", function() {
const form = $(this); const form = $(this);
form.find(".btn").attr("disabled", true); form.find(".btn").prop("disabled", true);
const values = {}; const values = {};
$.each(form.serializeArray(), function(i, obj) { $.each(form.serializeArray(), function(i, obj) {

View file

@ -24,7 +24,7 @@ socket.on("changelog", function(data) {
const links = $("#changelog .changelog-text a"); const links = $("#changelog .changelog-text a");
// Make sure all links will open a new tab instead of exiting the application // Make sure all links will open a new tab instead of exiting the application
links.attr("target", "_blank"); links.prop("target", "_blank");
// Add required metadata to image links, to support built-in image viewer // Add required metadata to image links, to support built-in image viewer
links.has("img").addClass("toggle-thumbnail"); links.has("img").addClass("toggle-thumbnail");
@ -64,6 +64,6 @@ $("#help").on("click", "#check-now", () => {
// Given a status and latest release information, update the version checker // Given a status and latest release information, update the version checker
// (CSS class and content) // (CSS class and content)
function renderVersionChecker({status, latest}) { function renderVersionChecker({status, latest}) {
$("#version-checker").attr("class", status) $("#version-checker").prop("class", status)
.html(templates.version_checker({latest, status})); .html(templates.version_checker({latest, status}));
} }

View file

@ -31,7 +31,7 @@ socket.on("configuration", function(data) {
const form = $(this); const form = $(this);
const event = form.data("event"); const event = form.data("event");
form.find(".btn").attr("disabled", true); form.find(".btn").prop("disabled", true);
const values = {}; const values = {};
$.each(form.serializeArray(), function(i, obj) { $.each(form.serializeArray(), function(i, obj) {

View file

@ -32,5 +32,5 @@ socket.on("join", function(data) {
return $(a).data("id") - $(b).data("id"); return $(a).data("id") - $(b).data("id");
}) })
.last() .last()
.click(); .trigger("click");
}); });

View file

@ -99,7 +99,7 @@ chat.on("click", ".show-more-button", function() {
let lastMessageId = -1; let lastMessageId = -1;
if (lastMessage.length > 0) { if (lastMessage.length > 0) {
lastMessageId = parseInt(lastMessage.attr("id").replace("msg-", ""), 10); lastMessageId = parseInt(lastMessage.prop("id").replace("msg-", ""), 10);
} }
self self

View file

@ -58,7 +58,7 @@ function processReceivedMessage(data) {
render.appendMessage( render.appendMessage(
container, container,
targetId, targetId,
channel.attr("data-type"), channel.prop("data-type"),
data.msg data.msg
); );
@ -172,7 +172,7 @@ function notifyMessage(targetId, channel, msg) {
}); });
notify.addEventListener("click", function() { notify.addEventListener("click", function() {
window.focus(); window.focus();
button.click(); button.trigger("click");
this.close(); this.close();
}); });
} }

View file

@ -9,7 +9,10 @@ socket.on("part", function(data) {
// When parting from the active channel/query, jump to the network's lobby // When parting from the active channel/query, jump to the network's lobby
if (chanMenuItem.hasClass("active")) { if (chanMenuItem.hasClass("active")) {
chanMenuItem.parent(".network").find(".lobby").click(); chanMenuItem
.parent(".network")
.find(".lobby")
.trigger("click");
} }
chanMenuItem.remove(); chanMenuItem.remove();

View file

@ -7,6 +7,6 @@ const helpers_parse = require("../libs/handlebars/parse");
socket.on("topic", function(data) { socket.on("topic", function(data) {
const topic = $("#chan-" + data.chan).find(".header .topic"); const topic = $("#chan-" + data.chan).find(".header .topic");
topic.html(helpers_parse(data.topic)); topic.html(helpers_parse(data.topic));
// .attr() is safe escape-wise but consider the capabilities of the attribute // .prop() is safe escape-wise but consider the capabilities of the attribute
topic.attr("title", data.topic); topic.prop("title", data.topic);
}); });

View file

@ -51,7 +51,7 @@ function isOpInChannel(channel) {
// Triggering click event opens the virtual keyboard on mobile // Triggering click event opens the virtual keyboard on mobile
// This can only be called from another interactive event (e.g. button click) // This can only be called from another interactive event (e.g. button click)
function forceFocus() { function forceFocus() {
input.trigger("click").focus(); input.trigger("click").trigger("focus");
} }
function collapse() { function collapse() {
@ -69,14 +69,14 @@ function join(args) {
if (channel) { if (channel) {
const chan = findCurrentNetworkChan(channel); const chan = findCurrentNetworkChan(channel);
if (chan.length) { if (chan.length) {
chan.click(); chan.trigger("click");
} }
} }
} }
function toggleNickEditor(toggle) { function toggleNickEditor(toggle) {
$("#nick").toggleClass("editable", toggle); $("#nick").toggleClass("editable", toggle);
$("#nick-value").attr("contenteditable", toggle); $("#nick-value").prop("contenteditable", toggle);
} }
function setNick(nick) { function setNick(nick) {
@ -92,8 +92,8 @@ const favicon = $("#favicon");
function toggleNotificationMarkers(newState) { function toggleNotificationMarkers(newState) {
// Toggles the favicon to red when there are unread notifications // Toggles the favicon to red when there are unread notifications
if (favicon.data("toggled") !== newState) { if (favicon.data("toggled") !== newState) {
var old = favicon.attr("href"); var old = favicon.prop("href");
favicon.attr("href", favicon.data("other")); favicon.prop("href", favicon.data("other"));
favicon.data("other", old); favicon.data("other", old);
favicon.data("toggled", newState); favicon.data("toggled", newState);
} }

View file

@ -11,7 +11,7 @@ let applicationServerKey;
if ("serviceWorker" in navigator) { if ("serviceWorker" in navigator) {
navigator.serviceWorker.addEventListener("message", (event) => { navigator.serviceWorker.addEventListener("message", (event) => {
if (event.data && event.data.type === "open") { if (event.data && event.data.type === "open") {
$("#sidebar").find(`.chan[data-target="#${event.data.channel}"]`).click(); $("#sidebar").find(`.chan[data-target="#${event.data.channel}"]`).trigger("click");
} }
}); });
} }
@ -24,14 +24,14 @@ module.exports.configurePushNotifications = (subscribedOnServer, key) => {
// If client has push registration but the server knows nothing about it, // If client has push registration but the server knows nothing about it,
// this subscription is broken and client has to register again // this subscription is broken and client has to register again
if (clientSubscribed === true && subscribedOnServer === false) { if (clientSubscribed === true && subscribedOnServer === false) {
pushNotificationsButton.attr("disabled", true); pushNotificationsButton.prop("disabled", true);
navigator.serviceWorker.ready navigator.serviceWorker.ready
.then((registration) => registration.pushManager.getSubscription()) .then((registration) => registration.pushManager.getSubscription())
.then((subscription) => subscription && subscription.unsubscribe()) .then((subscription) => subscription && subscription.unsubscribe())
.then((successful) => { .then((successful) => {
if (successful) { if (successful) {
alternatePushButton().removeAttr("disabled"); alternatePushButton().prop("disabled", false);
} }
}); });
} }
@ -58,7 +58,7 @@ module.exports.initialize = () => {
$("#pushNotificationsUnsupported").hide(); $("#pushNotificationsUnsupported").hide();
pushNotificationsButton pushNotificationsButton
.removeAttr("disabled") .prop("disabled", false)
.on("click", onPushButton); .on("click", onPushButton);
clientSubscribed = !!subscription; clientSubscribed = !!subscription;
@ -74,7 +74,7 @@ module.exports.initialize = () => {
}; };
function onPushButton() { function onPushButton() {
pushNotificationsButton.attr("disabled", true); pushNotificationsButton.prop("disabled", true);
navigator.serviceWorker.ready.then((registration) => navigator.serviceWorker.ready.then((registration) =>
registration.pushManager.getSubscription().then((existingSubscription) => { registration.pushManager.getSubscription().then((existingSubscription) => {
@ -106,7 +106,7 @@ function onPushButton() {
}); });
}).then((successful) => { }).then((successful) => {
if (successful) { if (successful) {
alternatePushButton().removeAttr("disabled"); alternatePushButton().prop("disabled", false);
} }
}) })
).catch((err) => { ).catch((err) => {