upgrade
This commit is contained in:
105
plugin/exercisefocused/templates/block.html.twig
Normal file
105
plugin/exercisefocused/templates/block.html.twig
Normal file
@@ -0,0 +1,105 @@
|
||||
{% if exercisefocused.show_region %}
|
||||
{% set enable_time_limit = 'true' == exercisefocused.plugin_info.obj.get('enable_time_limit') %}
|
||||
{% set time_limit = exercisefocused.plugin_info.obj.get('time_limit') %}
|
||||
{% set enable_outfocused_limit = 'true' == exercisefocused.plugin_info.obj.get('enable_outfocused_limit') %}
|
||||
{% set outfocused_limit = exercisefocused.plugin_info.obj.get('outfocused_limit') %}
|
||||
|
||||
<div id="exercisefocused-block" style="display: none;">
|
||||
<div class="exercisefocused-block__container">
|
||||
<div class="exercisefocused-block__message card">
|
||||
<p class="h3 text-danger">{{ 'YouHaveLeftTheExercise'|get_plugin_lang('ExerciseFocusedPlugin') }}</p>
|
||||
|
||||
{% if enable_time_limit %}
|
||||
<div id="time-limit-block">
|
||||
<p class="h4">
|
||||
{{ 'YouHaveXTimeToReturn'|get_plugin_lang('ExerciseFocusedPlugin')|format(time_limit) }}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if enable_outfocused_limit %}
|
||||
<div id="outfocused-limit-block">
|
||||
<p class="h4">{{ 'YouAreAllowedXOutfocused'|get_plugin_lang('ExerciseFocusedPlugin')|format(outfocused_limit) }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<style>
|
||||
#exercisefocused-block {
|
||||
background-color: #CCCC;
|
||||
border: 1px solid #DDD;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
min-height: 100%;
|
||||
min-width: 100%;
|
||||
position: fixed;
|
||||
right: 0;
|
||||
user-select: none;
|
||||
-ms-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
top: 0;
|
||||
z-index: 1010;
|
||||
}
|
||||
.exercisefocused-block__container {
|
||||
left: 50%;
|
||||
position: absolute;
|
||||
text-align: center;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
-webkit-transform: translate(-50%, -50%);
|
||||
}
|
||||
.exercisefocused-block__message {
|
||||
margin-bottom: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
.exercisefocused-block__message p,
|
||||
.exercisefocused-block__message span {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.exercisefocused-backdrop {
|
||||
background-color: rgba(0, 0, 0, 0.02);
|
||||
cursor: not-allowed;
|
||||
height: 100%;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
user-select: none;
|
||||
width: 100%;
|
||||
z-index: 1000;
|
||||
}
|
||||
.exercisefocused-backdrop::before {
|
||||
background-color: #FFF;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 2px rgba(204, 197, 185, 0.5);
|
||||
content: attr(data-alert);
|
||||
display: block;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
margin: 50px auto;
|
||||
opacity: 0;
|
||||
padding: 10px;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
width: 340px;
|
||||
transition: opacity 0s ease-in-out;
|
||||
}
|
||||
.exercisefocused-backdrop:hover::before {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.exercisefocused-backdrop.inmediate::before {
|
||||
transition-delay: 3.5s !important;
|
||||
}
|
||||
.exercisefocused-backdrop.out::before {
|
||||
transition-delay: 0s !important;
|
||||
}
|
||||
|
||||
form#exercise_form {
|
||||
background-color: #FFF;
|
||||
position: relative;
|
||||
z-index: 1005;
|
||||
}
|
||||
</style>
|
||||
{% endif %}
|
||||
163
plugin/exercisefocused/templates/script.html.twig
Normal file
163
plugin/exercisefocused/templates/script.html.twig
Normal file
@@ -0,0 +1,163 @@
|
||||
{% if exercisefocused.show_region %}
|
||||
{% set enable_time_limit = 'true' == exercisefocused.plugin_info.obj.get('enable_time_limit') %}
|
||||
{% set time_limit = exercisefocused.plugin_info.obj.get('time_limit') %}
|
||||
{% set enable_outfocused_limit = 'true' == exercisefocused.plugin_info.obj.get('enable_outfocused_limit') %}
|
||||
{% set outfocused_limit = exercisefocused.plugin_info.obj.get('outfocused_limit') %}
|
||||
|
||||
{% set ALL_ON_ONE_PAGE = exercisefocused.exercise_type == 1 %}
|
||||
{% set ONE_PER_PAGE = exercisefocused.exercise_type == 2 %}
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
var $exerciseFocused = $("#exercisefocused-block").appendTo('body');
|
||||
var $timeLimitBlock = $exerciseFocused.find('#time-limit-block');
|
||||
var $timeLimitTarget = $exerciseFocused.find('#time-limit-target');
|
||||
var $outfocusedLimitBlock = $exerciseFocused.find('#outfocused-limit-block');
|
||||
var $outfocusedLimitTarget = $exerciseFocused.find('#outfocused-limit-target');
|
||||
|
||||
var $backdrop = $('<div>')
|
||||
.addClass('exercisefocused-backdrop text-danger')
|
||||
.attr('data-alert', '{{ 'AlertBeforeLeaving'|get_plugin_lang('ExerciseFocusedPlugin') }}')
|
||||
.hover(
|
||||
function () {$backdrop.removeClass('out').addClass('inmediate'); },
|
||||
function () { $backdrop.addClass('out').removeClass('inmediate'); }
|
||||
);
|
||||
|
||||
var $btnSaveNow = $('button[name="save_now"]');
|
||||
|
||||
$backdrop.appendTo('body');
|
||||
|
||||
var secToken = "{{ exercisefocused.sec_token }}";
|
||||
var initDocumentTitle = document.title;
|
||||
var countdownInterval;
|
||||
var remainingTime;
|
||||
var enableTimeLimit = {{ enable_time_limit ? 'true' : 'false' }};
|
||||
var enableOutfocusedLimit = {{ enable_outfocused_limit ? 'true' : 'false' }};
|
||||
|
||||
{% if enable_outfocused_limit %}
|
||||
var remainingOutfocused = {{ exercisefocused.remaining_outfocused }};
|
||||
{% endif %}
|
||||
|
||||
function finishExam() {
|
||||
$(window).off("blur", onBlur)
|
||||
$(window).off("focus", onFocus)
|
||||
|
||||
{% if ALL_ON_ONE_PAGE %}
|
||||
save_now_all('validate');
|
||||
{% elseif ONE_PER_PAGE %}
|
||||
window.quizTimeEnding = true;
|
||||
$('[name="save_now"]').trigger('click');
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
{% if enable_time_limit %}
|
||||
function updateCountdown() {
|
||||
var seconds = remainingTime;
|
||||
var strSeconds = `${seconds.toString().padStart(2, '0')}`;
|
||||
|
||||
$timeLimitTarget.text(strSeconds);
|
||||
document.title = $timeLimitTarget.parent().text();
|
||||
|
||||
remainingTime--;
|
||||
|
||||
if (remainingTime < 0) {
|
||||
clearInterval(countdownInterval);
|
||||
|
||||
sendAction('time_limit', function () {
|
||||
finishExam()
|
||||
});
|
||||
}
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
function sendAction(action, callback) {
|
||||
{% if ALL_ON_ONE_PAGE %}
|
||||
var levelId = 0;
|
||||
{% elseif ONE_PER_PAGE %}
|
||||
var levelId = $btnSaveNow.data('question') || -1;
|
||||
{% endif %}
|
||||
|
||||
$.ajax({
|
||||
url: "{{ _p.web_plugin }}exercisefocused/pages/log.php",
|
||||
data: {
|
||||
action: action,
|
||||
exercisefocused_sec_token: secToken,
|
||||
level_id: levelId
|
||||
},
|
||||
success: function (response) {
|
||||
if (!response) {
|
||||
return;
|
||||
}
|
||||
|
||||
secToken = response.sec_token;
|
||||
|
||||
if (callback) {
|
||||
callback(response)
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function onBlur() {
|
||||
$exerciseFocused.show();
|
||||
|
||||
if (enableOutfocusedLimit) {
|
||||
if (remainingOutfocused <= 0) {
|
||||
$outfocusedLimitBlock.find('p').text("{{ 'OutfocusedLimitExceeded'|get_plugin_lang('ExerciseFocusedPlugin')|escape('js') }}");
|
||||
$timeLimitBlock.hide();
|
||||
|
||||
sendAction('outfocused_limit', function () {
|
||||
finishExam()
|
||||
});
|
||||
|
||||
return;
|
||||
} else {
|
||||
$outfocusedLimitTarget.text(remainingOutfocused);
|
||||
}
|
||||
|
||||
remainingOutfocused--;
|
||||
}
|
||||
|
||||
sendAction('outfocused');
|
||||
|
||||
{% if enable_time_limit %}
|
||||
remainingTime = {{ time_limit }};
|
||||
|
||||
updateCountdown();
|
||||
|
||||
countdownInterval = window.setInterval(updateCountdown, 1000);
|
||||
{% else %}
|
||||
document.title = "{{ 'WindowTitleOutfocused'|get_plugin_lang('ExerciseFocusedPlugin')|escape('js') }}";
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
function onFocus() {
|
||||
sendAction('return');
|
||||
|
||||
document.title = initDocumentTitle;
|
||||
|
||||
window.setTimeout(
|
||||
function () {
|
||||
$exerciseFocused.hide();
|
||||
},
|
||||
3500
|
||||
);
|
||||
|
||||
{% if enable_time_limit %}
|
||||
clearInterval(countdownInterval);
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
$(window).on("blur", onBlur)
|
||||
$(window).on("focus", onFocus)
|
||||
|
||||
$('body').on('click', 'a, button', function (e) {
|
||||
var $el = $(e.target);
|
||||
|
||||
if (0 === $el.parents('form#exercise_form').length) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
})
|
||||
</script>
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user