Code Monkey home page Code Monkey logo

dragular's Introduction

Dragular

Angular drag&drop based on dragula

Browser support includes every sane browser and IE7+. (Granted you polyfill the functional Array methods in ES5)

⚠️ IMPORTANT NOTICE!!! ⚠️

I am archiving this repository as I do not want to maintain it anymore, it is obsolete in some way and I am far from using angular v1+ now so it would be hard to continue with support. Please feel free to fork and continue on your own if you wish, thank you for understanding

Inspiration

I was working on angular project using several drag&drop libraries in it, one for UI elements, one for lists, etc.. I wanted to use one full-featured drag&drop library for whole project. As I could not find any suitable, I decided to create one. I have choosen great library dragula by Nicolas Bevacqua as my starting point, make it more angular and started to put features in it! If you wish light-weight angular version of dragula, there is official angular version of dragula.

Actual version 4.6.0 is based on dragula 3.6.3 and tested with angular 1.6.5.

Differences of dragular (against dragula)

  • replaced dragula crossvent with angulars event binding
  • replaced dragula contra.emitter with $scope.$emit if scope provided in options (options.scope)
  • provided as service or directive dragular where options can be passed via atribute dragular
  • automatic direction if not provided in options, instead of default vertical
  • accepting arraylike objects as containers array (jQuery, jQlite collections etc..)
  • accepting custom classes via option.classes
  • accepting custom event names via option.eventNames
  • namespaced containers groups available via option.nameSpace (containers in same nameSpace cooperate)
  • boundingBox (dragging element can me moved only in specific area)
  • lockX/Y (dragging element can me moved only in specific direction)
  • DOM can be synced with scope model
  • support css selectors to define containers
  • added syntax highlighter to example codes
  • etc..

Features

  • provided as service and also as directive
  • Easy to set up
  • No bloated dependencies
  • A shadow where the item would be dropped offers visual feedback
  • Touch events!
  • DOM can be synced with model
  • area or axes of movement can be restricted

Install

download dragular.js and dragular.css from dist folder

OR clone git

git clone http://github.com/luckylooke/dragular.git

OR use npm

[sudo] npm install dragular

OR use bower

bower install dragular

AND include files into your project

  <link href='styles/dragular.css' rel='stylesheet' type='text/css' />
  <script src='scripts/dragular.js'></script>

AND put dragularModule into dependency array

var app = angular.module('myApp', ['dragularModule', 'otherDependencies']);

DONE :)

Usage

Dragular provides the easiest possible API to make drag and drop a breeze in your applications. You can use it as service or as directive. Both arguments are optional. But you need to tell dragular what element(s) to use as container(s)(container is closest wrapping element of draggables and also it serves as droppable area). In service you can provide them in forst argument or in second via options.containers. Options.containers property is higher priority!

As service dragularService(containers?, options?)

By default, dragular will allow the user to drag an element in any of the containers and drop it in any other container in the list. If the element is dropped anywhere that's not one of the containers, the event will be gracefully cancelled according to the revertOnSpill and removeOnSpill options.

Note that dragging is only triggered on left clicks, and only if no meta keys are pressed. Clicks on buttons and anchor tags are ignored, too.

The example below allows the user to drag elements from left into right, and from right into left.

dragularService('#left, #right');

Containers supported types:

Type Description
element single element of container
string css selector (document.querySelectorAll, beware browser support), one or multiple containers
array array of DOM elements
array-like object containing elements on numerical properties (jQuery wrapper, jQlite, etc..), must have length property

You can also provide an options object into service as second parameter.

dragularService(containers, options);

for example

dragularService(containers, {
  moves: function (el, container, handle) {
    return true;                      // elements are always draggable by default
  },
  accepts: function (el, target, source, sibling) { // applied with target container options
    return true;                      // can target accept dragged item? (target context used)
  },
  canBeAccepted: function (el, target, source, sibling) { // applied with source container options
    return true;                      // can be dragged item accepted by target? (source context used)
  },
  direction: 'vertical',              // Y axis is considered when determining where an element would be dropped
  revertOnSpill: false,               // item returns to original place
  removeOnSpill: false                // item will be removed if not placed into valid target
});

As directive

For now just as attribute (restrict: A)!

<div dragular="dragularOptions"></div>

