Skip to content

Commit

Permalink
Merge pull request #510 from themeum/dev
Browse files Browse the repository at this point in the history
v2.2.3 merged to master
  • Loading branch information
harunollyo authored Jul 24, 2023
2 parents 7b3f2bc + a8d1846 commit ccbda39
Show file tree
Hide file tree
Showing 27 changed files with 629 additions and 502 deletions.
24 changes: 24 additions & 0 deletions assets/react/admin-dashboard/segments/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,28 @@ document.addEventListener('DOMContentLoaded', function () {
showHideToggleChildren($(this))
})

/**
* Maxlength counter for Textarea and Text field.
* @since 2.2.3
*/
let maxLengthTargets = $('.tutor-option-field-input textarea[maxlength], .tutor-option-field-input input[maxlength]')
maxLengthTargets.each(function () {
let el = $(this),
max = $(this).attr('maxlength'),
len = $(this).val().length,
text = `${len}/${max}`;

el.css('margin-right', 0)
$(this).parent().append(`<div class="tutor-field-maxlength-info tutor-mr-4 tutor-fs-8 tutor-color-muted">${text}</div>`)
});

maxLengthTargets.keyup(function () {
let el = $(this),
max = $(this).attr('maxlength'),
len = $(this).val().length,
text = `${len}/${max}`;

el.parent().find('.tutor-field-maxlength-info').text(text)
})

});
21 changes: 15 additions & 6 deletions assets/react/course-builder/assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@ window.jQuery(document).ready(function($){
success: function (data) {
$('.tutor-assignment-modal-wrap .tutor-modal-container').html(data.data.output);
$('.tutor-assignment-modal-wrap').addClass('tutor-is-active');

let editor_id = 'tutor_assignments_modal_editor',
editor_wrap_selector = '#wp-tutor_assignments_modal_editor-wrap',
tinymceConfig = tinyMCEPreInit.mceInit.tutor_assignment_editor_config;

if ($(editor_wrap_selector).hasClass('html-active')) {
$(editor_wrap_selector).removeClass('html-active');
}

$(editor_wrap_selector).addClass('tmce-active');

/**
* Add codesample plugin to support code snippet
*
* @since v2.0.9
* @since 2.0.9
*/
var tinymceConfig = tinyMCEPreInit.mceInit.tutor_assignment_editor_config;

if (tinymceConfig && _tutorobject.tutor_pro_url) {
if (!tinymceConfig.plugins.includes('codesample')) {
tinymceConfig.plugins = `${tinymceConfig.plugins}, codesample`;
Expand All @@ -44,16 +52,17 @@ window.jQuery(document).ready(function($){
}
}

tinymceConfig.wpautop = false;
tinymce.init(tinymceConfig);
tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor');
tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
tinymce.execCommand('mceRemoveEditor', false, editor_id );
tinyMCE.execCommand('mceAddEditor', false, editor_id );
quicktags({ id: editor_id });

window.dispatchEvent(new Event(_tutorobject.content_change_event));
window.dispatchEvent(new CustomEvent('tutor_modal_shown', {detail: e.target}));
},
complete: function () {
$that.removeClass('is-loading');
quicktags({ id: "tutor_assignments_modal_editor" });
}
});
});
Expand Down
81 changes: 32 additions & 49 deletions assets/react/course-builder/lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,48 +127,44 @@ window.jQuery(document).ready(function($) {
'data-lesson-id': lesson_id,
'data-topic-id': topic_id,
});

$('.tutor-lesson-modal-wrap').addClass('tutor-is-active');
if ($('#wp-tutor_lesson_modal_editor-wrap').hasClass('html-active')) {
$('#wp-tutor_lesson_modal_editor-wrap').removeClass('html-active');
}

$('#wp-tutor_lesson_modal_editor-wrap').addClass('tmce-active');
let editor_id = 'tutor_lesson_modal_editor',
editor_wrap_selector = '#wp-tutor_lesson_modal_editor-wrap',
tinymceConfig = tinyMCEPreInit.mceInit.tutor_lesson_editor_config;

var tinymceConfig = tinyMCEPreInit.mceInit.tutor_lesson_editor_config;
if (!tinymceConfig) {
tinymceConfig = tinyMCEPreInit.mceInit.course_description;
}

if ($(editor_wrap_selector).hasClass('html-active')) {
$(editor_wrap_selector).removeClass('html-active');
}
$(editor_wrap_selector).addClass('tmce-active');

