Skip to content

Commit

Permalink
Use jQuery3, add back babel configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Sep 28, 2024
1 parent 7f8c60e commit d87768b
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 53 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
["@babel/preset-env", {"targets": {"node": "current"}}],
"@babel/preset-typescript",
"@babel/preset-flow"
],
"plugins": [
"babel-plugin-transform-async-to-promises"
]
},
"jest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
${it.parameters.clear()}
<st:include page="/org/biouno/unochoice/common/choiceParameterCommon.jelly"/>
<st:bind value="${it}" var="cascadeChoiceParameter"/>
<script type="text/javascript">
// source, references table
var referencedParameters = Array();
<j:forEach var="value" items="${it.getReferencedParametersAsArray()}">
// add the element we want to monitor
referencedParameters.push("${value}");
// add the element we want to monitor
referencedParameters.push("${value}");
</j:forEach>

if (window.makeStaplerProxy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@
</j:choose>
</div>
</f:entry>
<st:bind value="${it}" var="dynamicReferenceParameter"/>
<script type="text/javascript">
// source, references table
var referencedParameters = Array();
<j:forEach var="value" items="${it.getReferencedParametersAsArray()}">
// add the element we want to monitor
referencedParameters.push("${value}");
// add the element we want to monitor
referencedParameters.push("${value}");
</j:forEach>

if (window.makeStaplerProxy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jQuery3.noConflict();
*
* <p>This module <strong>depends on JQuery</strong> only.</p>
*
* @param $ jQuery3 global var
* @param jQuery3 jQuery3 global var
* @author Bruno P. Kinoshita <[email protected]>
* @since 0.20
*/
var UnoChoice = UnoChoice || ($ => {
let util = new Util($);
var UnoChoice = UnoChoice || (jQuery3 => {
let util = new Util(jQuery3);
// The final public object
let instance = {};
let SEPARATOR = '__LESEP__';
Expand Down Expand Up @@ -153,13 +153,13 @@ var UnoChoice = UnoChoice || ($ => {
let spinner, rootDiv;
if (this.getRandomName()) {
let spinnerId = this.getRandomName().split('_').pop();
spinner = jQuery(`div#${spinnerId}-spinner`);
spinner = jQuery3(`div#${spinnerId}-spinner`);
// Show spinner
if (spinner) {
spinner.show();
}
// Disable DIV changes
rootDiv = jQuery(`div#${spinnerId}`);
rootDiv = jQuery3(`div#${spinnerId}`);
if (rootDiv) {
rootDiv.css('pointer-events', 'none');
}
Expand Down Expand Up @@ -240,7 +240,7 @@ var UnoChoice = UnoChoice || ($ => {
} else if (parameterElement.tagName === 'DIV' || parameterElement.tagName === 'SPAN') {
if (parameterElement.children.length > 0 && (parameterElement.children[0].tagName === 'DIV' || parameterElement.children[0].tagName === 'SPAN')) {
let tbody = parameterElement.children[0];
$(tbody).empty();
jQuery3(tbody).empty();
let originalArray = [];
// Check whether it is a radio or checkbox element
if (parameterElement.className === 'dynamic_checkbox') {
Expand Down Expand Up @@ -315,7 +315,7 @@ var UnoChoice = UnoChoice || ($ => {
// propagate change
// console.log('Propagating change event from ' + this.getParameterName());
// let e1 = $.Event('change', {parameterName: this.getParameterName()});
// $(this.getParameterElement()).trigger(e1);
// jQuery3(this.getParameterElement()).trigger(e1);
if (!avoidRecursion) {
if (cascadeParameters && cascadeParameters.length > 0) {
for (let i = 0; i < cascadeParameters.length; i++) {
Expand Down Expand Up @@ -376,18 +376,18 @@ var UnoChoice = UnoChoice || ($ => {
this.cascadeParameter = cascadeParameter;
// Add event listener
let _self = this;
$(this.paramElement).change(e => {
jQuery3(this.paramElement).change(e => {
if (e.parameterName === _self.paramName) {
console.log('Skipping self reference to avoid infinite loop!');
e.stopImmediatePropagation();
} else {
console.log(`Cascading changes from parameter ${_self.paramName}...`);
//_self.cascadeParameter.loading(true);
$(".behavior-loading").show();
jQuery3(".behavior-loading").show();
// start updating in separate async function so browser will be able to repaint and show 'loading' animation , see JENKINS-34487
setTimeout(async () => {
await _self.cascadeParameter.update(false);
$(".behavior-loading").hide();
jQuery3(".behavior-loading").hide();
}, 0);
}
});
Expand Down Expand Up @@ -446,12 +446,12 @@ var UnoChoice = UnoChoice || ($ => {
let spinner, rootDiv;
if (parameterElement.id) {
let spinnerId = parameterElement.id.split('_').pop();
spinner = jQuery(`div#${spinnerId}-spinner`);
spinner = jQuery3(`div#${spinnerId}-spinner`);
// Show spinner
if (spinner) {
spinner.show();
}
rootDiv = jQuery(`div#${spinnerId}`);
rootDiv = jQuery3(`div#${spinnerId}`);
// Disable DIV changes
if (rootDiv) {
rootDiv.css('pointer-events', 'none');
Expand All @@ -462,7 +462,7 @@ var UnoChoice = UnoChoice || ($ => {
if (parameterElement.tagName === 'OL') { // handle OL's
console.log('Calling Java server code to update HTML elements...');
await this.proxy.getChoicesForUI(t => {
$(parameterElement).empty(); // remove all children elements
jQuery3(parameterElement).empty(); // remove all children elements
const data = t.responseObject();
console.log(`Values returned from server: ${data}`);
let newValues = data[0];
Expand All @@ -474,7 +474,7 @@ var UnoChoice = UnoChoice || ($ => {
}
});
} else if (parameterElement.tagName === 'UL') { // handle OL's
$(parameterElement).empty(); // remove all children elements
jQuery3(parameterElement).empty(); // remove all children elements
console.log('Calling Java server code to update HTML elements...');
await this.proxy.getChoicesForUI(t => {
const data = t.responseObject();
Expand All @@ -499,7 +499,7 @@ var UnoChoice = UnoChoice || ($ => {
// propagate change
// console.log('Propagating change event from ' + this.getParameterName());
// let e1 = $.Event('change', {parameterName: this.getParameterName()});
// $(this.getParameterElement()).trigger(e1);
// jQuery3(this.getParameterElement()).trigger(e1);
if (!avoidRecursion) {
if (cascadeParameters && cascadeParameters.length > 0) {
for (let i = 0; i < cascadeParameters.length; i++) {
Expand Down Expand Up @@ -537,21 +537,21 @@ var UnoChoice = UnoChoice || ($ => {
this.originalArray = [];
// push existing values into originalArray array
if (this.paramElement.tagName === 'SELECT') { // handle SELECTS
let options = $(paramElement).children().toArray();
let options = jQuery3(paramElement).children().toArray();
for (let i = 0; i < options.length; ++i) {
this.originalArray.push(options[i]);
}
} else if (paramElement.tagName === 'DIV' || paramElement.tagName === 'SPAN') { // handle CHECKBOXES
if ($(paramElement).children().length > 0 && (paramElement.children[0].tagName === 'DIV' || paramElement.children[0].tagName === 'SPAN')) {
if (jQuery3(paramElement).children().length > 0 && (paramElement.children[0].tagName === 'DIV' || paramElement.children[0].tagName === 'SPAN')) {
let tbody = paramElement.children[0];
let trs = $(tbody).find('div');
let trs = jQuery3(tbody).find('div');
for (let i = 0; i < trs.length ; ++i) {
let tds = $(trs[i]).find('div');
let inputs = $(tds[0]).find('input');
let tds = jQuery3(trs[i]).find('div');
let inputs = jQuery3(tds[0]).find('input');
let input = inputs[0];
this.originalArray.push(input);
}
} // if ($(paramElement).children().length > 0 && paramElement.children[0].tagName === 'DIV') {
} // if (jQuery3(paramElement).children().length > 0 && paramElement.children[0].tagName === 'DIV') {
}
this.initEventHandler();
}
Expand Down Expand Up @@ -610,7 +610,7 @@ var UnoChoice = UnoChoice || ($ => {
*/
FilterElement.prototype.initEventHandler = function() {
let _self = this;
$(_self.filterElement).keyup(e => {
jQuery3(_self.filterElement).keyup(e => {
//let filterElement = e.target;
let filterElement = _self.getFilterElement();
let filteredElement = _self.getParameterElement();
Expand Down Expand Up @@ -641,17 +641,17 @@ var UnoChoice = UnoChoice || ($ => {
let tagName = filteredElement.tagName;

if (tagName === 'SELECT') { // handle SELECT's
$(filteredElement).children().remove();
jQuery3(filteredElement).children().remove();
for (let i = 0; i < newOptions.length ; ++i) {
let opt = document.createElement('option');
opt.value = newOptions[i].value;
opt.innerHTML = newOptions[i].innerHTML;
$(filteredElement).append(opt);
jQuery3(filteredElement).append(opt);
}
} else if (tagName === 'DIV' || tagName === 'SPAN') { // handle CHECKBOXES, RADIOBOXES and other elements (Jenkins renders them as tables)
if ($(filteredElement).children().length > 0 && ($(filteredElement).children()[0].tagName === 'DIV' || $(filteredElement).children()[0].tagName === 'SPAN')) {
if (jQuery3(filteredElement).children().length > 0 && (jQuery3(filteredElement).children()[0].tagName === 'DIV' || jQuery3(filteredElement).children()[0].tagName === 'SPAN')) {
let tbody = filteredElement.children[0];
$(tbody).empty();
jQuery3(tbody).empty();
if (filteredElement.className === 'dynamic_checkbox') {
for (let i = 0; i < newOptions.length; i++) {
let entry = newOptions[i];
Expand Down Expand Up @@ -702,12 +702,12 @@ var UnoChoice = UnoChoice || ($ => {
tbody.appendChild(tr);
}
}
} // if ($(filteredElement).children().length > 0 && $(filteredElement).children()[0].tagName === 'DIV') {
} // if (jQuery3(filteredElement).children().length > 0 && jQuery3(filteredElement).children()[0].tagName === 'DIV') {
} // if (tagName === 'SELECT') { // } else if (tagName === 'DIV') {
// Propagate the changes made by the filter
console.log('Propagating change event after filtering');
let e1 = $.Event('change', {parameterName: 'Filter Element Event'});
$(filteredElement).trigger(e1);
jQuery3(filteredElement).trigger(e1);
});
}
// HTML utility methods
Expand All @@ -731,11 +731,11 @@ var UnoChoice = UnoChoice || ($ => {
* @see issue #21 in GitHub - github.com/biouno/uno-choice-plugin/issues
*/
function fakeSelectRadioButton(clazzName, id) {
let element = $(`#${id}`).get(0);
let element = jQuery3(`#${id}`).get(0);
// deselect all radios with the class=clazzName
let radios = $(`input[class="${clazzName}"]`);
let radios = jQuery3(`input[class="${clazzName}"]`);
radios.each(function(index) {
$(this).attr('name', '');
jQuery3(this).attr('name', '');
});
// select the radio with the id=id
let parent = element.parentNode;
Expand Down Expand Up @@ -763,7 +763,7 @@ var UnoChoice = UnoChoice || ($ => {
* @return {string} the value of the HTML element used as parameter value in Jenkins, as a string
*/
function getParameterValue(htmlParameter) {
let e = $(htmlParameter);
let e = jQuery3(htmlParameter);
let value = '';
if (e.attr('name') === 'value') {
value = util.getElementValue(e);
Expand All @@ -772,7 +772,7 @@ var UnoChoice = UnoChoice || ($ => {
if (subElements) {
let valueBuffer = Array();
subElements.each(function() {
let tempValue = util.getElementValue($(this));
let tempValue = util.getElementValue(jQuery3(this));
if (tempValue)
valueBuffer.push(tempValue);
});
Expand Down Expand Up @@ -884,7 +884,7 @@ var UnoChoice = UnoChoice || ($ => {
}

function renderChoiceParameter(paramName, filterLength) {
let parentDiv = $(`#${paramName}`);
let parentDiv = jQuery3(`#${paramName}`);
let parameterHtmlElement = parentDiv.find('DIV');
if (!parameterHtmlElement || parameterHtmlElement.length === 0) {
console.log('Could not find element by name, perhaps it is a DIV?');
Expand All @@ -904,7 +904,7 @@ var UnoChoice = UnoChoice || ($ => {

async function renderCascadeChoiceParameter(parentDivRef, filterable, name, randomName, filterLength, paramName, referencedParameters, cascadeChoiceParameter) {
// find the cascade parameter element
let parentDiv = jQuery(parentDivRef);
let parentDiv = jQuery3(parentDivRef);
let parameterHtmlElement = parentDiv.find('DIV');
if (!parameterHtmlElement || parameterHtmlElement.length === 0) {
console.log('Could not find element by name, perhaps it is a DIV?');
Expand All @@ -926,10 +926,10 @@ var UnoChoice = UnoChoice || ($ => {
for (let i = 0; i < referencedParameters.length ; ++i) {
let parameterElement = null;
// FIXME: review the block below
let divs = jQuery('div[name="parameter"]');
let divs = jQuery3('div[name="parameter"]');
for (let j = 0; j < divs.length ; j++) {
let div = divs[j];
let hiddenNames = jQuery(div).find('input[name="name"]');
let hiddenNames = jQuery3(div).find('input[name="name"]');
if (hiddenNames[0].value === referencedParameters[i]) {
let children = div.children;
for (let k = 0; k < children.length; ++k) {
Expand All @@ -938,7 +938,7 @@ var UnoChoice = UnoChoice || ($ => {
parameterElement = child;
break;
} else if (child.tagName === 'DIV' || child.tagName === 'SPAN') {
let subValues = jQuery(child).find('input[name="value"]');
let subValues = jQuery3(child).find('input[name="value"]');
if (subValues && subValues.get(0)) {
parameterElement = child;
break;
Expand Down Expand Up @@ -970,36 +970,36 @@ var UnoChoice = UnoChoice || ($ => {

async function renderDynamicRenderParameter(parentDivRef, name, paramName, referencedParameters, dynamicReferenceParameter) {
// find the cascade parameter element
let parentDiv = jQuery(parentDivRef);
let parentDiv = jQuery3(parentDivRef);
// if the parameter class has been set to hidden, then we hide it now
if (parentDiv.get(0).getAttribute('class') === 'hidden_uno_choice_parameter') {
let parentTbody = jQuery(parentDiv.get(0)).parents('tbody');
let parentTbody = jQuery3(parentDiv.get(0)).parents('tbody');
// FIXME: temporary fix to support both TABLE and DIV in the Jenkins UI
// remove after most users have migrated to newer versions with DIVs
if (!parentTbody || parentTbody.length === 0) {
parentTbody = jQuery(parentDiv.get(0)).parents('div > div.tr');
parentTbody = jQuery3(parentDiv.get(0)).parents('div > div.tr');
}
if (parentTbody && parentTbody.length > 0) {
jQuery(parentTbody.get(0)).attr('style', 'visibility:hidden;position:absolute;');
jQuery3(parentTbody.get(0)).attr('style', 'visibility:hidden;position:absolute;');
}
}
let parameterHtmlElement = null;
for(let i = 0; i < parentDiv.children().length; i++) {
let child = parentDiv.children()[i];
if (child.getAttribute('name') === 'value' || child.id.indexOf('ecp_') > -1) {
parameterHtmlElement = jQuery(child);
parameterHtmlElement = jQuery3(child);
break;
}
if (child.id.indexOf('inputElement_') > -1) {
parameterHtmlElement = jQuery(child);
parameterHtmlElement = jQuery3(child);
break;
}
if (child.id.indexOf('formattedHtml_') > -1) {
parameterHtmlElement = jQuery(child);
parameterHtmlElement = jQuery3(child);
break;
}
if (child.id.indexOf('imageGallery_') > -1) {
parameterHtmlElement = jQuery(child);
parameterHtmlElement = jQuery3(child);
break;
}
}
Expand All @@ -1009,10 +1009,10 @@ var UnoChoice = UnoChoice || ($ => {
for (let i = 0; i < referencedParameters.length ; ++i) {
let parameterElement = null;
// FIXME: review the block below
let divs = jQuery('div[name="parameter"]');
let divs = jQuery3('div[name="parameter"]');
for (let j = 0; j < divs.length ; j++) {
let div = divs[j];
let hiddenNames = jQuery(div).find('input[name="name"]');
let hiddenNames = jQuery3(div).find('input[name="name"]');
if (hiddenNames[0].value === referencedParameters[i]) {
let children = div.children;
for (let k = 0; k < children.length; ++k) {
Expand All @@ -1021,7 +1021,7 @@ var UnoChoice = UnoChoice || ($ => {
parameterElement = child;
break;
} else if (child.tagName === 'DIV' || child.tagName === 'SPAN') {
let subValues = jQuery(child).find('input[name="value"]');
let subValues = jQuery3(child).find('input[name="value"]');
if (subValues && subValues.get(0)) {
parameterElement = child;
break;
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = (env, argv) => ({
module: {
rules: [
{use: "ts-loader", test: /\.ts$/},
{use: "babel-loader", test: /\.es6$/},
],
},
externals: {
Expand Down

0 comments on commit d87768b

Please sign in to comment.