The dragularOptions can be any name of property where options object is located or angular expression resulting with options object.

$scope.dragularOptions = {
  classes: {
    mirror: 'custom-green-mirror'
  },
  nameSpace: 'common',
  direction: 'horizontal'
};

OR providing options as JSON

<div dragular='{"classes":{"mirror":"custom-green-mirror"},"nameSpace":"common"}'></div>

dragular-model atribute

Model can be optionaly provided via dragular-model atribute, but only in case you are using dragular directive next to it. If presented it has higher priority than options.containersModel property and it extends options provided in dragula attribute into new options object!.

<div dragular-model="items"></div>

dragular-name-space atribute

For better readability of views.

<div dragular-name-space="oranges"></div>

dragular-on-init atribute

Same as options.onInit see bellow.

Options

The options are detailed below. All boolean options can be also function returning boolean except lockX and lockY!

options.containers

Container element, NodeList, array of elements, jQuery object returned by selector or any array-like object where containers elements are placed on properties named 0,1,2,.. etc.

options.containersModel

If you wish to have model synced with containers state, you need to provide it within this property. For single container you can provide an array with items in it. Items can by any type. For multiple containers you need to provide array of arrays (2D-array), where order of arrays representing containers (models) must be same as order of containers elements provided in containers parameter of service.

You can also provide callback function via options.containersModel which is called everytime drag starts. It must return array or 2D-array as mentioned in above paragraph.

String can be also provided to options.containersModel which is used against options.scope if provided, if not there is also opportunity to provide another object via options.containersModelCtx to be used as context and provided string will be evaluated against this object. In case that both options.containersModelCtx and options.scope are provided, options.containersModelCtx has higher priority, so it will be evaluated against it. Target property must be array or 2D-array as mentioned in first paragraph.

Please note that if you are using filters on your items you must provide filtered array no source one!

  <input ng-model="query">
  <div id="container">
     <div ng-repeat="item in getFilteredModel(filteredItems, sourceItems, query)">
       {{item}}
     </div>
  </div>
$scope.filteredItems = [];

dragularService('#container', {
 containersModel: sourceItems,
 containersFilteredModel: $scope.filteredItems
});

$scope.getFilteredModel = function (filteredModel, items, filterQuery) {
 filteredModel.length = 0;
 /*
 * Following one-liner is same like:
 *   var filteredModelTemp = $filter('filter')(items, filterQuery);
 *   angular.forEach(filteredModelTemp, function(item){
 *     filteredModel.push(item);
 *   });
 * Or like:
 *   var filteredModelTemp = $filter('filter')(items, filterQuery);
 *   for(var i; i < filteredModelTemp.length; i++){
 *     filteredModel.push(filteredModelTemp[i]);
 *   }
 *
 * You cannot just assign filtered array to filteredModel like this:
 *   filteredModel = $filter('filter')(items, filterQuery);
 * Because you would replace the array object you provide to dragular with new one.
 * So dragular will continue to use the one it was provided on init.
 * Hopefully I make it clear. :)
  */
 [].push.apply(filteredModel, $filter('filter')(items, filterQuery));
 return filteredModel;
};

options.containersFilteredModel

See 'options.containersModel' above for usecase.

options.isContainer( element )

Element can be forced to be container by custom logic function. Tested element is passed as argument. It is an element under dragged item called recursivelly so it can be also parent of element under the item or parent of a parent, etc..

options.isContainerModel( element )

If isContainer function is provided, you can provide also respective model. Tested element is passed as argument.

options.isContainerAccepts( shared.item, target, shared.source, reference, shared.sourceModel, shared.initialIndex )

If isContainer function is provided, you can provide also respective acceptation function. Parameters are same as for options.accepts.

options.moves

You can define a moves callback which will be invoked with (el, container, handle) whenever an element is clicked. If this method returns false, a drag event won't begin, and the event won't be prevented either. The handle element will be the original click target, which comes in handy to test if that element is an expected "drag handle".

options.accepts

You can set accepts to a method with the following signature: (el, target, source, sibling, sourceModel, initialIndex). It'll be called to make sure that an element el, that came from container source, can be dropped on container target before a sibling element. The sibling can be null, which would mean that the element would be placed as the last element in the container. Note that if options.copy is set to true, el will be set to the copy, instead of the originally dragged element. Applied with options provided with initialisation of target container.

