summaryrefslogtreecommitdiffstats
path: root/web/dom.js
blob: ee1931f440d8f214240c1855ef0bdb5fca999e9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * Copyright (c) 2012-2014 Kaarle Ritvanen
 * See LICENSE file for license details
 */

define(["aconf/navigation", "jquery", "underscore"], function(navi, $, _) {
    function href() {
	return $("<a>").attr({href: "javascript:void(0);"});
    }

    return {
	setText: function(el, s) {
	    el.html(_.map(s.split("\n"), _.escape).join("<br/>"));
	},

	href: href,

	objectRef: function(value, el) {
	    el = el || href();
	    if (value) {
		el.click(function() { navi.setPath(value); }).text("Show");
	    }
	    return el;
	},

	button: function(label, func) {
	    return $("<input>").attr(
		{type: "submit", value: label}
	    ).click(func);
	},

	makeRow: function(el) {
	    if (el.is("td")) return $("<tr>").html(el);
	    return el;
	},

	setStatus: function(el, status) { el.prop("class", status); }
    };
});