2 * $Id: editor_template_src.js 256 2007-04-24 09:03:20Z spocke $
5 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
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,
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 ['forecolorpicker', 'forecolor.gif', 'lang_theme_forecolor_desc', 'forecolorpicker', true],
47 ['backcolor', 'backcolor.gif', 'lang_theme_backcolor_desc', 'HiliteColor', true],
48 ['backcolorpicker', 'backcolor.gif', 'lang_theme_backcolor_desc', 'backcolorpicker', true],
49 ['charmap', 'charmap.gif', 'lang_theme_charmap_desc', 'mceCharMap'],
50 ['visualaid', 'visualaid.gif', 'lang_theme_visualaid_desc', 'mceToggleVisualAid'],
51 ['anchor', 'anchor.gif', 'lang_theme_anchor_desc', 'mceInsertAnchor'],
52 ['newdocument', 'newdocument.gif', 'lang_newdocument_desc', 'mceNewDocument']
55 _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',
58 * Returns HTML code for the specificed control.
60 getControlHTML : function(button_name) {
63 // Lookup button in button list
64 for (i=0; i<TinyMCE_AdvancedTheme._buttons.length; i++) {
65 but = TinyMCE_AdvancedTheme._buttons[i];
67 if (but[0] == button_name && (button_name == "forecolor" || button_name == "backcolor"))
68 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));
70 if (but[0] == button_name)
71 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));
74 // Custom controlls other than buttons
75 switch (button_name) {
77 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">';
78 var formats = tinyMCE.getParam("theme_advanced_blockformats", "p,address,pre,h1,h2,h3,h4,h5,h6", true).split(',');
80 ['p', '{$lang_theme_paragraph}'],
81 ['address', '{$lang_theme_address}'],
82 ['pre', '{$lang_theme_pre}'],
83 ['h1', '{$lang_theme_h1}'],
84 ['h2', '{$lang_theme_h2}'],
85 ['h3', '{$lang_theme_h3}'],
86 ['h4', '{$lang_theme_h4}'],
87 ['h5', '{$lang_theme_h5}'],
88 ['h6', '{$lang_theme_h6}'],
89 ['div', '{$lang_theme_div}'],
90 ['blockquote', '{$lang_theme_blockquote}'],
91 ['code', '{$lang_theme_code}'],
92 ['dt', '{$lang_theme_dt}'],
93 ['dd', '{$lang_theme_dd}'],
94 ['samp', '{$lang_theme_samp}']
97 html += '<option value="">{$lang_theme_block}</option>';
99 // Build format select
100 for (var i=0; i<formats.length; i++) {
101 for (var x=0; x<lookup.length; x++) {
102 if (formats[i] == lookup[x][0])
103 html += '<option value="<' + lookup[x][0] + '>">' + lookup[x][1] + '</option>';
112 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>';
115 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>';
116 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';
117 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';
118 var fonts = tinyMCE.getParam("theme_advanced_fonts", nFonts).split(';');
119 for (i=0; i<fonts.length; i++) {
120 if (fonts[i] != '') {
121 var parts = fonts[i].split('=');
122 fontHTML += '<option value="' + parts[1] + '">' + parts[0] + '</option>';
126 fontHTML += '</select>';
129 case "fontsizeselect":
130 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">'+
131 '<option value="0">{$lang_theme_font_size}</option>'+
132 '<option value="1">1 (8 pt)</option>'+
133 '<option value="2">2 (10 pt)</option>'+
134 '<option value="3">3 (12 pt)</option>'+
135 '<option value="4">4 (14 pt)</option>'+
136 '<option value="5">5 (18 pt)</option>'+
137 '<option value="6">6 (24 pt)</option>'+
138 '<option value="7">7 (36 pt)</option>'+
143 return '<img src="{$themeurl}/images/separator.gif" width="2" height="20" class="mceSeparatorLine" alt="" />';
146 return '<img src="{$themeurl}/images/separator.gif" width="2" height="15" border="0" class="mceSeparatorLine" style="vertical-align: middle" alt="" />';
156 * Theme specific execcommand handling.
158 execCommand : function(editor_id, element, command, user_interface, value) {
166 tinymce_version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion,
167 tinymce_releasedate : tinyMCE.releaseDate,
173 var inst = tinyMCE.getInstanceById(editor_id);
174 var doc = inst.getDoc();
175 var selectedText = "";
177 if (tinyMCE.isMSIE) {
178 var rng = doc.selection.createRange();
179 selectedText = rng.text;
181 selectedText = inst.getSel().toString();
183 if (!tinyMCE.linkElement) {
184 if ((tinyMCE.selectedElement.nodeName.toLowerCase() != "img") && (selectedText.length <= 0))
188 var href = "", target = "", title = "", onclick = "", action = "insert", style_class = "";
190 if (tinyMCE.selectedElement.nodeName.toLowerCase() == "a")
191 tinyMCE.linkElement = tinyMCE.selectedElement;
193 // Is anchor not a link
194 if (tinyMCE.linkElement != null && tinyMCE.getAttrib(tinyMCE.linkElement, 'href') == "")
195 tinyMCE.linkElement = null;
197 if (tinyMCE.linkElement) {
198 href = tinyMCE.getAttrib(tinyMCE.linkElement, 'href');
199 target = tinyMCE.getAttrib(tinyMCE.linkElement, 'target');
200 title = tinyMCE.getAttrib(tinyMCE.linkElement, 'title');
201 onclick = tinyMCE.getAttrib(tinyMCE.linkElement, 'onclick');
202 style_class = tinyMCE.getAttrib(tinyMCE.linkElement, 'class');
204 // Try old onclick to if copy/pasted content
206 onclick = tinyMCE.getAttrib(tinyMCE.linkElement, 'onclick');
208 onclick = tinyMCE.cleanupEventStr(onclick);
210 href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement, true);");
212 // Use mce_href if defined
213 mceRealHref = tinyMCE.getAttrib(tinyMCE.linkElement, 'mce_href');
214 if (mceRealHref != "") {
217 if (tinyMCE.getParam('convert_urls'))
218 href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement, true);");
224 var template = new Array();
226 template['file'] = 'link.htm';
227 template['width'] = 310;
228 template['height'] = 200;
230 // Language specific width and height addons
231 template['width'] += tinyMCE.getLang('lang_insert_link_delta_width', 0);
232 template['height'] += tinyMCE.getLang('lang_insert_link_delta_height', 0);
234 if (inst.settings['insertlink_callback']) {
235 var returnVal = eval(inst.settings['insertlink_callback'] + "(href, target, title, onclick, action, style_class);");
236 if (returnVal && returnVal['href'])
237 TinyMCE_AdvancedTheme._insertLink(returnVal['href'], returnVal['target'], returnVal['title'], returnVal['onclick'], returnVal['style_class']);
239 tinyMCE.openWindow(template, {href : href, target : target, title : title, onclick : onclick, action : action, className : style_class, inline : "yes"});
245 var src = "", alt = "", border = "", hspace = "", vspace = "", width = "", height = "", align = "";
246 var title = "", onmouseover = "", onmouseout = "", action = "insert";
247 var img = tinyMCE.imgElement;
248 var inst = tinyMCE.getInstanceById(editor_id);
250 if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") {
251 img = tinyMCE.selectedElement;
252 tinyMCE.imgElement = img;
256 // Is it a internal MCE visual aid image, then skip this one.
257 if (tinyMCE.getAttrib(img, 'name').indexOf('mce_') == 0)
260 src = tinyMCE.getAttrib(img, 'src');
261 alt = tinyMCE.getAttrib(img, 'alt');
263 // Try polling out the title
265 alt = tinyMCE.getAttrib(img, 'title');
267 // Fix width/height attributes if the styles is specified
268 if (tinyMCE.isGecko) {
269 var w = img.style.width;
270 if (w != null && w != "")
271 img.setAttribute("width", w);
273 var h = img.style.height;
274 if (h != null && h != "")
275 img.setAttribute("height", h);
278 border = tinyMCE.getAttrib(img, 'border');
279 hspace = tinyMCE.getAttrib(img, 'hspace');
280 vspace = tinyMCE.getAttrib(img, 'vspace');
281 width = tinyMCE.getAttrib(img, 'width');
282 height = tinyMCE.getAttrib(img, 'height');
283 align = tinyMCE.getAttrib(img, 'align');
284 onmouseover = tinyMCE.getAttrib(img, 'onmouseover');
285 onmouseout = tinyMCE.getAttrib(img, 'onmouseout');
286 title = tinyMCE.getAttrib(img, 'title');
288 // Is realy specified?
289 if (tinyMCE.isMSIE) {
290 width = img.attributes['width'].specified ? width : "";
291 height = img.attributes['height'].specified ? height : "";
294 //onmouseover = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseover));
295 //onmouseout = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseout));
297 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");
299 // Use mce_src if defined
300 mceRealSrc = tinyMCE.getAttrib(img, 'mce_src');
301 if (mceRealSrc != "") {
304 if (tinyMCE.getParam('convert_urls'))
305 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");
308 //if (onmouseover != "")
309 // onmouseover = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseover, img, true);");
311 //if (onmouseout != "")
312 // onmouseout = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseout, img, true);");
317 var template = new Array();
319 template['file'] = 'image.htm?src={$src}';
320 template['width'] = 355;
321 template['height'] = 265 + (tinyMCE.isMSIE ? 25 : 0);
323 // Language specific width and height addons
324 template['width'] += tinyMCE.getLang('lang_insert_image_delta_width', 0);
325 template['height'] += tinyMCE.getLang('lang_insert_image_delta_height', 0);
327 if (inst.settings['insertimage_callback']) {
328 var returnVal = eval(inst.settings['insertimage_callback'] + "(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout, action);");
329 if (returnVal && returnVal['src'])
330 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']);
332 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"});
337 var fcp = new TinyMCE_Layer(editor_id + '_fcPreview', false), p, img, elm;
339 TinyMCE_AdvancedTheme._hideMenus(editor_id);
342 fcp.create('div', 'mceColorPreview', document.getElementById(editor_id + '_toolbar'));
343 elm = fcp.getElement();
344 elm._editor_id = editor_id;
345 elm._command = "forecolor";
346 elm._switchId = editor_id + "_forecolor";
347 tinyMCE.addEvent(elm, 'click', TinyMCE_AdvancedTheme._handleMenuEvent);
348 tinyMCE.addEvent(elm, 'mouseover', TinyMCE_AdvancedTheme._handleMenuEvent);
349 tinyMCE.addEvent(elm, 'mouseout', TinyMCE_AdvancedTheme._handleMenuEvent);
352 img = tinyMCE.selectNodes(document.getElementById(editor_id + "_forecolor"), function(n) {return n.nodeName == "IMG";})[0];
353 p = tinyMCE.getAbsPosition(img, document.getElementById(editor_id + '_toolbar'));
355 fcp.moveTo(p.absLeft, p.absTop);
356 fcp.getElement().style.backgroundColor = value != null ? value : tinyMCE.getInstanceById(editor_id).foreColor;
361 case "forecolorpicker":
362 this._pickColor(editor_id, 'forecolor');
365 case "forecolorMenu":
366 TinyMCE_AdvancedTheme._hideMenus(editor_id);
368 // Create color layer
369 var ml = new TinyMCE_Layer(editor_id + '_fcMenu');
372 ml.create('div', 'mceMenu', document.body, TinyMCE_AdvancedTheme._getColorHTML(editor_id, 'theme_advanced_text_colors', 'forecolor'));
374 tinyMCE.switchClass(editor_id + '_forecolor', 'mceMenuButtonFocus');
375 ml.moveRelativeTo(document.getElementById(editor_id + "_forecolor"), 'bl');
377 ml.moveBy(tinyMCE.isMSIE && !tinyMCE.isOpera ? -1 : 1, -1);
386 var bcp = new TinyMCE_Layer(editor_id + '_bcPreview', false), p, img;
388 TinyMCE_AdvancedTheme._hideMenus(editor_id);
391 bcp.create('div', 'mceColorPreview', document.getElementById(editor_id + '_toolbar'));
392 elm = bcp.getElement();
393 elm._editor_id = editor_id;
394 elm._command = "HiliteColor";
395 elm._switchId = editor_id + "_backcolor";
396 tinyMCE.addEvent(elm, 'click', TinyMCE_AdvancedTheme._handleMenuEvent);
397 tinyMCE.addEvent(elm, 'mouseover', TinyMCE_AdvancedTheme._handleMenuEvent);
398 tinyMCE.addEvent(elm, 'mouseout', TinyMCE_AdvancedTheme._handleMenuEvent);
401 img = tinyMCE.selectNodes(document.getElementById(editor_id + "_backcolor"), function(n) {return n.nodeName == "IMG";})[0];
402 p = tinyMCE.getAbsPosition(img, document.getElementById(editor_id + '_toolbar'));
404 bcp.moveTo(p.absLeft, p.absTop);
405 bcp.getElement().style.backgroundColor = value != null ? value : tinyMCE.getInstanceById(editor_id).backColor;
410 case "HiliteColorMenu":
411 TinyMCE_AdvancedTheme._hideMenus(editor_id);
413 // Create color layer
414 var ml = new TinyMCE_Layer(editor_id + '_bcMenu');
417 ml.create('div', 'mceMenu', document.body, TinyMCE_AdvancedTheme._getColorHTML(editor_id, 'theme_advanced_background_colors', 'HiliteColor'));
419 tinyMCE.switchClass(editor_id + '_backcolor', 'mceMenuButtonFocus');
420 ml.moveRelativeTo(document.getElementById(editor_id + "_backcolor"), 'bl');
422 ml.moveBy(tinyMCE.isMSIE && !tinyMCE.isOpera ? -1 : 1, -1);
430 case "backcolorpicker":
431 this._pickColor(editor_id, 'HiliteColor');
434 case "mceColorPicker":
435 if (user_interface) {
438 if (!value['callback'] && !value['color'])
439 value['color'] = value['document'].getElementById(value['element_id']).value;
441 template['file'] = 'color_picker.htm';
442 template['width'] = 380;
443 template['height'] = 250;
444 template['close_previous'] = "no";
446 template['width'] += tinyMCE.getLang('lang_theme_advanced_colorpicker_delta_width', 0);
447 template['height'] += tinyMCE.getLang('lang_theme_advanced_colorpicker_delta_height', 0);
449 if (typeof(value['store_selection']) == "undefined")
450 value['store_selection'] = true;
452 tinyMCE.lastColorPickerValue = value;
453 tinyMCE.openWindow(template, {editor_id : editor_id, mce_store_selection : value['store_selection'], inline : "yes", command : "mceColorPicker", input_color : value['color']});
455 var savedVal = tinyMCE.lastColorPickerValue, elm;
457 if (savedVal['callback']) {
458 savedVal['callback'](value);
462 elm = savedVal['document'].getElementById(savedVal['element_id']);
465 if (elm.onchange != null && elm.onchange != '')
466 eval('elm.onchange();');
470 case "mceCodeEditor":
471 var template = new Array();
473 template['file'] = 'source_editor.htm';
474 template['width'] = parseInt(tinyMCE.getParam("theme_advanced_source_editor_width", 720));
475 template['height'] = parseInt(tinyMCE.getParam("theme_advanced_source_editor_height", 580));
477 tinyMCE.openWindow(template, {editor_id : editor_id, resizable : "yes", scrollbars : "no", inline : "yes"});
481 var template = new Array();
483 template['file'] = 'charmap.htm';
484 template['width'] = 550 + (tinyMCE.isOpera ? 40 : 0);
485 template['height'] = 250;
487 template['width'] += tinyMCE.getLang('lang_theme_advanced_charmap_delta_width', 0);
488 template['height'] += tinyMCE.getLang('lang_theme_advanced_charmap_delta_height', 0);
490 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
493 case "mceInsertAnchor":
494 var template = new Array();
496 template['file'] = 'anchor.htm';
497 template['width'] = 320;
498 template['height'] = 90 + (tinyMCE.isNS7 ? 30 : 0);
500 template['width'] += tinyMCE.getLang('lang_theme_advanced_anchor_delta_width', 0);
501 template['height'] += tinyMCE.getLang('lang_theme_advanced_anchor_delta_height', 0);
503 tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
506 case "mceNewDocument":
507 if (confirm(tinyMCE.getLang('lang_newdocument')))
508 tinyMCE.execInstanceCommand(editor_id, 'mceSetContent', false, ' ');
517 * Editor instance template function.
519 getEditorTemplate : function(settings, editorId) {
520 function removeFromArray(in_array, remove_array) {
521 var outArray = new Array(), skip;
523 for (var i=0; i<in_array.length; i++) {
526 for (var j=0; j<remove_array.length; j++) {
527 if (in_array[i] == remove_array[j]) {
533 outArray[outArray.length] = in_array[i];
540 function addToArray(in_array, add_array) {
541 for (var i=0; i<add_array.length; i++) {
542 in_array[in_array.length] = add_array[i];
548 var template = new Array();
550 var resizing = tinyMCE.getParam("theme_advanced_resizing", false);
551 var path = tinyMCE.getParam("theme_advanced_path", true);
552 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.themes.advanced._setResizing(event,\'{$editor_id}\',true);"></div><br style="clear: both" />';
553 var layoutManager = tinyMCE.getParam("theme_advanced_layout_manager", "SimpleLayout");
555 // Setup style select options -- MOVED UP FOR EXTERNAL TOOLBAR COMPATABILITY!
556 var styleSelectHTML = '<option value="">{$lang_theme_style_select}</option>';
557 if (settings['theme_advanced_styles']) {
558 var stylesAr = settings['theme_advanced_styles'].split(';');
560 for (var i=0; i<stylesAr.length; i++) {
563 key = stylesAr[i].split('=')[0];
564 value = stylesAr[i].split('=')[1];
566 styleSelectHTML += '<option value="' + value + '">' + key + '</option>';
569 TinyMCE_AdvancedTheme._autoImportCSSClasses = false;
572 switch(layoutManager) {
573 case "SimpleLayout" : //the default TinyMCE Layout (for backwards compatibility)...
574 var toolbarHTML = "";
575 var toolbarLocation = tinyMCE.getParam("theme_advanced_toolbar_location", "bottom");
576 var toolbarAlign = tinyMCE.getParam("theme_advanced_toolbar_align", "center");
577 var pathLocation = tinyMCE.getParam("theme_advanced_path_location", "none"); // Compatiblity
578 var statusbarLocation = tinyMCE.getParam("theme_advanced_statusbar_location", pathLocation);
580 theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,styleselect,formatselect",
581 theme_advanced_buttons2 : "bullist,numlist,separator,outdent,indent,separator,undo,redo,separator,link,unlink,anchor,image,cleanup,help,code",
582 theme_advanced_buttons3 : "hr,removeformat,visualaid,separator,sub,sup,separator,charmap"
585 // Add accessibility control
586 toolbarHTML += '<a href="#" accesskey="q" title="' + tinyMCE.getLang("lang_toolbar_focus") + '"';
588 if (!tinyMCE.getParam("accessibility_focus"))
589 toolbarHTML += ' onfocus="tinyMCE.getInstanceById(\'' + editorId + '\').getWin().focus();"';
591 toolbarHTML += '></a>';
594 for (var i=1; i<100; i++) {
595 var def = defVals["theme_advanced_buttons" + i];
597 var buttons = tinyMCE.getParam("theme_advanced_buttons" + i, def == null ? '' : def, true, ',');
598 if (buttons.length == 0)
601 buttons = removeFromArray(buttons, tinyMCE.getParam("theme_advanced_disable", "", true, ','));
602 buttons = addToArray(buttons, tinyMCE.getParam("theme_advanced_buttons" + i + "_add", "", true, ','));
603 buttons = addToArray(tinyMCE.getParam("theme_advanced_buttons" + i + "_add_before", "", true, ','), buttons);
605 for (var b=0; b<buttons.length; b++)
606 toolbarHTML += tinyMCE.getControlHTML(buttons[b]);
608 if (buttons.length > 0) {
609 toolbarHTML += "<br />";
614 // Add accessibility control
615 toolbarHTML += '<a href="#" accesskey="z" onfocus="tinyMCE.getInstanceById(\'' + editorId + '\').getWin().focus();"></a>';
617 // Setup template html
618 template['html'] = '<table class="mceEditor" border="0" cellpadding="0" cellspacing="0" width="{$width}" height="{$height}" style="width:{$width_style};height:{$height_style}"><tbody>';
620 if (toolbarLocation == "top")
621 template['html'] += '<tr><td dir="ltr" class="mceToolbarTop" align="' + toolbarAlign + '" height="1" nowrap="nowrap"><span id="' + editorId + '_toolbar" class="mceToolbarContainer">' + toolbarHTML + '</span></td></tr>';
623 if (statusbarLocation == "top") {
624 template['html'] += '<tr><td class="mceStatusbarTop" height="1">' + statusbarHTML + '</td></tr>';
628 template['html'] += '<tr><td align="center"><span id="{$editor_id}"></span></td></tr>';
630 if (toolbarLocation == "bottom")
631 template['html'] += '<tr><td dir="ltr" class="mceToolbarBottom" align="' + toolbarAlign + '" height="1"><span id="' + editorId + '_toolbar" class="mceToolbarContainer">' + toolbarHTML + '</span></td></tr>';
633 // External toolbar changes
634 if (toolbarLocation == "external") {
635 var bod = document.body;
636 var elm = document.createElement ("div");
638 toolbarHTML = tinyMCE.replaceVar(toolbarHTML, 'style_select_options', styleSelectHTML);
639 toolbarHTML = tinyMCE.applyTemplate(toolbarHTML, {editor_id : editorId});
641 elm.className = "mceToolbarExternal";
642 elm.id = editorId+"_toolbar";
643 elm.innerHTML = '<table width="100%" border="0" align="center"><tr><td align="center">'+toolbarHTML+'</td></tr></table>';
644 bod.appendChild (elm);
645 // bod.style.marginTop = elm.offsetHeight + "px";
648 tinyMCE.getInstanceById(editorId).toolbarElement = elm;
650 //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"];
652 tinyMCE.getInstanceById(editorId).toolbarElement = null;
655 if (statusbarLocation == "bottom") {
656 template['html'] += '<tr><td class="mceStatusbarBottom" height="1">' + statusbarHTML + '</td></tr>';
660 template['html'] += '</tbody></table>';
664 case "RowLayout" : //Container Layout - containers defined in "theme_advanced_containers" are rendered from top to bottom.
665 template['html'] = '<table class="mceEditor" border="0" cellpadding="0" cellspacing="0" width="{$width}" height="{$height}" style="width:{$width}px;height:{$height}px"><tbody>';
667 var containers = tinyMCE.getParam("theme_advanced_containers", "", true, ",");
668 var defaultContainerCSS = tinyMCE.getParam("theme_advanced_containers_default_class", "container");
669 var defaultContainerAlign = tinyMCE.getParam("theme_advanced_containers_default_align", "center");
672 for (var i = 0; i < containers.length; i++)
674 if (containers[i] == "mceEditor") //Exceptions for mceEditor and ...
675 template['html'] += '<tr><td align="center" class="mceEditor_border"><span id="{$editor_id}"></span></td></tr>';
676 else if (containers[i] == "mceElementpath" || containers[i] == "mceStatusbar") // ... mceElementpath:
678 var pathClass = "mceStatusbar";
680 if (i == containers.length-1)
682 pathClass = "mceStatusbarBottom";
686 pathClass = "mceStatusbar";
693 template['html'] += '<tr><td class="' + pathClass + '" height="1">' + statusbarHTML + '</td></tr>';
695 } else { // Render normal Container
696 var curContainer = tinyMCE.getParam("theme_advanced_container_"+containers[i], "", true, ',');
697 var curContainerHTML = "";
698 var curAlign = tinyMCE.getParam("theme_advanced_container_"+containers[i]+"_align", defaultContainerAlign);
699 var curCSS = tinyMCE.getParam("theme_advanced_container_"+containers[i]+"_class", defaultContainerCSS);
701 curContainer = removeFromArray(curContainer, tinyMCE.getParam("theme_advanced_disable", "", true, ','));
703 for (var j=0; j<curContainer.length; j++)
704 curContainerHTML += tinyMCE.getControlHTML(curContainer[j]);
706 if (curContainer.length > 0) {
707 curContainerHTML += "<br />";
711 template['html'] += '<tr><td class="' + curCSS + '" align="' + curAlign + '" height="1">' + curContainerHTML + '</td></tr>';
715 template['html'] += '</tbody></table>';
719 case "CustomLayout" : //User defined layout callback...
720 var customLayout = tinyMCE.getParam("theme_advanced_custom_layout","");
722 if (customLayout != "" && eval("typeof(" + customLayout + ")") != "undefined") {
723 template = eval(customLayout + "(template);");
729 template['html'] += '<span id="{$editor_id}_resize_box" class="mceResizeBox"></span>';
731 template['html'] = tinyMCE.replaceVar(template['html'], 'style_select_options', styleSelectHTML);
733 // Set to default values
734 if (!template['delta_width'])
735 template['delta_width'] = 0;
737 if (!template['delta_height'])
738 template['delta_height'] = deltaHeight;
743 initInstance : function(inst) {
744 if (tinyMCE.getParam("theme_advanced_resizing", false)) {
745 if (tinyMCE.getParam("theme_advanced_resizing_use_cookie", true)) {
746 var w = TinyMCE_AdvancedTheme._getCookie("TinyMCE_" + inst.editorId + "_width");
747 var h = TinyMCE_AdvancedTheme._getCookie("TinyMCE_" + inst.editorId + "_height");
749 TinyMCE_AdvancedTheme._resizeTo(inst, w, h, tinyMCE.getParam("theme_advanced_resize_horizontal", true));
753 inst.addShortcut('ctrl', 'k', 'lang_link_desc', 'mceLink');
756 removeInstance : function(inst) {
757 new TinyMCE_Layer(inst.editorId + '_fcMenu').remove();
758 new TinyMCE_Layer(inst.editorId + '_bcMenu').remove();
761 hideInstance : function(inst) {
762 TinyMCE_AdvancedTheme._hideMenus(inst.editorId);
765 _handleMenuEvent : function(e) {
766 var te = tinyMCE.isMSIE ? window.event.srcElement : e.target;
767 tinyMCE._menuButtonEvent(e.type == "mouseover" ? "over" : "out", document.getElementById(te._switchId));
769 if (e.type == "click")
770 tinyMCE.execInstanceCommand(te._editor_id, te._command);
773 _hideMenus : function(id) {
774 var fcml = new TinyMCE_Layer(id + '_fcMenu'), bcml = new TinyMCE_Layer(id + '_bcMenu');
776 if (fcml.exists() && fcml.isVisible()) {
777 tinyMCE.switchClass(id + '_forecolor', 'mceMenuButton');
781 if (bcml.exists() && bcml.isVisible()) {
782 tinyMCE.switchClass(id + '_backcolor', 'mceMenuButton');
788 * Node change handler.
790 handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection, setup_content) {
791 var alignNode, breakOut, classNode;
793 function selectByValue(select_elm, value, first_index) {
794 first_index = typeof(first_index) == "undefined" ? false : true;
797 for (var i=0; i<select_elm.options.length; i++) {
798 var ov = "" + select_elm.options[i].value;
800 if (first_index && ov.toLowerCase().indexOf(value.toLowerCase()) == 0) {
801 select_elm.selectedIndex = i;
806 select_elm.selectedIndex = i;
820 var pathElm = document.getElementById(editor_id + "_path");
821 var inst = tinyMCE.getInstanceById(editor_id);
822 var doc = inst.getDoc();
823 TinyMCE_AdvancedTheme._hideMenus(editor_id);
827 var parentNode = node;
828 var path = new Array();
830 while (parentNode != null) {
831 if (parentNode.nodeName.toUpperCase() == "BODY") {
835 // Only append element nodes to path
836 if (parentNode.nodeType == 1 && tinyMCE.getAttrib(parentNode, "class").indexOf('mceItemHidden') == -1) {
837 path[path.length] = parentNode;
840 parentNode = parentNode.parentNode;
845 for (var i=path.length-1; i>=0; i--) {
846 var nodeName = path[i].nodeName.toLowerCase();
849 if (nodeName.indexOf("html:") == 0)
850 nodeName = nodeName.substring(5);
852 if (nodeName == "b") {
856 if (nodeName == "i") {
860 if (nodeName == "span") {
861 var cn = tinyMCE.getAttrib(path[i], "class");
862 if (cn != "" && cn.indexOf('mceItem') == -1)
863 nodeData += "class: " + cn + " ";
865 var st = tinyMCE.getAttrib(path[i], "style");
867 st = tinyMCE.serializeStyle(tinyMCE.parseStyle(st));
868 nodeData += "style: " + tinyMCE.xmlEncode(st) + " ";
872 if (nodeName == "font") {
873 if (tinyMCE.getParam("convert_fonts_to_spans"))
876 var face = tinyMCE.getAttrib(path[i], "face");
878 nodeData += "font: " + tinyMCE.xmlEncode(face) + " ";
880 var size = tinyMCE.getAttrib(path[i], "size");
882 nodeData += "size: " + tinyMCE.xmlEncode(size) + " ";
884 var color = tinyMCE.getAttrib(path[i], "color");
886 nodeData += "color: " + tinyMCE.xmlEncode(color) + " ";
889 if (tinyMCE.getAttrib(path[i], 'id') != "") {
890 nodeData += "id: " + path[i].getAttribute('id') + " ";
893 var className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(path[i], "class"), false);
894 if (className != "" && className.indexOf('mceItem') == -1)
895 nodeData += "class: " + className + " ";
897 if (tinyMCE.getAttrib(path[i], 'src') != "") {
898 var src = tinyMCE.getAttrib(path[i], "mce_src");
901 src = tinyMCE.getAttrib(path[i], "src");
903 nodeData += "src: " + tinyMCE.xmlEncode(src) + " ";
906 if (path[i].nodeName == 'A' && tinyMCE.getAttrib(path[i], 'href') != "") {
907 var href = tinyMCE.getAttrib(path[i], "mce_href");
910 href = tinyMCE.getAttrib(path[i], "href");
912 nodeData += "href: " + tinyMCE.xmlEncode(href) + " ";
915 className = tinyMCE.getAttrib(path[i], "class");
916 if ((nodeName == "img" || nodeName == "span") && className.indexOf('mceItem') != -1) {
917 nodeName = className.replace(/mceItem([a-z]+)/gi, '$1').toLowerCase();
918 nodeData = path[i].getAttribute('title');
921 if (nodeName == "a" && (anchor = tinyMCE.getAttrib(path[i], "name")) != "") {
923 nodeName += "#" + tinyMCE.xmlEncode(anchor);
927 if (tinyMCE.getAttrib(path[i], 'name').indexOf("mce_") != 0) {
928 var className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(path[i], "class"), false);
929 if (className != "" && className.indexOf('mceItem') == -1) {
930 nodeName += "." + className;
934 var cmd = 'tinyMCE.execInstanceCommand(\'' + editor_id + '\',\'mceSelectNodeDepth\',false,\'' + i + '\');';
935 html += '<a title="' + nodeData + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" target="_self" class="mcePathItem">' + nodeName + '</a>';
942 pathElm.innerHTML = '<a href="#" accesskey="x"></a>' + tinyMCE.getLang('lang_theme_path') + ": " + html + ' ';
946 tinyMCE.switchClass(editor_id + '_justifyleft', 'mceButtonNormal');
947 tinyMCE.switchClass(editor_id + '_justifyright', 'mceButtonNormal');
948 tinyMCE.switchClass(editor_id + '_justifycenter', 'mceButtonNormal');
949 tinyMCE.switchClass(editor_id + '_justifyfull', 'mceButtonNormal');
950 tinyMCE.switchClass(editor_id + '_bold', 'mceButtonNormal');
951 tinyMCE.switchClass(editor_id + '_italic', 'mceButtonNormal');
952 tinyMCE.switchClass(editor_id + '_underline', 'mceButtonNormal');
953 tinyMCE.switchClass(editor_id + '_strikethrough', 'mceButtonNormal');
954 tinyMCE.switchClass(editor_id + '_bullist', 'mceButtonNormal');
955 tinyMCE.switchClass(editor_id + '_numlist', 'mceButtonNormal');
956 tinyMCE.switchClass(editor_id + '_sub', 'mceButtonNormal');
957 tinyMCE.switchClass(editor_id + '_sup', 'mceButtonNormal');
958 tinyMCE.switchClass(editor_id + '_anchor', 'mceButtonNormal');
959 tinyMCE.switchClass(editor_id + '_link', 'mceButtonDisabled');
960 tinyMCE.switchClass(editor_id + '_unlink', 'mceButtonDisabled');
961 tinyMCE.switchClass(editor_id + '_outdent', 'mceButtonDisabled');
962 tinyMCE.switchClass(editor_id + '_image', 'mceButtonNormal');
963 tinyMCE.switchClass(editor_id + '_hr', 'mceButtonNormal');
965 if (node.nodeName == "A" && tinyMCE.getAttrib(node, "class").indexOf('mceItemAnchor') != -1)
966 tinyMCE.switchClass(editor_id + '_anchor', 'mceButtonSelected');
969 var anchorLink = tinyMCE.getParentElement(node, "a", "href");
971 if (anchorLink || any_selection) {
972 tinyMCE.switchClass(editor_id + '_link', anchorLink ? 'mceButtonSelected' : 'mceButtonNormal');
973 tinyMCE.switchClass(editor_id + '_unlink', anchorLink ? 'mceButtonSelected' : 'mceButtonNormal');
977 tinyMCE.switchClass(editor_id + '_visualaid', visual_aid ? 'mceButtonSelected' : 'mceButtonNormal');
979 if (undo_levels != -1) {
980 tinyMCE.switchClass(editor_id + '_undo', 'mceButtonDisabled');
981 tinyMCE.switchClass(editor_id + '_redo', 'mceButtonDisabled');
984 // Within li, blockquote
985 if (tinyMCE.getParentElement(node, "li,blockquote"))
986 tinyMCE.switchClass(editor_id + '_outdent', 'mceButtonNormal');
989 if (undo_index != -1 && (undo_index < undo_levels-1 && undo_levels > 0))
990 tinyMCE.switchClass(editor_id + '_redo', 'mceButtonNormal');
993 if (undo_index != -1 && (undo_index > 0 && undo_levels > 0))
994 tinyMCE.switchClass(editor_id + '_undo', 'mceButtonNormal');
996 // Select class in select box
997 var selectElm = document.getElementById(editor_id + "_styleSelect");
1000 TinyMCE_AdvancedTheme._setupCSSClasses(editor_id);
1007 if (classNode && classNode.className) {
1008 for (var i=0; i<selectElm.options.length; i++) {
1009 if (selectElm.options[i].value == classNode.className) {
1016 } while (!breakOut && classNode != null && (classNode = classNode.parentNode) != null);
1018 selectElm.selectedIndex = index;
1021 // Select formatblock
1022 var selectElm = document.getElementById(editor_id + "_formatSelect");
1024 var elm = tinyMCE.getParentElement(node, "p,div,h1,h2,h3,h4,h5,h6,pre,address");
1027 selectByValue(selectElm, "<" + elm.nodeName.toLowerCase() + ">");
1029 selectByValue(selectElm, "");
1032 // Select fontselect
1033 var selectElm = document.getElementById(editor_id + "_fontNameSelect");
1035 if (!tinyMCE.isSafari && !(tinyMCE.isMSIE && !tinyMCE.isOpera)) {
1036 var face = inst.queryCommandValue('FontName');
1038 face = face == null || face == "" ? "" : face;
1040 selectByValue(selectElm, face, face != "");
1042 var elm = tinyMCE.getParentElement(node, "font", "face");
1045 var family = tinyMCE.getAttrib(elm, "face");
1048 family = '' + elm.style.fontFamily;
1050 if (!selectByValue(selectElm, family, family != ""))
1051 selectByValue(selectElm, "");
1053 selectByValue(selectElm, "");
1058 var selectElm = document.getElementById(editor_id + "_fontSizeSelect");
1060 if (!tinyMCE.isSafari && !tinyMCE.isOpera) {
1061 var size = inst.queryCommandValue('FontSize');
1062 selectByValue(selectElm, size == null || size == "" ? "0" : size);
1064 var elm = tinyMCE.getParentElement(node, "font", "size");
1066 var size = tinyMCE.getAttrib(elm, "size");
1069 var sizes = new Array('', '8px', '10px', '12px', '14px', '18px', '24px', '36px');
1071 size = '' + elm.style.fontSize;
1073 for (var i=0; i<sizes.length; i++) {
1074 if (('' + sizes[i]) == size) {
1081 if (!selectByValue(selectElm, size))
1082 selectByValue(selectElm, "");
1084 selectByValue(selectElm, "0");
1088 // Handle align attributes
1092 if (!alignNode.getAttribute || !alignNode.getAttribute('align'))
1095 switch (alignNode.getAttribute('align').toLowerCase()) {
1097 tinyMCE.switchClass(editor_id + '_justifyleft', 'mceButtonSelected');
1102 tinyMCE.switchClass(editor_id + '_justifyright', 'mceButtonSelected');
1108 tinyMCE.switchClass(editor_id + '_justifycenter', 'mceButtonSelected');
1113 tinyMCE.switchClass(editor_id + '_justifyfull', 'mceButtonSelected');
1117 } while (!breakOut && (alignNode = alignNode.parentNode) != null);
1119 // Div justification
1120 var div = tinyMCE.getParentElement(node, "div");
1121 if (div && div.style.textAlign == "center")
1122 tinyMCE.switchClass(editor_id + '_justifycenter', 'mceButtonSelected');
1125 if (!setup_content) {
1126 // , "JustifyLeft", "_justifyleft", "JustifyCenter", "justifycenter", "JustifyRight", "justifyright", "JustifyFull", "justifyfull", "InsertUnorderedList", "bullist", "InsertOrderedList", "numlist", "InsertUnorderedList", "bullist", "Outdent", "outdent", "Indent", "indent", "subscript", "sub"
1127 var ar = new Array("Bold", "_bold", "Italic", "_italic", "Strikethrough", "_strikethrough", "superscript", "_sup", "subscript", "_sub");
1128 for (var i=0; i<ar.length; i+=2) {
1129 if (inst.queryCommandState(ar[i]))
1130 tinyMCE.switchClass(editor_id + ar[i+1], 'mceButtonSelected');
1133 if (inst.queryCommandState("Underline") && (node.parentNode == null || node.parentNode.nodeName != "A"))
1134 tinyMCE.switchClass(editor_id + '_underline', 'mceButtonSelected');
1139 switch (node.nodeName) {
1141 tinyMCE.switchClass(editor_id + '_bullist', 'mceButtonSelected');
1145 tinyMCE.switchClass(editor_id + '_numlist', 'mceButtonSelected');
1149 tinyMCE.switchClass(editor_id + '_hr', 'mceButtonSelected');
1153 if (tinyMCE.getAttrib(node, 'name').indexOf('mce_') != 0 && tinyMCE.getAttrib(node, 'class').indexOf('mceItem') == -1) {
1154 tinyMCE.switchClass(editor_id + '_image', 'mceButtonSelected');
1158 } while ((node = node.parentNode) != null);
1161 // Private theme internal functions
1163 // This function auto imports CSS classes into the class selection droplist
1164 _setupCSSClasses : function(editor_id) {
1167 if (!TinyMCE_AdvancedTheme._autoImportCSSClasses)
1170 selectElm = document.getElementById(editor_id + '_styleSelect');
1172 if (selectElm && selectElm.getAttribute('cssImported') != 'true') {
1173 var csses = tinyMCE.getCSSClasses(editor_id);
1174 if (csses && selectElm) {
1175 for (i=0; i<csses.length; i++)
1176 selectElm.options[selectElm.options.length] = new Option(csses[i], csses[i]);
1179 // Only do this once
1180 if (csses != null && csses.length > 0)
1181 selectElm.setAttribute('cssImported', 'true');
1185 _setCookie : function(name, value, expires, path, domain, secure) {
1186 var curCookie = name + "=" + escape(value) +
1187 ((expires) ? "; expires=" + expires.toGMTString() : "") +
1188 ((path) ? "; path=" + escape(path) : "") +
1189 ((domain) ? "; domain=" + domain : "") +
1190 ((secure) ? "; secure" : "");
1192 document.cookie = curCookie;
1195 _getCookie : function(name) {
1196 var dc = document.cookie;
1197 var prefix = name + "=";
1198 var begin = dc.indexOf("; " + prefix);
1201 begin = dc.indexOf(prefix);
1208 var end = document.cookie.indexOf(";", begin);
1213 return unescape(dc.substring(begin + prefix.length, end));
1216 _resizeTo : function(inst, w, h, set_w) {
1217 var editorContainer = document.getElementById(inst.editorId + '_parent');
1218 var tableElm = editorContainer.firstChild;
1219 var iframe = inst.iframeElement;
1221 if (w == null || w == "null") {
1226 if (h == null || h == "null")
1232 if (tinyMCE.isGecko) {
1237 var dx = w - tableElm.clientWidth;
1238 var dy = h - tableElm.clientHeight;
1244 tableElm.style.width = w + "px";
1246 if ( !tinyMCE.isMSIE || tinyMCE.isMSIE7 || tinyMCE.isOpera ) // WordPress: do this later to avoid creeping toolbar bug in MSIE6
1247 tableElm.style.height = h + "px";
1249 iw = iframe.clientWidth + dx;
1250 ih = iframe.clientHeight + dy;
1252 iw = iw < 1 ? 30 : iw;
1253 ih = ih < 1 ? 30 : ih;
1254 /* WordPress: found that this led to a shrinking editor with every resize.
1255 (Gray background creeps in 1px at a time.)
1256 if (tinyMCE.isGecko) {
1263 iframe.style.width = iw + "px";
1265 iframe.style.height = ih + "px";
1267 // Is it to small, make it bigger again
1269 var tableBodyElm = tableElm.firstChild;
1270 var minIframeWidth = tableBodyElm.scrollWidth;
1271 if (inst.iframeElement.clientWidth < minIframeWidth) {
1272 dx = minIframeWidth - inst.iframeElement.clientWidth;
1274 inst.iframeElement.style.width = (iw + dx) + "px";
1278 tableElm.style.height = h + "px"; // WordPress: see above
1280 // Remove pesky table controls
1281 inst.useCSS = false;
1285 * Handles resizing events.
1287 _resizeEventHandler : function(e) {
1288 var resizer = TinyMCE_AdvancedTheme._resizer;
1291 if (!resizer.resizing)
1294 e = typeof(e) == "undefined" ? window.event : e;
1296 var dx = e.screenX - resizer.downX;
1297 var dy = e.screenY - resizer.downY;
1298 var resizeBox = resizer.resizeBox;
1299 var editorId = resizer.editorId;
1305 w = resizer.width + dx;
1306 h = resizer.height + dy;
1311 if (resizer.horizontal)
1312 resizeBox.style.width = w + "px";
1314 resizeBox.style.height = h + "px";
1318 TinyMCE_AdvancedTheme._setResizing(e, editorId, false);
1319 TinyMCE_AdvancedTheme._resizeTo(tinyMCE.getInstanceById(editorId), resizer.width + dx, resizer.height + dy, resizer.horizontal);
1321 // Expire in a month
1322 if (tinyMCE.getParam("theme_advanced_resizing_use_cookie", true)) {
1323 var expires = new Date();
1324 expires.setTime(expires.getTime() + 3600000 * 24 * 30);
1327 TinyMCE_AdvancedTheme._setCookie("TinyMCE_" + editorId + "_width", "" + (resizer.horizontal ? resizer.width + dx : ""), expires);
1328 TinyMCE_AdvancedTheme._setCookie("TinyMCE_" + editorId + "_height", "" + (resizer.height + dy), expires);
1335 * Starts/stops the editor resizing.
1337 _setResizing : function(e, editor_id, state) {
1338 e = typeof(e) == "undefined" ? window.event : e;
1340 var resizer = TinyMCE_AdvancedTheme._resizer;
1341 var editorContainer = document.getElementById(editor_id + '_parent');
1342 var editorArea = document.getElementById(editor_id + '_parent').firstChild;
1343 var resizeBox = document.getElementById(editor_id + '_resize_box');
1344 var inst = tinyMCE.getInstanceById(editor_id);
1347 // Place box over editor area
1348 var width = editorArea.clientWidth;
1349 var height = editorArea.clientHeight;
1351 resizeBox.style.width = width + "px";
1352 resizeBox.style.height = height + "px";
1354 resizer.iframeWidth = inst.iframeElement.clientWidth;
1355 resizer.iframeHeight = inst.iframeElement.clientHeight;
1357 // Hide editor and show resize box
1358 editorArea.style.display = "none";
1359 resizeBox.style.display = "block";
1361 // Add event handlers, only once
1362 if (!resizer.eventHandlers) {
1364 tinyMCE.addEvent(document, "mousemove", TinyMCE_AdvancedTheme._resizeEventHandler);
1366 tinyMCE.addEvent(window, "mousemove", TinyMCE_AdvancedTheme._resizeEventHandler);
1368 tinyMCE.addEvent(document, "mouseup", TinyMCE_AdvancedTheme._resizeEventHandler);
1370 resizer.eventHandlers = true;
1373 resizer.resizing = true;
1374 resizer.downX = e.screenX;
1375 resizer.downY = e.screenY;
1376 resizer.width = parseInt(resizeBox.style.width);
1377 resizer.height = parseInt(resizeBox.style.height);
1378 resizer.editorId = editor_id;
1379 resizer.resizeBox = resizeBox;
1380 resizer.horizontal = tinyMCE.getParam("theme_advanced_resize_horizontal", true);
1382 resizer.resizing = false;
1383 resizeBox.style.display = "none";
1384 editorArea.style.display = tinyMCE.isMSIE && !tinyMCE.isOpera ? "block" : "table";
1385 tinyMCE.execCommand('mceResetDesignMode');
1389 _getColorHTML : function(id, n, cm) {
1392 h = '<span class="mceMenuLine"></span>';
1393 cl = tinyMCE.getParam(n, TinyMCE_AdvancedTheme._defColors).split(',');
1395 h += '<table class="mceColors"><tr>';
1396 for (i=0; i<cl.length; i++) {
1397 c = 'tinyMCE.execInstanceCommand(\'' + id + '\', \'' + cm + '\', false, \'#' + cl[i] + '\');';
1398 h += '<td><a href="javascript:' + c + '" style="background-color: #' + cl[i] + '" onclick="' + c + ';return false;"></a></td>';
1404 h += '</tr></table>';
1406 if (tinyMCE.getParam("theme_advanced_more_colors", true))
1407 h += '<a href="javascript:void(0);" onclick="TinyMCE_AdvancedTheme._pickColor(\'' + id + '\',\'' + cm + '\');" class="mceMoreColors">' + tinyMCE.getLang('lang_more_colors') + '</a>';
1412 _pickColor : function(id, cm) {
1413 var inputColor, inst = tinyMCE.selectedInstance;
1415 if (cm == 'forecolor' && inst)
1416 inputColor = inst.foreColor;
1418 if ((cm == 'backcolor' || cm == 'HiliteColor') && inst)
1419 inputColor = inst.backColor;
1421 tinyMCE.execCommand('mceColorPicker', true, {color : inputColor, callback : function(c) {
1422 tinyMCE.execInstanceCommand(id, cm, false, c);
1426 _insertImage : function(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout) {
1427 tinyMCE.execCommand("mceInsertContent", false, tinyMCE.createTagHTML('img', {
1428 src : tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src), // Force absolute
1438 onmouseover : onmouseover,
1439 onmouseout : onmouseout
1443 _insertLink : function(href, target, title, onclick, style_class) {
1444 tinyMCE.execCommand('mceBeginUndoLevel');
1446 if (tinyMCE.selectedInstance && tinyMCE.selectedElement && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") {
1447 var doc = tinyMCE.selectedInstance.getDoc();
1448 var linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");
1449 var newLink = false;
1452 linkElement = doc.createElement("a");
1457 var thref = eval(tinyMCE.settings['urlconverter_callback'] + "(href, linkElement);");
1458 mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
1460 tinyMCE.setAttrib(linkElement, 'href', thref);
1461 tinyMCE.setAttrib(linkElement, 'mce_href', mhref);
1462 tinyMCE.setAttrib(linkElement, 'target', target);
1463 tinyMCE.setAttrib(linkElement, 'title', title);
1464 tinyMCE.setAttrib(linkElement, 'onclick', onclick);
1465 tinyMCE.setAttrib(linkElement, 'class', style_class);
1468 linkElement.appendChild(tinyMCE.selectedElement.cloneNode(true));
1469 tinyMCE.selectedElement.parentNode.replaceChild(linkElement, tinyMCE.selectedElement);
1475 if (!tinyMCE.linkElement && tinyMCE.selectedInstance) {
1476 if (tinyMCE.isSafari) {
1477 tinyMCE.execCommand("mceInsertContent", false, '<a href="' + tinyMCE.uniqueURL + '">' + tinyMCE.selectedInstance.selection.getSelectedHTML() + '</a>');
1479 tinyMCE.selectedInstance.contentDocument.execCommand("createlink", false, tinyMCE.uniqueURL);
1481 tinyMCE.linkElement = tinyMCE.getElementByAttributeValue(tinyMCE.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);
1483 var elementArray = tinyMCE.getElementsByAttributeValue(tinyMCE.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);
1485 for (var i=0; i<elementArray.length; i++) {
1487 var thref = eval(tinyMCE.settings['urlconverter_callback'] + "(href, elementArray[i]);");
1488 mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
1490 tinyMCE.setAttrib(elementArray[i], 'href', thref);
1491 tinyMCE.setAttrib(elementArray[i], 'mce_href', mhref);
1492 tinyMCE.setAttrib(elementArray[i], 'target', target);
1493 tinyMCE.setAttrib(elementArray[i], 'title', title);
1494 tinyMCE.setAttrib(elementArray[i], 'onclick', onclick);
1495 tinyMCE.setAttrib(elementArray[i], 'class', style_class);
1498 tinyMCE.linkElement = elementArray[0];
1501 if (tinyMCE.linkElement) {
1503 href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement);");
1504 mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
1506 tinyMCE.setAttrib(tinyMCE.linkElement, 'href', href);
1507 tinyMCE.setAttrib(tinyMCE.linkElement, 'mce_href', mhref);
1508 tinyMCE.setAttrib(tinyMCE.linkElement, 'target', target);
1509 tinyMCE.setAttrib(tinyMCE.linkElement, 'title', title);
1510 tinyMCE.setAttrib(tinyMCE.linkElement, 'onclick', onclick);
1511 tinyMCE.setAttrib(tinyMCE.linkElement, 'class', style_class);
1514 tinyMCE.execCommand('mceEndUndoLevel');
1518 tinyMCE.addTheme("advanced", TinyMCE_AdvancedTheme);
1520 // Add default buttons maps for advanced theme and all internal plugins
1521 tinyMCE.addButtonMap(TinyMCE_AdvancedTheme._buttonMap);