/
view_tutorial_only.js
233 lines (198 loc) · 8.24 KB
/
view_tutorial_only.js
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
var api = null;
$(document).ready(function() {
// This function is from http://awardwinningfjords.com/2010/09/22/handling-touch-events-in-jquery-tools-scrollable.html
$.fn.handleSwipes = function() {
return this.each(function() {
var api = $(this).data("scrollable");
api.getRoot().addSwipeEvents()
.bind('swipeleft', function() {
api.next();
})
.bind('swiperight', function() {
api.prev();
});
});
};
$('#progress').progressbar();
var size_scrollable = function() {
$('#scrollable').height($('body').height() - $('#progress').outerHeight(true) - $('#tab-1').height());
$('#scrollable-quiz').height($('body').height() - $('#progress').outerHeight(true) - $('#tab-1').height());
};
size_scrollable();
$('body').resize(size_scrollable);
// all this depends on jQuery Tools...
$("#scrollable").scrollable({
items : '.items',
touch : false
}).handleSwipes();
api = $("#scrollable").data("scrollable");
$('#scrollable .items').height($('#scrollable .items .step:nth-child(1)').height());
$('#prev-navigation').hide();
api.onSeek(function() {
if ($('#scrollable:visible').length != 0) {
$('#scrollable').scrollTop(0);
$('#scrollable .items').height($('#scrollable .items .step:nth-child(' + (this.getIndex() + 1) + ')').height());
var new_value = 100 * (this.getIndex() / (this.getSize() - 2));
$('#progress').progressbar("option", "value", new_value);
if (this.getIndex() == 0) {
$('#tabs').children(':not(:first)').css('background-color', 'gray').css('color', 'white');
$('#tabs :first').css('background-color', 'white').css('color', 'black');
} else {
$('#tabs').children(':not(:eq(1))').css('background-color', 'gray').css('color', 'white');
$('#tabs :eq(1)').css('background-color', 'white').css('color', 'black');
}
}
var current_step = this.getIndex();
$('#table-of-contents li', parent.window.document).each(function() {
var id = $(this).children('a').attr('id').split('-')[1];
if (current_step - 1 >= id) { // the -1 is to deal with the introduction in a separate step at the beginning.
// We may want to get rid of that extra step.
$(this).siblings().removeClass('current-chapter');
$(this).addClass('current-chapter');
}
});
});
if (top.cakephp.popup) {
$('a[target=site-frame]').click(function(e) {
e.preventDefault();
top.window.opener.location = e.target.href;
});
}
$('#email_and_print').submit(function() {
var postData = $(this).serialize();
$.post(cakephp.webroot + 'tutorials/view_certificate/', postData, function(returnData) {
var dialog = '<div id="email-print" style="display: none" title="' + cakephp.i18n.results + '">' + returnData + '</div>'
parent.$('body').append(dialog);
parent.$('#email-print').dialog({
modal : true,
autoOpen : false,
draggable : false,
buttons : [
{
text : cakephp.i18n.print,
click : function() {
parent.window.print();
}
},
{
text : cakephp.i18n.close,
click : function() {
var this_element = parent.$('#email-print');
this_element.dialog("close");
this_element.dialog("destroy");
this_element.remove();
parent.$('body').removeClass('print-certificate');
}
}
],
width: (parent.cakephp.popup) ? $(window).width() : 700,
height : (parent.cakephp.popup) ? $(window).height() : 'auto',
left: (parent.cakephp.popup) ? '0px' : 'auto',
top: (parent.cakephp.popup) ? '0px' : 'auto',
beforeClose : function() {
parent.$('email-print').text();
}
});
parent.$('body').addClass('print-certificate');
parent.$('#email-print').dialog('open');
parent.$('#email-print').closest('.ui-dialog').height('90%');
parent.$('#email-print-wrapper').height(parent.$('#email-print').closest('.ui-dialog').height() - 200);
parent.$('#email-print-wrapper').css('overflow-y', 'scroll');
});
return false;
});
$('.certificate_name').focus(function() {
if ($(this).val() == 'Your name') {
$(this).val('');
}
});
$('.certificate_name').blur(function() {
if ($(this).val() == '') {
$(this).val('Your name');
}
});
$('a[target=site-frame]').click(function() {
$('#site-frame', parent.window.document).attr('src', $(this).attr('href'));
return false;
});
$('.definition-body').hide();
var generate_definition_boxes = function () {
var this_id = $(this).attr('id');
var uuid = this_id.replace('definition-link-', '');
var body_div = "<aside id='definition-body-" + uuid + "' class='definition-body' style='display: none;'>";
var definition_text = $(this).data('content');
body_div += definition_text.QH_decodeURIComponent();
body_div += "</aside>";
$(this).after($(body_div));
};
$('.definition-link').each(generate_definition_boxes);
$('.definition-link').click(function() {
var this_id = $(this).attr('id');
var uuid = this_id.replace('definition-link-', '');
$('#definition-body-' + uuid).toggle();
$('#scrollable .items').height($(this).parents('.step:visible').height());
});
parent.$('#feedback-frame').dialog({
autoOpen : false,
modal : true,
height : 450,
title : $('#provide-feedback').text(),
buttons : {
'Send feedback' : function() {
var this_element = parent.$('#feedback-frame');
var form = this_element.contents().find("#TutorialProvideFeedbackForm");
var postData = form.serialize();
var action = form.attr('action');
$.post(action, postData, function(data) {
if (data == 'success') {
alert(cakephp.i18n.feedback_sent);
this_element.dialog("close");
} else {
this_element.contents().find('form').append(
'<div class="message">' + cakephp.i18n.feedback_not_sent + '</div>'
);
}
});
}
}
});
$('#provide-feedback').click(function() {
parent.$('#feedback-frame').dialog("open");
return false;
});
var response_dialog = "<div id='response-dialog'></div>";
parent.$('body').append(response_dialog);
parent.$('#response-dialog').dialog({
autoOpen : false,
modal : true,
draggable : false,
close: function (event, ui) {
$('#' + parent.$('#response-dialog').data('radio-return')).focus();
}
});
parent.$('#response-dialog').parents('.ui-widget').click(function () {
parent.$('#response-dialog').dialog("close");
});
// Quiz questions don't have pop-ups. Is this being checked at the backend? That could be problematic if
// you copy and paste from a tutorial into a quiz.
$('#scrollable :not(.no-feedback) > .answers').append("<button type='button'>" + cakephp.i18n.check_answer + "</button>");
// Since we've inserted HTML, adjust the height
$('#scrollable .items').height($('#scrollable .items .step:nth-child(1)').height());
$('#scrollable :not(.no-feedback) > .answers > button').click(function(e) {
var getData = $(this).parents('.answers').children('input').serialize();
$.post(cakephp.webroot + 'questions/get_immediate_feedback/' + cakephp.tutorial_id, getData, function(data) {
parent.$('#response-dialog').html(data.response);
if (data.correct) {
parent.$('#response-dialog').dialog({'dialogClass': 'correct', 'title': data.response_heading});
} else {
parent.$('#response-dialog').dialog({'dialogClass': 'incorrect', 'title': data.response_heading});
}
parent.$('#response-dialog').dialog("open");
parent.$('#response-dialog').data('radio-return', $(e.target).attr('id').replace(/(\[|\])/g, '\\$1'));
}, 'json');
});
$('a.prev').tooltip( { position: { my: 'center bottom', at: 'center top-15' } } );
$('a.next').tooltip( { position: { my: 'center bottom', at: 'center top-15' } } );
// Use jquery_ui buttons even when buttons aren't part of a dialog
$( "input:submit" ).button();
});