Run JS function when block has been deleted

Permalink
Hi all,

I am wondering if there is a way to hook into the js delete block function. For example when a block is deleted the update notification appears in the top right of the screen. I'd like to run my own js function at the same times as when the above notification message appears.

Any help would be greatly appreciated.

Cheers,
Mat

mbaxter91288
 
JohntheFish replied on at Permalink Reply
JohntheFish
The notification is handled in a global js function ccmAlert(). If you really wanted to tie some script to the actual notification appearing, you could write script to subvert that function using a technique similar to:

http://www.concrete5.org/documentation/how-tos/developers/subvert-t...

Applying a similar subversion to the global js function ccm_deleteBlock() would probably be more robust as it would not be susceptible to the whims of any changes to notification processing, but the script would run when the delete started, not when it had completed.

In c5.7 I suspect that both of the above could break because the ccm.app javascript is being substantially redeveloped.

In either case the script that inserts the subverted function would have to be loaded and run after ccm.app.js is loaded.
mbaxter91288 replied on at Permalink Reply
mbaxter91288
hi @JohntheFish

Thanks for the quick response much appreciated. Not following unfortunately. This is what I've come up with:

<script>
$(function () {
   var redirect_old_handler = ccmAlert;
   var redirect_new_handler = function() {
      redirect_old_handler();
      alert('test');
   };
   ccmAlert = redirect_new_handler;
});
</script>


But I get the below error:

Uncaught TypeError: Object function () {
redirect_old_handler();
alert('test');
} has no method 'hud'

Thanks,
Mat
JohntheFish replied on at Permalink Reply
JohntheFish
My mistake, ccmAlert() is an object with a couple of methods. You need to apply the trick to the individual method ccmAlert.hud (or maybe ccmAlert.notice).

You can see the source for what you are intercepting in the core file js/legacy_dialog.js