/**
* Add codesample plugin to support code snippet
* Code snippet support for PRO user.
*
* @since v2.0.9
* @since 2.0.9
*/
if (!tinymceConfig.plugins.includes('codesample')) {
if (tinymceConfig && _tutorobject.tutor_pro_url) {
tinymceConfig.plugins = `${tinymceConfig.plugins}, codesample`;
tinymceConfig.codesample_languages = codeSampleLang;
// tinymceConfig.codesample_dialog_width = '440';
tinymceConfig.toolbar1 = `${tinymceConfig.toolbar1}, codesample`;
}
if (_tutorobject.tutor_pro_url && tinymceConfig && !tinymceConfig.plugins.includes('codesample')) {
tinymceConfig.plugins = `${tinymceConfig.plugins}, codesample`;
tinymceConfig.codesample_languages = codeSampleLang;
tinymceConfig.toolbar1 = `${tinymceConfig.toolbar1}, codesample`;
}

tinymceConfig.wpautop = false;
tinymce.init(tinymceConfig);
tinymce.execCommand(
'mceRemoveEditor',
false,
'tutor_lesson_modal_editor',
);
tinyMCE.execCommand(
'mceAddEditor',
false,
'tutor_lesson_modal_editor',
);
tinymce.execCommand('mceRemoveEditor', false, editor_id);
tinyMCE.execCommand('mceAddEditor', false, editor_id);
quicktags({ id: editor_id });

window.dispatchEvent(new Event(_tutorobject.content_change_event));
window.dispatchEvent(new CustomEvent('tutor_modal_shown', {detail: e.target}));
window.dispatchEvent(new CustomEvent('tutor_modal_shown', { detail: e.target }));
},
complete: function() {
$that.removeClass('is-loading').attr('disabled', false);
quicktags({ id: 'tutor_lesson_modal_editor' });
},
});
});
Expand All @@ -187,37 +183,24 @@ window.jQuery(document).ready(function($) {
.attr('data-video_source', val);
});

