GithubHelp home page GithubHelp logo

tomchiverton / angular-drag-to-reorder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brandly/angular-drag-to-reorder

0.0 1.0 0.0 18 KB

:fist: Drag items in an ng-repeat to reorder them

Home Page: http://brandly.github.io/angular-drag-to-reorder/

License: MIT License

JavaScript 39.29% CoffeeScript 60.71%

angular-drag-to-reorder's Introduction

Angular Drag to Reorder

Drag items in an ng-repeat to reorder them

$ bower install --save angular-drag-to-reorder

I wrote this for another small project, and I figured someone else might find it useful. It's probably far less stable than something like UI Sortable, but that has all kinds of dependencies. This just needs Angular.

There aren't many frills, but it seems to do the job in up-to-date browsers.

But how?

Add drag-to-reorder alongside your ng-repeat and specify the name of the collection.

<ul>
  <li ng-repeat="item in list" drag-to-reorder="list"></li>
</ul>

And it should Just Work�.

What else?

Classes

When dragging and dropping elements, some classes will be added to those elements, so you can style accordingly.

The element being dragged will have a dragging class on it.

The element that is being hovered over by a dragged element will have a dropping class. More specifically, you'll see a dropping-above or dropping-below class on there, depending on where the dragged element will end up after being dropped.

Events

There's just one. When the list gets reordered, dragToReorder.reordered will fire, passing you some relevant data.

$scope.$on('dragToReorder.reordered', function ($event, reordered) {
  // The list being reordered
  reordered.array

  // The item that was relocated
  reordered.item

  // The initial index of that item
  reordered.from

  // The index where it ended up
  reordered.to
});

Demo

Look!

Development

Get your dependencies

$ npm install

And use gulp to build, watch, and host the project.

$ gulp

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.