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 editor.setData( html );
\r
88 editor.insertHtml( html );
\r
94 CKEDITOR.dialog.add( 'templates', function( editor )
\r
96 // Load skin at first.
\r
97 CKEDITOR.skins.load( editor, 'templates' );
\r
100 * Load templates once.
\r
102 var isLoaded = false;
\r
105 title :editor.lang.templates.title,
\r
107 minWidth : CKEDITOR.env.ie ? 440 : 400,
\r
114 label : editor.lang.templates.title,
\r
126 editor.lang.templates.selectPromptMsg +
\r
132 '<div id="' + listId + '" class="cke_tpl_list">' +
\r
133 '<div class="cke_tpl_loading"><span></span></div>' +
\r
137 id : 'chkInsertOpt',
\r
139 label : editor.lang.templates.insertOption,
\r
140 'default' : editor.config.templates_replaceContent
\r
148 buttons : [ CKEDITOR.dialog.cancelButton ],
\r
150 onShow : function()
\r
152 CKEDITOR.loadTemplates( editor.config.templates_files, function()
\r
154 var templates = editor.config.templates.split( ',' );
\r
156 if ( templates.length )
\r
157 renderTemplatesList( editor, templates );
\r
160 var listCtEl = doc.getById( listId );
\r
162 '<div class="cke_tpl_empty">' +
\r
163 '<span>' + editor.lang.templates.emptyListMsg + '</span>' +
\r