Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OEL-3343: Copyright overlay. #430

Open
wants to merge 26 commits into
base: EPIC/OEL-3442
Choose a base branch
from
Open

OEL-3343: Copyright overlay. #430

wants to merge 26 commits into from

Conversation

tibi2303
Copy link
Contributor

Jira issue(s):

Copy link
Contributor

@drishu drishu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I click the copy button, it gives no feedback, feels strange its fixed

drishu
drishu previously approved these changes Sep 16, 2024
Copy link
Contributor

@brummbar brummbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to write a JS test to test the functionality alone. Use the pattern preview page for the test.

@@ -0,0 +1,20 @@
.copyright-overlay {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a dedicated library to attach to the component alone.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library will have the standalone js and the copy_clipboard one as dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, have a look, i hope i understood corectly

Comment on lines 44 to 45
'attributes': create_attribute()
.setAttribute('id', modal_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'attributes': create_attribute()
.setAttribute('id', modal_id)
'attributes': create_attribute({
id: modal_id
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

*/
Drupal.behaviors.copyClipboard = {
attach: function (context) {
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-target]'), function (element) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-target]'), function (element) {
once('oebt-clipcopy', '[data-copy-target]', context).forEach(function (element) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And of course we need to add once library to the dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

detach: function (context, settings, trigger) {
if (trigger === 'unload') {
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-target]'), function (element) {
element.removeEventListener('click');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we remove all click events. To be more accurate, we should remove only our click event. In order to do so, you need to pass the same callback that you used in the addEventListener method. It's enough to name the function and put it in the current scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


detach: function (context, settings, trigger) {
if (trigger === 'unload') {
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-target]'), function (element) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

oe_bootstrap_theme.libraries.yml Show resolved Hide resolved
attach: function (context) {
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-target]'), function (element) {
var targetClass = element.getAttribute('data-copy-target');
var targetElement = document.querySelector('.' + targetClass);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One big problem here: if there are two copyright elements with the same class, the first one in the page will be always copied. If we want to be similar to bootstrap, let's just use the whole selector for the query, and leave the choice to the user. Otherwise we need to make sure to use an ID. Maybe ID in this case is better, or users won't know and pass a class and encounter the same issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.. now it has the whole selector as attr

oe_bootstrap_theme.libraries.yml Show resolved Hide resolved
resources/js/copy_clipboard.js Outdated Show resolved Hide resolved
resources/js/copy_clipboard.js Outdated Show resolved Hide resolved
tests/src/FunctionalJavascript/CopyClipboardTest.php Outdated Show resolved Hide resolved
tests/src/FunctionalJavascript/CopyClipboardTest.php Outdated Show resolved Hide resolved
tests/src/FunctionalJavascript/CopyClipboardTest.php Outdated Show resolved Hide resolved
tests/src/FunctionalJavascript/CopyClipboardTest.php Outdated Show resolved Hide resolved
resources/js/copy_clipboard.js Outdated Show resolved Hide resolved
drishu
drishu previously approved these changes Sep 26, 2024
Copy link
Contributor

@brummbar brummbar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one remark and one question.

*/
function oe_bootstrap_theme_preprocess_pattern_copyright_overlay(array &$variables): void {
$variables['modal_id'] = Html::getUniqueId('bcl-copyright-modal');
$variables['copy_selector'] = Html::getUniqueId('copy-selector');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use copyright-content as ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

const handleClick = function (event) {
const element = event.currentTarget;
const targetSelector = element.getAttribute('data-copy-target');
const targetElement = document.querySelector(targetSelector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we decided to go for the approach where is the user that needs to ensure to pass a selector that triggers one element only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i think it's better because we let the user make extended selectors and it's up to them to provide the correct one.

@tibi2303 tibi2303 changed the base branch from 1.x to EPIC/OEL-3442 September 30, 2024 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants