Rewrite code using requirejs, jquery