Template:domxref

  • Revision slug: Template:domxref
  • Revision title: Template:domxref
  • Revision id: 56126
  • Created:
  • Creator: trevorh
  • Is current revision? No
  • Comment Change comment to reflect actual order new/old; 2 words added, 2 words removed

Revision Content

/* accepts as input one required parameter: DOM API to create a xref to */
/* this will first try to link to DOM/parm1, then DOM:parm1 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 */

/* get a page's language (Don't use page.language!) */
var u = Uri.Parts(Page.uri);
var lang = u.path[0];
if(string.Contains(lang, "project") || string.Contains(lang, "Project")) {
 lang = string.Substr(lang, 8);
}
var api = $0;

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

var destOldType = lang + '/' + 'DOM:' + api;
var destNewType = lang + '/' + 'DOM/' + api;

if(wiki.pageExists(destNewType)) { /* the page exists from the dekiwiki age */
    (web.link(wiki.uri(destNewType),$0));
} else 
if (wiki.pageExists(destOldType)) { /* the page exists from the mediawiki age */
    (web.link(wiki.uri(destOldType),$0));
} else { /* the page doesn't exist */
    <a rel=('internal') href=(wiki.uri(destNewType)) class=('new')>$0a>;
}

%>

Revision Source

<pre class="script">
/* accepts as input one required parameter: DOM API to create a xref to */
/* this will first try to link to DOM/parm1, then DOM:parm1 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 */

/* get a page's language (Don't use page.language!) */
var u = Uri.Parts(Page.uri);
var lang = u.path[0];
if(string.Contains(lang, "project") || string.Contains(lang, "Project")) {
 lang = string.Substr(lang, 8);
}
var api = $0;

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

var destOldType = lang + '/' + 'DOM:' + api;
var destNewType = lang + '/' + 'DOM/' + api;

if(wiki.pageExists(destNewType)) { /* the page exists from the dekiwiki age */
    <code>(web.link(wiki.uri(destNewType),$0))</code>;
} else 
if (wiki.pageExists(destOldType)) { /* the page exists from the mediawiki age */
    <code>(web.link(wiki.uri(destOldType),$0))</code>;
} else { /* the page doesn't exist */
    <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>(<span>wiki.uri(</span>destNewType<span>)) </span><span class="attribute-name">class</span>=<span class="attribute-value">('new')></span>$0</<span class="end-tag">a></span></code>;
}

%>
Revert to this revision