insertcode.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. UE.parse.register("insertcode", function(utils) {
  2. var pres = this.root.getElementsByTagName("pre");
  3. if (pres.length) {
  4. if (typeof XRegExp == "undefined") {
  5. var jsurl, cssurl;
  6. if (this.rootPath !== undefined) {
  7. jsurl =
  8. utils.removeLastbs(this.rootPath) +
  9. "/third-party/SyntaxHighlighter/shCore.js";
  10. cssurl =
  11. utils.removeLastbs(this.rootPath) +
  12. "/third-party/SyntaxHighlighter/shCoreDefault.css";
  13. } else {
  14. jsurl = this.highlightJsUrl;
  15. cssurl = this.highlightCssUrl;
  16. }
  17. utils.loadFile(document, {
  18. id: "syntaxhighlighter_css",
  19. tag: "link",
  20. rel: "stylesheet",
  21. type: "text/css",
  22. href: cssurl
  23. });
  24. utils.loadFile(
  25. document,
  26. {
  27. id: "syntaxhighlighter_js",
  28. src: jsurl,
  29. tag: "script",
  30. type: "text/javascript",
  31. defer: "defer"
  32. },
  33. function() {
  34. utils.each(pres, function(pi) {
  35. if (pi && /brush/i.test(pi.className)) {
  36. SyntaxHighlighter.highlight(pi);
  37. }
  38. });
  39. }
  40. );
  41. } else {
  42. utils.each(pres, function(pi) {
  43. if (pi && /brush/i.test(pi.className)) {
  44. SyntaxHighlighter.highlight(pi);
  45. }
  46. });
  47. }
  48. }
  49. });