Converted some of javascript logic into directives