PageSourceSearch

https://ispringhelpdocs.com/includes/js/page-children.js

js ispringhelpdocs.com collected 2026-10-04 12:49:40 UTC 6,109 bytes, 165 lines download raw bytes

1/**
2 * Load the child pages.
3 * @module confluence/page-children
4 */
5define('confluence/page-children', [
6    'jquery',
7    'ajs',
8    'raphael',
9    'confluence/api/constants'
10], function(
11    $,
12    AJS,
13    Raphael,
14    CONSTANTS
15) {
16    'use strict';
17
18    return function() {
19        var throbber;
20        var spinner;
21
22        /**
23         * Render a link to a child page. This will render the link using three different icons: 'icon-home-page' for the
24         * link to the home page, 'icon-recently-updated-page' for a page that as been recently updated or
25         * 'icon-page' for the default page icon.
26         *
27         * This is based on the 'contentLink2' macro defined in macros.vm
28         *
29         * @param page object
30         */
31        var renderLink = function(page) {
32            if (page.homePage) {
33                var title = AJS.I18n.getText('home.page');
34                return '<span class="child-display"><span class="icon icon-home-page" title="' + title + '">' + title + ':</span> <a href="' + CONSTANTS.CONTEXT_PATH + page.href + '">' + page.text + '</a></span>';
35            }
36            var cssClass = page.recentlyUpdated ? 'icon icon-recently-updated-page' : 'icon icon-page';
37            return '<span class="child-display"><span class="' + cssClass + '" title="Page">Page:</span> <a href="' + CONSTANTS.CONTEXT_PATH + page.href + '">' + AJS.escapeHtml(page.text) + '</a></span>';
38        };
39
40        /**
41         * Callback handler for the Ajax call.
42         *
43         * @param data - list of page objects
44         */
45        var onPageChildrenLoadSuccess = function(data) {
46            var container = $('#page-children:not(.children-loaded)');
47            hideThrobber();
48            if (data && container.length) {
49                if (data.errorMessage) {
50                    container.html('<span class=\'error\'>' + data.errorMessage + '</span>');
51                    return;
52                }
53                var html = [];
54                $.each(data, function(index, page) {
55                    html.push(renderLink(page));
56                });
57                container.html(html.join(''));
58                container.addClass('children-loaded');
59            }
60        };
61
62        /**
63         * Hide the loading indicator.
64         */
65        var hideThrobber = function() {
66            if (spinner) {
67                spinner();
68                spinner = null;
69            }
70            throbber.addClass('hidden');
71        };
72
73        /**
74         * Update the UserInterfaceState -> setChildrenShowing.
75         *
76         * @param showChildren (boolean)
77         */
78        var updateUserSetting = function(showChildren) {
79            AJS.safe.ajax({
80                url: CONSTANTS.CONTEXT_PATH + '/json/pagechildrenstoresettings.action',
81                type: 'POST',
82                data: { pageId: AJS.params.pageId, showChildren: showChildren },
83                success: function() {},
84                error: function(xhr, text) {
85                    AJS.log('Failed to store the user \'showChildren\' user setting: ' + text);
86                }
87            });
88        };
89
90        /**
91         * Attempt to load the child pages. This will load the child pages only once per page.
92         */
93        var loadChildren = function() {
94            var container = $('#page-children:not(.children-loaded)');
95            // Don't load the children list twice...
96            if (container.length) {
97                throbber = $('<div class=\'throbber\'></div>');
98                container.append(throbber);
99                spinner = Raphael.spinner(throbber[0], 10, '#666');
100
101                // Retrieve the list of children objects AND store the user setting
102                AJS.safe.ajax({
103                    url: CONSTANTS.CONTEXT_PATH + '/json/pagechildren.action',
104                    type: 'POST',
105                    data: { pageId: AJS.params.pageId, showChildren: true },
106                    success: onPageChildrenLoadSuccess,
107                    error: function(xhr, text, error) {
108                        var errorText = AJS.I18n.getText('page.children.error.load');
109                        hideThrobber();
110                        container.html('<span class=\'error\'>' + errorText + '</span>');
111                        AJS.log('Error retrieving child pages: ' + text);
112                    }
113                });
114            } else {
115                // If we don't load the children we still have to update the user interface state.
116                updateUserSetting(true);
117            }
118        };
119
120        /**
121         * Hide the list of page children and update the 'showChildren' settings in the background.
122         */
123        var hideChildren = function() {
124            $('#page-children').hide();
125            // Store setting
126            updateUserSetting(false);
127        };
128
129        /**
130         * Show the children. Load the child data if necessary.
131         */
132        var showChildren = function() {
133            $('#page-children').show();
134            // Attempt to load the children only if they are not visible already
135            if ($('#children-section:not(.children-showing)').length) {
136                loadChildren();
137            } else {
138                updateUserSetting(true);
139            }
140        };
141
142        $('#children-section a.children-show-hide').each(function() {
143            $(this).click(function(e) {
144                var container = $('#children-section');
145                if (container.hasClass('children-showing')) {
146                    hideChildren();
147                    container.removeClass('children-showing').addClass('children-hidden');
148                } else {
149                    showChildren();
150                    container.removeClass('children-hidden').addClass('children-showing');
151                }
152                e.stopPropagation();
153                return false;
154            });
155        });
156    };
157});
158
159require('confluence/module-exporter').safeRequire('confluence/page-children', function(PageChildren) {
160    'use strict';
161
162    var AJS = require('ajs');
163
164    AJS.toInit(PageChildren);
165});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.