/tags/jsdoc_toolkit-2.3.2/jsdoc-toolkit/app/frame/Link.js

http://jsdoc-toolkit.googlecode.com/ · JavaScript · 153 lines · 119 code · 22 blank · 12 comment · 33 complexity · d8943a603c06a65d285de7883bd2d289 MD5 · raw file

  1. /** Handle the creation of HTML links to documented symbols.
  2. @constructor
  3. */
  4. function Link() {
  5. this.alias = "";
  6. this.src = "";
  7. this.file = "";
  8. this.text = "";
  9. this.innerName = "";
  10. this.classLink = false;
  11. this.targetName = "";
  12. this.target = function(targetName) {
  13. if (defined(targetName)) this.targetName = targetName;
  14. return this;
  15. }
  16. this.inner = function(inner) {
  17. if (defined(inner)) this.innerName = inner;
  18. return this;
  19. }
  20. this.withText = function(text) {
  21. if (defined(text)) this.text = text;
  22. return this;
  23. }
  24. this.toSrc = function(filename) {
  25. if (defined(filename)) this.src = filename;
  26. return this;
  27. }
  28. this.toSymbol = function(alias) {
  29. if (defined(alias)) this.alias = new String(alias);
  30. return this;
  31. }
  32. this.toClass = function(alias) {
  33. this.classLink = true;
  34. return this.toSymbol(alias);
  35. }
  36. this.toFile = function(file) {
  37. if (defined(file)) this.file = file;
  38. return this;
  39. }
  40. this.toString = function() {
  41. var linkString;
  42. var thisLink = this;
  43. if (this.alias) {
  44. linkString = this.alias.replace(/(^|[^a-z$0-9_#.:^-])([|a-z$0-9_#.:^-]+)($|[^a-z$0-9_#.:^-])/i,
  45. function(match, prematch, symbolName, postmatch) {
  46. var symbolNames = symbolName.split("|");
  47. var links = [];
  48. for (var i = 0, l = symbolNames.length; i < l; i++) {
  49. thisLink.alias = symbolNames[i];
  50. links.push(thisLink._makeSymbolLink(symbolNames[i]));
  51. }
  52. return prematch+links.join("|")+postmatch;
  53. }
  54. );
  55. }
  56. else if (this.src) {
  57. linkString = thisLink._makeSrcLink(this.src);
  58. }
  59. else if (this.file) {
  60. linkString = thisLink._makeFileLink(this.file);
  61. }
  62. return linkString;
  63. }
  64. }
  65. /** prefixed for hashes */
  66. Link.hashPrefix = "";
  67. /** Appended to the front of relative link paths. */
  68. Link.base = "";
  69. Link.symbolNameToLinkName = function(symbol) {
  70. var linker = "";
  71. if (symbol.isStatic) linker = ".";
  72. else if (symbol.isInner) linker = "-";
  73. return Link.hashPrefix+linker+symbol.name;
  74. }
  75. /** Create a link to another symbol. */
  76. Link.prototype._makeSymbolLink = function(alias) {
  77. var linkBase = Link.base+publish.conf.symbolsDir;
  78. var linkTo = Link.symbolSet.getSymbol(alias);
  79. var linkPath;
  80. var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
  81. // is it an internal link?
  82. if (alias.charAt(0) == "#") var linkPath = alias;
  83. // if there is no symbol by that name just return the name unaltered
  84. else if (!linkTo) return this.text || alias;
  85. // it's a symbol in another file
  86. else {
  87. if (!linkTo.is("CONSTRUCTOR") && !linkTo.isNamespace) { // it's a method or property
  88. if (linkTo.isEvent) {
  89. linkPath =
  90. (Link.filemap)? Link.filemap[linkTo.memberOf]
  91. :
  92. escape(linkTo.memberOf) || "_global_";
  93. linkPath += publish.conf.ext + "#event:" + Link.symbolNameToLinkName(linkTo);
  94. }
  95. else {
  96. linkPath =
  97. (Link.filemap)? Link.filemap[linkTo.memberOf]
  98. :
  99. escape(linkTo.memberOf) || "_global_";
  100. linkPath += publish.conf.ext + "#" + Link.symbolNameToLinkName(linkTo);
  101. }
  102. }
  103. else {
  104. linkPath = (Link.filemap)? Link.filemap[linkTo.alias] : escape(linkTo.alias);
  105. linkPath += publish.conf.ext;// + (this.classLink? "":"#" + Link.hashPrefix + "constructor");
  106. }
  107. linkPath = linkBase + linkPath
  108. }
  109. var linkText = this.text || alias;
  110. var link = {linkPath: linkPath, linkText: linkText, linkInner: (this.innerName? "#"+this.innerName : "")};
  111. if (typeof JSDOC.PluginManager != "undefined") {
  112. JSDOC.PluginManager.run("onSymbolLink", link);
  113. }
  114. return "<a href=\""+link.linkPath+link.linkInner+"\""+target+">"+link.linkText+"</a>";
  115. }
  116. /** Create a link to a source file. */
  117. Link.prototype._makeSrcLink = function(srcFilePath) {
  118. var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
  119. // transform filepath into a filename
  120. var srcFile = srcFilePath.replace(/\.\.?[\\\/]/g, "").replace(/[:\\\/]/g, "_");
  121. var outFilePath = Link.base + publish.conf.srcDir + srcFile + publish.conf.ext;
  122. if (!this.text) this.text = FilePath.fileName(srcFilePath);
  123. return "<a href=\""+outFilePath+"\""+target+">"+this.text+"</a>";
  124. }
  125. /** Create a link to a source file. */
  126. Link.prototype._makeFileLink = function(filePath) {
  127. var target = (this.targetName)? " target=\""+this.targetName+"\"" : "";
  128. var outFilePath = Link.base + filePath;
  129. if (!this.text) this.text = filePath;
  130. return "<a href=\""+outFilePath+"\""+target+">"+this.text+"</a>";
  131. }