Search code examples
jquerycookiesjquery-animatejquery-cookieadobe-edge

jquery cookies in edge animate


So in a regular html5 page in IE I can get the following jquery code to work:

       $.cookie('mycookieX',cookieXcounter,{expires:7,path:'/'});

       $.cookie('mycookieY',cookieYcounter,{expires:7,path:'/'});



       console.log($.cookie('mycookieX'));

But I can't get the code to work in my edgeActions.js file... I tried changing up the syntax (since when I use jquery in edge before I've had to change things for example:

       $('#blueCar').animate({

        left:carArrayX[carArrayXcounter] + "px",

        top:carArrayY[carArrayYcounter] + "px"

        }); '

to

       sym.$('blueCar').animate({

       left:myVariableX + "px",

       top:myVariableY + "px" 

       });

but I can't figure out the cookies in edge with jquery to get them workign... It's probaby a syntax thing but all I could think of was this:

      sym. $.cookie('mycookieX',cookieXcounter,{expires:7,path:'/'});

      sym. $.cookie('mycookieY',cookieYcounter,{expires:7,path:'/'});



       console.log($.cookie('mycookieX'));

--------------------------> and of course this doesn't work..

Please provide thoughts...


Solution

  • I never was able to get the plugin for jquery-cookies.js to work with edge animate, which should have been the simplest to cache:

    //jquery cookies not working in edge animate:
                                            //  $.cookie('mycookieX',btnArrayX,{expires:7,path:'/'});                                       
                                             // $.cookie('mycookieY',btnArrayY,{expires:7,path:'/'});
                                             //console.log($.cookie('mycookieX'));
    

    but I did get javascript (taken from another user on stackoverflow) to work with edge animate:

    //set cookie
                                                function createCookie(name,value,days) {
                                                    if (days) {
                                                        var date = new Date();
                                                        date.setTime(date.getTime()+(days*24*60*60*1000));
                                                        var expires = "; expires="+date.toGMTString();
                                                    }
                                                    else var expires = "";
                                                    document.cookie = name+"="+value+expires+"; path=/";
                                                }
    
                                                createCookie('ppkcookie',btnArrayX,7);
    
    //read cookie
    
                                                    function readCookie(name) {
                                                        var nameEQ = name + "=";
                                                        var ca = document.cookie.split(';');
                                                        for(var i=0;i < ca.length;i++) {
                                                            var c = ca[i];
                                                            while (c.charAt(0)==' ') c = c.substring(1,c.length);
                                                            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
                                                        }
                                                        return null;
                                                    }
    
                                                var yayCookie = readCookie('ppkcookie');
                                                console.log('yayCookie' + yayCookie);
    

    So, I guess anyone trying to read/set cookie in edge animate... it's probably still possible with the jquery plugin, I just don't know the correct syntax to make it edge animate compatible.. but the good news it that straight javascript (although longer) works fine :)