Ver Mensaje Individual
  #3 (permalink)  
Antiguo 28/05/2009, 08:39
c3sar0n
 
Fecha de Ingreso: mayo-2009
Mensajes: 9
Antigüedad: 17 años, 5 meses
Puntos: 0
Respuesta: Guardar orden despues de hacer Drag and Drop de divs

AKI la ultima de las librerias ui.sortable.js

Código PHP:
((function($) {

    if (
window.Node && Node.prototype && !Node.prototype.contains) {
        
Node.prototype.contains = function (arg) {
            return !!(
this.compareDocumentPosition(arg) & 16);
        };
    }

    $.
fn.extend({
        
sortable: function(options) {
            
            var 
args = Array.prototype.slice.call(arguments, 1);
            
            if ( 
options == "serialize" )
                return $.
data(this[0], "ui-sortable").serialize(arguments[1]);
            
            return 
this.each(function() {
                if (
typeof options == "string") {
                    var 
sort = $.data(this, "ui-sortable");
                    
sort[options].apply(sort, args);

                } else if(!$.
data(this, "ui-sortable"))
                    new $.
ui.sortable(this, options);
            });
            
            
            
alert("Aki esta el Drag xD");
        }
            
    });
    
    
    $.
ui.sortable = function(element, options) {
        
//Initialize needed constants
        
var self = this;
        
        
this.element = $(element);
        
        $.
data(element, "ui-sortable", this);
        
this.element.addClass("ui-sortable");

        
//Prepare the passed options
        
this.options = $.extend({}, options);
        var 
o = this.options;
        $.
extend(o, {
            
items: this.options.items || '> *',
            
zIndex: this.options.zIndex || 1000,
            
startCondition: function() {
                return !
self.disabled;    
            }        
        });
        
        $(
element).bind("setData.sortable", function(event, key, value){
            
self.options[key] = value;
        }).
bind("getData.sortable", function(event, key){
            return 
self.options[key];
        });
        
        
//Get the items
        
this.refresh();

        
//Let's determine if the items are floating
        
this.floating = /left|right/.test(this.items[0].item.css('float'));
        
        
//Let's determine the parent's offset
        
if(!(/(relative|absolute|fixed)/).test(this.element.css('position'))) this.element.css('position', 'relative');
        
this.offset = this.element.offset({ border: false });

        
//Initialize mouse events for interaction
        
this.element.mouseInteraction({
            
executor: this,
            
delay: o.delay,
            
distance: o.distance || 0,
            
dragPrevention: o.prevention ? o.prevention.toLowerCase().split(',') : ['input','textarea','button','select','option'],
            
start: this.start,
            
stop: this.stop,
            
drag: this.drag,
            
condition: function(e) {

                if(
this.disabled) return false;

                
//Find out if the clicked node (or one of its parents) is a actual item in this.items
                
var currentItem = null, nodes = $(e.target).parents().andSelf().each(function() {
                    if($.
data(this, 'ui-sortable-item')) currentItem = $(this);
                });
                if(
currentItem && (!this.options.handle || $(e.target).parents().andSelf().is(this.options.handle))) {
                    
this.currentItem = currentItem;
                    return 
true;
                } else return 
false; 

            }
        });

    };
    
    $.
extend($.ui.sortable.prototype, {
        
plugins: {},
        
ui: function() {
            return {
                
helper: this.helper,
                
placeholder: this.placeholder || $([]),
                
position: this.position,
                
absolutePosition: this.positionAbs,
                
instance: this,
                
options: this.options
            
};        
        },
        
propagate: function(n,e) {
            $.
ui.plugin.call(this, n, [e, this.ui()]);
            
this.element.triggerHandler(n == "sort" ? n : "sort"+n, [e, this.ui()], this.options[n]);
        },
        
serialize: function(o) {
            
            var 
items = $(this.options.items, this.element).not('.ui-sortable-helper'); //Only the items of the sortable itself
            
var str = [];
            
o = o || {};
            
            
items.each(function() {
                var 
res = (this.getAttribute(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
                if(
res) str.push((o.key || res[1])+'[]='+(o.key ? res[1] : res[2]));                
            });
            
            return 
str.join('&');
            
        },
        
intersectsWith: function(item) {
            
            var 
x1 = this.positionAbs.left, x2 = x1 + this.helperProportions.width,
                
y1 = this.positionAbs.top, y2 = y1 + this.helperProportions.height;
            var 
l = item.left, r = l + item.width, 
                
t = item.top,  b = t + item.height;
            
            return (   
l < x1 + (this.helperProportions.width  / 2)        // Right Half
                
&&     x2 - (this.helperProportions.width  / 2) < r    // Left Half
                
&& t < y1 + (this.helperProportions.height / 2)        // Bottom Half
                
&&     y2 - (this.helperProportions.height / 2) < b ); // Top Half
            
        
},