This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from zarathustra323/leaders-click-emitter
Create Leaders click event emitter
- Loading branch information
Showing
9 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<template> | ||
<div class="marko-web-leaders-click-emitter" style="display: none;" /> | ||
</template> | ||
|
||
<script> | ||
import { delegate } from 'dom-utils'; | ||
export default { | ||
data: () => ({ | ||
listener: null, | ||
}), | ||
created() { | ||
this.listener = delegate( | ||
document, | ||
'click', | ||
'a[data-leaders-action]', | ||
this.emit.bind(this), | ||
); | ||
}, | ||
beforeDestroy() { | ||
if (this.listener) this.listener.destroy(); | ||
}, | ||
methods: { | ||
emit(_, link) { | ||
const event = { | ||
type: link.getAttribute('data-leaders-action'), | ||
category: link.getAttribute('data-leaders-category'), | ||
label: link.getAttribute('data-leaders-label'), | ||
}; | ||
const payload = { | ||
...this.parseJSON(link.getAttribute('data-leaders-payload')), | ||
href: link.getAttribute('href'), | ||
}; | ||
this.$emit('action', event, payload); | ||
}, | ||
parseJSON(value) { | ||
try { | ||
return JSON.parse(value) || {}; | ||
} catch (e) { | ||
return {}; | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<marko-web-browser-component name="LeadersClickEmitter" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = (params = {}) => { | ||
const keys = ['action', 'category', 'label', 'payload']; | ||
return keys.reduce((o, key) => { | ||
const value = key === 'payload' ? JSON.stringify(params[key]) : params[key]; | ||
if (!value) return o; | ||
return { ...o, [`data-leaders-${key}`]: value }; | ||
}, {}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const leadersAttrs = require('./event-attrs'); | ||
|
||
module.exports = ({ | ||
category, | ||
label, | ||
companyId, | ||
linkAttrs, | ||
} = {}) => ({ | ||
...linkAttrs, | ||
...leadersAttrs({ | ||
action: 'click', | ||
category, | ||
label, | ||
payload: { companyId }, | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters