71 | | } |
72 | | |
| 71 | }, |
| 72 | |
| 73 | toolbar : |
| 74 | { |
| 75 | /** |
| 76 | * Click on a specific toolbar button and the {@param callback} will be |
| 77 | * fed with the consequential UI object which has been opened by this click. |
| 78 | * |
| 79 | * @param itemName The toolbar item definition name. |
| 80 | * @callback The callback function which is called after the affiliate |
| 81 | * button behavior has completed. |
| 82 | * @example |
| 83 | * |
| 84 | * // Click on 'Format' combo. |
| 85 | * CKEDITOR.test.toolbar.clickButton( 'Format' , |
| 86 | * function( combo ) |
| 87 | * { |
| 88 | * alert( combo instanceof CKEDITOR.ui.richCombo ); // true |
| 89 | * }); |
| 90 | * |
| 91 | * // Click on 'Image' dialog. |
| 92 | * CKEDITOR.test.toolbar.clickButton( 'Image' , |
| 93 | * function( dialog ) |
| 94 | * { |
| 95 | * alert( dialog instanceof CKEDITOR.dialog ); // true |
| 96 | * }); |
| 97 | */ |
| 98 | clickButton : function( editor, itemName, callback, context ) |
| 99 | { |
| 100 | var ui = editor.ui, |
| 101 | // Find the corresponding ui instances of the toolbar item. |
| 102 | uiItems = ui._.items, |
| 103 | uiItem =uiItems[ itemName ], |
| 104 | // Back reference the toolbar item instance. |
| 105 | toolbarItem = uiItem.toolbarItem, |
| 106 | // Find the command instance registered on this ui item. |
| 107 | command = editor.getCommand( uiItem.command ); |
| 108 | |
| 109 | // Special treatments for different types of button. |
| 110 | if( uiItem instanceof CKEDITOR.ui.button ) |
| 111 | { |
| 112 | // button of style command. |
| 113 | if( command && command.style ) |
| 114 | { |
| 115 | editor.on( 'selectionChange', function( evt ) |
| 116 | { |
| 117 | evt.removeListener(); |
| 118 | callback.call( context ); |
| 119 | }, null, null, 1000 ); |
| 120 | } |
| 121 | // button of dialog command. |
| 122 | if( command && command.dialogName ) |
| 123 | { |
| 124 | editor.on( 'dialogOpen', function( evt ) |
| 125 | { |
| 126 | evt.removeListener(); |
| 127 | callback.call( context, evt.data ); |
| 128 | }, null, null, 1000 ); |
| 129 | } |
| 130 | // button of panel. |
| 131 | else if( uiItem instanceof CKEDITOR.ui.panelButton ) |
| 132 | { |
| 133 | uiItem.on( 'open', function( evt ) |
| 134 | { |
| 135 | evt.removeListener(); |
| 136 | callback.call( context, uiItem ); |
| 137 | }, null, 1000 ); |
| 138 | } |
| 139 | // Trigger button. |
| 140 | toolbarItem.execute(); |
| 141 | } |
| 142 | else if( uiItem instanceof CKEDITOR.ui.richCombo ) |
| 143 | { |
| 144 | uiItem.on( 'open', function( evt ) |
| 145 | { |
| 146 | evt.removeListener(); |
| 147 | callback.call( context, uiItem ); |
| 148 | }, null, 1000 ); |
| 149 | |
| 150 | // Trigger combo. |
| 151 | var comboEntry = YAHOO.util.Selector.query( 'a', toolbarItem.id, true ); |
| 152 | comboEntry.onclick(); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | }, |
| 157 | |
| 158 | dialog : |
| 159 | { |
| 160 | /** |
| 161 | * Filling the assigned dialog with a specified set of field values and finally close it. |
| 162 | * @param dialog {CKEDITOR.dialog} The dialog instance to populate. |
| 163 | * @param profile {Object} The page - field - value map to be filled into the dialog. |
| 164 | * @example |
| 165 | * CKEDITOR.test.dialog.fill( imageDialog, |
| 166 | * { |
| 167 | * info : |
| 168 | * { |
| 169 | * txtUrl : 'http://ckeditor.com/logos.gif' |
| 170 | * }, |
| 171 | * Link : |
| 172 | * { |
| 173 | * txtUrl : 'http://ckeditor.com' |
| 174 | * }, |
| 175 | * advanced : |
| 176 | * { |
| 177 | * linkId : 'link_id1', |
| 178 | * txtGenClass : 'cls' |
| 179 | * } |
| 180 | * } ); |
| 181 | * |
| 182 | */ |
| 183 | fill : function ( dialog, profile ) |
| 184 | { |
| 185 | var field, page; |
| 186 | for( var pageName in profile ) |
| 187 | { |
| 188 | // Activate the page. |
| 189 | dialog.selectPage( pageName ); |
| 190 | |
| 191 | page = profile[ pageName ]; |
| 192 | for( var fieldId in page ) |
| 193 | { |
| 194 | field = dialog.getContentElement( pageName, fieldId ); |
| 195 | // Populate the field. |
| 196 | field.setValue( page[ fieldId ] ); |
| 197 | } |
| 198 | } |
| 199 | dialog.click( 'ok' ); |
| 200 | } |
| 201 | |
| 202 | }, |
| 203 | |
| 204 | editor : |
| 205 | { |
| 206 | /** |
| 207 | * Load the editor with specified content and the denoted selection within it. |
| 208 | * @param editor |
| 209 | * @param data {String} String presentation of the HTML and selection range marker. |
| 210 | * @example |
| 211 | * CKEDITOR.test.editor.loadDataWithSelection( editor, |
| 212 | * "<p>This is some <strong>[sample text]</strong>.</p>" ); |
| 213 | */ |
| 214 | loadDataWithSelection : function( editor, data ) |
| 215 | { |
| 216 | var docBody = editor.document.getBody(); |
| 217 | CKEDITOR.test.setHtmlWithSelection( docBody, data ); |
| 218 | }, |
| 219 | |
| 220 | /** |
| 221 | * Set the editor selection to what the start/end position denote. |
| 222 | * @param editor |
| 223 | * @param {Array} startPosition The expected range startContainer address plus startOffset. |
| 224 | * @param {Array} endPosition The expected range endContainer address plus endOffset. |
| 225 | * @example |
| 226 | * // Make the selection as: <p>[text] selection</p> |
| 227 | * CKEDITOR.test.editor.makeSelection( editor, [ 1, 0, 0, 0 ], [ 1, 0, 0, 4 ] ); |
| 228 | */ |
| 229 | makeSelection : function( editor, startPosition, endPosition ) |
| 230 | { |
| 231 | editor.getSelection().selectBookmarks( [ { |
| 232 | start : startPosition.slice( 0, startPosition.length - 1 ), |
| 233 | startOffset : startPosition[ startPosition.length -1 ], |
| 234 | end : endPosition == true ? null : endPosition.slice( 0, endPosition.length - 1 ), |
| 235 | endOffset : endPosition[ endPosition.length -1 ], |
| 236 | is2: true |
| 237 | } ] ); |
| 238 | }, |
| 239 | |
| 240 | /** |
| 241 | * Simulating type into the editor document char by char. |
| 242 | * Note: The document content will not be updated with this method, so |
| 243 | * it should only be used with those keystrokes whose handlers are defined |
| 244 | * by the editor. |
| 245 | * @param editor |
| 246 | * @param {String} sequences A sequence of ASCII characters, each of |
| 247 | * which represent a key stroke with the corresponding charCode, the modifier |
| 248 | * keys are denoted by the following syntax: |
| 249 | * 1. Ctrl : [] |
| 250 | * 2. Shfit : () |
| 251 | * 3. Alt : {} |
| 252 | * @example |
| 253 | * Type shift-enter key on the cursor position: |
| 254 | * CKEDITOR.test.editor.type( editor, "(\r)"); |
| 255 | */ |
| 256 | type : function( editor, sequences ) |
| 257 | { |
| 258 | var ctrl, alt, shift; |
| 259 | sequences.replace( /([()\[\]{}]*)([^()\[\]{}]+)/g, function( match, modifiers, keys ) |
| 260 | { |
| 261 | // Checking modifiers state. |
| 262 | for( var i = 0 ; i < modifiers.length ; i++ ) |
| 263 | { |
| 264 | var modifier = modifiers.charAt( i ); |
| 265 | switch( modifier ) |
| 266 | { |
| 267 | case '[' : |
| 268 | case ']' : |
| 269 | ctrl = modifier == '[' ? 1 : 0; |
| 270 | break; |
| 271 | case '(' : |
| 272 | case ')' : |
| 273 | shift = modifier == '(' ? 1 : 0; |
| 274 | break; |
| 275 | case '{' : |
| 276 | case '}' : |
| 277 | alt = modifier == '{' ? 1 : 0; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | // Simulating key strokes. |
| 282 | for( i = 0 ; i < keys.length ; i++ ) |
| 283 | { |
| 284 | var keyStroke = |
| 285 | { |
| 286 | charCode: keys.charCodeAt( i ), |
| 287 | keyCode : keys.charCodeAt( i ), |
| 288 | ctrlKey : !!ctrl, |
| 289 | altKey : !!alt, |
| 290 | shiftKey : !!shift |
| 291 | }, |
| 292 | target = editor.document.getBody().$; |
| 293 | |
| 294 | YAHOO.util.UserAction.keydown( target, keyStroke ); |
| 295 | YAHOO.util.UserAction.keyup( target, keyStroke ); |
| 296 | } |
| 297 | } ); |
| 298 | } |
| 299 | } |