提交 a7a48abe 编写于 作者: T Tom Fennelly

Merge pull request #1542 from tfennelly/JENKINS-26406

[FIXED JENKINS-26406] Build history text field wrap fails when containing markup
...@@ -956,7 +956,6 @@ table.parameters > tbody:hover { ...@@ -956,7 +956,6 @@ table.parameters > tbody:hover {
margin-top: 5px; margin-top: 5px;
white-space: normal; white-space: normal;
opacity: 0.6; opacity: 0.6;
font-style: italic;
} }
#buildHistory .build-row-cell { #buildHistory .build-row-cell {
......
...@@ -1681,9 +1681,9 @@ function updateBuildHistory(ajaxUrl,nBuild) { ...@@ -1681,9 +1681,9 @@ function updateBuildHistory(ajaxUrl,nBuild) {
resetCellOverflows(); resetCellOverflows();
// Insert zero-width spaces so as to allow text to wrap, allowing us to get the true clientWidth. // Insert zero-width spaces so as to allow text to wrap, allowing us to get the true clientWidth.
insertZeroWidthSpaces(displayName, 2); insertZeroWidthSpacesInElementText(displayName, 2);
if (desc) { if (desc) {
insertZeroWidthSpaces(desc, 30); insertZeroWidthSpacesInElementText(desc, 30);
markMultiline(); markMultiline();
} }
...@@ -1701,7 +1701,7 @@ function updateBuildHistory(ajaxUrl,nBuild) { ...@@ -1701,7 +1701,7 @@ function updateBuildHistory(ajaxUrl,nBuild) {
// If the name is overflowed, lets remove the zero-width spaces we added above and // If the name is overflowed, lets remove the zero-width spaces we added above and
// re-add zero-width spaces with a bigger max word sizes. // re-add zero-width spaces with a bigger max word sizes.
removeZeroWidthSpaces(displayName); removeZeroWidthSpaces(displayName);
insertZeroWidthSpaces(displayName, 20); insertZeroWidthSpacesInElementText(displayName, 20);
} }
function fitToControlsHeight(element) { function fitToControlsHeight(element) {
...@@ -1871,11 +1871,11 @@ function updateBuildHistory(ajaxUrl,nBuild) { ...@@ -1871,11 +1871,11 @@ function updateBuildHistory(ajaxUrl,nBuild) {
// Insert zero-width spaces in text that may cause overflow distortions. // Insert zero-width spaces in text that may cause overflow distortions.
var displayNames = $(bh).getElementsBySelector('.display-name'); var displayNames = $(bh).getElementsBySelector('.display-name');
for (var i = 0; i < displayNames.length; i++) { for (var i = 0; i < displayNames.length; i++) {
insertZeroWidthSpaces(displayNames[i], 2); insertZeroWidthSpacesInElementText(displayNames[i], 2);
} }
var descriptions = $(bh).getElementsBySelector('.desc'); var descriptions = $(bh).getElementsBySelector('.desc');
for (var i = 0; i < descriptions.length; i++) { for (var i = 0; i < descriptions.length; i++) {
insertZeroWidthSpaces(descriptions[i], 30); insertZeroWidthSpacesInElementText(descriptions[i], 30);
} }
for (var i = 0; i < rows.length; i++) { for (var i = 0; i < rows.length; i++) {
...@@ -1968,13 +1968,17 @@ function getElementOverflowParams(element) { ...@@ -1968,13 +1968,17 @@ function getElementOverflowParams(element) {
} }
var zeroWidthSpace = String.fromCharCode(8203); var zeroWidthSpace = String.fromCharCode(8203);
function insertZeroWidthSpaces(element, maxWordSize) { var ELEMENT_NODE = 1;
if (Element.hasClassName(element, 'zws-inserted')) { var TEXT_NODE = 3;
// already done. function insertZeroWidthSpacesInText(textNode, maxWordSize) {
if (textNode.textContent.length < maxWordSize) {
return; return;
} }
var words = element.textContent.split(/\s+/); // capture the original text
textNode.preZWSText = textNode.textContent;
var words = textNode.textContent.split(/\s+/);
var newTextContent = ''; var newTextContent = '';
var splitRegex = new RegExp('.{1,' + maxWordSize + '}', 'g'); var splitRegex = new RegExp('.{1,' + maxWordSize + '}', 'g');
...@@ -1995,12 +1999,49 @@ function insertZeroWidthSpaces(element, maxWordSize) { ...@@ -1995,12 +1999,49 @@ function insertZeroWidthSpaces(element, maxWordSize) {
newTextContent += ' '; newTextContent += ' ';
} }
element.textContent = newTextContent; textNode.textContent = newTextContent;
}
function insertZeroWidthSpacesInElementText(element, maxWordSize) {
if (Element.hasClassName(element, 'zws-inserted')) {
// already done.
return;
}
if (!element.hasChildNodes()) {
return;
}
var children = element.childNodes;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.nodeType === TEXT_NODE) {
insertZeroWidthSpacesInText(child, maxWordSize);
} else if (child.nodeType === ELEMENT_NODE) {
insertZeroWidthSpacesInElementText(child, maxWordSize);
}
}
Element.addClassName(element, 'zws-inserted'); Element.addClassName(element, 'zws-inserted');
} }
function removeZeroWidthSpaces(element) { function removeZeroWidthSpaces(element) {
if (element) { if (element) {
element.textContent = element.textContent.replace(zeroWidthSpace, ''); if (!Element.hasClassName(element, 'zws-inserted')) {
// Doesn't have ZWSed text.
return;
}
if (!element.hasChildNodes()) {
return;
}
var children = element.childNodes;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.nodeType === TEXT_NODE && child.preZWSText) {
child.textContent = child.preZWSText;
} else if (child.nodeType === ELEMENT_NODE) {
removeZeroWidthSpaces(child);
}
}
Element.removeClassName(element, 'zws-inserted'); Element.removeClassName(element, 'zws-inserted');
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册