fck_div.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
  2. <!--
  3. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  4. * Copyright (C) 2003-2010 Frederico Caldeira Knabben
  5. *
  6. * == BEGIN LICENSE ==
  7. *
  8. * Licensed under the terms of any of the following licenses at your
  9. * choice:
  10. *
  11. * - GNU General Public License Version 2 or later (the "GPL")
  12. * http://www.gnu.org/licenses/gpl.html
  13. *
  14. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  15. * http://www.gnu.org/licenses/lgpl.html
  16. *
  17. * - Mozilla Public License Version 1.1 or later (the "MPL")
  18. * http://www.mozilla.org/MPL/MPL-1.1.html
  19. *
  20. * == END LICENSE ==
  21. *
  22. * Form dialog window.
  23. -->
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <title></title>
  27. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  28. <meta content="noindex, nofollow" name="robots" />
  29. <script src="common/fck_dialog_common.js" type="text/javascript"></script>
  30. <script type="text/javascript">
  31. var dialog = window.parent ;
  32. var oEditor = dialog.InnerDialogLoaded() ;
  33. var FCK = oEditor.FCK ;
  34. var FCKLang = oEditor.FCKLang ;
  35. var FCKBrowserInfo = oEditor.FCKBrowserInfo ;
  36. var FCKStyles = oEditor.FCKStyles ;
  37. var FCKElementPath = oEditor.FCKElementPath ;
  38. var FCKDomRange = oEditor.FCKDomRange ;
  39. var FCKDomTools = oEditor.FCKDomTools ;
  40. var FCKDomRangeIterator = oEditor.FCKDomRangeIterator ;
  41. var FCKListsLib = oEditor.FCKListsLib ;
  42. var AlwaysCreate = dialog.Args().CustomValue ;
  43. String.prototype.IEquals = function()
  44. {
  45. var thisUpper = this.toUpperCase() ;
  46. var aArgs = arguments ;
  47. // The arguments could also be a single array.
  48. if ( aArgs.length == 1 && aArgs[0].pop )
  49. aArgs = aArgs[0] ;
  50. for ( var i = 0 ; i < aArgs.length ; i++ )
  51. {
  52. if ( thisUpper == aArgs[i].toUpperCase() )
  53. return true ;
  54. }
  55. return false ;
  56. }
  57. var CurrentContainers = [] ;
  58. if ( !AlwaysCreate )
  59. {
  60. dialog.Selection.EnsureSelection() ;
  61. CurrentContainers = FCKDomTools.GetSelectedDivContainers() ;
  62. }
  63. // Add some tabs
  64. dialog.AddTab( 'General', FCKLang.DlgDivGeneralTab );
  65. dialog.AddTab( 'Advanced', FCKLang.DlgDivAdvancedTab ) ;
  66. function AddStyleOption( styleName )
  67. {
  68. var el = GetE( 'selStyle' ) ;
  69. var opt = document.createElement( 'option' ) ;
  70. opt.text = opt.value = styleName ;
  71. if ( FCKBrowserInfo.IsIE )
  72. el.add( opt ) ;
  73. else
  74. el.add( opt, null ) ;
  75. }
  76. function OnDialogTabChange( tabCode )
  77. {
  78. ShowE( 'divGeneral', tabCode == 'General' ) ;
  79. ShowE( 'divAdvanced', tabCode == 'Advanced' ) ;
  80. dialog.SetAutoSize( true ) ;
  81. }
  82. function GetNearestAncestorDirection( node )
  83. {
  84. var dir = 'ltr' ; // HTML default.
  85. while ( ( node = node.parentNode ) )
  86. {
  87. if ( node.dir )
  88. dir = node.dir ;
  89. }
  90. return dir ;
  91. }
  92. window.onload = function()
  93. {
  94. // First of all, translate the dialog box texts
  95. oEditor.FCKLanguageManager.TranslatePage(document) ;
  96. dialog.SetOkButton( true ) ;
  97. dialog.SetAutoSize( true ) ;
  98. // Popuplate the style menu
  99. var styles = FCKStyles.GetStyles() ;
  100. var selectableStyles = {} ;
  101. for ( var i in styles )
  102. {
  103. if ( ! /^_FCK_/.test( i ) && styles[i].Element == 'div' )
  104. selectableStyles[i] = styles[i] ;
  105. }
  106. if ( CurrentContainers.length <= 1 )
  107. {
  108. var target = CurrentContainers[0] ;
  109. var match = null ;
  110. for ( var i in selectableStyles )
  111. {
  112. if ( target && styles[i].CheckElementRemovable( target, true ) )
  113. match = i ;
  114. }
  115. if ( !match )
  116. AddStyleOption( "" ) ;
  117. for ( var i in selectableStyles )
  118. AddStyleOption( i ) ;
  119. if ( match )
  120. GetE( 'selStyle' ).value = match ;
  121. // Set the value for other inputs
  122. if ( target )
  123. {
  124. GetE( 'txtClass' ).value = target.className ;
  125. GetE( 'txtId' ).value = target.id ;
  126. GetE( 'txtLang' ).value = target.lang ;
  127. GetE( 'txtInlineStyle').value = target.style.cssText ;
  128. GetE( 'txtTitle' ).value = target.title ;
  129. GetE( 'selLangDir').value = target.dir || GetNearestAncestorDirection( target ) ;
  130. }
  131. }
  132. else
  133. {
  134. GetE( 'txtId' ).disabled = true ;
  135. AddStyleOption( "" ) ;
  136. for ( var i in selectableStyles )
  137. AddStyleOption( i ) ;
  138. }
  139. }
  140. function CreateDiv()
  141. {
  142. var newBlocks = [] ;
  143. var range = new FCKDomRange( FCK.EditorWindow ) ;
  144. range.MoveToSelection() ;
  145. var bookmark = range.CreateBookmark() ;
  146. // Kludge for #1592: if the bookmark nodes are in the beginning of
  147. // $tagName, then move them to the nearest block element in the
  148. // $tagName.
  149. if ( FCKBrowserInfo.IsIE )
  150. {
  151. var bStart = range.GetBookmarkNode( bookmark, true ) ;
  152. var bEnd = range.GetBookmarkNode( bookmark, false ) ;
  153. var cursor ;
  154. if ( bStart
  155. && bStart.parentNode.nodeName.IEquals( 'div' )
  156. && !bStart.previousSibling )
  157. {
  158. cursor = bStart ;
  159. while ( ( cursor = cursor.nextSibling ) )
  160. {
  161. if ( FCKListsLib.BlockElements[ cursor.nodeName.toLowerCase() ] )
  162. FCKDomTools.MoveNode( bStart, cursor, true ) ;
  163. }
  164. }
  165. if ( bEnd
  166. && bEnd.parentNode.nodeName.IEquals( 'div' )
  167. && !bEnd.previousSibling )
  168. {
  169. cursor = bEnd ;
  170. while ( ( cursor = cursor.nextSibling ) )
  171. {
  172. if ( FCKListsLib.BlockElements[ cursor.nodeName.toLowerCase() ] )
  173. {
  174. if ( cursor.firstChild == bStart )
  175. FCKDomTools.InsertAfterNode( bStart, bEnd ) ;
  176. else
  177. FCKDomTools.MoveNode( bEnd, cursor, true ) ;
  178. }
  179. }
  180. }
  181. }
  182. var iterator = new FCKDomRangeIterator( range ) ;
  183. var block ;
  184. var paragraphs = [] ;
  185. while ( ( block = iterator.GetNextParagraph() ) )
  186. paragraphs.push( block ) ;
  187. // Make sure all paragraphs have the same parent.
  188. var commonParent = paragraphs[0].parentNode ;
  189. var tmp = [] ;
  190. for ( var i = 0 ; i < paragraphs.length ; i++ )
  191. {
  192. block = paragraphs[i] ;
  193. commonParent = FCKDomTools.GetCommonParents( block.parentNode, commonParent ).pop() ;
  194. }
  195. // The common parent must not be the following tags: table, tbody, tr, ol, ul.
  196. while ( commonParent.nodeName.IEquals( 'table', 'tbody', 'tr', 'ol', 'ul' ) )
  197. commonParent = commonParent.parentNode ;
  198. // Reconstruct the block list to be processed such that all resulting blocks
  199. // satisfy parentNode == commonParent.
  200. var lastBlock = null ;
  201. while ( paragraphs.length > 0 )
  202. {
  203. block = paragraphs.shift() ;
  204. while ( block.parentNode != commonParent )
  205. block = block.parentNode ;
  206. if ( block != lastBlock )
  207. tmp.push( block ) ;
  208. lastBlock = block ;
  209. }
  210. paragraphs = tmp ;
  211. // Split the paragraphs into groups depending on their BlockLimit element.
  212. var groups = [] ;
  213. var lastBlockLimit = null ;
  214. for ( var i = 0 ; i < paragraphs.length ; i++ )
  215. {
  216. block = paragraphs[i] ;
  217. var elementPath = new FCKElementPath( block ) ;
  218. if ( elementPath.BlockLimit != lastBlockLimit )
  219. {
  220. groups.push( [] ) ;
  221. lastBlockLimit = elementPath.BlockLimit ;
  222. }
  223. groups[groups.length - 1].push( block ) ;
  224. }
  225. // Create a DIV container for each group.
  226. for ( var i = 0 ; i < groups.length ; i++ )
  227. {
  228. var divNode = FCK.EditorDocument.createElement( 'div' ) ;
  229. groups[i][0].parentNode.insertBefore( divNode, groups[i][0] ) ;
  230. for ( var j = 0 ; j < groups[i].length ; j++ )
  231. FCKDomTools.MoveNode( groups[i][j], divNode ) ;
  232. newBlocks.push( divNode ) ;
  233. }
  234. range.MoveToBookmark( bookmark ) ;
  235. range.Select() ;
  236. FCK.Focus() ;
  237. FCK.Events.FireEvent( 'OnSelectionChange' ) ;
  238. return newBlocks ;
  239. }
  240. function Ok()
  241. {
  242. oEditor.FCKUndo.SaveUndoStep() ;
  243. if ( CurrentContainers.length < 1 )
  244. CurrentContainers = CreateDiv();
  245. var setValue = function( attrName, inputName )
  246. {
  247. var val = GetE( inputName ).value ;
  248. for ( var i = 0 ; i < CurrentContainers.length ; i++ )
  249. {
  250. if ( val == '' )
  251. CurrentContainers[i].removeAttribute( attrName ) ;
  252. else
  253. CurrentContainers[i].setAttribute( attrName, val ) ;
  254. }
  255. }
  256. // Apply modifications to the DIV container according to dialog inputs.
  257. if ( CurrentContainers.length == 1 )
  258. {
  259. setValue( 'class', 'txtClass' ) ;
  260. setValue( 'id', 'txtId' ) ;
  261. }
  262. setValue( 'lang', 'txtLang' ) ;
  263. if ( FCKBrowserInfo.IsIE )
  264. {
  265. for ( var i = 0 ; i < CurrentContainers.length ; i++ )
  266. CurrentContainers[i].style.cssText = GetE( 'txtInlineStyle' ).value ;
  267. }
  268. else
  269. setValue( 'style', 'txtInlineStyle' ) ;
  270. setValue( 'title', 'txtTitle' ) ;
  271. for ( var i = 0 ; i < CurrentContainers.length ; i++ )
  272. {
  273. var dir = GetE( 'selLangDir' ).value ;
  274. var styleName = GetE( 'selStyle' ).value ;
  275. if ( GetNearestAncestorDirection( CurrentContainers[i] ) != dir )
  276. CurrentContainers[i].dir = dir ;
  277. else
  278. CurrentContainers[i].removeAttribute( 'dir' ) ;
  279. if ( styleName )
  280. FCKStyles.GetStyle( styleName ).ApplyToObject( CurrentContainers[i] ) ;
  281. }
  282. return true ;
  283. }
  284. </script>
  285. <style type="text/css">
  286. body, td, input, textarea, select, label { font-family: Arial, Verdana, Geneva, helvetica, sans-serif; font-size: 11px; }
  287. </style>
  288. </head>
  289. <body style="overflow: hidden">
  290. <div id="divGeneral">
  291. <table cellspacing="0" cellpadding="0" width="100%" border="0">
  292. <colgroup span="2">
  293. <col width="49%" />
  294. <col width="2%" />
  295. <col width="49%" />
  296. </colgroup>
  297. <tr>
  298. <td>
  299. <span fcklang="DlgDivStyle">Style</span><br />
  300. <select id="selStyle" style="width: 100%;">
  301. </select>
  302. </td>
  303. <td>&nbsp;</td>
  304. <td>
  305. <span fcklang="DlgGenClass">Stylesheet Classes</span><br />
  306. <input id="txtClass" style="width: 100%" type="text" />
  307. </td>
  308. </tr>
  309. </table>
  310. </div>
  311. <div id="divAdvanced" style="display: none">
  312. <table cellspacing="0" cellpadding="0" width="100%" border="0">
  313. <colgroup span="2">
  314. <col width="49%" />
  315. <col width="2%" />
  316. <col width="49%" />
  317. </colgroup>
  318. <tr>
  319. <td>
  320. <span fcklang="DlgGenId">Id</span><br />
  321. <input style="width: 100%" type="text" id="txtId" />
  322. </td>
  323. <td>&nbsp;</td>
  324. <td>
  325. <span fcklang="DlgGenLangCode">Language Code</span><br />
  326. <input style="width: 100%" type="text" id="txtLang" />
  327. </td>
  328. </tr>
  329. <tr>
  330. <td colspan="3">&nbsp;</td>
  331. </tr>
  332. <tr>
  333. <td colspan="3">
  334. <span fcklang="DlgDivInlineStyle">Inline Style</span><br />
  335. <input style="width: 100%" type="text" id="txtInlineStyle" />
  336. </td>
  337. </tr>
  338. <tr>
  339. <td colspan="3">&nbsp;</td>
  340. </tr>
  341. <tr>
  342. <td colspan="3">
  343. <span fcklang="DlgGenTitle">Advisory Title</span><br />
  344. <input style="width: 100%" type="text" id="txtTitle" />
  345. </td>
  346. </tr>
  347. <tr>
  348. <td>&nbsp;</td>
  349. </tr>
  350. <tr>
  351. <td>
  352. <span fcklang="DlgGenLangDir">Language Direction</span><br />
  353. <select id="selLangDir">
  354. <option fcklang="DlgGenLangDirLtr" value="ltr">Left to Right (LTR)
  355. <option fcklang="DlgGenLangDirRtl" value="rtl">Right to Left (RTL)
  356. </select>
  357. </td>
  358. </tr>
  359. </table>
  360. </div>
  361. </body>
  362. </html>