From a29a50dd78fed4e9127abbcc42a70e15f8a974a1 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 15 Aug 2018 13:34:28 +0200 Subject: [PATCH] Use fos_js_routing to load URL in js file - rename main.js to vendor.js (third party libs) - create new app.js with the chamilo js code --- assets/js/app.js | 630 ++++++++++++++++++ assets/js/{main.js => vendor.js} | 1 + config/packages/fos_js_routing.yaml | 12 +- config/routes/chamilo.yaml | 8 + documentation/changelog.html | 4 +- src/CoreBundle/Controller/IndexController.php | 2 +- .../views/Layout/base-layout.html.twig | 7 - .../Resources/views/Layout/head.html.twig | 39 +- .../Resources/views/Layout/header.js.twig | 525 --------------- webpack.config.js | 5 +- 10 files changed, 676 insertions(+), 557 deletions(-) create mode 100644 assets/js/app.js rename assets/js/{main.js => vendor.js} (99%) delete mode 100644 src/ThemeBundle/Resources/views/Layout/header.js.twig diff --git a/assets/js/app.js b/assets/js/app.js new file mode 100644 index 0000000000..154700321c --- /dev/null +++ b/assets/js/app.js @@ -0,0 +1,630 @@ +const routes = require('../../public/js/fos_js_routes.json'); +import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js'; + +Routing.setRoutingData(routes); + +var homeUrl = Routing.generate('home'); +var legacyIndex = Routing.generate('legacy_index'); +var main = Routing.generate('legacy_main', {'name' : 'statusonline.png'}); +var webAjax = Routing.generate('web.ajax'); + +/*console.log(homeUrl); +console.log(legacyIndex); +console.log(main);*/ + +var ajax_url = webAjax + 'chat.ajax.php'; +var online_button = ''; +var offline_button = ''; +/*var connect_lang = '{{ "ChatConnected"|get_lang }}'; +var disconnect_lang = '{{ "ChatDisconnected"|get_lang }}';*/ + +var connect_lang = 'ChatConnected'; +var disconnect_lang = 'ChatDisconnected'; + +$(function() { + + 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); + }); + + checkBrand(); + + var id; + $(window).resize(function() { + clearTimeout(id); + id = setTimeout(doneResizing, 200); + }); + + // 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); + }); + }); + } + + $(".accordion_jquery").accordion({ + autoHeight: false, + active: false, // all items closed by default + collapsible: true, + header: ".accordion-heading" + }); + + // 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 modalDialog = $('#global-modal').find('.modal-dialog'), + modalSize = self.data('size') || get_url_params(contentUrl, 'modal_size'), + modalWidth = self.data('width') || get_url_params(contentUrl, 'width'), + modalTitle = self.data('title') || ' '; + + modalDialog.removeClass('modal-lg modal-sm').css('width', ''); + + if (modalSize && modalSize.length != 0) { + switch (modalSize) { + case 'lg': + modalDialog.addClass('modal-lg'); + break; + case 'sm': + modalDialog.addClass('modal-sm'); + break; + } + } else if (modalWidth) { + modalDialog.css('width', modalWidth + 'px'); + } + + $('#global-modal').find('.modal-title').text(modalTitle); + $('#global-modal').find('.modal-body').html(modalContent); + $('#global-modal').modal('show'); + }); + }); + + // 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); + } + ); + + /* Make responsive image maps */ + $('map').imageMapResize(); + + 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( + $('