Instead of requiring cordova, may be you could check if cordova exists. And do the code above if it does and otherwise do the old way.