I have a problem with Facebook and Twitter share buttons in my single page web application. My app has 3 views. A,B and C. Facebook and Twitter buttons are on A view. First time that app is loaded and view A is shown is OK I can see buttons and it works. When I move to view B I detach view A (I have to do that) and attach view B and by clicking on back button from View B we go to view A but this time the Facebook and Twitter buttons are now showing.
SharedButton.js
(function() {
define(['jquery'], function($) {
return {
init: function(){
var url = window.location.href;
$('.fb-share-button').attr('data-href', url);
(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/sdk.js#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');
}
};
});
}).call(this);
Every time I attach view A, shareButton.init() is being called.
Any idea what's the issue and how can I get it working?
Thanks.