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

MDLSITE-7917: Frontpage editable blocks #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

durenadev
Copy link

Hi David,

Working on the task https://tracker.moodle.org/browse/MDLSITE-7917

I have removed the initial blocks on the frontpage, and now they will be managed as content from the platform.

To do this and taking into account that part of the content is dynamic, I have added 2 JavaScripts that update the dynamic content:

  • The number of contributed strings
  • The list of contributors (modifying the links' contents to be accurate with the original styles).

In the task, I added the content with the structure the initial blocks must have. Using this content, the JavaScript modifies the necessary data and maintains the same appearance as the original blocks.

Thanks

@durenadev
Copy link
Author

As an example, you can see the differences between production and next (I added the changes directly into the next pod):

define([], function() {
return {
init: function(contributedstrings) {
const contributedstringsElements = document.querySelectorAll('.contributedstrings');
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that

class="contributedstrings"

is appropriate selector here. We should not use CSS selectors and identifiers for JS integration. An element that has special meaning for a JS (such as its content is provided like in this case) should be identified via data attribute. See https://moodledev.io/docs/5.0/guides/javascript

Copy link
Author

Choose a reason for hiding this comment

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

In this case, my content comes from an HTML block, and moodle filters all these data attributes from this type of content.
This class actually is inside a strong tag. I tried to add data-contributed-strings, and the editor changes that to data-contributed-strings="" but finally is filtered and disappears in the page, the same happens if I use an attribute with content like data-contributed-strings="placeholder".
¿Do you know how to change that from a class and works?

</div>
</div>
</div>
{{#js}}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need those scripts at all? Could not this simple replacement be put here into the JS section completely?

Copy link
Author

Choose a reason for hiding this comment

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

I added it in the module to maintain the standard, replicating what I did in other JavaScript developments like this, related to the HTML content of Moodle.org pages.
I could simplify it and place the content directly outside the AMD module, but that way, we wouldn't keep the code separate.

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.

2 participants