/*
* Tooltip Plugin
*
* @author Aliocha Mazurkiewicz <contact@renska.be>
* @version 0.1.0
*/
CKEDITOR.plugins.add( 'tooltip', {
    lang: [ 'en', 'fr'],
    init: function( editor ) {
		// crée le button
		editor.ui.addButton( 'Tooltip', {
			label: editor.lang.tooltip.button,
			command: 'tooltip',
			toolbar: 'insert',
			icon: this.path + 'icons/tooltip.png'
		});
		editor.ui.addButton( 'RemoveTooltip', {
					label: editor.lang.link.unlink,
					command: 'removeTooltip',
					toolbar: 'insert',
					icon: this.path + 'icons/tooltip.png'
        } );
		
		// quand on clique sur le button, il appelle après le dialog
        editor.addCommand( 'tooltip', new CKEDITOR.dialogCommand( 'tooltipDialog' ) );
        editor.addCommand( 'removeTooltip', new CKEDITOR.removeTooltipCommand() );
		CKEDITOR.dialog.add( 'tooltipDialog', this.path + 'dialogs/tooltip.js' );
		
		
		// crée un button clique droit
		if ( editor.contextMenu ) {
			editor.addMenuGroup( 'tooltipGroup' );
			editor.addMenuItem( 'tooltipItem', {
				label: 'Editer l\'information',
				icon: this.path + 'icons/tooltip-remove.png',
				command: 'tooltip',
				group: 'tooltipGroup'
			});
		
		
		// identifie au clique droit de l'element si c'est bien un type tooltip
	
			editor.contextMenu.addListener( function( element ) {
				if ( element.getAscendant( 'em', true )) {
					if(element.hasClass('source-info')){
						return { tooltipItem: CKEDITOR.TRISTATE_OFF };
					}
				}
			});
		}
		
		// affiche l'edition au double clique
		editor.on( 'doubleclick', function( evt )
        {
				var element = evt.data.element;

				if ( element.is( 'em' ) && element.hasClass('source-info') )
					evt.data.dialog = 'tooltipDialog';

		});

    }
});

	CKEDITOR.removeTooltipCommand = function() {};
	CKEDITOR.removeTooltipCommand.prototype = {
		exec: function( editor ) {
			var style = new CKEDITOR.style( { element: 'em', type: CKEDITOR.STYLE_INLINE, alwaysRemoveElement: 1 } );
			editor.removeStyle( style );
		},

		refresh: function( editor, path ) {
			// Despite our initial hope, document.queryCommandEnabled() does not work
			// for this in Firefox. So we must detect the state by element paths.

			var element = path.lastElement && path.lastElement.getAscendant( 'em', true );

			if ( element && element.getName() == 'em' && element.getAttribute( 'title' ) && element.getChildCount() )
				this.setState( CKEDITOR.TRISTATE_OFF );
			else
				this.setState( CKEDITOR.TRISTATE_DISABLED );
		},

		contextSensitive: 1,
		startDisabled: 1,
		requiredContent: 'em[title]'
    };

@@ -1012,32 +1012,183 @@
 );%0D%0A
-%09%09%09editor.addMenuItem( '
+            // If the %22menu%22 plugin is loaded, register the menu items.%0D%0A%09%09%09            if ( editor.addMenuItems ) %7B%0D%0A%09%09%09%09            editor.addMenuItems( %7B%0D%0A%09%09%09%09%09            
 tool
@@ -1194,26 +1194,25 @@
 ltipItem
-',
+:
  %7B%0D%0A%09%09%09%09
 label: '
@@ -1199,24 +1199,38 @@
 tem: %7B%0D%0A%09%09%09%09
+%09
+%09            
 label: 'Edit
@@ -1250,24 +1250,366 @@
 tion',%0D%0A%09%09%09%09
+%09%09            command: 'tooltip',%0D%0A%09%09%09%09%09%09            group: 'tooltipGroup',%0D%0A%09%09%09%09%09%09            icon: this.path + 'icons/tooltip.png',%0D%0A%09%09%09%09%09%09            order: 1%0D%0A%09%09%09%09%09            %7D,%0D%0A%0D%0A%09%09%09%09%09            removeTooltipItem: %7B%0D%0A%09%09%09%09%09%09            label: 'Supprimer l%5C'information',%0D%0A%09%09%09%09%09%09            command: 'removeTooltip',%0D%0A%09%09%09%09%09%09            
 icon: this.p
@@ -1643,41 +1643,16 @@
 .png
-',%0D%0A%09%09%09%09command: 'tooltip
 ',%0D%0A%09%09%09%09
 grou
@@ -1647,16 +1647,30 @@
 ',%0D%0A%09%09%09%09
+%09%09
+            
 group: '
@@ -1682,24 +1682,103 @@
 ipGroup'
+,
 %0D%0A%09%09%09
-%7D);
+%09%09%09            order: 2%0D%0A%09%09%09%09%09            %7D,%0D%0A%09%09%09%09            %7D );%0D%0A            %7D
 %0D%0A%09%09%0D%0A%09%09
@@ -1959,24 +1959,48 @@
  true )) %7B%0D%0A
+%09%09%09%09    var menu = %7B%7D;%0D%0A
 %09%09%09%09%09if(elem
@@ -2040,17 +2040,18 @@
 %09%09%09%09
-return
+menu =
  %7B 
+'
 tool
@@ -2057,16 +2057,17 @@
 ltipItem
+'
 : CKEDIT
@@ -2081,18 +2081,83 @@
 TATE_OFF
- %7D
+, 'removeTooltipItem': CKEDITOR.TRISTATE_OFF  %7D;%0D%0A%09%09%09%09%09%09return menu
 ;%0D%0A%09%09%09%09%09

add remove tooltip click right