0

I'm working on an Ember.js application that displays content from a Wordpress backend. In addition to text, this content can contain arbitrary javascript that is typical in the embed code of various social media sites (Facebook, Instagram, Twitter). Unfortunately, this javascript doesn't seem to get executed when the page loads which causes the page to not render the correct content.

Here is what I'm using in my template to render the post content:

{{{model.content}}}

And this is some example content that is not being rendered correctly:

<div id="fb-root"></div>
<script>// <![CDATA[
(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));
// ]]></script>
<div class="fb-post" data-href="https://www.facebook.com/185429188166097/photos/a.185450081497341.36203.185429188166097/852153634826979/?type=1" data-width="600">
<div class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/185429188166097/photos/a.185450081497341.36203.185429188166097/852153634826979/?type=1">Post</a> by <a href="https://www.facebook.com/pages/Sonnie-Trotter/185429188166097">Sonnie Trotter</a>.</div>
</div>

Is something like this possible?

Dhaulagiri
  • 3,281
  • 24
  • 26
  • Pull the javascript out and just execute it after inserting the content. – Kingpin2k Feb 17 '15 at 22:15
  • How would one go about doing that @Kingpin2k given the arbitrary nature of the javascript. Is there some way to just strip out all javascript and execute it later? – Dhaulagiri Feb 17 '15 at 22:19
  • No easy way, but having javascript littered in your templates should be easy to find using the eye test. – Kingpin2k Feb 17 '15 at 22:23
  • Hmm, that isn't ideal. The eye test doesn't help here since the content is not known until the data is received from the api. – Dhaulagiri Feb 17 '15 at 22:25
  • Try using a component. This may be what u are looking for http://stackoverflow.com/questions/24751621/show-a-js-script-component-in-ember-handlebars-app/24753392#24753392 – blessanm86 Feb 18 '15 at 08:35

0 Answers0