1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
// Import external list url javascript
var url = tinyMCE.getParam("template_external_list_url");
if (url != null) {
// Fix relative
if (url.charAt(0) != '/' && url.indexOf('://') == -1)
url = tinyMCE.documentBasePath + "/" + url;
document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></sc'+'ript>');
}
var TPU = { //Template Popup Utils
currentTemplateHTML : null,
templates : [],
inst : tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id')),
plugin : tinyMCE.getWindowArg('pluginObj'),
data : tinyMCE.selectedInstance.getData('template'),
init : function() {
document.forms[0].insert.value = tinyMCE.getLang('lang_' + this.data.currentAction, 'Insert', true);
TPU.loadTemplatePaths();
if (this.data.currentAction == "update")
document.getElementById('warning').innerHTML = tinyMCE.getLang('lang_template_warning');
this.resizeInputs();
},
loadTemplatePaths : function() {
var tsrc, sel, x, u;
tsrc = tinyMCE.getParam("template_templates", false);
sel = document.getElementById('tpath');
// Setup external template list
if (!tsrc && typeof(tinyMCETemplateList) != 'undefined') {
for (x=0, tsrc = []; x<tinyMCETemplateList.length; x++)
tsrc.push({title : tinyMCETemplateList[x][0], src : tinyMCETemplateList[x][1], description : tinyMCETemplateList[x][2]});
}
for (x=0; x<tsrc.length; x++) {
u = tsrc[x].src;
// Force absolute
if (u.indexOf('://') == -1 && u.indexOf('/') != 0)
u = tinyMCE.documentBasePath + "/" + u;
tsrc[x].src = u;
}
TPU.templates = tsrc;
for (x = 0; x < tsrc.length; x++)
sel.options[sel.options.length] = new Option(tsrc[x].title, tsrc[x].src);
},
selectTemplate : function(o) {
var x, d = window.frames['templatesrc'].document;
this.currentTemplateHTML = this.plugin._replaceValues(this.getFileContents(o.value));
// Force complete document
/* if (!/<body/gi.test(this.currentTemplateHTML)) {
this.currentTemplateHTML = '<html xmlns="http://www.w3.org/1999/xhtml">' +
'<head>' +
'<title>blank_page</title>' +
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
'</head>' +
'<body>' +
this.currentTemplateHTML +
'</body>' +
'</html>';
}*/
// Write HTML to preview iframe
d.body.innerHTML = this.currentTemplateHTML;
// Display description
for (x = 0; x < TPU.templates.length; x++) {
if (TPU.templates[x].src == o.value) {
document.getElementById('tmpldesc').innerHTML = TPU.templates[x].description;
break;
}
}
},
insertTemplate : function() {
var sel, opt;
sel = document.getElementById('tpath');
opt = sel.options[sel.selectedIndex];
// Is it a template or snippet
if (TPU.currentTemplateHTML.indexOf('mceTmpl'))
tinyMCEPopup.execCommand('mceTemplate', false, {title : opt.text, tsrc : opt.value, body : TPU.currentTemplateHTML});
else
tinyMCEPopup.execCommand('mceInsertContent', false, TPU.currentTemplateHTML);
tinyMCEPopup.close();
},
getFileContents : function(u) {
var x, d, t = 'text/plain';
function g(s) {
x = 0;
try {
x = new ActiveXObject(s);
} catch (s) {
}
return x;
};
x = window.ActiveXObject ? g('Msxml2.XMLHTTP') || g('Microsoft.XMLHTTP') : new XMLHttpRequest();
// Synchronous AJAX load file
x.overrideMimeType && x.overrideMimeType(t);
x.open("GET", u, false);
x.send(null);
return x.responseText;
},
resizeInputs : function() {
var wHeight, wWidth, elm;
if (!self.innerWidth) {
wHeight = document.body.clientHeight - 160;
wWidth = document.body.clientWidth - 40;
} else {
wHeight = self.innerHeight - 160;
wWidth = self.innerWidth - 40;
}
elm = document.getElementById('templatesrc');
if (elm) {
elm.style.height = Math.abs(wHeight) + 'px';
elm.style.width = Math.abs(wWidth - 5) + 'px';
}
}
};
|