|
/* 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); |
|
} |
|
}; |