开发者

jquery drag and drop function

开发者 https://www.devze.com 2023-02-01 05:22 出处:网络
This function takes an li element and adds it to another ul element.After this code is fired the jquery events attached to the children spans of the li element do not fire the first time they are clic

This function takes an li element and adds it to another ul element. After this code is fired the jquery events attached to the children spans of the li element do not fire the first time they are clicked.

function AddToDropBox(obj) {
    $(obj).children(".handle").animate({ width: "20px" }).children("strong").fadeOut();
    $(obj).children("span:not(.track,.play,.handle,:has(.btn-edit))").fadeOut('fa开发者_JAVA百科st');
    $(obj).children(".play").css("margin-right", "8px");
    $(obj).css({ "opacity": "0.0", "width": "284px" }).animate({ opacity: "1.0" });
    if ($(".sidebar-drop-box ul").children(".admin-song").length > 0) {
        $(".dropTitle").fadeOut("fast");
        $(".sidebar-drop-box ul.admin-song-list").css("min-height", "0");
    }
    if (typeof SetLinks == 'function') {
        SetLinks();
    }
    if(document.getElementById("ctl00_cphBody_hfRemoveMedia").value===""||document.getElementById("ctl00_cphBody_hfRemoveMedia").value===null)
    {
        document.getElementById("ctl00_cphBody_hfRemoveMedia").value=(obj).attr("mediaid");
    }
    else
    {
        var localMediaIDs=document.getElementById("ctl00_cphBody_hfRemoveMedia").value;
        localMediaIDs=    localMediaIDs.replace((obj).attr("mediaid"),"");
        document.getElementById("ctl00_cphBody_hfRemoveMedia").value=localMediaIDs+", "+(obj).attr("mediaid");
    }
}

Is there something missing in this code that would cause that?

UPDATE

thats exactly what I am using for the jquery sortable feature that actually calls the addtoDropbox Method().

// Make our dropbox a selectable & sortable.  
    $(".sidebar-drop-box ul").sortable({  
        connectWith: '.admin-left',  
        tolerance: "intersect",  
        handle: ".handle",  
        opacity: "0.5",  
        receive: function(event, ui) {  
            **AddToDropBox(ui.item)**;  
        },  
        start: function(event, ui) {  
            $(".sidebar-drop-box ul.admin-song-list").css("min-height", "70px");  
            isDraggingSong = true;  
            //soundManager.stopAll();  
            //$(".btn-stop").removeClass("btn-stop");  
        },  
        stop: function(event, ui) {  
            if ($(".sidebar-drop-box ul").children("li").length == 0) {  
                $(".dropTitle").fadeIn();  
            }  
        }  
    }); //.selectable({ filter: 'li', cancel: '.btn-stop,.btn-play,.notes,.btn-del,span.remove' });  

    // Do the same for our playlist.  
    $(".admin-left").sortable({  
        opacity: '0.5',  
        tolerance: "intersect",  
        handle: ".handle",  
        appendTo: 'appentToHolder',  
        items: "li.admin-song",  
        update: function(event, ui) {  
            $(ui.item).css("opacity", "0.0").animate({ opacity: "1.0" }, "medium");  
            if ($.browser.msie && $.browser.version == "7.0") {  
                $(ui.item).css("margin-bottom", "-6px");  
            }  
        },  
        receive: function(event, ui) {  
            AddToLeftList(ui.item);  
        },  
        start: function(event, ui) {  
            $(".admin-left li.ui-selected").removeClass("ui-selected");  
            isDraggingSong = true;  
            //soundManager.stopAll();  
            //$(".btn-stop").removeClass("btn-stop");  
        },  
        stop: function(event, ui) {  
            CheckLeftList();  

        },  
        connectWith: '.sidebar-drop-box ul'  
    }).selectable({ filter: 'li.admin-song', cancel: '.head *,.btn-stop,.btn-play,.notes,.btn-del,span.remove' }); // added .head * to fix bug# 1013  

the bold line calls the function I added previously, which places the li element.

I am not sure exactly where the disconnect happens, but i know between these 2 code segments that it breaks something and the next click doesn't not work on the source ul. i ahve been struggling with this for days. I cant turn this back to my boss this shape...lol

thanx


It doesn't look like this function is adding something to a list.

  • This function first does a couple of CSS changes to obj and it's descendants.
  • Then it goes and calls the global function SetLinks (if it is
    defined).
  • And thirdly it sets the value of the element
    "ctl00_cphBody_hfRemoveMedia", which is probably some kind of input.

Looks like this was pasted together from at least two other functions and would need refactoring.

I'm guessing that the cause for your lost events might be somewhere near a call to AddToDropBox.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号