Also note that the position where a drag starts is always going to be a valid place where to drop the element, even if accepts returned false for all cases.

options.canBeAccepted

Same as options.accepts but applied with options provided with initialisation of source container.

options.copy

options.copy( el, source )

If copy is set to true (or a method that returns true), items will be copied rather than moved. This implies the following differences:

Event Move Copy
dragulardrag Element will be concealed from source Nothing happens
dragulardrop Element will be moved into target Element will be cloned into target
dragularremove Element will be removed from DOM Nothing happens
dragularcancel Element will stay in source Nothing happens

If a function is passed, it'll be called whenever an element starts being dragged in order to decide whether it should follow copy behavior or not. Consider the following example.

copy: function (el, source) {
  return el.className === 'you-may-copy-us';
}

If you wish to event handlers binded to element to be copied too, you need to set copy option to 'events' value. It will trigger 'deepWithDataAndEvents' option in clone method of jQlite described in jQuery docs

copy: 'events'

options.copySortSource

If copy is set to true (or a method that returns true) and copySortSource is true as well, users will be able to sort elements in copy-source containers.

copy: true,
copySortSource: true

options.revertOnSpill

By default, spilling an element outside of any containers will move the element back to the drop position previewed by the feedback shadow. Setting revertOnSpill to true will ensure elements dropped outside of any approved containers are moved back to the source element where the drag event began, rather than stay at the drop position previewed by the feedback shadow.

options.removeOnSpill

By default, spilling an element outside of any containers will move the element back to the drop position previewed by the feedback shadow. Setting removeOnSpill to true will ensure elements dropped outside of any approved containers are removed from the DOM. Note that remove events won't fire if copy is set to true.

options.direction

When an element is dropped onto a container, it'll be placed near the point where the mouse was released. If the direction is 'vertical', the Y axis will be considered. Otherwise, if the direction is 'horizontal', the X axis will be considered. Default is automatic, where simple logic determines direction by comparison of dimensions of parent and its first child.

options.scope

Scope can be provided for emitting events, you can provide whichever scope you like.

options.lockX

Lock movement into x-axis.

options.lockY

Lock movement into y-axis.

options.boundingBox

Lock movement inside provided element boundaries.

options.mirrorContainer

Parent element for placing mirror helper element. (default is document.body)

options.ignoreInputTextSelection

Text selection in inputs wont be considered as drag (default is true).

options.classes

Default classes used by dragular can be modified here, providing object with custom names.

defaultClasses = {
  mirror: 'gu-mirror',
  hide: 'gu-hide',
  unselectable: 'gu-unselectable',
  transit: 'gu-transit'
},

// custom example
myClasses = {
  mirror: 'super-mirror'
}

options.eventNames

Default event names can be modified here, providing object with custom names.

defaultEventNames = {
  // drag-over DOM events
  dragularenter: 'dragularenter',
  dragularleave: 'dragularleave',
  dragularrelease: 'dragularrelease',
  // $scope events
  dragularcloned: 'dragularcloned',
  dragulardrag: 'dragulardrag',
  dragularcancel: 'dragularcancel',
  dragulardrop: 'dragulardrop',
  dragularremove: 'dragularremove',
  dragulardragend: 'dragulardragend',
  dragularshadow: 'dragularshadow',
  dragularover: 'dragularover',
  dragularout: 'dragularout'
}

// custom example
myEventNames = {
  dragularenter: 'denter',
  dragularleave: 'dleave'
}

options.compileItemOnDrop

In case your draggable items are customized by other directives/attributes, you can use this flag to run compilation of droped item after drop. It is not supposed to be used with containers items rendered by ng-repeat. In such case you are supposed to add directives/attributes to item template and use logic in controller to enable/disable them.

options.onInit

You can provide function callback called after dragular initialisation with drake as first argument and options object as second argumant.

Events

If $scope is provided as options.scope the following events can be tracked using $scope.$on(type, listener):

