PDA

View Full Version : Jquery Move Tracking


InterbredMonkey
02-26-2010, 11:08 AM
I have made a page with 3 columns with sortable divs. I need to be able to track the divs when they are moved so that when the user closes the page the divs will be in the same locations they were moved to. I got the following code from the BBC website yet I cannot get it to work. Anyone know what is wrong with it?

Code:
function update_positions(e, ui){
var widget_cookie_positions = loadCookie('iARC_widget_positions');
var moved_widget_id = $(ui.item).attr('id');
var moved_to_column_id = $(ui.item).parents('.column').attr('id');
var column_order = "0";

$('#' + moved_to_column_id + '> .widget').each(function(){

var widget_id = $(this).attr('id');

panel_positions[panel_id] = moved_to_column_id + ':' + column_order;

column_order++;

});
};

Spudhead
02-26-2010, 01:29 PM
It's not saving the new positions?

InterbredMonkey
02-26-2010, 01:45 PM
Sorry, I should of said. All it does is crash the sortable when you move the divs more than once. I tried writing to a cookie but this does not work either.

InterbredMonkey
03-03-2010, 07:47 PM
If anyone is interested in this post, I have managed to work out that the reason the sortable is crashing, the console that I have is showing that the this.helper is null and therefore stuck in a ever running loop. I am trying to sort out this issue and I will post the working code once it has been rectified.

InterbredMonkey
03-03-2010, 08:30 PM
function update_positions(e, ui){
var widget_cookie_positions = loadCookie('iARC_widget_positions');
var moved_widget_id = $(ui.item).attr('id');
var moved_to_column_id = $(ui.item).parents('.column').attr('id');
var column_order = "0";

$('#' + moved_to_column_id + '> .widget:not(this.helper)').each(function(){

var widget_id = $(this).attr('id');

panel_positions[panel_id] = moved_to_column_id + ':' + column_order;

column_order++;

});
};

Works Like a charm now. If you cannot see I have changed the code to exclude the helper which has stopped the loop.