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