Event Name Listener Arguments Event Description
dragulardrag Event, el, container el was lifted from container
dragularrelease Event, el, container, DOM-Event user released button
dragulardragend Event, el Dragging event for el ended with either cancel, remove, or drop
dragulardrop Event, el, target-container, source-container, con-model, el-index, target-model, drop-index el was dropped into target-container from source-container, con-model if models are used, provides model representating the source container and el-index is original index(position) in source-container. target-model is model of target container and drop-index is index (position) of drop.
dragularcancel Event, el, container, con-model, el-index el was being dragged but it got nowhere and went back into container, its last stable parent. con-model if models are used, provides model representating the source container and el-index is original index(position) in container.
dragularremove Event, el, container, con-model, el-index el was being dragged but it got nowhere and it was removed from the DOM. Its last stable parent was container. con-model if models are used, provides model representating the source container and el-index is original index(position) in container.
dragularshadow Event, el, container, DOM-Event el, the visual aid shadow, was moved into container. May trigger many times as the position of Event, el changes, even within the same container
dragularcloned Event, clone, original DOM element original was cloned as clone. Triggers for mirror images and when copy: true
dragularover Event, el, target, container, DOM-Event Dragged element el left hover target target and orginaly came from container
dragularout Event, el, target, container, DOM-Event Dragged element el left hovered target target and orginaly came from container

Event names can be modified via options.eventNames.

API

The dragularService method returns a tiny object with a concise API. We'll refer to the API returned by dragularService as drake.

drake.dragging

This property will be true whenever an element is being dragged.

drake.start(item)

Enter drag mode without a shadow. This method is most useful when providing complementary keyboard shortcuts to an existing drag and drop solution. Even though a shadow won't be created at first, the user will get one as soon as they click on item and start dragging it around. Note that if they click and drag something else, .end will be called before picking up the new item.

drake.end()

