views:

280

answers:

2

I am trying to save some css information into cookies with the below jquery script.

Everything is perfectly fine for Firefox however IE throws an error on jquery Line 4618, whenever i include this file

jQuery(document).ready(function() {

  // cookie period
  var days = 365;

  // load positions and z-index from cookies
  $("div[id*='tqitem']").each( function( index ){
    $(this).css( "left", 
      $.cookie( "im_" + $(this).attr("id") + "_left") );
    $(this).css( "top", 
      $.cookie( "im_" + this.id + "_top") );
     $(this).css( "zIndex", 
      $.cookie( "tqz_" + this.id + "_zIndex") );
  });


  //  bind event
  $(".pagenumbers").draggable({cursor: "move"});
  $("div[id*='tqitem']").bind('dragstop', savePos);
  $("div[id*='tqitem']").bind('dragstop', savePot);


  // save positions into cookies
  function savePos( event, ui ){
    $.cookie("im_" + $(this).attr("id") + "_left", 
      $(this).css("left"), { path: '/', expires: days });
    $.cookie("im_" + this.id + "_top", 
      $(this).css("top"), { path: '/', expires: days });
  $.cookie("im_" + this.id + "_zIndex", 
     $(this).css("zIndex"), { path: '/', expires: days });
  };

var thiss = $("div[id*='tqitem']");

function savePot(){
      $("div[id*='tqitem']").each(function (i) {
          $.cookie("tqz_" + $(this).attr("id") + "_zIndex", 
  $(this).css("zIndex"), { path: '/', expires: days });
      })
};

});



/*ADDITIONAL INFO:

SCRIPT HIERARCHY

Jquery itself
Jquery ui
Jquery cookie plugin
Save cookies js

no matter how i ordered them the result did not change*/
A: 

You're trying to use the functions savePos and savePot before you actually declare them. You can't bind a function to an event if the function doesn't exist yet.

Place the declarations of the savePos and savePot functions before the point where you bind them to events.

Syntactic
A: 

I think you need to wrap the rest of your this calls in the loading and saving portions into a jquery object. You do it on the first line, but you don't do it on the rest. For example, this code:

// load positions and z-index from cookies
  $("div[id*='tqitem']").each( function( index ){
    $(this).css( "left", 
      $.cookie( "im_" + $(this).attr("id") + "_left") );
    $(this).css( "top", 
      $.cookie( "im_" + this.id + "_top") );
     $(this).css( "zIndex", 
      $.cookie( "tqz_" + this.id + "_zIndex") );
  });

Should look like this:

// load positions and z-index from cookies
  $("div[id*='tqitem']").each( function( index ){
    $(this).css( "left", 
      $.cookie( "im_" + $(this).attr("id") + "_left") );
    $(this).css( "top", 
      $.cookie( "im_" + $(this).attr("id") + "_top") );
     $(this).css( "zIndex", 
      $.cookie( "tqz_" + $(this).attr("id") + "_zIndex") );
  });
ryanulit
i just solved it myself and came back to reply as solved but yeah that was the issue, thanks... used this.id while saving and attr.id while loading
eo