var followCompanyApp = angular.module('followCompanyApp', ["commonsApp"]); followCompanyApp.directive('followCompany',['Constants','commonsAppServices','mySharedService','$timeout', function( Constants,commonsAppServices,sharedService,$timeout) { return { restrict: "E", replace: true, scope: { isFollowing : '@', companyId : '=', callbackFn : '&', showFollowText : '@', showToolTip:'@', showTip:'@', nonLoggedInCallback:'&', }, template: 'FOLLOW
'+ ' FOLLOWING THIS COMPANY
', link:function(scope, element, attrs) { scope.following = false; scope.showTip = false; var initializing = true; element.bind('click', function() { sharedService.showLoading(); if(!memberData.isUserLoggedIn){ scope.nonLoggedInCallback(); return; } scope.following = !scope.$eval(attrs.isFollowing); commonsAppServices.followCompany(scope.companyId, scope.following).then(function(result) { if(scope.following == "true" || scope.following == true) { element.removeClass("fa-star-o"); element.addClass("fa-star"); scope.following = "false"; sharedService.hideLoading(); scope.callbackFn(); $timeout(function() { // scope.isFollowing = scope.$eval(attrs.isFollowing); scope.$apply(); }); } else if(scope.following == "false" || scope.following == false) { element.addClass("fa-star-o"); element.removeClass("fa-star"); scope.following = "true"; scope.callbackFn(); sharedService.hideLoading(); $timeout(function() { // scope.isFollowing = scope.$eval(attrs.isFollowing); scope.$apply(); }); } }); }); scope.$watch(function() {return element.attr('is-following'); }, function(newValue){ if (initializing) { $timeout(function() { initializing = false; },1000); } else { newValue = scope.$eval(newValue); if(newValue == true) { if(scope.showToolTip){ scope.showTip = true; $timeout(function(){ scope.showTip = false; scope.$apply(); },3000); } } } }); } }; }]);