[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/include/fckeditor/editor/_source/internals/ -> fcktools.js (source)

   1  /*
   2   * FCKeditor - The text editor for internet
   3   * Copyright (C) 2003-2005 Frederico Caldeira Knabben
   4   * 
   5   * Licensed under the terms of the GNU Lesser General Public License:
   6   *         http://www.opensource.org/licenses/lgpl-license.php
   7   * 
   8   * For further information visit:
   9   *         http://www.fckeditor.net/
  10   * 
  11   * "Support Open Source software. What about a donation today?"
  12   * 
  13   * File Name: fcktools.js
  14   *     Utility functions.
  15   * 
  16   * File Authors:
  17   *         Frederico Caldeira Knabben (fredck@fckeditor.net)
  18   */
  19  
  20  var FCKTools = new Object() ;
  21  
  22  //**
  23  // FCKTools.GetLinkedFieldValue: Gets the value of the hidden INPUT element
  24  // that is associated to the editor. This element has its ID set to the 
  25  // editor's instance name so the user reffers to the instance name when getting
  26  // the posted data.
  27  FCKTools.GetLinkedFieldValue = function()
  28  {
  29      return FCK.LinkedField.value ;
  30  }
  31  
  32  //**
  33  // FCKTools.AttachToLinkedFieldFormSubmit: attaches a function call to the 
  34  // submit event of the linked field form. This function us generally used to
  35  // update the linked field value before submitting the form.
  36  FCKTools.AttachToLinkedFieldFormSubmit = function( functionPointer )
  37  {
  38      // Gets the linked field form
  39      var oForm = FCK.LinkedField.form ;
  40      
  41      // Return now if no form is available
  42      if (!oForm) return ;
  43  
  44      // Attaches the functionPointer call to the onsubmit event
  45      if ( FCKBrowserInfo.IsIE )
  46          oForm.attachEvent( "onsubmit", functionPointer ) ;
  47      else
  48          oForm.addEventListener( 'submit', functionPointer, true ) ;
  49      
  50      //**
  51      // Attaches the functionPointer call to the submit method 
  52      // This is done because IE doesn't fire onsubmit when the submit method is called
  53      // BEGIN --
  54      
  55      // Creates a Array in the form object that will hold all Attached function call
  56      // (in the case there are more than one editor in the same page)
  57      if (! oForm.updateFCKeditor) oForm.updateFCKeditor = new Array() ;
  58      
  59      // Adds the function pointer to the array of functions to call when "submit" is called
  60      oForm.updateFCKeditor[oForm.updateFCKeditor.length] = functionPointer ;
  61  
  62      // Switches the original submit method with a new one that first call all functions
  63      // on the above array and the call the original submit
  64      // IE sees it oForm.submit function as an 'object'.
  65      if (! oForm.originalSubmit && ( typeof( oForm.submit ) == 'function' || ( !oForm.submit.tagName && !oForm.submit.length ) ) )
  66      {
  67          // Creates a copy of the original submit
  68          oForm.originalSubmit = oForm.submit ;
  69          
  70          // Creates our replacement for the submit
  71          oForm.submit = FCKTools_SubmitReplacer ;
  72      }
  73      // END --
  74  }
  75  
  76  function FCKTools_SubmitReplacer()
  77  {
  78      if (this.updateFCKeditor)
  79      {
  80          // Calls all functions in the functions array
  81          for (var i = 0 ; i < this.updateFCKeditor.length ; i++)
  82              this.updateFCKeditor[i]() ;
  83      }
  84      // Calls the original "submit"
  85      this.originalSubmit() ;
  86  }
  87  
  88  //**
  89  // FCKTools.AddSelectOption: Adds a option to a SELECT element.
  90  FCKTools.AddSelectOption = function( targetDocument, selectElement, optionText, optionValue )
  91  {
  92      var oOption = targetDocument.createElement("OPTION") ;
  93  
  94      oOption.text    = optionText ;
  95      oOption.value    = optionValue ;    
  96  
  97      selectElement.options.add(oOption) ;
  98  
  99      return oOption ;
 100  }
 101  /*
 102  FCKTools.RemoveAllSelectOptions = function( selectElement )
 103  {
 104      for ( var i = selectElement.options.length - 1 ; i >= 0 ; i-- )
 105      {
 106          selectElement.options.remove(i) ;
 107      }
 108  }
 109  
 110  FCKTools.SelectNoCase = function( selectElement, value, defaultValue )
 111  {
 112      var sNoCaseValue = value.toString().toLowerCase() ;
 113      
 114      for ( var i = 0 ; i < selectElement.options.length ; i++ )
 115      {
 116          if ( sNoCaseValue == selectElement.options[i].value.toLowerCase() )
 117          {
 118              selectElement.selectedIndex = i ;
 119              return ;
 120          }
 121      }
 122      
 123      if ( defaultValue != null ) FCKTools.SelectNoCase( selectElement, defaultValue ) ;
 124  }
 125  */
 126  FCKTools.HTMLEncode = function( text )
 127  {
 128      if ( !text )
 129          return '' ;
 130  
 131      text = text.replace( /&/g, "&amp;" ) ;
 132      text = text.replace( /"/g, "&quot;" ) ;
 133      text = text.replace( /</g, "&lt;" ) ;
 134      text = text.replace( />/g, "&gt;" ) ;
 135      text = text.replace( /'/g, "&#39;" ) ;
 136  
 137      return text ;
 138  }
 139  /*
 140  //**
 141  // FCKTools.GetResultingArray: Gets a array from a string (where the elements 
 142  // are separated by a character), a fuction (that returns a array) or a array.
 143  FCKTools.GetResultingArray = function( arraySource, separator )
 144  {
 145      switch ( typeof( arraySource ) )
 146      {
 147          case "string" :
 148              return arraySource.split( separator ) ;
 149          case "function" :
 150              return separator() ;
 151          default :
 152              if ( isArray( arraySource ) ) return arraySource ;
 153              else return new Array() ;
 154      }
 155  }
 156  */
 157  FCKTools.GetElementPosition = function( el, relativeWindow )
 158  {
 159  // Initializes the Coordinates object that will be returned by the function.
 160      var c = { X:0, Y:0 } ;
 161      
 162      var oWindow = relativeWindow || window ;
 163  
 164      // Loop throw the offset chain.
 165      while ( el )
 166      {
 167          c.X += el.offsetLeft ;
 168          c.Y += el.offsetTop ;
 169  
 170          if ( el.offsetParent == null )
 171          {
 172              var oOwnerWindow = FCKTools.GetElementWindow( el ) ;
 173              
 174              if ( oOwnerWindow != oWindow )
 175                  el = oOwnerWindow.frameElement ;
 176              else
 177                  break ;
 178          }
 179          else
 180              el = el.offsetParent ;
 181      }
 182  
 183      // Return the Coordinates object
 184      return c ;
 185  }
 186  
 187  // START iCM MODIFICATIONS
 188  // Amended to accept a list of one or more ascensor tag names
 189  // Amended to check the element itself before working back up through the parent hierarchy
 190  FCKTools.GetElementAscensor = function( element, ascensorTagNames )
 191  {
 192  //    var e = element.parentNode ;
 193      var e = element ;
 194      var lstTags = "," + ascensorTagNames.toUpperCase() + "," ;
 195  
 196      while ( e )
 197      {
 198          if ( lstTags.indexOf( "," + e.nodeName.toUpperCase() + "," ) != -1 )
 199              return e ;
 200  
 201          e = e.parentNode ;
 202      }
 203      return null ;
 204  }
 205  // END iCM MODIFICATIONS
 206  
 207  FCKTools.Pause = function( miliseconds )
 208  {
 209      var oStart = new Date() ;
 210  
 211      while (true)
 212      { 
 213          var oNow = new Date() ;
 214          if ( miliseconds < oNow - oStart ) 
 215              return ;
 216      }
 217  }
 218  
 219  FCKTools.ConvertStyleSizeToHtml = function( size )
 220  {
 221      return size.endsWith( '%' ) ? size : parseInt( size ) ;
 222  }
 223  
 224  FCKTools.ConvertHtmlSizeToStyle = function( size )
 225  {
 226      return size.endsWith( '%' ) ? size : ( size + 'px' ) ;
 227  }
 228  
 229  // Get the window object where the element is placed in.
 230  FCKTools.GetElementWindow = function( element )
 231  {
 232      var oDocument = element.ownerDocument || element.document ;
 233      
 234      // With Safari, there is not way to retrieve the window from the document, so we must fix it.
 235      if ( FCKBrowserInfo.IsSafari && !oDocument.parentWindow )
 236          FCKTools._FixDocumentParentWindow( window.top ) ;
 237      
 238      return oDocument.parentWindow || oDocument.defaultView ;
 239  }
 240  
 241  /*
 242      This is a Safari specific function that fix the reference to the parent 
 243      window from the document object.
 244  */
 245  FCKTools._FixDocumentParentWindow = function( targetWindow )
 246  {
 247      targetWindow.document.parentWindow = targetWindow ; 
 248      
 249      for ( var i = 0 ; i < targetWindow.frames.length ; i++ )
 250          FCKTools._FixDocumentParentWindow( targetWindow.frames[i] ) ;
 251  }
 252  
 253  FCKTools.CancelEvent = function( e )
 254  {
 255      return false ;
 256  }
 257  
 258  // START iCM MODIFICATIONS
 259  /*
 260  // Transfers the supplied attributes to the supplied node
 261  FCKTools.SetElementAttributes = function( oElement, oAttributes ) 
 262  {
 263      for ( var i = 0; i < oAttributes.length; i++ ) 
 264      {
 265          if ( oAttributes[i].specified ) // Needed for IE which always returns all attributes whether set or not
 266              oElement.setAttribute( oAttributes[i].nodeName, oAttributes[i].nodeValue, 0 ) ;
 267      }
 268  }
 269  
 270  // Get immediate block node (P, H1, for example) for the supplied node - the supplied node may itself be a block node in which
 271  // case it will be returned. If no block node found, returns null.
 272  FCKTools.GetParentBlockNode = function( oNode )
 273  {
 274      if ( oNode.nodeName.toUpperCase() == "BODY" )
 275          return null ;
 276      else if ( oNode.nodeType == 1 && FCKRegexLib.BlockElements.test(oNode.tagName) )
 277          return oNode ;
 278      else
 279          return FCKTools.GetParentBlockNode( oNode.parentNode ) ;
 280  }
 281  
 282  // Run through any children of the supplied node. If there are none, or they only comprise 
 283  // empty text nodes and BR nodes, then the node is effectively empty.
 284  // Sometimes (on Gecko) a seemingly empty node is coming back with several children that are solely
 285  // empty text nodes and BRs e.g. the first item in an OL list, for example, when 
 286  // UseBROnCarriageReturn is set to false. 
 287  // Seems to be due to the use of the <br _moz_editor_bogus_node="TRUE"> (GECKO_BOGUS) as fillers both
 288  // in fck_gecko_1.js when html is empty and in ENTER key handler ? If normal BR tags are
 289  // used instead this doesn't seem to happen....
 290  FCKTools.NodeIsEmpty = function( oNode )
 291  {
 292      var oSibling = oNode.childNodes[0] ;
 293      while ( oSibling )
 294      {
 295          if ( ( oSibling.nodeType != 1 && oSibling.nodeType != 3 ) || ( oSibling.nodeType == 1 && oSibling.nodeName.toUpperCase() != "BR" ) || ( oSibling.nodeType == 3 && oSibling.nodeValue && oSibling.nodeValue.trim() != '' ) )
 296              return false ;
 297          
 298          oSibling = oSibling.nextSibling ;
 299      }
 300  
 301      return true ;
 302  }
 303  
 304  // Returns a document fragment that contains a copy of the specified range of nodes
 305  FCKTools.GetDocumentFragment = function( oParentNode, oFromNode, oToNode, bIncludeFromNode, bIncludeToNode, bClone )
 306  {    
 307      if ( typeof bIncludeFromNode == "undefined" )  bIncludeFromNode = true ;
 308      if ( typeof bIncludeToNode == "undefined" )  bIncludeToNode = true ;
 309      if ( typeof bClone == "undefined" )  bClone = true ;
 310  
 311      var oFragment = FCK.EditorDocument.createDocumentFragment() ;
 312      
 313      var oNode = oFromNode ;
 314      while ( oNode && oNode != oToNode )
 315      {
 316          if ( oNode != oFromNode || bIncludeFromNode )
 317              oFragment.appendChild( bClone ? oNode.cloneNode( true ) : oNode ) ;
 318              
 319          oNode = oNode.nextSibling ;
 320      }
 321  
 322      if ( oNode && (oFromNode != oToNode && bIncludeToNode) )
 323          oFragment.appendChild( bClone ? oNode.cloneNode( true ) : oNode ) ; // Include To Node
 324  
 325      return oFragment ;
 326  }
 327  */
 328  // END iCM MODIFICATIONS


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7