fckplugin.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * FCKeditor - The text editor for internet
  3. * Copyright (C) 2003-2005 Frederico Caldeira Knabben
  4. *
  5. * Licensed under the terms of the GNU Lesser General Public License:
  6. * http://www.opensource.org/licenses/lgpl-license.php
  7. *
  8. * For further information visit:
  9. * http://www.fckeditor.net/
  10. *
  11. * File Name: fckplugin.js
  12. *
  13. */
  14. FCKCommands.RegisterCommand('Abbr', new FCKDialogCommand( 'Abbr', FCKLang.AbbrDlgTitle, FCKPlugins.Items['Abbr'].Path + 'fck_abbr.html', 350, 300 ) ) ;
  15. // Create the "Abbr" toolbar button.
  16. var oAbbrItem = new FCKToolbarButton( 'Abbr', FCKLang.AbbrBtn ) ;
  17. oAbbrItem.IconPath = FCKPlugins.Items['Abbr'].Path + 'Abbr.gif' ;
  18. FCKToolbarItems.RegisterItem( 'Abbr', oAbbrItem ) ;
  19. // The object used for all Abbr operations.
  20. var FCKAbbr = new Object() ;
  21. // Insert a new Abbr
  22. FCKAbbr.Insert = function(val) {
  23. var hrefStartHtml = (val == '') ? '<abbr>' : '<abbr title="'+val+'">';
  24. var hrefEndHtml = '</abbr>';
  25. mySelection = ( FCKBrowserInfo.IsIE) ? FCKSelection.GetSelectedHTML() : removeBR(FCKSelection.GetSelectedHTML());
  26. hrefHtml = hrefStartHtml+mySelection+hrefEndHtml;
  27. //////////////////////////////////////////////////////
  28. // choose one of these two lines; in fckeditor 2.5 both lines can be skipped!!!
  29. //
  30. // hrefHtml = FCK.ProtectTags( hrefHtml ) ; // needed because in fckeditor 2.4 protected tags only works with SetHTML
  31. hrefHtml = ProtectTags( hrefHtml ) ; // needed because IE doesn't support <abbr> and it breaks it.
  32. /////////////////////////////////////////////////////
  33. FCK.InsertHtml(hrefHtml);
  34. }
  35. FCKSelection.GetSelectedHTML = function() { // see http://www.quirksmode.org/js/selected.html for other browsers
  36. if( FCKBrowserInfo.IsIE) { // IE
  37. var oRange = FCK.EditorDocument.selection.createRange() ;
  38. //if an object like a table is deleted, the call to GetType before getting again a range returns Control
  39. switch ( this.GetType() ) {
  40. case 'Control' :
  41. return oRange.item(0).outerHTML;
  42. case 'None' :
  43. return '' ;
  44. default :
  45. return oRange.htmlText ;
  46. }
  47. }
  48. else if ( FCKBrowserInfo.IsGecko ) { // Mozilla, Safari
  49. var oSelection = FCK.EditorWindow.getSelection();
  50. //Gecko doesn't provide a function to get the innerHTML of a selection,
  51. //so we must clone the selection to a temporary element and check that innerHTML
  52. var e = FCK.EditorDocument.createElement( 'DIV' );
  53. for ( var i = 0 ; i < oSelection.rangeCount ; i++ ) {
  54. e.appendChild( oSelection.getRangeAt(i).cloneContents() );
  55. }
  56. return e.innerHTML;
  57. }
  58. }
  59. function removeBR(input) { /* Used with Gecko */
  60. var output = "";
  61. for (var i = 0; i < input.length; i++) {
  62. if ((input.charCodeAt(i) == 13) && (input.charCodeAt(i + 1) == 10)) {
  63. i++;
  64. output += " ";
  65. }
  66. else {
  67. output += input.charAt(i);
  68. }
  69. }
  70. return output;
  71. }
  72. function ProtectTags ( html ) { // copied from _source/internals/fck.js in fckeditor 2.4
  73. // IE doesn't support <abbr> and it breaks it. Let's protect it.
  74. if ( FCKBrowserInfo.IsIE ) {
  75. var sTags = 'ABBR' ;
  76. var oRegex = new RegExp( '<(' + sTags + ')([ \>])', 'gi' ) ;
  77. html = html.replace( oRegex, '<FCK:$1$2' ) ;
  78. oRegex = new RegExp( '<\/(' + sTags + ')>', 'gi' ) ;
  79. html = html.replace( oRegex, '<\/FCK:$1>' ) ;
  80. }
  81. return html ;
  82. }
  83. // put it into the contextmenu (optional)
  84. FCK.ContextMenu.RegisterListener( {
  85. AddItems : function( menu, tag, tagName ) {
  86. // when the option is displayed, show a separator then the command
  87. //menu.AddSeparator() ;//Disabled by Chamilo. TODO:config by toolbar name teacher on/ student off
  88. // the command needs the registered command name, the title for the context menu, and the icon path
  89. //menu.AddItem( 'Abbr', FCKLang.Abbr, oAbbrItem.IconPath ) ;//Disabled by Chamilo. TODO:config by toolbar name teacher on/ student off
  90. }
  91. }
  92. );