fckplugin.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Chamilo LMS
  3. *
  4. * Copyright (c) 2010 Ivan Tcholakov <ivantcholakov@gmail.com>
  5. *
  6. * License:
  7. * GNU Lesser General Public License, Version 3, 29 June 2007
  8. * by Free Software Foundation, Inc. (http://www.gnu.org/licenses/lgpl.html)
  9. */
  10. // Loading the ASCIIMathML.js if it is not present yet.
  11. if ( typeof AMprocessNode != 'function' )
  12. {
  13. LoadScript( FCKConfig.ScriptASCIIMathML ) ;
  14. }
  15. // Settings for ASCIIMathML.js
  16. // Suppressing the built-in notification messages when the browser is incompatible.
  17. var notifyIfNoMathML = false ;
  18. var alertIfNoMathML = false;
  19. var notifyIfNoSVG = false;
  20. var alertIfNoSVG = false;
  21. // Suppressing automatic parsing of the document at loading, the editor is to initate this.
  22. var translateASCIIMath = false ;
  23. // Registering the related command.
  24. FCKCommands.RegisterCommand( 'asciisvg', new FCKDialogCommand( FCKLang['DlgAsciiSvg'], FCKLang['DlgAsciiSvgGraphEditor'], FCKConfig.PluginsPath + 'asciisvg/fck_asciisvg.html', 750, 550 ) ) ;
  25. // Create the "asciisvg" toolbar button.
  26. var oAsciiSvgItem = new FCKToolbarButton( 'asciisvg', FCKLang['DlgAsciiSvg'] ) ;
  27. oAsciiSvgItem.IconPath = FCKConfig.PluginsPath + 'asciisvg/asciisvg.gif' ;
  28. // 'asciisvg' is the name used in the Toolbar config.
  29. FCKToolbarItems.RegisterItem( 'asciisvg', oAsciiSvgItem ) ;
  30. // Context menu support.
  31. FCK.ContextMenu.RegisterListener( {
  32. AddItems : function( menu, tag, tagName )
  33. {
  34. if ( tag.tagName == 'IMG' && tag.getAttribute( '_fckasciisvg' ) )
  35. {
  36. menu.AddSeparator() ;
  37. menu.AddItem( 'asciisvg', FCKLang['DlgAsciiSvg'], oAsciiSvgItem.IconPath ) ;
  38. }
  39. }}
  40. );
  41. // Double-click support.
  42. FCK.RegisterDoubleClickHandler(
  43. function ( tag )
  44. {
  45. if ( tag.tagName == 'IMG' && tag.getAttribute( '_fckasciisvg' ) )
  46. {
  47. FCKCommands.GetCommand( 'asciisvg' ).Execute() ;
  48. }
  49. }, null
  50. ) ;
  51. var FCKAsciiSvg = new Object() ;
  52. // We need to attach automaticaly the script AsciiMathML.js when saving a full page.
  53. FCKAsciiSvg.UpdateLinkedField = FCK.UpdateLinkedField ;
  54. FCK.UpdateLinkedField = function()
  55. {
  56. if ( FCKConfig.FullPage )
  57. {
  58. var html = FCK.EditorDocument.getElementsByTagName('html')[0] ;
  59. var head ;
  60. var body ;
  61. if ( typeof html == 'object' )
  62. {
  63. head = html.getElementsByTagName( 'HEAD' )[0] ;
  64. }
  65. if ( typeof head == 'object' )
  66. {
  67. var doc_data = FCK.GetData( false );
  68. var has_graph = false ;
  69. var has_script = false ;
  70. if ( doc_data )
  71. {
  72. if ( doc_data.toString().match( /<embed[^>]*sscr=[^>]*>/i ) )
  73. {
  74. has_graph = true ;
  75. }
  76. head_data = doc_data.toString().match( /<head[^>]*>(.*?)<\/head\s*>/i ) ;
  77. if ( head_data && head_data.toString().indexOf( 'ASCIIMathML.js' ) != -1 )
  78. {
  79. has_script = true ;
  80. }
  81. }
  82. if ( has_graph && !has_script )
  83. {
  84. // TODO: This fragment works in WYSIWYG mode only.
  85. script = FCK.EditorDocument.createElement( 'script' ) ;
  86. script.setAttribute( 'src', FCKConfig.ScriptASCIIMathML ) ;
  87. script.setAttribute( 'type', 'text/javascript' ) ;
  88. head.appendChild( script ) ;
  89. }
  90. }
  91. }
  92. // Calling the original method FCK.UpdateLinkedField().
  93. FCKAsciiSvg.UpdateLinkedField() ;
  94. } ;