[FIX] url click events in the cordova app open in external browser or not at all (#7205)

* fix url click events in the cordova app

fixes RocketChat/Rocket.Chat.Cordova#142

* make urls regexp case insensitive since mobile devices often autocapitalize them
pull/7448/head^2
Flavio Grossi 8 years ago committed by Aaron Ogle
parent b46dcc76d8
commit 5cb30b479f
  1. 2
      packages/rocketchat-ui-master/client/main.js
  2. 4
      packages/rocketchat-ui/client/lib/cordova/urls.js
  3. 16
      packages/rocketchat-ui/client/views/app/room.js

@ -184,7 +184,7 @@ Template.main.events({
},
'touchmove'(e, t) {
if (t.touchstartX != null) {
const [touch] = e.originalEvent.touches;
const touch = e.originalEvent.touches[0];
const diffX = touch.clientX - t.touchstartX;
const diffY = touch.clientY - t.touchstartY;
const absX = Math.abs(diffX);

@ -1,14 +1,14 @@
Meteor.startup(() => {
if (!Meteor.isCordova) { return; }
// Handle click events for all external URLs
$(document).on('deviceready', () => {
document.addEventListener('deviceready', () => {
// const platform = device.platform.toLowerCase();
$(document).on('click', function(e) {
const $link = $(e.target).closest('a[href]');
if (!($link.length > 0)) { return; }
const url = $link.attr('href');
if (/^https?:\/\/.+/.test(url) === true) {
if (/^https?:\/\/.+/i.test(url) === true) {
window.open(url, '_system');
return e.preventDefault();
}

@ -234,6 +234,8 @@ Template.room.helpers({
let isSocialSharingOpen = false;
let touchMoved = false;
let lastTouchX = null;
let lastTouchY = null;
Template.room.events({
'click, touchend'(e, t) {
@ -249,6 +251,11 @@ Template.room.events({
},
'touchstart .message'(e, t) {
const touches = e.originalEvent.touches;
if (touches && touches.length) {
lastTouchX = touches[0].pageX;
lastTouchY = touches[0].pagey;
}
touchMoved = false;
isSocialSharingOpen = false;
if (e.originalEvent.touches.length !== 1) {
@ -343,7 +350,14 @@ Template.room.events({
},
'touchmove .message'(e, t) {
touchMoved = true;
const touches = e.originalEvent.touches;
if (touches && touches.length) {
const deltaX = Math.abs(lastTouchX - touches[0].pageX);
const deltaY = Math.abs(lastTouchY - touches[0].pageY);
if (deltaX > 5 || deltaY > 5) {
touchMoved = true;
}
}
return Meteor.clearTimeout(t.touchtime);
},

Loading…
Cancel
Save