﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
10188	Append template option to templates plugin	Matti Järvinen		"Proposal for templates plugin expansion for adding an option to append selected template into editor data.

Sometimes and especially with responsive web design it would be very helpful if templates plugin would have an option to append selected template into editor HTML instead of just replacing whole content with a template or inserting template into cursor position.

Quick prototype solution below.

templates/dialogs/templates.js
{{{
function insertTemplate( html ) {
	var dialog = CKEDITOR.dialog.getCurrent(),
		replaceType = dialog.getValueOf( 'selectTpl', 'chkInsertOpt' );

	switch(replaceType)
	{
		case 'append':
			
			editor.fire( 'saveSnapshot' );
			// Everything should happen after the document is loaded (#4073).
			
			var currentHTML = editor.getData( );
			
			editor.setData( currentHTML + html, function() {
				dialog.hide();

				// Place the cursor at the first editable place.
				var range = editor.createRange();
				range.moveToElementEditStart( editor.editable() );
				range.select();
				setTimeout( function() {
					editor.fire( 'saveSnapshot' );
				}, 0 );

			} );
			
			break;
		case 'replace':
			
			editor.fire( 'saveSnapshot' );
			// Everything should happen after the document is loaded (#4073).
			editor.setData( html, function() {
				dialog.hide();

				// Place the cursor at the first editable place.
				var range = editor.createRange();
				range.moveToElementEditStart( editor.editable() );
				range.select();
				setTimeout( function() {
					editor.fire( 'saveSnapshot' );
				}, 0 );

			} );
			
			break;
			
		case 'in-place':
		default:
			
			editor.insertHtml( html );
			dialog.hide();
			
			break;
	}
}
}}}

templates/dialogs/templates.js dialog definition.
{{{
{
	id: 'chkInsertOpt',
	type: 'select',
	label: lang.insertOption,
	style: 'width:100%',
	'default': config.templates_replaceContent,
	items: [
	[ 'append' ],
	[ 'in-place' ],
	[ 'replace' ]
	]
}
}}}"	New Feature	confirmed	Normal		General	4.0 Beta			matti.jarvinen@…
