diff --git a/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.PasteboardLink.js b/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.PasteboardLink.js new file mode 100644 index 0000000..397189c --- /dev/null +++ b/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.PasteboardLink.js @@ -0,0 +1,58 @@ +/*! + * HotPocket by BTHLabs (https://hotpocket.app/) + * Copyright 2025-present BTHLabs (https://bthlabs.pl/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +((HotPocket) => { + class HotPocketUIPasteboardLinkPlugin { + constructor (app) { + } + onLoad (event) { + let canCopy = false; + if (navigator.clipboard && navigator.clipboard.writeText) { + canCopy = true; + } + + for (let pasteboardLink of document.querySelectorAll('.ui-pasteboard-link')) { + if (canCopy === false) { + pasteboardLink.classList.add('d-none'); + } else { + pasteboardLink.addEventListener('click', this.onClick); + } + } + } + onClick = (event) => { + event.stopPropagation(); + event.preventDefault(); + + const icon = event.target.querySelector('i.bi'); + icon.classList.replace('bi-clipboard-fill', 'bi-clipboard'); + + navigator.clipboard.writeText(event.target.href). + then(() => { + icon.classList.replace('bi-clipboard', 'bi-clipboard-fill'); + }). + catch((reason) => { + console.error('HotPocket.UI.PasteboardLink.onClick()', reason); + window.alert('Could not copy the link :('); + }); + + return false; + }; + } + + HotPocket.addPlugin('UI.PasteboardLink', (app) => { + return new HotPocketUIPasteboardLinkPlugin(app); + }); +})(window.HotPocket); diff --git a/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.ViewAssociationView.js b/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.ViewAssociationView.js index d719747..d7e3d5e 100644 --- a/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.ViewAssociationView.js +++ b/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.ViewAssociationView.js @@ -41,7 +41,20 @@ if (navigator.share) { shareButton.addEventListener('click', this.onShareButtonClick); } else { - shareButton.addClass('d-none'); + shareButton.remove(); + } + } + + const uiPlugin = this.app.plugin('UI'); + for (let controlButton of document.querySelectorAll('#ViewAssociationView .ui-controls > a.btn')) { + if (uiPlugin.jsEnabled === true) { + if (controlButton.classList.contains('ui-noscript-show')) { + controlButton.remove(); + } + } else { + if (controlButton.classList.contains('ui-noscript-hide')) { + controlButton.remove(); + } } } }; @@ -59,12 +72,9 @@ onShareButtonClick = (event) => { event.preventDefault(); - const shareUrl = new URL(window.location.href); - shareUrl.searchParams.set('share', 'true'); - navigator.share({ title: document.title, - url: shareUrl.toString(), + url: event.target.href, }); return false; diff --git a/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.js b/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.js index 1a049f8..fb646f9 100644 --- a/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.js +++ b/services/backend/hotpocket_backend/apps/ui/static/ui/js/hotpocket-backend.ui.js @@ -18,6 +18,7 @@ class HotPocketUIPlugin { constructor (app) { document.body.classList.add('ui-js-enabled'); + this.jsEnabled = document.body.classList.contains('ui-js-enabled'); if (window.navigator.standalone === true) { document.querySelector('body').classList.add('ui-mode-standalone'); diff --git a/services/backend/hotpocket_backend/apps/ui/templates/ui/associations/view.html b/services/backend/hotpocket_backend/apps/ui/templates/ui/associations/view.html index a0e7dc9..9affd49 100644 --- a/services/backend/hotpocket_backend/apps/ui/templates/ui/associations/view.html +++ b/services/backend/hotpocket_backend/apps/ui/templates/ui/associations/view.html @@ -25,8 +25,8 @@

{% if show_controls %} -

- {% spaceless %} +

+ +
{% endif %} {% if association.description %}
diff --git a/services/backend/hotpocket_backend/apps/ui/templates/ui/page.html b/services/backend/hotpocket_backend/apps/ui/templates/ui/page.html index 0706850..72231b9 100644 --- a/services/backend/hotpocket_backend/apps/ui/templates/ui/page.html +++ b/services/backend/hotpocket_backend/apps/ui/templates/ui/page.html @@ -152,6 +152,7 @@ + {% block page_scripts %}{% endblock %}