js_header_functions

NAML documentation   Watch a video
   Usages of this macro
... in js_header_functions.naml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<override_macro name="js_header_functions" requires="servlet">
    var t_login = "<t>Login</t>";
    var t_register = "<t>Register</t>";
    var t_logout = "<t>Log out</t>";
    var t_my_posts = "<t>My posts</t>";
    var t_account_settings = "<t>Account settings</t>";
    var t_show_nabble_notice = "<t>Show Nabble notice</t>";
    var t_permalink = "<t>Link</t>";
    var t_refresh = "<t>Refresh</t>";
    var login_path = "<n.login_path
Macro
Parameters: nextUrl, message
/>";
    var logout_path = "<n.logout_path
Macro
/>";
    var register_path = "<n.register_path
Macro
Parameters: nextUrl
/>";
    var user_profile_path = "<n.user_profile_path
Macro
/>";
    <![CDATA[
    Nabble.userId = Nabble.getCookie("userId");
    var encodedUsername = Nabble.getCookie("username");
    if (encodedUsername) {
        Nabble.username = decodeURIComponent(encodedUsername)
            .replace(new RegExp('\\+','g'),' ');
    }
 
    if (!Nabble.userId) {
        Nabble.anonymousId = Nabble.getCookie("anonymousId");
        var encodedName = Nabble.getCookie("anonymousName");
        if (encodedName) {
            Nabble.anonymousName = decodeURIComponent(encodedName)
                .replace(new RegExp('\\+','g'),' ')
                .replace(new RegExp('<','g'),'&lt;')
                .replace(new RegExp('>','g'),'&gt;');
        }
    }
 
    Nabble.embedPermalink = function(url) {
        if (!Nabble.isEmbedded)
            return url;
        return url.replace(/(;|&)cid=(\d|\-)+/g, '').replace(/\?cid=(\d|\-)+(&)?/g, '?');
    };
 
    Nabble.getPermalink = function() {
        return Nabble.embedPermalink(
            Nabble.overridePermalink? Nabble.overridePermalink : Nabble.getParent().nabbleiframe.location.href);
    };
 
    Nabble.permalinkLabel = function() {
        if (!Nabble.isEmbedded)
            return '';
        var p = "<script>function openPermalink() { prompt('Copy this:', Nabble.getPermalink()); };</script>";
        p += "<a href='javascript: void openPermalink();'>"+t_permalink+"</a>&nbsp;&nbsp;";
        return p;
    };
 
    Nabble.refreshLabel = function() {
        if (Nabble.isEmbedded)
            return "<a href='javascript: location.reload(true);'>"+t_refresh+"</a>&nbsp;&nbsp;";
        return '';
    };
 
    Nabble.siteHeader = function() {
        var s = Nabble.refreshLabel();
        s += Nabble.permalinkLabel();
        if (!Nabble.userId) {
            var nextUrl = typeof loginNextUrl == 'undefined'? window.location.href : loginNextUrl;
            s += '<a href="'+login_path+'&nextUrl='+encodeURIComponent(nextUrl)+'">'+t_login+'</a>';
            s += '&nbsp;&nbsp;';
            s += '<a href="'+register_path+'&nextUrl='+encodeURIComponent(nextUrl)+'">'+t_register+'</a>';
            if (Nabble.anonymousId && Nabble.anonymousName) {
                s += '&nbsp;&nbsp;';
                s += '<a href="/template/NamlServlet.jtp?macro=user_nodes&user=' + Nabble.anonymousId + '~' + Nabble.anonymousName + '">';
                s += Nabble.anonymousName;
                s += '</a>';
            }
        } else
            s += '<span id="user-dd"></span>';
        return s;
    };
 
    Nabble.userDropdown = function() {
        var $t = $('#user-dd');
        if ($t.size() == 0)
            return;
        $t.empty();
        var dropdown = new NabbleDropdown('usrdd', Nabble.escapeHTML(Nabble.username));
        dropdown.add('myPosts','<a href="/template/NamlServlet.jtp?macro=user_nodes&user='+Nabble.userId + '">'+t_my_posts+'</a>');
        dropdown.add('personalSettings','<a href="'+user_profile_path+'">'+t_account_settings+'</a>');
        dropdown.add('adminNotice','<a href="javascript: void Nabble.showAdminNotice()">'+t_show_nabble_notice+'</a>','display:none');
        dropdown.add('logout','<a href="javascript: void Nabble.logout()">'+t_logout+'</a>');
        $t.html(dropdown.getHtml());
        dropdownInit('usrdd');
    };
 
    Nabble.addUserHeaderListener(function() {
        Nabble.userDropdown();
    });
 
    Nabble.showAdminNotice = function() {
        Nabble.deleteCookie('admin-notice');
        window.location.reload();
    };
 
    Nabble.logout = function() {
        window.location = '/template/NamlServlet.jtp?macro=logout_page' + Nabble.getClientID();
    };
    ]]>
