Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Guardar orden despues de hacer Drag and Drop de divs

Estas en el tema de Guardar orden despues de hacer Drag and Drop de divs en el foro de Frameworks JS en Foros del Web. Hola... soy nuevito en esto de trabajar con ajax, me gusta y es una herramienta muy potente si se sabe manejar (osea no para mi ...
  #1 (permalink)  
Antiguo 28/05/2009, 08:33
 
Fecha de Ingreso: mayo-2009
Mensajes: 9
Antigüedad: 15 años
Puntos: 0
Pregunta Guardar orden despues de hacer Drag and Drop de divs

Hola... soy nuevito en esto de trabajar con ajax, me gusta y es una herramienta muy potente si se sabe manejar (osea no para mi =) ).

Tengo un administrador de tareas el cual guarda en una base de datos las tareas que tiene cada uno pendiente con sus respectivas prioridades.

El problema es...
al momento de imprimir en pantalla las tareas pendientes lo hago usando unas librerias que encontre por la web, las cuales permiten hacer drag and drop de lo q esta en pantalla. Encontre el punto en el cual se suelta el mouse y ahi es donde deberia..
"tomar el orden de las tareas en pantalla una vez q se cambiaron de lugar" para modificar en la base de datos las nuevas prioridades.
Si alguien tiene una leve idea de como hacerlo se lo agradezco

Adjunto las tres librerias que usa para hacer el drag and drop.

