forked from biouno/uno-choice-plugin
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use jQuery3, add back babel configuration
- Loading branch information
Showing
5 changed files
with
59 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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__'; | ||
|
@@ -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'); | ||
} | ||
|
@@ -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') { | ||
|
@@ -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++) { | ||
|
@@ -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); | ||
} | ||
}); | ||
|
@@ -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'); | ||
|
@@ -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]; | ||
|
@@ -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(); | ||
|
@@ -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++) { | ||
|
@@ -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(); | ||
} | ||
|
@@ -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(); | ||
|
@@ -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]; | ||
|
@@ -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 | ||
|
@@ -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; | ||
|
@@ -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); | ||
|
@@ -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); | ||
}); | ||
|
@@ -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?'); | ||
|
@@ -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?'); | ||
|
@@ -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) { | ||
|
@@ -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; | ||
|
@@ -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; | ||
} | ||
} | ||
|
@@ -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) { | ||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters