Moving DOM logic in demo to directive