﻿(function($) { $.fn.share = function(options) { var defaults = { digg: true, facebook: true, stumbleUpon: true, twitter: true, delicious: true, reddit: true, title: "", url: "", direction: "bottom", delay: 1 }; var options = $.extend(defaults, options); var digg = { cssClass: "DiggSmall", text: "Digg", func: "openDigg" }; var facebook = { cssClass: "FacebookSmall", text: "Facebook", func: "openFacebook" }; var stumbleupon = { cssClass: "StumbleUponSmall", text: "StumbleUpon", func: "openStumbleupon" }; var twitter = { cssClass: "TwitterSmall", text: "Twitter", func: "openTwitter" }; var delicious = { cssClass: "DeliciousSmall", text: "Del.icio.us", func: "openDelicious" }; var reddit = { cssClass: "RedditSmall", text: "Reddit", func: "openReddit" }; var timer; function addShareLink(container, linkObj) { var share = new shareMethods(options.title, options.url); var anchor = $("<a>" + linkObj.text + "</a>").addClass(linkObj.cssClass).click(eval("share." + linkObj.func)).attr("href", "#"); container.append($("<li>").append(anchor)); } function getContainer() { var container = $(".share_modal"); if (container.length > 0) { return container.empty(); } return $("<ul>").addClass("share_modal").appendTo("body"); } return this.hover(function() { switch (options.direction) { case "bottom": var container = getContainer().css({ top: $(this).offset().top + $(this).height() + 2, left: $(this).offset().left }); break; case "top": var container = getContainer().css({ top: $(this).offset().top - $(this).height() - 70, left: $(this).offset().left }); break; case "left": var container = getContainer().css({ top: $(this).offset().top, left: $(this).offset().left - 268 }); break; case "right": var container = getContainer().css({}); break; default: break; } if (options.digg) { addShareLink(container, digg); } if (options.facebook) { addShareLink(container, facebook); } if (options.stumbleUpon) { addShareLink(container, stumbleupon); } if (options.twitter) { addShareLink(container, twitter); } if (options.delicious) { addShareLink(container, delicious); } if (options.reddit) { addShareLink(container, reddit); } $(container).hover(function() { clearTimeout(timer); }, function() { container.remove(); }); }, function() { clearTimeout(timer); timer = setTimeout(function() { $(".share_modal").remove(); }, options.delay * 1000); }).click(function() { return false; }); }; })(jQuery); function shareMethods(d, a) { var e = escape(d ? d : jQuery("meta[name=title]").attr("content")); if (!e) { e = document.title; } var c = a ? a : b(); this.openReddit = function() { window.open("http://reddit.com/submit?title=" + e + "&url=" + c); return false; }; this.openFacebook = function() { window.open("http://www.facebook.com/share.php?u=" + c); return false; }; this.openStumbleupon = function() { window.open("http://www.stumbleupon.com/submit?url=" + c + "&title=" + e); return false; }; this.openDigg = function() { window.open("http://digg.com/submit?phase=2&title=" + e + "&url=" + c); return false; }; this.openDelicious = function() { window.open("http://del.icio.us/post?url=" + c + "&title=" + e); return false; }; this.openTwitter = function() { bitlyAPI(c, function(f) { if (f) { c = f; } window.open("http://twitter.com/home?status=" + c + " " + e); }); return false; }; function b() { var g = window.location.toString(); var f = g.indexOf("#"); if (f != -1) { g = g.substring(0, f); } return g; } }
