سؤال

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 but 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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top