Skip to content

Commit

Permalink
[JENKINS-70231] Fix tooltips on 2.379+ (#130)
Browse files Browse the repository at this point in the history
* Swtich to data-html-tooltip

* Update config.jelly

* Make the PR work on 2.380+

* Correctly determine whether we support data-html-tooltip

* Add TODO to remove version check once obsolete

Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>

Co-authored-by: Tim Jacomb <timjacomb1+github@gmail.com>
Co-authored-by: Daniel Beck <daniel-beck@users.noreply.github.com>
Co-authored-by: Daniel Beck <1831569+daniel-beck@users.noreply.github.com>
Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
  • Loading branch information
5 people authored Dec 8, 2022
1 parent b738a49 commit c07416b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,23 @@ THE SOFTWARE.
</j:forEach>
<local:isEditable sid="${attrs.sid}" type="${attrs.type}">
<td class="stop" style="text-align:left;">
<a href="#" class="selectall" tooltip="${%selectall(h.escape(attrs.sid))}" html-tooltip="${%selectall(h.escape(attrs.sid))}">
<a href="#" class="selectall" tooltip="${%selectall(h.escape(attrs.sid))}" data-html-tooltip="${%selectall(h.escape(attrs.sid))}">
<img alt="${%Select all}" src="${rootURL}/plugin/matrix-auth/images/select-all.svg" style='margin-right:0.2em' height="16" width="16"/>
</a>
<a href="#" class="unselectall" tooltip="${%unselectall(h.escape(attrs.sid))}" html-tooltip="${%unselectall(h.escape(attrs.sid))}">
<a href="#" class="unselectall" tooltip="${%unselectall(h.escape(attrs.sid))}" data-html-tooltip="${%unselectall(h.escape(attrs.sid))}">
<img alt="${%Unselect all}" src="${rootURL}/plugin/matrix-auth/images/unselect-all.svg" height="16" width="16"/>
</a>
<j:if test="${(attrs.sid != 'authenticated' or attrs.type != 'GROUP') and (attrs.sid != 'anonymous' or attrs.type != 'USER')}">
<a href="#" class="remove" tooltip="${%remove(h.escape(attrs.sid))}" html-tooltip="${%remove(h.escape(attrs.sid))}">
<a href="#" class="remove" tooltip="${%remove(h.escape(attrs.sid))}" data-html-tooltip="${%remove(h.escape(attrs.sid))}">
<l:icon alt="${%Remove user/group}" class="icon-stop icon-sm" />
</a>
</j:if>
<j:if test="${attrs.type == 'EITHER'}">
<!-- migration options -->
<a href="#" class="migrate migrate_user" tooltip="${%migrate_user(h.escape(attrs.sid))}" html-tooltip="${%migrate_user(h.escape(attrs.sid))}">
<a href="#" class="migrate migrate_user" tooltip="${%migrate_user(h.escape(attrs.sid))}" data-html-tooltip="${%migrate_user(h.escape(attrs.sid))}">
<l:icon alt="${%Migrate entry to user}" class="icon-person icon-sm" />
</a>
<a href="#" class="migrate migrate_group" tooltip="${%migrate_group(h.escape(attrs.sid))}" html-tooltip="${%migrate_group(h.escape(attrs.sid))}">
<a href="#" class="migrate migrate_group" tooltip="${%migrate_group(h.escape(attrs.sid))}" data-html-tooltip="${%migrate_group(h.escape(attrs.sid))}">
<l:icon alt="${%Migrate entry to group}" class="icon-user icon-sm" />
</a>
</j:if>
Expand Down Expand Up @@ -146,10 +146,10 @@ THE SOFTWARE.
<j:forEach var="g" items="${groups}">
<j:forEach var="p" items="${g.permissions}">
<j:if test="${descriptor.showPermission(p)}">
<th class="pane" html-tooltip="${descriptor.getDescription(p)}" tooltip="${descriptor.getDescription(p)}">
<th class="pane" data-html-tooltip="${descriptor.getDescription(p)}" tooltip="${descriptor.getDescription(p)}">
<!--
Tooltip needs to be HTML for GlobalMatrixAuthorizationStrategy.PermissionNotImpliedBy formatting.
So set 'html-tooltip' for Tippy and 'tooltip' for YUI.
So set 'data-html-tooltip' for Tippy and 'tooltip' for YUI.
-->
<span>
${p.name}
Expand Down
17 changes: 14 additions & 3 deletions src/main/resources/hudson/security/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ Behaviour.specify(".matrix-auth-add-button", 'GlobalMatrixAuthorizationStrategy'
var tooltipAttributeName = getTooltipAttributeName();

findElementsBySelector(copy, ".stop a").each(function(item) {
item.setAttribute("title", item.getAttribute("title").replace("__SID__", name).replace("__TYPE__", typeLabel));
let oldTitle = item.getAttribute("title");
if (oldTitle !== null) {
item.setAttribute("title", oldTitle.replace("__SID__", name).replace("__TYPE__", typeLabel));
}
item.setAttribute(tooltipAttributeName, item.getAttribute(tooltipAttributeName).replace("__SID__", name).replace("__TYPE__", typeLabel));
});

Expand Down Expand Up @@ -201,9 +204,17 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
e = null; // avoid memory leak
});

/*
* Determine which attribute to set tooltips in. Changed in Jenkins 2.379 with Tippy and data-html-tooltip support.
*/
function getTooltipAttributeName() {
var tippySupported = window.registerTooltips !== undefined;
return tippySupported ? 'html-tooltip' : 'tooltip';
let coreVersion = document.body.getAttribute('data-version');
if (coreVersion === null) {
return 'tooltip'
}
// TODO remove after minimum version is 2.379 or higher
let tippySupported = coreVersion >= '2.379';
return tippySupported ? 'data-html-tooltip' : 'tooltip';
}

/*
Expand Down

0 comments on commit c07416b

Please sign in to comment.