Update directives.js

Sometimes the window is loaded already.
Merge pull request #2 from wmh/patch-1

Update directives.js