From 91e250eb98ab62b50d95ac401d578a3735b0ec1a Mon Sep 17 00:00:00 2001 From: Migwel Date: Fri, 26 May 2023 23:37:17 +0200 Subject: [PATCH 1/4] Ajouter la copie du permalien dans le menu dropdown des messages --- assets/js/ajax-actions.js | 44 --------------------------- assets/js/topic-message.js | 52 ++++++++++++++++++++++++++++++++ templates/misc/message.part.html | 8 +++++ 3 files changed, 60 insertions(+), 44 deletions(-) create mode 100644 assets/js/topic-message.js diff --git a/assets/js/ajax-actions.js b/assets/js/ajax-actions.js index 44e700353a..e17f6f1799 100644 --- a/assets/js/ajax-actions.js +++ b/assets/js/ajax-actions.js @@ -320,48 +320,4 @@ editor.focus() } }) - - /* - * Mark a message useful - */ - $('.topic-message').on('click', "[data-ajax-input='mark-message-as-useful']", function(e) { - const $button = $(this) - const $form = $button.parents('form:first') - const $message = $form.parents('article') - const $usefulText = $message.find("[data-ajax-output='mark-message-as-useful']") - const csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() - - const $desktopText = $button.find('.desktop') - const $mobileText = $button.find('.until-desktop') - - $.ajax({ - url: $form.attr('action'), - type: 'POST', - data: { - csrfmiddlewaretoken: csrfmiddlewaretoken - }, - success: function() { - $message.toggleClass('helpful') - $usefulText.toggleClass('hidden') - $button.blur() - - // Toggle both mobile and desktop texts - if ($desktopText.length !== 0 && $mobileText.length !== 0) { - const currentDesktopText = $desktopText.text() - const currentMobileText = $mobileText.text() - - $desktopText.text($button.data('content-on-click')) - $mobileText.text($button.data('content-on-click-mobile')) - - $button.data('content-on-click', currentDesktopText) - $button.data('content-on-click-mobile', currentMobileText) - } else { - $button.toggleText('content-on-click') - } - } - }) - - e.stopPropagation() - e.preventDefault() - }) })(jQuery) diff --git a/assets/js/topic-message.js b/assets/js/topic-message.js new file mode 100644 index 0000000000..353278735c --- /dev/null +++ b/assets/js/topic-message.js @@ -0,0 +1,52 @@ +(function() { + 'use strict' + + $('.topic-message').on('click', "[data-ajax-input='copy-hyperlink']", function(e) { + e.stopPropagation() + e.preventDefault() + navigator.clipboard.writeText($(this).attr("data-message-url")); + const dropdown = e.target.closest(".dropdown") + dropdown.removeAttribute('open') + }) + + $('.topic-message').on('click', "[data-ajax-input='mark-message-as-useful']", function(e) { + const $button = $(this) + const $form = $button.parents('form:first') + const $message = $form.parents('article') + const $usefulText = $message.find("[data-ajax-output='mark-message-as-useful']") + const csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() + + const $desktopText = $button.find('.desktop') + const $mobileText = $button.find('.until-desktop') + + $.ajax({ + url: $form.attr('action'), + type: 'POST', + data: { + csrfmiddlewaretoken: csrfmiddlewaretoken + }, + success: function() { + $message.toggleClass('helpful') + $usefulText.toggleClass('hidden') + $button.blur() + + // Toggle both mobile and desktop texts + if ($desktopText.length !== 0 && $mobileText.length !== 0) { + const currentDesktopText = $desktopText.text() + const currentMobileText = $mobileText.text() + + $desktopText.text($button.data('content-on-click')) + $mobileText.text($button.data('content-on-click-mobile')) + + $button.data('content-on-click', currentDesktopText) + $button.data('content-on-click-mobile', currentMobileText) + } else { + $button.toggleText('content-on-click') + } + } + }) + + e.stopPropagation() + e.preventDefault() + }) +})(jQuery) diff --git a/templates/misc/message.part.html b/templates/misc/message.part.html index d67e32f7f7..17a4412356 100644 --- a/templates/misc/message.part.html +++ b/templates/misc/message.part.html @@ -142,6 +142,14 @@ {% endif %} + {% if not is_mp %} +
  • + + {% trans "Copier le permalien" %} + +
  • + {% endif %} + {% if not is_mp %}
  • From 6fa7900948aa3d67a1eae7416a865a5036d93f48 Mon Sep 17 00:00:00 2001 From: Migwel Date: Tue, 12 Sep 2023 23:08:42 +0200 Subject: [PATCH 2/4] Bouge (et retourne) les fonctions JQuery dans des fichiers qui ont plus de sens --- assets/js/ajax-actions.js | 44 ++++++++++++++++++++++++++++ assets/js/message-permalink.js | 11 +++++++ assets/js/topic-message.js | 52 ---------------------------------- 3 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 assets/js/message-permalink.js delete mode 100644 assets/js/topic-message.js diff --git a/assets/js/ajax-actions.js b/assets/js/ajax-actions.js index e17f6f1799..44e700353a 100644 --- a/assets/js/ajax-actions.js +++ b/assets/js/ajax-actions.js @@ -320,4 +320,48 @@ editor.focus() } }) + + /* + * Mark a message useful + */ + $('.topic-message').on('click', "[data-ajax-input='mark-message-as-useful']", function(e) { + const $button = $(this) + const $form = $button.parents('form:first') + const $message = $form.parents('article') + const $usefulText = $message.find("[data-ajax-output='mark-message-as-useful']") + const csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() + + const $desktopText = $button.find('.desktop') + const $mobileText = $button.find('.until-desktop') + + $.ajax({ + url: $form.attr('action'), + type: 'POST', + data: { + csrfmiddlewaretoken: csrfmiddlewaretoken + }, + success: function() { + $message.toggleClass('helpful') + $usefulText.toggleClass('hidden') + $button.blur() + + // Toggle both mobile and desktop texts + if ($desktopText.length !== 0 && $mobileText.length !== 0) { + const currentDesktopText = $desktopText.text() + const currentMobileText = $mobileText.text() + + $desktopText.text($button.data('content-on-click')) + $mobileText.text($button.data('content-on-click-mobile')) + + $button.data('content-on-click', currentDesktopText) + $button.data('content-on-click-mobile', currentMobileText) + } else { + $button.toggleText('content-on-click') + } + } + }) + + e.stopPropagation() + e.preventDefault() + }) })(jQuery) diff --git a/assets/js/message-permalink.js b/assets/js/message-permalink.js new file mode 100644 index 0000000000..b17d584ad7 --- /dev/null +++ b/assets/js/message-permalink.js @@ -0,0 +1,11 @@ +(function() { + 'use strict' + + $('.topic-message').on('click', "[data-ajax-input='copy-hyperlink']", function(e) { + e.stopPropagation() + e.preventDefault() + navigator.clipboard.writeText($(this).attr("data-message-url")); + const dropdown = e.target.closest(".dropdown") + dropdown.removeAttribute('open') + }) +})(jQuery) diff --git a/assets/js/topic-message.js b/assets/js/topic-message.js deleted file mode 100644 index 353278735c..0000000000 --- a/assets/js/topic-message.js +++ /dev/null @@ -1,52 +0,0 @@ -(function() { - 'use strict' - - $('.topic-message').on('click', "[data-ajax-input='copy-hyperlink']", function(e) { - e.stopPropagation() - e.preventDefault() - navigator.clipboard.writeText($(this).attr("data-message-url")); - const dropdown = e.target.closest(".dropdown") - dropdown.removeAttribute('open') - }) - - $('.topic-message').on('click', "[data-ajax-input='mark-message-as-useful']", function(e) { - const $button = $(this) - const $form = $button.parents('form:first') - const $message = $form.parents('article') - const $usefulText = $message.find("[data-ajax-output='mark-message-as-useful']") - const csrfmiddlewaretoken = $form.find('input[name=csrfmiddlewaretoken]').val() - - const $desktopText = $button.find('.desktop') - const $mobileText = $button.find('.until-desktop') - - $.ajax({ - url: $form.attr('action'), - type: 'POST', - data: { - csrfmiddlewaretoken: csrfmiddlewaretoken - }, - success: function() { - $message.toggleClass('helpful') - $usefulText.toggleClass('hidden') - $button.blur() - - // Toggle both mobile and desktop texts - if ($desktopText.length !== 0 && $mobileText.length !== 0) { - const currentDesktopText = $desktopText.text() - const currentMobileText = $mobileText.text() - - $desktopText.text($button.data('content-on-click')) - $mobileText.text($button.data('content-on-click-mobile')) - - $button.data('content-on-click', currentDesktopText) - $button.data('content-on-click-mobile', currentMobileText) - } else { - $button.toggleText('content-on-click') - } - } - }) - - e.stopPropagation() - e.preventDefault() - }) -})(jQuery) From 5c1dadd7782a31cbc270c66f940de06315e12354 Mon Sep 17 00:00:00 2001 From: Migwel Date: Tue, 12 Sep 2023 23:10:58 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Simplifie=20les=20data=20attributes=20utili?= =?UTF-8?q?s=C3=A9s=20pour=20la=20copie=20du=20permalien?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/message-permalink.js | 6 +++--- templates/misc/message.part.html | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/assets/js/message-permalink.js b/assets/js/message-permalink.js index b17d584ad7..97f7f637ea 100644 --- a/assets/js/message-permalink.js +++ b/assets/js/message-permalink.js @@ -1,11 +1,11 @@ (function() { 'use strict' - $('.topic-message').on('click', "[data-ajax-input='copy-hyperlink']", function(e) { + $('.topic-message').on('click', '[data-copy-permalink]', function(e) { e.stopPropagation() e.preventDefault() - navigator.clipboard.writeText($(this).attr("data-message-url")); - const dropdown = e.target.closest(".dropdown") + navigator.clipboard.writeText($(this).attr('data-copy-permalink')) + const dropdown = e.target.closest('.dropdown') dropdown.removeAttribute('open') }) })(jQuery) diff --git a/templates/misc/message.part.html b/templates/misc/message.part.html index 17a4412356..b0acc680a0 100644 --- a/templates/misc/message.part.html +++ b/templates/misc/message.part.html @@ -144,12 +144,11 @@ {% if not is_mp %}
  • - + {% trans "Copier le permalien" %}
  • {% endif %} - {% if not is_mp %}
  • From be5c21c45fcccd07b2454a574c6ed2875a9c1718 Mon Sep 17 00:00:00 2001 From: Migwel Date: Tue, 12 Sep 2023 23:11:34 +0200 Subject: [PATCH 4/4] Autorise la copie de permalien dans les MPs --- templates/misc/message.part.html | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/templates/misc/message.part.html b/templates/misc/message.part.html index b0acc680a0..9d9b3d7c36 100644 --- a/templates/misc/message.part.html +++ b/templates/misc/message.part.html @@ -142,13 +142,11 @@
  • {% endif %} - {% if not is_mp %} -
  • - - {% trans "Copier le permalien" %} - -
  • - {% endif %} +
  • + + {% trans "Copier le permalien" %} + +
  • {% if not is_mp %}