Skip to content

Instantly share code, notes, and snippets.

@cbertelegni
Last active December 18, 2015 08:19
Show Gist options
  • Save cbertelegni/5752960 to your computer and use it in GitHub Desktop.
Save cbertelegni/5752960 to your computer and use it in GitHub Desktop.
Mini social share plugin.

Mini plugin para compartir urls en redes sociales.

Ejemplo de uso:

var conf_share = {
   text: "Esto es un test!!",
	hashtag: "ejemplo",
	configWindow: null // toma el valor seteado por el plugin... 
};

var social = new MiniSocial(conf_share);

var boton = document.getElementById("facebook");

boton.onclick = function(){ 
   social.share("facebook");
   return false;
};

Tags html para Face

<!-- mestas face-->
<meta property="og:title" content="This is my web!"/>
<meta property="og:image" content="http://myweb.com/static/img/image.jpg"/>
<meta property="og:site_name" content="My web "/>
<meta property="og:description" content=""/>
/* Mini social share */
/*
* For: @cbertelegni
* https://gist.github.com/cbertelegni/5752960
*
* Posibles Redes Sociales:
* Facebook
* Twitter
* Google Plus
* Enviar URL por mail
*
*
* Ejemplo de uso:
*
* var conf_share = {
* text: "Esto es un test!!",
* hashtag: "ejemplo",
* configWindow: null // toma el valor seteado por el plugin...
* };
* var social = new MiniSocial(conf_share);
* var boton = document.getElementById("facebook");
* boton.onclick = function(){
* social.share("facebook");
* return false;
* };
*
*/
var MiniSocial = function (config){
if (!config) var config = {};
this.configWindow = "toolbar=no, location=no, resizable=no, scrollbars=no, width=500, height=300";
if(config.configWindow) this.configWindow = config.configWindow;
this.title = window.document.title;
this.text = config.text ? config.text : "";
this.hashTag = config.hashtag ? config.hashtag : "";
this.href;
}
MiniSocial.prototype.share = function(social){
var self = this;
switch (social){
case "facebook":
case "fb":
var w = window.open( self.get.face(self), "Facebook", self.configWindow);
break;
case "twitter":
case "tw":
var w = window.open( self.get.twitter(self), "Twitter", self.configWindow);
break;
case "plus":
case "g+":
var w = window.open( self.get.plus(self), "Google_Plus", self.configWindow);
break;
case "mail":
// var w = window.open( self.get.mail(self), "Mail", self.configWindow);
window.location.href = self.get.mail(self);
break;
}
};
MiniSocial.prototype.get= {
url: function(self){
return window.location.href
},
face: function(self){
var _face = {
u : self.get.url(),
t : self.title
};
var url = 'http://www.facebook.com/share.php?' + $.param(_face);
return url;
},
twitter: function(self){
var url = "http://twitter.com/?status=";
url += encodeURIComponent( self.text+ " "+ self.hashTag+ " " + self.get.url());
return url;
},
plus: function(self){
var url = "https://plus.google.com/share?url=";
url += self.get.url();
return url;
},
mail: function mailpage(self){
var url = "mailto:?subject=" + self.title;
var u = "&body=" + self.title + " ";
u += self.text + " ";
u += ". Enlace: " + self.get.url();
return url + (u);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment