Blame view

semantics/static/js/semantics_roles.js 4.09 KB
Bartłomiej Nitoń authored
1
var roles_display_table = ""; // roles table in html form
Tomasz Bartosiak authored
2
var roles_display_table_full = ""; // with lemma role
Bartłomiej Nitoń authored
3
4
5
var role_name = [];           // displayed names of roles
var role_color = [];          // colors assigned to roles
Tomasz Bartosiak authored
6
7
8
function rolesToHtml(roles_display, full){
    var i, j, k, table;
    table = '<table border="1" style="font-size: 11px">';
Bartłomiej Nitoń authored
9
    for (i = 0; i < roles_display.length; i++) {
Tomasz Bartosiak authored
10
        table += '<tr>';
Bartłomiej Nitoń authored
11
        for (j = 0; j < roles_display[i].length; j++) {
Tomasz Bartosiak authored
12
13
14
15
16
            table += '<td rowspan="';
            table += roles_display[i][j].rowspan;
            table += '" colspan="';
            table += roles_display[i][j].colspan;
            table += '">';
Bartłomiej Nitoń authored
17
            if (roles_display[i][j].caption != "None") {
Tomasz Bartosiak authored
18
19
20
                table += "<b>"
                table += roles_display[i][j].caption;
                table += "</b>"
Bartłomiej Nitoń authored
21
22
            }
            for (k = 0; k < roles_display[i][j].roles.length; k++) {
Tomasz Bartosiak authored
23
                table += '<div style=';
Bartłomiej Nitoń authored
24
                if (roles_display[i][j].roles[k].color != 'None') {
Tomasz Bartosiak authored
25
26
27
28
29
                    if (roles_display[i][j].roles[k].color == '256,256,256') {
                        table += '"background-color: rgb(256,256,256); font-weight:bold; margin: auto; width: 25%"';
                    } else {
                        table += '"background-color: rgb(' + roles_display[i][j].roles[k].color + ')';
                    }
Bartłomiej Nitoń authored
30
                } else {
Tomasz Bartosiak authored
31
                    table += '"background: linear-gradient(to ' + roles_display[i][j].roles[k].gradient + ',  rgba(100,100,100,0.1), rgba(100,100,100,1))';
Bartłomiej Nitoń authored
32
                }
Tomasz Bartosiak authored
33
34
35
36
37
38
39
40
41
                table += '"><input type="checkbox" name="roles" value="';
                table += roles_display[i][j].roles[k].id;
                table +=  '"><label>';
                table += roles_display[i][j].roles[k].rolename;
                table +=  '</label></div>';
		if (full) {
                    role_name[roles_display[i][j].roles[k].id] = roles_display[i][j].roles[k].rolename;
                    role_color[roles_display[i][j].roles[k].id] = {"color": roles_display[i][j].roles[k].color, "gradient": roles_display[i][j].roles[k].gradient};
		}
Bartłomiej Nitoń authored
42
            }
Tomasz Bartosiak authored
43
            table += '</td>';
Bartłomiej Nitoń authored
44
        }
Tomasz Bartosiak authored
45
        table += '</tr>';
Bartłomiej Nitoń authored
46
    }
Tomasz Bartosiak authored
47
48
49
50
51
    table += '</table>';

    return table;
}
Tomasz Bartosiak authored
52
53
54
55
56
57
58
function isLemma(roles) {
    if (roles.length != 1) {
        return false;
    }
    return (role_name[roles[0]] == 'Lemma');
}
Tomasz Bartosiak authored
59
60
61
function memorizeRoles(roles_display, roles_full){
    roles_display_table = rolesToHtml(roles_display, false);
    roles_display_table_full = rolesToHtml(roles_full, true);
Bartłomiej Nitoń authored
62
63
64
65
66
}

function getStyle(frame_id, complement_num) {
    style_type = "";
    style_color = "";
Tomasz Bartosiak authored
67
Bartłomiej Nitoń authored
68
    style_value = "";
Tomasz Bartosiak authored
69
    var roles = frame_content[parseInt(frame_id)].display.roles[complement_num].argument;
Bartłomiej Nitoń authored
70
71
72
73
    var i;
    for (i = 0; i < roles.length; i++) {
        var color = role_color[roles[i]];
        if (color.gradient != "None") {
Bartłomiej Nitoń authored
74
75
76
77
78
79
80
        	// Safari browser only
        	if(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) {
        		style_type = "-webkit-linear-gradient(" + color.gradient + ", ";
        	}
        	else {
        		style_type = "linear-gradient(to " + color.gradient + ", ";
        	}  
Bartłomiej Nitoń authored
81
82
83
84
85
86
87
88
        } else {
            style_color = color.color
        }
    }
    if (style_type == "") {
        style_type = "background-color";
        style_value = "rgb(" + style_color + ")";
    } else {
Bartłomiej Nitoń authored
89
90
91
92
93
94
95
    	// Safari browser only
    	if(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) {
    		style_value = style_type + "rgba(" + style_color + ",1), rgba(" + style_color + ",0.1))";
    	}
    	else {
    		style_value = style_type + "rgba(" + style_color + ",0.1), rgba(" + style_color + ",1))";
    	}
Bartłomiej Nitoń authored
96
97
98
99
        style_type = "background";
    }
    return {"type": style_type, "value": style_value};
}
Tomasz Bartosiak authored
100
101
102
103
104
105
106
107
108
109
110
111

function isPOL(frame_id, complement_num) {
    var roles = frame_content[parseInt(frame_id)].display.roles[complement_num].argument;
    if (roles.length != 1) {
	return false;
    }
    if (role_name[roles[0]] == 'Lemma') {
	return true;
    } else {
	return false;
    }
}