mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-11-04 05:53:21 +00:00 
			
		
		
		
	internal-links: Open image link in webapp lightbox.
This will open the image in the webapp lightbox. It shows the same behaviour that happens when clicking on the image preview. Improves: #469.
This commit is contained in:
		
				
					committed by
					
						
						Akash Nimare
					
				
			
			
				
	
			
			
			
						parent
						
							6e7333eab6
						
					
				
				
					commit
					60d693700e
				
			@@ -4,6 +4,7 @@ const { ipcRenderer } = require('electron');
 | 
			
		||||
const SetupSpellChecker = require('./spellchecker');
 | 
			
		||||
 | 
			
		||||
const ConfigUtil = require(__dirname + '/utils/config-util.js');
 | 
			
		||||
const LinkUtil = require(__dirname + '/utils/link-util.js');
 | 
			
		||||
 | 
			
		||||
// eslint-disable-next-line import/no-unassigned-import
 | 
			
		||||
require('./notification');
 | 
			
		||||
@@ -55,6 +56,24 @@ document.addEventListener('DOMContentLoaded', () => {
 | 
			
		||||
			ipcRenderer.send('forward-message', 'reload-viewer');
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Open image attachment link in the lightbox instead of opening in the default browser
 | 
			
		||||
	const { $, lightbox } = window;
 | 
			
		||||
 | 
			
		||||
	$('#main_div').on('click', '.message_content p a', function (e) {
 | 
			
		||||
		const url = $(this).attr('href');
 | 
			
		||||
 | 
			
		||||
		if (LinkUtil.isImage(url)) {
 | 
			
		||||
			const $img = $(this).parent().siblings('.message_inline_image').find('img');
 | 
			
		||||
 | 
			
		||||
			// prevent the image link from opening in a new page.
 | 
			
		||||
			e.preventDefault();
 | 
			
		||||
			// prevent the message compose dialog from happening.
 | 
			
		||||
			e.stopPropagation();
 | 
			
		||||
 | 
			
		||||
			lightbox.open($img);
 | 
			
		||||
		}
 | 
			
		||||
	});
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Clean up spellchecker events after you navigate away from this page;
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,12 @@ class LinkUtil {
 | 
			
		||||
 | 
			
		||||
		return (currentDomain === newDomain) && newUrl.includes('/#narrow');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	isImage(url) {
 | 
			
		||||
		// test for images extension as well as urls like .png?s=100
 | 
			
		||||
		const isImageUrl = /\.(bmp|gif|jpg|jpeg|png|webp)\?*.*$/i;
 | 
			
		||||
		return isImageUrl.test(url);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = new LinkUtil();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user