Not logged in. · Lost password · Registration disabled
Forum: Overview Files & Mods / Datein & Mods RSS
Bugfix category-selector
Sometimes the category-selector (javascript) does not work, this patch fixes it.
gw #1
Member since Jul 2009 · 5 posts
Group memberships: Mitglieder
Show profile · Link to this post
Subject: Bugfix category-selector
Issue
Under some circumstances, the category selector selects more categories than he should.

Example

[Image: http://www.gwegner.de/wp-content/images/forum/pn.png]

In this case for me clicking on the topmost checkbox "News" as well selects the whole subtree on "Störungen".

I managed to debug this one and will share the solution with you - and hope, the author will incorporate it into the next version.

Background

there is a somewhat "interesting" javascript logic turning the checkboxes on and off.

[Image: http://www.gwegner.de/wp-content/images/forum/pn_error.png]

It checks for the category Id and assumes, the category has ended, when the substring cat.0.1 changes.
In this case however (see example) this substring is not changing, although the parent categroy does. The reason ist, that the ID of next category "16" begins with "1". That's the problem when using strings for numbers...

Solution

Okay and here we go with the solution:

Exchange the contents of your pncats.js file with the following code:

var post_notification_running = false;
var post_notification_box = new Array();

function post_notification_cats_init(){
    var boxes =  document.getElementsByTagName("input");
    var tocheck = "";
    var i;
    if(post_notification_running) return;
    post_notification_running = true;
   
   
    for(i = 0; i < boxes.length; i++){
        if(boxes[i].id.substr(0, 4)== "cat."){
            if(boxes[i].disabled == true){
                boxes[i].checked = post_notification_box[i];
                boxes[i].disabled = false;   
            }
        }
    }
   
   
    for(i = 0; i < boxes.length; i++){
        if(boxes[i].id.substr(0, 4)== "cat."){
            if(tocheck != ""){
                // hack by gwegner.de
                if((boxes[i].id.substr(0, tocheck.length) == tocheck)
                  && (boxes[i].id.length > tocheck.length)
                  && (boxes[i].id.substr(tocheck.length, 1) == "."))
                // end of hack 
                {
                    post_notification_box[i]  = boxes[i].checked;
                    boxes[i].checked = true;
                    boxes[i].disabled = true;
                } else {
                    tocheck = "";
                }
            }
           
            if(tocheck == ""){ //There is no string
                if(boxes[i].checked == true){
                    tocheck = boxes[i].id; //From now on this is the new String
                }
            }
        }
    }
    post_notification_running = false;
}


function post_notification_cats_change(){

}

regards
gw
Morty (Administrator) #2
User title: Author
Member since Jun 2007 · 928 posts
Group memberships: Administratoren, Mitglieder
Show profile · Link to this post
Cheers! Thanks a lot!
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum