Skip to content

Commit c0410bf

Browse files
committed
Improve some modal styles
- use a similar font size for h1 than the rest (175% looked too big) - use inherit color from `rst-content` class - use h1 for modal title - default modal title option when there is no h1 in the content of modal - add option for default modal title - add option for modal prefix title - change max-width on mobile devices - add link to the content of the page in the title
1 parent 78d76d3 commit c0410bf

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

hoverxref/_static/css/micromodal.css

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
margin-top: 0;
3434
margin-bottom: 0;
3535
line-height: 1;
36-
font-size: 100%;
37-
color: #00449e;
36+
font-size: 165%;
3837
box-sizing: border-box;
3938
}
4039

@@ -43,13 +42,19 @@
4342
border: 0;
4443
}
4544

45+
.modal__footer {
46+
padding-bottom: 30px;
47+
/* display: ruby does not look really good here. However, I didn't
48+
find another way to merge footer padding with container padding
49+
instead of sum them */
50+
display: ruby;
51+
}
52+
4653
.modal__header .modal__close:before { content: "\2715"; }
4754

4855
.modal__content {
4956
margin-top: 2rem;
5057
margin-bottom: 2rem;
51-
line-height: 1.5;
52-
color: rgba(0,0,0,.8);
5358
}
5459

5560
.modal__btn {
@@ -59,7 +64,6 @@
5964
padding-top: .5rem;
6065
padding-bottom: .5rem;
6166
background-color: #e6e6e6;
62-
color: rgba(0,0,0,.8);
6367
border-radius: .25rem;
6468
border-style: none;
6569
border-width: 0;
@@ -102,7 +106,7 @@
102106
}
103107

104108
@keyframes mmslideOut {
105-
from { transform: translateY(0); }
109+
from { transform: translateY(0); }
106110
to { transform: translateY(-10%); }
107111
}
108112

@@ -134,3 +138,8 @@
134138
.micromodal-slide .modal__overlay {
135139
will-change: transform;
136140
}
141+
142+
@media screen and (max-width: 480px) {
143+
.modal__container {
144+
max-width: 90%;
145+
}

hoverxref/_static/js/hoverxref.js_t

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ $(document).ready(function() {
110110
<div class="modal__overlay" tabindex="-1" data-micromodal-close>
111111
<div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="micromodal-title">
112112
<header class="modal__header">
113-
<h2 class="modal__title" id="micromodal-title"></h2>
113+
<h1 class="modal__title" id="micromodal-title"></h1>
114114
<button class="modal__close" aria-label="Close modal" data-micromodal-close></button>
115115
</header>
116116
<main class="modal__content" id="micromodal-content"></main>
@@ -147,10 +147,18 @@ $(document).ready(function() {
147147
var content = $('<div></div>');
148148
content.html(data['content'][0]);
149149

150-
var title = $('h1', content)[0] || '';
151-
content.replaceWith('h1', '');
150+
var h1 = $('h1:first', content);
151+
var title = h1.text()
152+
if (title) {
153+
var link = $('a', h1).attr('href') || '#';
154+
var a = $('<a></a>').attr('href', link).text('{{ hoverxref_modal_prefix_title }}' + title.replace('¶', ''));
155+
}
156+
else {
157+
var a = '{{ hoverxref_modal_prefix_title }}{{ hoverxref_modal_default_title }}';
158+
}
159+
h1.replaceWith('');
152160

153-
$('#micromodal-title').html(title);
161+
$('#micromodal-title').html(a);
154162
$('#micromodal-content').html(content);
155163
MicroModal.show('micromodal', {
156164
disableScroll: false,

hoverxref/extension.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def setup(app):
124124
app.add_config_value('hoverxref_modal', False, 'env')
125125
app.add_config_value('hoverxref_modal_hover_delay', 350, 'env')
126126
app.add_config_value('hoverxref_modal_class', 'rst-content', 'env')
127+
app.add_config_value('hoverxref_modal_default_title', 'Note', 'env')
128+
app.add_config_value('hoverxref_modal_prefix_title', '📝 ', 'env')
127129

128130

129131
app.set_translator('html', HoverXRefHTMLTranslator, override=True)

0 commit comments

Comments
 (0)