/* * ----------------------------------------------------------------- * Copyright (c) 2009 Fluid, Inc. All Right Reserved. * This software is the proprietary information of Fluid, Inc. * Use is subject to strict licensing terms. * ----------------------------------------------------------------- * * CVS Information: * $Id: fluid.facebook-pdp.js.php,v 1.46 2009/10/27 18:02:41 fluiddev Exp $ * $Author: fluiddev $ * $Date: 2009/10/27 18:02:41 $ */ var FluidSocialPDP = function () {}; FluidSocialPDP.userInitiatedLogin = false; FluidSocialPDP.prototype = { // Configuration parameters: divId: "fluid-social-facebook", favoritesDivId: null, productId: null, productName: null, thumbnailUrl: null, pdpUrl: null, mainImageUrl: null, visibleTab: null, alreadyLoggedIn: false, sendInviteDialog: null, statusDialog: null, facebookUserId: null, isPageLoaded: false, singleProductMode: false, standaloneFavoritesOnly: false, favoritesScrollerSize: 2, standaloneFavoritesScrollerSize: 2, init: function() { this.isPageLoaded = false; var fluidSocial = this; // Create a hidden iframe so we can do xd calls to the Fluid Social server. var iframeUrl = "http://facebook.ghirardelli.com/ghirardelli/connect/connect_api.php"; var iframeHtml = '
' + '
'; $("body").append(iframeHtml); $('#fluid_api_server').load(function() { fluidSocial.isPageLoaded = true; }); // Add the Fluid Social for Facebook content to the specified div. if (this.divId != null) this.createFacebookContent(); if (this.favoritesDivId != null) this.createStandaloneFavoritesContent(); $(".fluid-fbLoggedIn").hide(); $(".fluid-fbNotLoggedIn").show(); // Initialize the client-side Facebook API. FB_RequireFeatures(["XFBML", "Api", "Connect"], function() { //FB.FBDebug.isEnabled = true; //FB.FBDebug.logLevel = 4; // We must wait until the Fluid Social connector iframe is loaded before // initializing Facebook Connect. We also need to take into account that // the page may already be fully loaded. if (fluidSocial.isPageLoaded) { fluidSocial.initializeFacebook(); } else { $('#fluid_api_server').load(function() { fluidSocial.initializeFacebook(); }); } }); $("a.fluid-fbLogin").click(function(event) { event.preventDefault(); fluidSocial.closeDialogs(); FluidSocialPDP.userInitiatedLogin = true; FB.Connect.requireSession(); }); $("a.fluid-fbLogout").click(function(event) { event.preventDefault(); fluidSocial.closeDialogs(); // Reset the Share link. $('#fluid-fbShareMessage').text('Share with Friends!').css('font-weight', 'normal'); $('#fluid-fbShareProduct').show(); FB.Connect.logout(); }); $("a.fluid-fbAddProduct").click(function(event) { event.preventDefault(); fluidSocial.closeDialogs(); FB.Connect.requireSession(function() { // Add the product. fluidSocial.addProduct(); }); }); $("a.fluid-fbcloselink, input.fluid-fbclosebutton").click(function(event) { event.preventDefault(); fluidSocial.closeDialogs(); }); $("#fluid-feedback_form_send").click(function(event) { event.preventDefault(); fluidSocial.sendFeedback(); }); // Some links appear in dynamically generated content, so we need // to reattach them sometimes. this.reattachEventHandlers(); if (location.search.indexOf('fluid-showFBComments=1') != -1) this.tabSwap('fluid-fbTab2Content'); }, initializeFacebook: function() { var fluidSocial = this; FB.init("2736fa277362bc0c00ce1cff79f8cba0", "http://shop.ghirardelli.com/xd_receiver.html", { "ifUserConnected": function(userId) { fluidSocial.debug("Facebook User Connected: " + userId + ", User Initiated Login: " + FluidSocialPDP.userInitiatedLogin); if (!fluidSocial.alreadyLoggedIn) { fluidSocial.facebookUserId = userId; $(".fluid-fbLoggedIn").show(); $(".fluid-fbNotLoggedIn").hide(); $("#fluid-fbProfilePic").html(''); $(".fluid-fbUserName").html(''); fluidSocial.parseDomElement('fluid-fbShareContent'); fluidSocial.getNewestReview(); fluidSocial.getFriendReviews(); if (!fluidSocial.singleProductMode) fluidSocial.getFriendFavorites(); if (FluidSocialPDP.userInitiatedLogin) { // Ask the user if we can update their status area on Facebook. FB.Facebook.apiClient.users_hasAppPermission('status_update', function(result) { fluidSocial.debug("Permission to update status: " + result); if (result == 0) { FB.Connect.showPermissionDialog('status_update', function(result) { fluidSocial.debug("Permission granted on prompt: " + result); if (result == 'status_update') fluidSocial.updateUserStatus(); }); } else { fluidSocial.updateUserStatus(); } }); } } fluidSocial.alreadyLoggedIn = true; }, "ifUserNotConnected": function() { fluidSocial.debug("Facebook User Disconnected"); $(".fluid-fbLoggedIn").hide(); $(".fluid-fbNotLoggedIn").show(); fluidSocial.alreadyLoggedIn = false; fluidSocial.facebookUserId = null; } } ); }, createFacebookContent: function() { var fluidSocial = this; var html = ''; if (!this.standaloneFavoritesOnly) { html += '
\n'; html += '
\n'; if (!this.singleProductMode) { html += '
\n'; } html += '
\n'; html += '
\n'; html += '
    \n'; html += '
  • \n'; html += '
  • \n'; if (!this.singleProductMode) { html += '
  • \n'; } html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += ' \n'; html += ' \n'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += ' Tell me how this works | Tell us what you think\n'; html += '
\n'; html += '
\n'; html += '\n'; if (!this.singleProductMode) { html += '\n'; } html += '\n'; html += '
\n'; } html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += ' Close  \n'; html += '
\n'; html += ' \n'; html += ' \n'; html += ' \n'; html += ' \n'; html += ' \n'; html += ' \n'; html += ' \n'; html += '
Click the 'Connect with Facebook' button to add the Application.

Once added, you can share as many products as you'd like!
Without leaving this site, you can view the ratings and comments from your friends on your products (as long as you are logged into Facebook).

You can even see the products your friends added to their own lists!
To get the full benefit of our Social Shopping feature, don't forget to Invite Your Friends to rate, comment and create their own list of favorites after you add your application!
\n'; html += '
'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += ' Close  \n'; html += '
\n'; html += '
\n'; html += '

TELL US WHAT YOU THINK!

\n'; html += '

Your feedback is important to us, so let us know what you think about the Facebook integration features on the Ghirardelli product detail page!

\n'; html += '

You can also report any problems or bugs you find here.

\n'; html += '
\n'; html += '
All fields are required unless indicated.
\n'; html += '
Ghirardelli Dev Team
\n'; html += '
\n'; html += '
(optional)
If you want a reply, please enter your email here. We will not disclose your information to anyone.
\n'; html += '
(optional)
\n'; html += '
\n'; html += '
 
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
'; html += '
\n'; html += '
\n'; html += '\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
Share, Rate and Comment on Ghirardelli products with your Facebook friends while you shop!
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += '
\n'; $('#' + this.divId).html(html); $('#fluid-fbTab1Share > a').click(function(event) { event.preventDefault(); }); $('#fluid-fbTab1Friends > a').click(function(event) { event.preventDefault(); fluidSocial.tabSwap('fluid-fbTab2Content'); }); $('#fluid-fbTab1Favorites > a').click(function(event) { event.preventDefault(); fluidSocial.tabSwap('fluid-fbTab3Content'); }); $('#fluid-fbTab2Share > a').click(function(event) { event.preventDefault(); fluidSocial.tabSwap('fluid-fbTab1Content'); }); $('#fluid-fbTab2Friends > a').click(function(event) { event.preventDefault(); }); $('#fluid-fbTab2Favorites > a').click(function(event) { event.preventDefault(); fluidSocial.tabSwap('fluid-fbTab3Content'); }); $('#fluid-fbTab3Share > a').click(function(event) { event.preventDefault(); fluidSocial.tabSwap('fluid-fbTab1Content'); }); $('#fluid-fbTab3Friends > a').click(function(event) { event.preventDefault(); fluidSocial.tabSwap('fluid-fbTab2Content'); }); $('#fluid-fbTab3Favorites > a').click(function(event) { event.preventDefault(); }); }, createStandaloneFavoritesContent: function() { var fluidSocial = this; var html = ''; html += '
\n'; html += '
\n'; html += '
See what other Ghirardelli
products your Friends like!
\n'; html += '
\n'; html += '
\n'; html += '
\n'; html += ' \n'; html += '
\n'; html += '
\n'; html += ' Tell me how this works | Tell us what you think\n'; html += '
\n'; $('#' + this.favoritesDivId).html(html); }, reattachEventHandlers: function() { var fluidSocial = this; $("a.fluid-fbShowInstructions").unbind("click").click(function(event) { event.preventDefault(); fluidSocial.closeDialogs(); $('#fluid-howitworks').show(); }); $("a.fluid-fbSendFeedback").unbind("click").click(function(event) { event.preventDefault(); fluidSocial.closeDialogs(); $('#fluid-feedback *').removeClass("fluid-feedback_form_value_error fluid-feedback_form_label_error"); $('#fluid-feedback_form')[0].reset(); $('#fluid-feedback').show(); }); $("a.fluid-fbInviteFriends").unbind("click").click(function(event) { event.preventDefault(); fluidSocial.closeDialogs(); fluidSocial.showInviteDialog(); }); }, tabSwap: function(id) { var tabToSwapWith = $('#' + id); if (!this.visibleTab) { this.visibleTab = $('#fluid-fbTab1Content'); } this.visibleTab.hide(); tabToSwapWith.show(); this.visibleTab = tabToSwapWith; // Track events in GA. if (this.analyticsPresent()) { if (id == 'fluid-fbTab2Content') { pageTracker._trackEvent("PDP Events", "Friend Comments Opened", this.productId); } else if (id == 'fluid-fbTab3Content') { pageTracker._trackEvent("PDP Events", "Friend Favorites Opened", this.productId); } } }, addProduct: function() { var fluidSocial = this; fluidSocial.debug("addProduct()"); window.frames['fluid_api_server'].fluidSocialConnector.addProduct( this.productId, this.productName, this.pdpUrl, this.thumbnailUrl, this.mainImageUrl, function(response) { if (!fluidSocial.validateResponse(response)) return; if (fluidSocial.analyticsPresent()) { // Inform GA that the product was added. pageTracker._trackEvent("PDP Events", "Add Product", fluidSocial.productId); } // Remove the Share link. $('#fluid-fbShareMessage').text('You shared this product successfully!').css('font-weight', 'bold'); $('#fluid-fbShareProduct').hide(); // Allow the user to post to their FB feed. var templateData = { "productName": fluidSocial.productName, "pdpUrl": fluidSocial.pdpUrl, "images": [{"src": fluidSocial.thumbnailUrl.replace(/%20/, ' '), "href": fluidSocial.pdpUrl}] }; FB.Connect.showFeedDialog('97630483173', templateData, null, null, null, FB.RequireConnect.require, null, response, null); }); }, updateUserStatus: function() { var fluidSocial = this; FB.Facebook.apiClient.users_setStatus('is currently shopping on shop.ghirardelli.com. Join me: ' + fluidSocial.pdpUrl, false, true, function() { fluidSocial.debug("Status Updated"); }); }, showInviteDialog: function() { var fluidSocial = this; var addProductUrl = 'http://apps.facebook.com/ghirardelli/' + '?productId=' + encodeURIComponent(this.productId) + '&productName=' + encodeURIComponent(this.productName) + '&thumbnailUrl=' + encodeURIComponent(this.thumbnailUrl) + '&pdpUrl=' + encodeURIComponent(this.pdpUrl) + '&action=addProduct'; if (this.mainImageUrl != null) addProductUrl += '&mainImageUrl=' + encodeURIComponent(this.mainImageUrl); // Facebook makes a Javascript call (fs.skip("_parent")) when the Cancel/Submit buttons on the form are clicked // that causes the action URL to get loaded in the FBML rendering iframe's parent (in our case, the top-level window). // This isn't desirable here, so we must add another iframe level of indirection to fix this. // (See http://bugs.developers.facebook.com/show_bug.cgi?id=4916) var iframeUrl = "http://facebook.ghirardelli.com/ghirardelli/connect/generate_invite.php?addProductUrl=" + encodeURIComponent(addProductUrl); var fbml = ''; // var content = ' has a favorite product on My Ghirardelli Favorites and would like to share it with you!\n'; // ''; // fbml = '' + // '' + // ''; this.sendInviteDialog = new FB.UI.FBMLPopupDialog('Invite Friends', fbml, false, false); this.sendInviteDialog.setContentWidth(760); this.sendInviteDialog.setContentHeight(560); this.sendInviteDialog.set_placement(FB.UI.PopupPlacement.topCenter); this.sendInviteDialog.add_closing(function() { fluidSocial.sendInviteDialog = null; }); this.sendInviteDialog.show(); }, getNewestReview: function() { var fluidSocial = this; fluidSocial.debug("In getNewestReview"); fluidSocial.debug(window.frames['fluid_api_server'].fluidSocialConnector); window.frames['fluid_api_server'].fluidSocialConnector.getNewestReview( this.productId, function(response) { if (!fluidSocial.validateResponse(response)) return; $("#fluid-fbCommentBubbleWrapper").html(response); $(".fluid-fbGoToReviewFormLink").click(function(event) { event.preventDefault(); fluidSocial.tabSwap('fluid-fbTab2Content'); $("#fluid-toggleFriendReviewsLink").text('Hide'); $("#fluid-reviewsBox").slideDown(); $('#fluid-friendsTabReviewText').focus(); }); fluidSocial.parseDomElement('fluid-fbCommentBubbleWrapper'); }); }, getFriendReviews: function() { var fluidSocial = this; fluidSocial.debug("In getFriendReviews"); window.frames['fluid_api_server'].fluidSocialConnector.getFriendReviews( this.productId, function(response) { if (!fluidSocial.validateResponse(response)) return; $("#fluid-fbFriendsContent").html(response); $('input[type=radio].star', $('#fluid-fbFriendsContent')).rating(); var commentCount = $('#fluid-fbFriendsContent .fluid-friendsTabPost').length; fluidSocial.debug("Friend Comment Count: " + commentCount); $('.fluid-fbCommentCount').html('(' + commentCount + ')'); $("#fluid-toggleFriendReviewsLink").click(function(event) { event.preventDefault(); if ($("#fluid-reviewsBox").is(":hidden")) { $("#fluid-toggleFriendReviewsLink").text('Hide'); $("#fluid-reviewsBox").slideDown(); } else { $("#fluid-toggleFriendReviewsLink").text('Show'); $("#fluid-reviewsBox").slideUp(); } }); $("#fluid-friendsTabPostingSubmit a").click(function(event) { event.preventDefault(); fluidSocial.postFriendsTabReview(); }); fluidSocial.reattachEventHandlers(); fluidSocial.parseDomElement('fluid-fbFriendsContent'); }); }, getFriendFavorites: function() { var fluidSocial = this; window.frames['fluid_api_server'].fluidSocialConnector.getFriendFavorites( this.productId, function(response) { if (!fluidSocial.validateResponse(response)) return; $("#fluid-fbFavoritesContent").html(response); // Ensure that the standalone version has unique ids. response = response.replace('fluid-favoritesTabCountMessage', 'fluid-standaloneFavoritesTabCountMessage'); response = response.replace('fluid-toggleFriendFavoritesLink', 'fluid-toggleFriendStandaloneFavoritesLink'); response = response.replace('fluid-favoritesBox', 'fluid-standaloneFavoritesBox'); response = response.replace('fluid-favoritesScroller', 'fluid-standaloneFavoritesScroller'); $("#fluid-fbStandaloneFavoritesContent").html(response); $("#fluid-favoritesScroller .scrollable").scrollable({ size: fluidSocial.favoritesScrollerSize, clickable: false }); $("#fluid-standaloneFavoritesScroller .scrollable").scrollable({ size: fluidSocial.standaloneFavoritesScrollerSize, clickable: false }); var favoritesCount = $('#fluid-fbFavoritesContent .fluid-scrollerItem').length; fluidSocial.debug("Friend Favorites Count: " + favoritesCount); $('.fluid-fbFavoritesCount').html('(' + favoritesCount + ')'); if (favoritesCount <= fluidSocial.favoritesScrollerSize) { $("#fluid-favoritesScroller .next").addClass("disabled"); } var standaloneFavoritesCount = $('#fluid-fbStandaloneFavoritesContent .fluid-scrollerItem').length; fluidSocial.debug("Standalone Friend Favorites Count: " + standaloneFavoritesCount); if (standaloneFavoritesCount <= fluidSocial.standaloneFavoritesScrollerSize) { $("#fluid-standaloneFavoritesScroller .next").addClass("disabled"); } $("#fluid-toggleFriendFavoritesLink").click(function(event) { event.preventDefault(); if ($("#fluid-favoritesBox").is(":hidden")) { $("#fluid-toggleFriendFavoritesLink").text('Hide'); $("#fluid-favoritesBox").slideDown(); } else { $("#fluid-toggleFriendFavoritesLink").text('Show'); $("#fluid-favoritesBox").slideUp(); } }); $("#fluid-toggleFriendStandaloneFavoritesLink").click(function(event) { event.preventDefault(); if ($("#fluid-standaloneFavoritesBox").is(":hidden")) { $("#fluid-toggleStandaloneFriendFavoritesLink").text('Hide'); $("#fluid-standaloneFavoritesBox").slideDown(); } else { $("#fluid-toggleFriendStandaloneFavoritesLink").text('Show'); $("#fluid-standaloneFavoritesBox").slideUp(); } }); $("a.fluid-friendFavoriteLink").click(function(event) { event.preventDefault(); // Inform GA that the user clicked on a friend's favorite. if (fluidSocial.analyticsPresent()) { pageTracker._trackEvent("PDP Events", "Friend Favorite Clicked"); } location.href = $(this).attr("href"); }); fluidSocial.reattachEventHandlers(); }); }, postFriendsTabReview: function() { var fluidSocial = this; $("#fluid-friendsTabPostingErrorMessage").hide(); $("#fluid-friendsTabPostingProgressMessage").show(); var rating = $("input[name='friendsTabRating']:checked").attr("value"); var review = $("#fluid-friendsTabReviewText").attr("value"); this.debug("postFriendsTabReview: " + this.productId + ", " + rating + ", " + review); if (rating == undefined && review == '') { $("#fluid-friendsTabPostingProgressMessage").hide(); alert('Please enter a rating or a review.'); return; } if (rating == undefined) rating = 0; window.frames['fluid_api_server'].fluidSocialConnector.postReview( this.productId, rating, review, function(response) { if (!fluidSocial.validateResponse(response)) return; // success callback $("#fluid-friendsTabPostingProgressMessage").hide(); fluidSocial.getFriendReviews(); // Inform GA that the product was commented on and rated. if (fluidSocial.analyticsPresent()) { pageTracker._trackEvent("PDP Events", "Review and Rate Product", this.productId, Number(rating)); } // Allow the user to post to their FB feed. var templateData = { "productName": fluidSocial.productName, "pdpUrl": fluidSocial.pdpUrl, "images": [{"src": fluidSocial.thumbnailUrl.replace(/%20/, ' '), "href": fluidSocial.pdpUrl}], "rating": rating + " star" + ((rating != 1) ? 's' : '') }; FB.Connect.showFeedDialog('97630478173', templateData, null, null, null, FB.RequireConnect.require, null, null, {value: review}); }, function() { // error callback $("#fluid-friendsTabPostingProgressMessage").hide(); $("#fluid-friendsTabPostingErrorMessage").show(); } ); }, sendFeedback: function() { // Validate the form. var reason = $("#fluid-feedback_form_reason").attr("value"); var email = $("#fluid-feedback_form_email").attr("value"); var subject = $("#fluid-feedback_form_subject").attr("value"); var message = $("#fluid-feedback_form_message").attr("value"); this.debug("sendFeedback: " + reason + ", " + email + ", " + subject + ", " + message); var valid = true; if (reason == '') { valid = false; $("#fluid-feedback_form_reason").addClass("fluid-feedback_form_value_error"); $("label[for=fluid-feedback_form_reason]").addClass("fluid-feedback_form_label_error"); } else { $("#fluid-feedback_form_reason").removeClass("fluid-feedback_form_value_error"); $("label[for=fluid-feedback_form_reason]").removeClass("fluid-feedback_form_label_error"); } if (message == '') { valid = false; $("#fluid-feedback_form_message").addClass("fluid-feedback_form_value_error"); $("label[for=fluid-feedback_form_message]").addClass("fluid-feedback_form_label_error"); } else { $("#fluid-feedback_form_message").removeClass("fluid-feedback_form_value_error"); $("label[for=fluid-feedback_form_message]").removeClass("fluid-feedback_form_label_error"); } if (!valid) return; this.closeDialogs(); // Submit the feedback to the server. window.frames['fluid_api_server'].fluidSocialConnector.sendFeedback( reason, email, subject, message, function(response) { if (!fluidSocial.validateResponse(response)) return; // Inform GA that feedback was submitted. if (fluidSocial.analyticsPresent()) { pageTracker._trackEvent("PDP Events", "Feedback Submitted", this.productId); } // Show confirmation. var message = $('
Thanks for your feedback!
'); fluidSocial.statusDialog = new FB.UI.PopupDialog('Feedback Received', message.get(0), false, false); fluidSocial.statusDialog.setContentWidth(400); fluidSocial.statusDialog.set_placement(FB.UI.PopupPlacement.topCenter); fluidSocial.statusDialog.add_closing(function() { fluidSocial.statusDialog = null; }); fluidSocial.statusDialog.show(); } ); }, closeDialogs: function() { if (this.sendInviteDialog != null) { this.sendInviteDialog.close(false); this.sendInviteDialog = null; } if (this.statusDialog != null) { this.statusDialog.close(false); this.statusDialog = null; } $('#fluid-howitworks').hide(); $('#fluid-firstVisitPopupWrapper').hide(); $('#fluid-feedback').hide(); }, validateResponse: function(response) { var valid; if (response.indexOf('top.location.href') == -1) { valid = true; } else { // The user logged into the FB app first, and Facebook // has messed up the session cookies. No choice but // to logout of Facebook and start over. this.closeDialogs(); FB.Connect.logout(); valid = false; } return valid; }, debug: function(message) { if (window.console) console.log(message); }, analyticsPresent: function() { return (typeof(pageTracker) != 'undefined' && pageTracker != null); }, parseDomElement: function(elementId) { var element = $('#' + elementId); if (element.length > 0) FB.XFBML.Host.parseDomElement(element.get(0)); } };