Skip to content

Commit

Permalink
Ajouter la copie du permalien dans le menu dropdown des messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Migwel committed May 26, 2023
1 parent 445eb9d commit a5a1707
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 44 deletions.
44 changes: 0 additions & 44 deletions assets/js/ajax-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
52 changes: 52 additions & 0 deletions assets/js/topic-message.js
Original file line number Diff line number Diff line change
@@ -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"));

Check failure on line 7 in assets/js/topic-message.js

View workflow job for this annotation

GitHub Actions / Lint and build front-end

Strings must use singlequote

Check failure on line 7 in assets/js/topic-message.js

View workflow job for this annotation

GitHub Actions / Lint and build front-end

Extra semicolon
const dropdown = e.target.closest(".dropdown")

Check failure on line 8 in assets/js/topic-message.js

View workflow job for this annotation

GitHub Actions / Lint and build front-end

Strings must use singlequote
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)
8 changes: 8 additions & 0 deletions templates/misc/message.part.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@
</li>
{% endif %}

{% if not is_mp %}
<li>
<a data-ajax-input="copy-hyperlink" data-message-url="{{ request.build_absolute_uri }}#p{{ message.pk }}" class="ico-after import">
<span>{% trans "Copier le permalien" %}</span>
</a>
</li>
{% endif %}

{% if not is_mp %}
<li>
<a href="#signal-message-{{ message.id }}" class="ico-after alert open-modal">
Expand Down

0 comments on commit a5a1707

Please sign in to comment.