전체 페이지뷰

2013년 11월 21일 목요일

jquery superCookie example

var object  = {};
var lastKey =0 ;

if ($.super_cookie().check("recentDocument") && $.super_cookie().verify("recentDocument")) {
//Read cookie values as JSON object
      object = $.super_cookie().read_JSON("recentDocument");
      $.each (object, function (key){
  if (object[key].doc  ==  docKey){
      return false ;
  } else {
     lastKey = key;
          }
      });
}

lastKey = parseInt(lastKey)+1;
console.log("lastKey ::: "+ lastKey + ': ' + object[lastKey]);

object[lastKey] = { doc: docKey , title: titleNm , link : linkNm };

$.super_cookie({expires: 7,path: "/"}).create("recentDocument",object);

// Check if cookie exists
// Check if cookie value is a valid JSON
if ($.super_cookie().check("recentDocument") && $.super_cookie().verify("recentDocument")) {
// Read cookie values as JSON object
     var obj = $.super_cookie().read_JSON("recentDocument");

     var html = '<ul class="num_list">';

     $.each (obj, function (key){
  var data =  obj[key];
  console.log ( data.title );
  
html += '<li><div class=""><span>'+key+'</span></div><a href="#" onclick="javascript:linkRecentKeyword(\'' + data.doc + '\');">'+data.title+'</a></li>';
     });

     html += '</ul>';
     console.log ("html :::: "+html);
$('#recentDocumentList').html(html).fadeIn(300);
}

댓글 없음:

댓글 쓰기