-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
I'm trying to embed the Facebook Like button plugin (http://developers.facebook.com/docs/reference/plugins/like/). I want to do it in Java and I have tried using a ZK native component (where NDiv extends HtmlNativeComponent):
NDiv fbDiv = new NDiv(); getWrapperDiv().appendChild(fbDiv); fbDiv.setDynamicProperty("class", "fb-like"); fbDiv.setDynamicProperty("data-href", "http://www.google.com"); fbDiv.setDynamicProperty("data-send", "true"); fbDiv.setDynamicProperty("data-layout", "button_count"); fbDiv.setDynamicProperty("data-width", "450"); fbDiv.setDynamicProperty("data-show-faces", "false"); fbDiv.setDynamicProperty("data-font", "arial");
fbDiv.setPrologContent("<div class=\"fb-like\" data-font=\"arial\" data-show-faces=\"false\" data-width=\"450\" data-layout=\"button_count\" data-send=\"true\" data-href=\"http://www.google.com\"></div>");
Hi Richard,
You need to call the initialize script provided by facebook after the fbDiv is added to the page, e.g.,
<zk> <!-- the fb root and initialization function, remove the exec fragment (document, 'script', 'facebook-jssdk') since we will call it manually --> <div id="fb-root"></div> <script>(window.initializelike = 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); });</script> <div id="WrapperDiv"> <button label="test"> <attribute name="onClick"><![CDATA[ // add the fbDiv ... // call the predefined initial function Clients.evalJavaScript("window.initializelike(document, 'script', 'facebook-jssdk')"); ]]></attribute> </button> </div> </zk>
Regards,
Ben
Asked: 2012-12-30 04:42:12 +0800
Seen: 74 times
Last updated: Dec 30 '12