You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScriptUtil.js 1.1KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Implements utility functions which facilitate the dealing with scripts such
  3. * as the download and execution of a JavaScript file.
  4. */
  5. var ScriptUtil = {
  6. /**
  7. * Loads a script from a specific source.
  8. *
  9. * @param src the source from the which the script is to be (down)loaded
  10. * @param async true to asynchronously load the script or false to
  11. * synchronously load the script
  12. * @param prepend true to schedule the loading of the script as soon as
  13. * possible or false to schedule the loading of the script at the end of the
  14. * scripts known at the time
  15. */
  16. loadScript: function (src, async, prepend) {
  17. var d = document;
  18. var tagName = 'script';
  19. var script = d.createElement(tagName);
  20. var referenceNode = d.getElementsByTagName(tagName)[0];
  21. script.async = async;
  22. script.src = src;
  23. if (prepend) {
  24. referenceNode.parentNode.insertBefore(script, referenceNode);
  25. } else {
  26. referenceNode.parentNode.appendChild(script);
  27. }
  28. },
  29. };
  30. module.exports = ScriptUtil;