Giter Club home page Giter Club logo

ngrepeatreorder's Introduction

ngRepeatReorder

Drag and Drop reordering for AngularJS Repeat.

Requirements

ngRepeatReorder requires angular-hammer and hammer.js

Install Instructions.

Either use bower install ngRepeatReorder or download from the github repository at http://github.com/SimeonC/ngRepeatReorder.

Include ngRepeatReorder.js, hammer.js and angular-hammer.js as a script in your html file.

Include ngRepeatReorder in your module, e.g. angular.module("myAppName", ['ngRepeatReorder'])

In your HTML you need to define two attributes, the first is ng-repeat-reorder this functions EXACTLY like AngularJS' native ng-repeat directive. The second attribute is ng-repeat-reorder-handle, this is a selector handle that is restricted by what you have loaded, ie if no jQuery then select by tag name only (internally uses .find for the curious). This attribute should select the element that you want to use as a "drag handle", if you leave this blank it uses the node you define it on.

You will need to mess around with CSS to get it to work correctly, see the demo for examples.

How It Works

In short this works by starting with the ngRepeat code in angular.js. Which in itself is complex as you have to also copy over a bunch of functions that it uses that are hidden elsewhere in the codebase. Then you add all the lovely complexity of moving elements around – I decided to simplify this by limiting the movement within the list bounds and only do vertical re-ordering. I animate this by fiddling with the margins – creating a gap where the ‘dragged’ element is going to drop into and then using +/- margins to position the dragging element correctly. Also we add in classes for display purposes.

The last hurdle I had to overcome is to modify the ngRepeat element before our modified ngRepeat compiles the element, I did this with a second directive that executes before the ngRepeat and adds the event tags onto the element.

Example

CodePen

Licence

Copyright (c) 2014 SimeonC, MIT

ngrepeatreorder's People

Contributors

mayrop avatar notatestuser avatar tombyrer avatar

Watchers

 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.