tidy up code and conform use of setAttribute/removeAttribute

This commit is contained in:
schlagmichdoch 2023-11-08 20:36:46 +01:00
parent 55d85ea7fb
commit cf55117a61
3 changed files with 30 additions and 28 deletions

View file

@ -15,7 +15,7 @@
<!-- Descriptions --> <!-- Descriptions -->
<meta name="description" content="Instantly share images, videos, PDFs, and links with people nearby. Peer2Peer and Open Source. No Setup, No Signup."> <meta name="description" content="Instantly share images, videos, PDFs, and links with people nearby. Peer2Peer and Open Source. No Setup, No Signup.">
<meta name="keywords" content="File, Transfer, Share, Peer2Peer"> <meta name="keywords" content="File, Transfer, Share, Peer2Peer">
<meta name="author" content="RobinLinus"> <meta name="author" content="schlagmichdoch">
<meta property="og:title" content="PairDrop"> <meta property="og:title" content="PairDrop">
<meta property="og:type" content="article"> <meta property="og:type" content="article">
<meta property="og:url" content="https://pairdrop.net/"> <meta property="og:url" content="https://pairdrop.net/">

View file

@ -782,7 +782,8 @@ class RTCPeer extends Peer {
channel.onopen = e => this._onChannelOpened(e); channel.onopen = e => this._onChannelOpened(e);
channel.onerror = e => this._onError(e); channel.onerror = e => this._onError(e);
this._conn.createOffer() this._conn
.createOffer()
.then(d => this._onDescription(d)) .then(d => this._onDescription(d))
.catch(e => this._onError(e)); .catch(e => this._onError(e));
} }
@ -1133,7 +1134,8 @@ class PeersManager {
// If no peers are connected anymore, we can safely assume that no other tab on the same browser is connected: // If no peers are connected anymore, we can safely assume that no other tab on the same browser is connected:
// Tidy up peerIds in localStorage // Tidy up peerIds in localStorage
if (Object.keys(this.peers).length === 0) { if (Object.keys(this.peers).length === 0) {
BrowserTabsConnector.removeOtherPeerIdsFromLocalStorage() BrowserTabsConnector
.removeOtherPeerIdsFromLocalStorage()
.then(peerIds => { .then(peerIds => {
if (!peerIds) return; if (!peerIds) return;
console.log("successfully removed other peerIds from localStorage"); console.log("successfully removed other peerIds from localStorage");
@ -1349,11 +1351,11 @@ class Events {
window.dispatchEvent(new CustomEvent(type, { detail: detail })); window.dispatchEvent(new CustomEvent(type, { detail: detail }));
} }
static on(type, callback, options = false) { static on(type, callback, options) {
return window.addEventListener(type, callback, options); return window.addEventListener(type, callback, options);
} }
static off(type, callback, options = false) { static off(type, callback, options) {
return window.removeEventListener(type, callback, options); return window.removeEventListener(type, callback, options);
} }
} }

View file

@ -43,7 +43,7 @@ class PeersUI {
this.$cancelPasteModeBtn.addEventListener('click', _ => this._cancelPasteMode()); this.$cancelPasteModeBtn.addEventListener('click', _ => this._cancelPasteMode());
// Show "Loading…" // Show "Loading…"
this.$displayName.setAttribute("placeholder", this.$displayName.dataset.placeholder); this.$displayName.setAttribute('placeholder', this.$displayName.dataset.placeholder);
this.$displayName.addEventListener('keydown', e => this._onKeyDownDisplayName(e)); this.$displayName.addEventListener('keydown', e => this._onKeyDownDisplayName(e));
this.$displayName.addEventListener('keyup', e => this._onKeyUpDisplayName(e)); this.$displayName.addEventListener('keyup', e => this._onKeyUpDisplayName(e));
@ -310,12 +310,12 @@ class PeersUI {
_onDragOver(e) { _onDragOver(e) {
e.preventDefault(); e.preventDefault();
this.$xInstructions.setAttribute('drop-bg', 1); this.$xInstructions.setAttribute('drop-bg', true);
this.$xNoPeers.setAttribute('drop-bg', 1); this.$xNoPeers.setAttribute('drop-bg', true);
} }
_onDragEnd() { _onDragEnd() {
this.$xInstructions.removeAttribute('drop-bg', 1); this.$xInstructions.removeAttribute('drop-bg');
this.$xNoPeers.removeAttribute('drop-bg'); this.$xNoPeers.removeAttribute('drop-bg');
} }
@ -392,7 +392,7 @@ class PeersUI {
this.$xNoPeers.querySelector('h2').innerHTML = Localization.getTranslation("instructions.no-peers-title"); this.$xNoPeers.querySelector('h2').innerHTML = Localization.getTranslation("instructions.no-peers-title");
this.$cancelPasteModeBtn.setAttribute('hidden', ""); this.$cancelPasteModeBtn.setAttribute('hidden', true);
console.log('Paste mode deactivated.') console.log('Paste mode deactivated.')
Events.fire('paste-mode-changed', { Events.fire('paste-mode-changed', {
@ -649,13 +649,13 @@ class PeerUI {
} }
_onDragOver() { _onDragOver() {
this.$el.setAttribute('drop', 1); this.$el.setAttribute('drop', true);
this.$xInstructions.setAttribute('drop-peer', 1); this.$xInstructions.setAttribute('drop-peer', true);
} }
_onDragEnd() { _onDragEnd() {
this.$el.removeAttribute('drop'); this.$el.removeAttribute('drop');
this.$xInstructions.removeAttribute('drop-peer', 1); this.$xInstructions.removeAttribute('drop-peer');
} }
_onRightClick(e) { _onRightClick(e) {
@ -698,7 +698,7 @@ class Dialog {
} }
show() { show() {
this.$el.setAttribute('show', 1); this.$el.setAttribute('show', true);
if (!window.isMobile && this.$autoFocus) this.$autoFocus.focus(); if (!window.isMobile && this.$autoFocus) this.$autoFocus.focus();
} }
@ -1047,7 +1047,7 @@ class ReceiveFileDialog extends ReceiveDialog {
} }
hide() { hide() {
this.$shareBtn.setAttribute('hidden', ''); this.$shareBtn.setAttribute('hidden', true);
this.$previewBox.innerHTML = ''; this.$previewBox.innerHTML = '';
super.hide(); super.hide();
this._dequeueFile(); this._dequeueFile();
@ -1157,11 +1157,11 @@ class InputKeyContainer {
} }
_enableChars() { _enableChars() {
this.$inputKeyChars.forEach(char => char.removeAttribute("disabled")); this.$inputKeyChars.forEach(char => char.removeAttribute('disabled'));
} }
_disableChars() { _disableChars() {
this.$inputKeyChars.forEach(char => char.setAttribute("disabled", "")); this.$inputKeyChars.forEach(char => char.setAttribute('disabled', true));
} }
_clearChars() { _clearChars() {
@ -1267,8 +1267,8 @@ class PairDeviceDialog extends Dialog {
this.inputKeyContainer = new InputKeyContainer( this.inputKeyContainer = new InputKeyContainer(
this.$el.querySelector('.input-key-container'), this.$el.querySelector('.input-key-container'),
/\d/, /\d/,
() => this.$pairSubmitBtn.removeAttribute("disabled"), () => this.$pairSubmitBtn.removeAttribute('disabled'),
() => this.$pairSubmitBtn.setAttribute("disabled", ""), () => this.$pairSubmitBtn.setAttribute('disabled', true),
() => this._submit() () => this._submit()
); );
@ -1489,8 +1489,8 @@ class PairDeviceDialog extends Dialog {
this.$footerInstructionsPairedDevices.removeAttribute('hidden'); this.$footerInstructionsPairedDevices.removeAttribute('hidden');
} }
else { else {
this.$editPairedDevicesHeaderBtn.setAttribute('hidden', ''); this.$editPairedDevicesHeaderBtn.setAttribute('hidden', true);
this.$footerInstructionsPairedDevices.setAttribute('hidden', ''); this.$footerInstructionsPairedDevices.setAttribute('hidden', true);
} }
Events.fire('evaluate-footer-badges'); Events.fire('evaluate-footer-badges');
Events.fire('header-evaluated', 'edit-paired-devices'); Events.fire('header-evaluated', 'edit-paired-devices');
@ -1637,8 +1637,8 @@ class PublicRoomDialog extends Dialog {
this.inputKeyContainer = new InputKeyContainer( this.inputKeyContainer = new InputKeyContainer(
this.$el.querySelector('.input-key-container'), this.$el.querySelector('.input-key-container'),
/[a-z|A-Z]/, /[a-z|A-Z]/,
() => this.$joinSubmitBtn.removeAttribute("disabled"), () => this.$joinSubmitBtn.removeAttribute('disabled'),
() => this.$joinSubmitBtn.setAttribute("disabled", ""), () => this.$joinSubmitBtn.setAttribute('disabled', true),
() => this._submit() () => this._submit()
); );
@ -1843,7 +1843,7 @@ class PublicRoomDialog extends Dialog {
this.roomId = null; this.roomId = null;
this.inputKeyContainer._cleanUp(); this.inputKeyContainer._cleanUp();
sessionStorage.removeItem('public_room_id'); sessionStorage.removeItem('public_room_id');
this.$footerBadgePublicRoomDevices.setAttribute('hidden', ''); this.$footerBadgePublicRoomDevices.setAttribute('hidden', true);
Events.fire('evaluate-footer-badges'); Events.fire('evaluate-footer-badges');
} }
} }
@ -1879,7 +1879,7 @@ class SendTextDialog extends Dialog {
_onChange() { _onChange() {
if (this._textInputEmpty()) { if (this._textInputEmpty()) {
this.$submit.setAttribute('disabled', ''); this.$submit.setAttribute('disabled', true);
} }
else { else {
this.$submit.removeAttribute('disabled'); this.$submit.removeAttribute('disabled');
@ -2086,7 +2086,7 @@ class Base64ZipDialog extends Dialog {
} }
else { else {
console.log("`navigator.clipboard.readText()` is not available on your browser.\nOn Firefox you can set `dom.events.asyncClipboard.readText` to true under `about:config` for convenience.") console.log("`navigator.clipboard.readText()` is not available on your browser.\nOn Firefox you can set `dom.events.asyncClipboard.readText` to true under `about:config` for convenience.")
this.$pasteBtn.setAttribute('hidden', ''); this.$pasteBtn.setAttribute('hidden', true);
this.$fallbackTextarea.setAttribute('placeholder', Localization.getTranslation("dialogs.base64-paste-to-send", null, {type: translateType})); this.$fallbackTextarea.setAttribute('placeholder', Localization.getTranslation("dialogs.base64-paste-to-send", null, {type: translateType}));
this.$fallbackTextarea.removeAttribute('hidden'); this.$fallbackTextarea.removeAttribute('hidden');
this._inputCallback = _ => this.processInput(type); this._inputCallback = _ => this.processInput(type);
@ -2219,7 +2219,7 @@ class Notifications {
return; return;
} }
Events.fire('notify-user', Localization.getTranslation("notifications.notifications-enabled")); Events.fire('notify-user', Localization.getTranslation("notifications.notifications-enabled"));
this.$headerNotificationButton.setAttribute('hidden', ""); this.$headerNotificationButton.setAttribute('hidden', true);
}); });
} }
@ -2940,7 +2940,7 @@ window.addEventListener('beforeinstallprompt', installEvent => {
const installBtn = document.querySelector('#install') const installBtn = document.querySelector('#install')
installBtn.removeAttribute('hidden'); installBtn.removeAttribute('hidden');
installBtn.addEventListener('click', () => { installBtn.addEventListener('click', () => {
installBtn.setAttribute('hidden', ''); installBtn.setAttribute('hidden', true);
installEvent.prompt(); installEvent.prompt();
}); });
} }