/*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
For licensing, see LICENSE.html or http://ckeditor.com/license\r
*/\r
\r
// Build the inner HTML of our new item DIV.\r
var html = '<table style="width:350px;" class="cke_tpl_preview"><tr>';\r
\r
- if( template.image && imagesPath )\r
+ if ( template.image && imagesPath )\r
html += '<td class="cke_tpl_preview_img"><img src="' + CKEDITOR.getUrl( imagesPath + template.image ) + '"></td>';\r
\r
html += '<td style="white-space:normal;"><span class="cke_tpl_title">' + template.title + '</span><br/>';\r
\r
- if( template.description )\r
+ if ( template.description )\r
html += '<span>' + template.description + '</span>';\r
\r
html += '</td></tr></table>';\r
var dialog = CKEDITOR.dialog.getCurrent(),\r
isInsert = dialog.getValueOf( 'selectTpl', 'chkInsertOpt' );\r
\r
- if( isInsert )\r
+ if ( isInsert )\r
{\r
+ // Everything should happen after the document is loaded (#4073).\r
+ editor.on( 'contentDom', function( evt )\r
+ {\r
+ evt.removeListener();\r
+ dialog.hide();\r
+\r
+ // Place the cursor at the first editable place.\r
+ var range = new CKEDITOR.dom.range( editor.document );\r
+ range.moveToElementEditStart( editor.document.getBody() );\r
+ range.select( true );\r
+ setTimeout( function ()\r
+ {\r
+ editor.fire( 'saveSnapshot' );\r
+ }, 0 );\r
+ } );\r
+\r
+ editor.fire( 'saveSnapshot' );\r
editor.setData( html );\r
}\r
else\r
{\r
editor.insertHtml( html );\r
+ dialog.hide();\r
}\r
-\r
- dialog.hide();\r
}\r
\r
CKEDITOR.dialog.add( 'templates', function( editor )\r