diff options
Diffstat (limited to 'web/react/utils/utils.jsx')
-rw-r--r-- | web/react/utils/utils.jsx | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index f19dd2b47..34a0d55da 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -289,7 +289,6 @@ function getYoutubeEmbed(link) { $('.video-uploader.' + youtubeId).html(metadata.channelTitle); $('.video-title.' + youtubeId).find('a').html(metadata.title); $('.post-list-holder-by-time').scrollTop($('.post-list-holder-by-time')[0].scrollHeight); - $('.post-list-holder-by-time').perfectScrollbar('update'); } if (config.GoogleDeveloperKey) { @@ -765,7 +764,7 @@ function switchChannel(channel, teammateName) { AsyncClient.getChannels(true, true, true); AsyncClient.getChannelExtraInfo(true); - AsyncClient.getPosts(true, channel.id, Constants.POST_CHUNK_SIZE); + AsyncClient.getPosts(channel.id); $('.inner__wrap').removeClass('move--right'); $('.sidebar--left').removeClass('move--right'); @@ -987,6 +986,58 @@ module.exports.isBrowserFirefox = function() { return navigator && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('firefox') > -1; }; +// Checks if browser is IE10 or IE11 +module.exports.isBrowserIE = function() { + if (window.navigator && window.navigator.userAgent) { + var ua = window.navigator.userAgent; + + return ua.indexOf('Trident/7.0') > 0 || ua.indexOf('Trident/6.0') > 0; + } + + return false; +}; + +module.exports.isBrowserEdge = function() { + return window.naviagtor && navigator.userAgent && navigator.userAgent.toLowerCase().indexOf('edge') > -1; +}; + +// Gets text length consistent with maxlength property of textarea html tag +module.exports.getLengthOfTextInTextarea = function(messageText) { + // Need to get length with carriage returns counting as two characters to match textbox maxlength behavior + // unless ie10/ie11/edge which already do + + var len = messageText.length; + if (!module.exports.isBrowserIE() && !module.exports.isBrowserEdge()) { + len = messageText.replace(/\r(?!\n)|\n(?!\r)/g, '--').length; + } + + return len; +}; + +module.exports.checkMessageLengthError = function(message, currentError, newError) { + var updatedError = currentError; + var len = module.exports.getLengthOfTextInTextarea(message); + + if (!currentError && len >= Constants.MAX_POST_LEN) { + updatedError = newError; + } else if (currentError === newError && len < Constants.MAX_POST_LEN) { + updatedError = ''; + } + + return updatedError; +}; + +// Necessary due to issues with textarea max length and pasting newlines +module.exports.truncateText = function(message) { + var lengthDifference = module.exports.getLengthOfTextInTextarea(message) - message.length; + + if (lengthDifference > 0) { + return message.substring(0, Constants.MAX_POST_LEN - lengthDifference); + } + + return message.substring(0, Constants.MAX_POST_LEN); +}; + // Used to get the id of the other user from a DM channel module.exports.getUserIdFromChannelName = function(channel) { var ids = channel.name.split('__'); |