| Conditions | 8 |
| Paths | 9 |
| Total Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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:
| 1 | // Copyright © 2017 Tangdongxin |
||
| 67 | document.addEventListener("click", function(e) { |
||
| 68 | console.log(e); |
||
| 69 | var target = e.target; |
||
| 70 | if (target.tagName.toUpperCase() == "I") { |
||
| 71 | var isClose = target.classList.contains(COLL); |
||
| 72 | console.log(isClose); |
||
| 73 | var classname = target.classList[0]; |
||
| 74 | console.log(classname); |
||
| 75 | if (isClose) { |
||
| 76 | target.removeAttribute("class"); |
||
| 77 | target.setAttribute("class", classname); |
||
| 78 | } else { |
||
| 79 | target.removeAttribute("class"); |
||
| 80 | target.setAttribute("class", classname + " C" + classname.substring(1)); |
||
| 81 | } |
||
| 82 | e.preventDefault(); |
||
| 83 | } else if (target.tagName.toUpperCase() == "STR") { |
||
| 84 | var parentElement = target.parentElement; |
||
| 85 | var originStr = parentElement.innerHTML; |
||
| 86 | parentElement.innerHTML = parentElement.getAttribute("content"); |
||
| 87 | parentElement.setAttribute("content", originStr); |
||
| 88 | } else if (target.tagName.toUpperCase() == "JSON") { |
||
| 89 | if (document.getElementById("light")) { |
||
| 90 | var lightDiv = document.getElementById("light"); |
||
| 91 | lightDiv.parentElement.removeChild(lightDiv); |
||
| 92 | } |
||
| 93 | if (document.getElementById("fade")) { |
||
| 94 | var fadeDiv = document.getElementById("fade"); |
||
| 95 | fadeDiv.parentElement.removeChild(fadeDiv); |
||
| 96 | } |
||
| 97 | |||
| 98 | var parentElement = target.parentElement; |
||
| 99 | |||
| 100 | var fadeDiv = document.createElement("div"); |
||
| 101 | fadeDiv.setAttribute("id", "fade"); |
||
| 102 | fadeDiv.classList.add("black_overlay"); |
||
| 103 | document.body.appendChild(fadeDiv); |
||
| 104 | |||
| 105 | var lightDiv = document.createElement("div"); |
||
| 106 | lightDiv.setAttribute("id", "light"); |
||
| 107 | lightDiv.classList.add("white_content"); |
||
| 108 | document.body.appendChild(lightDiv); |
||
| 109 | |||
| 110 | document.getElementById('light').style.display = 'block'; |
||
| 111 | document.getElementById('fade').style.display = 'block'; |
||
| 112 | draw(eval(parentElement.getAttribute("json")), lightDiv); |
||
| 113 | } else if (target.classList.contains("black_overlay")) { |
||
| 114 | var fadeDiv = document.getElementById("fade"); |
||
| 115 | fadeDiv.parentElement.removeChild(fadeDiv); |
||
| 116 | var lightDiv = document.getElementById("light"); |
||
| 117 | lightDiv.parentElement.removeChild(lightDiv); |
||
| 118 | } |
||
| 119 | }, true); |
||
| 120 | } |
||
| 122 |