template.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. tinyMCEPopup.requireLangPack();
  2. var TemplateDialog = {
  3. preInit : function() {
  4. var url = tinyMCEPopup.getParam("template_external_list_url");
  5. if (url != null)
  6. document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></sc'+'ript>');
  7. },
  8. init : function() {
  9. var ed = tinyMCEPopup.editor, tsrc, sel, x, u;
  10. tsrc = ed.getParam("template_templates", false);
  11. sel = document.getElementById('tpath');
  12. // Setup external template list
  13. if (!tsrc && typeof(tinyMCETemplateList) != 'undefined') {
  14. for (x=0, tsrc = []; x<tinyMCETemplateList.length; x++)
  15. tsrc.push({title : tinyMCETemplateList[x][0], src : tinyMCETemplateList[x][1], description : tinyMCETemplateList[x][2]});
  16. }
  17. for (x=0; x<tsrc.length; x++)
  18. sel.options[sel.options.length] = new Option(tsrc[x].title, tinyMCEPopup.editor.documentBaseURI.toAbsolute(tsrc[x].src));
  19. this.resize();
  20. this.tsrc = tsrc;
  21. },
  22. resize : function() {
  23. var w, h, e;
  24. if (!self.innerWidth) {
  25. w = document.body.clientWidth - 50;
  26. h = document.body.clientHeight - 160;
  27. } else {
  28. w = self.innerWidth - 50;
  29. h = self.innerHeight - 170;
  30. }
  31. e = document.getElementById('templatesrc');
  32. if (e) {
  33. e.style.height = Math.abs(h) + 'px';
  34. e.style.width = Math.abs(w - 5) + 'px';
  35. }
  36. },
  37. loadCSSFiles : function(d) {
  38. var ed = tinyMCEPopup.editor;
  39. tinymce.each(ed.getParam("content_css", '').split(','), function(u) {
  40. d.write('<link href="' + ed.documentBaseURI.toAbsolute(u) + '" rel="stylesheet" type="text/css" />');
  41. });
  42. },
  43. selectTemplate : function(u, ti) {
  44. var d = window.frames['templatesrc'].document, x, tsrc = this.tsrc;
  45. if (!u)
  46. return;
  47. d.body.innerHTML = this.templateHTML = this.getFileContents(u);
  48. for (x=0; x<tsrc.length; x++) {
  49. if (tsrc[x].title == ti)
  50. document.getElementById('tmpldesc').innerHTML = tsrc[x].description || '';
  51. }
  52. },
  53. insert : function() {
  54. tinyMCEPopup.execCommand('mceInsertTemplate', false, {
  55. content : this.templateHTML,
  56. selection : tinyMCEPopup.editor.selection.getContent()
  57. });
  58. tinyMCEPopup.close();
  59. },
  60. getFileContents : function(u) {
  61. var x, d, t = 'text/plain';
  62. function g(s) {
  63. x = 0;
  64. try {
  65. x = new ActiveXObject(s);
  66. } catch (s) {
  67. }
  68. return x;
  69. };
  70. x = window.ActiveXObject ? g('Msxml2.XMLHTTP') || g('Microsoft.XMLHTTP') : new XMLHttpRequest();
  71. // Synchronous AJAX load file
  72. x.overrideMimeType && x.overrideMimeType(t);
  73. x.open("GET", u, false);
  74. x.send(null);
  75. return x.responseText;
  76. }
  77. };
  78. TemplateDialog.preInit();
  79. tinyMCEPopup.onInit.add(TemplateDialog.init, TemplateDialog);