Coder Social home page Coder Social logo

eric013 / angular-dragula Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bevacqua/angularjs-dragula

0.0 3.0 0.0 846 KB

:ok_hand: Drag and drop so simple it hurts

Home Page: http://bevacqua.github.io/angular-dragula

License: MIT License

CSS 16.85% JavaScript 19.39% HTML 63.76%

angular-dragula's Introduction

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 angular-dragula --save

Or bower, too. (note that it's called angular-dragula.js in bower)

bower install angular-dragula.js --save

Setup

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

var angular = require('angular');
var angularDragula = require('angular-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>

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.

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

angular-dragula's People

Contributors

bevacqua avatar

Watchers

 avatar  avatar  avatar

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.