fckplugin.js 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  1. /*
  2. * This piece of software has been created for Chamilo LMS
  3. * Mail: info@chamilo.org
  4. *
  5. * Copyright (c) 2008-2010 Ivan Tcholakov <ivantcholakov@gmail.com>
  6. * Copyright (c) 2008-2009 Julio Montoya Armas <gugli100@gmail.com>
  7. *
  8. * For a full list of contributors detaining copyrights over parts of
  9. * the Chamilo software, see "documentation/credits.html".
  10. * The full license can be read in "documentation/license.html".
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License version 3
  14. * as published by the Free Software Foundation.
  15. *
  16. * See the GNU General Public License for more details.
  17. */
  18. /*
  19. * This plugin uses also fragments of the original source code of
  20. * FCKeditor version 2.6.4.
  21. *
  22. * FCKeditor - The text editor for Internet - http://www.fckeditor.net
  23. * Copyright (C) 2003-2009 Frederico Caldeira Knabben
  24. *
  25. * == BEGIN LICENSE ==
  26. *
  27. * Licensed under the terms of any of the following licenses at your
  28. * choice:
  29. *
  30. * - GNU General Public License Version 2 or later (the "GPL")
  31. * http://www.gnu.org/licenses/gpl.html
  32. *
  33. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  34. * http://www.gnu.org/licenses/lgpl.html
  35. *
  36. * - Mozilla Public License Version 1.1 or later (the "MPL")
  37. * http://www.mozilla.org/MPL/MPL-1.1.html
  38. *
  39. * == END LICENSE ==
  40. */
  41. /*
  42. **************************************************************************************
  43. * Validation and initialization of configuration data.
  44. **************************************************************************************
  45. */
  46. // Data about available toolbar sets should be unserialized when it comes from php-side.
  47. if ( typeof FCKConfig.ToolbarSets == 'string' || FCKConfig.ToolbarSets instanceof ( String ) )
  48. {
  49. FCKConfig.ToolbarSets = eval( '(' + FCKConfig.ToolbarSets + ')' ) ;
  50. }
  51. // Reading a setting which tells whether simple or advanced file manager is to be used.
  52. FCKConfig.AdvancedFileManager = null ;
  53. if ( FCKConfig.AdvancedFileManager )
  54. {
  55. FCKConfig.AdvancedFileManager = FCKConfig.AdvancedFileManager.toString().toLowerCase() == 'true' ? true : false ;
  56. }
  57. else
  58. {
  59. // If this setting has been omited, let us try to detect it indirectly.
  60. FCKConfig.AdvancedFileManager = false ;
  61. if ( ( FCKConfig.ImageBrowserURL && FCKConfig.ImageBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 )
  62. || ( FCKConfig.FlashBrowserURL && FCKConfig.FlashBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 )
  63. || ( FCKConfig.MP3BrowserURL && FCKConfig.MP3BrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 )
  64. || ( FCKConfig.VideoBrowserURL && FCKConfig.VideoBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 )
  65. || ( FCKConfig.LinkBrowserURL && FCKConfig.LinkBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 )
  66. || ( FCKConfig.MediaBrowserURL && FCKConfig.MediaBrowserURL.toString().indexOf( 'ajaxfilemanager' ) != -1 ) )
  67. {
  68. FCKConfig.AdvancedFileManager = true ;
  69. }
  70. }
  71. // A flag to see whether a course documents repository is to be used.
  72. if ( FCKConfig.InDocument )
  73. {
  74. FCKConfig.InDocument = FCKConfig.InDocument.toString().toLowerCase() == 'true' ? true : false ;
  75. }
  76. else
  77. {
  78. FCKConfig.InDocument = false ;
  79. }
  80. // Absolute URL to document repository root.
  81. if ( !FCKConfig.CreateDocumentWebDir )
  82. {
  83. FCKConfig.CreateDocumentWebDir = '' ;
  84. }
  85. // Relative path from the document to the repository root.
  86. if ( !FCKConfig.CreateDocumentDir )
  87. {
  88. FCKConfig.CreateDocumentDir = '' ;
  89. }
  90. // This is the base of the reltive URLs that are used by the dialog system.
  91. if ( !FCKConfig.BaseHref || FCKConfig.BaseHref.toString().length == 0 )
  92. {
  93. if ( FCKConfig.BaseHref.toString().length == 0 )
  94. {
  95. FCKConfig.BaseHref = FCKConfig.CreateDocumentWebDir ;
  96. }
  97. }
  98. if ( !FCKConfig.BaseHref )
  99. {
  100. if ( typeof ( FCKConfig.BaseHref ) != 'string' )
  101. {
  102. FCKConfig.BaseHref = FCKConfig.CreateDocumentWebDir ;
  103. }
  104. }
  105. FCKConfig.BaseHref = FCKConfig.BaseHref.toString();
  106. if ( FCKConfig.BaseHref.length > 0 )
  107. {
  108. if ( FCKConfig.BaseHref.substr( FCKConfig.BaseHref.length - 1 ) != '/' )
  109. {
  110. FCKConfig.BaseHref = FCKConfig.BaseHref + '/' ;
  111. }
  112. }
  113. // The icon for the image properties button/command.
  114. if ( !FCKConfig.ImagesIcon )
  115. {
  116. // This is the original icon from a chosen skin.
  117. //FCKConfig.ImagesIcon = 37 ;
  118. // We will use a better icon by default.
  119. FCKConfig.ImagesIcon = FCKConfig.PluginsPath + 'customizations/images/images_icon.gif' ;
  120. }
  121. /*
  122. **************************************************************************************
  123. * Plugins.
  124. **************************************************************************************
  125. */
  126. // Checks whether a specified plugin has been loaded.
  127. FCK.Plugins.IsLoaded = function( name )
  128. {
  129. if ( name )
  130. {
  131. for ( var i = 0 ; i < FCKConfig.Plugins.Items.length ; i++ )
  132. {
  133. if ( FCKConfig.Plugins.Items[i][0] == name )
  134. {
  135. return true ;
  136. }
  137. }
  138. }
  139. return false ;
  140. }
  141. /*
  142. **************************************************************************************
  143. * Customizations by Julio Montoya for enabling the external template selection dialog.
  144. * December, 2008
  145. **************************************************************************************
  146. */
  147. FCKToolbarButton.prototype.ClickFrame = function()
  148. {
  149. var A = this._ToolbarButton || this;
  150. return FCK.ToolbarSet.CurrentInstance.Commands.GetCommand(A.CommandName).ExecuteFrame() ;
  151. };
  152. FCKDialogCommand.prototype.ExecuteFrame = function()
  153. {
  154. return FCKDialog.OpenDialogFrame( 'FCKDialog_' + this.Name, this.Title, this.Url, this.Width, this.Height, this.CustomValue, this.Resizable ) ;
  155. };
  156. var FCKDialog = ( function()
  157. {
  158. var topDialog ;
  159. var baseZIndex ;
  160. var cover ;
  161. // The document that holds the dialog.
  162. var topWindow = window.parent ;
  163. while ( topWindow.parent && topWindow.parent != topWindow )
  164. {
  165. try
  166. {
  167. if ( topWindow.parent.document.domain != document.domain )
  168. break ;
  169. if ( topWindow.parent.document.getElementsByTagName( 'frameset' ).length > 0 )
  170. break ;
  171. }
  172. catch ( e )
  173. {
  174. break ;
  175. }
  176. topWindow = topWindow.parent ;
  177. }
  178. var topDocument = topWindow.document ;
  179. var getZIndex = function()
  180. {
  181. if ( !baseZIndex )
  182. baseZIndex = FCKConfig.FloatingPanelsZIndex + 999 ;
  183. return ++baseZIndex ;
  184. }
  185. // TODO : This logic is not actually working when reducing the window, only
  186. // when enlarging it.
  187. var resizeHandler = function()
  188. {
  189. if ( !cover )
  190. return ;
  191. var relElement = FCKTools.IsStrictMode( topDocument ) ? topDocument.documentElement : topDocument.body ;
  192. FCKDomTools.SetElementStyles( cover,
  193. {
  194. 'width' : Math.max( relElement.scrollWidth,
  195. relElement.clientWidth,
  196. topDocument.scrollWidth || 0 ) - 1 + 'px',
  197. 'height' : Math.max( relElement.scrollHeight,
  198. relElement.clientHeight,
  199. topDocument.scrollHeight || 0 ) - 1 + 'px'
  200. } ) ;
  201. }
  202. return {
  203. /**
  204. * Opens a dialog window using the standard dialog template.
  205. */
  206. OpenDialog : function( dialogName, dialogTitle, dialogPage, width, height, customValue, resizable )
  207. {
  208. if ( !topDialog )
  209. this.DisplayMainCover() ;
  210. // Setup the dialog info to be passed to the dialog.
  211. var dialogInfo =
  212. {
  213. Title : dialogTitle,
  214. Page : dialogPage,
  215. Editor : window,
  216. CustomValue : customValue, // Optional
  217. TopWindow : topWindow
  218. }
  219. FCK.ToolbarSet.CurrentInstance.Selection.Save( true ) ;
  220. // Calculate the dialog position, centering it on the screen.
  221. var viewSize = FCKTools.GetViewPaneSize( topWindow ) ;
  222. var scrollPosition = { 'X' : 0, 'Y' : 0 } ;
  223. var useAbsolutePosition = FCKBrowserInfo.IsIE && ( !FCKBrowserInfo.IsIE7 || !FCKTools.IsStrictMode( topWindow.document ) ) ;
  224. if ( useAbsolutePosition )
  225. scrollPosition = FCKTools.GetScrollPosition( topWindow ) ;
  226. var iTop = Math.max( scrollPosition.Y + ( viewSize.Height - height - 20 ) / 2, 0 ) ;
  227. var iLeft = Math.max( scrollPosition.X + ( viewSize.Width - width - 20 ) / 2, 0 ) ;
  228. // Setup the IFRAME that will hold the dialog.
  229. var dialog = topDocument.createElement( 'iframe' ) ;
  230. FCKTools.ResetStyles( dialog ) ;
  231. dialog.src = FCKConfig.BasePath + 'fckdialog.html' ;
  232. // Dummy URL for testing whether the code in fckdialog.js alone leaks memory.
  233. // dialog.src = 'about:blank';
  234. dialog.frameBorder = 0 ;
  235. dialog.allowTransparency = true ;
  236. FCKDomTools.SetElementStyles( dialog,
  237. {
  238. 'position' : ( useAbsolutePosition ) ? 'absolute' : 'fixed',
  239. 'top' : iTop + 'px',
  240. 'left' : iLeft + 'px',
  241. 'width' : width + 'px',
  242. 'height' : height + 'px',
  243. 'zIndex' : getZIndex()
  244. } ) ;
  245. // Save the dialog info to be used by the dialog page once loaded.
  246. dialog._DialogArguments = dialogInfo ;
  247. // Append the IFRAME to the target document.
  248. topDocument.body.appendChild( dialog ) ;
  249. // Keep record of the dialog's parent/child relationships.
  250. dialog._ParentDialog = topDialog ;
  251. topDialog = dialog ;
  252. },
  253. /*
  254. * Added by Julio Montoya for enabling the external template selection dialog.
  255. ***************************************************************************************
  256. */
  257. OpenDialogFrame: function( dialogName, dialogTitle, dialogPage, width, height, customValue, resizable )
  258. {
  259. //if ( !topDialog )
  260. // this.DisplayMainCover() ;
  261. var dialogInfo =
  262. {
  263. Title: dialogTitle,
  264. Page: dialogPage,
  265. Editor: window,
  266. CustomValue: customValue,
  267. TopWindow : topWindow
  268. } ;
  269. // Disabled by Ivan Tcholakov, 09-JUL-2010.
  270. // Makes a problem on IE (see task #541).
  271. //FCK.ToolbarSet.CurrentInstance.Selection.Save();
  272. //FCK.ToolbarSet.CurrentInstance.Selection.Save( true ) ;
  273. //
  274. var viewSize = FCKTools.GetViewPaneSize( topWindow ) ;
  275. var scrollPosition = { 'X': 0, 'Y': 0 } ;
  276. var useAbsolutePosition = FCKBrowserInfo.IsIE && ( !FCKBrowserInfo.IsIE7 || !FCKTools.IsStrictMode( topWindow.document ) ) ;
  277. if (useAbsolutePosition) scrollPosition = FCKTools.GetScrollPosition( topWindow ) ;
  278. var iTop = Math.max(scrollPosition.Y + ( viewSize.Height - height - 20 ) / 2, 0 ) ;
  279. var iLeft = Math.max(scrollPosition.X + ( viewSize.Width - width - 20 ) / 2, 0 ) ;
  280. var dialog = topDocument.createElement( 'iframe' ) ;
  281. //FCKTools.ResetStyles( dialog );
  282. dialog.src = FCKConfig.BasePath + 'fckdialogframe.html' ;
  283. dialog.frameBorder = 0 ;
  284. dialog.allowTransparency = true ;
  285. FCKDomTools.SetElementStyles(dialog,
  286. {
  287. 'position' : (useAbsolutePosition) ? 'absolute' : 'fixed',
  288. 'top' : iTop + 'px',
  289. 'left' : iLeft + 'px',
  290. 'width' : width + 'px',
  291. 'height' : height + 'px',
  292. 'zIndex' : getZIndex()
  293. }) ;
  294. dialog._DialogArguments = dialogInfo ;
  295. //E.body.appendChild( dialog ) ;
  296. // Removed by Ivan Tcholakov.
  297. // These statements are not relevant to the case, also they cause errors.
  298. //dialog._ParentDialog = topDialog ;
  299. //topDialog = dialog ;
  300. return dialogInfo ;
  301. },
  302. /*
  303. ***************************************************************************************
  304. */
  305. /**
  306. * (For internal use)
  307. * Called when the top dialog is closed.
  308. */
  309. OnDialogClose : function( dialogWindow )
  310. {
  311. var dialog = dialogWindow.frameElement ;
  312. FCKDomTools.RemoveNode( dialog ) ;
  313. if ( dialog._ParentDialog ) // Nested Dialog.
  314. {
  315. topDialog = dialog._ParentDialog ;
  316. // Modified by Ivan Tcholakov, caused errors during tests.
  317. //dialog._ParentDialog.contentWindow.SetEnabled( true ) ;
  318. try
  319. {
  320. dialog._ParentDialog.contentWindow.SetEnabled( true ) ;
  321. }
  322. catch ( ex ) { }
  323. //
  324. }
  325. else // First Dialog.
  326. {
  327. // Set the Focus in the browser, so the "OnBlur" event is not
  328. // fired. In IE, there is no need to do that because the dialog
  329. // already moved the selection to the editing area before
  330. // closing (EnsureSelection). Also, the Focus() call here
  331. // causes memory leak on IE7 (weird).
  332. if ( !FCKBrowserInfo.IsIE )
  333. FCK.Focus() ;
  334. this.HideMainCover() ;
  335. // Bug #1918: Assigning topDialog = null directly causes IE6 to crash.
  336. setTimeout( function(){ topDialog = null ; }, 0 ) ;
  337. // Release the previously saved selection.
  338. FCK.ToolbarSet.CurrentInstance.Selection.Release() ;
  339. }
  340. },
  341. DisplayMainCover : function()
  342. {
  343. // Setup the DIV that will be used to cover.
  344. cover = topDocument.createElement( 'div' ) ;
  345. FCKTools.ResetStyles( cover ) ;
  346. FCKDomTools.SetElementStyles( cover,
  347. {
  348. 'position' : 'absolute',
  349. 'zIndex' : getZIndex(),
  350. 'top' : '0px',
  351. 'left' : '0px',
  352. 'backgroundColor' : FCKConfig.BackgroundBlockerColor
  353. } ) ;
  354. FCKDomTools.SetOpacity( cover, FCKConfig.BackgroundBlockerOpacity ) ;
  355. // For IE6-, we need to fill the cover with a transparent IFRAME,
  356. // to properly block <select> fields.
  357. if ( FCKBrowserInfo.IsIE && !FCKBrowserInfo.IsIE7 )
  358. {
  359. var iframe = topDocument.createElement( 'iframe' ) ;
  360. FCKTools.ResetStyles( iframe ) ;
  361. iframe.hideFocus = true ;
  362. iframe.frameBorder = 0 ;
  363. iframe.src = FCKTools.GetVoidUrl() ;
  364. FCKDomTools.SetElementStyles( iframe,
  365. {
  366. 'width' : '100%',
  367. 'height' : '100%',
  368. 'position' : 'absolute',
  369. 'left' : '0px',
  370. 'top' : '0px',
  371. 'filter' : 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'
  372. } ) ;
  373. cover.appendChild( iframe ) ;
  374. }
  375. // We need to manually adjust the cover size on resize.
  376. FCKTools.AddEventListener( topWindow, 'resize', resizeHandler ) ;
  377. resizeHandler() ;
  378. topDocument.body.appendChild( cover ) ;
  379. FCKFocusManager.Lock() ;
  380. // Prevent the user from refocusing the disabled
  381. // editing window by pressing Tab. (Bug #2065)
  382. var el = FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'frameElement' ) ;
  383. el._fck_originalTabIndex = el.tabIndex ;
  384. el.tabIndex = -1 ;
  385. },
  386. HideMainCover : function()
  387. {
  388. FCKDomTools.RemoveNode( cover ) ;
  389. FCKFocusManager.Unlock() ;
  390. // Revert the tab index hack. (Bug #2065)
  391. var el = FCK.ToolbarSet.CurrentInstance.GetInstanceObject( 'frameElement' ) ;
  392. el.tabIndex = el._fck_originalTabIndex ;
  393. FCKDomTools.ClearElementJSProperty( el, '_fck_originalTabIndex' ) ;
  394. },
  395. GetCover : function()
  396. {
  397. return cover ;
  398. }
  399. } ;
  400. } )() ;
  401. /*
  402. **************************************************************************************
  403. * Blocking copy/pase feature.
  404. **************************************************************************************
  405. */
  406. FCK.BlockCopyPasteKeystrokes = function()
  407. {
  408. var Keystrokes = [] ;
  409. for ( var i = 0 ; i < FCKConfig.Keystrokes.length ; i++ )
  410. {
  411. switch ( FCKConfig.Keystrokes[i][0] )
  412. {
  413. case CTRL + 67 : // Ctrl + C, 'Copy'
  414. case CTRL + 86 : // Ctrl + V, 'Paste'
  415. case CTRL + 88 : // Ctrl + X, 'Cut'
  416. break ;
  417. default :
  418. Keystrokes.push( FCKConfig.Keystrokes[i] ) ;
  419. break ;
  420. }
  421. }
  422. FCKConfig.Keystrokes = Keystrokes ;
  423. }
  424. if ( FCKConfig.BlockCopyPaste )
  425. {
  426. FCK.BlockCopyPasteKeystrokes() ;
  427. }
  428. FCK.GetNamedCommandState = function( commandName )
  429. {
  430. // This is a modification of the original code.
  431. if ( FCKConfig.BlockCopyPaste )
  432. {
  433. switch ( commandName )
  434. {
  435. case 'Cut' :
  436. case 'Copy' :
  437. case 'Paste' :
  438. case 'PasteText' :
  439. case 'PasteWord' :
  440. return FCK_TRISTATE_DISABLED ;
  441. break ;
  442. default :
  443. break ;
  444. }
  445. }
  446. //
  447. try
  448. {
  449. // Bug #50 : Safari never returns positive state for the Paste command, override that.
  450. if ( (FCKBrowserInfo.IsSafari || FCKBrowserInfo.IsGecko) && FCK.EditorWindow && commandName.IEquals( 'Paste' ) )
  451. return FCK_TRISTATE_OFF ;
  452. if ( !FCK.EditorDocument.queryCommandEnabled( commandName ) )
  453. return FCK_TRISTATE_DISABLED ;
  454. else
  455. {
  456. return FCK.EditorDocument.queryCommandState( commandName ) ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF ;
  457. }
  458. }
  459. catch ( e )
  460. {
  461. return FCK_TRISTATE_OFF ;
  462. }
  463. }
  464. /*
  465. **************************************************************************************
  466. * Toolbar items (buttons).
  467. **************************************************************************************
  468. */
  469. // This function has been redefined here in order hard-codeded parameters
  470. // of toolbar items to be controlled by the developers.
  471. FCKToolbarItems.GetItem = function( itemName )
  472. {
  473. var oItem = FCKToolbarItems.LoadedItems[ itemName ] ;
  474. if ( oItem )
  475. return oItem ;
  476. switch ( itemName )
  477. {
  478. case 'Source' : oItem = new FCKToolbarButton( 'Source' , FCKLang.Source, null,null, true, true, 1 ) ; break ;
  479. case 'DocProps' : oItem = new FCKToolbarButton( 'DocProps' , FCKLang.DocProps, null, null, null, null, 2 ) ; break ;
  480. case 'Save' : oItem = new FCKToolbarButton( 'Save' , FCKLang.Save, null, null, true, null, 3 ) ; break ;
  481. case 'NewPage' : oItem = new FCKToolbarButton( 'NewPage' , FCKLang.NewPage, null, null, true, null, 4 ) ; break ;
  482. case 'Preview' : oItem = new FCKToolbarButton( 'Preview' , FCKLang.Preview, null, null, true, null, 5 ) ; break ;
  483. case 'Templates' : oItem = new FCKToolbarButton( 'Templates' , FCKLang.Templates, null, null, null, null, 6 ) ; break ;
  484. case 'About' : oItem = new FCKToolbarButton( 'About' , FCKLang.About, null, null, true, null, 47 ) ; break ;
  485. case 'Cut' : oItem = new FCKToolbarButton( 'Cut' , FCKLang.Cut, null, null, false, true, 7 ) ; break ;
  486. case 'Copy' : oItem = new FCKToolbarButton( 'Copy' , FCKLang.Copy, null, null, false, true, 8 ) ; break ;
  487. case 'Paste' : oItem = new FCKToolbarButton( 'Paste' , FCKLang.Paste, null, null, false, true, 9 ) ; break ;
  488. case 'PasteText' : oItem = new FCKToolbarButton( 'PasteText' , FCKLang.PasteText, null, null, false, true, 10 ) ; break ;
  489. case 'PasteWord' : oItem = new FCKToolbarButton( 'PasteWord' , FCKLang.PasteWord, null, null, false, true, 11 ) ; break ;
  490. case 'Print' : oItem = new FCKToolbarButton( 'Print' , FCKLang.Print, null, null, false, true, 12 ) ; break ;
  491. case 'SpellCheck' : oItem = new FCKToolbarButton( 'SpellCheck', FCKLang.SpellCheck, null, null, null, null, 13 ) ; break ;
  492. case 'Undo' : oItem = new FCKToolbarButton( 'Undo' , FCKLang.Undo, null, null, false, true, 14 ) ; break ;
  493. case 'Redo' : oItem = new FCKToolbarButton( 'Redo' , FCKLang.Redo, null, null, false, true, 15 ) ; break ;
  494. case 'SelectAll' : oItem = new FCKToolbarButton( 'SelectAll' , FCKLang.SelectAll, null, null, true, null, 18 ) ; break ;
  495. case 'RemoveFormat' : oItem = new FCKToolbarButton( 'RemoveFormat', FCKLang.RemoveFormat, null, null, false, true, 19 ) ; break ;
  496. case 'FitWindow' : oItem = new FCKToolbarButton( 'FitWindow' , FCKLang.FitWindow, null, null, true, true, 66 ) ; break ;
  497. case 'Bold' : oItem = new FCKToolbarButton( 'Bold' , FCKLang.Bold, null, null, false, true, 20 ) ; break ;
  498. case 'Italic' : oItem = new FCKToolbarButton( 'Italic' , FCKLang.Italic, null, null, false, true, 21 ) ; break ;
  499. case 'Underline' : oItem = new FCKToolbarButton( 'Underline' , FCKLang.Underline, null, null, false, true, 22 ) ; break ;
  500. case 'StrikeThrough' : oItem = new FCKToolbarButton( 'StrikeThrough' , FCKLang.StrikeThrough, null, null, false, true, 23 ) ; break ;
  501. case 'Subscript' : oItem = new FCKToolbarButton( 'Subscript' , FCKLang.Subscript, null, null, false, true, 24 ) ; break ;
  502. case 'Superscript' : oItem = new FCKToolbarButton( 'Superscript' , FCKLang.Superscript, null, null, false, true, 25 ) ; break ;
  503. case 'OrderedList' : oItem = new FCKToolbarButton( 'InsertOrderedList' , FCKLang.NumberedListLbl, FCKLang.NumberedList, null, false, true, 26 ) ; break ;
  504. case 'UnorderedList' : oItem = new FCKToolbarButton( 'InsertUnorderedList' , FCKLang.BulletedListLbl, FCKLang.BulletedList, null, false, true, 27 ) ; break ;
  505. case 'Outdent' : oItem = new FCKToolbarButton( 'Outdent' , FCKLang.DecreaseIndent, null, null, false, true, 28 ) ; break ;
  506. case 'Indent' : oItem = new FCKToolbarButton( 'Indent' , FCKLang.IncreaseIndent, null, null, false, true, 29 ) ; break ;
  507. case 'Blockquote' : oItem = new FCKToolbarButton( 'Blockquote' , FCKLang.Blockquote, null, null, false, true, 73 ) ; break ;
  508. case 'CreateDiv' : oItem = new FCKToolbarButton( 'CreateDiv' , FCKLang.CreateDiv, null, null, false, true, 74 ) ; break ;
  509. case 'Link' : oItem = new FCKToolbarButton( 'Link' , FCKLang.InsertLinkLbl, FCKLang.InsertLink, null, false, true, 34 ) ; break ;
  510. case 'Unlink' : oItem = new FCKToolbarButton( 'Unlink' , FCKLang.RemoveLink, null, null, false, true, 35 ) ; break ;
  511. case 'Anchor' : oItem = new FCKToolbarButton( 'Anchor' , FCKLang.Anchor, null, null, null, null, 36 ) ; break ;
  512. //case 'Image' : oItem = new FCKToolbarButton( 'Image' , FCKLang.InsertImageLbl, FCKLang.InsertImage, null, false, true, 37 ) ; break ;
  513. case 'Image' : oItem = new FCKToolbarButton( 'Image' , FCKLang.InsertImageLbl, FCKLang.InsertImage, null, false, true, FCKConfig.ImagesIcon ) ; break ;
  514. case 'Flash' : oItem = new FCKToolbarButton( 'Flash' , FCKLang.InsertFlashLbl, FCKLang.InsertFlash, null, false, true, 38 ) ; break ;
  515. case 'Table' : oItem = new FCKToolbarButton( 'Table' , FCKLang.InsertTableLbl, FCKLang.InsertTable, null, false, true, 39 ) ; break ;
  516. case 'SpecialChar' : oItem = new FCKToolbarButton( 'SpecialChar' , FCKLang.InsertSpecialCharLbl, FCKLang.InsertSpecialChar, null, false, true, 42 ) ; break ;
  517. case 'Smiley' : oItem = new FCKToolbarButton( 'Smiley' , FCKLang.InsertSmileyLbl, FCKLang.InsertSmiley, null, false, true, 41 ) ; break ;
  518. case 'PageBreak' : oItem = new FCKToolbarButton( 'PageBreak' , FCKLang.PageBreakLbl, FCKLang.PageBreak, null, false, true, 43 ) ; break ;
  519. case 'Rule' : oItem = new FCKToolbarButton( 'Rule' , FCKLang.InsertLineLbl, FCKLang.InsertLine, null, false, true, 40 ) ; break ;
  520. case 'JustifyLeft' : oItem = new FCKToolbarButton( 'JustifyLeft' , FCKLang.LeftJustify, null, null, false, true, 30 ) ; break ;
  521. case 'JustifyCenter' : oItem = new FCKToolbarButton( 'JustifyCenter' , FCKLang.CenterJustify, null, null, false, true, 31 ) ; break ;
  522. case 'JustifyRight' : oItem = new FCKToolbarButton( 'JustifyRight' , FCKLang.RightJustify, null, null, false, true, 32 ) ; break ;
  523. case 'JustifyFull' : oItem = new FCKToolbarButton( 'JustifyFull' , FCKLang.BlockJustify, null, null, false, true, 33 ) ; break ;
  524. case 'Style' : oItem = new FCKToolbarStyleCombo() ; break ;
  525. case 'FontName' : oItem = new FCKToolbarFontsCombo() ; break ;
  526. case 'FontSize' : oItem = new FCKToolbarFontSizeCombo() ; break ;
  527. case 'FontFormat' : oItem = new FCKToolbarFontFormatCombo() ; break ;
  528. case 'TextColor' : oItem = new FCKToolbarPanelButton( 'TextColor', FCKLang.TextColor, null, null, 45 ) ; break ;
  529. case 'BGColor' : oItem = new FCKToolbarPanelButton( 'BGColor' , FCKLang.BGColor, null, null, 46 ) ; break ;
  530. case 'Find' : oItem = new FCKToolbarButton( 'Find' , FCKLang.Find, null, null, null, null, 16 ) ; break ;
  531. case 'Replace' : oItem = new FCKToolbarButton( 'Replace' , FCKLang.Replace, null, null, null, null, 17 ) ; break ;
  532. case 'Form' : oItem = new FCKToolbarButton( 'Form' , FCKLang.Form, null, null, null, null, 48 ) ; break ;
  533. case 'Checkbox' : oItem = new FCKToolbarButton( 'Checkbox' , FCKLang.Checkbox, null, null, null, null, 49 ) ; break ;
  534. case 'Radio' : oItem = new FCKToolbarButton( 'Radio' , FCKLang.RadioButton, null, null, null, null, 50 ) ; break ;
  535. case 'TextField' : oItem = new FCKToolbarButton( 'TextField' , FCKLang.TextField, null, null, null, null, 51 ) ; break ;
  536. case 'Textarea' : oItem = new FCKToolbarButton( 'Textarea' , FCKLang.Textarea, null, null, null, null, 52 ) ; break ;
  537. case 'HiddenField' : oItem = new FCKToolbarButton( 'HiddenField' , FCKLang.HiddenField, null, null, null, null, 56 ) ; break ;
  538. case 'Button' : oItem = new FCKToolbarButton( 'Button' , FCKLang.Button, null, null, null, null, 54 ) ; break ;
  539. case 'Select' : oItem = new FCKToolbarButton( 'Select' , FCKLang.SelectionField, null, null, null, null, 53 ) ; break ;
  540. case 'ImageButton' : oItem = new FCKToolbarButton( 'ImageButton' , FCKLang.ImageButton, null, null, null, null, 55 ) ; break ;
  541. case 'ShowBlocks' : oItem = new FCKToolbarButton( 'ShowBlocks' , FCKLang.ShowBlocks, null, null, null, true, 72 ) ; break ;
  542. default:
  543. // Customization: We want to suppress this alarm in order to be
  544. // able to turn off plugins without need to modify defined toolbars.
  545. //alert( FCKLang.UnknownToolbarItem.replace( /%1/g, itemName ) ) ;
  546. return null ;
  547. }
  548. FCKToolbarItems.LoadedItems[ itemName ] = oItem ;
  549. return oItem ;
  550. }
  551. // A modification of the "Save" command in order "nice buttons" in Chamilo
  552. // forms to be supported (to be "clicked" when this command executes).
  553. FCKSaveCommand.prototype.Execute = function()
  554. {
  555. // Get the linked field form.
  556. var oForm = FCK.GetParentForm() ;
  557. if ( typeof( oForm.onsubmit ) == 'function' )
  558. {
  559. var bRet = oForm.onsubmit() ;
  560. if ( bRet != null && bRet === false )
  561. return ;
  562. }
  563. // Next, we will try to scan all styled buttons within the form and to find
  564. // the button that means "Save", "Ok" "Submit", or something similar.
  565. // The way of searching may be not accurate enough, it will be made more
  566. // precise if problems are reported.
  567. for ( var i = 0 ; i < oForm.elements.length ; i++)
  568. {
  569. if ( oForm.elements[i].type == 'submit' )
  570. {
  571. // Let us check whether the button is styled, i.e. whether it is "nice".
  572. if ( oForm.elements[i].getAttribute( 'class' )
  573. // A workaround for the introduction sections.
  574. || oForm.elements[i].getAttribute( 'name' ) == 'intro_cmdUpdate'
  575. // and for Forums
  576. || oForm.elements[i].getAttribute( 'name' ) == 'SubmitForumCategory'
  577. || oForm.elements[i].getAttribute( 'name' ) == 'SubmitForum'
  578. || oForm.elements[i].getAttribute( 'name' ) == 'SubmitPost'
  579. // and for Wikis
  580. || oForm.elements[i].getAttribute( 'name' ) == 'SaveWikiChange'
  581. || oForm.elements[i].getAttribute( 'name' ) == 'SaveWikiNew'
  582. )
  583. {
  584. try
  585. {
  586. // "Clicking" the found button.
  587. oForm.elements[i].click() ;
  588. } catch ( ex ) { }
  589. return ;
  590. }
  591. }
  592. }
  593. // An attempt for submitting the form that has no proper styled button detected.
  594. // If there's a button named "submit" then the form.submit() function is masked and
  595. // can't be called in Mozilla, so we call the click() method of that button.
  596. if ( typeof( oForm.submit ) == 'function' )
  597. oForm.submit() ;
  598. else
  599. oForm.submit.click() ;
  600. }
  601. // This is a modification of the FitWindow command.
  602. // Functionality has been implemented for providing differnt toolbars for normal-sized and maximized editor.
  603. FCKFitWindow.prototype.Execute = function()
  604. {
  605. var eEditorFrame = window.frameElement ;
  606. var eEditorFrameStyle = eEditorFrame.style ;
  607. var eMainWindow = parent ;
  608. var eDocEl = eMainWindow.document.documentElement ;
  609. var eBody = eMainWindow.document.body ;
  610. var eBodyStyle = eBody.style ;
  611. var eParent ;
  612. // Save the current selection and scroll position.
  613. var oRange, oEditorScrollPos ;
  614. if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
  615. {
  616. oRange = new FCKDomRange( FCK.EditorWindow ) ;
  617. oRange.MoveToSelection() ;
  618. oEditorScrollPos = FCKTools.GetScrollPosition( FCK.EditorWindow ) ;
  619. }
  620. else
  621. {
  622. var eTextarea = FCK.EditingArea.Textarea ;
  623. oRange = !FCKBrowserInfo.IsIE && [ eTextarea.selectionStart, eTextarea.selectionEnd ] ;
  624. oEditorScrollPos = [ eTextarea.scrollLeft, eTextarea.scrollTop ] ;
  625. }
  626. // No original style properties known? Go fullscreen.
  627. if ( !this.IsMaximized )
  628. {
  629. // Registering an event handler when the window gets resized.
  630. if( FCKBrowserInfo.IsIE )
  631. eMainWindow.attachEvent( 'onresize', FCKFitWindow_Resize ) ;
  632. else
  633. eMainWindow.addEventListener( 'resize', FCKFitWindow_Resize, true ) ;
  634. // Save the scrollbars position.
  635. this._ScrollPos = FCKTools.GetScrollPosition( eMainWindow ) ;
  636. // Save and reset the styles for the entire node tree. They could interfere in the result.
  637. eParent = eEditorFrame ;
  638. // The extra () is to avoid a warning with strict error checking. This is ok.
  639. while( (eParent = eParent.parentNode) )
  640. {
  641. if ( eParent.nodeType == 1 )
  642. {
  643. eParent._fckSavedStyles = FCKTools.SaveStyles( eParent ) ;
  644. eParent.style.zIndex = FCKConfig.FloatingPanelsZIndex - 1 ;
  645. }
  646. }
  647. // Hide IE scrollbars (in strict mode).
  648. if ( FCKBrowserInfo.IsIE )
  649. {
  650. this.documentElementOverflow = eDocEl.style.overflow ;
  651. eDocEl.style.overflow = 'hidden' ;
  652. eBodyStyle.overflow = 'hidden' ;
  653. }
  654. else
  655. {
  656. // Hide the scroolbars in Firefox.
  657. eBodyStyle.overflow = 'hidden' ;
  658. eBodyStyle.width = '0px' ;
  659. eBodyStyle.height = '0px' ;
  660. }
  661. // Save the IFRAME styles.
  662. this._EditorFrameStyles = FCKTools.SaveStyles( eEditorFrame ) ;
  663. // Resize.
  664. var oViewPaneSize = FCKTools.GetViewPaneSize( eMainWindow ) ;
  665. eEditorFrameStyle.position = "absolute";
  666. eEditorFrame.offsetLeft ; // Kludge for Safari 3.1 browser bug, do not remove. See #2066.
  667. eEditorFrameStyle.zIndex = FCKConfig.FloatingPanelsZIndex - 1;
  668. eEditorFrameStyle.left = "0px";
  669. eEditorFrameStyle.top = "0px";
  670. eEditorFrameStyle.width = oViewPaneSize.Width + "px";
  671. eEditorFrameStyle.height = oViewPaneSize.Height + "px";
  672. // Giving the frame some (huge) borders on his right and bottom
  673. // side to hide the background that would otherwise show when the
  674. // editor is in fullsize mode and the window is increased in size
  675. // not for IE, because IE immediately adapts the editor on resize,
  676. // without showing any of the background oddly in firefox, the
  677. // editor seems not to fill the whole frame, so just setting the
  678. // background of it to white to cover the page laying behind it anyway.
  679. if ( !FCKBrowserInfo.IsIE )
  680. {
  681. eEditorFrameStyle.borderRight = eEditorFrameStyle.borderBottom = "9999px solid white" ;
  682. eEditorFrameStyle.backgroundColor = "white";
  683. }
  684. // Scroll to top left.
  685. eMainWindow.scrollTo(0, 0);
  686. // Is the editor still not on the top left? Let's find out and fix that as well. (Bug #174)
  687. var editorPos = FCKTools.GetWindowPosition( eMainWindow, eEditorFrame ) ;
  688. if ( editorPos.x != 0 )
  689. eEditorFrameStyle.left = ( -1 * editorPos.x ) + "px" ;
  690. if ( editorPos.y != 0 )
  691. eEditorFrameStyle.top = ( -1 * editorPos.y ) + "px" ;
  692. // Added code: Loading a toolbar for maximized editor.
  693. var toolbar = FCKURLParams['Toolbar'] + 'Maximized' ;
  694. if ( FCKConfig.ToolbarSets[toolbar] )
  695. {
  696. var oEditor = FCKeditorAPI.GetInstance(FCK.Name) ;
  697. if ( toolbar != oEditor.ToolbarSet.Name )
  698. {
  699. oEditor.ToolbarSet.Load( toolbar ) ;
  700. }
  701. }
  702. //
  703. this.IsMaximized = true ;
  704. }
  705. else // Resize to original size.
  706. {
  707. // Added code: Loading a toolbar for editor with "normal" sizes.
  708. var toolbar = FCKURLParams['Toolbar'] ;
  709. if ( FCKConfig.ToolbarSets[toolbar] )
  710. {
  711. var oEditor = FCKeditorAPI.GetInstance(FCK.Name) ;
  712. if ( toolbar != oEditor.ToolbarSet.Name )
  713. {
  714. oEditor.ToolbarSet.Load( toolbar ) ;
  715. }
  716. }
  717. //
  718. // Remove the event handler of window resizing.
  719. if( FCKBrowserInfo.IsIE )
  720. eMainWindow.detachEvent( "onresize", FCKFitWindow_Resize ) ;
  721. else
  722. eMainWindow.removeEventListener( "resize", FCKFitWindow_Resize, true ) ;
  723. // Restore the CSS position for the entire node tree.
  724. eParent = eEditorFrame ;
  725. // The extra () is to avoid a warning with strict error checking. This is ok.
  726. while( (eParent = eParent.parentNode) )
  727. {
  728. if ( eParent._fckSavedStyles )
  729. {
  730. FCKTools.RestoreStyles( eParent, eParent._fckSavedStyles ) ;
  731. eParent._fckSavedStyles = null ;
  732. }
  733. }
  734. // Restore IE scrollbars
  735. if ( FCKBrowserInfo.IsIE )
  736. eDocEl.style.overflow = this.documentElementOverflow ;
  737. // Restore original size
  738. FCKTools.RestoreStyles( eEditorFrame, this._EditorFrameStyles ) ;
  739. // Restore the window scroll position.
  740. eMainWindow.scrollTo( this._ScrollPos.X, this._ScrollPos.Y ) ;
  741. this.IsMaximized = false ;
  742. }
  743. FCKToolbarItems.GetItem('FitWindow').RefreshState() ;
  744. // It seams that Firefox restarts the editing area when making this changes.
  745. // On FF 1.0.x, the area is not anymore editable. On FF 1.5+, the special
  746. //configuration, like DisableFFTableHandles and DisableObjectResizing get
  747. //lost, so we must reset it. Also, the cursor position and selection are
  748. //also lost, even if you comment the following line (MakeEditable).
  749. // if ( FCKBrowserInfo.IsGecko10 ) // Initially I thought it was a FF 1.0 only problem.
  750. if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
  751. FCK.EditingArea.MakeEditable() ;
  752. FCK.Focus() ;
  753. // Restore the selection and scroll position of inside the document.
  754. if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
  755. {
  756. oRange.Select() ;
  757. FCK.EditorWindow.scrollTo( oEditorScrollPos.X, oEditorScrollPos.Y ) ;
  758. }
  759. else
  760. {
  761. if ( !FCKBrowserInfo.IsIE )
  762. {
  763. eTextarea.selectionStart = oRange[0] ;
  764. eTextarea.selectionEnd = oRange[1] ;
  765. }
  766. eTextarea.scrollLeft = oEditorScrollPos[0] ;
  767. eTextarea.scrollTop = oEditorScrollPos[1] ;
  768. }
  769. }
  770. /*
  771. **************************************************************************************
  772. * Dialog system
  773. **************************************************************************************
  774. */
  775. // Making a new alternative command for processing Images.
  776. var FCKImageCommand = function( name )
  777. {
  778. this.Name = name ;
  779. this.ImageProperties = new FCKDialogCommand( 'Image', FCKLang.DlgImgTitle, 'dialog/fck_image.html', 600, 455 ) ;
  780. this.ImageManager = null ;
  781. if ( FCK.Plugins.IsLoaded( 'ImageManager' ) )
  782. {
  783. this.ImageManager = new FCKImageManager('ImageManager') ;
  784. }
  785. }
  786. FCKImageCommand.prototype.Execute = function()
  787. {
  788. // If the advanced file manager it to be used, the image properties dialog shoud be activated.
  789. if ( FCKConfig.AdvancedFileManager )
  790. {
  791. this.ImageProperties.Execute() ;
  792. }
  793. else
  794. {
  795. // If the ImageManager plugin has not been loaded, the image properties dialog shoud be activated too.
  796. if ( !this.ImageManager )
  797. {
  798. this.ImageProperties.Execute() ;
  799. }
  800. else
  801. {
  802. var image = FCK.Selection.GetSelectedElement() ;
  803. if ( image )
  804. {
  805. // If an image has been selected in the editor, the image properties dialog shoud be activated.
  806. if ( FCK.IsRealImage( image ) )
  807. {
  808. this.ImageProperties.Execute() ;
  809. }
  810. // If the selected object is fake image, the image manager dialog should be activated.
  811. else
  812. {
  813. this.ImageManager.Execute() ;
  814. }
  815. }
  816. // In other cases (no object selected or the selected object is not an image),
  817. // the image manager dialog should be activated.
  818. else
  819. {
  820. this.ImageManager.Execute() ;
  821. }
  822. }
  823. }
  824. } ;
  825. FCKImageCommand.prototype.GetState = function()
  826. {
  827. return FCK_TRISTATE_OFF ;
  828. }
  829. // This function has been redefined here in order hard-coded dialog sizes
  830. // to be controlled by the developers.
  831. // The Image command's behaviour has been changed.
  832. FCKCommands.GetCommand = function( commandName )
  833. {
  834. var oCommand = FCKCommands.LoadedCommands[ commandName ] ;
  835. if ( oCommand )
  836. return oCommand ;
  837. switch ( commandName )
  838. {
  839. case 'Bold' :
  840. case 'Italic' :
  841. case 'Underline' :
  842. case 'StrikeThrough':
  843. case 'Subscript' :
  844. case 'Superscript' : oCommand = new FCKCoreStyleCommand( commandName ) ; break ;
  845. case 'RemoveFormat' : oCommand = new FCKRemoveFormatCommand() ; break ;
  846. case 'DocProps' : oCommand = new FCKDialogCommand( 'DocProps' , FCKLang.DocProps , 'dialog/fck_docprops.html' , 540, 380, FCKCommands.GetFullPageState ) ; break ;
  847. case 'Templates' : oCommand = new FCKDialogCommand( 'Templates' , FCKLang.DlgTemplatesTitle , 'dialog/fck_template.html' , 380, 450 ) ; break ;
  848. case 'Link' : oCommand = new FCKDialogCommand( 'Link' , FCKLang.DlgLnkWindowTitle , 'dialog/fck_link.html' , 600, 300 ) ; break ;
  849. case 'Unlink' : oCommand = new FCKUnlinkCommand() ; break ;
  850. case 'VisitLink' : oCommand = new FCKVisitLinkCommand() ; break ;
  851. case 'Anchor' : oCommand = new FCKDialogCommand( 'Anchor' , FCKLang.DlgAnchorTitle , 'dialog/fck_anchor.html' , 420, 180 ) ; break ;
  852. case 'AnchorDelete' : oCommand = new FCKAnchorDeleteCommand() ; break ;
  853. case 'BulletedList' : oCommand = new FCKDialogCommand( 'BulletedList', FCKLang.BulletedListProp , 'dialog/fck_listprop.html?UL' , 420, 180 ) ; break ;
  854. case 'NumberedList' : oCommand = new FCKDialogCommand( 'NumberedList', FCKLang.NumberedListProp , 'dialog/fck_listprop.html?OL' , 420, 180 ) ; break ;
  855. case 'About' : oCommand = new FCKDialogCommand( 'About' , FCKLang.About , 'dialog/fck_about.html' , 500, 380, function(){ return FCK_TRISTATE_OFF ; } ) ; break ;
  856. case 'Find' : oCommand = new FCKDialogCommand( 'Find' , FCKLang.DlgFindAndReplaceTitle, 'dialog/fck_replace.html' , 450, 250, null, null, 'Find' ) ; break ;
  857. case 'Replace' : oCommand = new FCKDialogCommand( 'Replace' , FCKLang.DlgFindAndReplaceTitle, 'dialog/fck_replace.html' , 450, 250, null, null, 'Replace' ) ; break ;
  858. //case 'Image' : oCommand = new FCKDialogCommand( 'Image' , FCKLang.DlgImgTitle , 'dialog/fck_image.html' , 600, 450 ) ; break ;
  859. case 'Image' : oCommand = new FCKImageCommand( 'Image' ) ; break ;
  860. case 'Flash' : oCommand = new FCKDialogCommand( 'Flash' , FCKLang.DlgFlashTitle , 'dialog/fck_flash.html' , 600, 450 ) ; break ;
  861. case 'SpecialChar' : oCommand = new FCKDialogCommand( 'SpecialChar', FCKLang.DlgSpecialCharTitle , 'dialog/fck_specialchar.html' , 540, 450 ) ; break ;
  862. case 'Smiley' : oCommand = new FCKDialogCommand( 'Smiley' , FCKLang.DlgSmileyTitle , 'dialog/fck_smiley.html' , FCKConfig.SmileyWindowWidth, FCKConfig.SmileyWindowHeight ) ; break ;
  863. case 'Table' : oCommand = new FCKDialogCommand( 'Table' , FCKLang.DlgTableTitle , 'dialog/fck_table.html' , 600, 300 ) ; break ;
  864. case 'TableProp' : oCommand = new FCKDialogCommand( 'Table' , FCKLang.DlgTableTitle , 'dialog/fck_table.html?Parent', 600, 300 ) ; break ;
  865. case 'TableCellProp': oCommand = new FCKDialogCommand( 'TableCell' , FCKLang.DlgCellTitle , 'dialog/fck_tablecell.html' , 600, 300 ) ; break ;
  866. case 'Style' : oCommand = new FCKStyleCommand() ; break ;
  867. case 'FontName' : oCommand = new FCKFontNameCommand() ; break ;
  868. case 'FontSize' : oCommand = new FCKFontSizeCommand() ; break ;
  869. case 'FontFormat' : oCommand = new FCKFormatBlockCommand() ; break ;
  870. case 'Source' : oCommand = new FCKSourceCommand() ; break ;
  871. case 'Preview' : oCommand = new FCKPreviewCommand() ; break ;
  872. case 'Save' : oCommand = new FCKSaveCommand() ; break ;
  873. case 'NewPage' : oCommand = new FCKNewPageCommand() ; break ;
  874. case 'PageBreak' : oCommand = new FCKPageBreakCommand() ; break ;
  875. case 'Rule' : oCommand = new FCKRuleCommand() ; break ;
  876. case 'Nbsp' : oCommand = new FCKNbsp() ; break ;
  877. case 'TextColor' : oCommand = new FCKTextColorCommand('ForeColor') ; break ;
  878. case 'BGColor' : oCommand = new FCKTextColorCommand('BackColor') ; break ;
  879. case 'Paste' : oCommand = new FCKPasteCommand() ; break ;
  880. case 'PasteText' : oCommand = new FCKPastePlainTextCommand() ; break ;
  881. case 'PasteWord' : oCommand = new FCKPasteWordCommand() ; break ;
  882. case 'JustifyLeft' : oCommand = new FCKJustifyCommand( 'left' ) ; break ;
  883. case 'JustifyCenter' : oCommand = new FCKJustifyCommand( 'center' ) ; break ;
  884. case 'JustifyRight' : oCommand = new FCKJustifyCommand( 'right' ) ; break ;
  885. case 'JustifyFull' : oCommand = new FCKJustifyCommand( 'justify' ) ; break ;
  886. case 'Indent' : oCommand = new FCKIndentCommand( 'indent', FCKConfig.IndentLength ) ; break ;
  887. case 'Outdent' : oCommand = new FCKIndentCommand( 'outdent', FCKConfig.IndentLength * -1 ) ; break ;
  888. case 'Blockquote' : oCommand = new FCKBlockQuoteCommand() ; break ;
  889. case 'CreateDiv' : oCommand = new FCKDialogCommand( 'CreateDiv', FCKLang.CreateDiv, 'dialog/fck_div.html', 400, 300, null, null, true ) ; break ;
  890. case 'EditDiv' : oCommand = new FCKDialogCommand( 'EditDiv', FCKLang.EditDiv, 'dialog/fck_div.html', 400, 300, null, null, false ) ; break ;
  891. case 'DeleteDiv' : oCommand = new FCKDeleteDivCommand() ; break ;
  892. case 'TableInsertRowAfter' : oCommand = new FCKTableCommand('TableInsertRowAfter') ; break ;
  893. case 'TableInsertRowBefore' : oCommand = new FCKTableCommand('TableInsertRowBefore') ; break ;
  894. case 'TableDeleteRows' : oCommand = new FCKTableCommand('TableDeleteRows') ; break ;
  895. case 'TableInsertColumnAfter' : oCommand = new FCKTableCommand('TableInsertColumnAfter') ; break ;
  896. case 'TableInsertColumnBefore' : oCommand = new FCKTableCommand('TableInsertColumnBefore') ; break ;
  897. case 'TableDeleteColumns' : oCommand = new FCKTableCommand('TableDeleteColumns') ; break ;
  898. case 'TableInsertCellAfter' : oCommand = new FCKTableCommand('TableInsertCellAfter') ; break ;
  899. case 'TableInsertCellBefore' : oCommand = new FCKTableCommand('TableInsertCellBefore') ; break ;
  900. case 'TableDeleteCells' : oCommand = new FCKTableCommand('TableDeleteCells') ; break ;
  901. case 'TableMergeCells' : oCommand = new FCKTableCommand('TableMergeCells') ; break ;
  902. case 'TableMergeRight' : oCommand = new FCKTableCommand('TableMergeRight') ; break ;
  903. case 'TableMergeDown' : oCommand = new FCKTableCommand('TableMergeDown') ; break ;
  904. case 'TableHorizontalSplitCell' : oCommand = new FCKTableCommand('TableHorizontalSplitCell') ; break ;
  905. case 'TableVerticalSplitCell' : oCommand = new FCKTableCommand('TableVerticalSplitCell') ; break ;
  906. case 'TableDelete' : oCommand = new FCKTableCommand('TableDelete') ; break ;
  907. case 'Form' : oCommand = new FCKDialogCommand( 'Form' , FCKLang.Form , 'dialog/fck_form.html' , 380, 210 ) ; break ;
  908. case 'Checkbox' : oCommand = new FCKDialogCommand( 'Checkbox' , FCKLang.Checkbox , 'dialog/fck_checkbox.html' , 380, 200 ) ; break ;
  909. case 'Radio' : oCommand = new FCKDialogCommand( 'Radio' , FCKLang.RadioButton , 'dialog/fck_radiobutton.html' , 380, 200 ) ; break ;
  910. case 'TextField' : oCommand = new FCKDialogCommand( 'TextField' , FCKLang.TextField , 'dialog/fck_textfield.html' , 380, 210 ) ; break ;
  911. case 'Textarea' : oCommand = new FCKDialogCommand( 'Textarea' , FCKLang.Textarea , 'dialog/fck_textarea.html' , 380, 210 ) ; break ;
  912. case 'HiddenField' : oCommand = new FCKDialogCommand( 'HiddenField', FCKLang.HiddenField , 'dialog/fck_hiddenfield.html' , 380, 190 ) ; break ;
  913. case 'Button' : oCommand = new FCKDialogCommand( 'Button' , FCKLang.Button , 'dialog/fck_button.html' , 380, 210 ) ; break ;
  914. case 'Select' : oCommand = new FCKDialogCommand( 'Select' , FCKLang.SelectionField, 'dialog/fck_select.html' , 450, 380 ) ; break ;
  915. case 'ImageButton' : oCommand = new FCKDialogCommand( 'ImageButton', FCKLang.ImageButton , 'dialog/fck_image.html?ImageButton', 600, 450 ) ; break ;
  916. case 'SpellCheck' : oCommand = new FCKSpellCheckCommand() ; break ;
  917. case 'FitWindow' : oCommand = new FCKFitWindow() ; break ;
  918. case 'Undo' : oCommand = new FCKUndoCommand() ; break ;
  919. case 'Redo' : oCommand = new FCKRedoCommand() ; break ;
  920. case 'Copy' : oCommand = new FCKCutCopyCommand( false ) ; break ;
  921. case 'Cut' : oCommand = new FCKCutCopyCommand( true ) ; break ;
  922. case 'SelectAll' : oCommand = new FCKSelectAllCommand() ; break ;
  923. case 'InsertOrderedList' : oCommand = new FCKListCommand( 'insertorderedlist', 'ol' ) ; break ;
  924. case 'InsertUnorderedList' : oCommand = new FCKListCommand( 'insertunorderedlist', 'ul' ) ; break ;
  925. case 'ShowBlocks' : oCommand = new FCKShowBlockCommand( 'ShowBlocks', FCKConfig.StartupShowBlocks ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF ) ; break ;
  926. // Generic Undefined command (usually used when a command is under development).
  927. case 'Undefined' : oCommand = new FCKUndefinedCommand() ; break ;
  928. case 'Scayt' : oCommand = FCKScayt.CreateCommand() ; break ;
  929. case 'ScaytContext' : oCommand = FCKScayt.CreateContextCommand() ; break ;
  930. // By default we assume that it is a named command.
  931. default:
  932. if ( FCKRegexLib.NamedCommands.test( commandName ) )
  933. oCommand = new FCKNamedCommand( commandName ) ;
  934. else
  935. {
  936. alert( FCKLang.UnknownCommand.replace( /%1/g, commandName ) ) ;
  937. return null ;
  938. }
  939. }
  940. FCKCommands.LoadedCommands[ commandName ] = oCommand ;
  941. return oCommand ;
  942. }
  943. // Upgrading the language subsystem, so it could be able to translate new nice buttons.
  944. FCKLanguageManager.TranslatePage = function( targetDocument )
  945. {
  946. this.TranslateElements( targetDocument, 'INPUT', 'value' ) ;
  947. this.TranslateElements( targetDocument, 'SPAN', 'innerHTML' ) ;
  948. this.TranslateElements( targetDocument, 'LABEL', 'innerHTML' ) ;
  949. this.TranslateElements( targetDocument, 'OPTION', 'innerHTML', true ) ;
  950. this.TranslateElements( targetDocument, 'LEGEND', 'innerHTML' ) ;
  951. // The following tag has been added for searching:
  952. this.TranslateElements( targetDocument, 'BUTTON', 'innerHTML' ) ;
  953. }
  954. // Calculating size of rectangular object so it to fit within other rectangular object
  955. // with preserving aspect ratio.
  956. FCK.ResizeToFit = function( width, height, max_width, max_height )
  957. {
  958. var result = [0, 0] ;
  959. result[0] = width;
  960. result[1] = height ;
  961. if ( width <= max_width && height <= max_height )
  962. return result ;
  963. if ( width > max_width )
  964. {
  965. height = height * max_width / width ;
  966. width = max_width ;
  967. }
  968. if ( height > max_height )
  969. {
  970. width = width * max_height / height ;
  971. height = max_height ;
  972. }
  973. result[0] = parseInt ( width, 10 );
  974. result[1] = parseInt ( height, 10 ) ;
  975. return result ;
  976. }
  977. /*
  978. **************************************************************************************
  979. * Fake images support
  980. **************************************************************************************
  981. */
  982. // This is a modification of the original function.
  983. FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement )
  984. {
  985. // Premature detection of fake image type is needed here.
  986. if ( fakeClass == 'FCK__UnknownObject' )
  987. {
  988. if ( FCK.IsVideo( realElement ) )
  989. {
  990. fakeClass = 'FCK__Video' ;
  991. }
  992. else if ( FCK.IsAsciiSvg( realElement ) )
  993. {
  994. fakeClass = 'FCK__AsciiSvg' ;
  995. }
  996. }
  997. // The original code fragment.
  998. var oImg = FCKTools.GetElementDocument( realElement ).createElement( 'IMG' ) ;
  999. oImg.className = fakeClass ;
  1000. oImg.src = FCKConfig.BasePath + 'images/spacer.gif' ;
  1001. oImg.setAttribute( '_fckfakelement', 'true', 0 ) ;
  1002. oImg.setAttribute( '_fckrealelement', FCKTempBin.AddElement( realElement ), 0 ) ;
  1003. // Setting width and height for relevant types of fake images.
  1004. if ( fakeClass == 'FCK__Video' && realElement.nodeName.IEquals( 'div' ) )
  1005. {
  1006. // Specific to the flv player.
  1007. for ( var i = 0; i < realElement.childNodes.length; i++ )
  1008. {
  1009. if ( realElement.childNodes[i].nodeName.IEquals( 'div' ) )
  1010. {
  1011. oImg.style.width = realElement.childNodes[i].style.width ;
  1012. oImg.style.height = realElement.childNodes[i].style.height ;
  1013. break ;
  1014. }
  1015. }
  1016. }
  1017. else if ( fakeClass == 'FCK__Video' || fakeClass == 'FCK__AsciiSvg' )
  1018. {
  1019. try
  1020. {
  1021. var width = realElement.width ;
  1022. var height = realElement.height ;
  1023. if ( width )
  1024. {
  1025. oImg.style.width = FCKTools.ConvertHtmlSizeToStyle( width.toString() ) ;
  1026. }
  1027. if ( height )
  1028. {
  1029. oImg.style.height = FCKTools.ConvertHtmlSizeToStyle( height.toString() ) ;
  1030. }
  1031. if ( realElement.style.width ) {
  1032. oImg.style.width = realElement.style.width ;
  1033. }
  1034. if ( realElement.style.height ) {
  1035. oImg.style.height = realElement.style.height ;
  1036. }
  1037. }
  1038. catch ( ex ) { }
  1039. }
  1040. // Setting attributes for detection purpose.
  1041. if ( fakeClass == 'FCK__Video' )
  1042. {
  1043. oImg.setAttribute( '_fckvideo', 'true', 0 ) ;
  1044. }
  1045. else if ( fakeClass == 'FCK__AsciiSvg' )
  1046. {
  1047. oImg.setAttribute( '_fckasciisvg', 'true', 0 ) ;
  1048. }
  1049. return oImg ;
  1050. }
  1051. // A fake image handler for audio files.
  1052. FCKEmbedAndObjectProcessor.AddCustomHandler( function ( el, fakeImg )
  1053. {
  1054. if ( !FCK.IsAudio( el ) )
  1055. {
  1056. return ;
  1057. }
  1058. fakeImg.className = 'FCK__MP3' ;
  1059. fakeImg.setAttribute( '_fckmp3', 'true', 0 ) ;
  1060. } ) ;
  1061. // A fake image handler for video files.
  1062. FCKEmbedAndObjectProcessor.AddCustomHandler( function ( el, fakeImg )
  1063. {
  1064. if ( !FCK.IsVideo( el ) )
  1065. {
  1066. return ;
  1067. }
  1068. fakeImg.className = 'FCK__Video' ;
  1069. fakeImg.setAttribute( '_fckvideo', 'true', 0 ) ;
  1070. } ) ;
  1071. // Fake image support for flv video files.
  1072. FCKDocumentProcessor.AppendNew().ProcessDocument = function ( document )
  1073. {
  1074. // For the flv player.
  1075. var divs = document.getElementsByTagName( 'div' ) ;
  1076. var div;
  1077. var i = divs.length - 1 ;
  1078. while ( i >= 0 && ( div = divs[i--] ) )
  1079. {
  1080. if ( FCK.IsVideo( div ) )
  1081. {
  1082. var oImg = FCKDocumentProcessor_CreateFakeImage( 'FCK__Video', div.cloneNode(true) ) ;
  1083. oImg.setAttribute( '_fckvideo', 'true', 0 ) ;
  1084. div.parentNode.insertBefore( oImg, div ) ;
  1085. div.parentNode.removeChild( div ) ;
  1086. }
  1087. }
  1088. } ;
  1089. // Getting the corresponding real element.
  1090. FCK.GetRealElement = function( fakeElement )
  1091. {
  1092. var e = FCKTempBin.Elements[ fakeElement.getAttribute('_fckrealelement') ] ;
  1093. if ( fakeElement.getAttribute('_fckflash') )
  1094. {
  1095. if ( fakeElement.style.width.length > 0 )
  1096. e.width = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.width ) ;
  1097. if ( fakeElement.style.height.length > 0 )
  1098. e.height = FCKTools.ConvertStyleSizeToHtml( fakeElement.style.height ) ;
  1099. }
  1100. // Added by Ivan Tcholakov, February 2011.
  1101. else if ( fakeElement.getAttribute('_fckvideo') )
  1102. {
  1103. // Resizing a movie according to its fake image size.
  1104. // The user can resize the fake image on IE and Firefox.
  1105. if ( !FCKBrowserInfo.IsIE // This feature has been temporarily disabled for IE, additional tricky changes are needed.
  1106. && e.nodeName.IEquals( 'div' ) )
  1107. {
  1108. if ( e.id )
  1109. {
  1110. if ( e.id.match( /^player[0-9]*-parent$/ )
  1111. && typeof FCKConfig[ 'FlashEmbeddingMethod' ] == 'string'
  1112. && FCKConfig[ 'FlashEmbeddingMethod' ] != 'swfobject' ) // Resizing does not work with SWFObject embedding technique.
  1113. {
  1114. try
  1115. {
  1116. var width = fakeElement.width ;
  1117. var height = fakeElement.height ;
  1118. if ( fakeElement.style.width ) {
  1119. width = fakeElement.style.width ;
  1120. }
  1121. if ( fakeElement.style.height ) {
  1122. height = fakeElement.style.height ;
  1123. }
  1124. width = parseInt( width, 10 ) - 2 ;
  1125. height = parseInt( height, 10 ) - 2 ;
  1126. if ( width > 0 && height > 0 )
  1127. {
  1128. width = width.toString() ;
  1129. height = height.toString() ;
  1130. width = parseInt( width, 10 ) ;
  1131. height = parseInt( height, 10 ) ;
  1132. if ( width > 0 && height > 0 )
  1133. {
  1134. var divs = e.getElementsByTagName( 'div' ) ;
  1135. if ( typeof divs[ 1 ] != 'undefined' )
  1136. {
  1137. var div = divs[ 1 ] ;
  1138. if ( div.id && div.id.match( /^player[0-9]*-config$/ ) )
  1139. {
  1140. // This is the hidden div element that contains the movie's settings.
  1141. var config = div.innerHTML ;
  1142. var w ;
  1143. var h ;
  1144. if ( ( w = config.match( /width=([0-9]*)/ ) ) && ( h = config.match( /height=([0-9]*)/ ) ) )
  1145. {
  1146. w = parseInt( w[ 1 ], 10 );
  1147. h = parseInt( h[ 1 ] , 10 );
  1148. if ( Math.abs( width - w ) > 2 || Math.abs( height - h ) > 2 )
  1149. {
  1150. width = width.toString() ;
  1151. height = height.toString() ;
  1152. var s = e.innerHTML ;
  1153. // Replacements for div, object, end embed tags.
  1154. s = s.replace( /width\s*:\s*[0-9]+/ig , 'width: ' + width ) ;
  1155. s = s.replace( /height\s*:\s*[0-9]+/ig , 'height: ' + height ) ;
  1156. s = s.replace( /width=[0-9]+/ig , 'width=' + width ) ;
  1157. s = s.replace( /height=[0-9]+/ig , 'height=' + height ) ;
  1158. s = s.replace( /width="[0-9]+"/ig , 'width="' + width + '"' ) ;
  1159. s = s.replace( /height="[0-9]+"/ig , 'height="' + height + '"' ) ;
  1160. e.innerHTML = s ;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. }
  1167. }
  1168. catch ( ex ) { }
  1169. }
  1170. }
  1171. }
  1172. }
  1173. //
  1174. return e ;
  1175. } ;
  1176. /*
  1177. **************************************************************************************
  1178. * Context menu support
  1179. **************************************************************************************
  1180. */
  1181. // Removing some built-in context menu commands.
  1182. // Their default functionalities break proper working of the activated plugins.
  1183. for ( var i in FCK.ContextMenu.Listeners )
  1184. {
  1185. var listener = '' ;
  1186. if ( FCK.ContextMenu.Listeners[i].AddItems )
  1187. {
  1188. listener = FCK.ContextMenu.Listeners[i].AddItems.toString() ;
  1189. }
  1190. // Dealing with the built-in context menu handler for images.
  1191. if ( listener.indexOf( 'IMG' ) != -1 && listener.indexOf( '_fckfakelement' ) != -1 )
  1192. {
  1193. FCK.ContextMenu.Listeners[i].AddItems = function ( menu, tag, tagName )
  1194. {
  1195. return ;
  1196. } ;
  1197. }
  1198. // Dealing with the built-in context menu handler for flash objects.
  1199. if ( listener.indexOf( 'IMG' ) != -1 && listener.indexOf( '_fckflash' ) != -1 )
  1200. {
  1201. FCK.ContextMenu.Listeners[i].AddItems = function ( menu, tag, tagName )
  1202. {
  1203. return ;
  1204. } ;
  1205. }
  1206. }
  1207. // Adding context menu commands.
  1208. // Image-related commands.
  1209. FCK.ContextMenu.RegisterListener( {
  1210. AddItems : function ( menu, tag, tagName )
  1211. {
  1212. if ( FCK.IsRealImage( tag ) )
  1213. {
  1214. // Grouping all image-related commands at the bottom.
  1215. menu.AddSeparator();
  1216. //menu.AddItem( 'Image', FCKLang.ImageProperties, 37 ) ;
  1217. menu.AddItem( 'Image', FCKLang.ImageProperties, FCKConfig.ImagesIcon ) ;
  1218. // The "imgmap" plugin should add its own icon here.
  1219. }
  1220. } }
  1221. ) ;
  1222. // Flash command.
  1223. FCK.ContextMenu.RegisterListener( {
  1224. AddItems : function ( menu, tag, tagName )
  1225. {
  1226. if ( tagName == 'IMG' && tag.getAttribute( '_fckflash' ) &&
  1227. !tag.getAttribute( '_fckmp3' ) &&
  1228. !tag.getAttribute( '_fckvideo' ) )
  1229. {
  1230. menu.AddSeparator() ;
  1231. menu.AddItem( 'Flash', FCKLang.FlashProperties, 38 ) ;
  1232. }
  1233. } }
  1234. ) ;
  1235. // MP3 command.
  1236. FCK.ContextMenu.RegisterListener( {
  1237. AddItems : function ( menu, tag, tagName )
  1238. {
  1239. var AudioTitle = 'Import MP3' ;
  1240. var AudioIcon = FCKConfig.PluginsPath + 'MP3/mp3.gif' ;
  1241. if ( FCKLang.DlgAudioTitle )
  1242. {
  1243. AudioTitle = FCKLang.DlgAudioTitle ;
  1244. AudioIcon = FCKConfig.PluginsPath + 'audio/audio.gif' ;
  1245. }
  1246. else if ( FCKLang.DlgMP3Title )
  1247. {
  1248. AudioTitle = FCKLang.DlgMP3Title ;
  1249. }
  1250. if ( tagName == 'IMG' && tag.getAttribute( '_fckmp3' ) )
  1251. {
  1252. if ( FCK.Plugins.IsLoaded( 'audio' ) || FCK.Plugins.IsLoaded( 'MP3' ) )
  1253. {
  1254. menu.AddSeparator() ;
  1255. menu.AddItem( 'MP3', AudioTitle, AudioIcon ) ;
  1256. }
  1257. }
  1258. } }
  1259. ) ;
  1260. // Video-related commands.
  1261. FCK.ContextMenu.RegisterListener( {
  1262. AddItems : function ( menu, tag, tagName )
  1263. {
  1264. if ( tagName == 'IMG' && tag.getAttribute( '_fckvideo' ) )
  1265. {
  1266. switch ( FCK.GetVideoType( tag ) )
  1267. {
  1268. case 'embedded_video' :
  1269. if ( FCK.Plugins.IsLoaded( 'fckEmbedMovies' ) )
  1270. {
  1271. menu.AddSeparator() ;
  1272. menu.AddItem( 'EmbedMovies', FCKLang.DlgEmbedMoviesTitle, FCKConfig.PluginsPath + 'fckEmbedMovies/embedmovies.gif' ) ;
  1273. }
  1274. break ;
  1275. case 'youtube' :
  1276. if ( FCK.Plugins.IsLoaded( 'youtube' ) )
  1277. {
  1278. menu.AddSeparator() ;
  1279. menu.AddItem( 'YouTube', FCKLang.YouTubeTip, FCKConfig.PluginsPath + 'youtube/youtube.gif' ) ;
  1280. }
  1281. break ;
  1282. case 'media' :
  1283. if ( FCK.Plugins.IsLoaded( 'media' ) )
  1284. {
  1285. menu.AddSeparator() ;
  1286. menu.AddItem( 'Media', FCKLang.YouTubeTip, FCKConfig.PluginsPath + 'media/media.gif' ) ;
  1287. }
  1288. break ;
  1289. case 'flv' :
  1290. if ( FCK.Plugins.IsLoaded( 'flvPlayer' ) )
  1291. {
  1292. menu.AddSeparator() ;
  1293. menu.AddItem( 'flvPlayer', FCKLang.DlgFLVPlayerTitle, FCKConfig.PluginsPath + 'flvPlayer/flvPlayer.gif' ) ;
  1294. }
  1295. break ;
  1296. default :
  1297. break ;
  1298. }
  1299. }
  1300. } }
  1301. ) ;
  1302. /*
  1303. **************************************************************************************
  1304. * Double click support
  1305. **************************************************************************************
  1306. */
  1307. // Image properties command.
  1308. FCK.RegisterDoubleClickHandler(
  1309. function ( tag )
  1310. {
  1311. if ( FCK.IsRealImage( tag ) )
  1312. {
  1313. var command = new FCKDialogCommand( 'Image', FCKLang.DlgImgTitle, 'dialog/fck_image.html', 600, 455 ) ;
  1314. command.Execute() ;
  1315. }
  1316. }, 'IMG'
  1317. ) ;
  1318. // Flash command.
  1319. FCK.RegisterDoubleClickHandler(
  1320. function ( tag )
  1321. {
  1322. if ( tag.tagName == 'IMG' && tag.getAttribute( '_fckflash' ) &&
  1323. !tag.getAttribute( '_fckmp3' ) &&
  1324. !tag.getAttribute( '_fckvideo' ) )
  1325. {
  1326. FCKCommands.GetCommand( 'Flash' ).Execute() ;
  1327. }
  1328. }, 'IMG'
  1329. ) ;
  1330. // MP3 command.
  1331. FCK.RegisterDoubleClickHandler(
  1332. function ( tag )
  1333. {
  1334. if ( tag.tagName == 'IMG' && tag.getAttribute( '_fckmp3' ) )
  1335. {
  1336. if ( FCK.Plugins.IsLoaded( 'audio' ) || FCK.Plugins.IsLoaded( 'MP3' ) )
  1337. {
  1338. FCKCommands.GetCommand( 'MP3' ).Execute() ;
  1339. }
  1340. }
  1341. }, 'IMG'
  1342. ) ;
  1343. // Video-related commands.
  1344. FCK.RegisterDoubleClickHandler(
  1345. function ( tag )
  1346. {
  1347. if ( tag.tagName == 'IMG' && tag.getAttribute( '_fckvideo' ) )
  1348. {
  1349. switch ( FCK.GetVideoType( tag ) )
  1350. {
  1351. case 'embedded_video' :
  1352. if ( FCK.Plugins.IsLoaded( 'fckEmbedMovies' ) )
  1353. {
  1354. FCKCommands.GetCommand( 'EmbedMovies' ).Execute() ;
  1355. }
  1356. break ;
  1357. case 'youtube' :
  1358. if ( FCK.Plugins.IsLoaded( 'youtube' ) )
  1359. {
  1360. FCKCommands.GetCommand( 'YouTube' ).Execute() ;
  1361. }
  1362. break ;
  1363. case 'media' :
  1364. if ( FCK.Plugins.IsLoaded( 'media' ) )
  1365. {
  1366. FCKCommands.GetCommand( 'media' ).Execute() ;
  1367. }
  1368. break ;
  1369. case 'flv':
  1370. if ( FCK.Plugins.IsLoaded( 'flvPlayer' ) )
  1371. {
  1372. FCKCommands.GetCommand( 'flvPlayer' ).Execute() ;
  1373. }
  1374. break ;
  1375. default :
  1376. break ;
  1377. }
  1378. }
  1379. }, 'IMG'
  1380. ) ;
  1381. /*
  1382. **************************************************************************************
  1383. * Routines for testing the type of a selected visual object.
  1384. **************************************************************************************
  1385. */
  1386. // Checking whether a selected object is a real image or not.
  1387. FCK.IsRealImage = function ( tag )
  1388. {
  1389. if ( !tag )
  1390. {
  1391. return false ;
  1392. }
  1393. if ( tag.nodeName.IEquals( 'img' ) )
  1394. {
  1395. if ( tag.getAttribute( '_fckfakelement' )
  1396. || tag.getAttribute( '_fckflash' )
  1397. || tag.getAttribute( '_fckmp3' )
  1398. || tag.getAttribute( '_fckvideo' )
  1399. || tag.getAttribute( 'MapNumber' )
  1400. )
  1401. {
  1402. return false ;
  1403. }
  1404. if ( tag.getAttribute( 'src' ) )
  1405. {
  1406. var src = tag.getAttribute( 'src' ).toString().toLowerCase() ;
  1407. return ( src.indexOf( 'mimetex?' ) == -1
  1408. && src.indexOf( 'mimetex.cgi?' ) == -1
  1409. && src.indexOf( 'mimetex.exe?' ) == -1
  1410. && src.indexOf( 'mathtex?' ) == -1
  1411. && src.indexOf( 'mathtex.cgi?' ) == -1
  1412. && src.indexOf( 'mathtex.exe?' ) == -1
  1413. && src.indexOf( 'mathtran?' ) == -1
  1414. && src.indexOf( 'google.com/chart?' ) == -1
  1415. && src.indexOf( 'latex?' ) == -1
  1416. && src.indexOf( 'sscr=' ) == -1
  1417. ) ? true : false ;
  1418. }
  1419. else
  1420. {
  1421. return true ;
  1422. }
  1423. }
  1424. return false ;
  1425. } ;
  1426. // Checking for audio file reference which is to be used by a flash player.
  1427. FCK.IsAudio = function ( tag )
  1428. {
  1429. if ( !tag )
  1430. {
  1431. return false ;
  1432. }
  1433. if ( tag.nodeName.IEquals( 'embed' ) )
  1434. {
  1435. if ( !tag.src )
  1436. {
  1437. return false ;
  1438. }
  1439. if ( tag.type == 'application/x-shockwave-flash' || /\.swf($|#|\?|&)?/i.test( tag.src ) )
  1440. {
  1441. // Possible way of detection for other players.
  1442. if ( /\.mp3/i.test( tag.src ) )
  1443. {
  1444. return true ;
  1445. }
  1446. // Specific to mediaplayer detection.
  1447. var flashvars = FCKDomTools.GetAttributeValue( tag, 'flashvars' ) ;
  1448. flashvars = flashvars ? flashvars.toLowerCase() : '' ;
  1449. if ( /\.mp3/i.test( flashvars ) )
  1450. {
  1451. return true ;
  1452. }
  1453. }
  1454. }
  1455. return false ;
  1456. } ;
  1457. // Checking for video file reference within an embedded object.
  1458. FCK.IsVideo = function ( tag )
  1459. {
  1460. if ( !tag )
  1461. {
  1462. return false ;
  1463. }
  1464. if ( tag.nodeName.IEquals( 'embed' ) )
  1465. {
  1466. if ( !tag.src )
  1467. {
  1468. return false ;
  1469. }
  1470. // There are three plugins dealing with video content. Detection looks a bit messy.
  1471. // Embedded video.
  1472. if ( /\.(mpg|mpeg|mp4|avi|wmv|mov|asf)/i.test( tag.src ) )
  1473. {
  1474. return true ;
  1475. }
  1476. if ( tag.type == 'application/x-shockwave-flash' || /\.swf($|#|\?|&)?/i.test( tag.src ) )
  1477. {
  1478. // Youtube.
  1479. if ( /\.youtube\.com/i.test( tag.src ) )
  1480. {
  1481. return true ;
  1482. }
  1483. // FLV player.
  1484. if ( /\.flv/i.test( tag.src ) )
  1485. {
  1486. return true ;
  1487. }
  1488. var flashvars = FCKDomTools.GetAttributeValue( tag, 'flashvars' ) ;
  1489. flashvars = flashvars ? flashvars.toLowerCase() : '' ;
  1490. if ( /\.flv/i.test( flashvars ) )
  1491. {
  1492. return true ;
  1493. }
  1494. }
  1495. }
  1496. // This is for the flv player.
  1497. if ( tag.nodeName.IEquals( 'div' ) )
  1498. {
  1499. if ( tag.id )
  1500. {
  1501. if ( tag.id.match( /^player[0-9]*-parent$/ ) )
  1502. {
  1503. return true ;
  1504. }
  1505. }
  1506. }
  1507. return false ;
  1508. } ;
  1509. // Returns specific type/source of embedded video.
  1510. FCK.GetVideoType = function ( img )
  1511. {
  1512. var tag = FCK.GetRealElement( img ) ;
  1513. if ( !tag )
  1514. {
  1515. return false ;
  1516. }
  1517. // This is for the flv player.
  1518. if ( tag.nodeName.IEquals( 'div' ) )
  1519. {
  1520. if ( tag.id )
  1521. {
  1522. if ( tag.id.match( /^player[0-9]*-parent$/ ) )
  1523. {
  1524. return 'flv' ;
  1525. }
  1526. }
  1527. }
  1528. if ( !tag.src )
  1529. {
  1530. return false ;
  1531. }
  1532. // Embedded video.
  1533. if ( /\.(mpg|mpeg|mp4|avi|wmv|mov|asf)/i.test( tag.src ) )
  1534. {
  1535. return 'embedded_video' ;
  1536. }
  1537. // Youtube.
  1538. if ( /\.youtube\.com/i.test( tag.src ) )
  1539. {
  1540. return 'youtube' ;
  1541. }
  1542. // FLV player.
  1543. if ( /\.flv/i.test( tag.src ) )
  1544. {
  1545. return 'flv' ;
  1546. }
  1547. var flashvars = FCKDomTools.GetAttributeValue( tag, 'flashvars' ) ;
  1548. flashvars = flashvars ? flashvars.toLowerCase() : '' ;
  1549. if ( /\.flv/i.test( flashvars ) )
  1550. {
  1551. return 'flv' ;
  1552. }
  1553. return false ;
  1554. } ;
  1555. // Checking for AsciiSvg graphics.
  1556. FCK.IsAsciiSvg = function ( tag )
  1557. {
  1558. if ( !tag )
  1559. {
  1560. return false ;
  1561. }
  1562. if ( tag.nodeName.IEquals( 'embed' ) )
  1563. {
  1564. if ( FCKDomTools.HasAttribute( tag, 'sscr' ) )
  1565. {
  1566. return true ;
  1567. }
  1568. }
  1569. return false ;
  1570. } ;
  1571. /*
  1572. **************************************************************************************
  1573. * Routines to deal with conversions of absolute and relative URLs.
  1574. **************************************************************************************
  1575. */
  1576. // Constants for fundamental URL conversions.
  1577. var RELATIVE_URL = 'relative' ;
  1578. var ABSOLUTE_URL = 'absolute' ;
  1579. var SEMI_ABSOLUTE_URL = 'semi-absolute' ;
  1580. FCK.RELATIVE_URL = RELATIVE_URL ;
  1581. FCK.ABSOLUTE_URL = ABSOLUTE_URL ;
  1582. FCK.SEMI_ABSOLUTE_URL = SEMI_ABSOLUTE_URL ;
  1583. // Constants used for conversions of special relative URLs.
  1584. var REPOSITORY_RELATIVE_URL = 'repository-relative' ;
  1585. var DOCUMENT_RELATIVE_URL = 'document-relative' ;
  1586. FCK.REPOSITORY_RELATIVE_URL = REPOSITORY_RELATIVE_URL ;
  1587. FCK.DOCUMENT_RELATIVE_URL = DOCUMENT_RELATIVE_URL ;
  1588. // Conversion of selected by the file managers Flash URL.
  1589. // In introduction sections relative flash URLs do not work.
  1590. // This is why we will record semi-absolute URLs there.
  1591. FCK.GetSelectedFlashUrl = function ( url ) {
  1592. // Detection of introduction section.
  1593. if ( FCKConfig.CreateDocumentDir == 'document/' || /\.\.\/.*\/document\/$/.test( FCKConfig.CreateDocumentDir ) ) {
  1594. return FCK.GetUrl( url, SEMI_ABSOLUTE_URL ) ;
  1595. } else {
  1596. return FCK.GetSelectedUrl( url ) ;
  1597. }
  1598. }
  1599. // Conversion of selected by the file managers URLs.
  1600. FCK.GetSelectedUrl = function ( url )
  1601. {
  1602. /* Why you suppose that the url is relative? */
  1603. //url = FCK.GetUrl ( url, DOCUMENT_RELATIVE_URL ) ;
  1604. //Searching the correct type
  1605. my_type = FCK.GetUrlType (url);
  1606. url = FCK.GetUrl ( url, my_type);
  1607. if ( FCK.GetUrlType (url) != RELATIVE_URL ) {
  1608. url = FCK.GetUrl ( url, SEMI_ABSOLUTE_URL ) ;
  1609. }
  1610. return url ;
  1611. }
  1612. // Conversion of a URL into desired type.
  1613. FCK.GetUrl = function ( url, type )
  1614. {
  1615. if ( !url )
  1616. {
  1617. return url ;
  1618. }
  1619. if ( !type )
  1620. {
  1621. return url ;
  1622. }
  1623. url = url.toString().Trim() ;
  1624. if ( url.indexOf( './' ) == 0 )
  1625. {
  1626. url = url.substr( 2 );
  1627. }
  1628. switch ( type )
  1629. {
  1630. case RELATIVE_URL:
  1631. switch ( FCK.GetUrlType( url ) )
  1632. {
  1633. case RELATIVE_URL:
  1634. break ;
  1635. case ABSOLUTE_URL:
  1636. case SEMI_ABSOLUTE_URL:
  1637. url = FCK.ConvertUrl( url, RELATIVE_URL, FCKConfig.CreateDocumentWebDir ) ;
  1638. if ( FCK.GetUrlType( url ) == RELATIVE_URL )
  1639. {
  1640. url = FCK.GetUrl( url, DOCUMENT_RELATIVE_URL ) ;
  1641. }
  1642. break ;
  1643. default:
  1644. break ;
  1645. }
  1646. break ;
  1647. case REPOSITORY_RELATIVE_URL:
  1648. switch ( FCK.GetUrlType( url ) )
  1649. {
  1650. case RELATIVE_URL:
  1651. if ( url.indexOf( FCKConfig.CreateDocumentDir) == 0 )
  1652. {
  1653. url = url.substr( FCKConfig.CreateDocumentDir.length ) ;
  1654. }
  1655. break ;
  1656. case ABSOLUTE_URL:
  1657. url = FCK.ConvertUrl( url, RELATIVE_URL, FCKConfig.CreateDocumentWebDir ) ;
  1658. break ;
  1659. case SEMI_ABSOLUTE_URL:
  1660. url = FCK.ConvertUrl( url, RELATIVE_URL, FCKConfig.CreateDocumentWebDir ) ;
  1661. break ;
  1662. default:
  1663. break ;
  1664. }
  1665. break ;
  1666. case DOCUMENT_RELATIVE_URL:
  1667. switch ( FCK.GetUrlType( url ) )
  1668. {
  1669. case RELATIVE_URL:
  1670. if ( FCKConfig.CreateDocumentDir != '/' )
  1671. {
  1672. url = FCKConfig.CreateDocumentDir + url ;
  1673. }
  1674. break ;
  1675. case ABSOLUTE_URL:
  1676. case SEMI_ABSOLUTE_URL:
  1677. url = FCK.ConvertUrl( url, RELATIVE_URL, FCKConfig.CreateDocumentWebDir ) ;
  1678. if ( FCK.GetUrlType( url ) == RELATIVE_URL )
  1679. {
  1680. url = FCK.GetUrl( url, DOCUMENT_RELATIVE_URL ) ;
  1681. }
  1682. break ;
  1683. default:
  1684. break ;
  1685. }
  1686. break ;
  1687. case ABSOLUTE_URL:
  1688. switch ( FCK.GetUrlType( url ) )
  1689. {
  1690. case RELATIVE_URL:
  1691. url = FCK.GetUrl( url, REPOSITORY_RELATIVE_URL ) ;
  1692. url = FCK.ConvertUrl( url, ABSOLUTE_URL, FCKConfig.CreateDocumentWebDir) ;
  1693. break ;
  1694. case ABSOLUTE_URL:
  1695. break ;
  1696. case SEMI_ABSOLUTE_URL:
  1697. url = FCK.ConvertUrl( url, ABSOLUTE_URL, FCKConfig.CreateDocumentWebDir) ;
  1698. break ;
  1699. default:
  1700. break ;
  1701. }
  1702. break ;
  1703. case SEMI_ABSOLUTE_URL:
  1704. switch ( FCK.GetUrlType( url ) )
  1705. {
  1706. case RELATIVE_URL:
  1707. url = FCK.GetUrl( url, REPOSITORY_RELATIVE_URL ) ;
  1708. url = FCK.ConvertUrl( url, SEMI_ABSOLUTE_URL, FCKConfig.CreateDocumentWebDir) ;
  1709. break ;
  1710. case ABSOLUTE_URL:
  1711. url = FCK.ConvertUrl( url, SEMI_ABSOLUTE_URL, FCKConfig.CreateDocumentWebDir) ;
  1712. break ;
  1713. case SEMI_ABSOLUTE_URL:
  1714. break ;
  1715. default:
  1716. break ;
  1717. }
  1718. break ;
  1719. default:
  1720. break ;
  1721. }
  1722. return url ;
  1723. }
  1724. // Common URL conversion routine.
  1725. FCK.ConvertUrl = function ( url, type, base )
  1726. {
  1727. if ( !url )
  1728. {
  1729. return '' ;
  1730. }
  1731. if ( !type )
  1732. {
  1733. return '' ;
  1734. }
  1735. url = url.toString().Trim() ;
  1736. if ( url.indexOf( './' ) == 0 )
  1737. {
  1738. url = url.substr( 2 );
  1739. }
  1740. type = type.toString().Trim() ;
  1741. if ( !base )
  1742. {
  1743. base = '' ;
  1744. }
  1745. base = base.toString().Trim() ;
  1746. if ( base == '/' )
  1747. {
  1748. base = '' ;
  1749. }
  1750. switch ( type )
  1751. {
  1752. case RELATIVE_URL:
  1753. switch ( FCK.GetUrlType( url ) )
  1754. {
  1755. case ABSOLUTE_URL:
  1756. base = FCK.ConvertUrl( base, ABSOLUTE_URL ) ;
  1757. if ( url.indexOf( base ) == 0 )
  1758. {
  1759. url = url.substr( base.length ) ;
  1760. }
  1761. break ;
  1762. case SEMI_ABSOLUTE_URL:
  1763. base = FCK.ConvertUrl( base, SEMI_ABSOLUTE_URL ) ;
  1764. if ( url.indexOf( base ) == 0 )
  1765. {
  1766. url = url.substr( base.length ) ;
  1767. }
  1768. break ;
  1769. default:
  1770. break ;
  1771. }
  1772. break ;
  1773. case ABSOLUTE_URL:
  1774. switch ( FCK.GetUrlType( url ) )
  1775. {
  1776. case RELATIVE_URL:
  1777. base = FCK.ConvertUrl( base, ABSOLUTE_URL ) ;
  1778. url = base + url ;
  1779. break ;
  1780. case SEMI_ABSOLUTE_URL:
  1781. url = FCK.GetServerBase() + url.substr( 1 ) ;
  1782. break ;
  1783. default:
  1784. break ;
  1785. }
  1786. break ;
  1787. case SEMI_ABSOLUTE_URL:
  1788. switch ( FCK.GetUrlType( url ) )
  1789. {
  1790. case RELATIVE_URL:
  1791. base = FCK.ConvertUrl( base, SEMI_ABSOLUTE_URL ) ;
  1792. url = base + url ;
  1793. break ;
  1794. case ABSOLUTE_URL:
  1795. var serverBase = FCK.GetServerBase() ;
  1796. if ( serverBase == FCK.GetServerBase( url ) )
  1797. {
  1798. url = '/' + url.substr( serverBase.length ) ;
  1799. }
  1800. break ;
  1801. default:
  1802. break ;
  1803. }
  1804. break ;
  1805. default:
  1806. break ;
  1807. }
  1808. return url ;
  1809. }
  1810. // Returns type of a given URL.
  1811. // Returned values:
  1812. // RELATIVE_URL ( returned for example for images/image.png )
  1813. // SEMI_ABSOLUTE_URL ( /chamilo/courses/TEST/document/images/image.png )
  1814. // ABSOLUTE_URL ( http://localhost/chamilo/courses/TEST/document/images/image.png )
  1815. // '' - in case of error
  1816. FCK.GetUrlType = function ( url )
  1817. {
  1818. if ( !url )
  1819. {
  1820. return '' ;
  1821. }
  1822. url = url.toString().Trim() ;
  1823. if ( url.indexOf( '/' ) == 0 )
  1824. {
  1825. return SEMI_ABSOLUTE_URL ;
  1826. }
  1827. if ( url.match( /^([^:]+\:)?\/\// ) )
  1828. {
  1829. return ABSOLUTE_URL ;
  1830. }
  1831. return RELATIVE_URL ;
  1832. } ;
  1833. // Extracts the server base from a given URL.
  1834. // If the URL is omited, the function returns the base of the server where LMS runs.
  1835. // Example:
  1836. // Your site is http://www.mysite.org/chamilo
  1837. // The server base is http://www.mysite.org/
  1838. FCK.GetServerBase = function ( url )
  1839. {
  1840. if ( !url )
  1841. {
  1842. if ( FCKConfig.CreateDocumentWebDir )
  1843. {
  1844. url = FCKConfig.CreateDocumentWebDir ;
  1845. }
  1846. else
  1847. {
  1848. url = location.href ;
  1849. }
  1850. }
  1851. url = url.toString().replace( /(https?:\/\/[^\/]*)\/.*/, '$1' ) + '/' ;
  1852. return url ;
  1853. } ;
  1854. /*
  1855. **************************************************************************************
  1856. * Problem fixing.
  1857. **************************************************************************************
  1858. */
  1859. FCKEvents.prototype.FireEvent = function( eventName, params )
  1860. {
  1861. var bReturnValue = true ;
  1862. var oCalls = this._RegisteredEvents[ eventName ] ;
  1863. if ( oCalls )
  1864. {
  1865. for ( var i = 0 ; i < oCalls.length ; i++ )
  1866. {
  1867. try
  1868. {
  1869. bReturnValue = ( oCalls[ i ]( this.Owner, params ) && bReturnValue ) ;
  1870. }
  1871. catch(e)
  1872. {
  1873. // Additional patch from Ivan Tcholakov, 24-SEP-2009:
  1874. // Suppressing an error on IE8, "Object expected" -2146823281, when
  1875. // the editor unloads after "Fit Window" command has been used.
  1876. if ( e.number == -2146823281 )
  1877. {
  1878. continue ;
  1879. }
  1880. // Ignore the following error. It may happen if pointing to a
  1881. // script not anymore available (#934):
  1882. // -2146823277 = Can't execute code from a freed script
  1883. if ( e.number != -2146823277 )
  1884. throw e ;
  1885. }
  1886. }
  1887. }
  1888. return bReturnValue ;
  1889. }
  1890. // See http://dev.ckeditor.com/ticket/6322
  1891. if (navigator.userAgent.toLowerCase().match( /msie (\d+)/ )
  1892. && parseInt( navigator.userAgent.toLowerCase().match( /msie (\d+)/ )[1], 10 ) >= 9) {
  1893. // For IE9 or higher.
  1894. FCKTools.RegisterDollarFunction = function( targetWindow )
  1895. {
  1896. targetWindow.$ = function( id )
  1897. {
  1898. return targetWindow.document.getElementById( id ) ;
  1899. } ;
  1900. }
  1901. }