﻿/*
Social Buttons using jQuery and XML

By: Bryian Tan (bryian.tan at ysatech.com)
09112011 v01.00.00

Description:
Social sharing buttons script created using jQuery and XML.
The buttons container and buttons setting are stored in the XML file.
*/

var button_settings = { displayGooglePlusOne: "block", displayFacebookLike: "block", displayFacebookShare: "block", displayTwitter: "block", displayAddThis: "block", displayDigg: "none", displayStumbleUpon: "none", bgColor: "#fff", divPosition: "left", divMargin: "10%", divBorderStyle: "solid", divBorderWidth: 1, divBgColor: "Red", divPadding: 5, borderColor: "#000" }; var social_buttons = { setupDiv: function() { var a = button_settings.divMargin; if ($.browser.msie) { a = a - button_settings.divPadding * 2 } switch (button_settings.divPosition.toLowerCase()) { case "right": $("[id$='ysaSocialButton']").css({ right: 0, borderWidth: button_settings.divBorderWidth, width: 60, height: "auto", "margin-right": a + "px" }); break; case "left": $("[id$='ysaSocialButton']").css({ left: 0, borderWidth: button_settings.divBorderWidth, width: 60, height: "auto", "margin-left": a + "px" }); break; case "bottom": $("[id$='ysaSocialButton']").css({ bottom: 0, borderWidth: button_settings.divBorderWidth, width: "auto", height: 25, "margin-left": a + "px" }); break; default: $("[id$='ysaSocialButton']").css({ top: 0, borderWidth: button_settings.divBorderWidth, width: "auto", height: 28, "margin-left": a + "px" }) } }, createButtons: function() { var a = window.location.href; var b = $('<div id="ysaSocialButton"></div>').css({ position: "fixed", display: "block", "border-style": button_settings.divBorderStyle, "background-color": button_settings.divBgColor, "border-color": button_settings.borderColor, opacity: .9, textAlign: "center", padding: button_settings.divPadding }); switch (button_settings.divPosition.toLowerCase()) { case "left": case "right": b.append('<iframe allowtransparency="true" id="I5_1315804648720" name="I5_1315804648720" src="https://plusone.google.com/u/0/_/+1/fastbutton?url=' + a + '&size=tall&count=true&hl=en-US&jsh=r%3Bgc%2F22431124-0a127465#id=I5_1315804648720&rpctoken=709405964&_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" style="border:0;height:65px;width:70px;display:' + button_settings.displayGooglePlusOne + '"></iframe>'); b.append('<iframe scrolling="no" frameborder="0" allowtransparency="true" src="http://platform.twitter.com/widgets/tweet_button.html#_=1314929830654&count=vertical&id=twitter_tweet_button_0&lang=en&&text=&url=' + a + '" class="twitter-share-button twitter-count-horizontal" style="width: 70px; height: 65px; padding-top:5px;display:' + button_settings.displayTwitter + '" title="Twitter For Websites: Tweet Button"></iframe>'); b.append('<iframe scrolling="no" frameborder="0" allowtransparency="true" style="border: medium none; overflow: hidden; height: 65px;width:70px;padding-top:5px;display:' + button_settings.displayFacebookLike + '" src="http://www.facebook.com/plugins/like.php?app_id=215422211845197&href=' + a + '&send=false&layout=box_count&width=450&show_faces=true&action=like&colorscheme=light&font&height=65"></iframe>'); var c = '<div style="border: medium; overflow: hidden;height: 65px;width:70px;padding-top:5px;display:' + button_settings.displayFacebookShare + '"><a name="fb_share" type="box_count" href="http://www.facebook.com/sharer.php">Share</a></div>'; $.getScript("http://static.ak.fbcdn.net/connect.php/js/FB.Share", function() { }); b.append(c); var d = '<div style="border: medium; overflow: hidden; height: 70px;width:60px;padding-top:5px;display:' + button_settings.displayDigg + '"><a class="DiggThisButton DiggMedium"></a></div>'; $.getScript("http://widgets.digg.com/buttons.js", function() { }); b.append(d); var e = '<div style="border:medium;overflow:hidden;height:70px;width:60px;padding-top:5px;display:' + button_settings.displayAddThis + '"><a class="addthis_counter"></a></div>'; $.getScript("http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4a445bb32ad435b1", function() { }); b.append(e); var f = '<iframe scrolling="no" frameborder="0" allowtransparency="true" style="border: medium none;padding-top:5px; overflow: hidden; height: 65px;width:70px;display:' + button_settings.displayStumbleUpon + '" src="http://www.stumbleupon.com/badge/embed/5/?url=' + a + '"></iframe>'; b.append(f); break; case "bottom": case "top": b.append('<iframe id="I5_1315804648720" name="I5_1315804648720" allowtransparency="true" src="https://plusone.google.com/u/0/_/+1/fastbutton?url=' + a + '&size=standard&count=true&hl=en-US&jsh=r%3Bgc%2F22431124-0a127465#id=I5_1315804648720&rpctoken=709405964&_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" style="border:0;float:left;height:40px;width:70px;display:' + button_settings.displayGooglePlusOne + '"></iframe>'); b.append('<iframe scrolling="no" frameborder="0" allowtransparency="true" src="http://platform.twitter.com/widgets/tweet_button.html#_=1314929830654&count=horizontal&id=twitter_tweet_button_0&lang=en&&text=&url=' + a + '" class="twitter-share-button twitter-count-horizontal" style="width: 105px; height: 45px; padding-top:0px;float:left;display:' + button_settings.displayTwitter + '" title="Twitter For Websites: Tweet Button"></iframe>'); b.append('<iframe scrolling="no" frameborder="0" allowtransparency="true" style="border: medium none; overflow: hidden; height: 40px;width:80px;float:left;display:' + button_settings.displayFacebookLike + '" src="http://www.facebook.com/plugins/like.php?app_id=215422211845197&href=' + a + '&send=false&layout=button_count&width=450&show_faces=true&action=like&colorscheme=light&font&height=65"></iframe>'); var c = '<div style="border: medium; overflow: hidden; height: 40px;width:90px;padding-top:0px;float:left;display:' + button_settings.displayFacebookShare + '"><a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a></div>'; $.getScript("http://static.ak.fbcdn.net/connect.php/js/FB.Share", function() { }); b.append(c); var d = '<div style="border:medium;overflow:hidden;height:40px;width:90px;float:left;display:' + button_settings.displayDigg + '"><a class="DiggThisButton DiggCompact"></a></div>'; $.getScript("http://widgets.digg.com/buttons.js", function() { }); b.append(d); var e = '<div style="border: medium; overflow: hidden; height: 40px;width:100px;padding-left:5px;float:left;display:' + button_settings.displayAddThis + '"><a class="addthis_counter addthis_pill_style addthis_nonzero addthis_nonzero" style="display: block;"></a></div>'; $.getScript("http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4a445bb32ad435b1", function() { }); b.append(e); var f = '<iframe scrolling="no" frameborder="0" allowtransparency="true" style="border: medium none; overflow: hidden; height: 45px;width:80px;float:left;display:' + button_settings.displayStumbleUpon + '" src="http://www.stumbleupon.com/badge/embed/1/?url=' + a + '"></iframe>'; b.append(f); break } $("body").prepend(b); social_buttons.setupDiv() }, getButtonSetting: function() { $.ajax({ type: "GET", url: "xml/SocialButton.xml", dataType: "xml", success: function(a) { $(a).find("Button").each(function() { var a = $(this).find("DisplayGooglePlusOne").text(), b = $(this).find("DisplayFacebookLike").text(), c = $(this).find("DisplayFacebookShare").text(), d = $(this).find("DisplayTwitter").text(), e = $(this).find("DisplayDigg").text(), f = $(this).find("DisplayAddThis").text(), g = $(this).find("DisplayStumbleUpon").text(), h = $(this).find("DivPosition").text(), i = $(this).find("BgColor").text(), j = $(this).find("DivMargin").text(), k = $(this).find("DivBorderStyle").text(), l = $(this).find("DivBorderWidth").text(), m = $(this).find("DivBorderColor").text(), n = $(this).find("DivBgColor").text(); button_settings.displayGooglePlusOne = a; button_settings.displayFacebookLike = b; button_settings.displayFacebookShare = c; button_settings.displayTwitter = d; button_settings.displayDigg = e; button_settings.displayAddThis = f; button_settings.displayStumbleUpon = g; button_settings.divPosition = h; button_settings.bgColor = i; button_settings.divMargin = j; button_settings.divBorderStyle = k; button_settings.divBorderWidth = parseInt(l); button_settings.borderColor = m; button_settings.divBgColor = n }); social_buttons.createButtons() } }) }, init: function() { $(document).ready(function() { social_buttons.getButtonSetting() }) } }; social_buttons.init()
