1 /** Handle the creation of HTML links to documented symbols.
10 this.classLink
= false;
13 this.target
= function(targetName
) {
14 if (defined(targetName
)) this.targetName
= targetName
;
17 this.inner
= function(inner
) {
18 if (defined(inner
)) this.innerName
= inner
;
21 this.withText
= function(text
) {
22 if (defined(text
)) this.text
= text
;
25 this.toSrc
= function(filename
) {
26 if (defined(filename
)) this.src
= filename
;
29 this.toSymbol
= function(alias
) {
30 if (defined(alias
)) this.alias
= new String(alias
);
33 this.toClass
= function(alias
) {
34 this.classLink
= true;
35 return this.toSymbol(alias
);
37 this.toFile
= function(file
) {
38 if (defined(file
)) this.file
= file
;
42 this.toString
= function() {
47 linkString
= this.alias
.replace(/(^|[^a-z$0-9_#.:^-])([|a-z$0-9_#.:^-]+)($|[^a-z$0-9_#.:^-])/i,
48 function(match
, prematch
, symbolName
, postmatch
) {
49 var symbolNames
= symbolName
.split("|");
51 for (var i
= 0, l
= symbolNames
.length
; i
< l
; i
++) {
52 thisLink
.alias
= symbolNames
[i
];
53 links
.push(thisLink
._makeSymbolLink(symbolNames
[i
]));
55 return prematch
+links
.join("|")+postmatch
;
60 linkString
= thisLink
._makeSrcLink(this.src
);
63 linkString
= thisLink
._makeFileLink(this.file
);
70 /** prefixed for hashes */
73 /** Appended to the front of relative link paths. */
76 Link
.symbolNameToLinkName
= function(symbol
) {
80 if (symbol
.isStatic
) linker
= ".";
81 else if (symbol
.isInner
) linker
= "-";
83 if (symbol
.isEvent
&& !/^event:/.test(symbol
.name
)) {
86 return Link
.hashPrefix
+linker
+ns
+symbol
.name
;
89 Link
.getSymbol
= function(alias
) {
90 var symbol
= Link
.symbolSet
.getSymbol(alias
);
95 if ('#'!==alias
.charAt(0) || !Link
.currentSymbol
)
98 // resolve relative name
99 var container
= Link
.currentSymbol
;
103 symbol
= Link
.symbolSet
.getSymbol(container
.alias
+ alias
);
108 if (!container
.augments
.length
)
111 container
= Link
.symbolSet
.getSymbol(container
.augments
[0].desc
);
117 /** Create a link to another symbol. */
118 Link
.prototype._makeSymbolLink
= function(alias
) {
119 var linkBase
= Link
.base
+publish
.conf
.symbolsDir
;
120 var linkTo
= Link
.getSymbol(alias
);
122 var target
= (this.targetName
)? " target=\""+this.targetName
+"\"" : "";
124 // if there is no symbol by that name just return the name unaltered
126 return this.text
|| alias
;
128 // it's a symbol in another file
130 if (!linkTo
.is("CONSTRUCTOR") && !linkTo
.isNamespace
) { // it's a method or property
131 linkPath
= (Link
.filemap
) ? Link
.filemap
[linkTo
.memberOf
] :
132 escape(linkTo
.memberOf
) || "_global_";
133 linkPath
+= publish
.conf
.ext
+ "#" + Link
.symbolNameToLinkName(linkTo
);
136 linkPath
= (Link
.filemap
)? Link
.filemap
[linkTo
.alias
] : escape(linkTo
.alias
);
137 linkPath
+= publish
.conf
.ext
;// + (this.classLink? "":"#" + Link.hashPrefix + "constructor");
139 linkPath
= linkBase
+ linkPath
142 var linkText
= this.text
|| alias
;
144 var link
= {linkPath
: linkPath
, linkText
: linkText
, linkInner
: (this.innerName
? "#"+this.innerName
: "")};
146 if (typeof JSDOC
.PluginManager
!= "undefined") {
147 JSDOC
.PluginManager
.run("onSymbolLink", link
);
150 return "<a href=\""+link
.linkPath
+link
.linkInner
+"\""+target
+">"+link
.linkText
+"</a>";
153 /** Create a link to a source file. */
154 Link
.prototype._makeSrcLink
= function(srcFilePath
) {
155 var target
= (this.targetName
)? " target=\""+this.targetName
+"\"" : "";
157 // transform filepath into a filename
158 var srcFile
= srcFilePath
.replace(/\.\.?[\\\/]/g, "").replace(/[:\\\/]/g, "_");
159 var outFilePath
= Link
.base
+ publish
.conf
.srcDir
+ srcFile
+ publish
.conf
.ext
;
161 if (!this.text
) this.text
= FilePath
.fileName(srcFilePath
);
162 return "<a href=\""+outFilePath
+"\""+target
+">"+this.text
+"</a>";
165 /** Create a link to a source file. */
166 Link
.prototype._makeFileLink
= function(filePath
) {
167 var target
= (this.targetName
)? " target=\""+this.targetName
+"\"" : "";
169 var outFilePath
= Link
.base
+ filePath
;
171 if (!this.text
) this.text
= filePath
;
172 return "<a href=\""+outFilePath
+"\""+target
+">"+this.text
+"</a>";