Debian Codegraph @

os_api_ref/assets/api-site.js

raw symbols SCIP
1 window.onload = function() {
2 // the list of expanded element ids
3 var expanded = [];
4 // whether we should sync expand changes with the location
5 // url. We need to make this false during large scale
6 // operations because we're using the history API, which is
7 // expensive. So a bulk expand turns this off, expands
8 // everything, turns it back on, then does a history sync.
9 var should_sync = true;
10
11 $(document).ready(function() {
12 // Change the text on the expando buttons when
13 // appropriate. This also add or removes them to the list of
14 // expanded sections, and then syncs that list to the history
15 // after such a change.
16 $('.api-detail')
17 .on('hide.bs.collapse', function(e) {
18 processButton(this, 'detail');
19 var index = expanded.indexOf(this.id);
20 if (index > -1) {
21 expanded.splice(index, 1);
22 }
23 sync_expanded();
24 })
25 .on('show.bs.collapse', function(e) {
26 processButton(this, 'close');
27 expanded.push(this.id);
28 sync_expanded();
29 });
30
31 // Expand the world. Wires up the expand all button, it turns
32 // off the sync while it is running to save the costs with the
33 // history API.
34 var expandAllActive = true;
35 $('#expand-all').click(function () {
36 should_sync = false;
37 if (expandAllActive) {
38 expandAllActive = false;
39 $('.api-detail').collapse('show');
40 $('#expand-all').attr('data-toggle', '');
41 $(this).text('Hide All');
42 } else {
43 expandAllActive = true;
44 $('.api-detail').collapse('hide');
45 $('#expand-all').attr('data-toggle', 'collapse');
46 $(this).text('Show All');
47 }
48 should_sync = true;
49 sync_expanded();
50 });
51
52 // if there is an expanded parameter passed in a url, we run
53 // through and expand all the appropriate things.
54 if (window.location.search.substring(1).indexOf("expanded") > -1) {
55 should_sync = false;
56 var parts = window.location.search.substring(1).split('&');
57 for (var i = 0; i < parts.length; i++) {
58 var keyval = parts[i].split('=');
59 if (keyval[0] == "expanded" && keyval[1]) {
60 var expanded_ids = keyval[1].split(',');
61 for (var j = 0; j < expanded_ids.length; j++) {
62 $('#' + expanded_ids[j]).collapse('show');
63 }
64 }
65 }
66 should_sync = true;
67 // This is needed because the hash *might* be inside a
68 // collapsed section.
69 //
70 // NOTE(sdague): this doesn't quite seem to work while
71 // we're changing the rest of the document.
72 $(document.body).scrollTop($(window.location.hash).offset().top);
73 }
74
75 // Wire up microversion selector
76 $('.mv_selector').on('click', function(e) {
77 var version = e.currentTarget.innerHTML;
78 // flip what is active
79 $(this).addClass('active').siblings().removeClass('active');
80 if (version == "All") {
81 reset_microversion();
82 } else {
83 set_microversion(version);
84 }
85 });
86 });
87 /**
88 * Helper function for setting the text, styles for expandos
89 */
90 function processButton(button, text) {
91 $('#' + $(button).attr('id') + '-btn').text(text)
92 .toggleClass('btn-info')
93 .toggleClass('btn-default');
94 }
95
96 // Take the expanded array and push it into history. Because
97 // sphinx is building css appropriate ids, they should not have
98 // any special characters we need to encode. So we can simply join
99 // them into a comma separated list.
100 function sync_expanded() {
101 if (should_sync) {
102 var url = UpdateQueryString('expanded', expanded.join(','));
103 history.pushState('', 'new expand', url);
104 }
105 }
106
107
108 // Generically update the query string for a url. Credit to
109 // http://stackoverflow.com/questions/5999118/add-or-update-query-string-parameter
110 // for making this properly generic.
111 function UpdateQueryString(key, value, url) {
112 if (!url) url = window.location.href;
113 var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),
114 hash;
115
116 if (re.test(url)) {
117 if (typeof value !== 'undefined' && value !== null)
118 return url.replace(re, '$1' + key + "=" + value + '$2$3');
119 else {
120 hash = url.split('#');
121 url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
122 if (typeof hash[1] !== 'undefined' && hash[1] !== null)
123 url += '#' + hash[1];
124 return url;
125 }
126 }
127 else {
128 if (typeof value !== 'undefined' && value !== null) {
129 var separator = url.indexOf('?') !== -1 ? '&' : '?';
130 hash = url.split('#');
131 url = hash[0] + separator + key + '=' + value;
132 if (typeof hash[1] !== 'undefined' && hash[1] !== null)
133 url += '#' + hash[1];
134 return url;
135 }
136 else
137 return url;
138 }
139 }
140
141 // Set the Y value of the microversion to turn on / off visibility
142 // of components.
143 function set_microversion(number) {
144 var major = number.split(".")[0];
145 var micro = number.split(".")[1];
146 for (var i = os_min_mv; i <= os_max_mv; i++) {
147 var max_class = ".rp_max_ver_" + major + "_" + i;
148 var min_class = ".rp_min_ver_" + major + "_" + i;
149 if (i < micro) {
150 $(max_class).hide(400);
151 $(min_class).show(400);
152 } else if (i >= micro) {
153 $(min_class).hide(400);
154 $(max_class).show(400);
155 }
156 }
157 }
158
159 function reset_microversion() {
160 $('[class^=rp_min_ver]').show(400);
161 $('[class^=rp_max_ver]').show(400);
162 }
163
164 };