function wysiwyg_template_list_js in Wysiwyg API template plugin 7.2
Generate javascript for template loading
1 string reference to 'wysiwyg_template_list_js'
- wysiwyg_template_menu in ./
wysiwyg_template.module - Implementation of hook_menu().
File
- ./
wysiwyg_template.module, line 244 - Makes TinyMCE Templates available as plugin for client-side editors integrated via Wysiwyg API.
Code
function wysiwyg_template_list_js($editorName, $contentType) {
global $base_url;
//don't cache templates
drupal_add_http_header('CacheControl', 'no-cache');
drupal_add_http_header('Expires', '-1');
drupal_add_http_header('Content-Type', 'text/javascript; charset=UTF-8');
$templates = wysiwyg_template_load_all($contentType);
switch ($editorName) {
case 'tinymce':
print 'var tinyMCETemplateList = ';
$outArray = array();
foreach ($templates as $template) {
$outArray[] = array(
$template['title'],
url('wysiwyg-templates/' . $editorName . '/load/') . $template['name'],
$template['description'],
);
}
print json_encode($outArray) . ";";
break;
case 'ckeditor':
print "CKEDITOR.addTemplates( 'default', { imagesPath:'" . $base_url . "', templates: ";
// load the templates into the json array structure
foreach ($templates as &$template) {
$template['html'] = $template['body'];
unset($template['body']);
unset($template['tid']);
}
print json_encode($templates);
print "});";
break;
case 'fckeditor':
print '<?xml version="1.0" encoding="utf-8" ?>';
print '<Templates imagesBasePath="">';
foreach ($templates as $template) {
print '<Template title="' . check_plain($template['title']) . '" image="">';
print '<Description>' . check_plain($template['description']) . '</Description>';
print '<Html><![CDATA[';
print $template['body'];
print ']]></Html></Template>';
}
print '</Templates>';
break;
case '':
break;
}
}