ShareAll = { AjaxPOSTSync: function(q,d){var r;var w=window;if(w.XMLHttpRequest)r=new w.XMLHttpRequest();else{try{r=new w.ActiveXObject("MSXML2.XMLHTTP");}catch(ex){return null;}} r.open('POST',q,false);r.setRequestHeader('Content-Type','application/x-www-form-urlencoded');r.send(encodeURI(d));if(!w.JSON) return null; if(r.readyState===4&&r.status===200)return w.JSON.parse(r.responseText);return null;}, selfUrl: function(noUri){ if(noUri===true) return window.location.protocol+'//'+window.location.hostname; else return window.location.href; }, prepare: function(purl,ptitle,pimg,text){ //Check params: if(purl==null||purl=='') purl=ShareAll.selfUrl(); //Get current url. if(ptitle==null) ptitle=$('meta[name="og:title"]').attr('content'); if(pimg==null) pimg=$('meta[name="og:image"]').attr('content'); if(text==null) text=$('meta[name="og:description"]').attr('content'); //Re-check params after 1st attempt to resolve. if(ptitle==null||ptitle=='') ptitle='Default title'; if(pimg==null) pimg=''; if(text==null||text=='') text='Default description'; //Form a url query: if(purl.indexOf('#')==-1){ //Only if hashtag wasn't added prematurely... if(window.location.hash!="") purl=purl+window.location.hash; //Add hash, mufucka! } purl=encodeURIComponent(purl); //Encode, mufucka! var tempData = ShareAll.AjaxPOSTSync('/?module=shareall&ajax','title='+ptitle+'&description='+text+'&image='+pimg+'&url='+purl); //JSON parsing - part of this function. var genUrl = ShareAll.selfUrl(true)+'/?module=shareall&opcode='+tempData.opCode; return genUrl; }, popup: function(url,provider,countscore){ //Display popup: window.open(url,'','toolbar=0,status=0,width=626,height=436'); var networkNum = -1; if(provider==null||provider=="") provider="unknown"; //In case of a bug. if(provider=='vk') networkNum = 0; if(provider=='fb') networkNum = 1; if(provider=='twitter') networkNum = 2; if(provider=='odnoklassniki') networkNum = 3; if(provider=='google') networkNum = -1; if(provider=='mailru') networkNum = -1; if(countscore!=null) if(countscore) ShareAll.AjaxPOSTSync('/?module=stuff&shareReq='+networkNum,''); //If set & true. if(provider!=null&&provider!="") ShareAll.AjaxPOSTSync('/?module=sharecount&subject='+provider+'_share&id=0',''); //Provider-related share counter. }, //Social networks follow: vkontakte: function(purl,ptitle,pimg,text,countscore){ var purl = ShareAll.prepare(purl,ptitle,pimg,text); var url = 'http://vkontakte.ru/share.php?'; url += 'url='+encodeURIComponent(purl); if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){ //VK doesn't handle sharing on mobile devices properly: //Check params (shameless code duplication): if(ptitle==null) ptitle=$('meta[name="og:title"]').attr('content'); if(pimg==null) pimg=$('meta[name="og:image"]').attr('content'); if(text==null) text=$('meta[name="og:description"]').attr('content'); //Re-check params after 1st attempt to resolve. if(ptitle==null||ptitle=='') ptitle='Default title'; if(pimg==null) pimg=''; if(text==null||text=='') text='Default description'; if(pimg!=''&&pimg.indexOf('http')==-1) pimg=window.location.protocol+'//'+window.location.hostname+'/'+pimg; //Correct path! //Append mobile info to url: url += '&title=' + encodeURIComponent(ptitle); url += '&description=' + encodeURIComponent(text); url += '&image=' + encodeURIComponent(pimg); url += '&noparse=true'; } ShareAll.popup(url,'vk',countscore); }, google: function(purl,ptitle,pimg,text,countscore){ var purl = ShareAll.prepare(purl,ptitle,pimg,text); var url = 'https://plus.google.com/share?'; url += 'url='+encodeURIComponent(purl); ShareAll.popup(url,'google',countscore); }, odnoklassniki: function(purl,ptitle,pimg,text,countscore){ var purl = ShareAll.prepare(purl,ptitle,pimg,text); var url = 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1'; //OK text redo: if(text==null) text=$('meta[name="og:description"]').attr('content'); if(text==null||text=='') text='Default description'; url += '&st.comments='+encodeURIComponent(text); url += '&st._surl='+encodeURIComponent(purl); ShareAll.popup(url,'odnoklassniki',countscore); }, facebook: function(purl,ptitle,pimg,text,countscore){ var purl = ShareAll.prepare(purl,ptitle,pimg,text); //var url = 'http://www.facebook.com/sharer.php?s=100'; //url += '&p[url]=' + encodeURIComponent(purl); var url = 'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(purl); ShareAll.popup(url,'fb',countscore); }, twitter: function(purl,ptitle,pimg,text,countscore){ var purl = ShareAll.prepare(purl,ptitle,pimg,text); var url = 'http://twitter.com/share?'; //TW text redo: if(text==null) text=$('meta[name="og:description"]').attr('content'); if(text==null||text=='') text='Default description'; url += 'text=' + encodeURIComponent(text); url += '&url=' + encodeURIComponent(purl); url += '&counturl=' + encodeURIComponent(purl); ShareAll.popup(url,'twitter',countscore); }, mailru: function(purl,ptitle,pimg,text,countscore){ var purl = ShareAll.prepare(purl,ptitle,pimg,text); var url = 'http://connect.mail.ru/share?'; url += 'url=' + encodeURIComponent(purl); ShareAll.popup(url,'mailru',countscore); } };