var date_ck = new Date(); date_ck.setTime(date_ck.getTime() + (365 * 24 * 60 * 60 * 1000)); /** * Constant: sets the path to the root and expirary to one year from now */ var OPTIONS_CK = { path: '/', expires: date_ck}; /** * Constant: DO not alter post launch */ var COOKIE_NAME_CK = "__psuc"; var su_data = {email: null, zip: null}; /** * Checks cookies exists, if not, sets cookie for future use * * @param _name Constant: cookie name * @param _obj object: Email and name details * @return */ function check_cookie(_name, _obj) { // check if cookie is set, if so, parse it, if not, set a blank cookie with blank data if(_temp = get_cookie(_name, _obj)) { add_su_details(_temp); }else { set_cookie(_name, _obj); } } /** * @param _name COOKIE_NAME * @return object with s values from cookie */ function get_cookie(_name , _obj) { if($.cookie(_name)) { // grab the cookie _temp = $.cookie(_name); // set the slugs variable to cookies data and decode the json object BACK into a javascript object return _obj = jQuery.secureEvalJSON(_temp); }else { return false; } } // sets the cookie info, returns false if cannot set cookie /** * @param _name COOKIE_NAME * @param _obj save new cookie with serialized JSON object * @return boolean */ function set_cookie(_name, _obj) { try { // serialize the slugs obj to JSON _obj = jQuery.toJSON(_obj); // set the cookie with JSON object and options + 1y jQuery.cookie(_name, _obj, OPTIONS_CK); return true; } // if error completing this return false catch(err) { return false; } } /** * Adds details to email and name fields for both pop and entry forms * * @param _obj object: email and name details [null if not set] * @return void */ function add_su_details(_obj) { for (var name in _obj) { jQuery('#pop-signup #' + name + ", #signup.hide #" + name).attr('value', _obj[name]); } } /** * Initializes the cookie details signup form script * * @return void */ function init() { jQuery('#pop-signup input[name=submit-btn], #signup.hide input[name=submit-btn]').click(function() { for (var name in su_data) { su_data[name] = jQuery('#pop-signup #' + name).attr('value'); } set_cookie(COOKIE_NAME_CK, su_data); }); jQuery(document).ready(function(){ check_cookie(COOKIE_NAME_CK, su_data); }); } init();