From 167dd22eefeeeb9c1eaebd990a4f5902bd366302 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Mon, 29 Aug 2016 09:50:00 -0400 Subject: PLT-1752/PLT-3567/PLT-3998 Highlighting links in search, unit tests for autolinking (#3865) * Added highlighting to links when their URL includes the search term * Decoupling UserStore from react-router to allow for unit tests involving it * PLT-3998 Added SiteURL as an option to be passed into the text formatting code * Removed reference to PreferenceStore and window from TextFormatting * Refactored TextFormatting to remove remaining browser-only code * Updated ChannelHeader and MessageWrapper to match the changes to TextFormatting * Increased max listeners for Preference and Emoji stores * PLT-3832 Added automated unit tests for autolinking * PLT-3567 Rerender posts when mention keywords change * Updated RHS and search to match the changes to TextFormatting * Broke TextFormatting's dependency on the UserStore --- webapp/utils/utils.jsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'webapp/utils/utils.jsx') diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx index a880c1783..3059ce529 100644 --- a/webapp/utils/utils.jsx +++ b/webapp/utils/utils.jsx @@ -1344,3 +1344,27 @@ export function isValidPassword(password) { export function getSiteURL() { return global.mm_config.SiteURL || window.location.origin; } + +export function handleFormattedTextClick(e) { + const mentionAttribute = e.target.getAttributeNode('data-mention'); + const hashtagAttribute = e.target.getAttributeNode('data-hashtag'); + const linkAttribute = e.target.getAttributeNode('data-link'); + + if (mentionAttribute) { + e.preventDefault(); + + searchForTerm(mentionAttribute.value); + } else if (hashtagAttribute) { + e.preventDefault(); + + searchForTerm(hashtagAttribute.value); + } else if (linkAttribute) { + const MIDDLE_MOUSE_BUTTON = 1; + + if (!(e.button === MIDDLE_MOUSE_BUTTON || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) { + e.preventDefault(); + + browserHistory.push(linkAttribute.value); + } + } +} \ No newline at end of file -- cgit v1.2.3-1-g7c22