diff --git a/packages/rocketchat-ui-master/client/main.coffee b/packages/rocketchat-ui-master/client/main.coffee deleted file mode 100644 index fc18fa599d36..000000000000 --- a/packages/rocketchat-ui-master/client/main.coffee +++ /dev/null @@ -1,253 +0,0 @@ -`import Clipboard from 'clipboard';` - -Template.body.onRendered -> - clipboard = new Clipboard('.clipboard') - - $(document.body).on 'keydown', (e) -> - if e.keyCode in [80, 75] and (e.ctrlKey is true or e.metaKey is true) and e.shiftKey is false - e.preventDefault() - e.stopPropagation() - toolbarSearch.focus(true) - - unread = Session.get('unread') - if e.keyCode is 27 and e.shiftKey is true and unread? and unread isnt '' - e.preventDefault() - e.stopPropagation() - swal - title: t('Clear_all_unreads_question') - type: 'warning' - confirmButtonText: t('Yes_clear_all') - showCancelButton: true - cancelButtonText: t('Cancel') - confirmButtonColor: '#DD6B55' - , -> - subscriptions = ChatSubscription.find({open: true}, { fields: { unread: 1, alert: 1, rid: 1, t: 1, name: 1, ls: 1 } }) - for subscription in subscriptions.fetch() - if subscription.alert or subscription.unread > 0 - Meteor.call 'readMessages', subscription.rid - - $(document.body).on 'keydown', (e) -> - target = e.target - if(e.ctrlKey is true or e.metaKey is true) - return - if !(e.keyCode > 45 and e.keyCode < 91 or e.keyCode == 8) - return - if /input|textarea|select/i.test(target.tagName) - return - if target.id is 'pswp' - return - - inputMessage = $('textarea.input-message') - if inputMessage.length is 0 - return - inputMessage.focus() - - $(document.body).on 'click', 'a', (e) -> - link = e.currentTarget - if link.origin is s.rtrim(Meteor.absoluteUrl(), '/') and /msg=([a-zA-Z0-9]+)/.test(link.search) - e.preventDefault() - e.stopPropagation() - - if RocketChat.Layout.isEmbedded() - return fireGlobalEvent('click-message-link', { link: link.pathname + link.search }) - - FlowRouter.go(link.pathname + link.search, null, FlowRouter.current().queryParams) - - Tracker.autorun (c) -> - w = window - d = document - s = 'script' - l = 'dataLayer' - i = RocketChat.settings.get 'GoogleTagManager_id' - if Match.test(i, String) and i.trim() isnt '' - c.stop() - do (w,d,s,l,i) -> - w[l] = w[l] || [] - w[l].push {'gtm.start': new Date().getTime(), event:'gtm.js'} - f = d.getElementsByTagName(s)[0] - j = d.createElement(s) - dl = if l isnt 'dataLayer' then '&l=' + l else '' - j.async = true - j.src = '//www.googletagmanager.com/gtm.js?id=' + i + dl - f.parentNode.insertBefore j, f - - if Meteor.isCordova - $(document.body).addClass 'is-cordova' - - -Template.main.helpers - - siteName: -> - return RocketChat.settings.get 'Site_Name' - - logged: -> - if Meteor.userId()? - $('html').addClass("noscroll").removeClass("scroll") - return true - else - $('html').addClass("scroll").removeClass("noscroll") - return false - - useIframe: -> - iframeEnabled = (typeof RocketChat.iframeLogin isnt "undefined") - return (iframeEnabled and RocketChat.iframeLogin.reactiveEnabled.get()) - - iframeUrl: -> - iframeEnabled = (typeof RocketChat.iframeLogin isnt "undefined") - return (iframeEnabled and RocketChat.iframeLogin.reactiveIframeUrl.get()) - - subsReady: -> - routerReady = FlowRouter.subsReady('userData', 'activeUsers') - subscriptionsReady = CachedChatSubscription.ready.get() - - ready = not Meteor.userId()? or (routerReady and subscriptionsReady) - RocketChat.CachedCollectionManager.syncEnabled = ready - return ready - - hasUsername: -> - return Meteor.userId()? and Meteor.user().username? - - requirePasswordChange: -> - return Meteor.user()?.requirePasswordChange is true - - CustomScriptLoggedOut: -> - script = RocketChat.settings.get('Custom_Script_Logged_Out') or '' - if script.trim() - eval(script) - return - - CustomScriptLoggedIn: -> - script = RocketChat.settings.get('Custom_Script_Logged_In') or '' - if script.trim() - eval(script) - return - - embeddedVersion: -> - return 'embedded-view' if RocketChat.Layout.isEmbedded() - -Template.main.events - - "click .burger": -> - console.log 'room click .burger' if window.rocketDebug - menu.toggle() - - 'touchstart': (e, t) -> - if document.body.clientWidth > 780 - return - - t.touchstartX = undefined - t.touchstartY = undefined - t.movestarted = false - t.blockmove = false - t.isRtl = isRtl localStorage.getItem "userLanguage" - if $(e.currentTarget).closest('.main-content').length > 0 - t.touchstartX = e.originalEvent.touches[0].clientX - t.touchstartY = e.originalEvent.touches[0].clientY - t.mainContent = $('.main-content') - t.wrapper = $('.messages-box > .wrapper') - - 'touchmove': (e, t) -> - if t.touchstartX? - touch = e.originalEvent.touches[0] - diffX = touch.clientX - t.touchstartX - diffY = touch.clientY - t.touchstartY - absX = Math.abs(diffX) - absY = Math.abs(diffY) - - if t.movestarted isnt true and t.blockmove isnt true and absY > 5 - t.blockmove = true - - if t.blockmove isnt true and (t.movestarted is true or absX > 5) - t.movestarted = true - - if t.isRtl - if menu.isOpen() - t.diff = -260 + diffX - else - t.diff = diffX - - if t.diff < -260 - t.diff = -260 - if t.diff > 0 - t.diff = 0 - else - if menu.isOpen() - t.diff = 260 + diffX - else - t.diff = diffX - - if t.diff > 260 - t.diff = 260 - if t.diff < 0 - t.diff = 0 - - t.mainContent.addClass('notransition') - t.mainContent.css('transform', 'translate(' + t.diff + 'px)') - t.wrapper.css('overflow', 'hidden') - - 'touchend': (e, t) -> - if t.movestarted is true - t.mainContent.removeClass('notransition') - t.wrapper.css('overflow', '') - - if t.isRtl - if menu.isOpen() - if t.diff >= -200 - menu.close() - else - menu.open() - else - if t.diff <= -60 - menu.open() - else - menu.close() - else - if menu.isOpen() - if t.diff >= 200 - menu.open() - else - menu.close() - else - if t.diff >= 60 - menu.open() - else - menu.close() - -Template.main.onRendered -> - - # RTL Support - Need config option on the UI - if isRtl localStorage.getItem "userLanguage" - $('html').addClass "rtl" - else - $('html').removeClass "rtl" - - $('#initial-page-loading').remove() - - window.addEventListener 'focus', -> - Meteor.setTimeout -> - if not $(':focus').is('INPUT,TEXTAREA') - $('.input-message').focus() - , 100 - - Tracker.autorun -> - swal.setDefaults({cancelButtonText: t('Cancel')}) - - prefs = Meteor.user()?.settings?.preferences - if prefs?.hideUsernames - $(document.body).on('mouseleave', 'button.thumb', (e) -> - RocketChat.tooltip.hide(); - ) - - $(document.body).on('mouseenter', 'button.thumb', (e) -> - avatarElem = $(e.currentTarget) - username = avatarElem.attr('data-username') - if username - e.stopPropagation() - RocketChat.tooltip.showElement($('').text(username), avatarElem) - ) - else - $(document.body).off('mouseenter', 'button.thumb') - $(document.body).off('mouseleave', 'button.thumb') - -Meteor.startup -> - fireGlobalEvent 'startup', true diff --git a/packages/rocketchat-ui-master/client/main.js b/packages/rocketchat-ui-master/client/main.js new file mode 100644 index 000000000000..e90255fa0ff0 --- /dev/null +++ b/packages/rocketchat-ui-master/client/main.js @@ -0,0 +1,301 @@ +/* globals toolbarSearch, menu, isRtl, fireGlobalEvent, CachedChatSubscription */ +import Clipboard from 'clipboard'; + +Template.body.onRendered(function() { + new Clipboard('.clipboard'); + + $(document.body).on('keydown', function(e) { + if ((e.keyCode === 80 || e.keyCode === 75) && (e.ctrlKey === true || e.metaKey === true) && e.shiftKey === false) { + e.preventDefault(); + e.stopPropagation(); + toolbarSearch.focus(true); + } + const unread = Session.get('unread'); + if (e.keyCode === 27 && e.shiftKey === true && (unread != null) && unread !== '') { + e.preventDefault(); + e.stopPropagation(); + return swal({ + title: t('Clear_all_unreads_question'), + type: 'warning', + confirmButtonText: t('Yes_clear_all'), + showCancelButton: true, + cancelButtonText: t('Cancel'), + confirmButtonColor: '#DD6B55' + }, function() { + const subscriptions = ChatSubscription.find({ + open: true + }, { + fields: { + unread: 1, + alert: 1, + rid: 1, + t: 1, + name: 1, + ls: 1 + } + }); + + subscriptions.forEach((subscription) =>{ + if (subscription.alert || subscription.unread > 0) { + Meteor.call('readMessages', subscription.rid); + } + }); + }); + } + }); + + $(document.body).on('keydown', function(e) { + const target = e.target; + if (e.ctrlKey === true || e.metaKey === true) { + return; + } + if (!(e.keyCode > 45 && e.keyCode < 91 || e.keyCode === 8)) { + return; + } + if (/input|textarea|select/i.test(target.tagName)) { + return; + } + if (target.id === 'pswp') { + return; + } + const inputMessage = $('textarea.input-message'); + if (inputMessage.length === 0) { + return; + } + return inputMessage.focus(); + }); + $(document.body).on('click', 'a', function(e) { + const link = e.currentTarget; + if (link.origin === s.rtrim(Meteor.absoluteUrl(), '/') && /msg=([a-zA-Z0-9]+)/.test(link.search)) { + e.preventDefault(); + e.stopPropagation(); + if (RocketChat.Layout.isEmbedded()) { + return fireGlobalEvent('click-message-link', { + link: link.pathname + link.search + }); + } + return FlowRouter.go(link.pathname + link.search, null, FlowRouter.current().queryParams); + } + }); + Tracker.autorun(function(c) { + const w = window; + const d = document; + const s = 'script'; + const l = 'dataLayer'; + const i = RocketChat.settings.get('GoogleTagManager_id'); + if (Match.test(i, String) && i.trim() !== '') { + c.stop(); + return (function(w, d, s, l, i) { + w[l] = w[l] || []; + w[l].push({ + 'gtm.start': new Date().getTime(), + event: 'gtm.js' + }); + const f = d.getElementsByTagName(s)[0]; + const j = d.createElement(s); + const dl = l !== 'dataLayer' ? `&l=${ l }` : ''; + j.async = true; + j.src = `//www.googletagmanager.com/gtm.js?id=${ i }${ dl }`; + return f.parentNode.insertBefore(j, f); + }(w, d, s, l, i)); + } + }); + if (Meteor.isCordova) { + return $(document.body).addClass('is-cordova'); + } +}); + +Template.main.helpers({ + siteName() { + return RocketChat.settings.get('Site_Name'); + }, + logged() { + if (Meteor.userId() != null) { + $('html').addClass('noscroll').removeClass('scroll'); + return true; + } else { + $('html').addClass('scroll').removeClass('noscroll'); + return false; + } + }, + useIframe() { + const iframeEnabled = typeof RocketChat.iframeLogin !== 'undefined'; + return iframeEnabled && RocketChat.iframeLogin.reactiveEnabled.get(); + }, + iframeUrl() { + const iframeEnabled = typeof RocketChat.iframeLogin !== 'undefined'; + return iframeEnabled && RocketChat.iframeLogin.reactiveIframeUrl.get(); + }, + subsReady() { + const routerReady = FlowRouter.subsReady('userData', 'activeUsers'); + const subscriptionsReady = CachedChatSubscription.ready.get(); + const ready = (Meteor.userId() == null) || (routerReady && subscriptionsReady); + RocketChat.CachedCollectionManager.syncEnabled = ready; + return ready; + }, + hasUsername() { + return (Meteor.userId() != null) && (Meteor.user().username != null); + }, + requirePasswordChange() { + const user = Meteor.user(); + return user && user.requirePasswordChange === true; + }, + CustomScriptLoggedOut() { + const script = RocketChat.settings.get('Custom_Script_Logged_Out') || ''; + if (script.trim()) { + eval(script);//eslint-disable-line + } + }, + CustomScriptLoggedIn() { + const script = RocketChat.settings.get('Custom_Script_Logged_In') || ''; + if (script.trim()) { + eval(script);//eslint-disable-line + } + }, + embeddedVersion() { + if (RocketChat.Layout.isEmbedded()) { + return 'embedded-view'; + } + } +}); + +Template.main.events({ + 'click .burger'() { + if (window.rocketDebug) { + console.log('room click .burger'); + } + return menu.toggle(); + }, + 'touchstart'(e, t) { + if (document.body.clientWidth > 780) { + return; + } + t.touchstartX = undefined; + t.touchstartY = undefined; + t.movestarted = false; + t.blockmove = false; + t.isRtl = isRtl(localStorage.getItem('userLanguage')); + if ($(e.currentTarget).closest('.main-content').length > 0) { + t.touchstartX = e.originalEvent.touches[0].clientX; + t.touchstartY = e.originalEvent.touches[0].clientY; + t.mainContent = $('.main-content'); + return t.wrapper = $('.messages-box > .wrapper'); + } + }, + 'touchmove'(e, t) { + if (t.touchstartX != null) { + const [touch] = e.originalEvent.touches; + const diffX = touch.clientX - t.touchstartX; + const diffY = touch.clientY - t.touchstartY; + const absX = Math.abs(diffX); + const absY = Math.abs(diffY); + if (t.movestarted !== true && t.blockmove !== true && absY > 5) { + t.blockmove = true; + } + if (t.blockmove !== true && (t.movestarted === true || absX > 5)) { + t.movestarted = true; + if (t.isRtl) { + if (menu.isOpen()) { + t.diff = -260 + diffX; + } else { + t.diff = diffX; + } + if (t.diff < -260) { + t.diff = -260; + } + if (t.diff > 0) { + t.diff = 0; + } + } else { + if (menu.isOpen()) { + t.diff = 260 + diffX; + } else { + t.diff = diffX; + } + if (t.diff > 260) { + t.diff = 260; + } + if (t.diff < 0) { + t.diff = 0; + } + } + t.mainContent.addClass('notransition'); + t.mainContent.css('transform', `translate(${ t.diff }px)`); + return t.wrapper.css('overflow', 'hidden'); + } + } + }, + 'touchend'(e, t) { + if (t.movestarted === true) { + t.mainContent.removeClass('notransition'); + t.wrapper.css('overflow', ''); + if (t.isRtl) { + if (menu.isOpen()) { + if (t.diff >= -200) { + return menu.close(); + } else { + return menu.open(); + } + } else if (t.diff <= -60) { + return menu.open(); + } else { + return menu.close(); + } + } else if (menu.isOpen()) { + if (t.diff >= 200) { + return menu.open(); + } else { + return menu.close(); + } + } else if (t.diff >= 60) { + return menu.open(); + } else { + return menu.close(); + } + } + } +}); + +Template.main.onRendered(function() { + if (isRtl(localStorage.getItem('userLanguage'))) { + $('html').addClass('rtl'); + } else { + $('html').removeClass('rtl'); + } + $('#initial-page-loading').remove(); + window.addEventListener('focus', function() { + return Meteor.setTimeout(function() { + if (!$(':focus').is('INPUT,TEXTAREA')) { + return $('.input-message').focus(); + } + }, 100); + }); + return Tracker.autorun(function() { + swal.setDefaults({ + cancelButtonText: t('Cancel') + }); + const user = Meteor.user(); + const settings = user && user.settings; + const prefs = settings && settings.preferences; + if (prefs && prefs.hideUsernames != null) { + $(document.body).on('mouseleave', 'button.thumb', function() { + return RocketChat.tooltip.hide(); + }); + return $(document.body).on('mouseenter', 'button.thumb', function(e) { + const avatarElem = $(e.currentTarget); + const username = avatarElem.attr('data-username'); + if (username) { + e.stopPropagation(); + return RocketChat.tooltip.showElement($('').text(username), avatarElem); + } + }); + } else { + $(document.body).off('mouseenter', 'button.thumb'); + return $(document.body).off('mouseleave', 'button.thumb'); + } + }); +}); + +Meteor.startup(function() { + return fireGlobalEvent('startup', true); +}); diff --git a/packages/rocketchat-ui-master/package.js b/packages/rocketchat-ui-master/package.js index 040038126b16..9ed815f8b0b6 100644 --- a/packages/rocketchat-ui-master/package.js +++ b/packages/rocketchat-ui-master/package.js @@ -19,7 +19,6 @@ Package.onUse(function(api) { 'mongo', 'ecmascript', 'templating', - 'coffeescript', 'underscore', 'rocketchat:lib', 'meteorhacks:inject-initial' @@ -29,7 +28,7 @@ Package.onUse(function(api) { api.addFiles('client/loading.html', 'client'); api.addFiles('client/error.html', 'client'); api.addFiles('client/logoLayout.html', 'client'); - api.addFiles('client/main.coffee', 'client'); + api.addFiles('client/main.js', 'client'); api.addFiles('server/inject.js', 'server'); });