// Update lesson
/**
* Lesson Update From Lesson Modal
*/
$(document).on('click', '.update_lesson_modal_btn', function(event) {
event.preventDefault();

/**
* Fix - [embed] shortcode does not work from visual mode
* @since 2.1.6
*/
//$('#tutor_lesson_modal_editor-html').click();
let $that = $(this),
editor = tinyMCE.get('tutor_lesson_modal_editor'),
editorWrap = document.getElementById('wp-tutor_lesson_modal_editor-wrap'),
isHtmlActive = editorWrap.classList.contains('html-active'),
content = editor.getContent({ format: 'html' });

var $that = $(this);
var content;
var inputid = 'tutor_lesson_modal_editor';
var editor = tinyMCE.get(inputid);
const editorWrap = document.getElementById(
'wp-tutor_lesson_modal_editor-wrap',
);
const isHtmlActive = editorWrap.classList.contains('html-active');

if (editor) {
content = editor.getContent({format: 'raw'});
} else {
content = $('#' + inputid).val();
}

// removing <br data-mce-bogus="1">
if(content === '<p><br data-mce-bogus="1"></p>') {
if (content === '<p><br data-mce-bogus="1"></p>') {
content = '';
}

var form_data = $(this)
let form_data = $(this)
.closest('.tutor-modal')
.find('form')
.serializeObject();
Expand Down
95 changes: 62 additions & 33 deletions assets/react/course-builder/quiz.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { get_response_message } from '../helper/response';
import initTinyMCE from '../lib/tinymce';
import codeSampleLang from "../lib/codesample-lang";

window.jQuery(document).ready(function($) {
const { __ } = wp.i18n;
Expand Down Expand Up @@ -362,19 +363,21 @@ window.jQuery(document).ready(function($) {
}
});

// Add new or edit question button click
/**
* Add or edit Quiz question with modal
*/
$(document).on('click', '.tutor-quiz-open-question-form', function(e) {
e.preventDefault();

// Prepare related data for the question
var $that = $(this);
var modal = $that.closest('.tutor-modal');
var quiz_id = modal.find('[name="quiz_id"]').val();
var topic_id = modal.find('[name="topic_id"]').val();
var course_id = $('#post_ID').val();
var question_id = $that.attr('data-question-id');

var params = {
let $that = $(this),
modal = $that.closest('.tutor-modal'),
quiz_id = modal.find('[name="quiz_id"]').val(),
topic_id = modal.find('[name="topic_id"]').val(),
course_id = $('#post_ID').val(),
question_id = $that.attr('data-question-id');

let data = {
quiz_id,
topic_id,
course_id,
Expand All @@ -385,37 +388,59 @@ window.jQuery(document).ready(function($) {
$.ajax({
url: window._tutorobject.ajaxurl,
type: 'POST',
data: params,
data: data,
beforeSend: function() {
$that.addClass('is-loading').attr('disabled', true);
},
success: function(data) {
// Add the question form in modal
// Add the question form in modal.
modal.find('.tutor-modal-container').html(data.data.output);
modal.addClass('tutor-has-question-from');

// Enable quiz answer sorting for multi/radio select
// Enable quiz answer sorting for multi/radio select.
enable_quiz_answer_sorting();

/**
* If tutor pro active show rich text editor
* WP editor support to quiz question description for PRO user.
*
* @since v2.0.9
* @since 2.0.9 Rich text support.
* @since 2.2.3 WP editor support added to quiz question description.
*/
if (_tutorobject.tutor_pro_url) {
if (data.data.output) {
tinyMCE.remove('textarea#tutor_quiz_desc_text_editor');
initTinyMCE('textarea#tutor_quiz_desc_text_editor', 'codesample image', 'codesample image');

/**
* Quiz answer explanation rich text editor
* @since 2.2.0
*/
if (document.getElementById('tutor_answer_explanation')) {
tinyMCE.remove('textarea#tutor_answer_explanation');
initTinyMCE('textarea#tutor_answer_explanation', 'codesample image', 'codesample image');
if (_tutorobject.tutor_pro_url && data.data.output ) {
let id = 'tutor_quiz_desc_text_editor',
editor_wrap_selector = '#wp-tutor_quiz_desc_text_editor-wrap',
tinymceConfig = tinyMCEPreInit.mceInit.tutor_lesson_editor_config;

if (tinymceConfig) {
if ($(editor_wrap_selector).hasClass('html-active')) {
$(editor_wrap_selector).removeClass('html-active');
}
$(editor_wrap_selector).addClass('tmce-active');

if (!tinymceConfig.plugins.includes('codesample')) {
tinymceConfig.plugins = `${tinymceConfig.plugins}, codesample`;
tinymceConfig.codesample_languages = codeSampleLang;
tinymceConfig.toolbar1 = `${tinymceConfig.toolbar1}, codesample`;
}

tinymceConfig.wpautop = false;
tinymce.init(tinymceConfig);
tinymce.execCommand('mceRemoveEditor', false, id);
tinymce.execCommand('mceAddEditor', false, id);
quicktags({ id: id });
}

/**
* Quiz answer explanation rich text editor
*
* @since 2.2.0
*/
if (document.getElementById('tutor_answer_explanation')) {
tinyMCE.remove('textarea#tutor_answer_explanation');
initTinyMCE('textarea#tutor_answer_explanation', 'codesample image', 'codesample image');
}
}

window.dispatchEvent(new CustomEvent('tutor_modal_shown', {detail: e.target}));
},
complete: function() {
Expand Down Expand Up @@ -493,18 +518,22 @@ window.jQuery(document).ready(function($) {
$(document).on('click', '.quiz-modal-question-save-btn', function(e) {
e.preventDefault();

var $that = $(this);
var modal = $that.closest('.tutor-modal');
var $formInput = $('#tutor-quiz-question-wrapper :input').serializeObject();
let $that = $(this),
modal = $that.closest('.tutor-modal'),
$formInput = $('#tutor-quiz-question-wrapper :input').serializeObject();

$formInput.action = 'tutor_quiz_modal_update_question';
// If pro active then get desc text from tinyMCE editor
if (_tutorobject.tutor_pro_url) {
const questionId = $formInput.tutor_quiz_question_id;
const eidtorId = 'tutor_quiz_desc_text_editor';
const ansExplainEidtorId = 'tutor_answer_explanation';
const questionId = $formInput.tutor_quiz_question_id,
eidtorId = 'tutor_quiz_desc_text_editor',
ansExplainEidtorId = 'tutor_answer_explanation',
editorWrap = document.getElementById('wp-tutor_quiz_desc_text_editor-wrap'),
isHtmlActive = editorWrap.classList.contains('html-active');
$formInput.is_html_active = isHtmlActive;

if (tinyMCE.get(eidtorId)) {
$formInput["tutor_quiz_question["+questionId+"][question_description]"] = tinyMCE.get(eidtorId)?.getContent({format: 'raw'})
$formInput["tutor_quiz_question["+questionId+"][question_description]"] = tinyMCE.get(eidtorId)?.getContent({format: 'html'})
}

if (tinyMCE.get(ansExplainEidtorId)) {
Expand Down
7 changes: 6 additions & 1 deletion assets/scss/front/course/_single-course-details.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@

// Sidebar
.tutor-single-course-sidebar {
&.tutor-sidebar-sticky {
position: sticky;
top: 50px;
}

.tutor-sidebar-card {
.tutor-card-body {
background-color: #F4F6F9;
Expand Down Expand Up @@ -108,4 +113,4 @@
}
}
}
}
}
4 changes: 2 additions & 2 deletions cache/QuizAttempts.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class QuizAttempts extends AbstractCache {
*
* @since 2.0.6
*/
private const KEY = 'tutor_quiz_attempts_count';
const KEY = 'tutor_quiz_attempts_count';

/**
* Cache expire time
Expand All @@ -40,7 +40,7 @@ class QuizAttempts extends AbstractCache {
*
* @since 2.0.6
*/
private const HOUR_IN_SECONDS = 1800;
const HOUR_IN_SECONDS = 1800;

/**
* Data for caching
Expand Down
1 change: 0 additions & 1 deletion classes/Instructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public function add_new_instructor() {
'last_name' => __( 'Last name field is required', 'tutor' ),
'email' => __( 'E-Mail field is required', 'tutor' ),
'user_login' => __( 'User Name field is required', 'tutor' ),
'phone_number' => __( 'Phone Number field is required', 'tutor' ),
'password' => __( 'Password field is required', 'tutor' ),
'password_confirmation' => __( 'Your passwords should match each other. Please recheck.', 'tutor' ),
)
Expand Down
Loading

0 comments on commit ccbda39

Please sign in to comment.