mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	zoom for the attachment images
This commit is contained in:
		
							parent
							
								
									fed5f1a7d2
								
							
						
					
					
						commit
						5f6fded833
					
				
							
								
								
									
										2
									
								
								libraries/wheel-zoom.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								libraries/wheel-zoom.min.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -35,7 +35,7 @@ async function getRenderedContent(entity, options = {}) {
 | 
				
			|||||||
        await renderCode(entity, options, $renderedContent);
 | 
					        await renderCode(entity, options, $renderedContent);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (type === 'image') {
 | 
					    else if (type === 'image') {
 | 
				
			||||||
        renderImage(entity, $renderedContent);
 | 
					        renderImage(entity, $renderedContent, options);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (!options.tooltip && ['file', 'pdf', 'audio', 'video'].includes(type)) {
 | 
					    else if (!options.tooltip && ['file', 'pdf', 'audio', 'video'].includes(type)) {
 | 
				
			||||||
        renderFile(entity, type, $renderedContent);
 | 
					        renderFile(entity, type, $renderedContent);
 | 
				
			||||||
@ -118,7 +118,7 @@ async function renderCode(note, options, $renderedContent) {
 | 
				
			|||||||
    $renderedContent.append($("<pre>").text(trim(blob.content, options.trim)));
 | 
					    $renderedContent.append($("<pre>").text(trim(blob.content, options.trim)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function renderImage(entity, $renderedContent) {
 | 
					function renderImage(entity, $renderedContent, options = {}) {
 | 
				
			||||||
    const sanitizedTitle = entity.title.replace(/[^a-z0-9-.]/gi, "");
 | 
					    const sanitizedTitle = entity.title.replace(/[^a-z0-9-.]/gi, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let url;
 | 
					    let url;
 | 
				
			||||||
@ -129,11 +129,27 @@ function renderImage(entity, $renderedContent) {
 | 
				
			|||||||
        url = `api/attachments/${entity.attachmentId}/image/${sanitizedTitle}?${entity.utcDateModified}">`;
 | 
					        url = `api/attachments/${entity.attachmentId}/image/${sanitizedTitle}?${entity.utcDateModified}">`;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $renderedContent.append(
 | 
					    $renderedContent // styles needed for the zoom to work well
 | 
				
			||||||
        $("<img>")
 | 
					        .css('display', 'flex')
 | 
				
			||||||
 | 
					        .css('align-items', 'center')
 | 
				
			||||||
 | 
					        .css('justify-content', 'center');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const $img = $("<img>")
 | 
				
			||||||
        .attr("src", url)
 | 
					        .attr("src", url)
 | 
				
			||||||
            .css("max-width", "100%")
 | 
					        .attr("id", "attachment-image-" + idCounter++)
 | 
				
			||||||
    );
 | 
					        .css("max-width", "100%");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $renderedContent.append($img);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (options.imageHasZoom) {
 | 
				
			||||||
 | 
					        libraryLoader.requireLibrary(libraryLoader.WHEEL_ZOOM).then(() => {
 | 
				
			||||||
 | 
					            WZoom.create(`#${$img.attr("id")}`, {
 | 
				
			||||||
 | 
					                maxScale: 10,
 | 
				
			||||||
 | 
					                speed: 20,
 | 
				
			||||||
 | 
					                zoomOnClick: false
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function renderFile(entity, type, $renderedContent) {
 | 
					function renderFile(entity, type, $renderedContent) {
 | 
				
			||||||
 | 
				
			|||||||
@ -167,7 +167,9 @@ export default class AttachmentDetailWidget extends BasicWidget {
 | 
				
			|||||||
        this.$wrapper.find('.attachment-details')
 | 
					        this.$wrapper.find('.attachment-details')
 | 
				
			||||||
            .text(`Role: ${this.attachment.role}, Size: ${utils.formatSize(this.attachment.contentLength)}`);
 | 
					            .text(`Role: ${this.attachment.role}, Size: ${utils.formatSize(this.attachment.contentLength)}`);
 | 
				
			||||||
        this.$wrapper.find('.attachment-actions-container').append(this.attachmentActionsWidget.render());
 | 
					        this.$wrapper.find('.attachment-actions-container').append(this.attachmentActionsWidget.render());
 | 
				
			||||||
        this.$wrapper.find('.attachment-content-wrapper').append((await contentRenderer.getRenderedContent(this.attachment)).$renderedContent);
 | 
					
 | 
				
			||||||
 | 
					        const {$renderedContent} = await contentRenderer.getRenderedContent(this.attachment, { imageHasZoom: true });
 | 
				
			||||||
 | 
					        this.$wrapper.find('.attachment-content-wrapper').append($renderedContent);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async copyAttachmentLinkToClipboard() {
 | 
					    async copyAttachmentLinkToClipboard() {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user