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

XWIKI-21878: Various close button modals do not use intended icons #2888

Merged
merged 10 commits into from
Aug 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
<span aria-hidden="true">$services.icon.renderHTML('cross')</span>
</button>
<h5 class="modal-title">
$escapetool.xml($services.localization.render('attachment.move.targetLocation.modal.title'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,40 @@ define('modalTranslationKeys', [], [

define('modal', ['jquery', 'l10n!modal', 'bootstrap'], function($, translations) {
'use strict';
var modalTemplate =
// Fetch the cross icon from the icon theme to fill up the modal template.
let iconURL = `${XWiki.contextPath}/rest/wikis/${XWiki.currentWiki}/iconThemes/icons?name=cross`;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the wiki name should be URL-encoded to protect against wiki names with special characters (not sure if we allow them, though).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/search?q=repo%3Axwiki%2Fxwiki-platform%20%24%7BXWiki.currentWiki%7D&type=code
It's already used a few times in the codebase.

I took the opportunity to fix those other uses in 4 files in 217df8a .

I rebuilt the ckeditor plugin with the change, and it didn't break anything when testing on the main wiki :)

let iconRequest = new XMLHttpRequest();
Copy link
Member

Choose a reason for hiding this comment

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

any reason to not use a jquery $.get call here?

Copy link
Contributor Author

@Sereza7 Sereza7 Feb 28, 2024

Choose a reason for hiding this comment

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

No specific reason. I don't have much experience with async javascript and API calls yet. I'll spend some time to try and use jquery instead 👍
Setting this PR as a draft until this is done

let iconMetadata;
// Default value taken until the fetch is fulfilled
var closeIconTemplate = `<span aria-hidden="true">&times;</span>`;
iconRequest.onreadystatechange = function() {
if (iconRequest.readyState === 4 && iconRequest.status === 200 ) {
let response = iconRequest.responseXML;
iconMetadata = response.getElementsByTagName('icon')[0];
if (iconMetadata.getElementsByTagName('iconSetType')[0].textContent === 'IMAGE') {
closeIconTemplate = '<img src="' + iconMetadata.getElementsByTagName('url')[0].textContent +
'" alt="" />';
}
else if (iconMetadata.getElementsByTagName('iconSetType')[0].textContent === 'FONT') {
closeIconTemplate = '<span class="' +
iconMetadata.getElementsByTagName('cssClass')[0].textContent +
'" aria-hidden="true"></span>';
}
console.log(closeIconTemplate);
}
// We update the places where the modalTemplate has already been instanced with the asynchronously retrieved value
$('.modal').find('.close').html(closeIconTemplate);
};
iconRequest.open('GET', iconURL);
iconRequest.send();

let modalTemplate =
'<div class="modal" tabindex="-1" role="dialog" data-backdrop="static">' +
'<div class="modal-dialog" role="document">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-label="Close">' +
'<span aria-hidden="true">&times;</span>' +
closeIconTemplate +
'</button>' +
'<h4 class="modal-title"></h4>' +
'</div>' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
<span aria-hidden="true">$services.icon.renderHTML('cross')</span>
</button>
<h2 class="modal-title">
$escapetool.xml($services.localization.render('extension.security.liveData.advice'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
<span aria-hidden="true">$services.icon.renderHTML('cross')</span>
</button>
<h2 class="modal-title">
$escapetool.xml($services.localization.render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ $xwiki.ssfx.use('uicomponents/viewers/comments.css', true)
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<button type="button" class="close" data-dismiss="modal">$services.icon.renderHTML('cross')</button>
<div class="modal-title">$services.localization.render('core.viewers.comments.permalink')</div>
</div>
<div class="modal-body">
Expand All @@ -359,7 +359,7 @@ $xwiki.ssfx.use('uicomponents/viewers/comments.css', true)
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<button type="button" class="close" data-dismiss="modal">$services.icon.renderHTML('cross')</button>
<div class="modal-title">$services.localization.render('core.viewers.comments.delete')</div>
</div>
<div class="modal-body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">$services.icon.renderHTML('cross')</button>
<div class="modal-title" id="exportTreeModalLabel">
<span class="modal-title-icon">$services.icon.renderHTML('download')</span>
#set ($title = $escapetool.xml($services.localization.render('core.exporter.exportAs', ['__format__'])))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">$services.icon.renderHTML('cross')</button>
<div class="modal-title" id="previewDiffModalTitle">$services.localization.render('core.editors.save.previewDiff.title')</div>
<hr />
<div class="xHint">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@
#set ($discard = $l10n.put($key, $services.localization.render($key)))
#end
#end
#set ($iconNames = ['cross'])
#set ($icons = {})
#foreach ($iconName in $iconNames)
#set ($discard = $icons.put($iconName, $services.icon.renderHTML($iconName)))
#end
#[[*/
// Start JavaScript-only code.
(function(l10n) {
(function(l10n, icons) {
"use strict";

/**
Expand Down Expand Up @@ -114,9 +119,9 @@ require(['jquery', 'xwiki-syntax-converter', 'bootstrap'], function($, syntaxCon
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">`
+ icons.cross +
`</button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body"></div>
Expand Down Expand Up @@ -360,4 +365,4 @@ require(['jquery'], function($) {
});

// End JavaScript-only code.
}).apply(']]#', $jsontool.serialize([$l10n]));
}).apply(']]#', $jsontool.serialize([$l10n, $icons]));
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<button type="button" class="close" data-dismiss="modal">$services.icon.renderHTML('cross')</button>
<div class="modal-title">$services.localization.render('core.viewers.attachments.delete')</div>
</div>
<div class="modal-body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<span class="fa fa-times" aria-hidden="true"></span>
</button>
<div class="modal-title" id="exportModalLabel">Export</div>
</div>
<div class="modal-body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,9 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
<span class="fa fa-times" aria-hidden="true"></span>
</button>
<div class="modal-title" id="exportModalLabel">Export</div>
</div>
<div class="modal-body">
Expand Down