diff --git a/src/pyj/book_list/comments_editor.pyj b/src/pyj/book_list/comments_editor.pyj index 2dd51a73d7..795537dc48 100644 --- a/src/pyj/book_list/comments_editor.pyj +++ b/src/pyj/book_list/comments_editor.pyj @@ -8,6 +8,7 @@ from book_list.theme import color_scheme, get_color, get_color_as_rgba from dom import add_extra_css, build_rule, clear, ensure_id, svgicon from gettext import gettext as _ from iframe_comm import IframeClient, create_wrapped_iframe +from image_popup import fit_image from modals import create_custom_dialog from utils import html_escape from uuid import short_uuid4 @@ -75,10 +76,23 @@ def insert_image(editor): if accepted and img.src: align = parent.querySelector(f'input[name="{align_name}"]:checked').value s = style_from_align(align) - markup = ( - f'' - ) + + w = parseInt(parent.querySelector(f'input[name="width"]').value or '0') + page_width = (0 if isNaN(w) else w) or 1000000000 + h = parseInt(parent.querySelector(f'input[name="height"]').value or '0') + page_height = (0 if isNaN(h) else h) or 1000000000 + w, h = img.naturalWidth, img.naturalHeight + resized, nw, nh = fit_image(w, h, page_width, page_height) + if resized: + markup = ( + f'' + ) + else: + markup = ( + f'' + ) editor.exec_command('insertHTML', markup) def dialog(parent, close_modal): @@ -99,6 +113,7 @@ def insert_image(editor): def handle_files(files): parent.querySelector('.no-image-selected').style.display = 'none' parent.querySelector('.image-alignment').style.display = 'none' + parent.querySelector('.image-shrink').style.display = 'none' img = parent.getElementsByTagName('img')[0] img.src = '' img.dataset.filename = '' @@ -117,6 +132,7 @@ def insert_image(editor): if f.name: img.dataset.filename = f.name parent.querySelector('.image-alignment').style.display = 'block' + parent.querySelector('.image-shrink').style.display = 'block' return alert(_('No valid image file found')) @@ -160,6 +176,17 @@ def insert_image(editor): ' ', E.label(E.input(type='radio', name=align_name, value='right'), _('Float right')), ), + E.div( + style='display: none; margin-top: 0.5rem', class_='image-shrink', + _('Shrink image to fit (px):'), + E.div(style='display: flex; flex-wrap: wrap', + E.label(_('Width:') + '\xa0', E.input(type='number', min='0', max='10000', name='width'), + style='margin-left: 0.5rem', title=_('A value of zero means no effect')), + E.label(_('Height:') + '\xa0', E.input(type='number', min='0', max='10000', name='height'), + style='margin-left: 0.5rem', title=_('A value of zero means no effect') + )), + ), + E.p(_('No image selected!'), class_='no-image-selected', style='color:red; display:none'), ), ),