Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Remove the ability to pass a callback function as a string #12

Closed
JakeChampion opened this issue Oct 4, 2017 · 1 comment
Closed

Remove the ability to pass a callback function as a string #12

JakeChampion opened this issue Oct 4, 2017 · 1 comment
Labels
breaking Will require a major version bump

Comments

@JakeChampion
Copy link
Contributor

This is where we use new Function - https://github.com/Financial-Times/o-toggle/blob/master/src/js/toggle.js#L40 - we should avoid using new Function/eval in Origami components in case the product using Origami has a strict Content-Security-Policy which forbids using these powerful features of the language.

We can avoid the use of new Function/eval in this component by changing the option to take a reference to an already existing function that should be executed as the callback.

E.G.

<script>
function myOToggleCallback(state, event) {
  document.querySelector('.target').classList.toggle('hidden');
}
</script>

<button data-o-component="o-toggle"
		data-o-toggle-target=".target"
		data-o-toggle-callback="myOToggleCallback">Toggle</button>

<div class="target hidden">Target of the toggle</div>
@notlee
Copy link
Contributor

notlee commented Sep 2, 2019

This is done, to be released as part of the breaking cascade. Closing to keep track of progress. See:

Related issue: #25
Related PR: #27

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking Will require a major version bump
Projects
None yet
Development

No branches or pull requests

2 participants