home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / browser_dependent.js < prev    next >
Encoding:
JavaScript  |  2004-07-12  |  3.6 KB  |  134 lines

  1. /*
  2.  * Copyright 1999-2004 The Apache Software Foundation
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *     http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  *  Unless required by applicable law or agreed to in writing, software
  11.  *  distributed under the License is distributed on an "AS IS" BASIS,
  12.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  *  See the License for the specific language governing permissions and
  14.  *  limitations under the License.
  15.  */
  16.  
  17. /*
  18.  * This is where all the browser dependent functions should be
  19.  */
  20.  
  21. var IE = (document.all) ? true : false;
  22.  
  23. function addEvent(obj,type,func,bol) {
  24.     if (IE) {
  25.         obj.attachEvent(type,func);
  26.     } else {
  27.         obj.addEventListener(type.replace(/^on/g,""),func,bol);
  28.     }
  29. }
  30.  
  31. function removeEvent(obj,type,func,bol) {
  32.     if (IE) {
  33.         obj.detachEvent(type,func);
  34.     } else {
  35.         obj.removeEventListener(type.replace(/^on/g,""),func,bol);
  36.     }
  37. }
  38.  
  39. function setClass(obj,value) {
  40.     if (IE) {
  41.         obj.className = value;
  42.     } else {
  43.         obj.setAttribute("class",value,false);
  44.     }
  45. }
  46.  
  47. function getClass(obj) {
  48.     return (IE) ? obj.className : obj.getAttribute("class");
  49. }
  50.  
  51. function getTarget(e,obj) {
  52.     if (IE) {
  53.         return window.event.srcElement;
  54.     } else {
  55.         if (e) {
  56.             return e.target;
  57.         } else {
  58.             return obj;
  59.         }
  60.     }
  61. }
  62.  
  63. function getContentSource() {
  64.     var iframe = document.getElementById('edit');
  65.     var editor_body = iframe.contentWindow.document.body;
  66.     if (IE) {
  67.         return editor_body.createTextRange();
  68.     } else {
  69.         var source = editor_body.ownerDocument.createRange();
  70.         source.selectNodeContents(editor.body);
  71.         return source.toString();
  72.     }
  73. }
  74.  
  75. function getSelection(iframe) {
  76.     if (IE) {
  77.         return iframe.contentWindow.document.selection.createRange();
  78.     } else {
  79.         return iframe.contentWindow.getSelection();
  80.     }
  81. }
  82.  
  83. function getCommandFormat(block) {
  84.     return (IE) ? "<"+block+">" : block;
  85. }
  86.  
  87. // ------------------------ WARNING: HOTSPOT! ---------------------------
  88. // since it's called for every keystroke, keep it as fast as possible!!!
  89. // ----------------------------------------------------------------------
  90.  
  91. function getOrigin() {
  92.  
  93.     var iframe = document.getElementById('edit');
  94.     var selection = getSelection(iframe);
  95.     
  96.     if (IE) {
  97.         var event = iframe.contentWindow.event;
  98.         if (selection.type == "Control") {
  99.              if (selection.length > 1) {
  100.                  alert("Error too many obj");
  101.              } else {
  102.                  return selection(0);
  103.              }
  104.         } else {
  105.             if ((selection.parentElement().nodeType != NodeType.TEXT_NODE) && event) {
  106.                 var nodes = selection.parentElement().childNodes;
  107.                 if (nodes.length == 1) return nodes[0];
  108.                 for (var co = 0; co < nodes.length; co++) {
  109.                     if (!nodes[co].offsetTop && nodes[co].nextSibling) {
  110.                         if ((nodes[co].nextSibling.offsetTop <= event.y) 
  111.                              && (nodes[co].nextSibling.offsetTop + nodes[co].nextSibling.offsetHeight >= event.y) 
  112.                              && (nodes[co].nextSibling.offsetLeft <= event.x)) { 
  113.                                 return nodes[co];
  114.                         }
  115.                     } else if ((nodes[co].offsetTop <= event.y) 
  116.                                 && (nodes[co].offsetTop + nodes[co].offsetHeight >= event.y)) {
  117.                         return nodes[co];
  118.                     }
  119.                 }
  120.                 return nodes[nodes.length-1];
  121.             }
  122.         }
  123.         return selection.parentElement();
  124.     } else {
  125.         if (selection.anchorNode == selection.focusNode) {
  126.             if (selection.anchorNode.nodeType != selection.anchorNode.TEXT_NODE) {
  127.                 var index = (selection.focusOffset == 0) ? 0 : selection.focusOffset - 1;
  128.                 return selection.anchorNode.childNodes[index];
  129.             }
  130.         }
  131.         return selection.anchorNode;
  132.     }
  133. }
  134.