| Conditions | 17 |
| Paths | 1440 |
| Total Lines | 88 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like tableWidget.js ➔ initTableWidget often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | /* |
||
| 177 | function initTableWidget(objId, width, height, sortArray) { |
||
| 178 | width = width + ''; |
||
| 179 | height = height + ''; |
||
| 180 | var obj = document.getElementById(objId); |
||
| 181 | obj.parentNode.className = 'widget_tableDiv'; |
||
| 182 | if (navigator.userAgent.indexOf('MSIE') >= 0) { |
||
| 183 | obj.parentNode.style.overflowY = 'auto'; |
||
| 184 | } |
||
| 185 | tableWidget_arraySort[tableWidget_tableCounter] = sortArray; |
||
| 186 | if (width.indexOf('%') >= 0) { |
||
| 187 | obj.style.width = width; |
||
| 188 | obj.parentNode.style.width = width; |
||
| 189 | } else { |
||
| 190 | obj.style.width = width + 'px'; |
||
| 191 | obj.parentNode.style.width = width + 'px'; |
||
| 192 | } |
||
| 193 | |||
| 194 | if (height.indexOf('%') >= 0) { |
||
| 195 | obj.style.height = height; |
||
| 196 | obj.parentNode.style.height = height; |
||
| 197 | |||
| 198 | } else { |
||
| 199 | obj.style.height = height + 'px'; |
||
| 200 | obj.parentNode.style.height = height + 'px'; |
||
| 201 | } |
||
| 202 | obj.id = 'tableWidget' + tableWidget_tableCounter; |
||
| 203 | addEndCol(obj); |
||
| 204 | |||
| 205 | obj.cellSpacing = 0; |
||
| 206 | obj.cellPadding = 0; |
||
| 207 | obj.className = 'tableWidget'; |
||
| 208 | var tHead = obj.getElementsByTagName('THEAD')[0]; |
||
| 209 | var cells = tHead.getElementsByTagName('TD'); |
||
| 210 | for (var no = 0; no < cells.length; no++) { |
||
| 211 | cells[no].className = 'tableWidget_headerCell'; |
||
| 212 | cells[no].onselectstart = cancelTableWidgetEvent; |
||
| 213 | if (no == cells.length - 1) { |
||
| 214 | cells[no].style.borderRight = '0px'; |
||
| 215 | } |
||
| 216 | if (sortArray[no]) { |
||
| 217 | cells[no].onmouseover = highlightTableHeader; |
||
| 218 | cells[no].onmouseout = deHighlightTableHeader; |
||
| 219 | cells[no].onmousedown = mousedownTableHeader; |
||
| 220 | cells[no].onmouseup = highlightTableHeader; |
||
| 221 | cells[no].onclick = sortTable; |
||
| 222 | |||
| 223 | var img = document.createElement('IMG'); |
||
| 224 | img.src = arrowImagePath + 'arrow_up.gif'; |
||
| 225 | cells[no].appendChild(img); |
||
| 226 | img.style.visibility = 'hidden'; |
||
| 227 | |||
| 228 | var img = document.createElement('IMG'); |
||
| 229 | img.src = arrowImagePath + 'arrow_down.gif'; |
||
| 230 | cells[no].appendChild(img); |
||
| 231 | img.style.display = 'none'; |
||
| 232 | |||
| 233 | |||
| 234 | } else { |
||
| 235 | cells[no].style.cursor = 'default'; |
||
| 236 | } |
||
| 237 | |||
| 238 | |||
| 239 | } |
||
| 240 | var tBody = obj.getElementsByTagName('TBODY')[0]; |
||
| 241 | if (document.all && navigator.userAgent.indexOf('Opera') < 0) { |
||
| 242 | tBody.className = 'scrollingContent'; |
||
| 243 | tBody.style.display = 'block'; |
||
| 244 | } else { |
||
| 245 | tBody.className = 'scrollingContent'; |
||
| 246 | tBody.style.height = (obj.parentNode.clientHeight - tHead.offsetHeight) + 'px'; |
||
| 247 | if (navigator.userAgent.indexOf('Opera') >= 0) { |
||
| 248 | obj.parentNode.style.overflow = 'auto'; |
||
| 249 | } |
||
| 250 | } |
||
| 251 | |||
| 252 | for (var no = 1; no < obj.rows.length; no++) { |
||
| 253 | obj.rows[no].onmouseover = highlightDataRow; |
||
| 254 | obj.rows[no].onmouseout = deHighlightDataRow; |
||
| 255 | for (var no2 = 0; no2 < sortArray.length; no2++) { /* Right align numeric cells */ |
||
| 256 | if (sortArray[no2] && sortArray[no2] == 'N')obj.rows[no].cells[no2].style.textAlign = 'right'; |
||
| 257 | } |
||
| 258 | } |
||
| 259 | for (var no2 = 0; no2 < sortArray.length; no2++) { /* Right align numeric cells */ |
||
| 260 | if (sortArray[no2] && sortArray[no2] == 'N')obj.rows[0].cells[no2].style.textAlign = 'right'; |
||
| 261 | } |
||
| 262 | |||
| 263 | tableWidget_tableCounter++; |
||
| 264 | } |
||
| 265 | |||
| 287 |