Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function listBuilder(selector) {
- let secretUl
- let allLi = []
- let obj = {
- createNewList: () => {
- $(selector).empty()
- let ul = $("<ul>")
- secretUl = ul
- $(selector).append(ul)
- },
- addItem: (text) => {
- let li = $("<li>").text(text)
- let btnUp = $("<button>").text('Up').on('click', moveUp)
- let btnDwn = $("<button>").text("Down").on('click', moveDown)
- li.append(btnUp)
- li.append(btnDwn)
- allLi.push(li)
- secretUl.append(li)
- },
- }
- return obj
- function moveUp() {
- console.log(this)
- let li = $(this).parent();
- console.log(li);
- li.insertBefore(li.prev());
- }
- function moveDown() {
- console.log(this)
- let li = $(this).parent();
- console.log(li);
- li.insertAfter(li.next());
- }
- // function exchangeLi(li) {
- // if (li.index() !== 0) {
- // let tempLi = li
- // allLi[li.index()] = allLi[li.index() - 1]
- // allLi[li.index() - 1] = tempLi
- // secretUl.empty()
- // for (let l of allLi) {
- // secretUl.append(l)
- // }
- // }
- // }
- //
- // function exchangeLiDown(li) {
- // if (li.index() !== allLi.length - 1) {
- // let tempLi = li
- // allLi[li.index()] = allLi[li.index() + 1]
- // allLi[li.index() + 1] = tempLi
- // secretUl.empty()
- // for (let l of allLi) {
- // secretUl.append(l)
- // }
- // }
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement