fckplugin.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. ImgMap plugin for FCKeditor
  3. version 0.4 14/12/2007
  4. See docs/install.html
  5. */
  6. imgmapCommand_GetState = function() {
  7. if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG )
  8. return FCK_TRISTATE_DISABLED;
  9. var oImage = FCK.Selection.GetSelectedElement() ;
  10. if ( oImage && oImage.tagName == 'IMG' )
  11. {
  12. if ( !FCK.IsRealImage( oImage ) )
  13. {
  14. return FCK_TRISTATE_DISABLED ;
  15. }
  16. // Does it has an assigned map?
  17. if (oImage.getAttribute( 'usemap' ))
  18. return FCK_TRISTATE_ON;
  19. // Plain image
  20. return FCK_TRISTATE_OFF;
  21. }
  22. // No image selected
  23. return FCK_TRISTATE_DISABLED;
  24. }
  25. /*
  26. FCKCommands.RegisterCommand( 'imgmapPopup',
  27. new FCKDialogCommand( FCKLang.imgmapDlgName, FCKLang.imgmapDlgTitle, FCKPlugins.Items['imgmap'].Path + 'popup.html', 700, 620, imgmapCommand_GetState ) ) ;
  28. */
  29. FCKCommands.RegisterCommand( 'imgmapPopup',
  30. new FCKDialogCommand( FCKLang.imgmapDlgName, FCKLang.imgmapDlgTitle, FCKPlugins.Items['imgmap'].Path + 'popup.html', 750, 580, imgmapCommand_GetState ) ) ;
  31. // create imgmap toolbar button.
  32. var imgmapButton = new FCKToolbarButton('imgmapPopup', FCKLang.imgmapBtn, null, null, false, true);
  33. // Use the proper icon according to the skin:
  34. if ( /\/editor\/skins\/(.*)\//.test(FCKConfig.SkinPath) )
  35. imgmapButton.IconPath = FCKPlugins.Items['imgmap'].Path + 'images/icon_' + RegExp.$1 + '.gif';
  36. else
  37. imgmapButton.IconPath = FCKPlugins.Items['imgmap'].Path + 'images/editor_icon.gif';
  38. FCKToolbarItems.RegisterItem('imgmapPopup', imgmapButton);
  39. // register new contextmenu
  40. FCK.ContextMenu.RegisterListener({
  41. AddItems : function( menu, tag, tagName ) {
  42. // under what circumstances do we display this option
  43. if ( FCK.IsRealImage( tag ) )
  44. {
  45. // when the option is displayed, show a separator the command
  46. //menu.AddSeparator();
  47. // the command needs the registered command name, the title for the context menu, and the icon path
  48. menu.AddItem('imgmapPopup', FCKLang.imgmapDlgTitle, imgmapButton.IconPath);
  49. }
  50. }
  51. });
  52. /*
  53. // Removed by Ivan Tcholakov, 18-DEC-2008.
  54. // The code has been added in FCKeditor 2.5, so we only need it here for previous versions.
  55. if ( !FCKRegexLib.ProtectUrlsArea )
  56. {
  57. if ( FCKBrowserInfo.IsIE )
  58. {
  59. // Fix behavior for IE, it doesn't read back the .name on newly created maps
  60. FCKXHtml.TagProcessors['map'] = function( node, htmlNode )
  61. {
  62. if ( ! node.attributes.getNamedItem( 'name' ) )
  63. {
  64. var name = htmlNode.name ;
  65. if ( name )
  66. FCKXHtml._AppendAttribute( node, 'name', name ) ;
  67. }
  68. node = FCKXHtml._AppendChildNodes( node, htmlNode, true ) ;
  69. return node ;
  70. }
  71. }
  72. // The href in the areas might get distorted by the browser.
  73. // Keep a reference to the default processsor:
  74. var imgmap_OldAreaProcessor = FCKXHtml.TagProcessors['area'] ;
  75. FCKXHtml.TagProcessors['area'] = function( node, htmlNode )
  76. {
  77. var sSavedUrl = htmlNode.getAttribute( '_fcksavedurl' ) ;
  78. if ( sSavedUrl != null )
  79. FCKXHtml._AppendAttribute( node, 'href', sSavedUrl ) ;
  80. // Call the default processor
  81. if (typeof imgmap_OldAreaProcessor == 'function')
  82. node = imgmap_OldAreaProcessor ( node, htmlNode ) ;
  83. return node ;
  84. }
  85. // Saves URLs on links and images on special attributes, so they don't change when
  86. // moving around.
  87. var imgmap_OldProtectUrls = FCK.ProtectUrls ;
  88. FCK.ProtectUrls = function( html )
  89. {
  90. html = imgmap_OldProtectUrls( html ) ;
  91. // <AREA> href
  92. html = html.replace( /<area(?=\s).*?\shref=((?:(?:\s*)("|').*?\2)|(?:[^"'][^ >]+))/gi , '$& _fcksavedurl=$1' ) ;
  93. return html ;
  94. }
  95. }
  96. */