GithubHelp home page GithubHelp logo

kshutkin / drag_n_drop Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 17 KB

AngularJS 1.x Drag and Drop directives (jQuery UI)

License: MIT License

JavaScript 85.41% CSS 1.65% HTML 12.94%
angularjs drag-and-drop jquery

drag_n_drop's Introduction

AngularJS 1.x Drag and Drop directives (jQuery UI)

Demo:

Features:

  • Support all features of jQuery UI draggable and droppable
  • Easy configuration global and per element
  • Small code size (if you already use jQuery and jQuery UI in your project)

Get Started:

(1) Install using bower

bower install angular-drag-and-drop --save

(2) Include drag_n_drop.js in your index.html, after including jQuery, jQuery UI and Angular (you can skip this if you use something like wiredep)

<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/jqueryui/jquery-ui.js"></script>
<script src="bower_components/angular-drag-and-drop/drag_n_drop.js"></script>

(3) Add 'drag_n_drop' to your main module's list of dependencies

angular.module('myModuleName', ['drag_n_drop'])

How to use

Add dnd-draggable on element that you want to be able to drag:

<span dnd-draggable>I'm draggable!!</span>

Add dnd-droppable on element that you want to be able to accept draggable elements:

<div dnd-droppable on-drop="dropElement(draggableScope)"></div>

You can use draggableScope to access variables that defined on scope of dropped draggable element. Add implementation of the on-drop handler to your controller.

$scope.dropElement = function(draggableScope) {
    //do something here
};

dndDragAndDropConfigProvider

Can be used to pass the default global parameters for other directives.

angular.module('MyApp').config(['dndDragAndDropConfigProvider', function(dndDragAndDropConfigProvider) {
    dndDragAndDropConfigProvider.setGlobalDroppableOptions({
        //parameters here (see options for dnd-droppable)
    });
    
    dndDragAndDropConfigProvider.setGlobalDraggableOptions({
        //parameters here (see options for dnd-draggable)
    });
}]);

dnd-draggable directive

Marks element as draggable.

Can have additional options in config object:

<div dnd-draggable="options"></div>

"options" can be defined on scope or inside html.

Next options is supported according to the jQuery UI 1.11.4 documentation

You can use watchOptions property to provide array of options that will be watched using $scope.$watch. Corresponding properties have to be strings with watch expressions.

You can also setup next handlers on-create, on-drag, on-start and on-stop. Example:

<div dnd-draggable on-start="startDrag($event, draggableScope)"></div>

In each handler you can use $event object and draggableScope object(probably useless in this case).

dnd-droppable directive

Marks element as area to drop draggable elements.

Can have additional options in config object:

<div dnd-droppable="options"></div>

"options" can be defined on scope or inside html.

Next options is supported according to the jQuery UI 1.11.4 documentation

Next handlers can be setup:

In all handlers except accept handler you can use draggableScope, droppableScope and $event. In accept handler only draggableScope and droppableScope are available. Accept handler must return true if draggable should be accepted.

watchOptions should work the same way as for dnd-draggable directive.

Bug reports, tests and PRs are welcome

drag_n_drop's People

Contributors

kshutkin avatar

Stargazers

 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.