fckspecialcombo.js
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:10k
源码类别:

OA系统

开发平台:

C#

  1. /*
  2.  * FCKeditor - The text editor for internet
  3.  * Copyright (C) 2003-2006 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: fckspecialcombo.js
  14.  *  FCKSpecialCombo Class: represents a special combo.
  15.  * 
  16.  * File Authors:
  17.  *  Frederico Caldeira Knabben (fredck@fckeditor.net)
  18.  */
  19. var FCKSpecialCombo = function( caption, fieldWidth, panelWidth, panelMaxHeight, parentWindow )
  20. {
  21. // Default properties values.
  22. this.FieldWidth = fieldWidth || 100 ;
  23. this.PanelWidth = panelWidth || 150 ;
  24. this.PanelMaxHeight = panelMaxHeight || 150 ;
  25. this.Label = ' ' ;
  26. this.Caption = caption ;
  27. this.Tooltip = caption ;
  28. this.Style = FCK_TOOLBARITEM_ICONTEXT ;
  29. this.Enabled = true ;
  30. this.Items = new Object() ;
  31. this._Panel = new FCKPanel( parentWindow || window, true ) ;
  32. this._Panel.AppendStyleSheet( FCKConfig.SkinPath + 'fck_editor.css' ) ;
  33. this._PanelBox = this._Panel.MainNode.appendChild( this._Panel.Document.createElement( 'DIV' ) ) ;
  34. this._PanelBox.className = 'SC_Panel' ;
  35. this._PanelBox.style.width = this.PanelWidth + 'px' ;
  36. this._PanelBox.innerHTML = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT: fixed"><tr><td nowrap></td></tr></table>' ;
  37. this._ItemsHolderEl = this._PanelBox.getElementsByTagName('TD')[0] ;
  38. if ( FCK.IECleanup )
  39. FCK.IECleanup.AddItem( this, FCKSpecialCombo_Cleanup ) ;
  40. // this._Panel.StyleSheet = FCKConfig.SkinPath + 'fck_contextmenu.css' ;
  41. // this._Panel.Create() ;
  42. // this._Panel.PanelDiv.className += ' SC_Panel' ;
  43. // this._Panel.PanelDiv.innerHTML = '<table cellpadding="0" cellspacing="0" width="100%" style="TABLE-LAYOUT: fixed"><tr><td nowrap></td></tr></table>' ;
  44. // this._ItemsHolderEl = this._Panel.PanelDiv.getElementsByTagName('TD')[0] ;
  45. }
  46. function FCKSpecialCombo_ItemOnMouseOver()
  47. {
  48. this.className += ' SC_ItemOver' ;
  49. }
  50. function FCKSpecialCombo_ItemOnMouseOut()
  51. {
  52. this.className = this.originalClass ;
  53. }
  54. function FCKSpecialCombo_ItemOnClick()
  55. {
  56. this.className = this.originalClass ;
  57. this.FCKSpecialCombo._Panel.Hide() ;
  58. this.FCKSpecialCombo.SetLabel( this.FCKItemLabel ) ;
  59. if ( typeof( this.FCKSpecialCombo.OnSelect ) == 'function' )
  60. this.FCKSpecialCombo.OnSelect( this.FCKItemID, this ) ;
  61. }
  62. FCKSpecialCombo.prototype.AddItem = function( id, html, label, bgColor )
  63. {
  64. // <div class="SC_Item" onmouseover="this.className='SC_Item SC_ItemOver';" onmouseout="this.className='SC_Item';"><b>Bold 1</b></div>
  65. var oDiv = this._ItemsHolderEl.appendChild( this._Panel.Document.createElement( 'DIV' ) ) ;
  66. oDiv.className = oDiv.originalClass = 'SC_Item' ;
  67. oDiv.innerHTML = html ;
  68. oDiv.FCKItemID = id ;
  69. oDiv.FCKItemLabel = label || id ;
  70. oDiv.FCKSpecialCombo = this ;
  71. oDiv.Selected = false ;
  72. // In IE, the width must be set so the borders are shown correctly when the content overflows.
  73. if ( FCKBrowserInfo.IsIE )
  74. oDiv.style.width = '100%' ;
  75. if ( bgColor )
  76. oDiv.style.backgroundColor = bgColor ;
  77. oDiv.onmouseover = FCKSpecialCombo_ItemOnMouseOver ;
  78. oDiv.onmouseout = FCKSpecialCombo_ItemOnMouseOut ;
  79. oDiv.onclick = FCKSpecialCombo_ItemOnClick ;
  80. this.Items[ id.toString().toLowerCase() ] = oDiv ;
  81. return oDiv ;
  82. }
  83. FCKSpecialCombo.prototype.SelectItem = function( itemId )
  84. {
  85. itemId = itemId ? itemId.toString().toLowerCase() : '' ;
  86. var oDiv = this.Items[ itemId ] ;
  87. if ( oDiv )
  88. {
  89. oDiv.className = oDiv.originalClass = 'SC_ItemSelected' ;
  90. oDiv.Selected = true ;
  91. }
  92. }
  93. FCKSpecialCombo.prototype.SelectItemByLabel = function( itemLabel, setLabel )
  94. {
  95. for ( var id in this.Items )
  96. {
  97. var oDiv = this.Items[id] ;
  98. if ( oDiv.FCKItemLabel == itemLabel )
  99. {
  100. oDiv.className = oDiv.originalClass = 'SC_ItemSelected' ;
  101. oDiv.Selected = true ;
  102. if ( setLabel )
  103. this.SetLabel( itemLabel ) ;
  104. }
  105. }
  106. }
  107. FCKSpecialCombo.prototype.DeselectAll = function( clearLabel )
  108. {
  109. for ( var i in this.Items )
  110. {
  111. this.Items[i].className = this.Items[i].originalClass = 'SC_Item' ;
  112. this.Items[i].Selected = false ;
  113. }
  114. if ( clearLabel )
  115. this.SetLabel( '' ) ;
  116. }
  117. FCKSpecialCombo.prototype.SetLabelById = function( id )
  118. {
  119. id = id ? id.toString().toLowerCase() : '' ;
  120. var oDiv = this.Items[ id ] ;
  121. this.SetLabel( oDiv ? oDiv.FCKItemLabel : '' ) ;
  122. }
  123. FCKSpecialCombo.prototype.SetLabel = function( text )
  124. {
  125. this.Label = text.length == 0 ? '&nbsp;' : text ;
  126. if ( this._LabelEl )
  127. this._LabelEl.innerHTML = this.Label ;
  128. }
  129. FCKSpecialCombo.prototype.SetEnabled = function( isEnabled )
  130. {
  131. this.Enabled = isEnabled ;
  132. this._OuterTable.className = isEnabled ? '' : 'SC_FieldDisabled' ;
  133. }
  134. FCKSpecialCombo.prototype.Create = function( targetElement )
  135. {
  136. var oDoc = FCKTools.GetElementDocument( targetElement ) ;
  137. var eOuterTable = this._OuterTable = targetElement.appendChild( oDoc.createElement( 'TABLE' ) ) ;
  138. eOuterTable.cellPadding = 0 ;
  139. eOuterTable.cellSpacing = 0 ;
  140. eOuterTable.insertRow(-1) ;
  141. var sClass ;
  142. var bShowLabel ;
  143. switch ( this.Style )
  144. {
  145. case FCK_TOOLBARITEM_ONLYICON :
  146. sClass = 'TB_ButtonType_Icon' ;
  147. bShowLabel = false;
  148. break ;
  149. case FCK_TOOLBARITEM_ONLYTEXT :
  150. sClass = 'TB_ButtonType_Text' ;
  151. bShowLabel = false;
  152. break ;
  153. case FCK_TOOLBARITEM_ICONTEXT :
  154. bShowLabel = true;
  155. break ;
  156. }
  157. if ( this.Caption && this.Caption.length > 0 && bShowLabel )
  158. {
  159. var oCaptionCell = eOuterTable.rows[0].insertCell(-1) ;
  160. oCaptionCell.innerHTML = this.Caption ;
  161. oCaptionCell.className = 'SC_FieldCaption' ;
  162. }
  163. // Create the main DIV element.
  164. var oField = FCKTools.AppendElement( eOuterTable.rows[0].insertCell(-1), 'div' ) ;
  165. if ( bShowLabel )
  166. {
  167. oField.className = 'SC_Field' ;
  168. oField.style.width = this.FieldWidth + 'px' ;
  169. oField.innerHTML = '<table width="100%" cellpadding="0" cellspacing="0" style="TABLE-LAYOUT: fixed;"><tbody><tr><td class="SC_FieldLabel"><label>&nbsp;</label></td><td class="SC_FieldButton">&nbsp;</td></tr></tbody></table>' ;
  170. this._LabelEl = oField.getElementsByTagName('label')[0] ; // Memory Leak
  171. this._LabelEl.innerHTML = this.Label ;
  172. }
  173. else
  174. {
  175. oField.className = 'TB_Button_Off' ;
  176. //oField.innerHTML = '<span className="SC_FieldCaption">' + this.Caption + '<table cellpadding="0" cellspacing="0" style="TABLE-LAYOUT: fixed;"><tbody><tr><td class="SC_FieldButton" style="border-left: none;">&nbsp;</td></tr></tbody></table>' ;
  177. //oField.innerHTML = '<table cellpadding="0" cellspacing="0" style="TABLE-LAYOUT: fixed;"><tbody><tr><td class="SC_FieldButton" style="border-left: none;">&nbsp;</td></tr></tbody></table>' ;
  178. // Gets the correct CSS class to use for the specified style (param).
  179. oField.innerHTML = '<table title="' + this.Tooltip + '" class="' + sClass + '" cellspacing="0" cellpadding="0" border="0">' +
  180. '<tr>' +
  181. //'<td class="TB_Icon"><img src="' + FCKConfig.SkinPath + 'toolbar/' + this.Command.Name.toLowerCase() + '.gif" width="21" height="21"></td>' +
  182. '<td><img class="TB_Button_Padding" src="' + FCK_SPACER_PATH + '" /></td>' +
  183. '<td class="TB_Text">' + this.Caption + '</td>' +
  184. '<td><img class="TB_Button_Padding" src="' + FCK_SPACER_PATH + '" /></td>' +
  185. '<td class="TB_ButtonArrow"><img src="' + FCKConfig.SkinPath + 'images/toolbar.buttonarrow.gif" width="5" height="3"></td>' +
  186. '<td><img class="TB_Button_Padding" src="' + FCK_SPACER_PATH + '" /></td>' +
  187. '</tr>' +
  188. '</table>' ;
  189. }
  190. // Events Handlers
  191. oField.SpecialCombo = this ;
  192. oField.onmouseover = FCKSpecialCombo_OnMouseOver ;
  193. oField.onmouseout = FCKSpecialCombo_OnMouseOut ;
  194. oField.onclick = FCKSpecialCombo_OnClick ;
  195. FCKTools.DisableSelection( this._Panel.Document.body ) ;
  196. }
  197. function FCKSpecialCombo_Cleanup()
  198. {
  199. this._LabelEl = null ;
  200. this._OuterTable = null ;
  201. this._ItemsHolderEl = null ;
  202. this._PanelBox = null ;
  203. if ( this.Items )
  204. {
  205. for ( var key in this.Items )
  206. this.Items[key] = null ;
  207. }
  208. }
  209. function FCKSpecialCombo_OnMouseOver()
  210. {
  211. if ( this.SpecialCombo.Enabled )
  212. {
  213. switch ( this.SpecialCombo.Style )
  214. {
  215. case FCK_TOOLBARITEM_ONLYICON :
  216. this.className = 'TB_Button_On_Over';
  217. break ;
  218. case FCK_TOOLBARITEM_ONLYTEXT :
  219. this.className = 'TB_Button_On_Over';
  220. break ;
  221. case FCK_TOOLBARITEM_ICONTEXT :
  222. this.className = 'SC_Field SC_FieldOver' ;
  223. break ;
  224. }
  225. }
  226. }
  227. function FCKSpecialCombo_OnMouseOut()
  228. {
  229. switch ( this.SpecialCombo.Style )
  230. {
  231. case FCK_TOOLBARITEM_ONLYICON :
  232. this.className = 'TB_Button_Off';
  233. break ;
  234. case FCK_TOOLBARITEM_ONLYTEXT :
  235. this.className = 'TB_Button_Off';
  236. break ;
  237. case FCK_TOOLBARITEM_ICONTEXT :
  238. this.className='SC_Field' ;
  239. break ;
  240. }
  241. }
  242. function FCKSpecialCombo_OnClick( e )
  243. {
  244. // For Mozilla we must stop the event propagation to avoid it hiding 
  245. // the panel because of a click outside of it.
  246. // if ( e )
  247. // {
  248. // e.stopPropagation() ;
  249. // FCKPanelEventHandlers.OnDocumentClick( e ) ;
  250. // }
  251. var oSpecialCombo = this.SpecialCombo ;
  252. if ( oSpecialCombo.Enabled )
  253. {
  254. var oPanel = oSpecialCombo._Panel ;
  255. var oPanelBox = oSpecialCombo._PanelBox ;
  256. var oItemsHolder = oSpecialCombo._ItemsHolderEl ;
  257. var iMaxHeight = oSpecialCombo.PanelMaxHeight ;
  258. if ( oSpecialCombo.OnBeforeClick )
  259. oSpecialCombo.OnBeforeClick( oSpecialCombo ) ;
  260. // This is a tricky thing. We must call the "Load" function, otherwise
  261. // it will not be possible to retrieve "oItemsHolder.offsetHeight" (IE only).
  262. if ( FCKBrowserInfo.IsIE )
  263. oPanel.Preload( 0, this.offsetHeight, this ) ;
  264. if ( oItemsHolder.offsetHeight > iMaxHeight )
  265. // {
  266. oPanelBox.style.height = iMaxHeight + 'px' ;
  267. // if ( FCKBrowserInfo.IsGecko )
  268. // oPanelBox.style.overflow = '-moz-scrollbars-vertical' ;
  269. // }
  270. else
  271. oPanelBox.style.height = '' ;
  272. // oPanel.PanelDiv.style.width = oSpecialCombo.PanelWidth + 'px' ;
  273. oPanel.Show( 0, this.offsetHeight, this ) ;
  274. }
  275. // return false ;
  276. }
  277. /* 
  278. Sample Combo Field HTML output:
  279. <div class="SC_Field" style="width: 80px;">
  280. <table width="100%" cellpadding="0" cellspacing="0" style="table-layout: fixed;">
  281. <tbody>
  282. <tr>
  283. <td class="SC_FieldLabel"><label>&nbsp;</label></td>
  284. <td class="SC_FieldButton">&nbsp;</td>
  285. </tr>
  286. </tbody>
  287. </table>
  288. </div>
  289. */