fckadobeair.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  3. * Copyright (C) 2003-2010 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. * Compatibility code for Adobe AIR.
  22. */
  23. if ( FCKBrowserInfo.IsAIR )
  24. {
  25. var FCKAdobeAIR = (function()
  26. {
  27. /*
  28. * ### Private functions.
  29. */
  30. var getDocumentHead = function( doc )
  31. {
  32. var head ;
  33. var heads = doc.getElementsByTagName( 'head' ) ;
  34. if( heads && heads[0] )
  35. head = heads[0] ;
  36. else
  37. {
  38. head = doc.createElement( 'head' ) ;
  39. doc.documentElement.insertBefore( head, doc.documentElement.firstChild ) ;
  40. }
  41. return head ;
  42. } ;
  43. /*
  44. * ### Public interface.
  45. */
  46. return {
  47. FCKeditorAPI_Evaluate : function( parentWindow, script )
  48. {
  49. // TODO : This one doesn't work always. The parent window will
  50. // point to an anonymous function in this window. If this
  51. // window is destroyied the parent window will be pointing to
  52. // an invalid reference.
  53. // Evaluate the script in this window.
  54. eval( script ) ;
  55. // Point the FCKeditorAPI property of the parent window to the
  56. // local reference.
  57. parentWindow.FCKeditorAPI = window.FCKeditorAPI ;
  58. },
  59. EditingArea_Start : function( doc, html )
  60. {
  61. // Get the HTML for the <head>.
  62. var headInnerHtml = html.match( /<head>([\s\S]*)<\/head>/i )[1] ;
  63. if ( headInnerHtml && headInnerHtml.length > 0 )
  64. {
  65. // Inject the <head> HTML inside a <div>.
  66. // Do that before getDocumentHead because WebKit moves
  67. // <link css> elements to the <head> at this point.
  68. var div = doc.createElement( 'div' ) ;
  69. div.innerHTML = headInnerHtml ;
  70. // Move the <div> nodes to <head>.
  71. FCKDomTools.MoveChildren( div, getDocumentHead( doc ) ) ;
  72. }
  73. doc.body.innerHTML = html.match( /<body>([\s\S]*)<\/body>/i )[1] ;
  74. //prevent clicking on hyperlinks and navigating away
  75. doc.addEventListener('click', function( ev )
  76. {
  77. ev.preventDefault() ;
  78. ev.stopPropagation() ;
  79. }, true ) ;
  80. },
  81. Panel_Contructor : function( doc, baseLocation )
  82. {
  83. var head = getDocumentHead( doc ) ;
  84. // Set the <base> href.
  85. head.appendChild( doc.createElement('base') ).href = baseLocation ;
  86. doc.body.style.margin = '0px' ;
  87. doc.body.style.padding = '0px' ;
  88. },
  89. ToolbarSet_GetOutElement : function( win, outMatch )
  90. {
  91. var toolbarTarget = win.parent ;
  92. var targetWindowParts = outMatch[1].split( '.' ) ;
  93. while ( targetWindowParts.length > 0 )
  94. {
  95. var part = targetWindowParts.shift() ;
  96. if ( part.length > 0 )
  97. toolbarTarget = toolbarTarget[ part ] ;
  98. }
  99. toolbarTarget = toolbarTarget.document.getElementById( outMatch[2] ) ;
  100. },
  101. ToolbarSet_InitOutFrame : function( doc )
  102. {
  103. var head = getDocumentHead( doc ) ;
  104. head.appendChild( doc.createElement('base') ).href = window.document.location ;
  105. var targetWindow = doc.defaultView;
  106. targetWindow.adjust = function()
  107. {
  108. targetWindow.frameElement.height = doc.body.scrollHeight;
  109. } ;
  110. targetWindow.onresize = targetWindow.adjust ;
  111. targetWindow.setTimeout( targetWindow.adjust, 0 ) ;
  112. doc.body.style.overflow = 'hidden';
  113. doc.body.innerHTML = document.getElementById( 'xToolbarSpace' ).innerHTML ;
  114. }
  115. } ;
  116. })();
  117. /*
  118. * ### Overrides
  119. */
  120. ( function()
  121. {
  122. // Save references for override reuse.
  123. var _Original_FCKPanel_Window_OnFocus = FCKPanel_Window_OnFocus ;
  124. var _Original_FCKPanel_Window_OnBlur = FCKPanel_Window_OnBlur ;
  125. var _Original_FCK_StartEditor = FCK.StartEditor ;
  126. FCKPanel_Window_OnFocus = function( e, panel )
  127. {
  128. // Call the original implementation.
  129. _Original_FCKPanel_Window_OnFocus.call( this, e, panel ) ;
  130. if ( panel._focusTimer )
  131. clearTimeout( panel._focusTimer ) ;
  132. }
  133. FCKPanel_Window_OnBlur = function( e, panel )
  134. {
  135. // Delay the execution of the original function.
  136. panel._focusTimer = FCKTools.SetTimeout( _Original_FCKPanel_Window_OnBlur, 100, this, [ e, panel ] ) ;
  137. }
  138. FCK.StartEditor = function()
  139. {
  140. // Force pointing to the CSS files instead of using the inline CSS cached styles.
  141. window.FCK_InternalCSS = FCKConfig.BasePath + 'css/fck_internal.css' ;
  142. window.FCK_ShowTableBordersCSS = FCKConfig.BasePath + 'css/fck_showtableborders_gecko.css' ;
  143. _Original_FCK_StartEditor.apply( this, arguments ) ;
  144. }
  145. })();
  146. }