GureWiki > Ezagutza partekatzen / Compartiendo conocimiento
GureWiki: "Ezagutza partekatzen / Compartiendo conocimiento"
Template:@neilw > HideElements
    Aurkibidea
    Goibururik ez
    // HideElements
    // by neilw, 2009-2011
    //
    // 1.10    3/22/2011   neilw    - added "ratings" option to hide page ratings
    //                              - accepts a single string arg rather than a list of one item
    // 1.00    8/3/2009    neilw    first release
    //
    // Usage:  HideElements(elements, byuser)
    //    elements:    list of strings OR "all".  If list of strings, each indicating an element to hide:
    //        "tags"          page tags
    //        "files"         list of attached files
    //        "images",       gallery of attached images
    //        "comments",     comments at bottom of page
    //        "ratings_top"   page ratings at top right corner of page
    //        "ratings_bot"   page ratings at bottom of page
    //        "ratings"       page ratings at top and bottom of page
    //        "all"           all of the above
    //    byuser:      hide the above elements only for users without write permission on the page
    //
    
    var allowed_elements = {
        tags:            "div.pageInfo",
        files:           "div.file",
        images:          "div.gallery",
        comments:        "div#comments",
        ratings_top:     "div#deki-page-rating-bar",
        ratings_bottom:  "dd.pageRatings,dt.pageRatings",
        ratings:         "div#deki-page-rating-bar,dd.pageRatings,dt.pageRatings"
    };
    
    var elements = $0 ?? $elements;
    if (elements is not list) let elements = [ elements ];
    var byuser = $1 ?? $byuser ?? false;
    
    var selectors = [];
    var errors = [];
    
    foreach (var e in elements) {
        if (e == "all") {
            let selectors = list.select(map.values(allowed_elements), "string.indexof($,'_')<0");
            break;
        }
        else if (e is not str || !#allowed_elements[e])
            let errors ..= [ e ];
        else
            let selectors ..= [ allowed_elements[e] ];
    }
    
    <html>
    if (#selectors && (!byuser || !wiki.pagepermissions().update)) {
        <head>
            <style type="text/css"> string.join(selectors, ",").."{ display:none; }" </style>;
        </head>;
    }
    if (#errors) {
        <body>
            <div>
                "ERROR: HidePageElements: bad element(s): " .. string.serialize(errors) .. "; allowed elements are:";
                <ul> foreach (var ae in map.keys(allowed_elements)) <li> ae </li>; </ul>;
            </div>;
        </body>;
    }
    </html>;
    

    Webgune hau MindTouch Core "DekiWiki" software askearekin dabil

    Hemengo edukiak Creative Commons BY-NC-SA baimen baten mende daude