javascript - Saving drag position in localstorage issue -


i using grid layout plugin, gridifier, has dragging , re-ordering function. order of items set using attribute data-gridifier-item-id

i have set code original order data-gridifier-item-id , new order data-gridifier-item-id , save localstorage. can see in console both of these changing drag items new positions not sorted based on localstorage when reload page.

i novice , not able see missing in getting happen. or direction appreciated.

here example codepen

//gridifier code var grid = $(".gallery"); var settings = {      "class": "item",       grid: "vertical", // default = "vertical"  dragifier: true, // default = false  dragifiermode: "intersection"  }  var asyncgrid = new gridifier(grid, settings );   asyncgrid.append(asyncgrid.collectnew());   //localstorage code   $( function() {   var gridifier = asyncgrid.collectnew();   var newsortorder = []; // global variable saving order, used later  var storedsortorder = localstorage.getitem('sortorder');  if ( storedsortorder ) {  storedsortorder = json.parse( storedsortorder );  // create hash of items gridifier-item-id  var itemsbygridifierindex = {};  var gridifierindex;  ( var i=0, len = gridifier.length; < len; i++ ) {   var item = gridifier[i];   gridifierindex = $( item).attr('data-gridifier-item-id');   itemsbygridifierindex[ gridifierindex ] = item;   }   // overwrite  item order   = 0; len = storedsortorder.length;  (; < len; i++ ) {   gridifierindex = storedsortorder[i];   item = itemsbygridifierindex[ gridifierindex ];  } }  function orderitems() {  var itemelems = gridifier  // reset / empty oder array  newsortorder.length = 0;  (var i=0; i< gridifier.length; i++) {   newsortorder[i] = gridifier[i].getattribute("data-gridifier-item-id");  }  // save  ordering  localstorage.setitem('sortorder', json.stringify(newsortorder) );  }   asyncgrid.ondragend(function(sorteditems) {  orderitems();  //console.log(gridifier);  console.log( storedsortorder);  console.log(newsortorder)  //show gridifier-item-id number testing   $(gridifier).each(function(){ var gridnumber = $(this).attr("data-gridifier-item-id")  $(this).text(gridnumber); });  }); }); 


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -