-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplayHelper.js
119 lines (112 loc) · 3.84 KB
/
displayHelper.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
// Light version of the displayHelper from buttonsAndMessages
window.displayHelper = {
popupMessageShown: false,
avatarType: "beaver",
strings: null,
languageStrings: {
fr: {
alright: "D'accord",
validate: "Valider",
},
en: {
alright: "Alright",
validate: "Validate",
},
de: {
alright: "OK",
validate: "Überprüfen",
},
ar: {
alright: "حسناً",
validate: "تحقق",
},
es: {
alright: "De acuerdo",
validate: "Validar",
}
},
initLanguage: function() {
if (window.stringsLanguage == undefined) {
window.stringsLanguage = 'fr';
}
this.strings = this.languageStrings[window.stringsLanguage];
},
getAvatar: function(mood) {
if (displayHelper.avatarType == "beaver") {
return "castor.png";
} else {
if (mood == "success") {
return "laptop_success.png";
} else if (mood == "warning") {
return "laptop_warning.png";
}{
return "laptop_error.png";
}
}
},
showPopupMessage: function(message, mode, yesButtonText, agreeFunc, noButtonText, avatarMood, defaultText) {
if(!this.strings) {
this.initLanguage();
}
if ($('#popupMessage').length == 0) {
$('#sourcesEditor > #fioi-editor2').append('<div id="popupMessage"></div>');
}
if (mode == 'blanket' || mode == 'input') {
$('#popupMessage').addClass('floatingMessage');
} else {
$('#taskContent, #displayHelperAnswering').hide();
$('#popupMessage').removeClass('floatingMessage');
}
var imgPath = '/bower_components/bebras-modules/img/';
if(mode == 'lock') {
var buttonYes = '';
} else if (mode == 'input') {
var buttonYes = '<button class="buttonYes">' + (yesButtonText || this.strings.validate) + '</button>';
} else {
var buttonYes = '<button class="buttonYes">' + (yesButtonText || this.strings.alright) + '</button>';
}
var buttonNo = '';
if (noButtonText != undefined) {
buttonNo = '<button class="buttonNo" style="margin-left: 10px;">' + noButtonText + '</button>';
}
var popupHtml = '<div class="container">' +
'<img class="beaver" src="' + imgPath + this.getAvatar(avatarMood) + '"/>' +
'<img class="messageArrow" src="' + imgPath + 'fleche-bulle.png"/>' +
'<div class="message">' + message + '</div>';
if(mode == 'input') {
popupHtml += '<input id="popupInput" type="text" value="' + (defaultText ? defaultText : '') + '"></input>';
}
popupHtml += buttonYes + buttonNo + '</div>';
// We use .css('display') to not trigger the event in fioi-editor2, which triggers a Blockly reload
$('#popupMessage').html(popupHtml).css('display', 'block');
if(mode == 'input') {
$('#popupInput').focus();
}
var validateFunc = function() {
$('#popupMessage').css('display', 'none');
$('#displayHelperAnswering, #taskContent').show();
displayHelper.popupMessageShown = false;
if (agreeFunc) {
if(mode == 'input') {
agreeFunc($('#popupInput').val());
} else {
agreeFunc();
}
}
}
$('#popupMessage .buttonYes').click(validateFunc);
$('#popupInput').keypress(function (e) {
if(e.which === 13) { validateFunc(); }
});
$('#popupMessage .buttonNo').click(function() {
$('#popupMessage').css('display', 'none');
$('#displayHelperAnswering, #taskContent').show();
displayHelper.popupMessageShown = false;
});
this.popupMessageShown = true;
try {
$(parent.document).scrollTop(0);
} catch (e) {
}
},
};