Refactor directive.js