refactored jQuery code into angularJS directives