~launchpad-pqm/launchpad/devel

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
YUI.add('lp.app.privacy', function(Y) {

var namespace = Y.namespace('lp.app.privacy');
/*
 * Display privacy notifications
 *
 * This should be called after the page has loaded e.g. on 'domready'.
 */

function setup_privacy_notification(config) {
    var notification_text = 'The information on this page is private';
    var hidden = true;
    var target_id = "maincontent";
    if (config !== undefined) {
        if (config.notification_text !== undefined) {
            notification_text = config.notification_text;
        }
        if (config.hidden !== undefined) {
            hidden = config.hidden;
        }
        if (config.target_id !== undefined) {
            target_id = config.target_id;
        }
    }
    var id_selector = "#" + target_id;
    var main = Y.one(id_selector);
    var notification = Y.Node.create('<div></div>')
        .addClass('global-notification');
    if (hidden) {
        notification.addClass('hidden');
    }
    var notification_span = Y.Node.create('<span></span>')
        .addClass('sprite')
        .addClass('notification-private');
    var close_link = Y.Node.create('<a></a>')
        .addClass('global-notification-close')
        .set('href', '#');
    var close_span = Y.Node.create('<span></span>')
        .addClass('sprite')
        .addClass('notification-close');

    notification.set('text', notification_text);
    close_link.set('text', "Hide");

    main.appendChild(notification);
    notification.appendChild(notification_span);
    notification.appendChild(close_link);
    close_link.appendChild(close_span);

}
namespace.setup_privacy_notification = setup_privacy_notification;

function display_privacy_notification(highlight_portlet_on_close) {
    /* Check if the feature flag is set for this notification. */
    var highlight = true;
    if (highlight_portlet_on_close !== undefined) {
        highlight = highlight_portlet_on_close;
    }
    if (privacy_notification_enabled) {
        /* Set a temporary class on the body for the feature flag,
         this is because we have no way to use feature flags in
         css directly. This should be removed if the feature
         is accepted. */
        var body = Y.one('body');
        body.addClass('feature-flag-bugs-private-notification-enabled');
        /* Set the visible flag so that the content moves down. */
        body.addClass('global-notification-visible');

        var global_notification = Y.one('.global-notification');
        if (global_notification.hasClass('hidden')) {
            global_notification.addClass('transparent');
            global_notification.removeClass('hidden');

            var fade_in = new Y.Anim({
                node: global_notification,
                to: {opacity: 1},
                duration: 0.3
            });
            var body_space = new Y.Anim({
                node: 'body',
                to: {'paddingTop': '40px'},
                duration: 0.2,
                easing: Y.Easing.easeOut
            });
            var login_space = new Y.Anim({
                node: '.login-logout',
                to: {'top': '45px'},
                duration: 0.2,
                easing: Y.Easing.easeOut
            });

            fade_in.run();
            body_space.run();
            login_space.run();
        }

        Y.one('.global-notification-close').on('click', function(e) {
            hide_privacy_notification(highlight);
            e.halt();
        });
    }
}
namespace.display_privacy_notification = display_privacy_notification;

/*
 * Hide privacy notifications
 *
 * This should be called after the page has loaded e.g. on 'domready'.
 */
function hide_privacy_notification(highlight_portlet) {
    if (privacy_notification_enabled) {
        if (!Y.one('.global-notification').hasClass('hidden')) {
            var fade_out = new Y.Anim({
                node: '.global-notification',
                to: {opacity: 0},
                duration: 0.3
            });
            var body_space = new Y.Anim({
                node: 'body',
                to: {'paddingTop': 0},
                duration: 0.2,
                easing: Y.Easing.easeOut
            });
            var login_space = new Y.Anim({
                node: '.login-logout',
                to: {'top': '6px'},
                duration: 0.2,
                easing: Y.Easing.easeOut
            });
            fade_out.on('end', function() {
                fade_out.get('node').addClass('hidden');
            });
            body_space.on('end', function() {
                Y.one('body').removeClass('global-notification-visible');
            });

            fade_out.run();
            body_space.run();
            login_space.run();

            if (highlight_portlet) {
                var portlet_colour = new Y.Anim({
                    node: '.portlet.private',
                    to: {
                        color: '#fff',
                        backgroundColor:'#8d1f1f'
                    },
                    duration: 0.4
                });
                portlet_colour.run();
            }
        }
    }
}
namespace.hide_privacy_notification = hide_privacy_notification;


}, "0.1", {"requires": ["base", "node", "anim"]});