2009-11-21 7 views
0

Windows 탐색기 스타일의 끌어서 놓기 폴더 동작에 대한 정보는 여기를 참조하십시오. "// chapter items droppable"블록이 작동하지 않습니다. 특히 드래그 된 폴더의 목록에 드래그 가능 항목이 추가되지 않습니다.jQuery가 연결된 폴더에 끌어서 놓기를 추가하지 않음

<html> 

<head> 

    <script src="js/jquery-1.3.2.min.js" type="text/javascript"></script> 
    <script src="js/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script> 

    <style> 

    ul 
    { 
    margin: 0; 
    padding: 0; 
    } 

    ul#chapter_list 
    { 
    background: #fff; 
    } 

    #chapter_list li 
    { 
    list-style-type: none; 
    position: relative; 
    } 

    #chapter_list li .sortable_handle 
    { 
    cursor: move; 
    padding: 2px .5em 5px 5px; 
    position: relative; 
    top: -2px; 
    left: -5px; 
    } 
    span.chapter_title 
    { 
    cursor: pointer; 
    padding-left: 36px !important; 
    background: url(http://www.openwebgraphics.com/resources/data/2296/22x22_folder_orange_open.png) no-repeat 8px 50%; 
    } 

    .comic_chapter div, .comic_page 
    { 
    border: 2px solid black; 
    margin-bottom: 1px; 
    padding: 3px 5px; 
    -moz-border-radius: 6px; 
    -webkit-border-radius: 6px; 
    } 

    li.comic_chapter ul 
    { 
    padding: 2px 2px 2px 1em; 
    margin: 3px; 
    } 

    #chapter_list li.drop_highlight div 
    { 
    background: darkBlue; 
    color: white; 
    } 

    .comic_chapter div 
    { 
    background: LightBlue; 
    } 

    .comic_page 
    { 
    background: #fff; 
    } 

    .chapter-placeholder 
    { 
    border: 2px dashed LightBlue; 
    margin: 2px; 
    } 
    .page-placeholder 
    { 
    height: 1.6em; 
    border: 2px dashed #666; 
    margin: 2px; 
    } 

    </style> 

</head> 

<body> 

    <script type="text/javascript" /> 

    var chapter_list = { 

    0 : { 

    'chapter_title' : 'Un-Chaptered', 
    'chapter_pages' : {} 

    }, 
    1 : { 

    'chapter_title' : 'Chapter 1', 
    'chapter_pages' : { 

     1 : { 

     'page_title' : 'Page 1' 

     }, 
     2 : { 

     'page_title' : 'Page 2' 

     }, 
     3 : { 

     'page_title' : 'Page 3' 

     }, 
     4 : { 

     'page_title' : 'Page 4' 

     }, 
     5 : { 

     'page_title' : 'Page 5' 

     }, 
     6 : { 

     'page_title' : 'Page 6' 

     } 

    } 

    }, 
    2 : { 

    'chapter_title' : 'Chapter 2', 
    'chapter_pages' : { 

     7 : { 

     'page_title' : 'Page 7' 

     }, 
     8 : { 

     'page_title' : 'Page 8' 

     }, 
     9 : { 

     'page_title' : 'Page 9' 

     }, 
     10 : { 

     'page_title' : 'Page 10' 

     } 

    } 

    }, 
    3 : { 

    'chapter_title' : 'Chapter 3', 
    'chapter_pages' : { 

     11 : { 

     'page_title' : 'Page 11' 

     }, 
     12 : { 

     'page_title' : 'Page 12' 

     } 

    } 

    } 

    }; 

    document.write('<ul id="chapter_list">'); 

    for (i in chapter_list) { 

    chapter = chapter_list[i]; 

    document.write('<li id="chapter_' + i + '" class="comic_chapter">' + 
    '<div>' + 
     '<span class="sortable_handle">||</span>'); 

     if (i > 0) document.write('<input type="checkbox" />'); 

    document.write('<span class="chapter_title">' + chapter.chapter_title + '</span>' + 
    '</div>' + 
    '<ul id="chapter_' + i + '_pages">'); 

     for (n in chapter.chapter_pages) { 

     page = chapter.chapter_pages[n]; 

     document.write('<li id="page_' + n + '" class="comic_page">' + 
     '<span class="sortable_handle">||</span>' + 
     '<label for="page_' + n + '_chk">' + 
     '<input type="checkbox" id="page_' + n + '_chk" />' + 
     ' <span class="page_title">' + page.page_title + '</span>' + 
     '</label>' + 
     '</li>'); 

     } 

    document.write('</ul>' + 
    '</li>'); 

    } 

    document.write('</ul>'); 

    </script> 

    <div id="debug"></div> 

    <script type="text/javascript"> 

    // hide Chapter contents 
    $('.comic_chapter ul').hide(); 

    // add onClick => toggle chapter-contents visibility 
    $('.chapter_title').bind('click', function(e){ 
    $(this).parents('li.comic_chapter').children('ul').toggle(); 
    }); 

    // make Chapters sortable 
    $('#chapter_list').sortable({ 
    handle: 'div .sortable_handle', 
    placeholder: 'chapter-placeholder', 
    forcePlaceholderSize: true 
    }).disableSelection(); 

    // make Pages sortable 
    $('.comic_chapter ul').sortable({ 
    handle: '.sortable_handle', 
    placeholder: 'page-placeholder', 
    connectWith: '.comic_chapter ul' // allow pages to be dragged between chapters 
    }).disableSelection(); 

    $('.comic_chapter ul').droppable({ 
    greedy: true 
    }); 

    // make chapter items droppable 
    $('#chapter_list').children('li').droppable({ 
    accept: '.comic_page', 
    hoverClass: 'drop_highlight', 
    drop: function(e, ui) { 
    $(this).children('ul').append(ui.draggable); 
    } 
    }); 


    </script> 

</body> 

</html> 

감사합니다.

+0

지저분한 코드에 대해 사과드립니다. 분명히 너무 많은 쓰레기를 코드 태그에 게시하려고했습니다. – Dan

+0

각 줄 앞에 4 칸을 넣으면 코드 서식 문제를 해결할 수 있습니다. – wambotron

+0

예, 도움을 줄 수 있도록 코드에 4 칸을 추가하십시오. :-) – Bartek

답변

0

나는 당신에게 droppables가 있다는 것을 알지만, draggables는 어디에 있습니까? Droppables는 정적 HTML뿐만 아니라 draggables도 허용합니다. (실제로이 경우에는 아무것도 삭제되지 않습니다.)

+0

"페이지"분류는 본질적으로 드래그 가능합니다. – Dan

+0

당신은 draggable (.comic_chapter ul) 안에 li 요소 인 ".comic_page"를 받아 들일 수 있습니다. 그래서 .comic_page를 draggable로 등록하지 않았다고 생각합니다. – wambotron

+0

".comic_page"는 * sortable * 안에있는 li 요소로, 드래그 할 수 없습니까? – Dan

관련 문제