Task 1 - Tabs (22-August-2016)


0

Някой може ли да каже къде греша.Bgcoder ми дава 18/40 а според мен заданието съм го изпълнил и си върви в браузера.

function solve() {
    return function(selectortabs) {
        var element = document.querySelector(selector);
        var tabLink,
            textArea,
            editBtn;
        var ulTabsNav = document.createElement("ul");
        ulTabsNav.className += " tabs-nav";
        var ulTabCont = document.createElement("ul");
        ulTabCont.className += " tabs-content";
        element.appendChild(ulTabsNav);
        element.appendChild(ulTabCont);
        for (var i = 0i < tabs.lengthi += 1) {
            var liNav = document.createElement("li");
            tabLink = document.createElement("a");
            tabLink.className = "tab-link";
            tabLink.setAttribute("index"i)
            tabLink.setAttribute("href""#")
            tabLink.innerHTML = tabs[i].title;
            liNav.appendChild(tabLink);
            ulTabsNav.appendChild(liNav);
            var liContent = document.createElement("li");
            liContent.className = "tab-content";
            liContent.setAttribute("index"i)
            var pCont = document.createElement("p");
            pCont.innerHTML = tabs[i].content;
            editBtn = document.createElement("button");
            editBtn.className = "btn-edit";
            editBtn.innerHTML = "Edit";
            liContent.appendChild(pCont);
            liContent.appendChild(editBtn);
            ulTabCont.appendChild(liContent);
        }
        var tabsContents = element.getElementsByClassName("tab-content");
        tabsContents[0].className += " visible";
        document.addEventListener("click"function(ev) {
            var target = ev.target;
            if (target.className === 'tab-link') {
                var visibleCont = element.getElementsByClassName("visible")[0];
                visibleCont.classList.remove("visible");
                var atrIndex = target.getAttribute("index");
                tabsContents[atrIndex].className += " visible";
            }
            if (target.className === "btn-edit") {
                if (target.innerHTML === "Edit") {
                    target.innerHTML = "Save";
                    textArea = document.createElement("textarea");
                    textArea.className = "edit-content";
                    textArea.value = target.previousSibling.innerHTML;
                    target.parentNode.appendChild(textArea);
                } else {
                    target.innerHTML = "Edit";
                    target.previousSibling.innerHTML = textArea.value;
                    target.parentNode.removeChild(textArea);
                }
            }
        });
    }
}




Отговори



0
  • DO NOT use inline styles. You only need the classes from main.css.
  • DO NOT use innerText or textContent.
  • DO NOT use classList to add or remove classes.

Допълнителни условия, които се намират към края на описанието на задачата. В event handler-a ползваш classList.remove(...).


от IvanS1991 (80 точки)