How to override JS function?

Last modification: 2013-09-30 17:43:00

Let say you want to override some JS function. You can do that in the following workflow.

  • There is example in the extension folder. Basically there are two important files
    • customstatus/design/customstatustheme/tpl/pagelayouts/parts/page_head_js_extension.tpl.php
    • customstatus/design/customstatustheme/js/custom.js
  • So as we have a file where we can write our own JS. How to override default function? Let say we want to show alert to user then he decied to do not send transcript to his e-mail. Like in our system this executes. 

 

this.cancelcolorbox = function(){
        $.colorbox.remove();
    };

Our custom.js file content should look like.

lhinst.cancelcolorbox = function(data){

if (confirm('Are you sure')){
    $.colorbox.remove();
}

};

So this way we have overrided default behaviour without changing kernel.