Adding javasvript files

Re: Adding javasvript files

by Justin Hunt -
Number of replies: 2
Picture of Particularly helpful Moodlers Picture of Plugin developers

OK. 

Just post the plugin if its ok (unless that will just confuse me) ... 

If its not something you want to post here, send me a message with a URL or mail address and we can do it from there

In reply to Justin Hunt

Re: Adding javasvript files

by Ludo M -

I have found the solution:

The shim has to be:

datetimepicker: { exports: "$.fn.datetimepicker" }

Here are the files:

amd/src/config.js

define([], function () {
window.requirejs.config({
paths: {
//Enter the paths to your required java-script files
"moment": M.cfg.wwwroot + '/admin/tool/myplugin/js/moment.min',
"moment-fr": M.cfg.wwwroot + '/admin/tool/myplugin/js/moment-fr', // bootsrap 4 bundled with popper
"bootstrap": M.cfg.wwwroot + '/admin/tool/myplugin/js/bootstrap.bundle.min',
"datepickerfr": M.cfg.wwwroot + '/admin/tool/myplugin/js/bootstrap-datepicker.fr',
"datepicker": M.cfg.wwwroot + '/admin/tool/myplugin/js/datepicker',
"datetimepicker":M.cfg.wwwroot + '/admin/tool/myplugin/js/tempusdominus-bootstrap-4',
},
shim: {
//Enter the "names" that will be used to refer to your libraries
bootstrap: { deps: ["jquery"], exports: 'bootstrap'}, datepicker: { deps: ['bootstrap'],  exports: "datepicker" },
datepickerfr: { deps: ['datepicker'],  exports: "datepicker" },
datetimepicker: { exports: "$.fn.datetimepicker" }
}
});
});

amd/src/app.js

define([

'jquery',
'tool_myplugin/moment',
'tool_myplugin/bootstrap',
'tool_myplugin/datepicker',
'tool_myplugin/datetimepicker'

],
function ($,moment) {
//alert('bootstrap'+$.fn.tooltip.Constructor.VERSION);
//alert(moment({hour: 10, minute: 0}));

function initManage() {

$(document).ready(function () {

$('#datepicker').datepicker({
                    weekStart: 1,
                    todayBtn: "linked",
                    language: "fr",
                    locale: 'fr',
                    todayHighlight: true,
                    format: "dd/mm/yyyy",
                    orientation: "auto right"       });                 $('#datetimepicker1').datetimepicker({
                    format: 'HH:mm',
                    use24hours: true,
                    defaultDate: moment({hour: 9,minute:0}) });           

amd/src/datetimepicker.js

define(['tool_myplugin/config',  'datetimepicker'], function(unused,datetimepicker) {
return datetimepicker;
}
);

amd/src/moment.js

define(['tool_myplugin/config',  'moment','moment-fr'], function(unused,moment) {
moment.locale('fr');
window.moment = moment;
if (!window.moment) {
alert("moment ko");
}
//if no return, error:TypeError: moment is not a function
return moment;
}
);

amd/scr/datepicker.js

define(['tool_myplugin/config',  ,'datepicker','datepickerfr',], function(unused,datepicker) {
return datepicker;
}
);

amd/src/datepickerfr.js

define(['tool_myplugin/config', 'datepickerfr'], function(unused,datepickerfr) {
return datepickerfr;
}
);

In reply to Ludo M

Re: Adding javasvript files

by Justin Hunt -
Picture of Particularly helpful Moodlers Picture of Plugin developers

Great work. You really stuck at it. Thanks for posting back, its really useful.