(function(d){var c=d.requires("underscore"),k=d.requires("jquery"),e=d.requires("BaseControl"),g=d.requires("asyncRequest"),h=d.requires("Events");d.exports("scripts.FollowToggler",e.extend(function(d){var e={urlAttribute:"href",toggleClass:"is-following",toggleContainerClass:"",actionClassSuffix:"",globalEventSuffix:"",selectedClass:"",loadingClass:"loading",requestMethod:"GET"};return{init:function(a,b){c.defaults(b,e);d.init.call(this,a,b)},beforeDecoration:function(){var a=this._config;this._globalEventSuffix=
a.globalEventSuffix.length?":"+a.globalEventSuffix:"";this._followButtonClass=".action-follow"+a.actionClassSuffix;this._unfollowButtonClass=".action-unfollow"+a.actionClassSuffix},attachEventListeners:function(){var a=function(a,c){c.preventDefault();a(c)};this._$el.on("click",this._followButtonClass,c.bind(a,this,c.bind(this.follow,this)));this._$el.on("click",this._unfollowButtonClass,c.bind(a,this,c.bind(this.unfollow,this)))},_makeRequest:function(a,b,c){LI&&LI.asyncRequest?g(this._config.requestMethod,
a,{scope:this,success:b,failure:c,custom:{exception:c,error:c}}):g({url:a,type:this._config.requestMethod,success:b,error:c})},_doAction:function(a,b,d){var e,f;f=c.bind(function(b){a._$toggleContainer.removeClass(this._config.loadingClass);b(a)},this);e=c.wrap(c.bind(this._triggerFailureEvent,this,a,b),f);d=c.wrap(c.bind(d,this),f);switch(b){case "follow":b=a._followUrl;break;case "unfollow":b=a._unfollowUrl;break;default:throw Error("Unrecognized action");}a._$toggleContainer.addClass(this._config.loadingClass);
this._makeRequest(b,d,e)},_triggerFailureEvent:function(a,b){h.trigger("follow-toggler:"+b+":failure"+this._globalEventSuffix,a._id,this)},_triggerSuccessEvent:function(a,b){h.trigger("follow-toggler:"+b+":success"+this._globalEventSuffix,a._id,this)},_afterFollowSuccess:function(a){a._$toggleContainer.addClass(this._config.toggleClass);a._$unfollowEl.addClass(this._config.selectedClass);a._$followEl.removeClass(this._config.selectedClass)},follow:function(a){a=this._getFollowObj(a);this._doAction(a,
"follow",function(a){this._afterFollowSuccess(a);c.isFunction(this._followCB)&&this._followCB();this._triggerSuccessEvent(a,"follow")})},_followCB:null,_afterUnfollowSuccess:function(a){a._$toggleContainer.removeClass(this._config.toggleClass);a._$unfollowEl.removeClass(this._config.selectedClass);a._$followEl.addClass(this._config.selectedClass)},unfollow:function(a){a=this._getFollowObj(a);this._doAction(a,"unfollow",function(a){this._afterUnfollowSuccess(a);c.isFunction(this._unfollowCB)&&this._unfollowCB();
this._triggerSuccessEvent(a,"unfollow")})},_unfollowCB:null,_getFollowObj:function(a){var b={};a=k(a.target);b._$toggleContainer=this._config.toggleContainerClass?a.closest("."+this._config.toggleContainerClass):this._$el;b._$followEl=b._$toggleContainer.find(this._followButtonClass);b._followUrl=b._$followEl.attr(this._config.urlAttribute);b._$unfollowEl=b._$toggleContainer.find(this._unfollowButtonClass);b._unfollowUrl=b._$unfollowEl.attr(this._config.urlAttribute);(a=b._followUrl.match(/(followee|memberId|channels)[=|\/](\d+)/i))&&
3<=a.length&&(b._id=a[2]);return b}}}))})(window.LIModules);