Hi, I am a London and Berlin-based freelance web developer doing stuff like HTML,
CSS, Javascript (jQuery), PHP (Zend Framework, Concrete5, Typo3... more
Logo Twitter

Geek Tweet

doing that @BU_ev thing tomorrow in case anybody wants to join :)

Tweeted on May 18th 2012 - 22:21

Follow me @nerdess for 100% geekness.

jQuery: MoveAndRemove Plugin

Last updated: April 2012

What does it do?

Provides the ability to move items up and down or left and right. Optionally items can also be removed.

Useful to implement a sorting facility when you think your users will quite likely be overwhelmed with drag-and-drop sorting ;-)

Examples

Vertical sorting (unordered list)

Order these fruits so your favourite one comes first.

  • Apples

    apples
  • Bananas

    bananas
  • Oranges

    oranges
  • Strawberries

    strawberries
        /*Vertical sorting (default setting)*/
        $('ul#sortVertical').moveAndRemove();

Horizontal sorting + deleting

Move the fruits left or right.
If you don't like one you can also delete it.

  • Apples

    apples
  • Bananas

    bananas
  • Oranges

    oranges
  • Strawberries

    strawberries
        /*Horizontal sorting + deleting*/
        $('ul#sortHorizontal').moveAndRemove({
            mode: 'horizontal',
            showDelete: true,
            canDeleteLast: true
        });
    

Documentation

Options

elArrowUp
elArrowDown
elArrowLeft
elArrowRight
elDelete
  • HTML elements that gets inserted for the various arrows and the optional delete button..
  • type:string (html element)
  • default:For elArrowUp for example it is 'Move up'. For the other elements it's a similar chuck of HTML.
showDelete
  • Determines whether "delete" icon should be shown.
  • type:boolean
  • default:false
mode
  • Triggers horizonal or vertical arrow-styles.
  • type:string
  • default:vertical
  • options:'vertical', 'horizontal'
swapClasses
  • Swaps the classes of the items who change positions. Useful e.g. to preserve the zebra-stripyness of an item collection.
  • type:boolean
  • default:true
canDeleteLast
  • If showDelete = true this option makes it possible to delete all items, even the last one.
  • type:boolean
  • default:false
setZebraStripes
  • Automatically adds the classes odd/even to an item collection so it can be styled in cute zebra stripes
  • type:boolean
  • default:false

Events

afterMove
  • Gets triggered after an item is moved
  • type:function
  • default:empty function that does nothing
afterDelete
  • Gets triggered after an item is deleted
  • type:function
  • default:empty function that does nothing

Download

Grab the latest version of the jQuery MoveAndRemove plugin on GitHub.

Todo's

  • Refactoring code as it is a bit clumsy
  • Finish moving table rows/columns feature
  • Adding more hooks to customize it
blog comments powered by Disqus