Giter VIP home page Giter VIP logo

Comments (7)

luckylooke avatar luckylooke commented on September 27, 2024

Could you provide your setup? I think your problem is probably same or at least similar to this in dragula.

from angularjs-dragula.

gthomas3 avatar gthomas3 commented on September 27, 2024
    // Used for specifying different callbacks for the two drag directions
    var sourceName = "exercise-list"; // ID of source container where dragula directive is used
    var containerName = "workout";    // ID of destination container where dragula directive is used

    // 'exercise' is an arbitrary name assigned in the dragula directive of the two containers
    // Connecting these containers to the same dragulaService
    dragulaService.options($rootScope, 'exercise', {
        moves: function (el, container, handle) {
            // exercises in the work area, only enable drag-drop on title bar
            if (container.id == containerName) { 
                if ($(handle).closest(".sets").length === 1 || $(handle).closest("#no-exercises-message").length === 1) return false; // anything within .sets is disabled

                else return true; // anything within .title is draggable
            }
            else return true; // allow exercises in exercise list to be moveable by default
        },  
        accepts: function (el, target, source, sibling) {
            console.log('accepts');
            return true; // elements can be dropped in any of the `containers` by default
        },
        invalid: function (el, target) { // prevent buttons and anchor tags from starting a drag
            //return el.tagName === 'A' || el.tagName === 'BUTTON';
        },
        direction: 'vertical', // Y axis is considered when determining where an element would be dropped
        copy: true,            // make a copy of dragged element
        revertOnSpill: true,   // spilling will put the element back where it was dragged from, if this is true
        removeOnSpill: false,  // spilling will `.remove` the element, if this is true
        delay: 200             // enable regular clicks by setting to true or a number of milliseconds

    });

    var thisDragula = dragulaService.find($rootScope, 'exercise');

    thisDragula.drake
    .on("drag", function(el, container) {
        var exerciseId = $(el).data("exercise-id");

        if (container.id == sourceName) {
            for(var i=0; i < $scope.equipments_exercises.length; i++) {

                if ($scope.equipments_exercises[i].id == exerciseId) {
                    $scope.dragDuplicateCheck($scope.equipments_exercises[i]);  
                }

            }
        }
    })
    .on("drop", function(el, container, source) {
        console.log('drop');

        var exerciseId = $(el).data("exercise-id");
        var workoutExercisesDOM = $(container).children();
        for (var i=0; i < $scope.equipments_exercises.length; i++) {

            if ($scope.equipments_exercises[i].id == exerciseId) {

                $scope.$apply(function() {
                    // If there's >1 exercise, positioning the exercise at the correct index on drop
                    if (workoutExercisesDOM.length > 1) {
                        var index;

                        for (var x=0; x < workoutExercisesDOM.length; x++) {
                            if ($(workoutExercisesDOM[x]).attr("class") && $(workoutExercisesDOM[x]).attr("class").indexOf("exercise-js-binding") > 0) {
                                index = x - 1; 
                                // -1 because the 'drag an exercise here..' message adds 1 element to the workoutExercisesDOM length
                                // leaving for now. should be refactored
                            }
                        }

                        $scope.addEquipmentsExerciseToWorkout($scope.equipments_exercises[i], true, index);

                    } else $scope.addEquipmentsExerciseToWorkout($scope.equipments_exercises[i]);

                    $(el).remove(); // remove the dragula cloned element
                });

            }

        }       

    });

from angularjs-dragula.

luckylooke avatar luckylooke commented on September 27, 2024

You didn't provide html, but I assume that both containers are initialized with same options with copy true. Because of this, you cannot sort them once they are dropped in container with option copy: true. You need to provide different options with copy: false to destination container to be able to sort. Once the flag copySortSource will be merged into dragula, it will be passed to dragula-angular too.

from angularjs-dragula.

gthomas3 avatar gthomas3 commented on September 27, 2024

My two container's HTML are:

Source:
<div id="exercise-list" dragula='"exercise"'></div>

Destination:
<div id="workout" dragula='"exercise"'></div>

Not sure if I understood correctly.. Is it possible to initialize the containers with two separate copy options now? If so, how do you do that?

from angularjs-dragula.

luckylooke avatar luckylooke commented on September 27, 2024

Yes, you need two different options, for each container separately:

dragulaService.options($rootScope, 'exercise', {
        copy: true
    });
dragulaService.options($rootScope, 'workout', {
        copy: false // by default
    });

and then html:

<div id="exercise-list" dragula='"exercise"'></div>
<div id="workout" dragula='"workout"'></div>

from angularjs-dragula.

gthomas3 avatar gthomas3 commented on September 27, 2024

nice, that works well to get the desired sorting effect in the destination container, but it disables the cloned elements shadow in the destination container on drag, and also disables dragging elements back into the source container from the destination (removing elements from the destination).

Guessing this is the side-effect of using two unique names for the containers and not the same?

from angularjs-dragula.

luckylooke avatar luckylooke commented on September 27, 2024

@gthomas3 could you provide live code example via jsfiddle, codepen, your webpage or whatever else, so I can investigate problem in your enviroment/setup. It should not disable dragging back if you didn't set it that way.. thanks

from angularjs-dragula.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.