Skip to content

Commit

Permalink
Added support for external template files to template plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
spocke committed Oct 16, 2013
1 parent 1aad724 commit 3ada498
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.txt
@@ -1,4 +1,5 @@
Version 4.0.9 (2013-10-xx)
Added support for external template files to template plugin just set the templates option to a URL with JSON data.
Fixed bug where IE would sometimes throw a "Permission denied" error unless the Sizzle doc was properly removed.
Fixed bug where lists plugin would remove outer list items if inline editable element was within a LI parent.
Fixed bug where insert table grid widget would insert a table on item to large when using a RTL language pack.
Expand Down
27 changes: 22 additions & 5 deletions js/tinymce/plugins/template/plugin.js
Expand Up @@ -13,15 +13,32 @@
tinymce.PluginManager.add('template', function(editor) {
var each = tinymce.each;

function showDialog() {
function createTemplateList(callback) {
return function() {
var templateList = editor.settings.templates;

if (typeof(templateList) == "string") {
tinymce.util.XHR.send({
url: templateList,
success: function(text) {
callback(tinymce.util.JSON.parse(text));
}
});
} else {
callback(templateList);
}
};
}

function showDialog(templateList) {
var win, values = [], templateHtml;

if (!editor.settings.templates) {
if (!templateList || templateList.length === 0) {
editor.windowManager.alert('No templates defined');
return;
}

tinymce.each(editor.settings.templates, function(template) {
tinymce.each(templateList, function(template) {
values.push({
selected: !values.length,
text: template.title,
Expand Down Expand Up @@ -208,12 +225,12 @@ tinymce.PluginManager.add('template', function(editor) {

editor.addButton('template', {
title: 'Insert template',
onclick: showDialog
onclick: createTemplateList(showDialog)
});

editor.addMenuItem('template', {
text: 'Insert template',
onclick: showDialog,
onclick: createTemplateList(showDialog),
context: 'insert'
});

Expand Down

0 comments on commit 3ada498

Please sign in to comment.