| 1 | /* |
| 2 | Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. |
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license |
| 4 | */ |
| 5 | |
| 6 | CKEDITOR.plugins.add( 'devtools', |
| 7 | { |
| 8 | requires : [ 'dialog' ], |
| 9 | lang : [ 'en' ], |
| 10 | |
| 11 | init : function( editor ) |
| 12 | { |
| 13 | editor._.showDialogDefinitionTooltips = 1; |
| 14 | }, |
| 15 | onLoad : function() |
| 16 | { |
| 17 | CKEDITOR.document.appendStyleText( CKEDITOR.config.devtools_styles || |
| 18 | '#cke_tooltip { padding: 5px; border: 2px solid #333; background: #ffffff }' + |
| 19 | '#cke_tooltip h2 { font-size: 1.1em; border-bottom: 1px solid; margin: 0; padding: 1px; }' + |
| 20 | '#cke_tooltip ul { padding: 0pt; list-style-type: none; }' ); |
| 21 | } |
| 22 | }); |
| 23 | |
| 24 | (function() |
| 25 | { |
| 26 | function defaultCallback( editor, dialog, element, tabName ) |
| 27 | { |
| 28 | var lang = editor.lang.devTools, |
| 29 | link = '<a href="http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dialog.definition.' + |
| 30 | ( element ? ( element.type == 'text' ? 'textInput' : element.type ) : 'content' ) + |
| 31 | '.html" target="_blank">' + ( element ? element.type : 'content' ) + '</a>', |
| 32 | str = |
| 33 | '<h2>' + lang.title + '</h2>' + |
| 34 | '<ul>' + |
| 35 | '<li><strong>' + lang.dialogName + '</strong> : ' + dialog.getName() + '</li>' + |
| 36 | '<li><strong>' + lang.tabName + '</strong> : ' + tabName + '</li>'; |
| 37 | |
| 38 | if ( element ) |
| 39 | str += '<li><strong>' + lang.elementId + '</strong> : ' + element.id + '</li>'; |
| 40 | |
| 41 | str += '<li><strong>' + lang.elementType + '</strong> : ' + link + '</li>'; |
| 42 | |
| 43 | return str + '</ul>'; |
| 44 | } |
| 45 | |
| 46 | function showTooltip( callback, el, editor, dialog, obj, tabName ) |
| 47 | { |
| 48 | var pos = el.getDocumentPosition(), |
| 49 | styles = { 'z-index' : CKEDITOR.dialog._.currentZIndex + 10, top : ( pos.y + el.getSize( 'height' ) ) + 'px' }; |
| 50 | |
| 51 | tooltip.setHtml( callback( editor, dialog, obj, tabName ) ); |
| 52 | tooltip.show(); |
| 53 | |
| 54 | // Translate coordinate for RTL. |
| 55 | if ( editor.lang.dir == 'rtl' ) |
| 56 | { |
| 57 | var viewPaneSize = CKEDITOR.document.getWindow().getViewPaneSize(); |
| 58 | styles.right = ( viewPaneSize.width - pos.x - el.getSize( 'width' ) ) + 'px'; |
| 59 | } |
| 60 | else |
| 61 | styles.left = pos.x + 'px'; |
| 62 | |
| 63 | tooltip.setStyles( styles ); |
| 64 | } |
| 65 | |
| 66 | var tooltip; |
| 67 | CKEDITOR.on( 'reset', function() |
| 68 | { |
| 69 | tooltip && tooltip.remove(); |
| 70 | tooltip = null; |
| 71 | }); |
| 72 | |
| 73 | CKEDITOR.on( 'dialogDefinition', function( evt ) |
| 74 | { |
| 75 | var editor = evt.editor; |
| 76 | if ( editor._.showDialogDefinitionTooltips ) |
| 77 | { |
| 78 | if ( !tooltip ) |
| 79 | { |
| 80 | tooltip = CKEDITOR.dom.element.createFromHtml( '<div id="cke_tooltip" tabindex="-1" style="position: absolute"></div>', CKEDITOR.document ); |
| 81 | tooltip.hide(); |
| 82 | tooltip.on( 'mouseover', function(){ this.show(); } ); |
| 83 | tooltip.on( 'mouseout', function(){ this.hide(); } ); |
| 84 | tooltip.appendTo( CKEDITOR.document.getBody() ); |
| 85 | } |
| 86 | |
| 87 | var dialog = evt.data.definition.dialog, |
| 88 | callback = editor.config.devtools_textCallback || defaultCallback; |
| 89 | |
| 90 | dialog.on( 'load', function() |
| 91 | { |
| 92 | var tabs = dialog.parts.tabs.getChildren(), tab; |
| 93 | for ( var i = 0, len = tabs.count(); i < len; i++ ) |
| 94 | { |
| 95 | tab = tabs.getItem( i ); |
| 96 | tab.on( 'mouseover', function() |
| 97 | { |
| 98 | var id = this.$.id; |
| 99 | showTooltip( callback, this, editor, dialog, null, id.substring( 4, id.lastIndexOf( '_' ) ) ); |
| 100 | }); |
| 101 | tab.on( 'mouseout', function() |
| 102 | { |
| 103 | tooltip.hide(); |
| 104 | }); |
| 105 | } |
| 106 | |
| 107 | dialog.foreach( function( obj ) |
| 108 | { |
| 109 | if ( obj.type in { hbox : 1, vbox : 1 } ) |
| 110 | return; |
| 111 | |
| 112 | var el = obj.getElement(); |
| 113 | if ( el ) |
| 114 | { |
| 115 | el.on( 'mouseover', function() |
| 116 | { |
| 117 | showTooltip( callback, this, editor, dialog, obj, dialog._.currentTabId ); |
| 118 | }); |
| 119 | el.on( 'mouseout', function() |
| 120 | { |
| 121 | tooltip.hide(); |
| 122 | }); |
| 123 | } |
| 124 | }); |
| 125 | }); |
| 126 | } |
| 127 | }); |
| 128 | })(); |
| 129 | |
| 130 | /** |
| 131 | * A function that returns the text to be displayed inside the developer tooltip when hovering over a dialog UI element. |
| 132 | * There are 4 parameters that are being passed into the function: editor, dialog, element, tab name. |
| 133 | * @name editor.config.devtools_textCallback |
| 134 | * @since 3.6 |
| 135 | * @type Function |
| 136 | * @default (see example) |
| 137 | * @example |
| 138 | * // This is actually the default value. |
| 139 | * // Show dialog name, tab id and element id. |
| 140 | * config.devtools_textCallback = function( editor, dialog, element, tabName ) |
| 141 | * { |
| 142 | * var lang = editor.lang.devTools, |
| 143 | * link = '<a href="http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.dialog.definition.' + |
| 144 | * ( element ? ( element.type == 'text' ? 'textInput' : element.type ) : 'content' ) + |
| 145 | * '.html" target="_blank">' + ( element ? element.type : 'content' ) + '</a>', |
| 146 | * str = |
| 147 | * '<h2>' + lang.title + '</h2>' + |
| 148 | * '<ul>' + |
| 149 | * '<li><strong>' + lang.dialogName + '</strong> : ' + dialog.getName() + '</li>' + |
| 150 | * '<li><strong>' + lang.tabName + '</strong> : ' + tabName + '</li>'; |
| 151 | * |
| 152 | * if ( element ) |
| 153 | * str += '<li><strong>' + lang.elementId + '</strong> : ' + element.id + '</li>'; |
| 154 | * |
| 155 | * str += '<li><strong>' + lang.elementType + '</strong> : ' + link + '</li>'; |
| 156 | * |
| 157 | * return str + '</ul>'; |
| 158 | * } |
| 159 | */ |
| 160 | |
| 161 | /** |
| 162 | * A setting that holds CSS rules to be injected do page and contain styles to be applied to the tooltip element. |
| 163 | * @name CKEDITOR.config.devtools_styles |
| 164 | * @since 3.6 |
| 165 | * @type String |
| 166 | * @default (see example) |
| 167 | * @example |
| 168 | * // This is actually the default value. |
| 169 | * CKEDITOR.config.devtools_styles = " |
| 170 | * #cke_tooltip { padding: 5px; border: 2px solid #333; background: #ffffff } |
| 171 | * #cke_tooltip h2 { font-size: 1.1em; border-bottom: 1px solid; margin: 0; padding: 1px; } |
| 172 | * #cke_tooltip ul { padding: 0pt; list-style-type: none; } |
| 173 | * "; |
| 174 | */ |