email_link.js.tpl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <script>
  2. /* For licensing terms, see /license.txt */
  3. /*
  4. * JS library to deal with event handlers.
  5. * This script needs to be included from a script where the global include file has already been loaded.
  6. * @package chamilo.inc.lib.javascript
  7. * @author Yannick Warnier
  8. * @author Julio Montoya - Adding twig support
  9. */
  10. /*
  11. * Assigns any event handler to any element
  12. * @param object Element on which the event is added
  13. * @param string Name of event
  14. * @param string Function to trigger on event
  15. * @param boolean Capture the event and prevent
  16. */
  17. function addEvent(elm, evType, fn, useCapture) {
  18. if (elm.addEventListener){
  19. elm.addEventListener(evType, fn, useCapture);
  20. return true;
  21. } else if(elm.attachEvent) {
  22. var r = elm.attachEvent('on' + evType, fn);
  23. return r;
  24. } else {
  25. elm['on' + evType] = fn;
  26. }
  27. }
  28. /*
  29. * Adds the event listener
  30. */
  31. function addListeners(e) {
  32. var my_links = $('.clickable_email_link');
  33. for(var i=0;i < my_links.length;i++) {
  34. addEvent(my_links[i],'click',loadEmailEditor,false);
  35. }
  36. }
  37. /*
  38. * Loads a specific page on event triggering
  39. */
  40. function loadEmailEditor(e) {
  41. var el;
  42. if(window.event && window.event.srcElement) {
  43. el = window.event.srcElement;
  44. }
  45. if (e && e.target) {
  46. el = e.target;
  47. }
  48. if(!el) {
  49. return;
  50. }
  51. //el is now my link object, so I can get el.href here to load the new window
  52. var link = el.href.replace('mailto:','');
  53. document.location = "{{ _p.web_main }}inc/lib/email_editor.php?dest=" + link;
  54. //cancel default link action
  55. if (window.event && window.event.returnValue){
  56. window.event.returnValue = false;
  57. }
  58. if(e && e.preventDefault){
  59. e.preventDefault();
  60. }
  61. }
  62. $(document).ready(function() {
  63. addEvent(window,'load',addListeners,false);
  64. });
  65. </script>