Opened 11 years ago

Last modified 11 years ago

#10188 confirmed New Feature

Append template option to templates plugin

Reported by: Matti Järvinen Owned by:
Priority: Normal Milestone:
Component: General Version: 4.0 Beta
Keywords: Cc: matti.jarvinen@…

Description

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' ]
	]
}

Change History (3)

comment:1 Changed 11 years ago by Matti Järvinen

Cc: matti.jarvinen@… added

comment:2 Changed 11 years ago by Jakub Ś

Version: 4.0 Beta

@matti extending existing plugin to append data at the end (or start - this can be also added) of document sounds interesting.

To get your proposed fix/feature tested and applied (if it is correct) please fork CKEditor 4 code from https://github.com/ckeditor/ckeditor-dev, prepare your fix and make a "pull request" (here is the example list of pull requests https://github.com/ckeditor/ckeditor-dev/pulls?direction=desc&page=1&sort=created&state=open). In comment please specify link to bug for which this fix was prepared. This is much faster way to get proposed fix/feature implemented/rejected (if they are invalid). At least in V4.

comment:3 Changed 11 years ago by Jakub Ś

Status: newconfirmed
Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy