angular-dragula

WebJar for angular-dragula

License

License

MIT
Categories

Categories

Github Development Tools Version Controls Angular User Interface Web Frameworks
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

github-com-bevacqua-angular-dragula
Last Version

Last Version

1.2.8
Release Date

Release Date

Type

Type

jar
Description

Description

angular-dragula
WebJar for angular-dragula
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/bevacqua/angular-dragula

Download github-com-bevacqua-angular-dragula

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/github-com-bevacqua-angular-dragula/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>github-com-bevacqua-angular-dragula</artifactId>
    <version>1.2.8</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/github-com-bevacqua-angular-dragula/
implementation 'org.webjars.bower:github-com-bevacqua-angular-dragula:1.2.8'
// https://jarcasting.com/artifacts/org.webjars.bower/github-com-bevacqua-angular-dragula/
implementation ("org.webjars.bower:github-com-bevacqua-angular-dragula:1.2.8")
'org.webjars.bower:github-com-bevacqua-angular-dragula:jar:1.2.8'
<dependency org="org.webjars.bower" name="github-com-bevacqua-angular-dragula" rev="1.2.8">
  <artifact name="github-com-bevacqua-angular-dragula" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='github-com-bevacqua-angular-dragula', version='1.2.8')
)
libraryDependencies += "org.webjars.bower" % "github-com-bevacqua-angular-dragula" % "1.2.8"
[org.webjars.bower/github-com-bevacqua-angular-dragula "1.2.8"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

logo.png

Drag and drop so simple it hurts

Official Angular wrapper for dragula.

Demo

demo.png

Try out the demo!

Install

You can get it on npm.

npm install angularjs-dragula --save

Or bower, too.

bower install angularjs-dragula --save

Setup

You'll need to pass in angularDragula to your module when booting up your application. angularjs-dragula takes your angular instance and uses it to register its own module, service, and directive.

var angular = require('angular');
var angularDragula = require('angularjs-dragula');

var app = angular.module('my-app', [angularDragula(angular)]);

Usage

This package isn't very different from dragula itself. I'll mark the differences here, but please refer to the documentation for dragula if you need to learn more about dragula itself.

Directive

There's a dragula directive (as seen in the demo) that allows you to group containers together, as long as they belong to the same scope. That grouping of containers is called a bag.

<div dragula='"bag-one"'></div>
<div dragula='"bag-one"'></div>
<div dragula='"bag-two"'></div>

dragula-scope

ng-repeat creates a new isolate scope, which can sometimes cause issues with dragging between a bag with multiple containers. To avoid this you can pass in the scope you want the bag to be stored on (and fire events on) by setting the dragula-scope directive on the bag element.

<ul ng-controller="ItemsController">
  <li ng-repeat="item in items" dragula='"bag-one"' dragula-scope="$parent"></li>
</ul>

dragula-model

If your ng-repeat is compiled from array, you may wish to have it synced. For that purpose you need to provide model by setting the dragula-model attribute on the bag element

<ul ng-controller="ItemsController">
  <li ng-repeat="item in items" dragula='"bag-one"' dragula-model="items"></li>
</ul>

The standard drop event is fired before the model is synced. For that purpose you need to use the drop-model event. The same behavior exists in the remove event. Therefore is the remove-model event. Further details are available under Events

drake options

If you need to configure the drake (there's only one drake per bag), you'll have to use the dragulaService.

app.controller('ExampleCtrl', ['$scope', 'dragulaService',
  function ($scope, dragulaService) {
    dragulaService.options($scope, 'third-bag', {
      removeOnSpill: true
    });
  }
]);

Events

Whenever a drake instance created with the dragula directive emits an event, that event is replicated on the Angular $scope where the drake has an associated bag, and prefixed with the name on its bag.

<div dragula='"evented-bag"'></div>
app.controller('ExampleCtrl', ['$scope', function ($scope) {
  $scope
    .$on('evented-bag.over', function (e, el) {
      el.addClass('over');
    })
    .$on('evented-bag.out', function (e, el) {
      el.removeClass('over');
    });
]);

Note that these derived events don't expose the DOM elements directly. The elements get wrapped in angular.element calls.

Special Events for angularjs-dragula

Event Name Listener Arguments Event Description
drop-model el, target, source same as normal drop, but model was synced, just available with the use of dragula-model
remove-model el, container same as normal remove, but model was synced, just available with the use of dragula-model

dragulaService

This service exposes a few different methods with which you can interact with dragula in the Angular way.

dragulaService.add(scope, name, drake)

Creates a bag scoped under scope and identified by name. You should provide the entire drake instance. Typically, the directive takes care of this step.

dragulaService.options(scope, name, options)

Sets the options used to instantiate a drake. Refer to the documentation for dragula to learn more about the options themselves.

dragulaService.find(scope, name)

Returns the bag for a drake instance. Contains the following properties.

  • name is the name that identifies the bag under scope
  • drake is the raw drake instance itself

dragulaService.destroy(scope, name)

Destroys a drake instance named name scoped under scope.

License

MIT

Versions

Version
1.2.8