Skip to content

Instantly share code, notes, and snippets.

@collin
Created November 19, 2008 17:33
Show Gist options
  • Save collin/26604 to your computer and use it in GitHub Desktop.
Save collin/26604 to your computer and use it in GitHub Desktop.
,sortable: function(action, options) {
if(action == 'enable') {
console.log(this)
return this
.data('sortable', true)
.bind('dragstart.sortable', function() {
var _this = _(this);
var blank = _this.clone().css('visibility', 'hidden');
_this.before(blank);
_this.data('blank', blank);
_this.css('position', 'absolute');
_.dropManage(options);
return _this;
})
.bind('drag.sortable', function(e) {
_( e.dragProxy ).css({
top:e.offsetY
});
})
.bind('dragend.sortable', function(e) {
var _this = _( e.dragProxy );
_this.data('blank')
.before(_this)
.remove();
_this.css('position', '');
})
.bind('dropstart.sortable', function(e) {
var proxy = _(e.dragProxy);
var _this = _(e.dropTarget);
_this.before(proxy.data('blank'));
})
.bind('drop.sortable', function() {})
.bind('dropend.sortable', function(e) {
var proxy = _(e.dragProxy);
var _this = _(e.dropTarget);
if(_this.next().length) {} else {
_this.after(proxy.data('blank'));
}
});
}
else if (action == 'disable') {
return this
.data('sortable', null)
.unbind('dragstart.sortable')
.unbind('drag.sortable')
.unbind('dragend.sortable')
.unbind('dropstart.sortable')
.unbind('drop.sortable')
.unbind('dropend.sortable');
}
else if (action == 'toggle') {;
if(this.data('sortable'))
this.sortable('disable');
else
this.sortable('enable', options);
return this;
}
else if (action == 'serialize') {
var serial = [];
this.each(function() { serial.push(_(this).attr('class')); });
return serial;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment