-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasq-fiddle-q.html
147 lines (123 loc) · 3.96 KB
/
asq-fiddle-q.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
143
144
145
146
147
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../ace-element/ace-element.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../asq-base/asq-base.html">
<link rel="import" href="elements/asq-fiddle-q-viewer.html">
<link rel="import" href="elements/asq-fiddle-q-presenter.html">
<!--
Give students an image of a simple Web page + the HTML and ask them to write out the CSS to reproduce this image.
To seed the editors with initial values add a template with the attribute `seed`. Inside the template add elements with the tags `html`, `css` and `js` respectively. Their innerHTML will seed the corresponding editors.
### Example:
<asq-fiddle-q selected-panes='["html", "js", "result"]' editor-font-size="1.2em;">
<asq-stem><h4>Paint a circle in the canvas</h4></asq-stem>
<template seed>
<pre html><canvas id="c"></canvas></pre>
<pre css>#c {width: 200px; height: 200px}</pre>
<pre js>//Paint a circle in the canvas
var c = document.getElementById("c");</pre>
</template>
</asq-fiddle-q>
@group DELFT Elements
@element asq-fiddle-q
@demo demo/index.html
-->
<dom-module id="asq-fiddle-q">
<template>
<style>
:host {
@apply(--layout-vertical);
min-height:300px;
}
</style>
<!-- Viewer -->
<template is="dom-if" if="{{hasRole(role, roles.VIEWER)}}" restamp>
<asq-fiddle-q-viewer
role="viewer"
uid="[[uid]]"
event-bus="[[eventBus]]"
value="{{value}}"
selected-panes="{{selectedPanes}}"
editor-font-size="{{editorFontSize}}"
>
<content></content>
</asq-fiddle-q-viewer>
</template>
<!-- Presenter -->
<template is="dom-if" if="{{hasRole(role, roles.PRESENTER)}}" restamp>
<asq-fiddle-q-presenter
role="presenter"
uid="[[uid]]"
event-bus="[[eventBus]]"
value="{{value}}"
selected-panes="{{selectedPanes}}"
editor-font-size="{{editorFontSize}}"
>
<content></content>
</asq-fiddle-q-presenter>
</template>
</template>
</dom-module>
<script>
Polymer({
is: 'asq-fiddle-q',
behaviors: [ASQ.asqQuestionElementBehavior],
properties: {
/**
* The panes to display. When specifying it as an attribute, use an array serialized as string.
* For Example: `selected-panes='["js", "result"]'`. Notice the single quotes for the attributes
* and the double quotes for the array items.
*/
selectedPanes: {
type: Array,
value: function (){ return ['html', 'js', 'css', 'result'];},
reflectToAttribute: true,
notify: true
},
/**
* The font size of the editors.
* Example: `font-size="16em"`
*/
editorFontSize: {
type: String,
value: '12px',
reflectToAttribute: true,
notify: true
},
/**
* Event bus to communicate with ASQ
*/
eventBus: {
type: Object,
notify: true
}
},
created: function () {
document.addEventListener('asq-ready', function (evt) {
this.eventBus = evt.detail.asqEventBus
}.bind(this));
},
/**
* 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) {
var el = this.$$('asq-fiddle-q-viewer');
if (!el) {
throw new Error('submit(): expected asq-fiddle-q-viewer element to exist');
}
return el.submit();
}
},
hasRole: function (role, candidate) {
return role == candidate;
}
});
</script>