/* For licensing terms, see /license.txt */ const $ = require('jquery'); window.jQuery = $; window.$ = $; global.jQuery = $; global.$ = global.jQuery = $ //Routing.setRoutingData(routes); const locale = document.querySelector('html').lang; // moment const { DateTime } = require("luxon"); window.luxon = global.luxon = DateTime; import 'select2/dist/js/select2.full.min'; import 'select2/dist/css/select2.min.css'; import 'moment'; // Gets HTML content from tinymce window.getContentFromEditor = function (id) { if (typeof tinymce == "undefined") { return false; } let content = ''; if (tinymce.get(id)) { content = tinymce.get(id).getContent(); } return content; }; window.setContentFromEditor = function (id, content) { if (tinymce.get(id)) { tinymce.get(id).setContent(content); return true; } return false; }; //require('flatpickr'); import 'jquery-ui-dist/jquery-ui.js'; // const frameReady = require('/public/main/inc/lib/javascript/jquery.frameready.js'); // // global.frameReady = frameReady; // window.frameReady = frameReady; require('./vendor'); import './main'; // Date time settings. import moment from 'moment' global.moment = moment; moment.locale(locale); //$.datepicker.setDefaults($.datepicker.regional[locale]); //$.datepicker.regional["local"] = $.datepicker.regional[locale]; import('qtip2'); require('bootstrap-daterangepicker/daterangepicker.js'); require('blueimp-file-upload'); require('blueimp-load-image'); import('mediaelement'); require('multiselect-two-sides'); require('datepair.js'); require('timepicker'); //import 'jquery-sortablejs'; import Sortable from 'sortablejs'; window.Sortable = Sortable; import Swal from 'sweetalert2'; window.Swal = Swal; // @todo rework url naming //const homePublicUrl = Routing.generate('index'); const homePublicUrl = '/'; const mainUrl = homePublicUrl + 'main/'; const webAjax = homePublicUrl + 'main/inc/ajax/'; $(function () { let courseId = $('body').attr('data-course-id'); let webCidReq = '&cid=' + courseId + '&sid=' + $('body').attr('data-session-id'); window.webCidReq = webCidReq; $("#menu_courses").click(function(){ return false; }); $("#menu_social").click(function(){ return false; }); $("#menu_administrator").click(function(){ return false; }); if (courseId >0) { let courseCode = $("body").data("course-code"); let logOutUrl = webAjax + 'course.ajax.php?a=course_logout&cidReq=' + courseCode; function courseLogout() { $.ajax({ async: false, url: logOutUrl, success: function () { return 1; } }); } addMainEvent(window, 'unload', courseLogout ,false); } $("#open-view-list").click(function () { $("#student-list-work").fadeIn(300); }); $("#closed-view-list").click(function () { $("#student-list-work").fadeOut(300); }); // Removes the yellow input in Chrome if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) { $(window).on("load", function () { $('input:-webkit-autofill').each(function () { var text = $(this).val(); var name = $(this).attr('name'); $(this).after(this.outerHTML).remove(); $('input[name=' + name + ']').val(text); }); }); } // MODAL DELETE CONFIRM $('.delete-swal').click(function (e) { e.preventDefault(); // Prevent the href from redirecting directly var url = $(this).attr("href"); var title = $(this).data('title') || $(this).attr("title"); Swal.fire({ title: title, text: '', icon: 'warning', showCancelButton: true, cancelButtonText: 'Cancel', confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes', }).then((result) => { if (result.value) { /*Swal.fire( 'Deleted!', 'Your file has been deleted.', 'success' )*/ window.location.href = url; } }); }); // Start modals // class='ajax' loads a page in a modal $('body').on('click', 'a.ajax', function (e) { e.preventDefault(); var contentUrl = this.href, loadModalContent = $.get(contentUrl), self = $(this); $.when(loadModalContent).done(function (modalContent) { var modalTitle = self.data('title') || ' ', globalModalTitle = $('#global-modal').find('#global-modal-title'), globalModalBody = $('#global-modal').find('#global-modal-body'); globalModalTitle.text(modalTitle); globalModalBody.html(modalContent); globalModalBody.css({'max-height' : "500px", "overflow" : "auto"}); toggleModal('global-modal'); }); }); $('#global-modal').on('hidden.bs.modal', function () { $(".embed-responsive").find('iframe').remove(); }); $('#close-global-model').on('click', function () { toggleModal('global-modal'); }); // Expands an image modal $('a.expand-image').on('click', function (e) { e.preventDefault(); var title = $(this).attr('title'); var image = new Image(); image.onload = function () { if (title) { $('#expand-image-modal').find('.modal-title').text(title); } else { $('#expand-image-modal').find('.modal-title').html(' '); } $('#expand-image-modal').find('.modal-body').html(image); $('#expand-image-modal').modal({ show: true }); }; image.src = this.href; }); // Delete modal $('#confirm-delete').on('show.bs.modal', function (e) { $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href')); //var message = '{{ 'AreYouSureToDeleteJS' | get_lang }}: ' + $(e.relatedTarget).data('item-title') + ''; var message = 'AreYouSureToDeleteJS : ' + $(e.relatedTarget).data('item-title') + ''; if ($(e.relatedTarget).data('item-question')) { message = $(e.relatedTarget).data('item-question'); } $('.debug-url').html(message); }); // End modals // old jquery.menu.js $('#navigation a').stop().animate({ 'marginLeft':'50px' },1000); $('#navigation div').hover( function () { $('a',$(this)).stop().animate({ 'marginLeft':'1px' },200); }, function () { $('a',$(this)).stop().animate({ 'marginLeft':'50px' },200); } ); jQuery.fn.filterByText = function (textbox) { return this.each(function () { var select = this; var options = []; $(select).find('option').each(function () { options.push({value: $(this).val(), text: $(this).text()}); }); $(select).data('options', options); $(textbox).bind('change keyup', function () { var options = $(select).empty().data('options'); var search = $.trim($(this).val()); var regex = new RegExp(search, "gi"); $.each(options, function (i) { var option = options[i]; if (option.text.match(regex) !== null) { $(select).append( $('