dokeos-inc-lib-javascript
[ class tree: dokeos-inc-lib-javascript ] [ index: dokeos-inc-lib-javascript ] [ all elements ]

Source for file email_links.lib.js.php

Documentation is available at email_links.lib.js.php

  1. <?php //$id: $
  2. /**
  3.  * Pseudo JavaScript library to deal with event handlers.
  4.  * This script needs to be included from a script where the global include file has already been loaded.
  5.  * @package dokeos.inc.lib.javascript
  6.  * @author Yannick Warnier <ywarnier@beeznest.org>
  7.  */
  8. /**
  9.  * If the user is not logged in, don't define anything, so the normal
  10.  * handling of mailto link can proceed
  11.  */
  12. if(!empty($_user['user_id']AND string_2_boolean(api_get_setting('allow_email_editor'))){
  13. ?>
  14. <script language="javascript" version="1.3" type="text/javascript">
  15. /**
  16.  * Assigns any event handler to any element
  17.  * @param    object    Element on which the event is added
  18.  * @param    string    Name of event
  19.  * @param    string    Function to trigger on event
  20.  * @param    boolean    Capture the event and prevent 
  21.  */
  22. function addEvent(elm, evType, fn, useCapture)
  23. { //by Scott Andrew
  24.     if(elm.addEventListener){
  25.         elm.addEventListener(evType, fn, useCapture);
  26.         return true;
  27.     } else if(elm.attachEvent) {
  28.         var r = elm.attachEvent('on' + evType, fn);
  29.         return r;
  30.     } else {
  31.         elm['on' + evType] = fn;
  32.     } 
  33. }
  34. /**
  35.  * Adds the event listener
  36.  */
  37. function addListeners(e) {
  38.     var my_links = document.getElementsByName('clickable_email_link');
  39.     for(var i=0;i < my_links.length;i++)
  40.     {
  41.         addEvent(my_links[i],'click',loadEmailEditor,false);
  42.     }
  43. }
  44. /**
  45.  * Loads a specific page on event triggering
  46.  */
  47. function loadEmailEditor(e)
  48. {
  49.     var el;
  50.     if(window.event && window.event.srcElement)
  51.     {
  52.         el = window.event.srcElement;
  53.     }
  54.     if (e && e.target)
  55.     {
  56.         el = e.target;
  57.     }
  58.     if(!el)
  59.     {
  60.         return;
  61.     }
  62.     //el is now my link object, so I can get el.href here to load the new window
  63.     var link = el.href.replace('mailto:','');
  64.     //document.location = "/ecoles-ccifc/claroline/messaging/email_editor.php?dest=" + el.href;
  65.     document.location = "<?php echo api_get_path(WEB_CODE_PATH);?>messaging/email_editor.php?dest=" + link;
  66.     //cancel default link action
  67.     if(window.event && window.event.returnValue){
  68.         window.event.returnValue = false;
  69.     }
  70.     if(e && e.preventDefault){
  71.         e.preventDefault();
  72.     }    
  73. }
  74. addEvent(window,'load',addListeners,false);
  75. </script>
  76. <?php
  77. }
  78. ?>

Documentation generated on Thu, 12 Jun 2008 13:22:56 -0500 by phpDocumentor 1.4.1