Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ div.xwikirenderingerror {
& + .xwikirenderingerrordescription {
margin-top: -20px;
}

&[role="button"] {
cursor: pointer;
}
}

// In every cases, apply the DANGER styling from bootstrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,6 @@ Object.extend(XWiki, {
}
},

/**
* Add click listeners on all rendereing error messages to let the user read the detailed error description.
* If a content is passed, add click listener for errors reported in this content (usefull for AJAX requests response)
* Otherwise make all the document's body errors expandable.
*/
makeRenderingErrorsExpandable: function(content) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this removing a public JavaScript API? While I can't find any usages, I'm not sure if it's okay to just remove it. I think this would need a vote on the forum to break this API.

$(content || 'body').select(".xwikirenderingerror").each(function(error) {
var description = error.next(".xwikirenderingerrordescription");
if(description.innerHTML !== "" && description.hasClassName("xwikirenderingerrordescription")) {
error.style.cursor="pointer";
error.title = "$escapetool.javascript($services.localization.render('platform.core.rendering.error.readTechnicalInformation'))";
Event.observe(error, "click", function(event){
event.element().closest(".xwikirenderingerror").next(".xwikirenderingerrordescription").toggleClassName("hidden");
});
}
});
},

/**
* Make links marked with rel="external" in an external window and sets the target attribute to any
* rel attribute starting with "_". Note that We need to do this in Javascript
Expand Down Expand Up @@ -551,7 +533,6 @@ Object.extend(XWiki, {
_addBehaviour: function(container) {
container = container || $('body');

this.makeRenderingErrorsExpandable(container);
this.fixLinksTargetAttribute(container);
this.insertSectionEditLinks(container);
this.registerPanelToggle(container);
Expand Down Expand Up @@ -1849,6 +1830,7 @@ require(['jquery', 'xwiki-meta', 'bootstrap'], ($, xm) => {
if (XWiki.docsyntax !== "xwiki/1.0" && XWiki.contextaction === "view" && XWiki.hasEdit) {
$(rootElement).find('span.wikicreatelink:not(.skipCreatePagePopup) a').on('click', loadCreateModal);
}
makeRenderingErrorsExpandable(rootElement);
}

function loadCreateModal(event) {
Expand Down Expand Up @@ -1881,6 +1863,34 @@ require(['jquery', 'xwiki-meta', 'bootstrap'], ($, xm) => {
})
}

/**
* Add click listeners on all rendering error messages to let the user read the detailed error description.
* If a content is passed, add click listener for errors reported in this content (useful for AJAX requests response)
* Otherwise make all the document's body errors expandable.
*/
function makeRenderingErrorsExpandable(content) {
$(content || 'body').find('.xwikirenderingerror').each(function (index) {
let error = $(this);
let description = error.next(".xwikirenderingerrordescription");
if (description.innerHTML !== "" && description.hasClass("xwikirenderingerrordescription")) {
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 understand this if: first .innerHTML isn't jQuery but native HTML element, and I'm not sure you can access it directly without accessing the actual HTML element (with description[0] basically). Then, you need to check if description contains any element: maybe the selector returns an empty list. Finally the hasClass test is useless: you already are selecting the elements matching that class...

error.attr('id', 'xwikirenderingerror-' + index);
error.attr('role', 'button');
description.attr('id', 'xwikirenderingerrordescription-' + index);
error.attr('aria-controls', 'xwikirenderingerrordescription-' + index);
error.attr('aria-expanded', false);
Copy link
Member

Choose a reason for hiding this comment

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

Note that you can use an object in attr, that would make the code maybe a bit more readable:

error.attr({
  'id': 'xwikirenderingerror-' + index,
  'role': 'button',
  ....
})

let buttonDescription = "$escapetool.javascript($services.localization.render('platform.core.rendering.error.readTechnicalInformation'))"
error.attr('title', buttonDescription);
error.on("click", function () {
// Toggle both the description class and the aria-expanded attribute of the button.
let error = $(this);
let description = error.next('.xwikirenderingerrordescription');
description.toggleClass("hidden");
error.attr('aria-expanded', error.attr('aria-expanded') === 'true' ? 'false' : 'true')
});
}
});
}

$(document).on('xwiki:dom:updated', (event, data) => {
const containers = data?.elements || [document.documentElement];
containers.forEach(init);
Expand Down