game
Junior Member
Code Digger
Posts: 59
game said 0 great things
|
Post by game on Aug 20, 2012 19:50:51 GMT -8
I have seen this requested a lot and haven't seen it anywhere; Read instructions thoroughly before using.
Placement: Main Footer
Edit the Category Name and the Category ID The Category Name being the Category that you wish to edit and the Category ID being the desired ID that you wish to give the corrosponing Category. To add more Categorys add more [''Category Name'',''Category ID"], Be sure to add a comma at the end. No comma for the last one.
var catEdit=[//Enter [''Category Name'',''Category ID"] below. ["Category Name","Category ID"], ["Category Name","Category ID"] ]; The id is so that you can apply styles to the category through CSS. Therefore you will need to create a <style> sheet for the id's that you create. The best thing would be to name the id the same as the category. If the category is named "cats", name the id "cats" IMPORTANT You can not use white spaces while assigning an id. if you want to space words you can use the underscore_ . ex. (GENERAL_DISCUSSIONS) Or you can just make it one word. ex. (GENERALDISCUSSIONS)
Remember: You need to add a <style> sheet to your Main Header.
<style type= "text/css"> #Category ID{apply: styles;} </style>
Main Footer
<script type= "text/javascript"> //Individual Category Styles //PLacement: Footers //Coded By Game var catEdit=[//Enter [''Category Name'',''Category ID"] below. ["Category Name","Category ID"], ["Category Name","Category ID"] ]; //Editing Not Required Below var td= document.getElementsByTagName("td"),i,x;for(i=0; i<catEdit.length;i++){for(x=0;x<td.length;x++){if(td[x].className=="catbg" && td[x].innerHTML.match(catEdit[i][0])){ td[x].id=catEdit[i][1];}}} </script>
Enjoy!
|
|
|
Post by Wormopolis on Aug 20, 2012 19:58:55 GMT -8
you know that cell has an anchor tag in it with the catid right?
<td height="18" bgcolor="dadada" class="catbg" colspan="5"><a name="general"></a> <font size="2" color="0E0E0E" class="cattext"><b>General</b></font></td>
|
|
game
Junior Member
Code Digger
Posts: 59
game said 0 great things
|
Post by game on Aug 20, 2012 20:14:28 GMT -8
you know that cell has an anchor tag in it with the catid right? <td height="18" bgcolor="dadada" class="catbg" colspan="5"><a name="general"></a> <font size="2" color="0E0E0E" class="cattext"><b>General</b></font></td> But if my only argument was if(td[x].className=="catbg" && td[x].innerHTML.match(catEdit [0] )){
would that effect the anchor?
|
|
|
Post by Wormopolis on Aug 20, 2012 20:56:03 GMT -8
you could check for the presence of the anchor tag, then check to see if it has a name, then assign the td with an id that is the same as that name. if any CSS exists for an object with that id, then it gets applied. if no CSS exists, then nothing happens. that way you dont have to worry about setting up any arrays for the categories at all, they just have to use the id they already assigned to it. turns 2 for loops into 1.
|
|
game
Junior Member
Code Digger
Posts: 59
game said 0 great things
|
Post by game on Aug 20, 2012 22:40:10 GMT -8
you could check for the presence of the anchor tag, then check to see if it has a name, then assign the td with an id that is the same as that name. if any CSS exists for an object with that id, then it gets applied. if no CSS exists, then nothing happens. that way you dont have to worry about setting up any arrays for the categories at all, they just have to use the id they already assigned to it. turns 2 for loops into 1. Hmm very clever! The id will be the id given when creating the category. So you mean this: <script type= "text/javascript"> var td= document.getElementsByTagName("td"),i; for(i=0; i<td.length;i++){ if(td[i].className== "catbg" && td[i].firstChild.document.getElementsByTagName("a")[0] && td[i].firstChild.getElementsByTagName("a")[0].name )){ var tdid= td[i].getElementsByTagName('a')[0].name; td[i].id=tdid; }} </script> , Wormopolis wrote:you could check for the presence of the anchor tag, then check to see if it has a name, then assign the td with an id that is the same as that name. if any CSS exists for an object with that id, then it gets applied. if no CSS exists, then nothing happens. that way you dont have to worry about setting up any arrays for the categories at all, they just have to use the id they already assigned to it. turns 2 for loops into 1. |
|
Hmm very clever! The id will be the id given when creating the category. So you mean this: <script type= 'text/javascript'> var td= document.getElementsByTagName('td'),i; for(i=0; i<td.length;i++){ if(td[i].className== 'catbg' && td[i].firstChild.document.getElementsByTagName('a')){ var tdid= td[i].firstChild.name; td[i].id=tdid; }} </script> [/FONT][/TD][/TR][/TBODY][/TABLE][/TD][/TR][/TBODY][/TABLE] td .firstChild.document.getElementsByTagName('a')[0] && td.firstChild.getElementsByTagName('a')[0].name )
var tdid= td.firstChildgetElementsByTagName('a')[0].name;[/quote] , Wormopolis wrote:you could check for the presence of the anchor tag, then check to see if it has a name, then assign the td with an id that is the same as that name. if any CSS exists for an object with that id, then it gets applied. if no CSS exists, then nothing happens. that way you dont have to worry about setting up any arrays for the categories at all, they just have to use the id they already assigned to it. turns 2 for loops into 1. |
|
Hmm very clever! The id will be the id given when creating the category. So you mean this: <script type= 'text/javascript'> var td= document.getElementsByTagName('td'),i; for(i=0; i<td.length;i++){ if(td[i].className== 'catbg' && td[i].firstChild.document.getElementsByTagName('a')){ var tdid= td[i].firstChild.name; td[i].id=tdid; }} </script> [/FONT][/TD][/TR][/TBODY][/TABLE][/TD][/TR][/TBODY][/TABLE] td .firstChild.document.getElementsByTagName('a')[0] && td.firstChild.getElementsByTagName('a')[0].name )
var tdid= td.firstChildgetElementsByTagName('a')[0].name;[/quote]
|
|
|
Post by Wormopolis on Aug 21, 2012 5:53:01 GMT -8
you could check for the presence of the anchor tag, then check to see if it has a name, then assign the td with an id that is the same as that name. if any CSS exists for an object with that id, then it gets applied. if no CSS exists, then nothing happens. that way you dont have to worry about setting up any arrays for the categories at all, they just have to use the id they already assigned to it. turns 2 for loops into 1. Hmm very clever! The id will be the id given when creating the category. So you mean this: <script type= "text/javascript"> var td= document.getElementsByTagName("td"),i; for(i=0; i<td.length;i++){ if(td[i].className== "catbg" && td[i].firstChild.document.getElementsByTagName("a")){ var tdid= td[i].firstChild.name; td[i].id=tdid; }} </script> td .firstChild.document.getElementsByTagName("a")[0] && td.firstChild.getElementsByTagName("a")[0].name )
var tdid= td.firstChildgetElementsByTagName('a')[0].name;
|
|
game
Junior Member
Code Digger
Posts: 59
game said 0 great things
|
Post by game on Aug 21, 2012 10:30:51 GMT -8
Hmm very clever! The id will be the id given when creating the category. So you mean this: <script type= "text/javascript"> var td= document.getElementsByTagName("td"),i; for(i=0; i<td.length;i++){ if(td[i].className== "catbg" && td[i].firstChild.document.getElementsByTagName("a")){ var tdid= td[i].firstChild.name; td[i].id=tdid; }} </script> td .firstChild.document.getElementsByTagName("a")[0] && td.firstChild.getElementsByTagName("a")[0].name )
var tdid= td.firstChildgetElementsByTagName('a')[0].name;I've tried this method and can't seem to find the problem. I completely understand you are trying to help make this more efficient and I understand that I'm most likely missing something here, So in regards to that I just want to clear the fact that I'm not being hard-headed or anything of that nature when I tell you that my code worked. I know for you to add your input as you did that you feel that it wasn't efficient even though it worked. And I trust your opinion.But I am still genuinely curious to why it isn't. But here's the code with your method. What am I missing? <script type= "text/javascript"> //Individual Category Styles //PLacement: Footers var td= document.getElementsByTagName("td"),i; for(i=0; i<td.length;i++){ if(td[i].className== "catbg" && td[i].firstChild.getElementsByTagName("a")[0] && td[i].firstChild.getElementsByTagName("a")[0].name )){ var tdid= td[i].getElementsByTagName("a")[0].name; td[i].id=tdid; }} </script>
|
|
|
Post by Wormopolis on Aug 21, 2012 15:53:05 GMT -8
remove the firstChild out of the if statement too. I should have struck that out.
and yes, it worked the way you had it, but part of coding is trying to make things efficient. breaking out fo a for loop if you can, reducing for loops that are unnecessary, and using things like function calls and recursion when possible to make the code run faster. the smaller a code is, the less time it takes to load it as well. Even I occasionally make revisions to older codes to try and streamline them a bit more.
sometimes making these changes will require retesting.
|
|
game
Junior Member
Code Digger
Posts: 59
game said 0 great things
|
Post by game on Aug 22, 2012 14:11:04 GMT -8
[replyingto=admin]%3CFONT%20color%3D%23ff5500%3EWormopoli%3CFONT%20color%3D%23ffffff%3Es%3C/FONT%3E%3C/FONT%3E[/replyingto]OK, i figured it out. There were a few firstChilds that needed excluded and the there was an extra ) that snuck in the argument.
<script type= "text/javascript"> //Individual Category Styles //PLacement: Footers var td= document.getElementsByTagName("td"),i; for(i=0; i<td.length;i++){ if(td[i].className== "catbg" && td[i].getElementsByTagName("a")[0] && td[i].getElementsByTagName("a")[0].name){ var tdid= td[i].getElementsByTagName("a")[0].name; td[i].id=tdid; }} </script>
And I believe this is ready to be submitted? I didn't include a creator since you basically talked me through the whole process.
|
|
|
Post by Wormopolis on Aug 22, 2012 16:04:54 GMT -8
you did the typing, you get to take credit
|
|