Skip to content

Commit

Permalink
Fixup repeatableDeleteButton compat
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Jan 9, 2022
1 parent fd5a5a7 commit 3d25000
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
25 changes: 23 additions & 2 deletions core/src/main/resources/lib/form/repeatable/repeatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,28 @@ Behaviour.specify("INPUT.repeatable-add", 'repeatable', 0, function(e) {
e = null; // avoid memory leak
});

Behaviour.specify("BUTTON.repeatable-delete, INPUT.repeatable-delete", 'repeatable', 0, function(e) {
/**
* Converts markup for plugins that aren't using the repeatableDeleteButton tag
*/
Behaviour.specify('input.repeatable-delete', 'repeatable-button-fallbacks', 0, function (input) {
var button = document.createElement("button");
for (var index = input.attributes.length - 1; index >= 0; --index) {
button.attributes.setNamedItem(input.attributes[index].cloneNode());
}
if (input.value) {
button.setAttribute("tooltip", input.value);
button.removeAttribute("value");
}

button.classList.add('danger');

button.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M368 368L144 144M368 144L144 368"/></svg>'
input.parentNode.replaceChild(button, input);
console.warn('Adapted element to new markup, it should be changed to use f:repeatableDeleteButton instead in the plugin', button)
});


Behaviour.specify("BUTTON.repeatable-delete, INPUT.repeatable-delete", 'repeatable', 1, function(e) {
e.addEventListener("click", function() {
repeatableSupport.onDelete(e);
})
Expand All @@ -197,4 +218,4 @@ Behaviour.specify("DIV.repeated-chunk", 'repeatable', -200, function(d) {
if (inputs[i].defaultChecked) inputs[i].checked = true;
}
}
});
});
12 changes: 0 additions & 12 deletions war/src/main/webapp/scripts/hudson-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -1507,18 +1507,6 @@ function rowvgStartEachRow(recursive,f) {
adjustSticker();
});

/**
* Converts markup for plugins that aren't using the repeatableDeleteButton tag
*/
Behaviour.specify('input.repeatable-delete', 'repeatable-button-fallbacks', 1000, function (input) {
var button = document.createElement("button");
for (var index = input.attributes.length - 1; index >= 0; --index) {
button.attributes.setNamedItem(input.attributes[index].cloneNode());
}
button.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><title>Close</title><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32" d="M368 368L144 144M368 144L144 368"/></svg>'
input.parentNode.replaceChild(button, input);
});

/**
* Function that provides compatibility to the checkboxes without title on an f:entry
*
Expand Down

0 comments on commit 3d25000

Please sign in to comment.