From 22cff569198e4ca2112d19ae4a73ba949a8caf76 Mon Sep 17 00:00:00 2001 From: Coston Perkins Date: Wed, 17 Apr 2019 14:35:30 -0500 Subject: [PATCH 1/4] Allow html href if already human interaction --- dist/obfuscate.js | 17 ++++++++++------- src/obfuscate.js | 17 ++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/dist/obfuscate.js b/dist/obfuscate.js index 8328ea74..55c103e8 100644 --- a/dist/obfuscate.js +++ b/dist/obfuscate.js @@ -89,15 +89,18 @@ function (_Component) { }, { key: "handleClick", value: function handleClick(event) { - var onClick = this.props.onClick; - event.preventDefault(); // Allow instantiator to provide an onClick method to be called - // before we change location (e.g. for analytics tracking) + var onClick = this.props.onClick; // If focused or hovered, this js will be skipped with preference for html - if (onClick && typeof onClick === 'function') { - onClick(); - } + if (this.state.humanInteraction === false) { + event.preventDefault(); // Allow instantiator to provide an onClick method to be called + // before we change location (e.g. for analytics tracking) + + if (onClick && typeof onClick === 'function') { + onClick(); + } - window.location.href = this.createContactLink(this.props); + window.location.href = this.createContactLink(this.props); + } } }, { key: "handleCopiability", diff --git a/src/obfuscate.js b/src/obfuscate.js index 2fb87c8f..4d8bb2a4 100644 --- a/src/obfuscate.js +++ b/src/obfuscate.js @@ -46,15 +46,18 @@ export default class Obfuscate extends Component { handleClick(event) { const { onClick } = this.props - event.preventDefault() + // If focused or hovered, this js will be skipped with preference for html + if (this.state.humanInteraction === false) { + event.preventDefault() + + // Allow instantiator to provide an onClick method to be called + // before we change location (e.g. for analytics tracking) + if (onClick && typeof onClick === 'function') { + onClick() + } - // Allow instantiator to provide an onClick method to be called - // before we change location (e.g. for analytics tracking) - if (onClick && typeof onClick === 'function') { - onClick() + window.location.href = this.createContactLink(this.props) } - - window.location.href = this.createContactLink(this.props) } handleCopiability() { From b4ba8d74bc947d7503e0a7ba20de9091f1f81f81 Mon Sep 17 00:00:00 2001 From: Coston Perkins Date: Wed, 17 Apr 2019 14:35:48 -0500 Subject: [PATCH 2/4] Divide common and uncommon options --- readme.md | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/readme.md b/readme.md index 0a536263..6fcc6df5 100644 --- a/readme.md +++ b/readme.md @@ -70,20 +70,26 @@ export default () => (

``` -## Options - -| Prop | Type | Argument | Default | Description | -| --------- | ----------- | ------------ | ------------ | -------------------------------------------------------------- | -| email | `string` | `` | `null` | email address of the intended recipient | -| tel | `string` | `` | `null` | telephone number of the intended recipient | -| sms | `string` | `` | `null` | sms number of the intended recipient | -| facetime | `string` | `` | `null` | facetime address of the intended recipient | -| href | `string` | `` | `null` | Obfuscate any other URL type | -| headers | `object` | `` | `null` | subject, cc, bcc, body, etc | -| obfuscate | `boolean` | `` | `true` | set to false to disable obfuscation | -| linkText | `string` | `` | `obfuscated` | add custom pre-interaction href attribute placeholder text | -| element | `string` | `` | `'a'` | custom element to render instead of an `a` tag | -| onClick | `function` | `` | `null` | called prior to setting location (e.g. for analytics tracking) | +## Common Options + +| Prop | Type | Argument | Default | Description | +| -------- | -------- | ---------- | ------- | -------------------------------------------- | +| email | `string` | `optional` | `null` | email address of the intended recipient | +| headers | `object` | `optional` | `null` | subject, cc, bcc, body, etc | +| tel | `string` | `optional` | `null` | telephone number of the intended recipient | +| sms | `string` | `optional` | `null` | sms number of the intended recipient | +| facetime | `string` | `optional` | `null` | facetime address of the intended recipient | +| href | `string` | `optional` | `null` | Obfuscate any other URL type (e.g. WhatsApp) | + +## Uncommon Options + +| Prop | Type | Argument | Default | Description | +| --------- | ---------- | ---------- | ------------ | -------------------------------------------------------------- | +| linkText | `string` | `optional` | `obfuscated` | add custom pre-interaction href attribute placeholder text | +| obfuscate | `boolean` | `optional` | `true` | set to false to disable obfuscation | +| element | `string` | `optional` | `'a'` | use if you want to override the default `a` tag | +| onClick | `function` | `optional` | `null` | called prior to setting location (e.g. for analytics tracking) | + ## Development From 435aa3f2189531fa5ebbe011d435790e19b96959 Mon Sep 17 00:00:00 2001 From: Coston Perkins Date: Wed, 17 Apr 2019 15:04:47 -0500 Subject: [PATCH 3/4] Add humanInteraction disables onClick js test --- test/obfuscate.test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/obfuscate.test.js b/test/obfuscate.test.js index 9f3eb279..a5a48c4d 100755 --- a/test/obfuscate.test.js +++ b/test/obfuscate.test.js @@ -4,6 +4,7 @@ import Obfuscate from '../src/obfuscate.js' const testEmail = 'coston.perkins@ua.edu' const testTel = '205-454-1234' const testTelReveresed = '4321-454-502' +const originalLocation = 'https://example.com/' describe('obfuscate', () => { @@ -11,7 +12,7 @@ describe('obfuscate', () => { delete global.window.location global.window.location = { - href: new URL('https://example.com'), + href: new URL(originalLocation), } }) @@ -152,6 +153,15 @@ describe('obfuscate', () => { expect(wrapper.prop('href')).toEqual(`mailto:${testEmail}`) }) + test('Human interaction disables onClick setting js location.href', () => { + const wrapper = shallow( + + ) + wrapper.simulate('mouseover') + wrapper.simulate('click') + expect(global.window.location.href.toString()).toEqual(originalLocation) + }) + test('Return empty href link if child is an object and no link is provided', () => { const wrapper = shallow( From aed69839288215e55ac14a819281bc2ccfb5b9f5 Mon Sep 17 00:00:00 2001 From: Coston Perkins Date: Wed, 17 Apr 2019 15:10:08 -0500 Subject: [PATCH 4/4] 3.5.0-0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 44b9e0bb..0eaa5186 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-obfuscate", - "version": "3.4.0", + "version": "3.5.0-0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d463ba97..ecb101d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-obfuscate", - "version": "3.4.0", + "version": "3.5.0-0", "description": "An intelligent React component to obfuscate any contact link", "main": "dist/obfuscate.js", "files": [