Código PHP:
(function($) {
    
    
//If the UI scope is not available, add it
    
$.ui = $.ui || {};
    
    
//Add methods that are vital for all mouse interaction stuff (plugin registering)
    
$.extend($.ui, {
        
plugin: {
            
add: function(moduleoptionset) {
                var 
proto = $.ui[module].prototype;
                for(var 
i in set) {
                    
proto.plugins[i] = proto.plugins[i] || [];
                    
proto.plugins[i].push([optionset[i]]);
                }
            },
            
call: function(instancenamearguments) {
                var 
set instance.plugins[name]; if(!set) return;
                for (var 
0set.lengthi++) {
                    if (
instance.options[set[i][0]]) set[i][1].apply(instance.elementarguments);
                }
            }    
        },
        
cssCache: {},
        
css: function(name) {
            if ($.
ui.cssCache[name]) return $.ui.cssCache[name];
            
            var 
tmp = $('<div class="ui-resizable-gen">').addClass(name).css(
                {
position:'absolute'top:'-5000px'left:'-5000px'display:'block'}
            ).
appendTo('body');
            
            
//Opera and Safari set width and height to 0px instead of auto
            //Safari returns rgba(0,0,0,0) when bgcolor is not set
            
$.ui.cssCache[name] = !!(
                ((/^[
1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) || 
                !(/
none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba(0000)/).test(tmp.css('backgroundColor')))
            );
            try { $(
'body').get(0).removeChild(tmp.get(0));    } catch(e){}
            return $.
ui.cssCache[name];
        },
        
disableSelection: function(e) {
            if (!
e) return;
            
e.unselectable "on";
            
e.onselectstart = function() {    return false; };
            if (
e.stylee.style.MozUserSelect "none";
        },
        
enableSelection: function(e) {
            if (!
e) return;
            
e.unselectable "off";
            
e.onselectstart = function() { return true; };
            if (
e.stylee.style.MozUserSelect "";
        }
    });
    
    
/*******************************************/
    
$.fn.extend({
        
mouseInteraction: function(o) {
            return 
this.each(function() {
                new $.
ui.mouseInteraction(thiso);
            });
        },
        
removeMouseInteraction: function(o) {
            return 
this.each(function() {
                if($.
data(this"ui-mouse"))
                    $.
data(this"ui-mouse").destroy();
            });
        }
    });
    
    
/*****************************/
    
    
$.ui.mouseInteraction = function(elementoptions) {
    
        var 
self this;
        
this.element element;
        $.
data(this.element"ui-mouse"this);
        
this.options = $.extend({}, options);
        
        $(
element).bind('mousedown.draggable', function() { return self.click.apply(selfarguments); });
        if($.
browser.msie) $(element).attr('unselectable''on'); //Prevent text selection in IE
        
    
};
    
    $.
extend($.ui.mouseInteraction.prototype, {
        
        
destroy: function() { $(this.element).unbind('mousedown.draggable'); },
        
trigger: function() { return this.click.apply(thisarguments); },
        
click: function(e) {
            
            if(
                   
e.which != //only left click starts dragging
                
|| $.inArray(e.target.nodeName.toLowerCase(), this.options.dragPrevention) != -// Prevent execution on defined elements
                
|| (this.options.condition && !this.options.condition.apply(this.options.executor || this, [ethis.element])) //Prevent execution on condition
            
) return true;
            
            var 
self this;
            var 
initialize = function() {
                
self._MP = { lefte.pageXtope.pageY }; // Store the click mouse position
                
$(document).bind('mouseup.draggable', function() { return self.stop.apply(selfarguments); });
                $(
document).bind('mousemove.draggable', function() { return self.drag.apply(selfarguments); });
            };

            if(
this.options.delay) {
                if(
this.timerclearInterval(this.timer);
                
this.timer setTimeout(initializethis.options.delay);
            } else {
                
initialize();
            }
            
            return 
false;
            
        },
        
stop: function(e) {            
            
            var 
this.options;
            if(!
this.initialized) return $(document).unbind('mouseup.draggable').unbind('mousemove.draggable');

            if(
this.options.stopthis.options.stop.call(this.options.executor || thisethis.element);
            $(
document).unbind('mouseup.draggable').unbind('mousemove.draggable');
            
this.initialized false;
    
            
alert("Aki esta el STOP !!! (cuando se suelta el mouse)  q(^.^)p ");

            return 
false;
            
        },
        
drag: function(e) {

            var 
this.options;
            if ($.
browser.msie && !e.button) return this.stop.apply(this, [e]); // IE mouseup check
            
            
if(!this.initialized && (Math.abs(this._MP.left-e.pageX) >= o.distance || Math.abs(this._MP.top-e.pageY) >= o.distance)) {
                if(
this.options.startthis.options.start.call(this.options.executor || thisethis.element);
                
this.initialized true;
            } else {
                if(!
this.initialized) return false;
            }
            if(
o.drago.drag.call(this.options.executor || thisethis.element);
            return 
false;
        }
    });
 })(
jQuery); 
  #2 (permalink)  
Antiguo 28/05/2009, 08:35
 
Fecha de Ingreso: mayo-2009
Mensajes: 9
Antigüedad: 15 años
Puntos: 0
Respuesta: Guardar orden despues de hacer Drag and Drop de divs

Aka va la otra libreria...

Código PHP:
/*
 * 'this' -> original element
 * 1. argument: browser event
 * 2.argument: ui object
 */

(function($) {

    $.
ui.plugin.add("sortable""cursor", {
        
start: function(e,ui) {
            var 
= $('body');
            if (
t.css("cursor")) ui.options._cursor t.css("cursor");
            
t.css("cursor"ui.options.cursor);
        },
        
stop: function(e,ui) {
            if (
ui.options._cursor) $('body').css("cursor"ui.options._cursor);
        }
    });

    $.
ui.plugin.add("sortable""zIndex", {
        
start: function(e,ui) {
            var 
ui.helper;
            if(
t.css("zIndex")) ui.options._zIndex t.css("zIndex");
            
t.css('zIndex'ui.options.zIndex);
        },
        
stop: function(e,ui) {
            if(
ui.options._zIndex) $(ui.helper).css('zIndex'ui.options._zIndex);
        }
    });

    $.
ui.plugin.add("sortable""opacity", {
        
start: function(e,ui) {
            var 
ui.helper;
            if(
t.css("opacity")) ui.options._opacity t.css("opacity");
            
t.css('opacity'ui.options.opacity);
        },
        
stop: function(e,ui) {
            if(
ui.options._opacity) $(ui.helper).css('opacity'ui.options._opacity);
        }
    });


    $.
ui.plugin.add("sortable""revert", {
        
stop: function(e,ui) {
            var 
self ui.instance;
            
self.cancelHelperRemoval true;
            var 
cur self.currentItem.offset();
            if(
ui.instance.options.zIndexui.helper.css('zIndex'ui.instance.options.zIndex); //Do the zIndex again because it already was resetted by the plugin above on stop

            //Also animate the placeholder if we have one
            
if(ui.instance.placeholderui.instance.placeholder.animate({ opacity'hide' }, parseInt(ui.options.revert10) || 500);
            
            
ui.helper.animate({
                
leftcur.left self.offsetParentOffset.left - (parseInt(self.currentItem.css('marginLeft'),10) || 0),
                
topcur.top self.offsetParentOffset.top - (parseInt(self.currentItem.css('marginTop'),10) || 0)
            }, 
parseInt(ui.options.revert10) || 500, function() {
                
self.currentItem.css('visibility''visible');
                
window.setTimeout(function() {
                    if(
self.placeholderself.placeholder.remove();
                    
self.helper.remove();
                    if(
ui.options._zIndexui.helper.css('zIndex'ui.options._zIndex);
                }, 
50);
            });
        }
    });

    
    $.
ui.plugin.add("sortable""containment", {
        
start: function(e,ui) {

            var 
ui.options;
            if((
o.containment.left != undefined || o.containment.constructor == Array) && !o._containment) return;
            if(!
o._containmento._containment o.containment;

            if(
o._containment == 'parent'o._containment this[0].parentNode;
            if(
o._containment == 'document') {
                
o.containment = [
                    
0,
                    
0,
                    $(
document).width(),
                    ($(
document).height() || document.body.parentNode.scrollHeight)
                ];
            } else { 
//I'm a node, so compute top/left/right/bottom

                
var ce = $(o._containment)[0];
                var 
co = $(o._containment).offset();

                
o.containment = [
                    
co.left,
                    
co.top,
                    
co.left+(ce.offsetWidth || ce.scrollWidth),
                    
co.top+(ce.offsetHeight || ce.scrollHeight)
                ];
            }

        },
        
sort: function(e,ui) {

            var 
ui.options;
            var 
ui.helper;
            var 
o.containment;
            var 
self ui.instance;
            
            if(
c.constructor == Array) {
                if((
ui.absolutePosition.left c[0])) self.position.left c[0] - (self.offset.left self.clickOffset.left);
                if((
ui.absolutePosition.top c[1])) self.position.top c[1] - (self.offset.top self.clickOffset.top);
                if(
ui.absolutePosition.left c[2] + self.helperProportions.width >= 0self.position.left c[2] - (self.offset.left self.clickOffset.left) - self.helperProportions.width;
                if(
ui.absolutePosition.top c[3] + self.helperProportions.height >= 0self.position.top c[3] - (self.offset.top self.clickOffset.top) - self.helperProportions.height;
            } else {
                if((
ui.position.left c.left)) self.position.left c.left;
                if((
ui.position.top c.top)) self.position.top c.top;
                if(
ui.position.left self.offsetParent.innerWidth() + self.helperProportions.width c.right + (parseInt(self.offsetParent.css("borderLeftWidth"), 10) || 0) + (parseInt(self.offsetParent.css("borderRightWidth"), 10) || 0) >= 0self.position.left self.offsetParent.innerWidth() - self.helperProportions.width c.right - (parseInt(self.offsetParent.css("borderLeftWidth"), 10) || 0) - (parseInt(self.offsetParent.css("borderRightWidth"), 10) || 0);
                if(
ui.position.top self.offsetParent.innerHeight() + self.helperProportions.height c.bottom + (parseInt(self.offsetParent.css("borderTopWidth"), 10) || 0) + (parseInt(self.offsetParent.css("borderBottomWidth"), 10) || 0) >= 0self.position.top self.offsetParent.innerHeight() - self.helperProportions.height c.bottom - (parseInt(self.offsetParent.css("borderTopWidth"), 10) || 0) - (parseInt(self.offsetParent.css("borderBottomWidth"), 10) || 0);
            }

        }
    });

    $.
ui.plugin.add("sortable""axis", {
        
sort: function(e,ui) {
            var 
ui.options;
            if(
o.constrainto.axis o.constraint//Legacy check
            
o.axis == 'x' ui.instance.position.top ui.instance.originalPosition.top ui.instance.position.left ui.instance.originalPosition.left;
        }
    });

    $.
ui.plugin.add("sortable""scroll", {
        
start: function(e,ui) {
            var 
ui.options;
            
o.scrollSensitivity    o.scrollSensitivity || 20;
            
o.scrollSpeed        o.scrollSpeed || 20;

            
ui.instance.overflowY = function(el) {
                do { if((/
auto|scroll/).test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return elel el.parent(); } while (el[0].parentNode);
                return $(
document);
            }(
this);
            
ui.instance.overflowX = function(el) {
                do { if((/
auto|scroll/).test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return elel el.parent(); } while (el[0].parentNode);
                return $(
document);
            }(
this);
        },
        
sort: function(e,ui) {
            
            var 
ui.options;
            var 
ui.instance;

            if(
i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') {
                if(
i.overflowY[0].offsetHeight - (ui.position.top i.overflowY[0].scrollTop i.clickOffset.top) < o.scrollSensitivity)
                    
i.overflowY[0].scrollTop i.overflowY[0].scrollTop o.scrollSpeed;
                if((
ui.position.top i.overflowY[0].scrollTop i.clickOffset.top) < o.scrollSensitivity)
                    
i.overflowY[0].scrollTop i.overflowY[0].scrollTop o.scrollSpeed;                
            } else {
                
//$(document.body).append('<p>'+(e.pageY - $(document).scrollTop())+'</p>');
                
if(e.pageY - $(document).scrollTop() < o.scrollSensitivity)
                    $(
document).scrollTop($(document).scrollTop() - o.scrollSpeed);
                if($(
window).height() - (e.pageY - $(document).scrollTop()) < o.scrollSensitivity)
                    $(
document).scrollTop($(document).scrollTop() + o.scrollSpeed);
            }
            
            if(
i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') {
                if(
i.overflowX[0].offsetWidth - (ui.position.left i.overflowX[0].scrollLeft i.clickOffset.left) < o.scrollSensitivity)
                    
i.overflowX[0].scrollLeft i.overflowX[0].scrollLeft o.scrollSpeed;
                if((
ui.position.top i.overflowX[0].scrollLeft i.clickOffset.left) < o.scrollSensitivity)
                    
i.overflowX[0].scrollLeft i.overflowX[0].scrollLeft o.scrollSpeed;                
            } else {
                if(
e.pageX - $(document).scrollLeft() < o.scrollSensitivity)
                    $(
document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
                if($(
window).width() - (e.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
                    $(
document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
            }
            
            
ui.instance.recallOffset(e);

        }
    });

})(
jQuery); 
  #3 (permalink)  
Antiguo 28/05/2009, 08:39
 
Fecha de Ingreso: mayo-2009
Mensajes: 9
Antigüedad: 15 años
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(arguments1);
            
            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(sortargs);

                } else if(!$.
data(this"ui-sortable"))
                    new $.
ui.sortable(thisoptions);
            });
            
            
            
alert("Aki esta el Drag xD");
        }
            
    });
    
    
    $.
ui.sortable = function(elementoptions) {
        
//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 
this.options;
        $.
extend(o, {
            
itemsthis.options.items || '> *',
            
zIndexthis.options.zIndex || 1000,
            
startCondition: function() {
                return !
self.disabled;    
            }        
        });
        
        $(
element).bind("setData.sortable", function(eventkeyvalue){
            
self.options[key] = value;
        }).
bind("getData.sortable", function(eventkey){
            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({ borderfalse });

        
//Initialize mouse events for interaction
        
this.element.mouseInteraction({
            
executorthis,
            
delayo.delay,
            
distanceo.distance || 0,
            
dragPreventiono.prevention o.prevention.toLowerCase().split(',') : ['input','textarea','button','select','option'],
            
startthis.start,
            
stopthis.stop,
            
dragthis.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 nullnodes = $(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 {
                
helperthis.helper,
                
placeholderthis.placeholder || $([]),
                
positionthis.position,
                
absolutePositionthis.positionAbs,
                
instancethis,
                
optionsthis.options
            
};        
        },
        
propagate: function(n,e) {
            $.
ui.plugin.call(thisn, [ethis.ui()]);
            
this.element.triggerHandler(== "sort" "sort"+n, [ethis.ui()], this.options[n]);
        },
        
serialize: function(o) {
            
            var 
items = $(this.options.itemsthis.element).not('.ui-sortable-helper'); //Only the items of the sortable itself
            
var str = [];
            
|| {};
            
            
items.each(function() {
                var 
res = (this.getAttribute(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
                if(
resstr.push((o.key || res[1])+'[]='+(o.key res[1] : res[2]));                
            });
            
            return 
str.join('&');
            
        },
        
intersectsWith: function(item) {
            
            var 
x1 this.positionAbs.leftx2 x1 this.helperProportions.width,
                
y1 this.positionAbs.topy2 y1 this.helperProportions.height;
            var 
item.leftitem.width
                
item.top,  item.height;
            
            return (   
x1 + (this.helperProportions.width  2)        // Right Half
                
&&     x2 - (this.helperProportions.width  2) < r    // Left Half
                
&& y1 + (this.helperProportions.height 2)        // Bottom Half
                
&&     y2 - (this.helperProportions.height 2) < ); // Top Half
            
        
}, 
  #4 (permalink)  
Antiguo 28/05/2009, 08:40
 
Fecha de Ingreso: mayo-2009
Mensajes: 9
Antigüedad: 15 años
Puntos: 0
Respuesta: Guardar orden despues de hacer Drag and Drop de divs

Segunda parte de ui

Código PHP:
refresh: function() {
            
            
this.items = [];
            var 
items this.items;
            var 
queries = [$(this.options.itemsthis.element)];
            
            if(
this.options.connectWith) {
                for (var 
this.options.connectWith.length 1>= 0i--){
                    var 
inst = $.data($(this.options.connectWith[i])[0], 'ui-sortable');
                    if(
inst && !inst.disabledqueries.push($(inst.options.itemsinst.element));
                };
            }
            
            for (var 
queries.length 1>= 0i--){
                
queries[i].each(function() {
                    $.
data(this'ui-sortable-item'true); // Data for target checking (mouse manager)
                    
items.push({
                        
item: $(this),
                        
width0height0,
                        
left0top0
                    
});
                });
            };

        },
        
refreshPositions: function(fast) {
            for (var 
this.items.length 1>= 0i--){
                if(!
fastthis.items[i].width this.items[i].item.outerWidth();
                if(!
fastthis.items[i].height this.items[i].item.outerHeight();
                var 
this.items[i].item.offset();
                
this.items[i].left p.left;
                
this.items[i].top p.top;
            };

        },
        
destroy: function() {
            
this.element
                
.removeClass("ui-sortable ui-sortable-disabled")
                .
removeData("ui-sortable")
                .
unbind(".sortable")
                .
removeMouseInteraction();
            for ( var 
this.items.length 1>= 0i-- )
                
this.items[i].item.removeData("ui-sortable-item");
        },
        
enable: function() {
            
this.element.removeClass("ui-sortable-disabled");
            
this.disabled false;
        },
        
disable: function() {
            
this.element.addClass("ui-sortable-disabled");
            
this.disabled true;
        },
        
createPlaceholder: function() {
            
this.placeholderElement this.options.placeholderElement ? $(this.options.placeholderElementthis.currentItem) : this.currentItem;
            
this.placeholder = $('<div></div>')
                .
addClass(this.options.placeholder)
                .
appendTo('body')
                .
css({ position'absolute' })
                .
css(this.placeholderElement.offset())
                .
css({ widththis.placeholderElement.outerWidth(), heightthis.placeholderElement.outerHeight() })
                ;
        },
        
recallOffset: function(e) {

            var 
elementPosition = { leftthis.elementOffset.left this.offsetParentOffset.lefttopthis.elementOffset.top this.offsetParentOffset.top };
            var 
this.helper.css('position') == 'relative';

            
//Generate the original position
            
this.originalPosition = {
                
left: (parseInt(this.helper.css('left'),10) || elementPosition.left + (this.offsetParent[0] == document.body this.offsetParent[0].scrollLeft)),
                
top: (parseInt(this.helper.css('top'),10) || elementPosition.top + (this.offsetParent[0] == document.body this.offsetParent[0].scrollTop))
            };
            
            
//Generate a flexible offset that will later be subtracted from e.pageX/Y
            
this.offset = {
                
leftthis._pageX this.originalPosition.left + (parseInt(this.currentItem.css('marginLeft'),10) || 0),
                
topthis._pageY this.originalPosition.top + (parseInt(this.currentItem.css('marginTop'),10) || 0)
            };
            
        },
        
start: function(e) {
            
            var 
this.options;

            
//Refresh the droppable items
            
this.refresh(); this.refreshPositions();

            
//Create and append the visible helper
            
this.helper typeof o.helper == 'function' ? $(o.helper.apply(this.element[0], [ethis.currentItem])) : this.currentItem.clone();
            
this.helper.appendTo(this.currentItem[0].parentNode).css({ position'absolute'clear'both' }).addClass('ui-sortable-helper');

            
//Find out the next positioned parent
            
this.offsetParent = (function(cp) {
                while(
cp) {
                    if(
cp.style && (/(absolute|relative|fixed)/).test($.css(cp,'position'))) return $(cp);
                    
cp cp.parentNode cp.parentNode null;
                }; return $(
"body");        
            })(
this.helper[0].parentNode);
            
            
//Prepare variables for position generation
            
this.elementOffset this.currentItem.offset();
            
this.offsetParentOffset this.offsetParent.offset();
            var 
elementPosition = { leftthis.elementOffset.left this.offsetParentOffset.lefttopthis.elementOffset.top this.offsetParentOffset.top };
            
this._pageX e.pageXthis._pageY e.pageY;
            
this.clickOffset = { lefte.pageX this.elementOffset.lefttope.pageY this.elementOffset.top };
            var 
this.helper.css('position') == 'relative';
            
            
//Generate the original position
            
this.originalPosition = {
                
left: (parseInt(this.helper.css('left'),10) || elementPosition.left + (this.offsetParent[0] == document.body this.offsetParent[0].scrollLeft)),
                
top: (parseInt(this.helper.css('top'),10) || elementPosition.top + (this.offsetParent[0] == document.body this.offsetParent[0].scrollTop))
            };
            
            
//Generate a flexible offset that will later be subtracted from e.pageX/Y
            //I hate margins - they need to be removed before positioning the element absolutely..
            
this.offset = {
                
lefte.pageX this.originalPosition.left + (parseInt(this.currentItem.css('marginLeft'),10) || 0),
                
tope.pageY this.originalPosition.top + (parseInt(this.currentItem.css('marginTop'),10) || 0)
            };

            
//Save the first time position
            
this.position = { tope.pageY this.offset.toplefte.pageX this.offset.left };
            
this.positionAbs = { lefte.pageX this.clickOffset.lefttope.pageY this.clickOffset.top };
            
this.positionDOM this.currentItem.prev()[0];

            
//If o.placeholder is used, create a new element at the given position with the class
            
if(o.placeholderthis.createPlaceholder();

            
//Call plugins and callbacks
            
this.propagate("start"e);

            
//Save and store the helper proportions
            
this.helperProportions = { widththis.helper.outerWidth(), heightthis.helper.outerHeight() };
            
            
//Set the original element visibility to hidden to still fill out the white space    
            
$(this.currentItem).css('visibility''hidden');
            
            return 
false;
                        
        },
        
stop: function(e) {

            
this.propagate("stop"e); //Call plugins and trigger callbacks
            
if(this.positionDOM != this.currentItem.prev()[0]) this.propagate("update"e);
            
            if(
this.cancelHelperRemoval) return false;            
            $(
this.currentItem).css('visibility''');
            if(
this.placeholderthis.placeholder.remove();
            
this.helper.remove();
            return 
false;
            
        },
        
drag: function(e) {

            
//Compute the helpers position
            
this.direction = (this.floating && this.positionAbs.left e.pageX this.clickOffset.left) || (this.positionAbs.top e.pageY this.clickOffset.top) ? 'down' 'up';
            
this.position = { tope.pageY this.offset.toplefte.pageX this.offset.left };
            
this.positionAbs = { lefte.pageX this.clickOffset.lefttope.pageY this.clickOffset.top };

            
//Rearrange
            
for (var this.items.length 1>= 0i--) {
                if(
this.intersectsWith(this.items[i]) && this.items[i].item[0] != this.currentItem[0] && (this.options.tree ? !this.currentItem[0].contains(this.items[i].item[0]) : true)) {
                    
//Rearrange the DOM
                    
this.items[i].item[this.direction == 'down' 'before' 'after'](this.currentItem);
                    
this.refreshPositions(true); //Precompute after each DOM insertion, NOT on mousemove
                    
if(this.placeholderElementthis.placeholder.css(this.placeholderElement.offset());
                    
this.propagate("change"e); //Call plugins and callbacks
                    
break;
                }
            }

            
this.propagate("sort"e); //Call plugins and callbacks
            
this.helper.css({ leftthis.position.left+'px'topthis.position.top+'px' }); // Stick the helper to the cursor
            
            
return false;
            
        }
    });

})(
jQuery); 
  #5 (permalink)  
Antiguo 28/05/2009, 08:57
 
Fecha de Ingreso: mayo-2009
Mensajes: 9
Antigüedad: 15 años
Puntos: 0
Respuesta: Guardar orden despues de hacer Drag and Drop de divs

aca esta la aplicacion con la q listo las tareas.

Disculpen la multiplicidad de post pero necesitaba mostrarles las librerias q uso...


Código PHP:
<head>
<meta http-equiv="Content-Language" content="en" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Listar Tareas - </title>
<link rel="stylesheet" href="../styles/flora/flora.all.css" type="text/css" media="screen" title="Flora (Default)" />
<link rel="stylesheet" href="../styles/estilo.css" type="text/css" />
<script src="jquery-1.2.3.min.js" type="text/javascript"></script>
<script type="text/javascript" src="jquery.dimensions.js"></script>

<script type="text/javascript" src="ui.mouse.js"></script>
<script type="text/javascript" src="../js/funciones.js"></script>
<script type="text/javascript" src="ui.sortable.js"></script>
<script type="text/javascript" src="ui.sortable.ext.js"></script>

</head>

<script type="text/javascript">


if(!window.console) {
 window.console = {
     log: function() {
         alert(arguments[0]);    
     }    
 }    
}
$(window).bind("load",function(){
    $("#example1_2").sortable({ connectWith: ['#example1'], revert: true });
    $("#example2").sortable({ revert: true });
});
</script>
<?php
    $_POST
['dequien'] = $_GET['dequien'];
    
$aquien $_POST['dequien'];
    include(
'../conectarBase.php');
    
$query "select aquien, pendiente, descripcion, prioridad from tareas WHERE aquien = '$aquien' ORDER BY prioridad ASC";
    
$resultado=mysql_query($query);

    echo 
"<div class=\"playground\" id='lista'><ul id='example2' style='list-style-position: inside; height: 30px; cursor: hand; cursor: pointer;'>";
    while( 
$fila mysql_fetch_assoc($resultado) )
    {
        if(
$fila['pendiente'] == 'si'){
            echo 
"<li style='float: top; padding: 5px; border: 1px solid #ffg; margin: 3px; background: red;' value='".$fila['id']."'>Pendiente - Prioridad [".$fila['prioridad']."] - Descripcion Tarea: ".$fila['descripcion']."</li>";
        }else { 
            echo 
"<li style='float: top; padding: 5px; border: 1px solid #ffg; margin: 3px; background: green;' value='".$fila['id']."'>Pendiente - Prioridad [".$fila['prioridad']."] - Descripcion Tarea: ".$fila['descripcion']."</li>";
        }
        
$cuack ++;
    }
    echo 
"</ul></div>";
    
mysql_close($link);
?>
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:38.