View Full Version : Sortables with jquery and cookies?
webdevised
09-09-2008, 03:52 PM
I have a sortable div page http://bt5.awardspace.com and the sortable works just fine.. My issue is i need to set a cookie after they sort it so that the next time they come to the page the order is kept.. any ideas??
index.html (http://bt5.awardspace.com)
jquery-1.2.6.min.js (http://bt5.awardspace.com/jquery-1.2.6.min.js)
interface.js (http://bt5.awardspace.com/interface.js)
Jon Hanlon
09-14-2008, 02:23 AM
Do a web search for Bill Dortch.
http://cookiecentral.com/ is also good.
webdevised
09-15-2008, 12:37 PM
What i meant to say is..
I can read the cookie I can set the cookie.. I just need help on getting the info from the cookie and reordering the content on the page to what the cookie has in it.. If you go to my example site and then reorder the divs and then refresh the page you will see the cookie string at the bottom..
I have found this code that randomly reorders each page load.. wonder how i can use this script..
<style type="text/css">
.jsclass body .randomordercontent{
display: none;
}
</style>
<script type="text/javascript">
if (document.getElementById)
document.documentElement.className = 'jsclass'; //hide content for DOM capable browsers
var randomordercontentdisplay={
divholders:new Object(),
masterclass: "randomordercontent",
init:function(){
if (!document.getElementById)
return
var alldivs=document.getElementsByTagName("div")
var randomcontentsearch=new RegExp(this.masterclass+"\\s+(group\\d+)", "i") //check for CSS class="randomcontent groupX" (x=integer)
for (var i=0; i<alldivs.length; i++){
if (randomcontentsearch.test(alldivs[i].className)){
if (typeof this.divholders[RegExp.$1]=="undefined"){ //if object to hold this group of divs doesn't exist yet
this.divholders[RegExp.$1]=new Object() //create object
this.divholders[RegExp.$1].ref=[] //create array to hold each div within group
this.divholders[RegExp.$1].contents=[] //create array to hold each div's content within group
}
this.divholders[RegExp.$1].ref.push(alldivs[i]) //add this div to the array
this.divholders[RegExp.$1].contents.push(alldivs[i].innerHTML) //add this div's content to the array
}
}
this.scrambleorder()
},
scrambleorder:function(){
for (group in this.divholders){ //loop thru each array within object
this.divholders[group].contents.sort(function() {return 0.5 - Math.random()}) //scramble contents array
for (var i=0; i<this.divholders[group].ref.length; i++){
this.divholders[group].ref[i].innerHTML=this.divholders[group].contents[i]
this.divholders[group].ref[i].style.display="block"
}
}
}
}
</script>
<head>
<h3>Random Order Content Group 1 (4 pieces of content total):</h3>
<div class="randomordercontent group1">
<p style="border:1px dashed gray; background-color:lightyellow; padding: 10px">Group 1 Content 1</p>
</div>
<div class="randomordercontent group1">
<p style="border:1px dashed gray; background-color:lightyellow; padding: 10px">Group 1 Content 2</p>
</div>
<div class="randomordercontent group1">
<p style="border:1px dashed gray; background-color:lightyellow; padding: 10px">Group 1 Content 3</p>
</div>
<div class="randomordercontent group1">
<p style="border:1px dashed gray; background-color:lightyellow; padding: 10px">Group 1 Content 4</p>
</div>
<h3>Random Order Content Group 2 (2 pieces of content total):</h3>
<div class="randomordercontent group2">
<p style="border:1px dashed gray; background-color:#D8EA99; padding: 10px">Group 2 Content 1</p>
</div>
<div class="randomordercontent group2">
<p style="border:1px dashed gray; background-color:#D8EA99; padding: 10px">Group 2 Content 2</p>
</div>
<script type="text/javascript">
randomordercontentdisplay.init()
</script>
webdevised
09-22-2008, 09:37 AM
no one has any ideas?
webdevised
09-30-2008, 08:56 AM
bump bump bump it up
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.