/source/Plug-in/fck/editor/_source/classes/fckevents.js

http://prosporous.googlecode.com/ · JavaScript · 71 lines · 37 code · 7 blank · 27 comment · 8 complexity · a7d29831ec21366e7024ed85002f3276 MD5 · raw file

  1. /*
  2. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3. * Copyright (C) 2003-2007 Frederico Caldeira Knabben
  4. *
  5. * == BEGIN LICENSE ==
  6. *
  7. * Licensed under the terms of any of the following licenses at your
  8. * choice:
  9. *
  10. * - GNU General Public License Version 2 or later (the "GPL")
  11. * http://www.gnu.org/licenses/gpl.html
  12. *
  13. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14. * http://www.gnu.org/licenses/lgpl.html
  15. *
  16. * - Mozilla Public License Version 1.1 or later (the "MPL")
  17. * http://www.mozilla.org/MPL/MPL-1.1.html
  18. *
  19. * == END LICENSE ==
  20. *
  21. * FCKEvents Class: used to handle events is a advanced way.
  22. */
  23. var FCKEvents = function( eventsOwner )
  24. {
  25. this.Owner = eventsOwner ;
  26. this._RegisteredEvents = new Object() ;
  27. }
  28. FCKEvents.prototype.AttachEvent = function( eventName, functionPointer )
  29. {
  30. var aTargets ;
  31. if ( !( aTargets = this._RegisteredEvents[ eventName ] ) )
  32. this._RegisteredEvents[ eventName ] = [ functionPointer ] ;
  33. else
  34. {
  35. // Check that the event handler isn't already registered with the same listener
  36. // It doesn't detect function pointers belonging to an object (at least in Gecko)
  37. if ( aTargets.IndexOf( functionPointer ) == -1 )
  38. aTargets.push( functionPointer ) ;
  39. }
  40. }
  41. FCKEvents.prototype.FireEvent = function( eventName, params )
  42. {
  43. var bReturnValue = true ;
  44. var oCalls = this._RegisteredEvents[ eventName ] ;
  45. if ( oCalls )
  46. {
  47. for ( var i = 0 ; i < oCalls.length ; i++ )
  48. {
  49. try
  50. {
  51. bReturnValue = ( oCalls[ i ]( this.Owner, params ) && bReturnValue ) ;
  52. }
  53. catch(e)
  54. {
  55. // Ignore the following error. It may happen if pointing to a
  56. // script not anymore available (#934):
  57. // -2146823277 = Can't execute code from a freed script
  58. if ( e.number != -2146823277 )
  59. throw e ;
  60. }
  61. }
  62. }
  63. return bReturnValue ;
  64. }