-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasq-code.html
142 lines (117 loc) · 3.64 KB
/
asq-code.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../asq-base/asq-base.html">
<link rel="import" href="elements/asq-code-presenter/asq-code-presenter.html">
<link rel="import" href="elements/asq-code-viewer/asq-code-viewer.html">
<!--
`asq-code` is a question type where students can answer programming question proposed by professors. It is built above the `ace` editor.
##### Example
<asq-code mode="java" tabsize="2">
<asq-stem><h4>Implement a for loop in Java</h4></asq-stem>
<code>public class C {
public void m() {
int i = i + 5 + ((int)5.0) + ((int)5f);
}
}
</code>
</asq-code>
@element asq-code
@group ASQ Elements
@blurb Element that used for programming questions.
@homepage http://github.com/ASQ-USI/asq-code
-->
<polymer-element name="asq-code" attributes="fontSize tabSize disabled value theme mode wrap" vertical layout>
<template>
<style>
:host{
min-width:100px;
min-height: 200px;
}
</style>
<!-- Viewer -->
<template if="{{role == roles.VIEWER}}">
<asq-code-viewer mode="{{mode}}" theme="{{theme}}" fontSize="{{fontSize}}" tabSize="{{tabSize}}" disabled="{{disabled}}" value="{{value}}" wrap?="{{wrap}}" >
<content></content>
</asq-code-viewer>
</template>
<!-- Presenter -->
<template if="{{role == roles.PRESENTER}}">
<asq-code-presenter mode="{{mode}}" theme="{{theme}}" fontSize="{{fontSize}}" tabSize="{{tabSize}}" disabled="{{disabled}}" value="{{value}}" wrap?="{{wrap}}">
<content></content>
</asq-code-presenter>
</template>
</template>
<script>
(function () {
var p = {
publish: {
/**
* Set to true to style the element as disabled.
* Bind to `readonly` of ace-editor.
*
* @attribute disabled
* @type boolean
* @default false
*/
disabled: {value: false, reflect: true},
/**
* Set the content of the editor.
*
* @attribute value
* @type object
* @default null
*/
value: null,
/**
* Set or get the theme of ace-editor.
*
* @attribute theme
* @type string
* @default 'monokai'
*/
theme: 'monokai',
/**
* Set or get the mode of ace-editor.
*
* @attribute mode
* @type string
* @default 'javascript'
*/
mode: 'javascript',
wrap: false,
},
domReady: function(){
if ( !this.value ) {
var code = this.querySelector('code');
if ( code ) {
this.value = code.textContent;
}
}
},
/**
* The `submit` method returns an object that respresents the submission of this question. The object has the following structure:
{
questionUid: this.uid,
timestamp: new Date(),
submission: []
}
* Only enabled when the `role` of the element is <b>viewer</b>.
*
* @method submit
*/
submit: function() {
if ( this.role !== this.roles.VIEWER ) {
return;
}
var submission = this.$.editor.editor.session.getValue();
return {
questionUid: this.uid,
timestamp: new Date(),
submission: submission
};
},
};
ASQ.asqify(p, true);
Polymer('asq-code', p);
})();
</script>
</polymer-element>