Tagged: javascript

Moodle js code : To execute jquery

in moodle , the way of writting javascript has changed.

you can use followin basic to get the document ready in using jquery

Mustache Tempate

{{#js}}
require(['jquery'], function($){
    $(document).ready(function(){
         alert("hello");
    });
});
{{/js}}

In PHP File

require(['jquery'], function($){
    $(document).ready(function(){
         alert("hello");
    });
});

AMD javascript plugin to disable right click / cut / copy paste for Moodle

Following JS file can be included, that can disable

  • Mouse Right Click
  • Opening of developer console in Browser
  • Disable Cut / Copy / Paste

Following is the code

You just need to unzip this. This will show an amd folder. this contains the compiled file as well.

put that folder into plugin

and call this js by putting this php code on any page

// remember : local_poc means you are writing local plugin name as poc, so you will put amd folder in poc directory

//if you are writing block then, 
//$PAGE->requires->js_call_amd('block_poc/disabler', 'init');

$PAGE->requires->js_call_amd('local_poc/disabler', 'init');

for more about javascript in moodle , read following