Files
Testing/js/scripts/socialBW.js
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

322 lines
12 KiB
JavaScript

/*
* 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 = $('<div id="socialBW"></div>');
if (opts.displayTitle) {
var title = $('<div id="socialBW_title"><span>'+ opts.title +'</span><span id="socialBW_close"><a href="javascript:void(0);" class="socialBW_close">x</a></span></div>');
}
var icons = $('<div id="socialBW_icons" style="height:'+ opts.height +';"></div>');
if(opts.fbLikebox) {
var fbLikebox = '<iframe src="http://www.facebook.com/plugins/like.php?href='+ encodeURIComponent(shared_url) +'&amp;layout=button_count&amp;width=100&amp;action='+ opts.fbAction +'&amp;colorscheme='+ opts.fbcolorscheme +'&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:105px; height:30px; float:left;" allowTransparency="true"></iframe>';
} else {
var fbLikebox = '';
}
if(opts.tweets) {
var tweet_via = '&amp;via='+opts.tweetVia;
var tweets = '<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.html?url='+ encodeURIComponent(shared_url) +'&amp;text='+ encodeURIComponent(opts.tweetText) + '&amp;related='+ encodeURIComponent(opts.twitterRelated) + tweet_via +'" style="width:100px; height:30px; float:left;"></iframe>';
} else {
var tweets = '';
}
if(opts.gplus) {
var gplus = '<iframe allowtransparency="true" frameborder="0" scrolling="no" src="https://plusone.google.com/u/0/_/+1/fastbutton?url='+ encodeURIComponent(shared_url) +'&amp;size=medium" style="width:85px; height:30px; float:left;"></iframe>';
} else {
var gplus ='';
}
if(opts.pin) {
if(opts.pinMedia){
var pin = '<div style="width:80px; height:30px; padding: 5px; float:left;"><a data-pin-config="beside" href="http://pinterest.com/pin/create/button/?url='+ encodeURIComponent(shared_url) +'&media='+ encodeURIComponent(opts.pinMedia) +'&description='+ encodeURIComponent(meta_description) +'" target="_blank" data-pin-do="buttonPin"><img src="http://assets.pinterest.com/images/pidgets/pin_it_button.png" /></a></div>';
} else {
var pin = '<div style="width:80px; height:21px; padding: 5px; float:left;"><a class="pin_socialBW" href="http://pinterest.com/pin/create/button/?url='+ encodeURIComponent(shared_url) +'"><img src="http://assets.pinterest.com/images/pidgets/pin_it_button.png" /></a></div>';
}
} else {
var pin = '';
}
if (opts.fbLikebox || opts.tweets || opts.gplus || opts.pin) {
var extras = $('<div id="socialBW_extras" style="height:60px;clear:both;">' + fbLikebox + tweets + gplus + pin + '</div>');
}
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 = $('<div id="socialBW_overlay"></div>');
$('body').append(overlay);
if (opts.sticker) {
var sticker = $('<a href="javascript:void(0);" onClick="jQuery(\'.socialBW\').socialBW(\'open\');" class="socialBW"><div id="socialBW_sticker" class="'+ opts.stickerAlign +'"></div></a>');
$('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 = '<a href="' + url + '" target="' + target + '" class="socialBW_icon ' + name + '"><span>' + name + '</span></a>';
$(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 = $('<a href="javascript:void(0);" class="socialBW" style="display:none;visibility:hidden;">socialBW</a>');
$('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);