# jquery.shapeshift
**Repository Path**: mirrors_leecade/jquery.shapeshift
## Basic Information
- **Project Name**: jquery.shapeshift
- **Description**: A dynamic grid system with drag and drop functionality.
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-09
- **Last Updated**: 2026-02-07
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
Shapeshift v2.0
===============
[Check out a demo here.](http://mcpants.github.com/jquery.shapeshift/)
**April 16th, 2013: Version 2.0 released.**
**There may be bugs and we are still browser testing. Please report any bugs you find through issues.**
Column Grid System + Drag and Drop
----------------------------------
Inspired heavily by the [jQuery Masonry plugin](http://masonry.desandro.com/), Shapeshift is a plugin which will dynamically arrange a collection of elements into a column grid system similar to [Pinterest](http://www.pinterest.com). What sets it apart is the ability to drag and drop items within the grid while still maintaining a logical index position for each item. This allows for the grid to be rendered exactly the same every time Shapeshift is used, as long as the child elements are in the correct order.
Features
--------
* **Drag and Drop**
Rearrange items within a container or even drag items between multiple Shapeshift enabled containers. Dragging elements around will physically change their index position within their parent container. When a page reloads, as long as the child elements are placed in the correct order then the grid will look exactly the same.
* **Works on Touch Devices**
Shapeshift uses jQuery UI Draggable/Droppable for help with the drag and drop system. Luckily there is already a plugin called [jQuery Touch Punch](http://touchpunch.furf.com/) which provides touch support for jQuery UI D/D. It can be found in the vendor folder.
* **Multiwidth Elements**
A new feature in 2.0 is the ability to add elements that can span across multiple columns as long as their width is correctly set through CSS.
* **Responsive Grid**
Enabled by default, Shapeshift will listen for window resize events and arrange the elements within it according to the space provided by their parent container.
Credits
-------
A big thanks to all of our [contributors](https://github.com/McPants/jquery.shapeshift/graphs/contributors)!

Shapeshift is maintained by [We The Media, inc.](http://wtmworldwide.com/)
Sites Using Shapeshift
----------------------
Got a project that you are using shapeshift on? Let us know and we will happily throw a link to your page here!
Index
-----
1. [Getting Started](#getting-started)
* [Dependencies](#dependencies)
* [Setting up the Parent Container](#setting-up-the-parent-container)
* [Setting up the Child Elements](#setting-up-the-child-elements)
* [Multiwidth Elements](#multiwidth-elements)
2. [Shapeshift Options](#shapeshift-options)
* [The Basics](#the-basics)
* [Extra Features](#extra-features)
* [Grid Properties](#grid-properties)
* [Animation Settings](#animation-settings)
* [Drag and Drop Settings](#drag-and-drop-settings)
* [Customize CSS](#customize-css)
3. [Detecting Changes](#detecting-changes)
* [Event Listening Examples](#event-listening-examples)
4. [Triggering a Rearrange](#triggering-a-rearrange)
5. [Destroying Shapeshift](#destroying-shapeshift)
6. [For Contributors](#for-contributors)
Getting Started
---------------
### Dependencies
Shapeshift requires the latest version of jQuery, and drag and drop feature (enabled by default) requires jQuery UI Draggable/Droppable libraries. It also requires [jQuery Touch Punch](http://touchpunch.furf.com/) to work on touch devices.
### Setting Up the Parent Container
Shapeshift arranges child elements by absolutely positioning them in their parent container which must be set to "position: relative". The container does not have to be a div and can be substituted for any element that can have child elements, such as an unordered list. The container also must have a width specified.
###### HTML:
```html
| Option |
Description |
Acceptable Values |
Default |
| align |
Align / justify the grid. |
"left", "center", "right" |
"center" |
| colWidth |
Manually set the column width. Column width is automatically determined by Shapeshift, however it is required to be set if the container has no initial children to calculate it from. |
Any Integer >= 1 |
1 |
| columns |
Force the grid to have a specific number of columns. Setting this to null will automatically determine the maximum columns for the width of the container. |
Any Integer >= 1 |
null |
| minColumns |
This will prevent the grid from ever going below a set number of columns. If using multiwidth then this must be set to the highest colspan child element. |
Any Integer >= 1 |
1 |
| autoHeight |
Automatically sets the height of the container according to the height of the contents within it. If set to false, then the "height" option must also be specified. |
true, false |
true |
| maxHeight |
If "autoHeight" is turned on, maxHeight will never allow the container height to go above this number. |
Any Integer >= 1 |
null |
| minHeight |
If "autoHeight" is turned on, minHeight will never allow the container height to go below this number. |
Any Integer >= 1 |
100 |
| gutterX |
The number of pixels horizontally between each column. |
Any Integer >= 0 |
10 |
| gutterY |
The number of pixels vertically between each element. |
Any Integer >= 0 |
10 |
| paddingX |
Sets the horizontal padding of the grid between the left and right sides of the container. |
Any Integer >= 0 |
10 |
| paddingY |
Sets the vertical padding of the grid between the top and bottom sides of the container. |
Any Integer >= 0 |
10 |
### Animation Settings
| Option |
Description |
Acceptable Values |
Default |
| dragClone |
When an element is dragged it will create a clone instead. |
true, false |
false |
| deleteClone |
If a cloned item is dropped into its original container, delete the clone that was made. |
true, false |
true |
| dragRate |
The number of milliseconds that Shapeshift will attempt to find a target pisition for a dragged item. |
Any Integer >= 0 |
100 |
| dragRate |
The number of milliseconds that Shapeshift will attempt to find a target pisition for a dragged item. |
Any Integer >= 0 |
100 |
| dragWhitelist |
A CSS selector specifying the elements which can be dragged. |
Any CSS selector, such as ".river" or "#song" |
"*" |
| crossDropWhitelist |
A CSS selector specifying the elements which can be dropped into this container from *other* containers. |
Any CSS selector, such as ".martha" or "#jones" |
"*" |
| cutoffStart |
Items cannot be dragged to an index position below this number. |
Any Integer >= 0 |
null |
| cutoffEnd |
Items cannot be dragged to an index position past this number. |
Any Integer >= 0 |
null |
| handle |
If specified, restricts dragging from starting unless the mousedown occurs on the specified element(s). |
Any CSS selector, such as ".jack" or "#harkness" |
false |
### Customize CSS
Certain elements will have CSS classes attached to them for specific events. Customize those CSS classes if needed.
| Option |
Affected Element |
Description |
Default |
| activeClass |
Child Elements |
Every active Shapeshift child item will have this class applied to them. |
ss-active-child |
| cloneClass |
Cloned Child Element |
If the "dragClone" option is used, this is the CSS class applied to the clone that is created. |
ss-cloned-child |
| draggedClass |
Dragged Child Element |
The class applied to an element while it is being dragged. |
ss-dragged-child |
| placeholderClass |
Placeholder Element |
When an item is dragged, a placeholder element is created to show the new target position. |
ss-placeholder-child |
| originalContainerClass |
Container Element |
When an item is dragged, this is the class applied to the container it originated from. |
ss-original-container |
| currentContainerClass |
Container Element |
When an item is dragged, this is the class applied to the container it currently is in. |
ss-current-container |
| previousContainerClass |
Container Element |
When an item is dragged between containers, this is the class applied to the container it was previously in. |
ss-previous-container |
### Detecting Changes
Changes to the grid will trigger several different events on the container element and important objects will be returned with it. Here are a list of events that can be listened to, with some examples following.
| Event Name |
Triggered When |
Triggered On |
Variables Returned |
| ss-rearranged |
When an item is dropped into the container it originated from. |
original container element |
selected element |
| ss-removed |
When an item is dropped into a container it didn't originate from. |
original container element |
selected element |
| ss-added |
When an item is dropped into a container it didn't originate from. |
new container element |
selected element |
| ss-trashed |
When an item is dropped into a container that has trash enabled and therefore is removed from the DOM. |
trash enabled container element |
selected element |
| ss-drop-complete |
When an item is dropped into a container, this gets called when it has stopped moving to its new position. |
new container element |
none |
| ss-arranged |
When an item is dragged around in a container, arranged is triggered every time items are shifted. |
current container element |
none |
#### Event Listening Examples
When an item has begun being dragged, it will trigger the "ss-event-dragged" on the container element. You can then write out some code to be fired off when that event occurs. The object that was just selected is also passed back to you. For example,
```coffeescript
$containers = $(".ss-container")
$containers.on "ss-rearranged", (e, selected) ->
console.log "This container:", $(this)
console.log "Has rearranged this item:", $(selected)
console.log "Into this position:", $(selected).index()
$containers.on "ss-removed", (e, selected) ->
console.log "This item:", $(selected)
console.log "Has been removed from this container:", $(this)
$containers.on "ss-added", (e, selected) ->
console.log "This item:", $(selected)
console.log "Has been added to this container:", $(this)
$containers.on "ss-trashed", (e, selected) ->
console.log "This item:", $(selected)
console.log "Has been removed from the DOM"
$containers.on "ss-drop-complete", (e) ->
console.log "This container:", $(this)
console.log "Has finished rearrangement after a drop."
$containers.on "ss-arranged", (e) ->
console.log "This container:", $(this)
console.log "Has just rearranged items but no drop has occurred."
```
### Triggering a Rearrange
If you add, remove, hide, or show elements through your own code then you may need to rearrange the items into their new positions. Triggering "ss-rearrange" on the target container will do so.
```coffeescript
$(".ss-container").trigger("ss-rearrange")
```
### Destroying Shapeshift
Simply trigger the event "ss-destroy" on the container.
```coffeescript
$(".ss-container").trigger("ss-destroy")
```
## For Contributors
Feel like you've got an idea on how to optimize the code and want to share it? We are totally open to new changes, however this is one of the first publically available plugins that I am offering and therefore do not have an exact process on pull requests. Feel free to fork the project all you want, but be aware any pull requests that are made may take a while to get implemented (if at all).