</override_macro>
Overrides default macro
... in javascript_library.naml
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
<macro name="js_header_functions" requires="servlet">
    var t_login = "<t>Login</t>";
    var t_register = "<t>Register</t>";
    var t_logout = "<t>Log out</t>";
    var t_my_posts = "<t>My posts</t>";
    var t_account_settings = "<t>Account settings</t>";
    var t_show_nabble_notice = "<t>Show Nabble notice</t>";
    var t_permalink = "<t>Permalink</t>";
    var t_refresh = "<t>Refresh</t>";
    var login_path = "<n.login_path/>";
    var logout_path = "<n.logout_path/>";
    var register_path = "<n.register_path/>";
    var user_profile_path = "<n.user_profile_path/>";
    <![CDATA[
    Nabble.userId = Nabble.getCookie("userId");
    var encodedUsername = Nabble.getCookie("username");
    if (encodedUsername) {
        Nabble.username = decodeURIComponent(encodedUsername)
            .replace(new RegExp('\\+','g'),' ');
    }
 
    if (!Nabble.userId) {
        Nabble.anonymousId = Nabble.getCookie("anonymousId");
        var encodedName = Nabble.getCookie("anonymousName");
        if (encodedName) {
            Nabble.anonymousName = decodeURIComponent(encodedName)
                .replace(new RegExp('\\+','g'),' ')
                .replace(new RegExp('<','g'),'&lt;')
                .replace(new RegExp('>','g'),'&gt;');
        }
    }
 
    Nabble.embedPermalink = function(url) {
        if (!Nabble.isEmbedded)
            return url;
        return url.replace(/(;|&)cid=(\d|\-)+/g, '').replace(/\?cid=(\d|\-)+(&)?/g, '?');
    };
 
    Nabble.getPermalink = function() {
        return Nabble.embedPermalink(
            Nabble.overridePermalink? Nabble.overridePermalink : Nabble.getParent().nabbleiframe.location.href);
    };
 
    Nabble.permalinkLabel = function() {
        if (!Nabble.isEmbedded)
            return '';
        var p = "<script>function openPermalink() { prompt('Copy this:', Nabble.getPermalink()); };</script>";
        p += "<a href='javascript: void openPermalink();'>"+t_permalink+"</a>&nbsp;&nbsp;";
        return p;
    };
 
    Nabble.refreshLabel = function() {
        if (Nabble.isEmbedded)
            return "<a href='javascript: location.reload(true);'>"+t_refresh+"</a>&nbsp;&nbsp;";
        return '';
    };
 
    Nabble.siteHeader = function() {
        var s = Nabble.refreshLabel();
        s += Nabble.permalinkLabel();
        if (!Nabble.userId) {
            var nextUrl = typeof loginNextUrl == 'undefined'? window.location.href : loginNextUrl;
            s += '<a href="'+login_path+'&nextUrl='+encodeURIComponent(nextUrl)+'">'+t_login+'</a>';
            s += '&nbsp;&nbsp;';
            s += '<a href="'+register_path+'&nextUrl='+encodeURIComponent(nextUrl)+'">'+t_register+'</a>';
            if (Nabble.anonymousId && Nabble.anonymousName) {
                s += '&nbsp;&nbsp;';
                s += '<a href="/template/NamlServlet.jtp?macro=user_nodes&user=' + Nabble.anonymousId + '~' + Nabble.anonymousName + '">';
                s += Nabble.anonymousName;
                s += '</a>';
            }
        } else
            s += '<span id="user-dd"></span>';
        return s;
    };
 
    Nabble.userDropdown = function() {
        var $t = $('#user-dd');
        if ($t.size() == 0)
            return;
        $t.empty();
        var dropdown = new NabbleDropdown('usrdd', Nabble.escapeHTML(Nabble.username));
        dropdown.add('myPosts','<a href="/template/NamlServlet.jtp?macro=user_nodes&user='+Nabble.userId + '">'+t_my_posts+'</a>');
        dropdown.add('personalSettings','<a href="'+user_profile_path+'">'+t_account_settings+'</a>');
        dropdown.add('adminNotice','<a href="javascript: void Nabble.showAdminNotice()">'+t_show_nabble_notice+'</a>','display:none');
        dropdown.add('logout','<a href="javascript: void Nabble.logout()">'+t_logout+'</a>');
        $t.html(dropdown.getHtml());
        dropdownInit('usrdd');
    };
 
    Nabble.addUserHeaderListener(function() {
        Nabble.userDropdown();
    });
 
    Nabble.showAdminNotice = function() {
        Nabble.deleteCookie('admin-notice');
        window.location.reload();
    };
 
    Nabble.logout = function() {
        window.location = '/template/NamlServlet.jtp?macro=logout_page' + Nabble.getClientID();
    };
    ]]>
</macro>