1 /* Import theme specific language pack */
2 tinyMCE.importThemeLanguagePack('advanced');
4 // Variable declarations
5 var TinyMCE_advanced_autoImportCSSClasses = true;
6 var TinyMCE_advanced_resizer = new Object();
7 var TinyMCE_advanced_buttons = [
8 // Control id, button img, button title, command, user_interface, value
9 ['bold', '{$lang_bold_img}', '{$lang_bold_desc}', 'Bold'],
10 ['italic', '{$lang_italic_img}', '{$lang_italic_desc}', 'Italic'],
11 ['underline', '{$lang_underline_img}', '{$lang_underline_desc}', 'Underline'],
12 ['strikethrough', 'strikethrough.gif', '{$lang_striketrough_desc}', 'Strikethrough'],
13 ['justifyleft', 'left.gif', '{$lang_justifyleft_desc}', 'JustifyLeft'],
14 ['justifycenter', 'center.gif', '{$lang_justifycenter_desc}', 'JustifyCenter'],
15 ['justifyright', 'right.gif', '{$lang_justifyright_desc}', 'JustifyRight'],
16 ['justifyfull', 'full.gif', '{$lang_justifyfull_desc}', 'JustifyFull'],
17 ['bullist', 'bullist.gif', '{$lang_bullist_desc}', 'InsertUnorderedList'],
18 ['numlist', 'numlist.gif', '{$lang_numlist_desc}', 'InsertOrderedList'],
19 ['outdent', 'outdent.gif', '{$lang_outdent_desc}', 'Outdent'],
20 ['indent', 'indent.gif', '{$lang_indent_desc}', 'Indent'],
21 ['cut', 'cut.gif', '{$lang_cut_desc}', 'Cut'],
22 ['copy', 'copy.gif', '{$lang_copy_desc}', 'Copy'],
23 ['paste', 'paste.gif', '{$lang_paste_desc}', 'Paste'],
24 ['undo', 'undo.gif', '{$lang_undo_desc}', 'Undo'],
25 ['redo', 'redo.gif', '{$lang_redo_desc}', 'Redo'],
26 ['link', 'link.gif', '{$lang_link_desc}', 'mceLink', true],
27 ['unlink', 'unlink.gif', '{$lang_unlink_desc}', 'unlink'],
28 ['image', 'image.gif', '{$lang_image_desc}', 'mceImage', true],
29 ['cleanup', 'cleanup.gif', '{$lang_cleanup_desc}', 'mceCleanup'],
30 ['help', 'help.gif', '{$lang_help_desc}', 'mceHelp'],
31 ['code', 'code.gif', '{$lang_theme_code_desc}', 'mceCodeEditor'],
32 ['hr', 'hr.gif', '{$lang_theme_hr_desc}', 'inserthorizontalrule'],
33 ['removeformat', 'removeformat.gif', '{$lang_theme_removeformat_desc}', 'removeformat'],
34 ['sub', 'sub.gif', '{$lang_theme_sub_desc}', 'subscript'],
35 ['sup', 'sup.gif', '{$lang_theme_sup_desc}', 'superscript'],
36 ['forecolor', 'forecolor.gif', '{$lang_theme_forecolor_desc}', 'mceForeColor', true],
37 ['backcolor', 'backcolor.gif', '{$lang_theme_backcolor_desc}', 'mceBackColor', true],
38 ['charmap', 'charmap.gif', '{$lang_theme_charmap_desc}', 'mceCharMap'],
39 ['visualaid', 'visualaid.gif', '{$lang_theme_visualaid_desc}', 'mceToggleVisualAid'],
40 ['anchor', 'anchor.gif', '{$lang_theme_anchor_desc}', 'mceInsertAnchor'],
41 ['newdocument', 'newdocument.gif', '{$lang_newdocument_desc}', 'mceNewDocument']
45 * Returns HTML code for the specificed control.
47 function TinyMCE_advanced_getControlHTML(button_name)
49 var buttonTileMap = new Array('anchor.gif','backcolor.gif','bullist.gif','center.gif',
50 'charmap.gif','cleanup.gif','code.gif','copy.gif','custom_1.gif',
51 'cut.gif','forecolor.gif','full.gif','help.gif','hr.gif',
52 'image.gif','indent.gif','left.gif','link.gif','numlist.gif',
53 'outdent.gif','paste.gif','redo.gif','removeformat.gif',
54 'right.gif','strikethrough.gif','sub.gif','sup.gif','undo.gif',
55 'unlink.gif','visualaid.gif');
57 // Lookup button in button list
58 for (var i=0; i<TinyMCE_advanced_buttons.length; i++)
60 var but = TinyMCE_advanced_buttons[i];
62 if (but[0] == button_name)
64 // Check for it in tilemap
65 if (tinyMCE.settings['button_tile_map'])
67 for (var x=0; !tinyMCE.isMSIE && x<buttonTileMap.length; x++)
69 if (buttonTileMap[x] == but[1])
71 return '<a href="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + but[3] + '\', ' + (but.length > 4 ? but[4] : false) + (but.length > 5 ? ', \'' + but[5] + '\'' : '') + ')" onmousedown="return false;"><img id="{$editor_id}_' + but[0] +'" src="{$themeurl}/images/spacer.gif" style="background-image:url({$themeurl}/images/buttons.gif); background-position: ' + (0-(x*20)) + 'px 0px" title="' + but[2] + '" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';
77 return '<a href="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + but[3] + '\', ' + (but.length > 4 ? but[4] : false) + (but.length > 5 ? ', \'' + but[5] + '\'' : '') + ')" onmousedown="return false;"><img id="{$editor_id}_' + but[0] + '" src="{$themeurl}/images/' + but[1] + '" title="' + but[2] + '" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';
81 // Custom controlls other than buttons
85 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">';
86 var formats = tinyMCE.getParam("theme_advanced_blockformats", "p,address,pre,h1,h2,h3,h4,h5,h6", true).split(',');
88 ['p', '{$lang_theme_paragraph}'],
89 ['address', '{$lang_theme_address}'],
90 ['pre', '{$lang_theme_pre}'],
91 ['h1', '{$lang_theme_h1}'],
92 ['h2', '{$lang_theme_h2}'],
93 ['h3', '{$lang_theme_h3}'],
94 ['h4', '{$lang_theme_h4}'],
95 ['h5', '{$lang_theme_h5}'],
96 ['h6', '{$lang_theme_h6}']
99 html += '<option value="">{$lang_theme_block}</option>';
101 // Build format select
102 for (var i=0; i<formats.length; i++)
104 for (var x=0; x<lookup.length; x++)
106 if (formats[i] == lookup[x][0])
108 html += '<option value="<' + lookup[x][0] + '>">' + lookup[x][1] + '</option>';
119 return '<select id="{$editor_id}_styleSelect" onmousedown="TinyMCE_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>';
122 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>';
123 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';
124 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';
125 var fonts = tinyMCE.getParam("theme_advanced_fonts", nFonts).split(';');
126 for (var i=0; i<fonts.length; i++) {
127 if (fonts[i] != '') {
128 var parts = fonts[i].split('=');
129 fontHTML += '<option value="' + parts[1] + '">' + parts[0] + '</option>';
133 fontHTML += '</select>';
136 case "fontsizeselect":
138 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">\
139 <option value="0">{$lang_theme_font_size}</option>\
140 <option value="1">1 (8 pt)</option>\
141 <option value="2">2 (10 pt)</option>\
142 <option value="3">3 (12 pt)</option>\
143 <option value="4">4 (14 pt)</option>\
144 <option value="5">5 (18 pt)</option>\
145 <option value="6">6 (24 pt)</option>\
146 <option value="7">7 (36 pt)</option>\
151 return '<img src="{$themeurl}/images/spacer.gif" width="1" height="15" class="mceSeparatorLine">';
154 return '<img src="{$themeurl}/images/spacer.gif" width="1" height="15" border="0" class="mceSeparatorLine" style="vertical-align: middle" />';
164 * Theme specific exec command handeling.
166 function TinyMCE_advanced_execCommand(editor_id, element, command, user_interface, value)
171 var template = new Array();
172 var elm = tinyMCE.selectedInstance.getFocusElement();
173 var inputColor = tinyMCE.getAttrib(elm, "color");
175 if (inputColor == '')
176 inputColor = elm.style.color;
179 inputColor = "#000000";
181 template['file'] = 'color_picker.htm';
182 template['width'] = 220;
183 template['height'] = 190;
185 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes", command : "forecolor", input_color : inputColor});
189 var template = new Array();
190 var elm = tinyMCE.selectedInstance.getFocusElement();
191 var inputColor = elm.style.backgroundColor;
194 inputColor = "#000000";
196 template['file'] = 'color_picker.htm';
197 template['width'] = 220;
198 template['height'] = 190;
200 template['width'] += tinyMCE.getLang('lang_theme_advanced_backcolor_delta_width', 0);
201 template['height'] += tinyMCE.getLang('lang_theme_advanced_backcolor_delta_height', 0);
203 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes", command : "HiliteColor", input_color : inputColor});
207 case "mceColorPicker":
208 if (user_interface) {
209 var template = new Array();
210 var inputColor = value['document'].getElementById(value['element_id']).value;
212 template['file'] = 'color_picker.htm';
213 template['width'] = 220;
214 template['height'] = 190;
216 template['width'] += tinyMCE.getLang('lang_theme_advanced_colorpicker_delta_width', 0);
217 template['height'] += tinyMCE.getLang('lang_theme_advanced_colorpicker_delta_height', 0);
219 if (typeof(value['store_selection']) == "undefined")
220 value['store_selection'] = true;
222 tinyMCE.lastColorPickerValue = value;
223 tinyMCE.openWindow(template, {editor_id : editor_id, mce_store_selection : value['store_selection'], inline : "yes", command : "mceColorPicker", input_color : inputColor});
225 var savedVal = tinyMCE.lastColorPickerValue;
226 var elm = savedVal['document'].getElementById(savedVal['element_id']);
228 eval('elm.onchange();');
232 case "mceCodeEditor":
233 var template = new Array();
235 template['file'] = 'source_editor.htm';
236 template['width'] = parseInt(tinyMCE.getParam("theme_advanced_source_editor_width", 500));
237 template['height'] = parseInt(tinyMCE.getParam("theme_advanced_source_editor_height", 400));
239 tinyMCE.openWindow(template, {editor_id : editor_id, resizable : "yes", scrollbars : "no", inline : "yes"});
244 var template = new Array();
246 template['file'] = 'charmap.htm';
247 template['width'] = 550;
248 template['height'] = 250;
250 template['width'] += tinyMCE.getLang('lang_theme_advanced_charmap_delta_width', 0);
251 template['height'] += tinyMCE.getLang('lang_theme_advanced_charmap_delta_height', 0);
253 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
257 case "mceInsertAnchor":
258 var template = new Array();
260 template['file'] = 'anchor.htm';
261 template['width'] = 320;
262 template['height'] = 90;
264 template['width'] += tinyMCE.getLang('lang_theme_advanced_anchor_delta_width', 0);
265 template['height'] += tinyMCE.getLang('lang_theme_advanced_anchor_delta_height', 0);
267 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
270 case "mceNewDocument":
271 if (confirm(tinyMCE.getLang('lang_newdocument')))
272 tinyMCE.execInstanceCommand(editor_id, 'mceSetContent', false, '');
282 * Editor instance template function.
284 function TinyMCE_advanced_getEditorTemplate(settings, editorId)
286 function removeFromArray(in_array, remove_array)
288 var outArray = new Array();
290 for (var i=0; i<in_array.length; i++)
294 for (var j=0; j<remove_array.length; j++)
296 if (in_array[i] == remove_array[j])
304 outArray[outArray.length] = in_array[i];
311 function addToArray(in_array, add_array)
313 for (var i=0; i<add_array.length; i++)
315 in_array[in_array.length] = add_array[i];
321 var template = new Array();
324 var resizing = tinyMCE.getParam("theme_advanced_resizing", false);
325 var path = tinyMCE.getParam("theme_advanced_path", true);
326 var statusbarHTML = '<div id="{$editor_id}_path" class="mceStatusbarPathText" style="display: ' + (path ? "block" : "none") + '"> </div><div id="{$editor_id}_resize" class="mceStatusbarResize" style="display: ' + (resizing ? "block" : "none") + '" onmousedown="TinyMCE_advanced_setResizing(event,\'{$editor_id}\',true);"></div><br style="clear: both" />';
327 var layoutManager = tinyMCE.getParam("theme_advanced_layout_manager", "SimpleLayout");
329 // Setup style select options -- MOVED UP FOR EXTERNAL TOOLBAR COMPATABILITY!
330 var styleSelectHTML = '<option value="">{$lang_theme_style_select}</option>';
331 if (settings['theme_advanced_styles'])
333 var stylesAr = settings['theme_advanced_styles'].split(';');
335 for (var i=0; i<stylesAr.length; i++)
339 key = stylesAr[i].split('=')[0];
340 value = stylesAr[i].split('=')[1];
342 styleSelectHTML += '<option value="' + value + '">' + key + '</option>';
345 TinyMCE_advanced_autoImportCSSClasses = false;
348 switch(layoutManager)
350 case "SimpleLayout" : //the default TinyMCE Layout (for backwards compatibility)...
351 var toolbarHTML = "";
352 var toolbarLocation = tinyMCE.getParam("theme_advanced_toolbar_location", "bottom");
353 var toolbarAlign = tinyMCE.getParam("theme_advanced_toolbar_align", "center");
354 var pathLocation = tinyMCE.getParam("theme_advanced_path_location", "none"); // Compatiblity
355 var statusbarLocation = tinyMCE.getParam("theme_advanced_statusbar_location", pathLocation);
357 theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,styleselect,formatselect",
358 theme_advanced_buttons2 : "bullist,numlist,separator,outdent,indent,separator,undo,redo,separator,link,unlink,anchor,image,cleanup,help,code",
359 theme_advanced_buttons3 : "hr,removeformat,visualaid,separator,sub,sup,separator,charmap"
363 for (var i=1; i<100; i++) {
364 var def = defVals["theme_advanced_buttons" + i];
366 buttons = tinyMCE.getParam("theme_advanced_buttons" + i, def == null ? '' : def, true, ',');
367 if (buttons.length == 0)
370 buttons = removeFromArray(buttons, tinyMCE.getParam("theme_advanced_disable", "", true, ','));
371 buttons = addToArray(buttons, tinyMCE.getParam("theme_advanced_buttons" + i + "_add", "", true, ','));
372 buttons = addToArray(tinyMCE.getParam("theme_advanced_buttons" + i + "_add_before", "", true, ','), buttons);
374 for (var b=0; b<buttons.length; b++)
375 toolbarHTML += tinyMCE.getControlHTML(buttons[b]);
377 if (buttons.length > 0) {
378 toolbarHTML += "<br />";
383 // Setup template html
384 template['html'] = '<table class="mceEditor" border="0" cellpadding="0" cellspacing="0" width="{$width}" height="{$height}" style="width:{$width}px;height:{$height}px"><tbody>';
386 if (toolbarLocation == "top")
388 template['html'] += '<tr><td class="mceToolbarTop" align="' + toolbarAlign + '" height="1" nowrap="nowrap">' + toolbarHTML + '</td></tr>';
391 if (statusbarLocation == "top")
393 template['html'] += '<tr><td class="mceStatusbarTop" height="1">' + statusbarHTML + '</td></tr>';
397 template['html'] += '<tr><td align="center"><span id="{$editor_id}"></span></td></tr>';
399 if (toolbarLocation == "bottom")
401 template['html'] += '<tr><td class="mceToolbarBottom" align="' + toolbarAlign + '" height="1">' + toolbarHTML + '</td></tr>';
404 // External toolbar changes
405 if (toolbarLocation == "external")
407 var bod = document.body;
408 var elm = document.createElement ("div");
410 toolbarHTML = tinyMCE.replaceVars(toolbarHTML, tinyMCE.settings);
411 toolbarHTML = tinyMCE.replaceVars(toolbarHTML, tinyMCELang);
412 toolbarHTML = tinyMCE.replaceVar(toolbarHTML, 'style_select_options', styleSelectHTML);
413 toolbarHTML = tinyMCE.replaceVar(toolbarHTML, "editor_id", editorId);
414 toolbarHTML = tinyMCE.applyTemplate(toolbarHTML);
416 elm.className = "mceToolbarExternal";
417 elm.id = editorId+"_toolbar";
418 elm.innerHTML = '<table width="100%" border="0" align="center"><tr><td align="center">'+toolbarHTML+'</td></tr></table>';
419 bod.appendChild (elm);
420 // bod.style.marginTop = elm.offsetHeight + "px";
423 tinyMCE.getInstanceById(editorId).toolbarElement = elm;
425 //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"];
429 tinyMCE.getInstanceById(editorId).toolbarElement = null;
432 if (statusbarLocation == "bottom")
434 template['html'] += '<tr><td class="mceStatusbarBottom" height="1">' + statusbarHTML + '</td></tr>';
438 template['html'] += '</table>';
442 case "RowLayout" : //Container Layout - containers defined in "theme_advanced_containers" are rendered from top to bottom.
443 template['html'] = '<table class="mceEditor" border="0" cellpadding="0" cellspacing="0" width="{$width}" height="{$height}" style="width:{$width}px;height:{$height}px"><tbody>';
445 var containers = tinyMCE.getParam("theme_advanced_containers", "", true, ",");
446 var defaultContainerCSS = tinyMCE.getParam("theme_advanced_containers_default_class", "container");
447 var defaultContainerAlign = tinyMCE.getParam("theme_advanced_containers_default_align", "center");
450 for (var i = 0; i < containers.length; i++)
452 if (containers[i] == "mceEditor") //Exceptions for mceEditor and ...
454 template['html'] += '<tr><td align="center" class="mceEditor_border">\
455 <span id="{$editor_id}"></span>\
458 else if (containers[i] == "mceElementpath" || containers[i] == "mceStatusbar") // ... mceElementpath:
460 var pathClass = "mceStatusbar";
462 if (i == containers.length-1)
464 pathClass = "mceStatusbarBottom";
468 pathClass = "mceStatusbar";
475 template['html'] += '<tr><td class="' + pathClass + '" height="1">' + statusbarHTML + '</td></tr>';
478 else //Render normal Container:
480 var curContainer = tinyMCE.getParam("theme_advanced_container_"+containers[i], "", true, ',');
481 var curContainerHTML = "";
482 var curAlign = tinyMCE.getParam("theme_advanced_container_"+containers[i]+"_align", defaultContainerAlign);
483 var curCSS = tinyMCE.getParam("theme_advanced_container_"+containers[i]+"_class", defaultContainerCSS);
485 for (var j=0; j<curContainer.length; j++)
487 curContainerHTML += tinyMCE.getControlHTML(curContainer[j]);
490 if (curContainer.length > 0)
492 curContainerHTML += "<br />";
496 template['html'] += '<tr><td class="' + curCSS + '" align="' + curAlign + '" height="1">' + curContainerHTML + '</td></tr>';
500 template['html'] += '</tbody></table>';
504 case "BorderLayout" : //will be like java.awt.BorderLayout of SUN Java...
505 // Not implemented yet...
508 case "CustomLayout" : //User defined layout callback...
509 var customLayout = tinyMCE.getParam("theme_advanced_custom_layout","");
511 if (customLayout != "" && eval("typeof(" + customLayout + ")") != "undefined")
513 template = eval(customLayout + "(template);");
518 alert('UNDEFINED LAYOUT MANAGER! PLEASE CHECK YOUR TINYMCE CONFIG!');
523 template['html'] += '<div id="{$editor_id}_resize_box" class="mceResizeBox"></div>';
524 template['html'] = tinyMCE.replaceVar(template['html'], 'style_select_options', styleSelectHTML);
525 template['delta_width'] = 0;
526 template['delta_height'] = deltaHeight;
532 * Starts/stops the editor resizing.
534 function TinyMCE_advanced_setResizing(e, editor_id, state) {
535 e = typeof(e) == "undefined" ? window.event : e;
537 var resizer = TinyMCE_advanced_resizer;
538 var editorContainer = document.getElementById(editor_id + '_parent');
539 var editorArea = document.getElementById(editor_id + '_parent').firstChild;
540 var resizeBox = document.getElementById(editor_id + '_resize_box');
541 var inst = tinyMCE.getInstanceById(editor_id);
544 // Place box over editor area
545 var width = editorArea.clientWidth;
546 var height = editorArea.clientHeight;
548 resizeBox.style.width = width + "px";
549 resizeBox.style.height = height + "px";
551 resizer.iframeWidth = inst.iframeElement.clientWidth;
552 resizer.iframeHeight = inst.iframeElement.clientHeight;
554 // Hide editor and show resize box
555 editorArea.style.display = "none";
556 resizeBox.style.display = "block";
558 // Add event handlers, only once
559 if (!resizer.eventHandlers) {
561 tinyMCE.addEvent(document, "mousemove", TinyMCE_advanced_resizeEventHandler);
563 tinyMCE.addEvent(window, "mousemove", TinyMCE_advanced_resizeEventHandler);
565 tinyMCE.addEvent(document, "mouseup", TinyMCE_advanced_resizeEventHandler);
567 resizer.eventHandlers = true;
570 resizer.resizing = true;
571 resizer.downX = e.screenX;
572 resizer.downY = e.screenY;
573 resizer.width = parseInt(resizeBox.style.width);
574 resizer.height = parseInt(resizeBox.style.height);
575 resizer.editorId = editor_id;
576 resizer.resizeBox = resizeBox;
577 resizer.horizontal = tinyMCE.getParam("theme_advanced_resize_horizontal", true);
579 resizer.resizing = false;
580 resizeBox.style.display = "none";
581 editorArea.style.display = tinyMCE.isMSIE ? "block" : "table";
582 tinyMCE.execCommand('mceResetDesignMode');
586 function TinyMCE_advanced_initInstance(inst) {
587 if (tinyMCE.getParam("theme_advanced_resizing", false)) {
588 var w = TinyMCE_advanced_getCookie("TinyMCE_" + inst.editorId + "_width");
589 var h = TinyMCE_advanced_getCookie("TinyMCE_" + inst.editorId + "_height");
591 TinyMCE_advanced_resizeTo(inst, w, h, tinyMCE.getParam("theme_advanced_resize_horizontal", true));
595 function TinyMCE_advanced_setCookie(name, value, expires, path, domain, secure) {
596 var curCookie = name + "=" + escape(value) +
597 ((expires) ? "; expires=" + expires.toGMTString() : "") +
598 ((path) ? "; path=" + escape(path) : "") +
599 ((domain) ? "; domain=" + domain : "") +
600 ((secure) ? "; secure" : "");
602 document.cookie = curCookie;
605 function TinyMCE_advanced_getCookie(name) {
606 var dc = document.cookie;
607 var prefix = name + "=";
608 var begin = dc.indexOf("; " + prefix);
611 begin = dc.indexOf(prefix);
618 var end = document.cookie.indexOf(";", begin);
623 return unescape(dc.substring(begin + prefix.length, end));
626 function TinyMCE_advanced_resizeTo(inst, w, h, set_w) {
627 var editorContainer = document.getElementById(inst.editorId + '_parent');
628 var tableElm = editorContainer.firstChild;
629 var iframe = inst.iframeElement;
631 if (w == null || w == "null") {
636 if (h == null || h == "null")
642 if (tinyMCE.isGecko) {
647 var dx = w - tableElm.clientWidth;
648 var dy = h - tableElm.clientHeight;
651 tableElm.style.width = w + "px";
653 tableElm.style.height = h + "px";
655 iw = iframe.clientWidth + dx;
656 ih = iframe.clientHeight + dy;
658 if (tinyMCE.isGecko) {
664 iframe.style.width = iw + "px";
666 iframe.style.height = ih + "px";
668 // Is it to small, make it bigger again
670 var tableBodyElm = tableElm.firstChild;
671 var minIframeWidth = tableBodyElm.scrollWidth;
672 if (inst.iframeElement.clientWidth < minIframeWidth) {
673 dx = minIframeWidth - inst.iframeElement.clientWidth;
675 inst.iframeElement.style.width = (iw + dx) + "px";
681 * Handles resizing events.
683 function TinyMCE_advanced_resizeEventHandler(e) {
684 var resizer = TinyMCE_advanced_resizer;
687 if (!resizer.resizing)
690 e = typeof(e) == "undefined" ? window.event : e;
692 var dx = e.screenX - resizer.downX;
693 var dy = e.screenY - resizer.downY;
694 var resizeBox = resizer.resizeBox;
695 var editorId = resizer.editorId;
699 if (resizer.horizontal)
700 resizeBox.style.width = (resizer.width + dx) + "px";
702 resizeBox.style.height = (resizer.height + dy) + "px";
706 TinyMCE_advanced_setResizing(e, editorId, false);
707 TinyMCE_advanced_resizeTo(tinyMCE.getInstanceById(editorId), resizer.width + dx, resizer.height + dy, resizer.horizontal);
710 var expires = new Date();
711 expires.setTime(expires.getTime() + 3600000 * 24 * 30);
714 TinyMCE_advanced_setCookie("TinyMCE_" + editorId + "_width", "" + (resizer.horizontal ? resizer.width + dx : ""), expires);
715 TinyMCE_advanced_setCookie("TinyMCE_" + editorId + "_height", "" + (resizer.height + dy), expires);
721 * Insert link template function.
723 function TinyMCE_advanced_getInsertLinkTemplate()
725 var template = new Array();
727 template['file'] = 'link.htm';
728 template['width'] = 330;
729 template['height'] = 170;
731 // Language specific width and height addons
732 template['width'] += tinyMCE.getLang('lang_insert_link_delta_width', 0);
733 template['height'] += tinyMCE.getLang('lang_insert_link_delta_height', 0);
739 * Insert image template function.
741 function TinyMCE_advanced_getInsertImageTemplate()
743 var template = new Array();
745 template['file'] = 'image.htm?src={$src}';
746 template['width'] = 340;
747 template['height'] = 245;
749 // Language specific width and height addons
750 template['width'] += tinyMCE.getLang('lang_insert_image_delta_width', 0);
751 template['height'] += tinyMCE.getLang('lang_insert_image_delta_height', 0);
757 * Node change handler.
759 function TinyMCE_advanced_handleNodeChange (editor_id, node, undo_index,
760 undo_levels, visual_aid, any_selection)
762 function selectByValue(select_elm, value)
766 for (var i=0; i<select_elm.options.length; i++)
768 if (select_elm.options[i].value == value)
770 select_elm.selectedIndex = i;
779 function getAttrib(elm, name)
781 return elm.getAttribute(name) ? elm.getAttribute(name) : "";
791 var pathElm = document.getElementById(editor_id + "_path");
796 var parentNode = node;
797 var path = new Array();
801 if (parentNode.nodeName.toLowerCase() == "body")
806 // Only append element nodes to path
807 if (parentNode.nodeType == 1)
809 path[path.length] = parentNode;
812 parentNode = parentNode.parentNode;
817 for (var i=path.length-1; i>=0; i--)
819 var nodeName = path[i].nodeName.toLowerCase();
832 if (getAttrib(path[i], 'id') != "")
834 nodeData += "id: " + path[i].getAttribute('id') + " ";
837 var className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(path[i], "class"), false);
838 if (className != "" && className.indexOf('mceItem') == -1)
839 nodeData += "class: " + className + " ";
841 if (getAttrib(path[i], 'src') != "")
843 nodeData += "src: " + path[i].getAttribute('src') + " ";
846 if (getAttrib(path[i], 'href') != "")
848 nodeData += "href: " + path[i].getAttribute('href') + " ";
851 if (nodeName == "img" && tinyMCE.getAttrib(path[i], "class").indexOf('mceItemFlash') != -1)
857 if (nodeName == "a" && (anchor = tinyMCE.getAttrib(path[i], "name")) != "")
860 nodeName += "#" + anchor;
864 if (getAttrib(path[i], 'name').indexOf("mce_") != 0)
866 var className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(path[i], "class"), false);
867 if (className != "" && className.indexOf('mceItem') == -1)
868 nodeName += "." + className;
873 html += '<a title="' + nodeData + '" href="javascript:void(0);" onmousedown="tinyMCE.execInstanceCommand(\'' + editor_id + '\',\'mceSelectNodeDepth\',false,\'' + i + '\');return false;" class="mcePathItem">' + nodeName + '</a>';
877 html += '<a title="' + nodeData + '" href="javascript:tinyMCE.execInstanceCommand(\'' + editor_id + '\',\'mceSelectNodeDepth\',false,\'' + i + '\');" class="mcePathItem">' + nodeName + '</a>';
886 pathElm.innerHTML = tinyMCE.getLang('lang_theme_path') + ": " + html + ' ';
890 tinyMCE.switchClassSticky(editor_id + '_justifyleft', 'mceButtonNormal');
891 tinyMCE.switchClassSticky(editor_id + '_justifyright', 'mceButtonNormal');
892 tinyMCE.switchClassSticky(editor_id + '_justifycenter', 'mceButtonNormal');
893 tinyMCE.switchClassSticky(editor_id + '_justifyfull', 'mceButtonNormal');
894 tinyMCE.switchClassSticky(editor_id + '_bold', 'mceButtonNormal');
895 tinyMCE.switchClassSticky(editor_id + '_italic', 'mceButtonNormal');
896 tinyMCE.switchClassSticky(editor_id + '_underline', 'mceButtonNormal');
897 tinyMCE.switchClassSticky(editor_id + '_strikethrough', 'mceButtonNormal');
898 tinyMCE.switchClassSticky(editor_id + '_bullist', 'mceButtonNormal');
899 tinyMCE.switchClassSticky(editor_id + '_numlist', 'mceButtonNormal');
900 tinyMCE.switchClassSticky(editor_id + '_sub', 'mceButtonNormal');
901 tinyMCE.switchClassSticky(editor_id + '_sup', 'mceButtonNormal');
902 tinyMCE.switchClassSticky(editor_id + '_anchor', 'mceButtonNormal');
903 tinyMCE.switchClassSticky(editor_id + '_link', 'mceButtonDisabled', true);
904 tinyMCE.switchClassSticky(editor_id + '_unlink', 'mceButtonDisabled', true);
905 tinyMCE.switchClassSticky(editor_id + '_outdent', 'mceButtonDisabled', true);
906 tinyMCE.switchClassSticky(editor_id + '_image', 'mceButtonNormal');
907 tinyMCE.switchClassSticky(editor_id + '_hr', 'mceButtonNormal');
909 if (node.nodeName == "A" && tinyMCE.getAttrib(node, "class").indexOf('mceItemAnchor') != -1)
910 tinyMCE.switchClassSticky(editor_id + '_anchor', 'mceButtonSelected');
913 var anchorLink = tinyMCE.getParentElement(node, "a", "href");
915 if (anchorLink || any_selection)
917 tinyMCE.switchClassSticky(editor_id + '_link', anchorLink ? 'mceButtonSelected' : 'mceButtonNormal', false);
918 tinyMCE.switchClassSticky(editor_id + '_unlink', anchorLink ? 'mceButtonSelected' : 'mceButtonNormal', false);
922 tinyMCE.switchClassSticky(editor_id + '_visualaid', visual_aid ? 'mceButtonSelected' : 'mceButtonNormal', false);
924 if (undo_levels != -1)
926 tinyMCE.switchClassSticky(editor_id + '_undo', 'mceButtonDisabled', true);
927 tinyMCE.switchClassSticky(editor_id + '_redo', 'mceButtonDisabled', true);
930 // Within li, blockquote
931 if (tinyMCE.getParentElement(node, "li,blockquote"))
933 tinyMCE.switchClassSticky(editor_id + '_outdent', 'mceButtonNormal', false);
937 if (undo_index != -1 && (undo_index < undo_levels-1 && undo_levels > 0))
939 tinyMCE.switchClassSticky(editor_id + '_redo', 'mceButtonNormal', false);
943 if (undo_index != -1 && (undo_index > 0 && undo_levels > 0))
945 tinyMCE.switchClassSticky(editor_id + '_undo', 'mceButtonNormal', false);
948 // Select class in select box
949 var selectElm = document.getElementById(editor_id + "_styleSelect");
953 TinyMCE_advanced_setupCSSClasses(editor_id);
961 if (classNode && classNode.className)
963 for (var i=0; i<selectElm.options.length; i++)
965 if (selectElm.options[i].value == classNode.className)
973 } while (!breakOut && classNode != null && (classNode = classNode.parentNode));
975 selectElm.selectedIndex = index;
978 // Select formatblock
979 var selectElm = document.getElementById(editor_id + "_formatSelect");
983 var elm = tinyMCE.getParentElement(node, "p,div,h1,h2,h3,h4,h5,h6,pre,address");
987 selectByValue(selectElm, "<" + elm.nodeName.toLowerCase() + ">");
991 selectByValue(selectElm, "");
996 var selectElm = document.getElementById(editor_id + "_fontNameSelect");
998 var elm = tinyMCE.getParentElement(node);
1001 var family = tinyMCE.getAttrib(elm, "face");
1003 family = '' + elm.style.fontFamily;
1005 if (!selectByValue(selectElm, family))
1006 selectByValue(selectElm, "");
1008 selectByValue(selectElm, "");
1012 var selectElm = document.getElementById(editor_id + "_fontSizeSelect");
1014 var elm = tinyMCE.getParentElement(node);
1017 var size = tinyMCE.getAttrib(elm, "size");
1019 var sizes = new Array('', '8px', '10px', '12px', '14px', '18px', '24px', '36px');
1021 size = '' + elm.style.fontSize;
1023 for (var i=0; i<sizes.length; i++) {
1024 if (('' + sizes[i]) == size) {
1031 if (!selectByValue(selectElm, size))
1032 selectByValue(selectElm, "");
1034 selectByValue(selectElm, "0");
1037 // Handle align attributes
1042 if (!alignNode.getAttribute || !alignNode.getAttribute('align'))
1047 switch (alignNode.getAttribute('align').toLowerCase())
1050 tinyMCE.switchClassSticky(editor_id + '_justifyleft', 'mceButtonSelected');
1055 tinyMCE.switchClassSticky(editor_id + '_justifyright', 'mceButtonSelected');
1061 tinyMCE.switchClassSticky(editor_id + '_justifycenter', 'mceButtonSelected');
1066 tinyMCE.switchClassSticky(editor_id + '_justifyfull', 'mceButtonSelected');
1070 } while (!breakOut && (alignNode = alignNode.parentNode));
1072 // Div justification
1073 var div = tinyMCE.getParentElement(node, "div");
1074 if (div && div.style.textAlign == "center")
1075 tinyMCE.switchClassSticky(editor_id + '_justifycenter', 'mceButtonSelected');
1078 if (tinyMCE.isGecko && node.nodeType == 3)
1080 var inst = tinyMCE.getInstanceById(editor_id);
1081 var doc = inst.getDoc();
1083 if (doc.queryCommandState("Bold"))
1085 tinyMCE.switchClassSticky(editor_id + '_bold', 'mceButtonSelected');
1088 if (doc.queryCommandState("Italic"))
1090 tinyMCE.switchClassSticky(editor_id + '_italic', 'mceButtonSelected');
1093 if (doc.queryCommandState("Underline") &&
1094 (node.parentNode == null || node.parentNode.nodeName != "A"))
1096 tinyMCE.switchClassSticky(editor_id + '_underline', 'mceButtonSelected');
1099 if (doc.queryCommandState("Strikethrough"))
1101 tinyMCE.switchClassSticky(editor_id + '_strikethrough', 'mceButtonSelected');
1108 switch (node.nodeName.toLowerCase())
1112 tinyMCE.switchClassSticky(editor_id + '_bold', 'mceButtonSelected');
1117 tinyMCE.switchClassSticky(editor_id + '_italic', 'mceButtonSelected');
1121 tinyMCE.switchClassSticky(editor_id + '_underline', 'mceButtonSelected');
1125 tinyMCE.switchClassSticky(editor_id + '_strikethrough', 'mceButtonSelected');
1129 tinyMCE.switchClassSticky(editor_id + '_bullist', 'mceButtonSelected');
1133 tinyMCE.switchClassSticky(editor_id + '_numlist', 'mceButtonSelected');
1137 tinyMCE.switchClassSticky(editor_id + '_sub', 'mceButtonSelected');
1141 tinyMCE.switchClassSticky(editor_id + '_sup', 'mceButtonSelected');
1145 tinyMCE.switchClassSticky(editor_id + '_hr', 'mceButtonSelected');
1149 if (getAttrib(node, 'name').indexOf('mce_') != 0)
1151 tinyMCE.switchClassSticky(editor_id + '_image', 'mceButtonSelected');
1155 } while ((node = node.parentNode));
1158 // This function auto imports CSS classes into the class selection droplist
1159 function TinyMCE_advanced_setupCSSClasses(editor_id)
1161 if (!TinyMCE_advanced_autoImportCSSClasses)
1166 var selectElm = document.getElementById(editor_id + '_styleSelect');
1168 if (selectElm && selectElm.getAttribute('cssImported') != 'true')
1170 var csses = tinyMCE.getCSSClasses(editor_id);
1171 if (csses && selectElm)
1173 for (var i=0; i<csses.length; i++)
1175 selectElm.options[selectElm.length] = new Option(csses[i], csses[i]);
1179 // Only do this once
1180 if (csses != null && csses.length > 0)
1182 selectElm.setAttribute('cssImported', 'true');