/* * SocialBW * Copyright 2015 MadeInPluto * www.madeinpluto.com * * Version 1.0 - Last Updated: Feb 06, 2015 * * Licenced to BateWorld for exclusive use on www.bateworld.com * */ (function($){ var PLUGIN_NS = 'socialBW'; var Plugin = function ( target, options ) { this.$T = $(target); var opts = $.extend( true, { height: '150px', speedIn: 400, speedOut: 600, displayTitle: true, title: "Share & Tell a Friend", socialtitle: "", socialurl: "", icons: "facebook,twitter,google,digg,delicious,stumble,tumblr,linkedin,live,myspace,bebo,email", targetBlank: true, fbLikebox: true, fbAction: "like", fbcolorscheme: "light", tweets: true, tweetText: "", tweetVia: "bateworld", twitterRelated: "bateworld", tweetButton: "Tweet", pin: true, pinMedia: "", gplus: true, ga: false, open: function(){}, opened: function(){}, exit: function(){}, exited: function(){}, sticker: true, stickerAlign: 'left' }, options ); $(this).data(opts); this._create( target, opts ); $(target).click(function() { Plugin.prototype.open(opts); }) $('#socialBW_close, #socialBW_overlay').click(function(){ Plugin.prototype.close(opts); }); return this; } Plugin.prototype._create = function (target, opts) { var iformat = { email : "mailto:?subject={TITLE}&body={DESCRIPTION}%20{URL}", digg : "http://digg.com/submit?phase=2&url={URL}&title={TITLE}", linkedin : "http://www.linkedin.com/shareArticle?mini=true&url={URL}&title={TITLE}&summary={DESCRIPTION}&source=", technorati : "http://www.technorati.com/faves?add={URL}", delicious : "http://del.icio.us/post?url={URL}&title={TITLE}", yahoo : "http://myweb2.search.yahoo.com/myresults/bookmarklet?u={URL}&t={TITLE}", google : "http://www.google.com/bookmarks/mark?op=edit&bkmk={URL}&title={TITLE}", newsvine : "http://www.newsvine.com/_wine/save?u={URL}&h={TITLE}", reddit : "http://reddit.com/submit?url={URL}&title={TITLE}", live : "https://favorites.live.com/quickadd.aspx?marklet=1&mkt=en-us&url={URL}&title={TITLE}&top=1", facebook : "http://www.facebook.com/share.php?u={URL}", twitter : "http://twitter.com/?status={TITLE}%20-%20{URL}", stumble : "http://www.stumbleupon.com/submit?url={URL}&title={TITLE}", orkut : "http://promote.orkut.com/preview?nt=orkut.com&tt={TITLE}&du={URL}&cn={DESCRIPTION}", bebo : "http://www.bebo.com/c/share?Url={URL}&title={TITLE}", evernote : "http://s.evernote.com/grclip?url={URL}&title={TITLE}", mixx : "http://www.mixx.com/submit?page_url={URL}&title={TITLE}", myspace : "http://www.myspace.com/Modules/PostTo/Pages/?u={URL}&title={TITLE}", netvibes : "http://www.netvibes.com/share?title={TITLE}&url={URL}", tumblr : "http://www.tumblr.com/share?v=3&u={URL}&t={TITLE}&s=", friendfeed : "http://friendfeed.com/share/bookmarklet/frame#title={TITLE}&url={URL}", designmoo : "http://www.designmoo.com/node/add/drigg/?url={URL}&title={TITLE}", designfloat : "http://www.designfloat.com/submit.php?url={URL}&title={TITLE}", designbump : "http://www.designbump.com/node/add/drigg/?url={URL}&title={TITLE}", squidoo : "http://www.squidoo.com/lensmaster/bookmark?{URL}", yahoo_buzz : "http://buzz.yahoo.com/buzz?targetUrl={URL}&headline={TITLE}&summary={DESCRIPTION}", pinterest : "http://pinterest.com/pin/create/button/?url={URL}&description={DESCRIPTION}", print : 'javascript:void(0);" onClick="window.print();" target="_self', favorites : 'javascript:void(0);" onClick="alert(\'Press ctrl + D to bookmark\');" target="_self' }; var shared_title = opts.socialtitle ? opts.socialtitle : document.title; var shared_url = opts.socialurl ? opts.socialurl : document.location.href; var meta_description = $("meta[name=description]").attr("content"); var socialBW = $('
'); if (opts.displayTitle) { var title = $(''); } var icons = $(''); if(opts.fbLikebox) { var fbLikebox = ''; } else { var fbLikebox = ''; } if(opts.tweets) { var tweet_via = '&via='+opts.tweetVia; var tweets = ''; } else { var tweets = ''; } if(opts.gplus) { var gplus = ''; } else { var gplus =''; } if(opts.pin) { if(opts.pinMedia){ var pin = ''; } else { var pin = ''; } } else { var pin = ''; } if (opts.fbLikebox || opts.tweets || opts.gplus || opts.pin) { var extras = $(''); } socialBW.html(title); socialBW.append(icons, extras); $('body').append(socialBW); $(".pin_socialBW").click(function(event){ event.preventDefault(); $("#pinmarklet").remove(); var pin = document.createElement('script'); pin.setAttribute('type','text/javascript'); pin.setAttribute('charset','UTF-8'); pin.setAttribute('id','pinmarklet'); pin.setAttribute('src','http://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999); document.body.appendChild(pin); }); var overlay = $(''); $('body').append(overlay); if (opts.sticker) { var sticker = $(''); $('body').append(sticker); } var social = opts.icons.split(","); for ( var key in social ) { var services = social[key]; var name = services.replace(/_/gi, " "); var url = iformat[services]; var target = opts.targetBlank ? "_blank" : "_self"; if(url){ url = url.replace("{TITLE}", encodeURIComponent(shared_title)); url = url.replace("{URL}", encodeURIComponent(shared_url)); url = url.replace("{DESCRIPTION}", encodeURIComponent(meta_description)); var sociallink = '' + name + ''; $(sociallink).appendTo(icons); } } // Google Analytics $(".socialBW_icon").click(function(){ if(opts.ga){ var _gaq = _gaq || []; var name = $(this).text(); _gaq.push(['_trackSocial', name, 'social', shared_url]); } }); } // end GA var dummy = $('socialBW'); $('body').append(dummy); Plugin.prototype.open = function (opts) { if(opts == '') var opts = $(this).data(); var socialBW = $('#socialBW'); opts.open.call(this); $(socialBW).stop(); $("#socialBW_overlay").fadeIn(opts.speedIn); $(socialBW).fadeIn(opts.speedIn); opts.opened.call(this); $(document).keyup(function(e) { if ($(socialBW).is(":visible") && e.keyCode == 27) { $(".socialBW").socialBW('close'); } }); var $win = $(window); var winH = $win.height(); var winW = $win.width(); socialBW.css('top', winH/2-socialBW.height()/2); socialBW.css('left', winW/2-socialBW.width()/2); $win.resize(function() { var winH = $win.height(); var winW = $win.width(); socialBW.css('top', winH/2-socialBW.height()/2); socialBW.css('left', winW/2-socialBW.width()/2); }); return this.$T; } Plugin.prototype.close = function (opts) { if(opts == '') var opts = $(this).data(); var socialBW = $('#socialBW'); opts.exit.call(this); $("#socialBW_overlay").fadeOut(opts.speedOut); socialBW.fadeOut(opts.speedOut); opts.exited.call(this); return this.$T; } $.fn[ PLUGIN_NS ] = function( methodOrOptions ) { if (!$(this).length) { return $(this); } var instance = $(this).data(PLUGIN_NS); if ( instance && methodOrOptions.indexOf('_') != 0 && instance[ methodOrOptions ] && typeof( instance[ methodOrOptions ] ) == 'function' ) { return instance[ methodOrOptions ]( Array.prototype.slice.call( arguments, 1 ) ); } else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) { instance = new Plugin( $(this), methodOrOptions ); $(this).data( PLUGIN_NS, instance ); return $(this); } else if ( !instance ) { $.error( 'socialBW must be initialised before using method: ' + methodOrOptions ); } else if ( methodOrOptions.indexOf('_') == 0 ) { $.error( 'Method ' + methodOrOptions + ' is private!' ); } else { $.error( 'Method ' + methodOrOptions + ' does not exist.' ); } }; })(jQuery);