开发者

Disabling copying in dojo.dnd

开发者 https://www.devze.com 2023-02-02 16:30 出处:网络
By default a dojo.dnd.Source container allows you to hold Ctrl to duplicate/copy a dragged item rather than just move it.

By default a dojo.dnd.Source container allows you to hold Ctrl to duplicate/copy a dragged item rather than just move it.

I know you can set singular=true to stop multiple items being dragged b开发者_如何转开发ut how do I stop copying? Duplicating items makes no sense in the context of my items (I am making a draggable list for reordering pages on a website menu).

Thanks


I'm unsure if there's a nicer way, but I've always accomplished this by clobbering the copyState method on the Source instance to always return false.

If you've got several Sources on the page, you could also elect to dojo.declare a subclass with the method overridden, or dojo.extend dojo.dnd.Source itself to clobber the method in all instances.


Or second option

dojo.addOnLoad(function(){

    //Disable the key events Ctrl and Shift
    dojo.extend( dojo.dnd.Source, { copyState: function( keyPressed, self ){ 
        return false; }}
    );

    //Create the dnd source object for data point column bar
    columnBar = new dojo.dnd.Source("viewColumnBar",{ singular: true });

});


Thanks to Ken Franquiero, I managed to solve this problem. For others in the same boat, here's my code:

/**
 * Extend dojo.dnd.Source to prevent copying
 */

dojo.require( 'dojo.dnd.Source' );
dojo.addOnLoad( function() {

    dojo.declare
    (
        'EditPosition',
        dojo.dnd.Source,
        {
            copyState: function( keyPressed, self )
            {
                return false;
            }
        }
    );

    oEditPosition = new EditPosition
    ( 
        'position_container', 
        {
            withHandles: 'true'
        } 
    );

} );

HTML:

<div id="position_container">
    <div class="dojoDndItem">
        <div class="dojoDndHandle drag_icon drag_handle"></div> <strong>Short Paragraphs</strong>
    </div>
    <div class="dojoDndItem">
        <div class="drag_icon fixed_handle"></div> About Us
    </div>
    <div class="dojoDndItem">
        <div class="drag_icon fixed_handle"></div> Team Members
    </div>
</div>
0

精彩评论

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