var wpFollow;(function($){var extWin;wpFollow={version:'1382729516',lang:'en',jsonAPIbase:'https://public-api.wordpress.com/rest/v1',hasUpgradedProxy:false,isLoggedIn:false,APIqueue:[],cache:[],batchFinished:true,batchWaiting:[],me:false,blogInfo:{},isFollowing:false,showFollowerCount:false,showBlogName:true,i18n:false,wpFollow:function(){wpFollow.query=wpFollow.splitParams(location.hash.replace(/^#/,''));if(undefined!==wpFollow.query.lang){wpFollow.lang=wpFollow.query.lang;}
if(undefined!==wpFollow.query.show_follower_count){wpFollow.showFollowerCount=(wpFollow.query.show_follower_count=="true"||wpFollow.query.show_follower_count=="yes")?true:false;}
if(undefined!==wpFollow.query.show_blog_name){wpFollow.showBlogName=(wpFollow.query.show_blog_name=="true"||wpFollow.query.show_blog_name=="yes")?true:false;}
wpFollow.loadTranslation();wpFollow.getBatchData(wpFollow.query.blog,wpFollow.displayWidget);},followBlog:function(blog,success,error){return this.ajax({type:'POST',path:'/sites/'+encodeURIComponent(blog)+'/follows/new',success:success,error:error});},unfollowBlog:function(blog,success,error){return this.ajax({type:'POST',path:'/sites/'+encodeURIComponent(blog)+'/follows/mine/delete',success:success,error:error});},doFollow:function(blog){if(!wpFollow.isLoggedIn){wpFollow.openLoginWindow();return;}
if(false==wpFollow.isFollowing){wpFollow.followBlog(blog,function(result){wpFollow.isFollowing=true;++wpFollow.blogInfo.subscribers_count;wpFollow.updateWidget();});}else if(true==wpFollow.isFollowing){wpFollow.unfollowBlog(blog,function(result){wpFollow.isFollowing=false;--wpFollow.blogInfo.subscribers_count;wpFollow.updateWidget();});}},splitParams:function(queryString){var params={};jQuery.each(queryString.split('&'),function(i,value){var pair=value.split('=');params[pair[0]]=decodeURIComponent(pair[1]);});return params;},ajax:function(options){var request={path:options.path,method:options.type,url:wpFollow.jsonAPIbase+options.path};if(!wpFollow.batchFinished&&'/batch'!==options.path){wpFollow.batchWaiting.push(options);return;}
if('undefined'==typeof options.fromCache)
options.fromCache=true;if(options.path in wpFollow.cache&&options.fromCache){'function'==typeof options.success&&options.success(wpFollow.cache[options.path],options.path);return;}
if(options.type.toLowerCase()=='post'){request.body=options.data;request.query=options.query;}else{request.query=options.data;}
var data={event:'ajax',request:request};var makeProxyCall=function(){return jQuery.wpcom_proxy_request(request,function(response,statusCode){if(200==statusCode)
'function'==typeof options.success&&options.success(response,request.path);else
'function'==typeof options.error&&options.error(statusCode,request.path);});};if(wpFollow.hasUpgradedProxy){return makeProxyCall();}else{return jQuery.wpcom_proxy_request({metaAPI:{accessAllUsersBlogs:true}}).done(function(){wpFollow.hasUpgradedProxy=true;makeProxyCall();});}},postMessage:function(message,target,messageType){if("string"===typeof message){try{message=JSON.parse(message);}
catch(e){return;}}
if('undefined'==typeof messageType){messageType='followMessage';}
pm({target:target,type:messageType,data:message});},openLoginWindow:function(){if(extWin){if(!extWin.closed){extWin.close();}
extWin=false;}
$('#wp-login-polling-iframe').remove();var url='//wordpress.com/public.api/connect/?action=request&service=wordpress';extWin=window.open(url,'likeconn','status=0,toolbar=0,location=1,menubar=0,directories=0,resizable=1,scrollbars=1,height=500,width=1000');var loginIframe=$("<iframe id='wp-login-polling-iframe'></iframe>");loginIframe.attr("src","//wordpress.com/public.api/connect/?iframe=true");loginIframe.css("display","none");$(document.body).append(loginIframe);},loadTranslation:function(){var load_default=true;if('en'!=wpFollow.lang){var json_locale_data;jQuery.ajax({url:'/languages/'+wpFollow.lang+'.json'+'?ver='+wpFollow.version,dataType:'json',async:false,success:function(json){json_locale_data=json;load_default=false;}});}
if(null==json_locale_data)
load_default=true;if(load_default){var json_locale_data={"":{"domain":"messages","lang":wpFollow.lang,"plural-forms":"nplurals=2; plural=(n != 1);"}};}
wpFollow.i18n=new Jed({locale_data:{"messages":json_locale_data},"domain":"messages"});},getBatchData:function(blog_url,callback){blog_url=encodeURIComponent(blog_url);wpFollow.APIqueue.push('/me');wpFollow.APIqueue.push('/sites/'+blog_url+'/follows/mine');var batchRequest={path:'/batch',type:'GET',url:'//public-api.wordpress.com/rest/v1/batch',data:{urls:wpFollow.APIqueue},success:function(response){for(var path in response){if(!response[path]['error_data']&&!response[path]['errors']){if('/me'==path){wpFollow.me=response[path];wpFollow.isLoggedIn=true;}else if(('/sites/'+blog_url+'/follows/mine')==path){wpFollow.isFollowing=response[path].is_following;}else{continue;}}}
jQuery.get(wpFollow.jsonAPIbase+'/sites/'+blog_url,function(response){wpFollow.blogInfo=response;callback();});},error:function(response){console.log('batch loading error');}};wpFollow.ajax(batchRequest);},readMessage:function(event){if("undefined"==typeof event.event)
return;if('login'==event.event&&event.success){if(extWin){if(!extWin.closed){extWin.close();}
extWin=false;}
$('#wp-login-polling-iframe').remove();wpFollow.isLoggedIn=true;wpFollow.hasUpgradedProxy=false;$.wpcom_proxy_rebuild();wpFollow.doFollow(wpFollow.blogInfo.URL);}},displayWidget:function(){var style=document.createElement('link');style.setAttribute('type','text/css');style.setAttribute('rel','stylesheet');style.setAttribute('href','//widgets.wp.com/follow/style.css?ver='+wpFollow.version);jQuery(document).find('head')[0].appendChild(style);if(undefined!==wpFollow.blogInfo.URL)
wpFollow.updateWidget();},updateWidget:function(){var following=wpFollow.isFollowing?'following':'follow';var label=wpFollow.i18n.translate(following.charAt(0).toUpperCase()+following.slice(1)).fetch();if(wpFollow.showBlogName)
label+=' '+wpFollow.blogInfo.name;var template=jQuery('#wordpress-follow-button').html();jQuery('body').find('#target').html(_.template(template)({following:following,label:label,show_follower_count:wpFollow.showFollowerCount,subscribers_count:wpFollow.blogInfo.subscribers_count.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}));jQuery(document).find('.wordpress-follow-button a').click(function(e){e.preventDefault();wpFollow.doFollow(wpFollow.blogInfo.URL);});}};wpFollow.wpFollow();pm.bind('loginMessage',function(e){wpFollow.readMessage(e);});})(jQuery);