Skip to content

Commit f06de6c

Browse files
committed
Libdoc: Persistent shortcut/tag list styles.
See issue robotframework#3635 and PR robotframework#3634 for more details.
1 parent ab04045 commit f06de6c

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/robot/htmldata/libdoc/libdoc.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ a:hover {
4343
font-weight: normal !important;
4444
letter-spacing: 0 !important;
4545
}
46-
.list-style-toggle {
46+
.shortcut-list-toggle, .tag-list-toggle {
4747
margin-bottom: 1em;
4848
font-size: 0.9em;
4949
}

src/robot/htmldata/libdoc/libdoc.html

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<link rel="stylesheet" type="text/css" href="print.css" media="print">
1313
<link rel="stylesheet" type="text/css" href="../common/js_disabled.css" media="all">
1414
<link rel="stylesheet" type="text/css" href="../common/doc_formatting.css" media="all">
15+
<script type="text/javascript" src="../common/storage.js"></script>
1516
<script type="text/javascript" src="../rebot/util.js"></script> <!-- TODO: Should util.js be moved under common? -->
1617
<script type="text/javascript" src="../lib/jquery.min.js"></script>
1718
<script type="text/javascript" src="../lib/jquery.tmpl.min.js"></script>
@@ -39,13 +40,16 @@ <h1>Opening library documentation failed</h1>
3940
$(document).ready(function() {
4041
parseTemplates();
4142
document.title = libdoc.name;
43+
storage.init('libdoc');
4244
renderTemplate('base', libdoc, $('body'));
4345
if (libdoc.inits.length) {
4446
renderTemplate('importing', libdoc);
4547
}
4648
renderTemplate('shortcuts', libdoc);
49+
initShortcutListStyle('shortcut');
4750
if (libdoc.contains_tags) {
4851
renderTemplate('tags', libdoc);
52+
initShortcutListStyle('tag');
4953
}
5054
renderTemplate('keywords', libdoc);
5155
renderTemplate('footer', libdoc);
@@ -81,9 +85,17 @@ <h1>Opening library documentation failed</h1>
8185
$('.shortcuts a').width('max-content');
8286
}
8387

84-
function toggleListStyle(locator) {
85-
var separator = $(locator).text()[0];
86-
$(locator).html(separator == '\u00b7' ? '<br>' : '&middot;');
88+
function initShortcutListStyle(name) {
89+
if (storage.get(name + '-list-style', 'compact') != 'compact') {
90+
$('.' + name + '-list-separator').html('<br>');
91+
$('.' + name + '-list-toggle .switch').prop('checked', true);
92+
}
93+
}
94+
95+
function setShortcutListStyle(name) {
96+
var compact = !$('.' + name + '-list-toggle .switch').prop('checked');
97+
$('.' + name + '-list-separator').html(compact ? '&middot;' : '<br>');
98+
storage.set(name + '-list-style', compact ? 'compact' : 'expanded');
8799
}
88100

89101
function handleKeyDown(event) {
@@ -325,10 +337,10 @@ <h2 id="Importing">Importing</h2>
325337
<script type="text/x-jquery-tmpl" id="shortcuts-template">
326338
<h2 id="Shortcuts">Shortcuts</h2>
327339
{{if keywords.length > 3}}
328-
<div class="list-style-toggle">
340+
<div class="shortcut-list-toggle">
329341
<b>List style:</b>&nbsp; Compact
330342
<label title="Switch between compact list and expanded list">
331-
<input type="checkbox" class="switch" onclick="toggleListStyle('.shortcut-separator');">
343+
<input type="checkbox" class="switch" onclick="setShortcutListStyle('shortcut');">
332344
<span class="slider"></span>
333345
</label>
334346
Expanded
@@ -340,7 +352,7 @@ <h2 id="Shortcuts">Shortcuts</h2>
340352
class="{{if $value.matched === false}}no-{{/if}}match"
341353
title="${$value.shortdoc}">${$value.name}</a>
342354
{{if $index < keywords.length-1}}
343-
<span class="shortcut-separator">&middot;</span>
355+
<span class="shortcut-list-separator">&middot;</span>
344356
{{/if}}
345357
{{/each}}
346358
</div>
@@ -349,10 +361,10 @@ <h2 id="Shortcuts">Shortcuts</h2>
349361
<script type="text/x-jquery-tmpl" id="tags-template">
350362
<h2 id="Tags">Tags</h2>
351363
{{if all_tags.length > 3}}
352-
<div class="list-style-toggle">
364+
<div class="tag-list-toggle">
353365
<b>List style:</b>&nbsp; Compact
354366
<label title="Switch between compact list and expanded list">
355-
<input type="checkbox" class="switch" onclick="toggleListStyle('.tag-separator');">
367+
<input type="checkbox" class="switch" onclick="setShortcutListStyle('tag');">
356368
<span class="slider"></span>
357369
</label>
358370
Expanded
@@ -362,7 +374,7 @@ <h2 id="Tags">Tags</h2>
362374
{{each all_tags}}
363375
<a href="javascript:tagSearch('${$value}')"
364376
title="Show keywords with this tag">${$value}</a>
365-
<span class="tag-separator">&middot;</span>
377+
<span class="tag-list-separator">&middot;</span>
366378
{{/each}}
367379
<a href="javascript:resetKeywords()" class="normal-first-letter"
368380
title="Show all keywords">[Reset]</a>

0 commit comments

Comments
 (0)