Łatwe kopiowanie i ładny kod
Zaczynam upiekszanie kodu. Najlepeiej, jeśli mialby numery linii (To nie mój pomysł).
Nad stylami muszę jeszcze popracować, ale tutaj jest próbka:
- function Code2Ol() {
- var codes = document.getElementsByTagName("code");
- for(var i = 0; i < codes.length; i++) {
- var code = codes[i];
- var lines = code.textContent.split('\n');
- var ol = document.createElement("ol");
- for(var x = 0; x < lines.length; x++) {
- var li = document.createElement("li");
- var li_code = document.createElement("pre");
- li_code.appendChild(document.createTextNode(lines[x]));
- li.appendChild(li_code);
- ol.appendChild(li);
- }
- code.parentNode.insertBefore(ol, code);
- ol.setAttribute("onclick", "ShowCode(this);");
- code.setAttribute("onclick", "HideCode(this);");
- HideCode(code);
- }
- }
- function ShowCode(ol) {
- ol.nextSibling.setAttribute("class", "code");
- ol.setAttribute("class", "hide");
- }
- function HideCode(code) {
- code.setAttribute("class", "hide");
- code.previousSibling.setAttribute("class", "code");
- }
Po prostu kliknik w kod :)