-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: EPIC/OEL-3442
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
templates/patterns/copyright_overlay/copyright_overlay.ui_patterns.yml
Outdated
Show resolved
Hide resolved
templates/patterns/copyright_overlay/pattern-copyright-overlay.html.twig
Outdated
Show resolved
Hide resolved
templates/patterns/copyright_overlay/pattern-copyright-overlay.html.twig
Outdated
Show resolved
Hide resolved
templates/patterns/copyright_overlay/pattern-copyright-overlay.html.twig
Outdated
Show resolved
Hide resolved
templates/patterns/copyright_overlay/pattern-copyright-overlay.html.twig
Outdated
Show resolved
Hide resolved
templates/patterns/copyright_overlay/pattern-copyright-overlay.html.twig
Outdated
Show resolved
Hide resolved
templates/patterns/copyright_overlay/pattern-copyright-overlay.html.twig
Outdated
Show resolved
Hide resolved
templates/patterns/copyright_overlay/pattern-copyright-overlay.html.twig
Outdated
Show resolved
Hide resolved
tests/src/Kernel/fixtures/markup_rendering_patterns/copyright_overlay.yml
Outdated
Show resolved
Hide resolved
tests/src/Kernel/fixtures/markup_rendering_patterns/copyright_overlay.yml
Show resolved
Hide resolved
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
templates/patterns/copyright_overlay/pattern-copyright-overlay.html.twig
Outdated
Show resolved
Hide resolved
'attributes': create_attribute() | ||
.setAttribute('id', modal_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'attributes': create_attribute() | |
.setAttribute('id', modal_id) | |
'attributes': create_attribute({ | |
id: modal_id | |
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
resources/js/copy_clipboard.js
Outdated
*/ | ||
Drupal.behaviors.copyClipboard = { | ||
attach: function (context) { | ||
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-target]'), function (element) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-target]'), function (element) { | |
once('oebt-clipcopy', '[data-copy-target]', context).forEach(function (element) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added.
resources/js/copy_clipboard.js
Outdated
detach: function (context, settings, trigger) { | ||
if (trigger === 'unload') { | ||
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-target]'), function (element) { | ||
element.removeEventListener('click'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
resources/js/copy_clipboard.js
Outdated
|
||
detach: function (context, settings, trigger) { | ||
if (trigger === 'unload') { | ||
Array.prototype.forEach.call(document.querySelectorAll('[data-copy-target]'), function (element) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
resources/js/copy_clipboard.js
Outdated
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
includes/pattern.inc
Outdated
*/ | ||
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Jira issue(s):