22
22
* Defines some generic JavaScript utility functions.
25
/* Expects the following variables to have been declared by JavaScript in
26
* the HTML generated by the server:
25
31
/** Removes all children of a given DOM element
26
32
* \param elem A DOM Element. Will be modified.
34
40
/** Creates a DOM element with simple text inside it.
35
41
* \param tagname String. Name of the element's tag (eg. "p").
36
42
* \param text String. Text to be placed inside the element.
43
* \param title String, optional. Tooltip for the text.
44
* (Note, title creates a span element around the text).
37
45
* \return DOM Element object.
39
function dom_make_text_elem(tagname, text)
47
function dom_make_text_elem(tagname, text, title)
41
49
if (text == null) text = "";
42
50
var elem = document.createElement(tagname);
43
elem.appendChild(document.createTextNode(text));
53
textnode = document.createTextNode(text);
56
textnode = document.createElement("span");
57
textnode.setAttribute("title", title);
58
textnode.appendChild(document.createTextNode(text));
60
elem.appendChild(textnode);
47
64
/** Creates a DOM element with hyperlinked text inside it.
48
65
* \param tagname String. Name of the element's tag (eg. "p").
49
66
* \param text String. Text to be placed inside the element.
67
* \param title String, optional. Sets a tooltip for the link.
50
68
* \param href String. URL the text will link to. This is a raw string,
51
69
* it will automatically be URL-encoded.
52
70
* \param onclick Optional string. Will be set as the "onclick" attribute
53
71
* of the "a" element.
54
72
* \return DOM Element object.
56
function dom_make_link_elem(tagname, text, href, onclick)
74
function dom_make_link_elem(tagname, text, title, href, onclick)
58
76
if (text == null) text = "";
59
77
if (href == null) href = "";
60
78
var elem = document.createElement(tagname);
61
79
var link = document.createElement("a");
62
80
link.setAttribute("href", encodeURI(href));
82
link.setAttribute("title", title);
63
83
if (onclick != null)
64
84
link.setAttribute("onclick", onclick);
65
85
link.appendChild(document.createTextNode(text));