/* Namespace setup */ if (typeof tjx == "undefined") { var tjx = {}; } if (typeof tjx.widget == "undefined") { tjx['widget'] = {}; } if (typeof tjx.widget.facebook == "undefined") { tjx.widget['facebook'] = {}; } jQuery(document).ready(function($) { //if Facebook featureloader is not defined if( typeof FB === "undefined" ) { tjx.widget.facebook.enabled = false; } else { try { //make sure FBConnect plugin is not initialized before FB init if( typeof FBConnect === "undefined" ) { FB.init('f2e5afc298977d1b2a16f4510ea8e336', "http://www.marshallsonline.com/wp-content/tjx-commons/thirdparty/facebook/xd_receiver.htm", {"forceBrowserPopupForLogin":false} ); } tjx.widget.facebook.enabled = true; } catch(e) { tjx.widget.facebook.enabled = false; } } if( tjx.widget.facebook.enabled ) { tjx.widget.facebook.FBFacade = function() { return { init: function() { FB.ensureInit(function() { FB.Facebook.get_sessionState().waitUntilReady(function(session) { var is_now_logged_into_facebook = session ? true : false; }); }); }, /** * This function accepts an array of facebook parameters and the callback function. */ publishPost: function(paramArr, callback) { //if facebook is not initialized dont try to post if( typeof FBConnect !== "undefined" && FBConnect.initialized == false) { callback(); } that = this; that.callback = callback; FB.ensureInit(function() { console.log("in ensure init"); var images = []; //Check for the environment as images can be supported only when the enrvironment is live //since FB validates the image urls. if( "prod" === "prod" && paramArr['images'] && paramArr['images'].length != 0 ) { images[0] = { "src": paramArr['images'], "href": paramArr['url'] }; } template_data = { "title" : paramArr['title'], "url" : paramArr['url'], "desc" : paramArr['desc'], "images" : images }; result = FB.Connect.showFeedDialog(129626369940, template_data, null, null, null, FB.RequireConnect.promptConnect, that.callback ); }); }, publishComment: function(paramArr, callback) { //if facebook is not initialized dont try to post if( typeof FBConnect !== "undefined" && FBConnect.initialized == false) { callback(); } that = this; that.commentCallback = callback; FB.ensureInit(function() { console.log("publishComment in ensure init"); var images = []; FB.Connect.requireSession(function(exception){ console.log(FB.Facebook.apiClient.get_session().uid + " is logged in"); result = FB.Connect.showFeedDialog(137492967928, { "comment" : paramArr['comment'], "product" : paramArr['product'], "price" : paramArr['price'], "content" : paramArr['desc'], "url" : paramArr['url'] }, null,'',null, FB.RequireConnect.promptConnect, that.commentCallback ); }); }); } }; }; } else { //dummy object if facebook is not enabled tjx.widget.facebook.FBFacade = function() { return { init: function() { console.log("FB is not enabled"); }, publishPost: function(paramArr, callback) { console.log("publishPost: FB is not enabled"); callback(); }, publishComment: function(paramArr, callback) { console.log("publishComment: FB is not enabled"); callback(); } } }; } });