Skip to content

Instantly share code, notes, and snippets.

@Prinzhorn
Created February 25, 2014 09:19
Show Gist options
  • Save Prinzhorn/9205560 to your computer and use it in GitHub Desktop.
Save Prinzhorn/9205560 to your computer and use it in GitHub Desktop.
Code quality.

This is an excerpt from a 465 lines js file. This is not satirical. This is actual code from a large codebase (>100k js) of an application that is used in production at multiple customers.

If you're giving a talk or lecture about code quality, feel free to use this as the first slide to make your audience giggle for a second. And then look at their faces when you tell them it's actual code.

for (var i = 0; i < tempNode.childNodes.length; i++) {
if (tempNode.childNodes[i].className.indexOf("picture") >= 0) {
var tempChildNodes = tempNode.childNodes[i].childNodes;
for (var ii = 0; ii < tempChildNodes.length; ii++) {
if (tempChildNodes[ii].className.indexOf("thumbnail") >= 0) {
f.nodeid.value = tempChildNodes[ii].id;
f.thumburi.value = tempChildNodes[ii].src;
f.width.value = tempChildNodes[ii].width;
f.height.value = tempChildNodes[ii].height;
f.alt.value = tempChildNodes[ii].alt;
ImageDialog.callbackTinyMCE([tempChildNodes[ii].id], true);
}
else if (tempChildNodes[ii].className.indexOf("zoom-button") >= 0) {
tempChildChildNodes = tempChildNodes[ii].childNodes;
for (var iii = 0; iii < tempChildChildNodes.length; iii++) {
if (tempChildChildNodes[iii].className.indexOf("thumbnail") >=
0) {
f.nodeid.value = tempChildChildNodes[iii].id;
f.thumburi.value = tempChildChildNodes[iii].src;
f.width.value = tempChildChildNodes[iii].width;
f.height.value = tempChildChildNodes[iii].height;
f.alt.value = tempChildChildNodes[iii].alt;
ImageDialog.callbackTinyMCE([tempChildChildNodes[iii].id], true);
}
}
}
}
}
else if (tempNode.childNodes[i].className.indexOf("expand") >= 0) {
var tempFillNodes = tempNode.childNodes[i].childNodes;
for (var j = 0; j < tempFillNodes.length; j++) {
var tempFillNode = tempFillNodes[j];
if (tempFillNode.className.indexOf("picture") >= 0) {
var tempChildNodes = tempFillNode.childNodes;
for (var ii = 0; ii < tempChildNodes.length; ii++) {
if (tempChildNodes[ii].className.indexOf("thumbnail") >= 0) {
f.nodeid.value = tempChildNodes[ii].id;
f.thumburi.value = tempChildNodes[ii].src;
f.width.value = tempChildNodes[ii].width;
f.height.value = tempChildNodes[ii].height;
f.alt.value = tempChildNodes[ii].alt;
ImageDialog.callbackTinyMCE([tempChildNodes[ii].id], true);
}
else if (tempChildNodes[ii].className.indexOf("zoom-button") >= 0) {
tempChildChildNodes = tempChildNodes[ii].childNodes;
for (var iii = 0; iii < tempChildChildNodes.length; iii++) {
if (tempChildChildNodes[iii].className.indexOf("thumbnail") >= 0) {
f.nodeid.value = tempChildChildNodes[iii].id;
f.thumburi.value = tempChildChildNodes[iii].src;
f.width.value = tempChildChildNodes[iii].width;
f.height.value = tempChildChildNodes[iii].height;
f.alt.value = tempChildChildNodes[iii].alt;
ImageDialog.callbackTinyMCE([tempChildChildNodes[iii].id], true);
}
}
}
}
}
else
if (tempFillNode.className.indexOf("label") >= 0) {
var tempChildNodes = tempFillNode.childNodes;
for (var ii = 0; ii < tempChildNodes.length; ii++) {
if (tempChildNodes[ii].className.indexOf("tools") >= 0) {
f.displayenlarge.checked = true;
}
else if (tempChildNodes[ii].className.indexOf("author") >= 0) {
f.displayauthor.checked = true;
f.author.value = tempChildNodes[ii].innerHTML;
}
else if (tempChildNodes[ii].className.indexOf("description") >= 0) {
f.displaydescription.checked = true;
f.desc.value = tempChildNodes[ii].innerHTML;
}
}
}
}
}
if (tempNode.childNodes[i].className.indexOf("label") >= 0) {
var tempChildNodes = tempNode.childNodes[i].childNodes;
for (var ii = 0; ii < tempChildNodes.length; ii++) {
if (tempChildNodes[ii].className.indexOf("tools") >= 0) {
f.displayenlarge.checked = true;
}
else
if (tempChildNodes[ii].className.indexOf("author") >=
0) {
f.displayauthor.checked = true;
f.author.value = tempChildNodes[ii].innerHTML;
}
else
if (tempChildNodes[ii].className.indexOf("description") >=
0) {
f.displaydescription.checked = true;
f.desc.value = tempChildNodes[ii].innerHTML;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment