/static/scripts/tiny_mce/plugins/template/js/template.js

http://n23.googlecode.com/ · JavaScript · 100 lines · 72 code · 26 blank · 2 comment · 13 complexity · bcf71074d7b36355503342986b7ec9f7 MD5 · raw file

  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. },
  21. resize : function() {
  22. var w, h, e;
  23. if (!self.innerWidth) {
  24. w = document.body.clientWidth - 50;
  25. h = document.body.clientHeight - 160;
  26. } else {
  27. w = self.innerWidth - 50;
  28. h = self.innerHeight - 170;
  29. }
  30. e = document.getElementById('templatesrc');
  31. if (e) {
  32. e.style.height = Math.abs(h) + 'px';
  33. e.style.width = Math.abs(w - 5) + 'px';
  34. }
  35. },
  36. loadCSSFiles : function(d) {
  37. var ed = tinyMCEPopup.editor;
  38. tinymce.each(ed.getParam("content_css", '').split(','), function(u) {
  39. d.write('<link href="' + ed.documentBaseURI.toAbsolute(u) + '" rel="stylesheet" type="text/css" />');
  40. });
  41. },
  42. selectTemplate : function(u) {
  43. var d = window.frames['templatesrc'].document;
  44. if (!u)
  45. return;
  46. d.body.innerHTML = this.templateHTML = this.getFileContents(u);
  47. },
  48. insert : function() {
  49. tinyMCEPopup.execCommand('mceInsertTemplate', false, {
  50. content : this.templateHTML,
  51. selection : tinyMCEPopup.editor.selection.getContent()
  52. });
  53. tinyMCEPopup.close();
  54. },
  55. getFileContents : function(u) {
  56. var x, d, t = 'text/plain';
  57. function g(s) {
  58. x = 0;
  59. try {
  60. x = new ActiveXObject(s);
  61. } catch (s) {
  62. }
  63. return x;
  64. };
  65. x = window.ActiveXObject ? g('Msxml2.XMLHTTP') || g('Microsoft.XMLHTTP') : new XMLHttpRequest();
  66. // Synchronous AJAX load file
  67. x.overrideMimeType && x.overrideMimeType(t);
  68. x.open("GET", u, false);
  69. x.send(null);
  70. return x.responseText;
  71. }
  72. };
  73. TemplateDialog.preInit();
  74. tinyMCEPopup.onInit.add(TemplateDialog.init, TemplateDialog);