Nicht angemeldet. · Kennwort vergessen · Registrierung deaktiviert
Forum: Übersicht Files & Mods / Datein & Mods RSS
Bugfix category-selector
Sometimes the category-selector (javascript) does not work, this patch fixes it.
gw #1
Mitglied seit 07/2009 · 5 Beiträge
Gruppenmitgliedschaften: Mitglieder
Profil anzeigen · Link auf diesen Beitrag
Betreff: Bugfix category-selector
Issue
Under some circumstances, the category selector selects more categories than he should.

Example

[Bild: 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.

[Bild: 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
Benutzertitel: Author
Mitglied seit 06/2007 · 928 Beiträge
Gruppenmitgliedschaften: Administratoren, Mitglieder
Profil anzeigen · Link auf diesen Beitrag
Cheers! Thanks a lot!
Schließen Kleiner – Größer + Auf diesen Beitrag antworten:
Prüfcode: VeriCode Gib bitte das Wort aus dem Bild ins folgende Textfeld ein. (Nur die Buchstaben eingeben, Kleinschreibung ist in Ordnung.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Weitere Zeichen:
Gehe zu Forum