2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
8 var doc = CKEDITOR.document;
\r
10 var listId = 'cke' + CKEDITOR.tools.getNextNumber();
\r
12 // Constructs the HTML view of the specified templates data.
\r
13 function renderTemplatesList( editor, templatesDefinitions )
\r
15 var listDiv = doc.getById( listId );
\r
17 // clear loading wait text.
\r
18 listDiv.setHtml( '' );
\r
20 for ( var i = 0 ; i < templatesDefinitions.length ; i++ )
\r
22 var definition = CKEDITOR.getTemplates( templatesDefinitions[ i ] ),
\r
23 imagesPath = definition.imagesPath,
\r
24 templates = definition.templates;
\r
26 for ( var j = 0 ; j < templates.length ; j++ )
\r
28 var template = templates[ j ];
\r
29 listDiv.append( createTemplateItem( editor, template, imagesPath ) );
\r
34 function createTemplateItem( editor, template, imagesPath )
\r
36 var div = doc.createElement( 'div' );
\r
37 div.setAttribute( 'class', 'cke_tpl_item' );
\r
39 // Build the inner HTML of our new item DIV.
\r
40 var html = '<table style="width:350px;" class="cke_tpl_preview"><tr>';
\r
42 if( template.image && imagesPath )
\r
43 html += '<td class="cke_tpl_preview_img"><img src="' + CKEDITOR.getUrl( imagesPath + template.image ) + '"></td>';
\r
45 html += '<td style="white-space:normal;"><span class="cke_tpl_title">' + template.title + '</span><br/>';
\r
47 if( template.description )
\r
48 html += '<span>' + template.description + '</span>';
\r
50 html += '</td></tr></table>';
\r
52 div.setHtml( html );
\r
54 div.on( 'mouseover', function()
\r
56 div.addClass( 'cke_tpl_hover' );
\r
59 div.on( 'mouseout', function()
\r
61 div.removeClass( 'cke_tpl_hover' );
\r
64 div.on( 'click', function()
\r
66 insertTemplate( editor, template.html );
\r
73 * Insert the specified template content
\r
75 * @param {Number} index
\r
77 function insertTemplate( editor, html )
\r
79 var dialog = CKEDITOR.dialog.getCurrent(),
\r
80 isInsert = dialog.getValueOf( 'selectTpl', 'chkInsertOpt' );
\r
84 // Everything should happen after the document is loaded (#4073).
\r
85 editor.on( 'contentDom', function( evt )
\r
87 evt.removeListener();
\r
90 // Place the cursor at the first editable place.
\r
91 var range = new CKEDITOR.dom.range( editor.document );
\r
92 range.moveToElementEditStart( editor.document.getBody() );
\r
93 range.select( true );
\r
95 editor.setData( html );
\r
99 editor.insertHtml( html );
\r
104 CKEDITOR.dialog.add( 'templates', function( editor )
\r
106 // Load skin at first.
\r
107 CKEDITOR.skins.load( editor, 'templates' );
\r
110 * Load templates once.
\r
112 var isLoaded = false;
\r
115 title :editor.lang.templates.title,
\r
117 minWidth : CKEDITOR.env.ie ? 440 : 400,
\r
124 label : editor.lang.templates.title,
\r
136 editor.lang.templates.selectPromptMsg +
\r
142 '<div id="' + listId + '" class="cke_tpl_list">' +
\r
143 '<div class="cke_tpl_loading"><span></span></div>' +
\r
147 id : 'chkInsertOpt',
\r
149 label : editor.lang.templates.insertOption,
\r
150 'default' : editor.config.templates_replaceContent
\r
158 buttons : [ CKEDITOR.dialog.cancelButton ],
\r
160 onShow : function()
\r
162 CKEDITOR.loadTemplates( editor.config.templates_files, function()
\r
164 var templates = editor.config.templates.split( ',' );
\r
166 if ( templates.length )
\r
167 renderTemplatesList( editor, templates );
\r
170 var listCtEl = doc.getById( listId );
\r
172 '<div class="cke_tpl_empty">' +
\r
173 '<span>' + editor.lang.templates.emptyListMsg + '</span>' +
\r