JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / plugins / templates / plugin.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license\r
4 */\r
5 \r
6 (function()\r
7 {\r
8         CKEDITOR.plugins.add( 'templates',\r
9                 {\r
10                         requires : [ 'dialog' ],\r
11 \r
12                         init : function( editor )\r
13                         {\r
14                                 CKEDITOR.dialog.add( 'templates', CKEDITOR.getUrl( this.path + 'dialogs/templates.js' ) );\r
15 \r
16                                 editor.addCommand( 'templates', new CKEDITOR.dialogCommand( 'templates' ) );\r
17 \r
18                                 editor.ui.addButton( 'Templates',\r
19                                         {\r
20                                                 label : editor.lang.templates.button,\r
21                                                 command : 'templates'\r
22                                         });\r
23                         }\r
24                 });\r
25 \r
26         var templates = {},\r
27                 loadedTemplatesFiles = {};\r
28 \r
29         CKEDITOR.addTemplates = function( name, definition )\r
30         {\r
31                 templates[ name ] = definition;\r
32         };\r
33 \r
34         CKEDITOR.getTemplates = function( name )\r
35         {\r
36                 return templates[ name ];\r
37         };\r
38 \r
39         CKEDITOR.loadTemplates = function( templateFiles, callback )\r
40         {\r
41                 // Holds the templates files to be loaded.\r
42                 var toLoad = [];\r
43 \r
44                 // Look for pending template files to get loaded.\r
45                 for ( var i = 0 ; i < templateFiles.length ; i++ )\r
46                 {\r
47                         if ( !loadedTemplatesFiles[ templateFiles[ i ] ] )\r
48                         {\r
49                                 toLoad.push( templateFiles[ i ] );\r
50                                 loadedTemplatesFiles[ templateFiles[ i ] ] = 1;\r
51                         }\r
52                 }\r
53 \r
54                 if ( toLoad.length > 0 )\r
55                         CKEDITOR.scriptLoader.load( toLoad, callback );\r
56                 else\r
57                         setTimeout( callback, 0 );\r
58         };\r
59 })();\r
60 \r
61 \r
62 \r
63 /**\r
64  * The templates definition set to use. It accepts a list of names separated by\r
65  * comma. It must match definitions loaded with the templates_files setting.\r
66  * @type String\r
67  * @default 'default'\r
68  * @example\r
69  * config.templates = 'my_templates';\r
70  */\r
71 CKEDITOR.config.templates = 'default';\r
72 \r
73 /**\r
74  * The list of templates definition files to load.\r
75  * @type (String) Array\r
76  * @default [ 'plugins/templates/templates/default.js' ]\r
77  * @example\r
78  * config.templates_files =\r
79  *     [\r
80  *         '/editor_templates/site_default.js',\r
81  *         'http://www.example.com/user_templates.js\r
82  *     ];\r
83  *\r
84  */\r
85 CKEDITOR.config.templates_files =\r
86         [\r
87                 CKEDITOR.getUrl(\r
88                         '_source/' + // @Packager.RemoveLine\r
89                         'plugins/templates/templates/default.js' )\r
90         ];\r
91 \r
92 /**\r
93  * Whether the "Replace actual contents" checkbox is checked by default in the\r
94  * Templates dialog.\r
95  * @type Boolean\r
96  * @default true\r
97  * @example\r
98  * config.templates_replaceContent = false;\r
99  */\r
100 CKEDITOR.config.templates_replaceContent = true;\r