upz, forgot to take out comments
[boxroom-stian.git] / public / javascripts / tiny_mce / themes / advanced / editor_template_src.js
blob9382952390cdb3c0c45870d6391b153456cba5bf
1 /**
2 * $Id: editor_template_src.js 129 2006-10-23 09:45:17Z spocke $
4 * @author Moxiecode
5 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
6 */
8 /* Import theme specific language pack */
9 tinyMCE.importThemeLanguagePack('advanced');
11 var TinyMCE_AdvancedTheme = {
12 // Private theme fields
13 _defColors : "000000,993300,333300,003300,003366,000080,333399,333333,800000,FF6600,808000,008000,008080,0000FF,666699,808080,FF0000,FF9900,99CC00,339966,33CCCC,3366FF,800080,999999,FF00FF,FFCC00,FFFF00,00FF00,00FFFF,00CCFF,993366,C0C0C0,FF99CC,FFCC99,FFFF99,CCFFCC,CCFFFF,99CCFF,CC99FF,FFFFFF",
14 _autoImportCSSClasses : true,
15 _resizer : {},
16 _buttons : [
17 // Control id, button img, button title, command, user_interface, value
18 ['bold', '{$lang_bold_img}', 'lang_bold_desc', 'Bold'],
19 ['italic', '{$lang_italic_img}', 'lang_italic_desc', 'Italic'],
20 ['underline', '{$lang_underline_img}', 'lang_underline_desc', 'Underline'],
21 ['strikethrough', 'strikethrough.gif', 'lang_striketrough_desc', 'Strikethrough'],
22 ['justifyleft', 'justifyleft.gif', 'lang_justifyleft_desc', 'JustifyLeft'],
23 ['justifycenter', 'justifycenter.gif', 'lang_justifycenter_desc', 'JustifyCenter'],
24 ['justifyright', 'justifyright.gif', 'lang_justifyright_desc', 'JustifyRight'],
25 ['justifyfull', 'justifyfull.gif', 'lang_justifyfull_desc', 'JustifyFull'],
26 ['bullist', 'bullist.gif', 'lang_bullist_desc', 'InsertUnorderedList'],
27 ['numlist', 'numlist.gif', 'lang_numlist_desc', 'InsertOrderedList'],
28 ['outdent', 'outdent.gif', 'lang_outdent_desc', 'Outdent'],
29 ['indent', 'indent.gif', 'lang_indent_desc', 'Indent'],
30 ['cut', 'cut.gif', 'lang_cut_desc', 'Cut'],
31 ['copy', 'copy.gif', 'lang_copy_desc', 'Copy'],
32 ['paste', 'paste.gif', 'lang_paste_desc', 'Paste'],
33 ['undo', 'undo.gif', 'lang_undo_desc', 'Undo'],
34 ['redo', 'redo.gif', 'lang_redo_desc', 'Redo'],
35 ['link', 'link.gif', 'lang_link_desc', 'mceLink', true],
36 ['unlink', 'unlink.gif', 'lang_unlink_desc', 'unlink'],
37 ['image', 'image.gif', 'lang_image_desc', 'mceImage', true],
38 ['cleanup', 'cleanup.gif', 'lang_cleanup_desc', 'mceCleanup'],
39 ['help', 'help.gif', 'lang_help_desc', 'mceHelp'],
40 ['code', 'code.gif', 'lang_theme_code_desc', 'mceCodeEditor'],
41 ['hr', 'hr.gif', 'lang_theme_hr_desc', 'inserthorizontalrule'],
42 ['removeformat', 'removeformat.gif', 'lang_theme_removeformat_desc', 'removeformat'],
43 ['sub', 'sub.gif', 'lang_theme_sub_desc', 'subscript'],
44 ['sup', 'sup.gif', 'lang_theme_sup_desc', 'superscript'],
45 ['forecolor', 'forecolor.gif', 'lang_theme_forecolor_desc', 'forecolor', true],
46 ['backcolor', 'backcolor.gif', 'lang_theme_backcolor_desc', 'HiliteColor', true],
47 ['charmap', 'charmap.gif', 'lang_theme_charmap_desc', 'mceCharMap'],
48 ['visualaid', 'visualaid.gif', 'lang_theme_visualaid_desc', 'mceToggleVisualAid'],
49 ['anchor', 'anchor.gif', 'lang_theme_anchor_desc', 'mceInsertAnchor'],
50 ['newdocument', 'newdocument.gif', 'lang_newdocument_desc', 'mceNewDocument']
53 _buttonMap : 'anchor,backcolor,bold,bullist,charmap,cleanup,code,copy,cut,forecolor,help,hr,image,indent,italic,justifycenter,justifyfull,justifyleft,justifyright,link,newdocument,numlist,outdent,paste,redo,removeformat,strikethrough,sub,sup,underline,undo,unlink,visualaid,advhr,ltr,rtl,emotions,flash,fullpage,fullscreen,iespell,insertdate,inserttime,pastetext,pasteword,selectall,preview,print,save,replace,search,table,cell_props,delete_col,delete_row,col_after,col_before,row_after,row_before,merge_cells,row_props,split_cells,delete_table',
55 /**
56 * Returns HTML code for the specificed control.
58 getControlHTML : function(button_name) {
59 var i, x, but;
61 // Lookup button in button list
62 for (i=0; i<TinyMCE_AdvancedTheme._buttons.length; i++) {
63 but = TinyMCE_AdvancedTheme._buttons[i];
65 if (but[0] == button_name && (button_name == "forecolor" || button_name == "backcolor"))
66 return tinyMCE.getMenuButtonHTML(but[0], but[2], '{$themeurl}/images/' + but[1], but[3] + "Menu", but[3], (but.length > 4 ? but[4] : false), (but.length > 5 ? but[5] : null));
68 if (but[0] == button_name)
69 return tinyMCE.getButtonHTML(but[0], but[2], '{$themeurl}/images/' + but[1], but[3], (but.length > 4 ? but[4] : false), (but.length > 5 ? but[5] : null));
72 // Custom controlls other than buttons
73 switch (button_name) {
74 case "formatselect":
75 var html = '<select id="{$editor_id}_formatSelect" name="{$editor_id}_formatSelect" onfocus="tinyMCE.addSelectAccessibility(event, this, window);" onchange="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'FormatBlock\',false,this.options[this.selectedIndex].value);" class="mceSelectList">';
76 var formats = tinyMCE.getParam("theme_advanced_blockformats", "p,address,pre,h1,h2,h3,h4,h5,h6", true).split(',');
77 var lookup = [
78 ['p', '{$lang_theme_paragraph}'],
79 ['address', '{$lang_theme_address}'],
80 ['pre', '{$lang_theme_pre}'],
81 ['h1', '{$lang_theme_h1}'],
82 ['h2', '{$lang_theme_h2}'],
83 ['h3', '{$lang_theme_h3}'],
84 ['h4', '{$lang_theme_h4}'],
85 ['h5', '{$lang_theme_h5}'],
86 ['h6', '{$lang_theme_h6}'],
87 ['div', '{$lang_theme_div}'],
88 ['blockquote', '{$lang_theme_blockquote}'],
89 ['code', '{$lang_theme_code}'],
90 ['dt', '{$lang_theme_dt}'],
91 ['dd', '{$lang_theme_dd}'],
92 ['samp', '{$lang_theme_samp}']
95 html += '<option value="">{$lang_theme_block}</option>';
97 // Build format select
98 for (var i=0; i<formats.length; i++) {
99 for (var x=0; x<lookup.length; x++) {
100 if (formats[i] == lookup[x][0])
101 html += '<option value="&lt;' + lookup[x][0] + '&gt;">' + lookup[x][1] + '</option>';
105 html += '</select>';
107 return html;
109 case "styleselect":
110 return '<select id="{$editor_id}_styleSelect" onmousedown="tinyMCE.themes.advanced._setupCSSClasses(\'{$editor_id}\');" name="{$editor_id}_styleSelect" onfocus="tinyMCE.addSelectAccessibility(event,this,window);" onchange="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSetCSSClass\',false,this.options[this.selectedIndex].value);" class="mceSelectList">{$style_select_options}</select>';
112 case "fontselect":
113 var fontHTML = '<select id="{$editor_id}_fontNameSelect" name="{$editor_id}_fontNameSelect" onfocus="tinyMCE.addSelectAccessibility(event, this, window);" onchange="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'FontName\',false,this.options[this.selectedIndex].value);" class="mceSelectList"><option value="">{$lang_theme_fontdefault}</option>';
114 var iFonts = 'Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;WingDings=wingdings';
115 var nFonts = 'Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sand;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats';
116 var fonts = tinyMCE.getParam("theme_advanced_fonts", nFonts).split(';');
117 for (i=0; i<fonts.length; i++) {
118 if (fonts[i] != '') {
119 var parts = fonts[i].split('=');
120 fontHTML += '<option value="' + parts[1] + '">' + parts[0] + '</option>';
124 fontHTML += '</select>';
125 return fontHTML;
127 case "fontsizeselect":
128 return '<select id="{$editor_id}_fontSizeSelect" name="{$editor_id}_fontSizeSelect" onfocus="tinyMCE.addSelectAccessibility(event, this, window);" onchange="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'FontSize\',false,this.options[this.selectedIndex].value);" class="mceSelectList">'+
129 '<option value="0">{$lang_theme_font_size}</option>'+
130 '<option value="1">1 (8 pt)</option>'+
131 '<option value="2">2 (10 pt)</option>'+
132 '<option value="3">3 (12 pt)</option>'+
133 '<option value="4">4 (14 pt)</option>'+
134 '<option value="5">5 (18 pt)</option>'+
135 '<option value="6">6 (24 pt)</option>'+
136 '<option value="7">7 (36 pt)</option>'+
137 '</select>';
139 case "|":
140 case "separator":
141 return '<img src="{$themeurl}/images/separator.gif" width="2" height="20" class="mceSeparatorLine" />';
143 case "spacer":
144 return '<img src="{$themeurl}/images/separator.gif" width="2" height="15" border="0" class="mceSeparatorLine" style="vertical-align: middle" />';
146 case "rowseparator":
147 return '<br />';
150 return "";
154 * Theme specific execcommand handling.
156 execCommand : function(editor_id, element, command, user_interface, value) {
157 switch (command) {
158 case 'mceHelp':
159 tinyMCE.openWindow({
160 file : 'about.htm',
161 width : 480,
162 height : 380
163 }, {
164 tinymce_version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion,
165 tinymce_releasedate : tinyMCE.releaseDate,
166 inline : "yes"
168 return true;
170 case "mceLink":
171 var inst = tinyMCE.getInstanceById(editor_id);
172 var doc = inst.getDoc();
173 var selectedText = "";
175 if (tinyMCE.isMSIE) {
176 var rng = doc.selection.createRange();
177 selectedText = rng.text;
178 } else
179 selectedText = inst.getSel().toString();
181 if (!tinyMCE.linkElement) {
182 if ((tinyMCE.selectedElement.nodeName.toLowerCase() != "img") && (selectedText.length <= 0))
183 return true;
186 var href = "", target = "", title = "", onclick = "", action = "insert", style_class = "";
188 if (tinyMCE.selectedElement.nodeName.toLowerCase() == "a")
189 tinyMCE.linkElement = tinyMCE.selectedElement;
191 // Is anchor not a link
192 if (tinyMCE.linkElement != null && tinyMCE.getAttrib(tinyMCE.linkElement, 'href') == "")
193 tinyMCE.linkElement = null;
195 if (tinyMCE.linkElement) {
196 href = tinyMCE.getAttrib(tinyMCE.linkElement, 'href');
197 target = tinyMCE.getAttrib(tinyMCE.linkElement, 'target');
198 title = tinyMCE.getAttrib(tinyMCE.linkElement, 'title');
199 onclick = tinyMCE.getAttrib(tinyMCE.linkElement, 'onclick');
200 style_class = tinyMCE.getAttrib(tinyMCE.linkElement, 'class');
202 // Try old onclick to if copy/pasted content
203 if (onclick == "")
204 onclick = tinyMCE.getAttrib(tinyMCE.linkElement, 'onclick');
206 onclick = tinyMCE.cleanupEventStr(onclick);
208 href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement, true);");
210 // Use mce_href if defined
211 mceRealHref = tinyMCE.getAttrib(tinyMCE.linkElement, 'mce_href');
212 if (mceRealHref != "") {
213 href = mceRealHref;
215 if (tinyMCE.getParam('convert_urls'))
216 href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement, true);");
219 action = "update";
222 var template = new Array();
224 template['file'] = 'link.htm';
225 template['width'] = 310;
226 template['height'] = 200;
228 // Language specific width and height addons
229 template['width'] += tinyMCE.getLang('lang_insert_link_delta_width', 0);
230 template['height'] += tinyMCE.getLang('lang_insert_link_delta_height', 0);
232 if (inst.settings['insertlink_callback']) {
233 var returnVal = eval(inst.settings['insertlink_callback'] + "(href, target, title, onclick, action, style_class);");
234 if (returnVal && returnVal['href'])
235 TinyMCE_AdvancedTheme._insertLink(returnVal['href'], returnVal['target'], returnVal['title'], returnVal['onclick'], returnVal['style_class']);
236 } else {
237 tinyMCE.openWindow(template, {href : href, target : target, title : title, onclick : onclick, action : action, className : style_class, inline : "yes"});
240 return true;
242 case "mceImage":
243 var src = "", alt = "", border = "", hspace = "", vspace = "", width = "", height = "", align = "";
244 var title = "", onmouseover = "", onmouseout = "", action = "insert";
245 var img = tinyMCE.imgElement;
246 var inst = tinyMCE.getInstanceById(editor_id);
248 if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") {
249 img = tinyMCE.selectedElement;
250 tinyMCE.imgElement = img;
253 if (img) {
254 // Is it a internal MCE visual aid image, then skip this one.
255 if (tinyMCE.getAttrib(img, 'name').indexOf('mce_') == 0)
256 return true;
258 src = tinyMCE.getAttrib(img, 'src');
259 alt = tinyMCE.getAttrib(img, 'alt');
261 // Try polling out the title
262 if (alt == "")
263 alt = tinyMCE.getAttrib(img, 'title');
265 // Fix width/height attributes if the styles is specified
266 if (tinyMCE.isGecko) {
267 var w = img.style.width;
268 if (w != null && w != "")
269 img.setAttribute("width", w);
271 var h = img.style.height;
272 if (h != null && h != "")
273 img.setAttribute("height", h);
276 border = tinyMCE.getAttrib(img, 'border');
277 hspace = tinyMCE.getAttrib(img, 'hspace');
278 vspace = tinyMCE.getAttrib(img, 'vspace');
279 width = tinyMCE.getAttrib(img, 'width');
280 height = tinyMCE.getAttrib(img, 'height');
281 align = tinyMCE.getAttrib(img, 'align');
282 onmouseover = tinyMCE.getAttrib(img, 'onmouseover');
283 onmouseout = tinyMCE.getAttrib(img, 'onmouseout');
284 title = tinyMCE.getAttrib(img, 'title');
286 // Is realy specified?
287 if (tinyMCE.isMSIE) {
288 width = img.attributes['width'].specified ? width : "";
289 height = img.attributes['height'].specified ? height : "";
292 //onmouseover = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseover));
293 //onmouseout = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseout));
295 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");
297 // Use mce_src if defined
298 mceRealSrc = tinyMCE.getAttrib(img, 'mce_src');
299 if (mceRealSrc != "") {
300 src = mceRealSrc;
302 if (tinyMCE.getParam('convert_urls'))
303 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");
306 //if (onmouseover != "")
307 // onmouseover = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseover, img, true);");
309 //if (onmouseout != "")
310 // onmouseout = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseout, img, true);");
312 action = "update";
315 var template = new Array();
317 template['file'] = 'image.htm?src={$src}';
318 template['width'] = 355;
319 template['height'] = 265 + (tinyMCE.isMSIE ? 25 : 0);
321 // Language specific width and height addons
322 template['width'] += tinyMCE.getLang('lang_insert_image_delta_width', 0);
323 template['height'] += tinyMCE.getLang('lang_insert_image_delta_height', 0);
325 if (inst.settings['insertimage_callback']) {
326 var returnVal = eval(inst.settings['insertimage_callback'] + "(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout, action);");
327 if (returnVal && returnVal['src'])
328 TinyMCE_AdvancedTheme._insertImage(returnVal['src'], returnVal['alt'], returnVal['border'], returnVal['hspace'], returnVal['vspace'], returnVal['width'], returnVal['height'], returnVal['align'], returnVal['title'], returnVal['onmouseover'], returnVal['onmouseout']);
329 } else
330 tinyMCE.openWindow(template, {src : src, alt : alt, border : border, hspace : hspace, vspace : vspace, width : width, height : height, align : align, title : title, onmouseover : onmouseover, onmouseout : onmouseout, action : action, inline : "yes"});
332 return true;
334 case "forecolor":
335 var fcp = new TinyMCE_Layer(editor_id + '_fcPreview', false), p, img, elm;
337 TinyMCE_AdvancedTheme._hideMenus(editor_id);
339 if (!fcp.exists()) {
340 fcp.create('div', 'mceColorPreview', document.getElementById(editor_id + '_toolbar'));
341 elm = fcp.getElement();
342 elm._editor_id = editor_id;
343 elm._command = "forecolor";
344 elm._switchId = editor_id + "_forecolor";
345 tinyMCE.addEvent(elm, 'click', TinyMCE_AdvancedTheme._handleMenuEvent);
346 tinyMCE.addEvent(elm, 'mouseover', TinyMCE_AdvancedTheme._handleMenuEvent);
347 tinyMCE.addEvent(elm, 'mouseout', TinyMCE_AdvancedTheme._handleMenuEvent);
350 img = tinyMCE.selectNodes(document.getElementById(editor_id + "_forecolor"), function(n) {return n.nodeName == "IMG";})[0];
351 p = tinyMCE.getAbsPosition(img, document.getElementById(editor_id + '_toolbar'));
353 fcp.moveTo(p.absLeft, p.absTop);
354 fcp.getElement().style.backgroundColor = value != null ? value : tinyMCE.getInstanceById(editor_id).foreColor;
355 fcp.show();
357 return false;
359 case "forecolorMenu":
360 TinyMCE_AdvancedTheme._hideMenus(editor_id);
362 // Create color layer
363 var ml = new TinyMCE_Layer(editor_id + '_fcMenu');
365 if (!ml.exists())
366 ml.create('div', 'mceMenu', document.body, TinyMCE_AdvancedTheme._getColorHTML(editor_id, 'theme_advanced_text_colors', 'forecolor'));
368 tinyMCE.switchClass(editor_id + '_forecolor', 'mceMenuButtonFocus');
369 ml.moveRelativeTo(document.getElementById(editor_id + "_forecolor"), 'bl');
371 ml.moveBy(tinyMCE.isMSIE && !tinyMCE.isOpera ? -1 : 1, -1);
373 if (tinyMCE.isOpera)
374 ml.moveBy(0, -2);
376 ml.show();
377 return true;
379 case "HiliteColor":
380 var bcp = new TinyMCE_Layer(editor_id + '_bcPreview', false), p, img;
382 TinyMCE_AdvancedTheme._hideMenus(editor_id);
384 if (!bcp.exists()) {
385 bcp.create('div', 'mceColorPreview', document.getElementById(editor_id + '_toolbar'));
386 elm = bcp.getElement();
387 elm._editor_id = editor_id;
388 elm._command = "HiliteColor";
389 elm._switchId = editor_id + "_backcolor";
390 tinyMCE.addEvent(elm, 'click', TinyMCE_AdvancedTheme._handleMenuEvent);
391 tinyMCE.addEvent(elm, 'mouseover', TinyMCE_AdvancedTheme._handleMenuEvent);
392 tinyMCE.addEvent(elm, 'mouseout', TinyMCE_AdvancedTheme._handleMenuEvent);
395 img = tinyMCE.selectNodes(document.getElementById(editor_id + "_backcolor"), function(n) {return n.nodeName == "IMG";})[0];
396 p = tinyMCE.getAbsPosition(img, document.getElementById(editor_id + '_toolbar'));
398 bcp.moveTo(p.absLeft, p.absTop);
399 bcp.getElement().style.backgroundColor = value != null ? value : tinyMCE.getInstanceById(editor_id).backColor;
400 bcp.show();
402 return false;
404 case "HiliteColorMenu":
405 TinyMCE_AdvancedTheme._hideMenus(editor_id);
407 // Create color layer
408 var ml = new TinyMCE_Layer(editor_id + '_bcMenu');
410 if (!ml.exists())
411 ml.create('div', 'mceMenu', document.body, TinyMCE_AdvancedTheme._getColorHTML(editor_id, 'theme_advanced_background_colors', 'HiliteColor'));
413 tinyMCE.switchClass(editor_id + '_backcolor', 'mceMenuButtonFocus');
414 ml.moveRelativeTo(document.getElementById(editor_id + "_backcolor"), 'bl');
416 ml.moveBy(tinyMCE.isMSIE && !tinyMCE.isOpera ? -1 : 1, -1);
418 if (tinyMCE.isOpera)
419 ml.moveBy(0, -2);
421 ml.show();
422 return true;
424 case "mceColorPicker":
425 if (user_interface) {
426 var template = new Array();
427 var inputColor = value['document'].getElementById(value['element_id']).value;
429 template['file'] = 'color_picker.htm';
430 template['width'] = 220;
431 template['height'] = 190;
432 template['close_previous'] = "no";
434 template['width'] += tinyMCE.getLang('lang_theme_advanced_colorpicker_delta_width', 0);
435 template['height'] += tinyMCE.getLang('lang_theme_advanced_colorpicker_delta_height', 0);
437 if (typeof(value['store_selection']) == "undefined")
438 value['store_selection'] = true;
440 tinyMCE.lastColorPickerValue = value;
441 tinyMCE.openWindow(template, {editor_id : editor_id, mce_store_selection : value['store_selection'], inline : "yes", command : "mceColorPicker", input_color : inputColor});
442 } else {
443 var savedVal = tinyMCE.lastColorPickerValue;
444 var elm = savedVal['document'].getElementById(savedVal['element_id']);
445 elm.value = value;
447 if (elm.onchange != null && elm.onchange != '')
448 eval('elm.onchange();');
450 return true;
452 case "mceCodeEditor":
453 var template = new Array();
455 template['file'] = 'source_editor.htm';
456 template['width'] = parseInt(tinyMCE.getParam("theme_advanced_source_editor_width", 720));
457 template['height'] = parseInt(tinyMCE.getParam("theme_advanced_source_editor_height", 580));
459 tinyMCE.openWindow(template, {editor_id : editor_id, resizable : "yes", scrollbars : "no", inline : "yes"});
460 return true;
462 case "mceCharMap":
463 var template = new Array();
465 template['file'] = 'charmap.htm';
466 template['width'] = 550 + (tinyMCE.isOpera ? 40 : 0);
467 template['height'] = 250;
469 template['width'] += tinyMCE.getLang('lang_theme_advanced_charmap_delta_width', 0);
470 template['height'] += tinyMCE.getLang('lang_theme_advanced_charmap_delta_height', 0);
472 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
473 return true;
475 case "mceInsertAnchor":
476 var template = new Array();
478 template['file'] = 'anchor.htm';
479 template['width'] = 320;
480 template['height'] = 90 + (tinyMCE.isNS7 ? 30 : 0);
482 template['width'] += tinyMCE.getLang('lang_theme_advanced_anchor_delta_width', 0);
483 template['height'] += tinyMCE.getLang('lang_theme_advanced_anchor_delta_height', 0);
485 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
486 return true;
488 case "mceNewDocument":
489 if (confirm(tinyMCE.getLang('lang_newdocument')))
490 tinyMCE.execInstanceCommand(editor_id, 'mceSetContent', false, ' ');
492 return true;
495 return false;
499 * Editor instance template function.
501 getEditorTemplate : function(settings, editorId) {
502 function removeFromArray(in_array, remove_array) {
503 var outArray = new Array(), skip;
505 for (var i=0; i<in_array.length; i++) {
506 skip = false;
508 for (var j=0; j<remove_array.length; j++) {
509 if (in_array[i] == remove_array[j]) {
510 skip = true;
514 if (!skip) {
515 outArray[outArray.length] = in_array[i];
519 return outArray;
522 function addToArray(in_array, add_array) {
523 for (var i=0; i<add_array.length; i++) {
524 in_array[in_array.length] = add_array[i];
527 return in_array;
530 var template = new Array();
531 var deltaHeight = 0;
532 var resizing = tinyMCE.getParam("theme_advanced_resizing", false);
533 var path = tinyMCE.getParam("theme_advanced_path", true);
534 var statusbarHTML = '<div id="{$editor_id}_path" class="mceStatusbarPathText" style="display: ' + (path ? "block" : "none") + '">&#160;</div><div id="{$editor_id}_resize" class="mceStatusbarResize" style="display: ' + (resizing ? "block" : "none") + '" onmousedown="tinyMCE.themes.advanced._setResizing(event,\'{$editor_id}\',true);"></div><br style="clear: both" />';
535 var layoutManager = tinyMCE.getParam("theme_advanced_layout_manager", "SimpleLayout");
537 // Setup style select options -- MOVED UP FOR EXTERNAL TOOLBAR COMPATABILITY!
538 var styleSelectHTML = '<option value="">{$lang_theme_style_select}</option>';
539 if (settings['theme_advanced_styles']) {
540 var stylesAr = settings['theme_advanced_styles'].split(';');
542 for (var i=0; i<stylesAr.length; i++) {
543 var key, value;
545 key = stylesAr[i].split('=')[0];
546 value = stylesAr[i].split('=')[1];
548 styleSelectHTML += '<option value="' + value + '">' + key + '</option>';
551 TinyMCE_AdvancedTheme._autoImportCSSClasses = false;
554 switch(layoutManager) {
555 case "SimpleLayout" : //the default TinyMCE Layout (for backwards compatibility)...
556 var toolbarHTML = "";
557 var toolbarLocation = tinyMCE.getParam("theme_advanced_toolbar_location", "bottom");
558 var toolbarAlign = tinyMCE.getParam("theme_advanced_toolbar_align", "center");
559 var pathLocation = tinyMCE.getParam("theme_advanced_path_location", "none"); // Compatiblity
560 var statusbarLocation = tinyMCE.getParam("theme_advanced_statusbar_location", pathLocation);
561 var defVals = {
562 theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,styleselect,formatselect",
563 theme_advanced_buttons2 : "bullist,numlist,separator,outdent,indent,separator,undo,redo,separator,link,unlink,anchor,image,cleanup,help,code",
564 theme_advanced_buttons3 : "hr,removeformat,visualaid,separator,sub,sup,separator,charmap"
567 // Add accessibility control
568 toolbarHTML += '<a href="#" accesskey="q" title="' + tinyMCE.getLang("lang_toolbar_focus") + '"';
570 if (!tinyMCE.getParam("accessibility_focus"))
571 toolbarHTML += ' onfocus="tinyMCE.getInstanceById(\'' + editorId + '\').getWin().focus();"';
573 toolbarHTML += '></a>';
575 // Render rows
576 for (var i=1; i<100; i++) {
577 var def = defVals["theme_advanced_buttons" + i];
579 var buttons = tinyMCE.getParam("theme_advanced_buttons" + i, def == null ? '' : def, true, ',');
580 if (buttons.length == 0)
581 break;
583 buttons = removeFromArray(buttons, tinyMCE.getParam("theme_advanced_disable", "", true, ','));
584 buttons = addToArray(buttons, tinyMCE.getParam("theme_advanced_buttons" + i + "_add", "", true, ','));
585 buttons = addToArray(tinyMCE.getParam("theme_advanced_buttons" + i + "_add_before", "", true, ','), buttons);
587 for (var b=0; b<buttons.length; b++)
588 toolbarHTML += tinyMCE.getControlHTML(buttons[b]);
590 if (buttons.length > 0) {
591 toolbarHTML += "<br />";
592 deltaHeight -= 23;
596 // Add accessibility control
597 toolbarHTML += '<a href="#" accesskey="z" onfocus="tinyMCE.getInstanceById(\'' + editorId + '\').getWin().focus();"></a>';
599 // Setup template html
600 template['html'] = '<table class="mceEditor" border="0" cellpadding="0" cellspacing="0" width="{$width}" height="{$height}" style="width:{$width_style};height:{$height_style}"><tbody>';
602 if (toolbarLocation == "top") {
603 template['html'] += '<tr><td class="mceToolbarTop" align="' + toolbarAlign + '" height="1" nowrap="nowrap"><span id="' + editorId + '_toolbar" class="mceToolbarContainer">' + toolbarHTML + '</span></td></tr>';
606 if (statusbarLocation == "top") {
607 template['html'] += '<tr><td class="mceStatusbarTop" height="1">' + statusbarHTML + '</td></tr>';
608 deltaHeight -= 23;
611 template['html'] += '<tr><td align="center"><span id="{$editor_id}"></span></td></tr>';
613 if (toolbarLocation == "bottom") {
614 template['html'] += '<tr><td class="mceToolbarBottom" align="' + toolbarAlign + '" height="1"><span id="' + editorId + '_toolbar" class="mceToolbarContainer">' + toolbarHTML + '</span></td></tr>';
617 // External toolbar changes
618 if (toolbarLocation == "external") {
619 var bod = document.body;
620 var elm = document.createElement ("div");
622 toolbarHTML = tinyMCE.replaceVar(toolbarHTML, 'style_select_options', styleSelectHTML);
623 toolbarHTML = tinyMCE.applyTemplate(toolbarHTML, {editor_id : editorId});
625 elm.className = "mceToolbarExternal";
626 elm.id = editorId+"_toolbar";
627 elm.innerHTML = '<table width="100%" border="0" align="center"><tr><td align="center">'+toolbarHTML+'</td></tr></table>';
628 bod.appendChild (elm);
629 // bod.style.marginTop = elm.offsetHeight + "px";
631 deltaHeight = 0;
632 tinyMCE.getInstanceById(editorId).toolbarElement = elm;
634 //template['html'] = '<div id="mceExternalToolbar" align="center" class="mceToolbarExternal"><table width="100%" border="0" align="center"><tr><td align="center">'+toolbarHTML+'</td></tr></table></div>' + template["html"];
635 } else {
636 tinyMCE.getInstanceById(editorId).toolbarElement = null;
639 if (statusbarLocation == "bottom") {
640 template['html'] += '<tr><td class="mceStatusbarBottom" height="1">' + statusbarHTML + '</td></tr>';
641 deltaHeight -= 23;
644 template['html'] += '</tbody></table>';
645 //"SimpleLayout"
646 break;
648 case "RowLayout" : //Container Layout - containers defined in "theme_advanced_containers" are rendered from top to bottom.
649 template['html'] = '<table class="mceEditor" border="0" cellpadding="0" cellspacing="0" width="{$width}" height="{$height}" style="width:{$width}px;height:{$height}px"><tbody>';
651 var containers = tinyMCE.getParam("theme_advanced_containers", "", true, ",");
652 var defaultContainerCSS = tinyMCE.getParam("theme_advanced_containers_default_class", "container");
653 var defaultContainerAlign = tinyMCE.getParam("theme_advanced_containers_default_align", "center");
655 //Render Containers:
656 for (var i = 0; i < containers.length; i++)
658 if (containers[i] == "mceEditor") //Exceptions for mceEditor and ...
659 template['html'] += '<tr><td align="center" class="mceEditor_border"><span id="{$editor_id}"></span></td></tr>';
660 else if (containers[i] == "mceElementpath" || containers[i] == "mceStatusbar") // ... mceElementpath:
662 var pathClass = "mceStatusbar";
664 if (i == containers.length-1)
666 pathClass = "mceStatusbarBottom";
668 else if (i == 0)
670 pathClass = "mceStatusbar";
672 else
674 deltaHeight-=2;
677 template['html'] += '<tr><td class="' + pathClass + '" height="1">' + statusbarHTML + '</td></tr>';
678 deltaHeight -= 22;
679 } else { // Render normal Container
680 var curContainer = tinyMCE.getParam("theme_advanced_container_"+containers[i], "", true, ',');
681 var curContainerHTML = "";
682 var curAlign = tinyMCE.getParam("theme_advanced_container_"+containers[i]+"_align", defaultContainerAlign);
683 var curCSS = tinyMCE.getParam("theme_advanced_container_"+containers[i]+"_class", defaultContainerCSS);
685 curContainer = removeFromArray(curContainer, tinyMCE.getParam("theme_advanced_disable", "", true, ','));
687 for (var j=0; j<curContainer.length; j++)
688 curContainerHTML += tinyMCE.getControlHTML(curContainer[j]);
690 if (curContainer.length > 0) {
691 curContainerHTML += "<br />";
692 deltaHeight -= 23;
695 template['html'] += '<tr><td class="' + curCSS + '" align="' + curAlign + '" height="1">' + curContainerHTML + '</td></tr>';
699 template['html'] += '</tbody></table>';
700 //RowLayout
701 break;
703 case "CustomLayout" : //User defined layout callback...
704 var customLayout = tinyMCE.getParam("theme_advanced_custom_layout","");
706 if (customLayout != "" && eval("typeof(" + customLayout + ")") != "undefined") {
707 template = eval(customLayout + "(template);");
709 break;
712 if (resizing)
713 template['html'] += '<span id="{$editor_id}_resize_box" class="mceResizeBox"></span>';
715 template['html'] = tinyMCE.replaceVar(template['html'], 'style_select_options', styleSelectHTML);
716 template['delta_width'] = 0;
717 template['delta_height'] = deltaHeight;
719 return template;
722 initInstance : function(inst) {
723 if (tinyMCE.getParam("theme_advanced_resizing", false)) {
724 if (tinyMCE.getParam("theme_advanced_resizing_use_cookie", true)) {
725 var w = TinyMCE_AdvancedTheme._getCookie("TinyMCE_" + inst.editorId + "_width");
726 var h = TinyMCE_AdvancedTheme._getCookie("TinyMCE_" + inst.editorId + "_height");
728 TinyMCE_AdvancedTheme._resizeTo(inst, w, h, tinyMCE.getParam("theme_advanced_resize_horizontal", true));
732 inst.addShortcut('ctrl', 'k', 'lang_link_desc', 'mceLink');
735 _handleMenuEvent : function(e) {
736 var te = tinyMCE.isMSIE ? window.event.srcElement : e.target;
737 tinyMCE._menuButtonEvent(e.type == "mouseover" ? "over" : "out", document.getElementById(te._switchId));
739 if (e.type == "click")
740 tinyMCE.execInstanceCommand(te._editor_id, te._command);
743 _hideMenus : function(id) {
744 var fcml = new TinyMCE_Layer(id + '_fcMenu'), bcml = new TinyMCE_Layer(id + '_bcMenu');
746 if (fcml.exists() && fcml.isVisible()) {
747 tinyMCE.switchClass(id + '_forecolor', 'mceMenuButton');
748 fcml.hide();
751 if (bcml.exists() && bcml.isVisible()) {
752 tinyMCE.switchClass(id + '_backcolor', 'mceMenuButton');
753 bcml.hide();
758 * Node change handler.
760 handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection, setup_content) {
761 var alignNode, breakOut, classNode;
763 function selectByValue(select_elm, value, first_index) {
764 first_index = typeof(first_index) == "undefined" ? false : true;
766 if (select_elm) {
767 for (var i=0; i<select_elm.options.length; i++) {
768 var ov = "" + select_elm.options[i].value;
770 if (first_index && ov.toLowerCase().indexOf(value.toLowerCase()) == 0) {
771 select_elm.selectedIndex = i;
772 return true;
775 if (ov == value) {
776 select_elm.selectedIndex = i;
777 return true;
782 return false;
785 function getAttrib(elm, name) {
786 return elm.getAttribute(name) ? elm.getAttribute(name) : "";
789 // No node provided
790 if (node == null)
791 return;
793 // Update path
794 var pathElm = document.getElementById(editor_id + "_path");
795 var inst = tinyMCE.getInstanceById(editor_id);
796 var doc = inst.getDoc();
797 TinyMCE_AdvancedTheme._hideMenus(editor_id);
799 if (pathElm) {
800 // Get node path
801 var parentNode = node;
802 var path = new Array();
804 while (parentNode != null) {
805 if (parentNode.nodeName.toUpperCase() == "BODY") {
806 break;
809 // Only append element nodes to path
810 if (parentNode.nodeType == 1 && tinyMCE.getAttrib(parentNode, "class").indexOf('mceItemHidden') == -1) {
811 path[path.length] = parentNode;
814 parentNode = parentNode.parentNode;
817 // Setup HTML
818 var html = "";
819 for (var i=path.length-1; i>=0; i--) {
820 var nodeName = path[i].nodeName.toLowerCase();
821 var nodeData = "";
823 if (nodeName.indexOf("html:") == 0)
824 nodeName = nodeName.substring(5);
826 if (nodeName == "b") {
827 nodeName = "strong";
830 if (nodeName == "i") {
831 nodeName = "em";
834 if (nodeName == "span") {
835 var cn = tinyMCE.getAttrib(path[i], "class");
836 if (cn != "" && cn.indexOf('mceItem') == -1)
837 nodeData += "class: " + cn + " ";
839 var st = tinyMCE.getAttrib(path[i], "style");
840 if (st != "") {
841 st = tinyMCE.serializeStyle(tinyMCE.parseStyle(st));
842 nodeData += "style: " + st + " ";
846 if (nodeName == "font") {
847 if (tinyMCE.getParam("convert_fonts_to_spans"))
848 nodeName = "span";
850 var face = tinyMCE.getAttrib(path[i], "face");
851 if (face != "")
852 nodeData += "font: " + face + " ";
854 var size = tinyMCE.getAttrib(path[i], "size");
855 if (size != "")
856 nodeData += "size: " + size + " ";
858 var color = tinyMCE.getAttrib(path[i], "color");
859 if (color != "")
860 nodeData += "color: " + color + " ";
863 if (getAttrib(path[i], 'id') != "") {
864 nodeData += "id: " + path[i].getAttribute('id') + " ";
867 var className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(path[i], "class"), false);
868 if (className != "" && className.indexOf('mceItem') == -1)
869 nodeData += "class: " + className + " ";
871 if (getAttrib(path[i], 'src') != "") {
872 var src = tinyMCE.getAttrib(path[i], "mce_src");
874 if (src == "")
875 src = tinyMCE.getAttrib(path[i], "src");
877 nodeData += "src: " + src + " ";
880 if (path[i].nodeName == 'A' && getAttrib(path[i], 'href') != "") {
881 var href = tinyMCE.getAttrib(path[i], "mce_href");
883 if (href == "")
884 href = tinyMCE.getAttrib(path[i], "href");
886 nodeData += "href: " + href + " ";
889 className = tinyMCE.getAttrib(path[i], "class");
890 if ((nodeName == "img" || nodeName == "span") && className.indexOf('mceItem') != -1) {
891 nodeName = className.replace(/mceItem([a-z]+)/gi, '$1').toLowerCase();
892 nodeData = path[i].getAttribute('title');
895 if (nodeName == "a" && (anchor = tinyMCE.getAttrib(path[i], "name")) != "") {
896 nodeName = "a";
897 nodeName += "#" + anchor;
898 nodeData = "";
901 if (getAttrib(path[i], 'name').indexOf("mce_") != 0) {
902 var className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(path[i], "class"), false);
903 if (className != "" && className.indexOf('mceItem') == -1) {
904 nodeName += "." + className;
908 var cmd = 'tinyMCE.execInstanceCommand(\'' + editor_id + '\',\'mceSelectNodeDepth\',false,\'' + i + '\');';
909 html += '<a title="' + nodeData + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" target="_self" class="mcePathItem">' + nodeName + '</a>';
911 if (i > 0) {
912 html += " &raquo; ";
916 pathElm.innerHTML = '<a href="#" accesskey="x"></a>' + tinyMCE.getLang('lang_theme_path') + ": " + html + '&#160;';
919 // Reset old states
920 tinyMCE.switchClass(editor_id + '_justifyleft', 'mceButtonNormal');
921 tinyMCE.switchClass(editor_id + '_justifyright', 'mceButtonNormal');
922 tinyMCE.switchClass(editor_id + '_justifycenter', 'mceButtonNormal');
923 tinyMCE.switchClass(editor_id + '_justifyfull', 'mceButtonNormal');
924 tinyMCE.switchClass(editor_id + '_bold', 'mceButtonNormal');
925 tinyMCE.switchClass(editor_id + '_italic', 'mceButtonNormal');
926 tinyMCE.switchClass(editor_id + '_underline', 'mceButtonNormal');
927 tinyMCE.switchClass(editor_id + '_strikethrough', 'mceButtonNormal');
928 tinyMCE.switchClass(editor_id + '_bullist', 'mceButtonNormal');
929 tinyMCE.switchClass(editor_id + '_numlist', 'mceButtonNormal');
930 tinyMCE.switchClass(editor_id + '_sub', 'mceButtonNormal');
931 tinyMCE.switchClass(editor_id + '_sup', 'mceButtonNormal');
932 tinyMCE.switchClass(editor_id + '_anchor', 'mceButtonNormal');
933 tinyMCE.switchClass(editor_id + '_link', 'mceButtonDisabled');
934 tinyMCE.switchClass(editor_id + '_unlink', 'mceButtonDisabled');
935 tinyMCE.switchClass(editor_id + '_outdent', 'mceButtonDisabled');
936 tinyMCE.switchClass(editor_id + '_image', 'mceButtonNormal');
937 tinyMCE.switchClass(editor_id + '_hr', 'mceButtonNormal');
939 if (node.nodeName == "A" && tinyMCE.getAttrib(node, "class").indexOf('mceItemAnchor') != -1)
940 tinyMCE.switchClass(editor_id + '_anchor', 'mceButtonSelected');
942 // Get link
943 var anchorLink = tinyMCE.getParentElement(node, "a", "href");
945 if (anchorLink || any_selection) {
946 tinyMCE.switchClass(editor_id + '_link', anchorLink ? 'mceButtonSelected' : 'mceButtonNormal');
947 tinyMCE.switchClass(editor_id + '_unlink', anchorLink ? 'mceButtonSelected' : 'mceButtonNormal');
950 // Handle visual aid
951 tinyMCE.switchClass(editor_id + '_visualaid', visual_aid ? 'mceButtonSelected' : 'mceButtonNormal');
953 if (undo_levels != -1) {
954 tinyMCE.switchClass(editor_id + '_undo', 'mceButtonDisabled');
955 tinyMCE.switchClass(editor_id + '_redo', 'mceButtonDisabled');
958 // Within li, blockquote
959 if (tinyMCE.getParentElement(node, "li,blockquote"))
960 tinyMCE.switchClass(editor_id + '_outdent', 'mceButtonNormal');
962 // Has redo levels
963 if (undo_index != -1 && (undo_index < undo_levels-1 && undo_levels > 0))
964 tinyMCE.switchClass(editor_id + '_redo', 'mceButtonNormal');
966 // Has undo levels
967 if (undo_index != -1 && (undo_index > 0 && undo_levels > 0))
968 tinyMCE.switchClass(editor_id + '_undo', 'mceButtonNormal');
970 // Select class in select box
971 var selectElm = document.getElementById(editor_id + "_styleSelect");
973 if (selectElm) {
974 TinyMCE_AdvancedTheme._setupCSSClasses(editor_id);
976 classNode = node;
977 breakOut = false;
978 var index = 0;
980 do {
981 if (classNode && classNode.className) {
982 for (var i=0; i<selectElm.options.length; i++) {
983 if (selectElm.options[i].value == classNode.className) {
984 index = i;
985 breakOut = true;
986 break;
990 } while (!breakOut && classNode != null && (classNode = classNode.parentNode) != null);
992 selectElm.selectedIndex = index;
995 // Select formatblock
996 var selectElm = document.getElementById(editor_id + "_formatSelect");
997 if (selectElm) {
998 var elm = tinyMCE.getParentElement(node, "p,div,h1,h2,h3,h4,h5,h6,pre,address");
1000 if (elm)
1001 selectByValue(selectElm, "<" + elm.nodeName.toLowerCase() + ">");
1002 else
1003 selectByValue(selectElm, "");
1006 // Select fontselect
1007 var selectElm = document.getElementById(editor_id + "_fontNameSelect");
1008 if (selectElm) {
1009 if (!tinyMCE.isSafari && !(tinyMCE.isMSIE && !tinyMCE.isOpera)) {
1010 var face = inst.queryCommandValue('FontName');
1012 face = face == null || face == "" ? "" : face;
1014 selectByValue(selectElm, face, face != "");
1015 } else {
1016 var elm = tinyMCE.getParentElement(node, "font", "face");
1018 if (elm) {
1019 var family = tinyMCE.getAttrib(elm, "face");
1021 if (family == '')
1022 family = '' + elm.style.fontFamily;
1024 if (!selectByValue(selectElm, family, family != ""))
1025 selectByValue(selectElm, "");
1026 } else
1027 selectByValue(selectElm, "");
1031 // Select fontsize
1032 var selectElm = document.getElementById(editor_id + "_fontSizeSelect");
1033 if (selectElm) {
1034 if (!tinyMCE.isSafari && !tinyMCE.isOpera) {
1035 var size = inst.queryCommandValue('FontSize');
1036 selectByValue(selectElm, size == null || size == "" ? "0" : size);
1037 } else {
1038 var elm = tinyMCE.getParentElement(node, "font", "size");
1039 if (elm) {
1040 var size = tinyMCE.getAttrib(elm, "size");
1042 if (size == '') {
1043 var sizes = new Array('', '8px', '10px', '12px', '14px', '18px', '24px', '36px');
1045 size = '' + elm.style.fontSize;
1047 for (var i=0; i<sizes.length; i++) {
1048 if (('' + sizes[i]) == size) {
1049 size = i;
1050 break;
1055 if (!selectByValue(selectElm, size))
1056 selectByValue(selectElm, "");
1057 } else
1058 selectByValue(selectElm, "0");
1062 // Handle align attributes
1063 alignNode = node;
1064 breakOut = false;
1065 do {
1066 if (!alignNode.getAttribute || !alignNode.getAttribute('align'))
1067 continue;
1069 switch (alignNode.getAttribute('align').toLowerCase()) {
1070 case "left":
1071 tinyMCE.switchClass(editor_id + '_justifyleft', 'mceButtonSelected');
1072 breakOut = true;
1073 break;
1075 case "right":
1076 tinyMCE.switchClass(editor_id + '_justifyright', 'mceButtonSelected');
1077 breakOut = true;
1078 break;
1080 case "middle":
1081 case "center":
1082 tinyMCE.switchClass(editor_id + '_justifycenter', 'mceButtonSelected');
1083 breakOut = true;
1084 break;
1086 case "justify":
1087 tinyMCE.switchClass(editor_id + '_justifyfull', 'mceButtonSelected');
1088 breakOut = true;
1089 break;
1091 } while (!breakOut && (alignNode = alignNode.parentNode) != null);
1093 // Div justification
1094 var div = tinyMCE.getParentElement(node, "div");
1095 if (div && div.style.textAlign == "center")
1096 tinyMCE.switchClass(editor_id + '_justifycenter', 'mceButtonSelected');
1098 // Do special text
1099 if (!setup_content) {
1100 // , "JustifyLeft", "_justifyleft", "JustifyCenter", "justifycenter", "JustifyRight", "justifyright", "JustifyFull", "justifyfull", "InsertUnorderedList", "bullist", "InsertOrderedList", "numlist", "InsertUnorderedList", "bullist", "Outdent", "outdent", "Indent", "indent", "subscript", "sub"
1101 var ar = new Array("Bold", "_bold", "Italic", "_italic", "Strikethrough", "_strikethrough", "superscript", "_sup", "subscript", "_sub");
1102 for (var i=0; i<ar.length; i+=2) {
1103 if (inst.queryCommandState(ar[i]))
1104 tinyMCE.switchClass(editor_id + ar[i+1], 'mceButtonSelected');
1107 if (inst.queryCommandState("Underline") && (node.parentNode == null || node.parentNode.nodeName != "A"))
1108 tinyMCE.switchClass(editor_id + '_underline', 'mceButtonSelected');
1111 // Handle elements
1112 do {
1113 switch (node.nodeName) {
1114 case "UL":
1115 tinyMCE.switchClass(editor_id + '_bullist', 'mceButtonSelected');
1116 break;
1118 case "OL":
1119 tinyMCE.switchClass(editor_id + '_numlist', 'mceButtonSelected');
1120 break;
1122 case "HR":
1123 tinyMCE.switchClass(editor_id + '_hr', 'mceButtonSelected');
1124 break;
1126 case "IMG":
1127 if (getAttrib(node, 'name').indexOf('mce_') != 0 && tinyMCE.getAttrib(node, 'class').indexOf('mceItem') == -1) {
1128 tinyMCE.switchClass(editor_id + '_image', 'mceButtonSelected');
1130 break;
1132 } while ((node = node.parentNode) != null);
1135 // Private theme internal functions
1137 // This function auto imports CSS classes into the class selection droplist
1138 _setupCSSClasses : function(editor_id) {
1139 var i, selectElm;
1141 if (!TinyMCE_AdvancedTheme._autoImportCSSClasses)
1142 return;
1144 selectElm = document.getElementById(editor_id + '_styleSelect');
1146 if (selectElm && selectElm.getAttribute('cssImported') != 'true') {
1147 var csses = tinyMCE.getCSSClasses(editor_id);
1148 if (csses && selectElm) {
1149 for (i=0; i<csses.length; i++)
1150 selectElm.options[selectElm.options.length] = new Option(csses[i], csses[i]);
1153 // Only do this once
1154 if (csses != null && csses.length > 0)
1155 selectElm.setAttribute('cssImported', 'true');
1159 _setCookie : function(name, value, expires, path, domain, secure) {
1160 var curCookie = name + "=" + escape(value) +
1161 ((expires) ? "; expires=" + expires.toGMTString() : "") +
1162 ((path) ? "; path=" + escape(path) : "") +
1163 ((domain) ? "; domain=" + domain : "") +
1164 ((secure) ? "; secure" : "");
1166 document.cookie = curCookie;
1169 _getCookie : function(name) {
1170 var dc = document.cookie;
1171 var prefix = name + "=";
1172 var begin = dc.indexOf("; " + prefix);
1174 if (begin == -1) {
1175 begin = dc.indexOf(prefix);
1177 if (begin != 0)
1178 return null;
1179 } else
1180 begin += 2;
1182 var end = document.cookie.indexOf(";", begin);
1184 if (end == -1)
1185 end = dc.length;
1187 return unescape(dc.substring(begin + prefix.length, end));
1190 _resizeTo : function(inst, w, h, set_w) {
1191 var editorContainer = document.getElementById(inst.editorId + '_parent');
1192 var tableElm = editorContainer.firstChild;
1193 var iframe = inst.iframeElement;
1195 if (w == null || w == "null") {
1196 set_w = false;
1197 w = 0;
1200 if (h == null || h == "null")
1201 return;
1203 w = parseInt(w);
1204 h = parseInt(h);
1206 if (tinyMCE.isGecko) {
1207 w += 2;
1208 h += 2;
1211 var dx = w - tableElm.clientWidth;
1212 var dy = h - tableElm.clientHeight;
1214 w = w < 1 ? 30 : w;
1215 h = h < 1 ? 30 : h;
1217 if (set_w)
1218 tableElm.style.width = w + "px";
1220 tableElm.style.height = h + "px";
1222 iw = iframe.clientWidth + dx;
1223 ih = iframe.clientHeight + dy;
1225 iw = iw < 1 ? 30 : iw;
1226 ih = ih < 1 ? 30 : ih;
1228 if (tinyMCE.isGecko) {
1229 iw -= 2;
1230 ih -= 2;
1233 if (set_w)
1234 iframe.style.width = iw + "px";
1236 iframe.style.height = ih + "px";
1238 // Is it to small, make it bigger again
1239 if (set_w) {
1240 var tableBodyElm = tableElm.firstChild;
1241 var minIframeWidth = tableBodyElm.scrollWidth;
1242 if (inst.iframeElement.clientWidth < minIframeWidth) {
1243 dx = minIframeWidth - inst.iframeElement.clientWidth;
1245 inst.iframeElement.style.width = (iw + dx) + "px";
1249 // Remove pesky table controls
1250 inst.useCSS = false;
1254 * Handles resizing events.
1256 _resizeEventHandler : function(e) {
1257 var resizer = TinyMCE_AdvancedTheme._resizer;
1259 // Do nothing
1260 if (!resizer.resizing)
1261 return;
1263 e = typeof(e) == "undefined" ? window.event : e;
1265 var dx = e.screenX - resizer.downX;
1266 var dy = e.screenY - resizer.downY;
1267 var resizeBox = resizer.resizeBox;
1268 var editorId = resizer.editorId;
1270 switch (e.type) {
1271 case "mousemove":
1272 var w, h;
1274 w = resizer.width + dx;
1275 h = resizer.height + dy;
1277 w = w < 1 ? 1 : w;
1278 h = h < 1 ? 1 : h;
1280 if (resizer.horizontal)
1281 resizeBox.style.width = w + "px";
1283 resizeBox.style.height = h + "px";
1284 break;
1286 case "mouseup":
1287 TinyMCE_AdvancedTheme._setResizing(e, editorId, false);
1288 TinyMCE_AdvancedTheme._resizeTo(tinyMCE.getInstanceById(editorId), resizer.width + dx, resizer.height + dy, resizer.horizontal);
1290 // Expire in a month
1291 if (tinyMCE.getParam("theme_advanced_resizing_use_cookie", true)) {
1292 var expires = new Date();
1293 expires.setTime(expires.getTime() + 3600000 * 24 * 30);
1295 // Set the cookies
1296 TinyMCE_AdvancedTheme._setCookie("TinyMCE_" + editorId + "_width", "" + (resizer.horizontal ? resizer.width + dx : ""), expires);
1297 TinyMCE_AdvancedTheme._setCookie("TinyMCE_" + editorId + "_height", "" + (resizer.height + dy), expires);
1299 break;
1304 * Starts/stops the editor resizing.
1306 _setResizing : function(e, editor_id, state) {
1307 e = typeof(e) == "undefined" ? window.event : e;
1309 var resizer = TinyMCE_AdvancedTheme._resizer;
1310 var editorContainer = document.getElementById(editor_id + '_parent');
1311 var editorArea = document.getElementById(editor_id + '_parent').firstChild;
1312 var resizeBox = document.getElementById(editor_id + '_resize_box');
1313 var inst = tinyMCE.getInstanceById(editor_id);
1315 if (state) {
1316 // Place box over editor area
1317 var width = editorArea.clientWidth;
1318 var height = editorArea.clientHeight;
1320 resizeBox.style.width = width + "px";
1321 resizeBox.style.height = height + "px";
1323 resizer.iframeWidth = inst.iframeElement.clientWidth;
1324 resizer.iframeHeight = inst.iframeElement.clientHeight;
1326 // Hide editor and show resize box
1327 editorArea.style.display = "none";
1328 resizeBox.style.display = "block";
1330 // Add event handlers, only once
1331 if (!resizer.eventHandlers) {
1332 if (tinyMCE.isMSIE)
1333 tinyMCE.addEvent(document, "mousemove", TinyMCE_AdvancedTheme._resizeEventHandler);
1334 else
1335 tinyMCE.addEvent(window, "mousemove", TinyMCE_AdvancedTheme._resizeEventHandler);
1337 tinyMCE.addEvent(document, "mouseup", TinyMCE_AdvancedTheme._resizeEventHandler);
1339 resizer.eventHandlers = true;
1342 resizer.resizing = true;
1343 resizer.downX = e.screenX;
1344 resizer.downY = e.screenY;
1345 resizer.width = parseInt(resizeBox.style.width);
1346 resizer.height = parseInt(resizeBox.style.height);
1347 resizer.editorId = editor_id;
1348 resizer.resizeBox = resizeBox;
1349 resizer.horizontal = tinyMCE.getParam("theme_advanced_resize_horizontal", true);
1350 } else {
1351 resizer.resizing = false;
1352 resizeBox.style.display = "none";
1353 editorArea.style.display = tinyMCE.isMSIE && !tinyMCE.isOpera ? "block" : "table";
1354 tinyMCE.execCommand('mceResetDesignMode');
1358 _getColorHTML : function(id, n, cm) {
1359 var i, h, cl;
1361 h = '<span class="mceMenuLine"></span>';
1362 cl = tinyMCE.getParam(n, TinyMCE_AdvancedTheme._defColors).split(',');
1364 h += '<table class="mceColors"><tr>';
1365 for (i=0; i<cl.length; i++) {
1366 c = 'tinyMCE.execInstanceCommand(\'' + id + '\', \'' + cm + '\', false, \'#' + cl[i] + '\');';
1367 h += '<td><a href="javascript:' + c + '" style="background-color: #' + cl[i] + '" onclick="' + c + ';return false;"></a></td>';
1369 if ((i+1) % 8 == 0)
1370 h += '</tr><tr>';
1373 h += '</tr></table>';
1375 h += '<a href="" class="mceMoreColors">More colors</a>';
1378 return h;
1381 _insertImage : function(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout) {
1382 tinyMCE.execCommand('mceBeginUndoLevel');
1384 if (src == "")
1385 return;
1387 if (!tinyMCE.imgElement && tinyMCE.isSafari) {
1388 var html = "";
1390 html += '<img src="' + src + '" alt="' + alt + '"';
1391 html += ' border="' + border + '" hspace="' + hspace + '"';
1392 html += ' vspace="' + vspace + '" width="' + width + '"';
1393 html += ' height="' + height + '" align="' + align + '" title="' + title + '" onmouseover="' + onmouseover + '" onmouseout="' + onmouseout + '" />';
1395 tinyMCE.execCommand("mceInsertContent", false, html);
1396 } else {
1397 if (!tinyMCE.imgElement && tinyMCE.selectedInstance) {
1398 if (tinyMCE.isSafari)
1399 tinyMCE.execCommand("mceInsertContent", false, '<img src="' + tinyMCE.uniqueURL + '" />');
1400 else
1401 tinyMCE.selectedInstance.contentDocument.execCommand("insertimage", false, tinyMCE.uniqueURL);
1403 tinyMCE.imgElement = tinyMCE.getElementByAttributeValue(tinyMCE.selectedInstance.contentDocument.body, "img", "src", tinyMCE.uniqueURL);
1407 if (tinyMCE.imgElement) {
1408 var needsRepaint = false;
1409 var msrc = src;
1411 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, tinyMCE.imgElement);");
1413 if (tinyMCE.getParam('convert_urls'))
1414 msrc = src;
1416 if (onmouseover && onmouseover != "")
1417 onmouseover = "this.src='" + eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseover, tinyMCE.imgElement);") + "';";
1419 if (onmouseout && onmouseout != "")
1420 onmouseout = "this.src='" + eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseout, tinyMCE.imgElement);") + "';";
1422 // Use alt as title if it's undefined
1423 if (typeof(title) == "undefined")
1424 title = alt;
1426 if (width != tinyMCE.imgElement.getAttribute("width") || height != tinyMCE.imgElement.getAttribute("height") || align != tinyMCE.imgElement.getAttribute("align"))
1427 needsRepaint = true;
1429 tinyMCE.setAttrib(tinyMCE.imgElement, 'src', src);
1430 tinyMCE.setAttrib(tinyMCE.imgElement, 'mce_src', msrc);
1431 tinyMCE.setAttrib(tinyMCE.imgElement, 'alt', alt);
1432 tinyMCE.setAttrib(tinyMCE.imgElement, 'title', title);
1433 tinyMCE.setAttrib(tinyMCE.imgElement, 'align', align);
1434 tinyMCE.setAttrib(tinyMCE.imgElement, 'border', border, true);
1435 tinyMCE.setAttrib(tinyMCE.imgElement, 'hspace', hspace, true);
1436 tinyMCE.setAttrib(tinyMCE.imgElement, 'vspace', vspace, true);
1437 tinyMCE.setAttrib(tinyMCE.imgElement, 'width', width, true);
1438 tinyMCE.setAttrib(tinyMCE.imgElement, 'height', height, true);
1439 tinyMCE.setAttrib(tinyMCE.imgElement, 'onmouseover', onmouseover);
1440 tinyMCE.setAttrib(tinyMCE.imgElement, 'onmouseout', onmouseout);
1442 // Fix for bug #989846 - Image resize bug
1443 if (width && width != "")
1444 tinyMCE.imgElement.style.pixelWidth = width;
1446 if (height && height != "")
1447 tinyMCE.imgElement.style.pixelHeight = height;
1449 if (needsRepaint)
1450 tinyMCE.selectedInstance.repaint();
1453 tinyMCE.execCommand('mceEndUndoLevel');
1456 _insertLink : function(href, target, title, onclick, style_class) {
1457 tinyMCE.execCommand('mceBeginUndoLevel');
1459 if (tinyMCE.selectedInstance && tinyMCE.selectedElement && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") {
1460 var doc = tinyMCE.selectedInstance.getDoc();
1461 var linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");
1462 var newLink = false;
1464 if (!linkElement) {
1465 linkElement = doc.createElement("a");
1466 newLink = true;
1469 var mhref = href;
1470 var thref = eval(tinyMCE.settings['urlconverter_callback'] + "(href, linkElement);");
1471 mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
1473 tinyMCE.setAttrib(linkElement, 'href', thref);
1474 tinyMCE.setAttrib(linkElement, 'mce_href', mhref);
1475 tinyMCE.setAttrib(linkElement, 'target', target);
1476 tinyMCE.setAttrib(linkElement, 'title', title);
1477 tinyMCE.setAttrib(linkElement, 'onclick', onclick);
1478 tinyMCE.setAttrib(linkElement, 'class', style_class);
1480 if (newLink) {
1481 linkElement.appendChild(tinyMCE.selectedElement.cloneNode(true));
1482 tinyMCE.selectedElement.parentNode.replaceChild(linkElement, tinyMCE.selectedElement);
1485 return;
1488 if (!tinyMCE.linkElement && tinyMCE.selectedInstance) {
1489 if (tinyMCE.isSafari) {
1490 tinyMCE.execCommand("mceInsertContent", false, '<a href="' + tinyMCE.uniqueURL + '">' + tinyMCE.selectedInstance.selection.getSelectedHTML() + '</a>');
1491 } else
1492 tinyMCE.selectedInstance.contentDocument.execCommand("createlink", false, tinyMCE.uniqueURL);
1494 tinyMCE.linkElement = tinyMCE.getElementByAttributeValue(tinyMCE.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);
1496 var elementArray = tinyMCE.getElementsByAttributeValue(tinyMCE.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);
1498 for (var i=0; i<elementArray.length; i++) {
1499 var mhref = href;
1500 var thref = eval(tinyMCE.settings['urlconverter_callback'] + "(href, elementArray[i]);");
1501 mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
1503 tinyMCE.setAttrib(elementArray[i], 'href', thref);
1504 tinyMCE.setAttrib(elementArray[i], 'mce_href', mhref);
1505 tinyMCE.setAttrib(elementArray[i], 'target', target);
1506 tinyMCE.setAttrib(elementArray[i], 'title', title);
1507 tinyMCE.setAttrib(elementArray[i], 'onclick', onclick);
1508 tinyMCE.setAttrib(elementArray[i], 'class', style_class);
1511 tinyMCE.linkElement = elementArray[0];
1514 if (tinyMCE.linkElement) {
1515 var mhref = href;
1516 href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement);");
1517 mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
1519 tinyMCE.setAttrib(tinyMCE.linkElement, 'href', href);
1520 tinyMCE.setAttrib(tinyMCE.linkElement, 'mce_href', mhref);
1521 tinyMCE.setAttrib(tinyMCE.linkElement, 'target', target);
1522 tinyMCE.setAttrib(tinyMCE.linkElement, 'title', title);
1523 tinyMCE.setAttrib(tinyMCE.linkElement, 'onclick', onclick);
1524 tinyMCE.setAttrib(tinyMCE.linkElement, 'class', style_class);
1527 tinyMCE.execCommand('mceEndUndoLevel');
1531 tinyMCE.addTheme("advanced", TinyMCE_AdvancedTheme);
1533 // Add default buttons maps for advanced theme and all internal plugins
1534 tinyMCE.addButtonMap(TinyMCE_AdvancedTheme._buttonMap);