Skip to content

Commit 824ef7f

Browse files
committed
modified the function to use behaviour-shim with active-choice-plugin instead of DOMConrentLoaded dispatch from jenkins core
1 parent eeed1aa commit 824ef7f

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

src/main/js/components/dialogs/index.js

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@ import { createElementFromHtml } from "@/util/dom";
22
import { CLOSE } from "@/util/symbols";
33
import behaviorShim from "@/util/behavior-shim";
44
import jenkins from "@/util/jenkins";
5-
function _reapplyBehaviors(container) {
6-
behaviorShim.applySubtree(container, true);
7-
8-
// Dispatch on both document and window since plugins may listen on either.
9-
// The Active Choices plugin uses window.addEventListener("DOMContentLoaded")
10-
// and manually created events do not bubble, so we must dispatch on window explicitly.
11-
var event = new Event("DOMContentLoaded");
12-
document.dispatchEvent(event);
13-
window.dispatchEvent(event);
14-
}
155

166
let _defaults = {
177
title: null,
@@ -64,7 +54,7 @@ Dialog.prototype.init = function () {
6454
);
6555
content.appendChild(this.options.content);
6656
this.dialog.appendChild(content);
67-
_reapplyBehaviors(content);
57+
behaviorShim.applySubtree(content, true);
6858
}
6959
if (this.options.hideCloseButton !== true) {
7060
const closeButton = createElementFromHtml(`
@@ -96,7 +86,7 @@ Dialog.prototype.init = function () {
9686
this.form = this.options.form;
9787
contents.appendChild(this.options.form);
9888
this.dialog.appendChild(contents);
99-
_reapplyBehaviors(contents);
89+
behaviorShim.applySubtree(contents, true);
10090
}
10191
if (this.dialogType !== "form") {
10292
const message = createElementFromHtml(
@@ -105,7 +95,7 @@ Dialog.prototype.init = function () {
10595
if (this.options.content != null && this.dialogType === "alert") {
10696
message.appendChild(this.options.content);
10797
this.dialog.appendChild(message);
108-
_reapplyBehaviors(message);
98+
behaviorShim.applySubtree(message, true);
10999
} else if (this.options.message != null && this.dialogType !== "prompt") {
110100
const message = createElementFromHtml(
111101
`<div class='jenkins-dialog__contents'/>`,
@@ -161,14 +151,11 @@ Dialog.prototype.checkInput = function () {
161151
Dialog.prototype.appendButtons = function () {
162152
const buttons = createElementFromHtml(`<div
163153
class="jenkins-buttons-row jenkins-buttons-row--equal-width jenkins-dialog__buttons">
164-
<button data-id="ok" type="${
165-
this.options.submitButton ? "submit" : "button"
166-
}" class="jenkins-button jenkins-button--primary ${
167-
_typeClassMap[this.options.type]
168-
}">${this.options.okText}</button>
169-
<button data-id="cancel" class="jenkins-button">${
170-
this.options.cancelText
171-
}</button>
154+
<button data-id="ok" type="${this.options.submitButton ? "submit" : "button"
155+
}" class="jenkins-button jenkins-button--primary ${_typeClassMap[this.options.type]
156+
}">${this.options.okText}</button>
157+
<button data-id="cancel" class="jenkins-button">${this.options.cancelText
158+
}</button>
172159
</div>`);
173160

174161
if (this.dialogType === "form") {
@@ -294,7 +281,7 @@ function init() {
294281
dialog
295282
.show()
296283
.then()
297-
.catch(() => {});
284+
.catch(() => { });
298285
},
299286

300287
alert: function (title, options) {
@@ -307,7 +294,7 @@ function init() {
307294
dialog
308295
.show()
309296
.then()
310-
.catch(() => {});
297+
.catch(() => { });
311298
},
312299

313300
confirm: function (title, options) {

0 commit comments

Comments
 (0)