Файл: магазин/e-proger/js/share.min.js
Строк: 509
<?php
(function(){var Share,reinit,watch;Share=function(){function Share(){null==window.sharing_buttons&&(window.sharing_buttons={}),this.init()}var ajax,create_counter,generate_callback_script,options,services;return options={url:window.location.href.replace(window.location.hash,""),title:document.title,counters:!0,button_title:""},null==window.VK&&(window.VK={}),window.VK.Share={count:function(idx,number){var script;return script=document.getElementById("vkontakte-"+idx+"-init-script"),null!=script&&script.remove(),number>0?create_counter(document.getElementById("vkontakte-button-"+idx),number):void 0}},services={vkontakte:{url:"https://vk.com/share.php?url={{url}}&title={{title}}",counter_url:"https://vk.com/share.php?url={{url}}&act=count&index={{index}}",counter:0,title:"Поделиться в ВК",remove_attr:["title","text"]},facebook:{url:"https://www.facebook.com/sharer/sharer.php?u={{url}}",counter_url:'https://graph.facebook.com/fql?q=SELECT total_count FROM link_stat WHERE url="{{url}}"',type:"ajax",title:"Facebook",remove_attr:["title","text"],getter:function(type,element,counter_url,url){return ajax.get(counter_url,[],services[type].callback,!0,{element:element})},callback:function(response,opt){return response=JSON.parse(response),response.data.length&&null!=response.data[0].total_count&&response.data[0].total_count>0?create_counter(opt.element,response.data[0].total_count):void 0}},twitter:{url:"https://twitter.com/intent/tweet?url={{url}}&text={{title}}",counter_url:"",counter:0,title:"Twitter",remove_attr:["title","text"]},"google-plus":{url:"https://plus.google.com/share?url={{url}}",counter_url:"https://clients6.google.com/rpc",type:"ajax",counter:0,title:"Google+",remove_attr:["title","text"],getter:function(type,element,counter_url,url){var params;return window.sharing_buttons[type]++,params={method:"pos.plusones.get",id:type+"-button-"+window.sharing_buttons[type],jsonrpc:"2.0",key:"p",apiVersion:"v1",params:{nolog:!0,id:url,source:"widget",userId:"@viewer",groupId:"@self"}},element.setAttribute("id",type+"-button-"+window.sharing_buttons[type]),ajax.post(services[type].counter_url,params,services[type].callback,!0)},callback:function(response){return response=JSON.parse(response),null==response.result.metadata.globalCounts.count||response.result.metadata.globalCounts.count<=0?void 0:create_counter(document.getElementById(response.id),response.result.metadata.globalCounts.count)}},pinterest:{url:"https://pinterest.com/pin/create/button/?url={{url}}&description={{title}}",counter_url:"https://api.pinterest.com/v1/urls/count.json?url={{url}}",counter:0,title:"Pinterest",remove_attr:["title","text"]}},ajax={},ajax.x=function(){var i,j,len,versions,xhr;if("undefined"!=typeof XMLHttpRequest&&null!==XMLHttpRequest)return new XMLHttpRequest;for(versions=["MSXML2.XmlHttp.6.0","MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp.2.0","Microsoft.XmlHttp"],xhr=null,j=0,len=versions.length;len>j;j++){i=versions[j];try{xhr=new ActiveXObject(versions[i]);break}catch(_error){}}return xhr},ajax.send=function(url,callback,method,data,sync,params){var x;return x=ajax.x(),x.open(method,url,sync),x.onreadystatechange=function(){return 4===x.readyState?callback(x.responseText,params):void 0},"POST"===method&&x.setRequestHeader("Content-type","application/json"),x.send(data)},ajax.get=function(url,data,callback,sync,params){var key,query;query=[];for(key in data)query.push(encodeURIComponent(key)+"="+encodeURIComponent(data[key]));return query.length&&(url+="?"+query.join("&")),ajax.send(url,callback,"GET",null,sync,params)},ajax.post=function(url,data,callback,sync,params){var query;return query=[],ajax.send(url,callback,"POST",JSON.stringify(data),sync,params)},Share.prototype.init=function(){var elements,results,type_service;results=[];for(type_service in services)elements=document.querySelectorAll(".sharing-buttons ."+type_service),elements.length&&results.push(this.init_type_buttons(elements,type_service));return results},Share.prototype.init_type_buttons=function(elements,type){var i,j,ref,results;for(results=[],i=j=0,ref=elements.length-1;ref>=0?ref>=j:j>=ref;i=ref>=0?++j:--j)results.push(this.button(elements.item(i),type));return results},Share.prototype.button=function(element,type){var btn,img,share_url,text,url;if(null!=element&&!element.classList.contains("sharing-widget"))return img=document.createElement("span"),img.className="share-icon",btn=document.createElement("span"),url=this.get_share_url(type,element),btn.className="sharing-button",text=document.createTextNode(element.dataset.text||services[type].title),btn.appendChild(text),element.innerHTML="",element.title=element.getAttribute("title")||options.button_title+services[type].title,element.className+=" sharing-widget",element.onclick=function(){return window.open(url)},element.appendChild(img),element.appendChild(btn),share_url=element.dataset.url||element.parentElement.dataset.url||options.url,"true"===element.parentElement.dataset.counters||options.counters&&null==element.parentElement.dataset.counters?(null==window.sharing_buttons[type]&&(window.sharing_buttons[type]=0),this.get_counter(type,element,share_url)):void 0},Share.prototype.get_share_url=function(type,element,title){var baseUrl,param,params,url;url=element.dataset.url||element.parentElement.dataset.url||options.url,title=element.dataset.title||element.parentElement.dataset.title||options.title,/^(https?):///i.test(url)||-1!=="http://".indexOf(url)||(url="http://"+url),baseUrl=services[type].url,null!=url&&(baseUrl=baseUrl.replace("{{url}}",url)),null!=title&&(baseUrl=baseUrl.replace("{{title}}",title)),params=[];for(param in element.dataset)this.is_add_attribute(type,param)||params.push([param,element.dataset[param]].join("="));return params.length&&(baseUrl+="&"+params.join("&")),baseUrl},Share.prototype.get_counter=function(type,element,url){var counter_url;if(null!=services[type].counter_url&&0!==services[type].counter_url.length)return/^(https?):///i.test(url)||-1!=="http://".indexOf(url)||(url="http://"+url),counter_url=services[type].counter_url,null!=url&&(counter_url=counter_url.replace("{{url}}",encodeURIComponent(url))),null!=services[type].type&&"ajax"===services[type].type?services[type].getter(type,element,counter_url,url):this.create_script(type,element,counter_url,url)},Share.prototype.create_script=function(type,element,counter_url,url){var script;return window.sharing_buttons[type]++,counter_url=counter_url.replace("{{index}}",window.sharing_buttons[type]),element.setAttribute("id",type+"-button-"+window.sharing_buttons[type]),"vkontakte"!==type&&generate_callback_script(type,window.sharing_buttons[type]),script=document.createElement("script"),script.type="text/javascript",script.id=type+"-"+window.sharing_buttons[type]+"-init-script",script.setAttribute("src",counter_url+("&callback="+type+"_"+window.sharing_buttons[type]+"_callback")),element.appendChild(script)},Share.prototype.is_add_attribute=function(type,attribute){var j,len,param,ref;if(null==services[type].remove_attr)return!1;for(ref=services[type].remove_attr,j=0,len=ref.length;len>j;j++)if(param=ref[j],param===attribute)return!0;return!1},create_counter=function(element,count){var counter;return counter=document.createElement("span"),counter.className="sharing-couter",counter.appendChild(document.createTextNode(count)),element.appendChild(counter)},generate_callback_script=function(type,number){var code,e,script;script=document.createElement("script"),script.type="text/javascript",script.id=type+"-"+number+"-script",code=["function "+type+"_"+number+"_callback(data) {","if (typeof data.count != 'undefined' && data.count > 0) {","var counter = document.createElement('span'); counter.className = 'sharing-couter';","counter.appendChild(document.createTextNode(data.count));","document.getElementById('"+type+"-button-"+number+"').appendChild(counter); }","document.getElementById('"+type+"-"+number+"-init-script').remove();","document.getElementById('"+type+"-"+number+"-script').remove();}"].join(" ");try{return script.appendChild(document.createTextNode(code)),document.body.appendChild(script)}catch(_error){return e=_error,script.text=code,document.body.appendChild(script)}},Share}(),new Share,watch=function(){var options;return options=document.getElementById("sharing-buttons-options"),"true"===options.dataset.watch?setInterval(function(){return reinit()},300):void 0},reinit=function(){var element,j,len,ref;if(element=document.getElementById("sharing-buttons-options"),"true"===element.dataset.reinit){for(element.removeAttribute("data-reinit"),ref=document.querySelectorAll(".sharing-widget"),j=0,len=ref.length;len>j;j++)element=ref[j],element.classList.remove("sharing-widget");return new Share}},null!=document.getElementById("sharing-buttons-options")&&watch()}).call(this);
?>