Streber PM PHP Cross Reference Groupware Applications

Source: /js/contextMenus.js - 213 lines - 7025 bytes - Summary - Text - Print

   1   // context menu data objects

   2  var cMenu = new Object( );
   3  
   4  // position and display context menu

   5  function showContextMenu(evt) {
   6      // hide any existing menu just in case

   7      hideContextMenus( );
   8      evt = (evt) ? evt : ((event) ? event : null);
   9      if (evt) {
  10          var elem = (evt.target) ? evt.target : evt.srcElement;
  11           if (elem.nodeType == 3) {
  12              elem = elem.parentNode;
  13          }
  14  
  15          var table_id="";
  16          if(elem.tagName == 'TD') {
  17              var par= elem.parentNode;
  18              table_id= cMenu.table_id= par.parentNode.parentNode.id;
  19              cMenu.tr_id= par.id;
  20          }
  21  
  22          //--- look for menu-defintion ----

  23          for (var i in cMenu.menus) {
  24  
  25              if(elem && table_id == i) {
  26  
  27              //alert("table_id="+elem.tagName);

  28              //if (elem && table_id == "tasks") {

  29  
  30                  var menu = document.getElementById(cMenu.menus[table_id].menuID);
  31  
  32                 /* var list_elem= document.getElementById(cMenu[table_id].menuID+"_items");

  33                  alert(list_elem);

  34                  var children= list_elem.childNodes;

  35  

  36                  while(list_elem.hasChildNodes()) {

  37                        var knoten= list_elem.firstChild;

  38                      alert ("knoten="+knoten);

  39                      list_elem.removeChild(knoten);

  40                  }

  41                  */
  42  
  43                  //alert("menu is now"+menu);

  44                  // turn on IE mouse capture

  45                  if (menu.setCapture) {
  46                      menu.setCapture( );
  47                  }
  48                  // position menu at mouse event location

  49                  var left, top;
  50                  if (evt.pageX) {
  51                      left = evt.pageX;
  52                      top = evt.pageY;
  53                  //} else if (evt.offsetX || evt.offsetY) {

  54                  //    left = evt.offsetX;

  55                  //    top = evt.offsetY;

  56                  } else if (evt.clientX) {
  57                      left = evt.clientX;
  58                      top = evt.clientY;
  59                  }
  60                  menu.style.display="block";
  61                  menu.style.left = left + "px";
  62                  menu.style.top = top + "px";
  63                  menu.style.visibility = "visible";
  64                  if (evt.preventDefault) {
  65                      evt.preventDefault( );
  66                  }
  67                  evt.returnValue = false;
  68              }
  69          }
  70      }
  71  }
  72  
  73  // retrieve URL from cMenu object related to chosen item

  74  function getMenuItem(tdElem) {
  75      var div = tdElem.parentNode.parentNode.parentNode.parentNode;
  76      var index = tdElem.parentNode.rowIndex;
  77      for (var i in cMenu.menus) {
  78          if (cMenu.menus[i].menuID == div.id) {
  79              cMenu.cur_item=cMenu.menus[i].items[index];
  80              cMenu.cur_menu=cMenu.menus[i];
  81              return cMenu.menus[i].items[index];
  82          }
  83      }
  84      return "";
  85  }
  86  
  87  // navigate to chosen menu item

  88  function execMenu(evt) {
  89      evt = (evt) ? evt : ((event) ? event : null);
  90      if (evt) {
  91          var elem = (evt.target) ? evt.target : evt.srcElement;
  92          if (elem.nodeType == 3) {
  93              elem = elem.parentNode;
  94          }
  95          if (elem.className == "menuItemOn") {
  96              var item=getMenuItem(elem);
  97  
  98              //--- submit-actions for one of more items ---------

  99              if(item.type == 'submit') {
 100                  var num_selected= getNumSelected(cMenu.table_id);
 101                  //alert("exec!"+ item +","+cMenu.table_id +","+cMenu.tr_id);

 102  
 103                  if(!num_selected) {
 104                      checkbox= document.getElementById(cMenu.tr_id+"_chk");
 105                      checkbox.checked=1;
 106                  }
 107  
 108                  if(item.go) {
 109                      document.my_form.go.value=item.go;
 110                  }
 111                  document.my_form.submit();
 112              }
 113          //    location.href = getHref(elem);

 114          }
 115          hideContextMenus( );
 116      }
 117  }
 118  
 119  function getNumSelected(table_id) {
 120      var counter=0;
 121      //alert("table_id="+table_id);

 122      var checkboxes=document.getElementsByTagName('input');
 123      for(i in checkboxes) {
 124          //alert("c="+ checkboxes[i] +" c.id="+checkboxes[i].id);

 125          c=checkboxes[i];
 126          if(c.id && c.id.indexOf(table_id)!=-1) {
 127              //alert("checkbox:"+c);

 128              counter+= c.checked;
 129          }
 130      }
 131      //alert("num checkboxes="+counter);

 132      return counter;
 133  }
 134  
 135  // hide all context menus

 136  function hideContextMenus( ) {
 137      if (document.releaseCapture) {
 138          // turn off IE mouse event capture

 139          document.releaseCapture( );
 140      }
 141      for (var i in cMenu.menus) {
 142          //alert("hide="+cMenu.menus[i].menuID);

 143          var div = document.getElementById(cMenu.menus[i].menuID);
 144          //alert("div="+div);

 145          div.style.visibility = "hidden";
 146      }
 147  }
 148  
 149  // rollover highlights of context menu items

 150  function toggleHighlight(evt) {
 151      evt = (evt) ? evt :
 152   ((event) ? event : null);
 153      if (evt) {
 154          var elem = (evt.target) ? evt.target : evt.srcElement;
 155          if (elem.nodeType == 3) {
 156              elem = elem.parentNode;
 157          }
 158          if (elem.className.indexOf("menuItem") != -1) {
 159              elem.className = (evt.type == "mouseover") ? "menuItemOn" : "menuItem";
 160          }
 161      }
 162  }
 163  
 164  // set tooltips for menu-capable and lesser browsers

 165  function setContextTitles( ) {
 166      var cMenuReady = (document.body.addEventListener ||
 167          typeof document.oncontextmenu != "undefined")
 168      var spans = document.body.getElementsByTagName("span");
 169      for (var i = 0; i < spans.length; i++) {
 170          if (spans[i].className == "contextEntry") {
 171              if (cMenuReady) {
 172                  var menuAction = (navigator.userAgent.indexOf("Mac") != -1) ?
 173                      "Click and hold " : "Right click ";
 174                  spans[i].title = menuAction + "to view relevant links"
 175              } else {
 176                  spans[i].title = "Relevant links available with other browsers " +
 177                  "(IE5+/Windows, Netscape 6+)."
 178                  spans[i].style.cursor = "default";
 179              }
 180          }
 181      }
 182  }
 183  
 184  // bind events and initialize tooltips

 185  function initContextMenus( ) {
 186      if (document.body.addEventListener) {
 187          // W3C DOM event model

 188          document.body.addEventListener("contextmenu", showContextMenu, true);
 189          document.body.addEventListener("click", hideContextMenus, true);
 190      } else {
 191          // IE event model

 192          document.body.oncontextmenu = showContextMenu;
 193      }
 194      // set intelligent tooltips

 195      setContextTitles( );
 196  
 197  }
 198  
 199  /*

 200  function addMenu(table,menu_div) {

 201      cMenu.menus[table]={menuID:menu_div};

 202      //alert("addMenu="+table+","+menu_div);

 203  }

 204  */
 205  
 206  
 207   function SelectJump() {
 208      var welcherLink = document.Springen.URLs.selectedIndex;
 209      document.Springen.URLs.selectedIndex = "0";
 210      if(welcherLink > "0"){
 211         top.location.href = document.Springen.URLs.options[welcherLink].value;
 212      }
 213   }

title

Description

title

Description

title

Description

title

title

Body