Template:domxref

  • Revision slug: Template:domxref
  • Revision title: Template:domxref
  • Revision id: 56143
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment 1 words added, 1 words removed

Revision Content

<% /* Used for generating cross-references within the DOM documentation. */ /* This will first try to link to DOM/$0, then DOM:$0 if that doesn't exist */ /* if you specify the API name with parens (ie, "foo()"), the link is to */ /* lang/DOM/foo but the title is displayed as "foo()" to make it clear it's */ /* a function */ /* @param */ /* The path of the page to link to, relative to the DOM documentation path. */ /* @param [optional] */ /* The text to use for the link. If omitted, the value of the first */ /* parameter will be used */ /* @param [optional] */ /* An anchor to link to on the page. Link text will display as $0.$2 or $1.$2 */ /* get a page's language (Don't use page.language!) */ var u = Uri.Parts(Page.uri); var lang = string.toLower(u.path[0]); if(string.Contains(lang, "project")) { lang = string.Substr(lang, 8); } /* fall back to page.language on a user page */ else if (string.StartsWith(lang, "user:")) { lang = page.language; } var api = $0; var str = $0; if ($1 && string.IsLetter($1)) {   str = $1; } if (string.endswith($0, '()')) { api = string.remove(api, string.length(api) - 2); } var destOldType = lang + '/' + 'Document_Object_Model_(DOM)/' + api; /* Warning temporary change */ var destNewType = lang + '/' + 'DOM/' + api; var destEng = 'en' + '/' + 'DOM/' + api; var anch = ''; if ($2) {   str = str + '.' + $2; anch = '#' + $2; } if(wiki.pageExists(destNewType)) { /* the page exists from the dekiwiki age */ (web.link(wiki.uri(destNewType) + anch,str)); } else if (wiki.pageExists(destOldType)) { /* the page exists from the mediawiki age */ (web.link(wiki.uri(destOldType) + anch,str)); } else if (lang == 'zh_tw' && wiki.pageExists(destEng)){  /* the MozTW community consider links to English pages better than red ones. I'll write about this to mozilla.dev.mdc later */ (web.link(wiki.uri(destEng) + anch,str)); } else { /* the page doesn't exist */   var targeturi = "https://developer.mozilla.org/Article_not_found?uri=" + destNewType; <a rel=('internal') href=(targeturi) class=('new')>(str)a>; }

Revision Source

<%

/* Used for generating cross-references within the DOM documentation. */
/* This will first try to link to DOM/$0, then DOM:$0 if that doesn't exist */
/* if you specify the API name with parens (ie, "foo()"), the link is to */
/* lang/DOM/foo but the title is displayed as "foo()" to make it clear it's */
/* a function */
/* @param */
/*   The path of the page to link to, relative to the DOM documentation path. */
/* @param [optional] */
/*   The text to use for the link.  If omitted, the value of the first */
/*   parameter will be used */
/* @param [optional] */
/*   An anchor to link to on the page. Link text will display as $0.$2 or $1.$2 */

/* get a page's language (Don't use page.language!) */
var u = Uri.Parts(Page.uri);
var lang = string.toLower(u.path[0]);
if(string.Contains(lang, "project")) {
  lang = string.Substr(lang, 8);
}
/* fall back to page.language on a user page */
else if (string.StartsWith(lang, "user:")) {
  lang = page.language;
}

var api = $0;
var str = $0;

if ($1 && string.IsLetter($1)) {
  str = $1;
}

if (string.endswith($0, '()')) {
  api = string.remove(api, string.length(api) - 2);
}

var destOldType = lang + '/' + 'Document_Object_Model_(DOM)/' + api; /* Warning temporary change */
var destNewType = lang + '/' + 'DOM/' + api;
var destEng = 'en' + '/' + 'DOM/' + api;
var anch = '';

if ($2) {
  str = str + '.' + $2;
  anch = '#' + $2;
}
if(wiki.pageExists(destNewType)) { /* the page exists from the dekiwiki age */
  <code>(web.link(wiki.uri(destNewType) + anch,str))</code>;
} else if (wiki.pageExists(destOldType)) { /* the page exists from the mediawiki age */
  <code style="text-decoration:overline">(web.link(wiki.uri(destOldType) + anch,str))</code>;
} else if (lang == 'zh_tw' && wiki.pageExists(destEng)){  
  /* the MozTW community consider links to English pages better than red ones. 
     I'll write about this to mozilla.dev.mdc later */ 
  <code>(web.link(wiki.uri(destEng) + anch,str))</code>;
} else { /* the page doesn't exist */
  var targeturi = "https://developer.mozilla.org/Article_not_found?uri=" + destNewType;
  <code><<span class="start-tag">a</span><span class="attribute-name"> rel</span>=(<span class="attribute-value">'internal') </span><span class="attribute-name">href</span><span>=</span>(targeturi<span>) </span><span class="attribute-name">class</span>=<span class="attribute-value">('new')></span>(str)</<span class="end-tag">a></span></code>;
}
</pre>
Revert to this revision