Ver Mensaje Individual
  #4 (permalink)  
Antiguo 28/05/2009, 08:40
c3sar0n
 
Fecha de Ingreso: mayo-2009
Mensajes: 9
Antigüedad: 15 años, 5 meses
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);