Gracefully end the drag event as if using the last position marked by the preview shadow as the drop target. The proper cancel or drop event will be fired, depending on whether the item was dropped back where it was originally lifted from (which is essentially a no-op that's treated as a cancel event).

drake.cancel(revert)

If an element managed by drake is currently being dragged, this method will gracefully cancel the drag action. You can also pass in revert at the method invocation level, effectively producing the same result as if revertOnSpill was true.

Note that a "cancellation" will result in a cancel event only in the following scenarios.

  • revertOnSpill is true
  • Drop target (as previewed by the feedback shadow) is the source container and the item is dropped in the same position where it was originally dragged from

drake.remove()

If an element managed by drake is currently being dragged, this method will gracefully remove it from the DOM.

drake.destroy()

Removes all drag and drop events used by dragularService to manage drag and drop between the containers. If .destroy is called while an element is being dragged, the drag will be effectively cancelled.

drake.addContainers( containers )

Method to add containers dynamicaly into drake initialised earlier.

drake.removeContainers( containers )

Method to remove containers dynamicaly from drake initialised earlier.

License

MIT

eyes.png

dragular's People

Contributors

aubm avatar eh-am avatar eoinsha avatar felippenardi avatar gduchemin avatar hyzual avatar januslo avatar luckylooke avatar maralmosayebi avatar mih-kopylov avatar orlandovallejos avatar stirelli avatar wezeolaky avatar ycintre avatar zakdances avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dragular's Issues

$element can't be injected as part of route change

Hi there,
Great work getting this going. The examples you show use ng-controller defined statically on the page. When used this way angular seems to have no trouble injecting in the $element dependency.

However when the controller is instantiated using angular route and associated with a partial view (like below) then the $element service just seems completely not injectable by angular. I suspect it isn't ready or available at the time the route change is being done.

  $routeProvider.
      when('/Calculator', {
          templateUrl: uriUtility.getAbsoluteUri('PartialViews/Calculator.html'),
          controller: 'calcEngineController'
      }).

Do you have any ideas to get around this?

Bad redraw on refill array of items

Use case: Put some items to dragular, than I get some changes back, what mean assign different array of items to dragular. For a second is showing item from both arrays. What am I doing wrong? I tried delete previous version of array, but without changes. Maybe bug in dragular?

In GIF are 2 items at first time, than I put one away by assign previous version of array. For a second there are 3 items - 2 from previous version and 1 from actual version.

dragular redraw list problem

How to re-initialize the dragularService? I keep running into error...

So in my Angular App, I have 2 drag container. I use this format to set them up:

     drakeObj = dragularService("#containerVideosDrag", {
    containersModel: admin.addedVideos,
    scope: $scope,
});
     drakeObj = dragularService("#containerSlidersDrag", {
    containersModel: admin.addedSliders,
    scope: $scope,
});

And the page need to load different elements inside the #containerVideosDrag and the #containerSlidersDrag container. So everything need to reset / re-initialize without a forced page refresh. I try to set
drakeObj.destroy();
OR
drakeObj = {}
OR
drakeObj.containers.dragularCommon.splice(0, 2);
OR
drakeObj.containers.dragularCommon = [];

But none of it works. So when load new element from the server and new content into the #containerVideosDrag and the #containerSlidersDrag container and drag again, this error show up:

angular.js:12477 TypeError: Cannot read property 'null' of null
at dragular.js:523
at Scope.$eval (angular.js:15989)
at $applyAsyncExpression (angular.js:16128)
at flushApplyAsync (angular.js:16381)
at Scope.$eval (angular.js:15989)
at Scope.$apply (angular.js:16089)
at angular.js:16392
at completeOutstandingRequest (angular.js:5507)
at angular.js:5784(anonymous function) @ angular.js:12477(anonymous function) @ angular.js:9246flushApplyAsync @ angular.js:16383Scope.$eval @ angular.js:15989Scope.$apply @ angular.js:16089(anonymous function) @ angular.js:16392completeOutstandingRequest @ angular.js:5507(anonymous function) @ angular.js:5784
dragular.js:582 Uncaught TypeError: Cannot read property 'parentElement' of null

Force refresh the page is the only way to reset dragularService now. Please help to clearly destroy all the dragularService without page refresh so I can reuse drakeObj = dragularService(...

cdn for production, locals for dev

Hi, @alferov, I'm on business trip now and I have very slow internet connection, which really slow downs development workflow loop due to CDN (bootstrap.min.css). Do you know some easy trick to switch CDNs to local sources in development and keep CDNs in production? :)

options for different container is not possible?

let me write an example, there are 2 containers (containerA, containerB), i want containerA with the "copy" option set to true so that this can just copy to containerB, but i want containerB to be set true in the "removeOnSpill" option so i can remove elements from this container, i have tried many ways but havent found a way to make this work, is there a way to do what i want or should i do a hack to do that?

Trying to create a destkop on dragula and angular2

Hey, sorry for writing you here.

I need some help, I'm trying to do a complicate drag&drop with angula 2 beta.9 and ng2-dragula which uses dragula.

Look at this not working example.
http://jsbin.com/yutifozini/edit?html,css,js,output

There are a menu with three sub-menus, they should not be draggable but droppable.

Than I have three big containers, this containers should be draggable and droppable each other and the container should be also draggable in the submenue

Each of the containers, contain four widgets, this widgets also I need to drag into the sub-menu, so it should be droppable into sub-menu but not draggable each other.

I'm trying to make a normal desktop behaviour in the browser, and I will store my widgets into the Menus by simple drag&drop it into the Menu. Also i need to Drag&Drop the big container into a Menu, but also I need to change position of the containers in my view. Doing this with dragula is a thrill!

I hope I was able to explain it, du you think I can do something like that with your lib. If it works I'll wrap it into an angular2 lib.

thx
Michael

Feature wanted: Multiple namespaces for a group

I'll need that a group could belong to more then one namespace.

Imagine that we have fruits, vegetables and meat groups, then an apple must be dropped into the fruits or into the vegetables group.

Dragular and iFrame

I trying to drop dragular elements in a iFrame but no works. Do you know if is possible or maybe you have a example link?

Best regards

Filtered Model not copied to target Model

Hi, thanks for your awesome adaptation of dragula to angular, I love it!

I'm trying to copy the data from a filtered ng-repeat model to a target model, but it doesn't works, only I have a copy of the ng-repeat node in the target zone, and the target model empty. I don't know if I'm doing something wrong or I missing something in the docs.

Can you take a quick look to this simple example please?
http://plnkr.co/edit/78NX5QDpbMTklVzdAdap?p=preview

Best regards.

copy option breaks model bindings

When using options.copy, the model is being copied via angular.copy (https://github.com/luckylooke/dragular/blob/master/src/dragularService.js#L532).

        $rootScope.$applyAsync(function applyDrop() {
          if (target === shared.source) {
            shared.sourceModel.splice(dropIndex, 0, shared.sourceModel.splice(shared.initialIndex, 1)[0]);
          } else {
            shared.dropElmModel = shared.copy ? angular.copy(shared.sourceModel[shared.initialIndex]) : shared.sourceModel[shared.initialIndex];

            if (!shared.tempModel) {
              shared.targetModel = shared.targetCtx.m;
            } else {
              shared.targetModel = shared.tempModel;

Is this intentional or a known issue?

The problem is that this breaks scope binding. E.g. when editing the "original" model, the copied model (that has been dropped into a different container) is not being updated.

Observation

I believe there should be some kind of html usage reference/example for this component.

Can't make it work on tablet

Below is my set up. It works fine on desktop, but when I try the dragging on tablet mode, it doesn't do anything. Is there something I need to do?

<div ng-controller="testCtrl">
    <div class="test">
         <div class="drag">TEST</div>
    </div>
</div>
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'infinite-scroll', 'ui.bootstrap', 'uiSlider','dragularModule']);

app.controller('testCtrl', function ($scope, dragularService, $timeout, $interval, $rootScope) {
    dragularService.cleanEnviroment();
    dragularService('.test', {
        scope: $scope
    });
});

Moving api&docs from readme.md to gh-pages

I like how some libs have api and examples coupled in one place. Like for example Angular have after each api documentation one or few examples on same topics. I would like to have same concept for dragular so I have created new gh-pages. I am looking for some help with creating it. Anybody wants to help?

Deploy:docs config bug (@alferov)

Hi @alferov!
I have fixed landing page for docs in exampleRouter.js, but file is loading from home/alferov/www/dragular, I think it is just matter of config, could you fix it please? Thanks ;)

Get sort order index

A feature of dragular is that: it "Figures out sort order on its own". Is there any way to get the variables based on which the order is determined?
I need it because I save object positions in my database.
Thank you.

How I can disable Dragular?

I'm triyng to disable dragular with a chekbox with the aiming to modify the target content, but when the disable flag is on, the source and target drag still working but no drop. And on target model If I have more than one element, I can drop the elements only to the latest slot.

Is there any flag on dragularService for a safe disable?

You can see this example on:

` /*** SET VARS AND DRAGULAR SERVICES WHEN DATA ARE READY ****/

    MagicMailResource.query(function(res) {
        $scope.categories = res[0].categories;
        $scope.apiElements = res[0].elements;

        dragularService.cleanEnviroment();
        // Asignamos a esta etiqueta el comportamiento y origen de datos
        dragularService(dragZone, {
            //move only from left to right
            containersModel: $scope.apiElements,
            containersFilteredModel: $scope.filteredItems,
            copy: true,
            accepts: accepts
        });

        // Esta etiqueta asígna el modelo de datos vacío y la funcción de control
        dragularService(dropZone, {
            //move only from left to right
            containersModel: $scope.emailElements,
            accepts: accepts
        });
    });`

Cannot sync with model when the model is filled by a promise

Hi !

I'm having an issue when using dragular v3.2.0. I have a model array, say test_model that is filled asynchronously using a promise ($q). I want each item of this array to be draggable with dragular with the option containersModel: test_model , but it seems that in this configuration every time I drop an item, it disappears and the javascript model is not updated.

Here is a plunker that shows the issue : http://plnkr.co/edit/ksLE1T7gVovoWrWnBwfp?p=preview

If you try to edit it, you'll notice that if test_model is defined directly without using a promise, it works as expected.

I would very much like to see this issue resolved as it seems to be the only thing stopping us from replacing our current (slow) javascript drag'n'drop library with dragular.

Let me know if there is anything I can do to help.

Nested ngRepeat - with model is not working

I'm using AngularJS v.1.4.3 + Dragular v. 3.2.0.

Nested ngRepeat works fine instead of Nested ngRepeat - with model

The problem is:
My cells / rows are not draggable. There are not errors in console. I've debugged the code and all obj are initialized fine.

CSS-File invalid in v4.0.0

Your css file looks like this

.gu-mirror {
position: fixed !important;
margin: 0 !important;
width: z-index 9999 !important;
opacity: 0.8;
}
[...]

The line 'width: z-index 9999 !important;' is invalid due to 'width: z-index'

commonjs syntax for webpack

hi, your library is cool but at the time of importing it through webpack I got this message

WARNING in .//dragular/dist/dragular.min.js
Critical dependencies:
1:113-120 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
@ ./
/dragular/dist/dragular.min.js 1:113-120

maybe an index.js pointing to a simple clean concatenated file will be more confortable :)

like angular

tree structure

hi, well, this is an opinion on what about a tree structure, I'll be great if dragular could have this kind of feature, I found an example but I think isn't friendly to use.

http://angular-ui-tree.github.io/angular-ui-tree/#/basic-example

maybe dragular can Improve that area.

also it lacks of 'controller aliasing', so there a bunch of $scopes round there

they implement this.scope = $scope

Preserve ng-click events

I have a use case where I'd like to preserve the ng-click event on a draggable container, however Dragular seems to disable this unless the element is an anchor or a button. This doesn't satisfy my use case because I want to be able to click anywhere on the element to trigger the ng-click event, and allow the user to drag from anywhere inside the element as well. Any suggestions?

screen shot 2015-07-24 at 8 33 56 am

Version mismatch

When I install dragular via bower:
$ bower install dragular -save

A warning is displayed:
bower mismatch Version declared in the json (2.0.1) is different than the resolved one (2.1.0)

Changing model values when dragging

Hello Lucklooke, thanks for this wonderful project.

I have a question regarding the usage of this. I implemented drag and drop with this project in angular. My question is :- I am using a list of objects as my model, which I set in the div using ng-repeat. When I drag an item o another div, is it possible to change/modify some property of the object that I dragged ?

I tried ways to get the model of the moving object, but failed. Hope someone have found a solution for this.

element nesting makes wrong behavior

let me explain, if i do something like this :

<div ng-controller="exampleCtrl">
      <div id='left1' class='container'>
        <div>Move me, but you can only drop me in one of these containers.</div>
        <div>If you try to drop me somewhere other than these containers, I'll just come back.</div>
        <div>Item 3.</div>
        <div>Item 6.</div>
      </div>
      <div id='right1' class='container'>
        <div>You can drop me in the left container, otherwise I'll stay here.</div>
        <div>Item 4.</div>
        <div>Item 5.</div>
      </div>    
</div>```

This is gonna work as espected, taking the items inside containers but if i do this:
```html 
<div ng-controller="exampleCtrl">
   <div class="anotherdiv">
      <div id='left1' class='container'>
        <div>Move me, but you can only drop me in one of these containers.</div>
        <div>If you try to drop me somewhere other than these containers, I'll just come back.</div>
        <div>Item 3.</div>
        <div>Item 6.</div>
      </div>
      <div id='right1' class='container'>
        <div>You can drop me in the left container, otherwise I'll stay here.</div>
        <div>Item 4.</div>
        <div>Item 5.</div>
      </div>
   </div>
</div>```

is not gonna work as expected just cause the parent div of the containers is not the same that the one that contains the ng-controller.

Get a reference to drake when using the directive

Hi,

In our application we want to cancel drag and drop using the 'ESC' key. We made our own directive for that purpose but it forced us to change from using the dragular directive to the dragular service. We had to do this because the only way to get the drake object is through the dragular service. It causes other problems (dealing with init of the dragular service, etc).
We would like to have a way to get a hold of the drake created when using the dragular directive.
I don't think I'll have time to make a PR soon, anyway my first idea would be to add an isolate scope to the directive with a property or function returning the drake object reference that the directive would update.
Something like that:

scope: {
    drake: '=dragularDrake'
}

We could then attach it to the model:

<ul dragular dragular-drake="vm.drake"></ul>

What do you think about it ?

use model reference instead of DOM index

I think it would be a good idea to reference the model data directly, rather than an index from the DOM, which will take care of issues like reference mismatches in filtered lists, as well as being able to reference the model data when events are emitted. I haven't really thought about implementation, just making the suggestion at this stage. Are you still actively maintaining this @luckylooke, or have you shifted focus to Nicolas' angular-dragula? The API for dragular seems much sane-r than angular-dragula, I kinda prefer dragular to be honest 😸

Drop items into a non-list container

I need to drop items from a list into a non-list container without any shadow and sorting within the target container. It should work like here. Just pick any element and drop it into the trashcan.
Is it possible to achieve this functionality with dragular?
Thanks!

Tests

Hi, are you planning to write tests?

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.