1 /*
  2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
  3 For licensing, see LICENSE.html or http://ckeditor.com/license
  4 */
  5
  6 (function()
  7 {
  8 	CKEDITOR.plugins.add( 'templates',
  9 		{
 10 			requires : [ 'dialog' ],
 11
 12 			init : function( editor )
 13 			{
 14 				CKEDITOR.dialog.add( 'templates', CKEDITOR.getUrl( this.path + 'dialogs/templates.js' ) );
 15
 16 				editor.addCommand( 'templates', new CKEDITOR.dialogCommand( 'templates' ) );
 17
 18 				editor.ui.addButton( 'Templates',
 19 					{
 20 						label : editor.lang.templates.button,
 21 						command : 'templates'
 22 					});
 23 			}
 24 		});
 25
 26 	var templates = {},
 27 		loadedTemplatesFiles = {};
 28
 29 	CKEDITOR.addTemplates = function( name, definition )
 30 	{
 31 		templates[ name ] = definition;
 32 	};
 33
 34 	CKEDITOR.getTemplates = function( name )
 35 	{
 36 		return templates[ name ];
 37 	};
 38
 39 	CKEDITOR.loadTemplates = function( templateFiles, callback )
 40 	{
 41 		// Holds the templates files to be loaded.
 42 		var toLoad = [];
 43
 44 		// Look for pending template files to get loaded.
 45 		for ( var i = 0 ; i < templateFiles.length ; i++ )
 46 		{
 47 			if ( !loadedTemplatesFiles[ templateFiles[ i ] ] )
 48 			{
 49 				toLoad.push( templateFiles[ i ] );
 50 				loadedTemplatesFiles[ templateFiles[ i ] ] = 1;
 51 			}
 52 		}
 53
 54 		if ( toLoad.length > 0 )
 55 			CKEDITOR.scriptLoader.load( toLoad, callback );
 56 		else
 57 			setTimeout( callback, 0 );
 58 	};
 59 })();
 60
 61
 62
 63 /**
 64  * The templates definition set to use. It accepts a list of names separated by
 65  * comma. It must match definitions loaded with the templates_files setting.
 66  * @type String
 67  * @default 'default'
 68  */
 69 CKEDITOR.config.templates = 'default';
 70
 71 /**
 72  * The list of templates definition files to load.
 73  * @type (String) Array
 74  * @default [ 'plugins/templates/templates/default.js' ]
 75  */
 76 CKEDITOR.config.templates_files =
 77 	[
 78 		CKEDITOR.getUrl(
 80 			'plugins/templates/templates/default.js' )
 81 	];
 82
 83 /**
 84  * Whether replace the current document content OR insert current
 85  * editing position.
 86  * @type Boolean
 87  * @default true
 88  */
 89 CKEDITOR.config.templates_replaceContent = true;
 90