Instantly share code, notes, and snippets.
Created
September 24, 2014 19:26
-
Save anythinggraphic/cd475e545e5f1e7deb0f to your computer and use it in GitHub Desktop.
Hideshare - Includes Email Option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*-----Version of hideshare modified by Patrick */ | |
/*! hideshare - v0.1.0 - 2013-09-11 | |
* https://github.com/arnonate/jQuery-FASS-Widget | |
* Copyright (c) 2013 Nate Arnold; Licensed MIT */ | |
/* ======================================================================== | |
* HIDESHARE v1.0.0 | |
* https://github.com/arnonate/hideshare | |
* ======================================================================== | |
Copyright (c) 2013 Nate Arnold | |
Permission is hereby granted, free of charge, to any person | |
obtaining a copy of this software and associated documentation | |
files (the "Software"), to deal in the Software without | |
restriction, including without limitation the rights to use, | |
copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the | |
Software is furnished to do so, subject to the following | |
conditions: | |
The above copyright notice and this permission notice shall be | |
included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
*/ | |
/*global jQuery:false, window:false, document:false */ | |
;(function(window, $) { | |
"use strict"; | |
// HIDESHARE PUBLIC CLASS DEFINITION | |
// ================================= | |
var Hideshare = function (elem, options) { | |
this.elem = elem; | |
this.$elem = $(elem); | |
this.options = options; | |
Hideshare.numInstances = (Hideshare.numInstances || 0) + 1; | |
this.instanceNumber = Hideshare.numInstances; | |
}; | |
Hideshare.prototype = { | |
defaults: { | |
link: document.URL, | |
title: document.title, | |
description: '', | |
media: null, | |
facebook: true, | |
twitter: true, | |
pinterest: true, | |
googleplus: true, | |
linkedin: true, | |
email: true, | |
position: "bottom", | |
speed: 100 | |
}, | |
init: function() { | |
this.config = $.extend({}, this.defaults, this.options); | |
this.wrapHideshare(); | |
return this; | |
}, | |
wrapHideshare: function() { | |
var output = output, | |
width = this.$elem.outerWidth(), | |
height = this.$elem.outerHeight(), | |
liWidth = 0, | |
placement = this.config.position, | |
transition = this.config.speed, | |
shareTitle = this.config.title, | |
shareLink = this.config.link, | |
shareMedia = this.config.media, | |
shareDescription = this.config.description, | |
facebookTemplate = '<li><a class="hideshare-facebook" id="hideshare-facebook_' + this.instanceNumber + '" href="#"><i class="fa fa-facebook fa-2x"></i><span>Facebook</span></a></li>', | |
twitterTemplate = '<li><a class="hideshare-twitter" id="hideshare-twitter_' + this.instanceNumber + '" href="#"><i class="fa fa-twitter fa-2x"></i><span>Twitter</span></a></li>', | |
pinterestTemplate = '<li><a class="hideshare-pinterest" id="hideshare-pinterest_' + this.instanceNumber + '" href="#" data-pin-do="buttonPin" data-pin-config="above"><i class="fa fa-pinterest fa-2x"></i><span>Pinterest</span></a></li>', | |
googleplusTemplate = '<li><a class="hideshare-google-plus" id="hideshare-google-plus_' + this.instanceNumber + '" href="#"><i class="fa fa-google-plus fa-2x"></i><span>Google Plus</span></a></li>', | |
linkedinTemplate = '<li><a class="hideshare-linkedin" id="hideshare-linkedin_' + this.instanceNumber + '" href="#"><i class="fa fa-linkedin fa-2x"></i><span>Linked In</span></a></li>', | |
emailTemplate = '<li><a id="hideshare-email_' + this.instanceNumber + '"href="mailto:?subject=You might be interested in this job listing from Elevano"><i class="fa fa-envelope"></i></a></li>' | |
if (this.config.facebook) { | |
output = facebookTemplate; | |
liWidth += 40; | |
} else { | |
output = ""; | |
liWidth = liWidth; | |
} | |
if (this.config.twitter) { | |
output += twitterTemplate; | |
liWidth += 40; | |
} else { | |
output = output; | |
liWidth = liWidth; | |
} | |
if (this.config.pinterest) { | |
output += pinterestTemplate; | |
liWidth += 40; | |
} else { | |
output = output; | |
liWidth = liWidth; | |
} | |
if (this.config.googleplus) { | |
output += googleplusTemplate; | |
liWidth += 40; | |
} else { | |
output = output; | |
liWidth = liWidth; | |
} | |
if (this.config.linkedin) { | |
output += linkedinTemplate; | |
liWidth += 40; | |
} else { | |
output = output; | |
liWidth = liWidth; | |
} | |
if (this.config.email) { | |
output += emailTemplate; | |
liWidth += 40; | |
} else { | |
output = output; | |
liWidth = liWidth; | |
} | |
if (liWidth < width) { | |
liWidth = width; | |
} | |
// Construct sharing list | |
var hideshareList = '<ul class="hideshare-list" style="display: none; width: ' + liWidth + 'px' + '">' + output + '</ul>'; | |
// Wrap button | |
this.$elem.addClass("hideshare-btn").wrap("<div class='hideshare-wrap' style='width:" + width + "px; height:" + height + "px;' />"); | |
// Insert sharing button list | |
$(hideshareList).insertAfter(this.$elem); | |
// Get placement of share buttons | |
var getPlacement = function(placement, width, height, speed) { | |
var styles = {}; | |
if (placement === "right") { | |
styles = { | |
"left" : width + 10 + "px", | |
"right" : -(width + 10) + "px", | |
"opacity" : "toggle" | |
}; | |
} else if (placement === "left") { | |
styles = { | |
"left" : -(width + 10) + "px", | |
"right" : width + 10 + "px", | |
"opacity" : "toggle" | |
}; | |
} else if (placement === "top") { | |
styles = { | |
"top" : -(height + 10) + "px", | |
"bottom" : height + 10 + "px", | |
"opacity" : "toggle" | |
}; | |
} else /* placement === "bottom" */ { | |
styles = { | |
"top" : height + 10 + "px", | |
"bottom" : -(height + 10) + "px", | |
"left" : "0px", | |
"opacity" : "toggle" | |
}; | |
} | |
$(".hideshare-list").animate(styles, speed).addClass("shown"); | |
}; | |
// Return to original position | |
var returnPlacement = function(speed) { | |
var styles = { | |
"top" : "0px", | |
"left" : "0px", | |
"opacity" : "toggle" | |
}; | |
$(".hideshare-list").animate(styles, speed).removeClass("shown"); | |
}; | |
// Toggle sharing on button click | |
this.$elem.click(function() { | |
var list = $(".hideshare-list"); | |
if (list.hasClass("shown")){ | |
returnPlacement(transition); | |
} else { | |
getPlacement(placement, width, height, transition); | |
} | |
return false; | |
}); | |
// SHARING FUNCTIONS | |
var shareFacebook = function() { | |
window.open('//www.facebook.com/share.php?m2w&s=100&p[url]=' + encodeURIComponent(shareLink) + '&p[images][0]=' + encodeURIComponent(shareMedia) + '&p[title]=' + encodeURIComponent(shareTitle) + '&p[summary]=' + encodeURIComponent(shareDescription),'Facebook','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); | |
}; | |
var shareTwitter = function() { | |
window.open('https://twitter.com/intent/tweet?original_referer=' + encodeURIComponent(shareLink) + '&text=' + encodeURIComponent(shareTitle) + '%20' + encodeURIComponent(shareLink),'Twitter','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); | |
}; | |
var sharePinterest = function() { | |
window.open('//pinterest.com/pin/create/button/?url=' + encodeURIComponent(shareLink) + '&media=' + encodeURIComponent(shareMedia) + '&description=' + encodeURIComponent(shareTitle),'Pinterest','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); | |
}; | |
var shareGooglePlus = function() { | |
window.open('//plus.google.com/share?url=' + encodeURIComponent(shareLink),'GooglePlus','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); | |
}; | |
var shareLinkedIn = function() { | |
window.open('//www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(shareLink) + '&title=' + encodeURIComponent(shareTitle) + '&source=' + encodeURIComponent(shareLink),'LinkedIn','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); | |
}; | |
var shareEmail = function() { | |
'<a href="mailto:?subject=You might be interested in this job listing from Elevano"><i class="fa fa-envelope"></i></a>'; | |
//window.open('//www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(shareLink) + '&title=' + encodeURIComponent(shareTitle) + '&source=' + encodeURIComponent(shareLink),'LinkedIn','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600'); | |
}; | |
$("#hideshare-facebook_" + this.instanceNumber).click(function() { | |
shareFacebook(); | |
return false; | |
}); | |
$("#hideshare-twitter_" + this.instanceNumber).click(function() { | |
shareTwitter(); | |
return false; | |
}); | |
$("#hideshare-pinterest_" + this.instanceNumber).click(function() { | |
sharePinterest(); | |
return false; | |
}); | |
$("#hideshare-google-plus_" + this.instanceNumber).click(function() { | |
shareGooglePlus(); | |
return false; | |
}); | |
$("#hideshare-linkedin_" + this.instanceNumber).click(function() { | |
shareLinkedIn(); | |
return false; | |
}); | |
$("#hideshare-email_" + this.instanceNumber).click(function() { | |
shareEmail(); | |
}); | |
} | |
}; | |
Hideshare.defaults = Hideshare.prototype.defaults; | |
$.fn.hideshare = function(options) { | |
return this.each(function() { | |
new Hideshare(this, options).init(); | |
}); | |
}; | |
window.Hideshare = Hideshare; | |
})(window, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment