absinthe
Not New Member
Posts: 5
absinthe said 0 great things
|
Post by absinthe on Jan 24, 2011 23:16:44 GMT -8
my real siteI need to create a div tag that only certain groups can see but know almost nothing about javascript D:
|
|
|
Post by Wormopolis on Jan 24, 2011 23:44:49 GMT -8
you posted alink to a striped image?
you are looking for something that would go in a post that only a certain group would see or something that goes in headers/footers?
|
|
absinthe
Not New Member
Posts: 5
absinthe said 0 great things
|
Post by absinthe on Jan 25, 2011 3:51:27 GMT -8
lol relinked my site (:
no, i want something a bit more simpler than that, though that is a pretty neat code idea.
I have cleaned my admin button out of the menu website and have been typing it out, so I have decided that I want to recreate it, instead of doing the obvious option and change the buttons to images and moving them around. D:
I moved it out cos it looks prettier (:
|
|
|
Post by Wormopolis on Jan 25, 2011 4:16:16 GMT -8
I need a bit more info then. Where would this Div show? I get that only a certain usergroup would see the div, but is it something that they click a spacial area to open the div, or is it visible o the page to them the whole time?
|
|
absinthe
Not New Member
Posts: 5
absinthe said 0 great things
|
Post by absinthe on Jan 25, 2011 4:40:41 GMT -8
visible on the page the whole time.
basically a really basic div. with a class
|
|
|
Post by Wormopolis on Jan 26, 2011 1:29:36 GMT -8
ok. I can do this, but there will be a small catch. usergroup isnt a normal variable on the page. it has to be captured and stored. I have done this before and stored in a cookie, but it relied on the fact that at some point the members username was spotted on the page.
I should be able to get something for you tomorrow night.
|
|
|
Post by Wormopolis on Jan 27, 2011 19:07:02 GMT -8
currently working on this in testing area
|
|
|
Post by Wormopolis on Jan 27, 2011 22:31:35 GMT -8
ok.. this will seem kinda weird, and I may tweak it later, but it works in IE and FF and is simple to understand and edit.
this is what DIVs would be like:
<style type="text/css"> .SquirrlyDiv {display: none;} </style>
<center> <div class="SquirrlyDiv SQgroup1" style="background: #000000; border: #ff0000 1px solid; color: #ffffff"> This div should show for group 1 only <br> hopefully </div> <div class="SquirrlyDiv SQgroup1 SQgroup2" style="background: #000000; border: #ff0000 1px solid; color: #ffffff"> This div should show for group 1 and 2 <br> hopefully </div> <div class="SquirrlyDiv SQgroupG" style="background: #000000; border: #ff0000 1px solid; color: #ffffff"> This div should show for groupG (guests) <br> hopefully </div> <div class="SquirrlyDiv SQgroup2 SQgroup0" style="background: #000000; border: #ff0000 1px solid; color: #ffffff"> This div should show for group 2 and 0 <br> hopefully </div> <div class="SquirrlyDiv SQgroup1 SQgroup2 SQgroup11" style="background: #000000; border: #ff0000 1px solid; color: #ffffff"> This div should show for group 1, 2 and 11 <br> hopefully </div> <div class="SquirrlyDiv SQgroup11" style="background: #000000; border: #ff0000 1px solid; color: #ffffff"> This div should show for group 11 only <br> hopefully </div> <div class="SquirrlyDiv SQgroup0" style="background: #000000; border: #ff0000 1px solid; color: #ffffff"> This div should show for group 0 only <br> hopefully </div> </center>
notice the CSS that defaults ALL divs to hidden because the all have the classname SquirrlyDiv in common. then each div has additional parts of their classname that let you assign which groups will see them. the groupID is the same as the usergroup ID. Guests would be under SQgroupG. see my examples for how it works.
then you will need this in global footer:
<script type="text/javascript"> <!-- // divs revealed by usergroup // by Wormopolis - www.wormocodes.com // request by absinthe // keep header intact
for (lnks=document.getElementsByTagName('a'), ug=0; ug<lnks.length; ug++) { if (lnks[ug].className && lnks[ug].href.match(/action=viewprofile&user=(.*?)$/)) { var lnkuser=RegExp.$1; if (lnkuser==pb_username) { var tmptime=new Date(); tmptime.setFullYear(tmptime.getFullYear()+1); var pb_usergroup=lnks[ug].className; document.cookie="pb_usergroup="+pb_usergroup+"; expires="+tmptime; break; } } } if (pb_username=='Guest') { var holdgroup="groupG"; } else { if (document.cookie.match(/pb_usergroup=(.*?)($|;)/)) { var holdgroup=RegExp.$1; } else { // not a guest but usergroup hasnt been captured. assume not a guest, but dont reveal any divs var holdgroup="none"; } }
if (holdgroup!='none') document.write('<style type="text/css"> .SQ'+holdgroup+' {display: block;} </sty'+'le>');
// --> </script>
if for some reason, their name hasnt been scanned and group id captured, no divs will show to them. I can change that if you need it, but it might confuse someone.
|
|
The Wanderer
Not New Member
Posts: 3
The Wanderer said 0 great things
|
Post by The Wanderer on Jan 31, 2011 23:38:45 GMT -8
mmm... I'm trying this but it seems... in Firefox anyway... that although the cookie is written it does not add the group id to it... there is an entry for pb_usergroup but no value
{EDIT} I've removed the code and put back the code I had originally which means if you go to my site now you won't actually be able to see this...
If anyone looks into this I can put the code back to show the problem.
|
|
|
Post by Wormopolis on Feb 1, 2011 21:16:31 GMT -8
ok.. have some time to look into this. Im runnign this code in my testing section. Which divs do you see there?
where in your headers/footers do you have this code?
|
|
|
Post by Wormopolis on Feb 1, 2011 21:19:46 GMT -8
and keep in mind I have a full time job so I cant jump on every problem immediately.
|
|
The Wanderer
Not New Member
Posts: 3
The Wanderer said 0 great things
|
Post by The Wanderer on Feb 1, 2011 22:29:59 GMT -8
I understand perfectly I also work full time If I look in the cookie for here I see pb_usergroup group0 but not sure where you mean by your testing section my site is: SiteIt was at the top of the footers and the div was around two side tables a little further down. Currently I removed the code though as I couldn't get it to work and didn't know how long it would be before someone had the time to look at this... I can easily put it back though if needs be. {EDIT} Okay I've just had another look at this and played around with it some more... I've tried it with the script part at the top (global footers) and below the div but still I'm not getting a value written to the cookie the div is around box 2 and 3 in the side tables with the script part currently just below it. I'll leave the code in for now so you can see it.
|
|
|
Post by Wormopolis on Feb 1, 2011 23:43:01 GMT -8
looking right now.
|
|
|
Post by Wormopolis on Feb 2, 2011 0:05:07 GMT -8
your PM bar was stealing my thunder. recopy the script part above. I added in something.
|
|
The Wanderer
Not New Member
Posts: 3
The Wanderer said 0 great things
|
Post by The Wanderer on Feb 2, 2011 0:10:04 GMT -8
Okay that got the boxes back but I lose the background around them... It's now black ?? Does that mean I need to move the div bit ? I can make you a temp member if that helps to see what the problem is... {EDIT} Okay figured it out I only had to change the background to "transparent"
|
|