/EQT_V1/EQTWebApp/fckeditor/editor/_source/classes/fckicon.js

http://sgsoft-las.googlecode.com/ · JavaScript · 103 lines · 60 code · 13 blank · 30 comment · 4 complexity · c8cf50f0ddd1b00dff314027084372a4 MD5 · raw file

  1. /*
  2. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3. * Copyright (C) 2003-2009 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. * FCKIcon Class: renders an icon from a single image, a strip or even a
  22. * spacer.
  23. */
  24. var FCKIcon = function( iconPathOrStripInfoArray )
  25. {
  26. var sTypeOf = iconPathOrStripInfoArray ? typeof( iconPathOrStripInfoArray ) : 'undefined' ;
  27. switch ( sTypeOf )
  28. {
  29. case 'number' :
  30. this.Path = FCKConfig.SkinPath + 'fck_strip.gif' ;
  31. this.Size = 16 ;
  32. this.Position = iconPathOrStripInfoArray ;
  33. break ;
  34. case 'undefined' :
  35. this.Path = FCK_SPACER_PATH ;
  36. break ;
  37. case 'string' :
  38. this.Path = iconPathOrStripInfoArray ;
  39. break ;
  40. default :
  41. // It is an array in the format [ StripFilePath, IconSize, IconPosition ]
  42. this.Path = iconPathOrStripInfoArray[0] ;
  43. this.Size = iconPathOrStripInfoArray[1] ;
  44. this.Position = iconPathOrStripInfoArray[2] ;
  45. }
  46. }
  47. FCKIcon.prototype.CreateIconElement = function( document )
  48. {
  49. var eIcon, eIconImage ;
  50. if ( this.Position ) // It is using an icons strip image.
  51. {
  52. var sPos = '-' + ( ( this.Position - 1 ) * this.Size ) + 'px' ;
  53. if ( FCKBrowserInfo.IsIE )
  54. {
  55. // <div class="TB_Button_Image"><img src="strip.gif" style="top:-16px"></div>
  56. eIcon = document.createElement( 'DIV' ) ;
  57. eIconImage = eIcon.appendChild( document.createElement( 'IMG' ) ) ;
  58. eIconImage.src = this.Path ;
  59. eIconImage.style.top = sPos ;
  60. }
  61. else
  62. {
  63. // <img class="TB_Button_Image" src="spacer.gif" style="background-position: 0px -16px;background-image: url(strip.gif);">
  64. eIcon = document.createElement( 'IMG' ) ;
  65. eIcon.src = FCK_SPACER_PATH ;
  66. eIcon.style.backgroundPosition = '0px ' + sPos ;
  67. eIcon.style.backgroundImage = 'url("' + this.Path + '")' ;
  68. }
  69. }
  70. else // It is using a single icon image.
  71. {
  72. if ( FCKBrowserInfo.IsIE )
  73. {
  74. // IE makes the button 1px higher if using the <img> directly, so we
  75. // are changing to the <div> system to clip the image correctly.
  76. eIcon = document.createElement( 'DIV' ) ;
  77. eIconImage = eIcon.appendChild( document.createElement( 'IMG' ) ) ;
  78. eIconImage.src = this.Path ? this.Path : FCK_SPACER_PATH ;
  79. }
  80. else
  81. {
  82. // This is not working well with IE. See notes above.
  83. // <img class="TB_Button_Image" src="smiley.gif">
  84. eIcon = document.createElement( 'IMG' ) ;
  85. eIcon.src = this.Path ? this.Path : FCK_SPACER_PATH ;
  86. }
  87. }
  88. eIcon.className = 'TB_Button_Image' ;
  89. return eIcon ;
  90. }