Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elements to be avoided #11

Closed
ethantw opened this issue Sep 15, 2013 · 3 comments
Closed

Elements to be avoided #11

ethantw opened this issue Sep 15, 2013 · 3 comments
Assignees

Comments

@ethantw
Copy link
Contributor

ethantw commented Sep 15, 2013

Avoiding child elements, such as <style> and <script>, to be replaced inside the target elements is necessary; otherwise, it would simply keep them from executing. For example,

<p id="tester">
    <style scoped>span {  color: red;  }</style>

    <span>Hello,</span>
    people in red.
</p>

<script>
findAndReplaceDOMText(
    /red/g,
    document.getElementById('tester'),
    'em'
);
</script>

Would outputs,

<p id="tester">
    <style scoped>span {  color: <em>red</em>;  }</style>

    <span>Hello,</span>
    people in <em>red</em>.
</p>

Tried editing the function, but just not able to make it right. Hoping this could be solved.

@ghost ghost assigned padolsey Sep 15, 2013
@padolsey
Copy link
Owner

Hi, thanks for reporting. In 0.3.0 you can filter out elements:

findAndReplaceDOMText(/foo/g, myElement, 'span', null, function(el) {
    var name = el.nodeName.toLowerCase();
    return name !== 'style' && name !== 'script';
});

@ethantw
Copy link
Contributor Author

ethantw commented Sep 16, 2013

Neat! Although the function and the return value are not that comprehensible, it totally works now.

Thanks for the great repo. :)

@padolsey
Copy link
Owner

The function is used to filter what elements should be processed. The above example will return false on SCRIPT and STYLE elements, meaning that they will not be processed. I tried for an intuitive API, and I thought the concept of 'filtering' would be best. Always open to suggestions :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants