* upgraded new version of tiny_mce
[citadel.git] / webcit / tiny_mce / themes / advanced / editor_template_src.js
blobb3cef0199bd93e9357f6e2edab30d923c8f4dde9
1 /**\r
2  * $Id: editor_template_src.js 960 2008-11-12 18:30:32Z spocke $\r
3  *\r
4  * @author Moxiecode\r
5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.\r
6  */\r
7 \r
8 (function() {\r
9         var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, each = tinymce.each, Cookie = tinymce.util.Cookie, lastExtID, explode = tinymce.explode;\r
11         // Tell it to load theme specific language pack(s)\r
12         tinymce.ThemeManager.requireLangPack('advanced');\r
14         tinymce.create('tinymce.themes.AdvancedTheme', {\r
15                 sizes : [8, 10, 12, 14, 18, 24, 36],\r
17                 // Control name lookup, format: title, command\r
18                 controls : {\r
19                         bold : ['bold_desc', 'Bold'],\r
20                         italic : ['italic_desc', 'Italic'],\r
21                         underline : ['underline_desc', 'Underline'],\r
22                         strikethrough : ['striketrough_desc', 'Strikethrough'],\r
23                         justifyleft : ['justifyleft_desc', 'JustifyLeft'],\r
24                         justifycenter : ['justifycenter_desc', 'JustifyCenter'],\r
25                         justifyright : ['justifyright_desc', 'JustifyRight'],\r
26                         justifyfull : ['justifyfull_desc', 'JustifyFull'],\r
27                         bullist : ['bullist_desc', 'InsertUnorderedList'],\r
28                         numlist : ['numlist_desc', 'InsertOrderedList'],\r
29                         outdent : ['outdent_desc', 'Outdent'],\r
30                         indent : ['indent_desc', 'Indent'],\r
31                         cut : ['cut_desc', 'Cut'],\r
32                         copy : ['copy_desc', 'Copy'],\r
33                         paste : ['paste_desc', 'Paste'],\r
34                         undo : ['undo_desc', 'Undo'],\r
35                         redo : ['redo_desc', 'Redo'],\r
36                         link : ['link_desc', 'mceLink'],\r
37                         unlink : ['unlink_desc', 'unlink'],\r
38                         image : ['image_desc', 'mceImage'],\r
39                         cleanup : ['cleanup_desc', 'mceCleanup'],\r
40                         help : ['help_desc', 'mceHelp'],\r
41                         code : ['code_desc', 'mceCodeEditor'],\r
42                         hr : ['hr_desc', 'InsertHorizontalRule'],\r
43                         removeformat : ['removeformat_desc', 'RemoveFormat'],\r
44                         sub : ['sub_desc', 'subscript'],\r
45                         sup : ['sup_desc', 'superscript'],\r
46                         forecolor : ['forecolor_desc', 'ForeColor'],\r
47                         forecolorpicker : ['forecolor_desc', 'mceForeColor'],\r
48                         backcolor : ['backcolor_desc', 'HiliteColor'],\r
49                         backcolorpicker : ['backcolor_desc', 'mceBackColor'],\r
50                         charmap : ['charmap_desc', 'mceCharMap'],\r
51                         visualaid : ['visualaid_desc', 'mceToggleVisualAid'],\r
52                         anchor : ['anchor_desc', 'mceInsertAnchor'],\r
53                         newdocument : ['newdocument_desc', 'mceNewDocument'],\r
54                         blockquote : ['blockquote_desc', 'mceBlockQuote']\r
55                 },\r
57                 stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],\r
59                 init : function(ed, url) {\r
60                         var t = this, s, v, o;\r
61         \r
62                         t.editor = ed;\r
63                         t.url = url;\r
64                         t.onResolveName = new tinymce.util.Dispatcher(this);\r
66                         // Default settings\r
67                         t.settings = s = extend({\r
68                                 theme_advanced_path : true,\r
69                                 theme_advanced_toolbar_location : 'bottom',\r
70                                 theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",\r
71                                 theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",\r
72                                 theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap",\r
73                                 theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",\r
74                                 theme_advanced_toolbar_align : "center",\r
75                                 theme_advanced_fonts : "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,sans-serif;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",\r
76                                 theme_advanced_more_colors : 1,\r
77                                 theme_advanced_row_height : 23,\r
78                                 theme_advanced_resize_horizontal : 1,\r
79                                 theme_advanced_resizing_use_cookie : 1,\r
80                                 theme_advanced_font_sizes : "1,2,3,4,5,6,7",\r
81                                 readonly : ed.settings.readonly\r
82                         }, ed.settings);\r
84                         // Setup default font_size_style_values\r
85                         if (!s.font_size_style_values)\r
86                                 s.font_size_style_values = "8pt,10pt,12pt,14pt,18pt,24pt,36pt";\r
88                         if (tinymce.is(s.theme_advanced_font_sizes, 'string')) {\r
89                                 s.font_size_style_values = tinymce.explode(s.font_size_style_values);\r
90                                 s.font_size_classes = tinymce.explode(s.font_size_classes || '');\r
92                                 // Parse string value\r
93                                 o = {};\r
94                                 ed.settings.theme_advanced_font_sizes = s.theme_advanced_font_sizes;\r
95                                 each(ed.getParam('theme_advanced_font_sizes', '', 'hash'), function(v, k) {\r
96                                         var cl;\r
98                                         if (k == v && v >= 1 && v <= 7) {\r
99                                                 k = v + ' (' + t.sizes[v - 1] + 'pt)';\r
101                                                 if (ed.settings.convert_fonts_to_spans) {\r
102                                                         cl = s.font_size_classes[v - 1];\r
103                                                         v = s.font_size_style_values[v - 1] || (t.sizes[v - 1] + 'pt');\r
104                                                 }\r
105                                         }\r
107                                         if (/\s*\./.test(v))\r
108                                                 cl = v.replace(/\./g, '');\r
110                                         o[k] = cl ? {'class' : cl} : {fontSize : v};\r
111                                 });\r
113                                 s.theme_advanced_font_sizes = o;\r
114                         }\r
116                         if ((v = s.theme_advanced_path_location) && v != 'none')\r
117                                 s.theme_advanced_statusbar_location = s.theme_advanced_path_location;\r
119                         if (s.theme_advanced_statusbar_location == 'none')\r
120                                 s.theme_advanced_statusbar_location = 0;\r
122                         // Init editor\r
123                         ed.onInit.add(function() {\r
124                                 ed.onNodeChange.add(t._nodeChanged, t);\r
126                                 if (ed.settings.content_css !== false)\r
127                                         ed.dom.loadCSS(ed.baseURI.toAbsolute("themes/advanced/skins/" + ed.settings.skin + "/content.css"));\r
128                         });\r
130                         ed.onSetProgressState.add(function(ed, b, ti) {\r
131                                 var co, id = ed.id, tb;\r
133                                 if (b) {\r
134                                         t.progressTimer = setTimeout(function() {\r
135                                                 co = ed.getContainer();\r
136                                                 co = co.insertBefore(DOM.create('DIV', {style : 'position:relative'}), co.firstChild);\r
137                                                 tb = DOM.get(ed.id + '_tbl');\r
139                                                 DOM.add(co, 'div', {id : id + '_blocker', 'class' : 'mceBlocker', style : {width : tb.clientWidth + 2, height : tb.clientHeight + 2}});\r
140                                                 DOM.add(co, 'div', {id : id + '_progress', 'class' : 'mceProgress', style : {left : tb.clientWidth / 2, top : tb.clientHeight / 2}});\r
141                                         }, ti || 0);\r
142                                 } else {\r
143                                         DOM.remove(id + '_blocker');\r
144                                         DOM.remove(id + '_progress');\r
145                                         clearTimeout(t.progressTimer);\r
146                                 }\r
147                         });\r
149                         DOM.loadCSS(s.editor_css ? ed.documentBaseURI.toAbsolute(s.editor_css) : url + "/skins/" + ed.settings.skin + "/ui.css");\r
151                         if (s.skin_variant)\r
152                                 DOM.loadCSS(url + "/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css");\r
153                 },\r
155                 createControl : function(n, cf) {\r
156                         var cd, c;\r
158                         if (c = cf.createControl(n))\r
159                                 return c;\r
161                         switch (n) {\r
162                                 case "styleselect":\r
163                                         return this._createStyleSelect();\r
165                                 case "formatselect":\r
166                                         return this._createBlockFormats();\r
168                                 case "fontselect":\r
169                                         return this._createFontSelect();\r
171                                 case "fontsizeselect":\r
172                                         return this._createFontSizeSelect();\r
174                                 case "forecolor":\r
175                                         return this._createForeColorMenu();\r
177                                 case "backcolor":\r
178                                         return this._createBackColorMenu();\r
179                         }\r
181                         if ((cd = this.controls[n]))\r
182                                 return cf.createButton(n, {title : "advanced." + cd[0], cmd : cd[1], ui : cd[2], value : cd[3]});\r
183                 },\r
185                 execCommand : function(cmd, ui, val) {\r
186                         var f = this['_' + cmd];\r
188                         if (f) {\r
189                                 f.call(this, ui, val);\r
190                                 return true;\r
191                         }\r
193                         return false;\r
194                 },\r
196                 _importClasses : function(e) {\r
197                         var ed = this.editor, c = ed.controlManager.get('styleselect');\r
199                         if (c.getLength() == 0) {\r
200                                 each(ed.dom.getClasses(), function(o) {\r
201                                         c.add(o['class'], o['class']);\r
202                                 });\r
203                         }\r
204                 },\r
206                 _createStyleSelect : function(n) {\r
207                         var t = this, ed = t.editor, cf = ed.controlManager, c = cf.createListBox('styleselect', {\r
208                                 title : 'advanced.style_select',\r
209                                 onselect : function(v) {\r
210                                         if (c.selectedValue === v) {\r
211                                                 ed.execCommand('mceSetStyleInfo', 0, {command : 'removeformat'});\r
212                                                 c.select();\r
213                                                 return false;\r
214                                         } else\r
215                                                 ed.execCommand('mceSetCSSClass', 0, v);\r
216                                 }\r
217                         });\r
219                         if (c) {\r
220                                 each(ed.getParam('theme_advanced_styles', '', 'hash'), function(v, k) {\r
221                                         if (v)\r
222                                                 c.add(t.editor.translate(k), v);\r
223                                 });\r
225                                 c.onPostRender.add(function(ed, n) {\r
226                                         if (!c.NativeListBox) {\r
227                                                 Event.add(n.id + '_text', 'focus', t._importClasses, t);\r
228                                                 Event.add(n.id + '_text', 'mousedown', t._importClasses, t);\r
229                                                 Event.add(n.id + '_open', 'focus', t._importClasses, t);\r
230                                                 Event.add(n.id + '_open', 'mousedown', t._importClasses, t);\r
231                                         } else\r
232                                                 Event.add(n.id, 'focus', t._importClasses, t);\r
233                                 });\r
234                         }\r
236                         return c;\r
237                 },\r
239                 _createFontSelect : function() {\r
240                         var c, t = this, ed = t.editor;\r
242                         c = ed.controlManager.createListBox('fontselect', {title : 'advanced.fontdefault', cmd : 'FontName'});\r
243                         if (c) {\r
244                                 each(ed.getParam('theme_advanced_fonts', t.settings.theme_advanced_fonts, 'hash'), function(v, k) {\r
245                                         c.add(ed.translate(k), v, {style : v.indexOf('dings') == -1 ? 'font-family:' + v : ''});\r
246                                 });\r
247                         }\r
249                         return c;\r
250                 },\r
252                 _createFontSizeSelect : function() {\r
253                         var t = this, ed = t.editor, c, i = 0, cl = [];\r
255                         c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', onselect : function(v) {\r
256                                 if (v.fontSize)\r
257                                         ed.execCommand('FontSize', false, v.fontSize);\r
258                                 else {\r
259                                         each(t.settings.theme_advanced_font_sizes, function(v, k) {\r
260                                                 if (v['class'])\r
261                                                         cl.push(v['class']);\r
262                                         });\r
264                                         ed.editorCommands._applyInlineStyle('span', {'class' : v['class']}, {check_classes : cl});\r
265                                 }\r
266                         }});\r
268                         if (c) {\r
269                                 each(t.settings.theme_advanced_font_sizes, function(v, k) {\r
270                                         var fz = v.fontSize;\r
272                                         if (fz >= 1 && fz <= 7)\r
273                                                 fz = t.sizes[parseInt(fz) - 1] + 'pt';\r
275                                         c.add(k, v, {'style' : 'font-size:' + fz, 'class' : 'mceFontSize' + (i++) + (' ' + (v['class'] || ''))});\r
276                                 });\r
277                         }\r
279                         return c;\r
280                 },\r
282                 _createBlockFormats : function() {\r
283                         var c, fmts = {\r
284                                 p : 'advanced.paragraph',\r
285                                 address : 'advanced.address',\r
286                                 pre : 'advanced.pre',\r
287                                 h1 : 'advanced.h1',\r
288                                 h2 : 'advanced.h2',\r
289                                 h3 : 'advanced.h3',\r
290                                 h4 : 'advanced.h4',\r
291                                 h5 : 'advanced.h5',\r
292                                 h6 : 'advanced.h6',\r
293                                 div : 'advanced.div',\r
294                                 blockquote : 'advanced.blockquote',\r
295                                 code : 'advanced.code',\r
296                                 dt : 'advanced.dt',\r
297                                 dd : 'advanced.dd',\r
298                                 samp : 'advanced.samp'\r
299                         }, t = this;\r
301                         c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', cmd : 'FormatBlock'});\r
302                         if (c) {\r
303                                 each(t.editor.getParam('theme_advanced_blockformats', t.settings.theme_advanced_blockformats, 'hash'), function(v, k) {\r
304                                         c.add(t.editor.translate(k != v ? k : fmts[v]), v, {'class' : 'mce_formatPreview mce_' + v});\r
305                                 });\r
306                         }\r
308                         return c;\r
309                 },\r
311                 _createForeColorMenu : function() {\r
312                         var c, t = this, s = t.settings, o = {}, v;\r
314                         if (s.theme_advanced_more_colors) {\r
315                                 o.more_colors_func = function() {\r
316                                         t._mceColorPicker(0, {\r
317                                                 color : c.value,\r
318                                                 func : function(co) {\r
319                                                         c.setColor(co);\r
320                                                 }\r
321                                         });\r
322                                 };\r
323                         }\r
325                         if (v = s.theme_advanced_text_colors)\r
326                                 o.colors = v;\r
328                         if (s.theme_advanced_default_foreground_color)\r
329                                 o.default_color = s.theme_advanced_default_foreground_color;\r
331                         o.title = 'advanced.forecolor_desc';\r
332                         o.cmd = 'ForeColor';\r
333                         o.scope = this;\r
335                         c = t.editor.controlManager.createColorSplitButton('forecolor', o);\r
337                         return c;\r
338                 },\r
340                 _createBackColorMenu : function() {\r
341                         var c, t = this, s = t.settings, o = {}, v;\r
343                         if (s.theme_advanced_more_colors) {\r
344                                 o.more_colors_func = function() {\r
345                                         t._mceColorPicker(0, {\r
346                                                 color : c.value,\r
347                                                 func : function(co) {\r
348                                                         c.setColor(co);\r
349                                                 }\r
350                                         });\r
351                                 };\r
352                         }\r
354                         if (v = s.theme_advanced_background_colors)\r
355                                 o.colors = v;\r
357                         if (s.theme_advanced_default_background_color)\r
358                                 o.default_color = s.theme_advanced_default_background_color;\r
360                         o.title = 'advanced.backcolor_desc';\r
361                         o.cmd = 'HiliteColor';\r
362                         o.scope = this;\r
364                         c = t.editor.controlManager.createColorSplitButton('backcolor', o);\r
366                         return c;\r
367                 },\r
369                 renderUI : function(o) {\r
370                         var n, ic, tb, t = this, ed = t.editor, s = t.settings, sc, p, nl;\r
372                         n = p = DOM.create('span', {id : ed.id + '_parent', 'class' : 'mceEditor ' + ed.settings.skin + 'Skin' + (s.skin_variant ? ' ' + ed.settings.skin + 'Skin' + t._ufirst(s.skin_variant) : '')});\r
374                         if (!DOM.boxModel)\r
375                                 n = DOM.add(n, 'div', {'class' : 'mceOldBoxModel'});\r
377                         n = sc = DOM.add(n, 'table', {id : ed.id + '_tbl', 'class' : 'mceLayout', cellSpacing : 0, cellPadding : 0});\r
378                         n = tb = DOM.add(n, 'tbody');\r
380                         switch ((s.theme_advanced_layout_manager || '').toLowerCase()) {\r
381                                 case "rowlayout":\r
382                                         ic = t._rowLayout(s, tb, o);\r
383                                         break;\r
385                                 case "customlayout":\r
386                                         ic = ed.execCallback("theme_advanced_custom_layout", s, tb, o, p);\r
387                                         break;\r
389                                 default:\r
390                                         ic = t._simpleLayout(s, tb, o, p);\r
391                         }\r
393                         n = o.targetNode;\r
395                         // Add classes to first and last TRs\r
396                         nl = DOM.stdMode ? sc.getElementsByTagName('tr') : sc.rows; // Quick fix for IE 8\r
397                         DOM.addClass(nl[0], 'mceFirst');\r
398                         DOM.addClass(nl[nl.length - 1], 'mceLast');\r
400                         // Add classes to first and last TDs\r
401                         each(DOM.select('tr', tb), function(n) {\r
402                                 DOM.addClass(n.firstChild, 'mceFirst');\r
403                                 DOM.addClass(n.childNodes[n.childNodes.length - 1], 'mceLast');\r
404                         });\r
406                         if (DOM.get(s.theme_advanced_toolbar_container))\r
407                                 DOM.get(s.theme_advanced_toolbar_container).appendChild(p);\r
408                         else\r
409                                 DOM.insertAfter(p, n);\r
411                         Event.add(ed.id + '_path_row', 'click', function(e) {\r
412                                 e = e.target;\r
414                                 if (e.nodeName == 'A') {\r
415                                         t._sel(e.className.replace(/^.*mcePath_([0-9]+).*$/, '$1'));\r
417                                         return Event.cancel(e);\r
418                                 }\r
419                         });\r
420 /*\r
421                         if (DOM.get(ed.id + '_path_row')) {\r
422                                 Event.add(ed.id + '_tbl', 'mouseover', function(e) {\r
423                                         var re;\r
424         \r
425                                         e = e.target;\r
427                                         if (e.nodeName == 'SPAN' && DOM.hasClass(e.parentNode, 'mceButton')) {\r
428                                                 re = DOM.get(ed.id + '_path_row');\r
429                                                 t.lastPath = re.innerHTML;\r
430                                                 DOM.setHTML(re, e.parentNode.title);\r
431                                         }\r
432                                 });\r
434                                 Event.add(ed.id + '_tbl', 'mouseout', function(e) {\r
435                                         if (t.lastPath) {\r
436                                                 DOM.setHTML(ed.id + '_path_row', t.lastPath);\r
437                                                 t.lastPath = 0;\r
438                                         }\r
439                                 });\r
440                         }\r
441 */\r
443                         if (!ed.getParam('accessibility_focus') || ed.getParam('tab_focus'))\r
444                                 Event.add(DOM.add(p, 'a', {href : '#'}, '<!-- IE -->'), 'focus', function() {tinyMCE.get(ed.id).focus();});\r
446                         if (s.theme_advanced_toolbar_location == 'external')\r
447                                 o.deltaHeight = 0;\r
449                         t.deltaHeight = o.deltaHeight;\r
450                         o.targetNode = null;\r
452                         return {\r
453                                 iframeContainer : ic,\r
454                                 editorContainer : ed.id + '_parent',\r
455                                 sizeContainer : sc,\r
456                                 deltaHeight : o.deltaHeight\r
457                         };\r
458                 },\r
460                 getInfo : function() {\r
461                         return {\r
462                                 longname : 'Advanced theme',\r
463                                 author : 'Moxiecode Systems AB',\r
464                                 authorurl : 'http://tinymce.moxiecode.com',\r
465                                 version : tinymce.majorVersion + "." + tinymce.minorVersion\r
466                         }\r
467                 },\r
469                 resizeBy : function(dw, dh) {\r
470                         var e = DOM.get(this.editor.id + '_tbl');\r
472                         this.resizeTo(e.clientWidth + dw, e.clientHeight + dh);\r
473                 },\r
475                 resizeTo : function(w, h) {\r
476                         var ed = this.editor, s = ed.settings, e = DOM.get(ed.id + '_tbl'), ifr = DOM.get(ed.id + '_ifr'), dh;\r
478                         // Boundery fix box\r
479                         w = Math.max(s.theme_advanced_resizing_min_width || 100, w);\r
480                         h = Math.max(s.theme_advanced_resizing_min_height || 100, h);\r
481                         w = Math.min(s.theme_advanced_resizing_max_width || 0xFFFF, w);\r
482                         h = Math.min(s.theme_advanced_resizing_max_height || 0xFFFF, h);\r
484                         // Calc difference between iframe and container\r
485                         dh = e.clientHeight - ifr.clientHeight;\r
487                         // Resize iframe and container\r
488                         DOM.setStyle(ifr, 'height', h - dh);\r
489                         DOM.setStyles(e, {width : w, height : h});\r
490                 },\r
492                 destroy : function() {\r
493                         var id = this.editor.id;\r
495                         Event.clear(id + '_resize');\r
496                         Event.clear(id + '_path_row');\r
497                         Event.clear(id + '_external_close');\r
498                 },\r
500                 // Internal functions\r
502                 _simpleLayout : function(s, tb, o, p) {\r
503                         var t = this, ed = t.editor, lo = s.theme_advanced_toolbar_location, sl = s.theme_advanced_statusbar_location, n, ic, etb, c;\r
505                         if (s.readonly) {\r
506                                 n = DOM.add(tb, 'tr');\r
507                                 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});\r
508                                 return ic;\r
509                         }\r
511                         // Create toolbar container at top\r
512                         if (lo == 'top')\r
513                                 t._addToolbars(tb, o);\r
515                         // Create external toolbar\r
516                         if (lo == 'external') {\r
517                                 n = c = DOM.create('div', {style : 'position:relative'});\r
518                                 n = DOM.add(n, 'div', {id : ed.id + '_external', 'class' : 'mceExternalToolbar'});\r
519                                 DOM.add(n, 'a', {id : ed.id + '_external_close', href : 'javascript:;', 'class' : 'mceExternalClose'});\r
520                                 n = DOM.add(n, 'table', {id : ed.id + '_tblext', cellSpacing : 0, cellPadding : 0});\r
521                                 etb = DOM.add(n, 'tbody');\r
523                                 if (p.firstChild.className == 'mceOldBoxModel')\r
524                                         p.firstChild.appendChild(c);\r
525                                 else\r
526                                         p.insertBefore(c, p.firstChild);\r
528                                 t._addToolbars(etb, o);\r
530                                 ed.onMouseUp.add(function() {\r
531                                         var e = DOM.get(ed.id + '_external');\r
532                                         DOM.show(e);\r
534                                         DOM.hide(lastExtID);\r
536                                         var f = Event.add(ed.id + '_external_close', 'click', function() {\r
537                                                 DOM.hide(ed.id + '_external');\r
538                                                 Event.remove(ed.id + '_external_close', 'click', f);\r
539                                         });\r
541                                         DOM.show(e);\r
542                                         DOM.setStyle(e, 'top', 0 - DOM.getRect(ed.id + '_tblext').h - 1);\r
544                                         // Fixes IE rendering bug\r
545                                         DOM.hide(e);\r
546                                         DOM.show(e);\r
547                                         e.style.filter = '';\r
549                                         lastExtID = ed.id + '_external';\r
551                                         e = null;\r
552                                 });\r
553                         }\r
555                         if (sl == 'top')\r
556                                 t._addStatusBar(tb, o);\r
558                         // Create iframe container\r
559                         if (!s.theme_advanced_toolbar_container) {\r
560                                 n = DOM.add(tb, 'tr');\r
561                                 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});\r
562                         }\r
564                         // Create toolbar container at bottom\r
565                         if (lo == 'bottom')\r
566                                 t._addToolbars(tb, o);\r
568                         if (sl == 'bottom')\r
569                                 t._addStatusBar(tb, o);\r
571                         return ic;\r
572                 },\r
574                 _rowLayout : function(s, tb, o) {\r
575                         var t = this, ed = t.editor, dc, da, cf = ed.controlManager, n, ic, to, a;\r
577                         dc = s.theme_advanced_containers_default_class || '';\r
578                         da = s.theme_advanced_containers_default_align || 'center';\r
580                         each(explode(s.theme_advanced_containers || ''), function(c, i) {\r
581                                 var v = s['theme_advanced_container_' + c] || '';\r
583                                 switch (v.toLowerCase()) {\r
584                                         case 'mceeditor':\r
585                                                 n = DOM.add(tb, 'tr');\r
586                                                 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});\r
587                                                 break;\r
589                                         case 'mceelementpath':\r
590                                                 t._addStatusBar(tb, o);\r
591                                                 break;\r
593                                         default:\r
594                                                 a = (s['theme_advanced_container_' + c + '_align'] || da).toLowerCase();\r
595                                                 a = 'mce' + t._ufirst(a);\r
597                                                 n = DOM.add(DOM.add(tb, 'tr'), 'td', {\r
598                                                         'class' : 'mceToolbar ' + (s['theme_advanced_container_' + c + '_class'] || dc) + ' ' + a || da\r
599                                                 });\r
601                                                 to = cf.createToolbar("toolbar" + i);\r
602                                                 t._addControls(v, to);\r
603                                                 DOM.setHTML(n, to.renderHTML());\r
604                                                 o.deltaHeight -= s.theme_advanced_row_height;\r
605                                 }\r
606                         });\r
608                         return ic;\r
609                 },\r
611                 _addControls : function(v, tb) {\r
612                         var t = this, s = t.settings, di, cf = t.editor.controlManager;\r
614                         if (s.theme_advanced_disable && !t._disabled) {\r
615                                 di = {};\r
617                                 each(explode(s.theme_advanced_disable), function(v) {\r
618                                         di[v] = 1;\r
619                                 });\r
621                                 t._disabled = di;\r
622                         } else\r
623                                 di = t._disabled;\r
625                         each(explode(v), function(n) {\r
626                                 var c;\r
628                                 if (di && di[n])\r
629                                         return;\r
631                                 // Compatiblity with 2.x\r
632                                 if (n == 'tablecontrols') {\r
633                                         each(["table","|","row_props","cell_props","|","row_before","row_after","delete_row","|","col_before","col_after","delete_col","|","split_cells","merge_cells"], function(n) {\r
634                                                 n = t.createControl(n, cf);\r
636                                                 if (n)\r
637                                                         tb.add(n);\r
638                                         });\r
640                                         return;\r
641                                 }\r
643                                 c = t.createControl(n, cf);\r
645                                 if (c)\r
646                                         tb.add(c);\r
647                         });\r
648                 },\r
650                 _addToolbars : function(c, o) {\r
651                         var t = this, i, tb, ed = t.editor, s = t.settings, v, cf = ed.controlManager, di, n, h = [], a;\r
653                         a = s.theme_advanced_toolbar_align.toLowerCase();\r
654                         a = 'mce' + t._ufirst(a);\r
656                         n = DOM.add(DOM.add(c, 'tr'), 'td', {'class' : 'mceToolbar ' + a});\r
658                         if (!ed.getParam('accessibility_focus') || ed.getParam('tab_focus'))\r
659                                 h.push(DOM.createHTML('a', {href : '#', onfocus : 'tinyMCE.get(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));\r
661                         h.push(DOM.createHTML('a', {href : '#', accesskey : 'q', title : ed.getLang("advanced.toolbar_focus")}, '<!-- IE -->'));\r
663                         // Create toolbar and add the controls\r
664                         for (i=1; (v = s['theme_advanced_buttons' + i]); i++) {\r
665                                 tb = cf.createToolbar("toolbar" + i, {'class' : 'mceToolbarRow' + i});\r
667                                 if (s['theme_advanced_buttons' + i + '_add'])\r
668                                         v += ',' + s['theme_advanced_buttons' + i + '_add'];\r
670                                 if (s['theme_advanced_buttons' + i + '_add_before'])\r
671                                         v = s['theme_advanced_buttons' + i + '_add_before'] + ',' + v;\r
673                                 t._addControls(v, tb);\r
675                                 //n.appendChild(n = tb.render());\r
676                                 h.push(tb.renderHTML());\r
678                                 o.deltaHeight -= s.theme_advanced_row_height;\r
679                         }\r
681                         h.push(DOM.createHTML('a', {href : '#', accesskey : 'z', title : ed.getLang("advanced.toolbar_focus"), onfocus : 'tinyMCE.getInstanceById(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));\r
682                         DOM.setHTML(n, h.join(''));\r
683                 },\r
685                 _addStatusBar : function(tb, o) {\r
686                         var n, t = this, ed = t.editor, s = t.settings, r, mf, me, td;\r
688                         n = DOM.add(tb, 'tr');\r
689                         n = td = DOM.add(n, 'td', {'class' : 'mceStatusbar'});\r
690                         n = DOM.add(n, 'div', {id : ed.id + '_path_row'}, s.theme_advanced_path ? ed.translate('advanced.path') + ': ' : '&nbsp;');\r
691                         DOM.add(n, 'a', {href : '#', accesskey : 'x'});\r
693                         if (s.theme_advanced_resizing && !tinymce.isOldWebKit) {\r
694                                 DOM.add(td, 'a', {id : ed.id + '_resize', href : 'javascript:;', onclick : "return false;", 'class' : 'mceResize'});\r
696                                 if (s.theme_advanced_resizing_use_cookie) {\r
697                                         ed.onPostRender.add(function() {\r
698                                                 var o = Cookie.getHash("TinyMCE_" + ed.id + "_size"), c = DOM.get(ed.id + '_tbl');\r
700                                                 if (!o)\r
701                                                         return;\r
703                                                 if (s.theme_advanced_resize_horizontal)\r
704                                                         c.style.width = Math.max(10, o.cw) + 'px';\r
706                                                 c.style.height = Math.max(10, o.ch) + 'px';\r
707                                                 DOM.get(ed.id + '_ifr').style.height = Math.max(10, parseInt(o.ch) + t.deltaHeight) + 'px';\r
708                                         });\r
709                                 }\r
711                                 ed.onPostRender.add(function() {\r
712                                         Event.add(ed.id + '_resize', 'mousedown', function(e) {\r
713                                                 var c, p, w, h, n, pa;\r
715                                                 // Measure container\r
716                                                 c = DOM.get(ed.id + '_tbl');\r
717                                                 w = c.clientWidth;\r
718                                                 h = c.clientHeight;\r
720                                                 miw = s.theme_advanced_resizing_min_width || 100;\r
721                                                 mih = s.theme_advanced_resizing_min_height || 100;\r
722                                                 maw = s.theme_advanced_resizing_max_width || 0xFFFF;\r
723                                                 mah = s.theme_advanced_resizing_max_height || 0xFFFF;\r
725                                                 // Setup placeholder\r
726                                                 p = DOM.add(DOM.get(ed.id + '_parent'), 'div', {'class' : 'mcePlaceHolder'});\r
727                                                 DOM.setStyles(p, {width : w, height : h});\r
729                                                 // Replace with placeholder\r
730                                                 DOM.hide(c);\r
731                                                 DOM.show(p);\r
733                                                 // Create internal resize obj\r
734                                                 r = {\r
735                                                         x : e.screenX,\r
736                                                         y : e.screenY,\r
737                                                         w : w,\r
738                                                         h : h,\r
739                                                         dx : null,\r
740                                                         dy : null\r
741                                                 };\r
743                                                 // Start listening\r
744                                                 mf = Event.add(DOM.doc, 'mousemove', function(e) {\r
745                                                         var w, h;\r
747                                                         // Calc delta values\r
748                                                         r.dx = e.screenX - r.x;\r
749                                                         r.dy = e.screenY - r.y;\r
751                                                         // Boundery fix box\r
752                                                         w = Math.max(miw, r.w + r.dx);\r
753                                                         h = Math.max(mih, r.h + r.dy);\r
754                                                         w = Math.min(maw, w);\r
755                                                         h = Math.min(mah, h);\r
757                                                         // Resize placeholder\r
758                                                         if (s.theme_advanced_resize_horizontal)\r
759                                                                 p.style.width = w + 'px';\r
761                                                         p.style.height = h + 'px';\r
763                                                         return Event.cancel(e);\r
764                                                 });\r
766                                                 me = Event.add(DOM.doc, 'mouseup', function(e) {\r
767                                                         var ifr;\r
769                                                         // Stop listening\r
770                                                         Event.remove(DOM.doc, 'mousemove', mf);\r
771                                                         Event.remove(DOM.doc, 'mouseup', me);\r
773                                                         c.style.display = '';\r
774                                                         DOM.remove(p);\r
776                                                         if (r.dx === null)\r
777                                                                 return;\r
779                                                         ifr = DOM.get(ed.id + '_ifr');\r
781                                                         if (s.theme_advanced_resize_horizontal)\r
782                                                                 c.style.width = Math.max(10, r.w + r.dx) + 'px';\r
784                                                         c.style.height = Math.max(10, r.h + r.dy) + 'px';\r
785                                                         ifr.style.height = Math.max(10, ifr.clientHeight + r.dy) + 'px';\r
787                                                         if (s.theme_advanced_resizing_use_cookie) {\r
788                                                                 Cookie.setHash("TinyMCE_" + ed.id + "_size", {\r
789                                                                         cw : r.w + r.dx,\r
790                                                                         ch : r.h + r.dy\r
791                                                                 });\r
792                                                         }\r
793                                                 });\r
795                                                 return Event.cancel(e);\r
796                                         });\r
797                                 });\r
798                         }\r
800                         o.deltaHeight -= 21;\r
801                         n = tb = null;\r
802                 },\r
804                 _nodeChanged : function(ed, cm, n, co) {\r
805                         var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn;\r
807                         if (s.readonly)\r
808                                 return;\r
810                         tinymce.each(t.stateControls, function(c) {\r
811                                 cm.setActive(c, ed.queryCommandState(t.controls[c][1]));\r
812                         });\r
814                         cm.setActive('visualaid', ed.hasVisual);\r
815                         cm.setDisabled('undo', !ed.undoManager.hasUndo() && !ed.typing);\r
816                         cm.setDisabled('redo', !ed.undoManager.hasRedo());\r
817                         cm.setDisabled('outdent', !ed.queryCommandState('Outdent'));\r
819                         p = DOM.getParent(n, 'A');\r
820                         if (c = cm.get('link')) {\r
821                                 if (!p || !p.name) {\r
822                                         c.setDisabled(!p && co);\r
823                                         c.setActive(!!p);\r
824                                 }\r
825                         }\r
827                         if (c = cm.get('unlink')) {\r
828                                 c.setDisabled(!p && co);\r
829                                 c.setActive(!!p && !p.name);\r
830                         }\r
832                         if (c = cm.get('anchor')) {\r
833                                 c.setActive(!!p && p.name);\r
835                                 if (tinymce.isWebKit) {\r
836                                         p = DOM.getParent(n, 'IMG');\r
837                                         c.setActive(!!p && DOM.getAttrib(p, 'mce_name') == 'a');\r
838                                 }\r
839                         }\r
841                         p = DOM.getParent(n, 'IMG');\r
842                         if (c = cm.get('image'))\r
843                                 c.setActive(!!p && n.className.indexOf('mceItem') == -1);\r
845                         if (c = cm.get('styleselect')) {\r
846                                 if (n.className) {\r
847                                         t._importClasses();\r
848                                         c.select(n.className);\r
849                                 } else\r
850                                         c.select();\r
851                         }\r
853                         if (c = cm.get('formatselect')) {\r
854                                 p = DOM.getParent(n, DOM.isBlock);\r
856                                 if (p)\r
857                                         c.select(p.nodeName.toLowerCase());\r
858                         }\r
860                         if (ed.settings.convert_fonts_to_spans) {\r
861                                 ed.dom.getParent(n, function(n) {\r
862                                         if (n.nodeName === 'SPAN') {\r
863                                                 if (!cl && n.className)\r
864                                                         cl = n.className;\r
866                                                 if (!fz && n.style.fontSize)\r
867                                                         fz = n.style.fontSize;\r
869                                                 if (!fn && n.style.fontFamily)\r
870                                                         fn = n.style.fontFamily.replace(/[\"\']+/g, '').replace(/^([^,]+).*/, '$1').toLowerCase();\r
871                                         }\r
873                                         return false;\r
874                                 });\r
876                                 if (c = cm.get('fontselect')) {\r
877                                         c.select(function(v) {\r
878                                                 return v.replace(/^([^,]+).*/, '$1').toLowerCase() == fn;\r
879                                         });\r
880                                 }\r
882                                 if (c = cm.get('fontsizeselect')) {\r
883                                         c.select(function(v) {\r
884                                                 if (v.fontSize && v.fontSize === fz)\r
885                                                         return true;\r
887                                                 if (v['class'] && v['class'] === cl)\r
888                                                         return true;\r
889                                         });\r
890                                 }\r
891                         } else {\r
892                                 if (c = cm.get('fontselect'))\r
893                                         c.select(ed.queryCommandValue('FontName'));\r
895                                 if (c = cm.get('fontsizeselect')) {\r
896                                         v = ed.queryCommandValue('FontSize');\r
897                                         c.select(function(iv) {\r
898                                                 return iv.fontSize == v;\r
899                                         });\r
900                                 }\r
901                         }\r
903                         if (s.theme_advanced_path && s.theme_advanced_statusbar_location) {\r
904                                 p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'});\r
905                                 DOM.setHTML(p, '');\r
907                                 ed.dom.getParent(n, function(n) {\r
908                                         var na = n.nodeName.toLowerCase(), u, pi, ti = '';\r
910                                         // Ignore non element and hidden elements\r
911                                         if (n.nodeType != 1 || n.nodeName === 'BR' || (DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved')))\r
912                                                 return;\r
914                                         // Fake name\r
915                                         if (v = DOM.getAttrib(n, 'mce_name'))\r
916                                                 na = v;\r
918                                         // Handle prefix\r
919                                         if (tinymce.isIE && n.scopeName !== 'HTML')\r
920                                                 na = n.scopeName + ':' + na;\r
922                                         // Remove internal prefix\r
923                                         na = na.replace(/mce\:/g, '');\r
925                                         // Handle node name\r
926                                         switch (na) {\r
927                                                 case 'b':\r
928                                                         na = 'strong';\r
929                                                         break;\r
931                                                 case 'i':\r
932                                                         na = 'em';\r
933                                                         break;\r
935                                                 case 'img':\r
936                                                         if (v = DOM.getAttrib(n, 'src'))\r
937                                                                 ti += 'src: ' + v + ' ';\r
939                                                         break;\r
941                                                 case 'a':\r
942                                                         if (v = DOM.getAttrib(n, 'name')) {\r
943                                                                 ti += 'name: ' + v + ' ';\r
944                                                                 na += '#' + v;\r
945                                                         }\r
947                                                         if (v = DOM.getAttrib(n, 'href'))\r
948                                                                 ti += 'href: ' + v + ' ';\r
950                                                         break;\r
952                                                 case 'font':\r
953                                                         if (s.convert_fonts_to_spans)\r
954                                                                 na = 'span';\r
956                                                         if (v = DOM.getAttrib(n, 'face'))\r
957                                                                 ti += 'font: ' + v + ' ';\r
959                                                         if (v = DOM.getAttrib(n, 'size'))\r
960                                                                 ti += 'size: ' + v + ' ';\r
962                                                         if (v = DOM.getAttrib(n, 'color'))\r
963                                                                 ti += 'color: ' + v + ' ';\r
965                                                         break;\r
967                                                 case 'span':\r
968                                                         if (v = DOM.getAttrib(n, 'style'))\r
969                                                                 ti += 'style: ' + v + ' ';\r
971                                                         break;\r
972                                         }\r
974                                         if (v = DOM.getAttrib(n, 'id'))\r
975                                                 ti += 'id: ' + v + ' ';\r
977                                         if (v = n.className) {\r
978                                                 v = v.replace(/(webkit-[\w\-]+|Apple-[\w\-]+|mceItem\w+|mceVisualAid)/g, '');\r
980                                                 if (v && v.indexOf('mceItem') == -1) {\r
981                                                         ti += 'class: ' + v + ' ';\r
983                                                         if (DOM.isBlock(n) || na == 'img' || na == 'span')\r
984                                                                 na += '.' + v;\r
985                                                 }\r
986                                         }\r
988                                         na = na.replace(/(html:)/g, '');\r
989                                         na = {name : na, node : n, title : ti};\r
990                                         t.onResolveName.dispatch(t, na);\r
991                                         ti = na.title;\r
992                                         na = na.name;\r
994                                         //u = "javascript:tinymce.EditorManager.get('" + ed.id + "').theme._sel('" + (de++) + "');";\r
995                                         pi = DOM.create('a', {'href' : "javascript:;", onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na);\r
997                                         if (p.hasChildNodes()) {\r
998                                                 p.insertBefore(DOM.doc.createTextNode(' \u00bb '), p.firstChild);\r
999                                                 p.insertBefore(pi, p.firstChild);\r
1000                                         } else\r
1001                                                 p.appendChild(pi);\r
1002                                 }, ed.getBody());\r
1003                         }\r
1004                 },\r
1006                 // Commands gets called by execCommand\r
1008                 _sel : function(v) {\r
1009                         this.editor.execCommand('mceSelectNodeDepth', false, v);\r
1010                 },\r
1012                 _mceInsertAnchor : function(ui, v) {\r
1013                         var ed = this.editor;\r
1015                         ed.windowManager.open({\r
1016                                 url : tinymce.baseURL + '/themes/advanced/anchor.htm',\r
1017                                 width : 320 + parseInt(ed.getLang('advanced.anchor_delta_width', 0)),\r
1018                                 height : 90 + parseInt(ed.getLang('advanced.anchor_delta_height', 0)),\r
1019                                 inline : true\r
1020                         }, {\r
1021                                 theme_url : this.url\r
1022                         });\r
1023                 },\r
1025                 _mceCharMap : function() {\r
1026                         var ed = this.editor;\r
1028                         ed.windowManager.open({\r
1029                                 url : tinymce.baseURL + '/themes/advanced/charmap.htm',\r
1030                                 width : 550 + parseInt(ed.getLang('advanced.charmap_delta_width', 0)),\r
1031                                 height : 250 + parseInt(ed.getLang('advanced.charmap_delta_height', 0)),\r
1032                                 inline : true\r
1033                         }, {\r
1034                                 theme_url : this.url\r
1035                         });\r
1036                 },\r
1038                 _mceHelp : function() {\r
1039                         var ed = this.editor;\r
1041                         ed.windowManager.open({\r
1042                                 url : tinymce.baseURL + '/themes/advanced/about.htm',\r
1043                                 width : 480,\r
1044                                 height : 380,\r
1045                                 inline : true\r
1046                         }, {\r
1047                                 theme_url : this.url\r
1048                         });\r
1049                 },\r
1051                 _mceColorPicker : function(u, v) {\r
1052                         var ed = this.editor;\r
1054                         v = v || {};\r
1056                         ed.windowManager.open({\r
1057                                 url : tinymce.baseURL + '/themes/advanced/color_picker.htm',\r
1058                                 width : 375 + parseInt(ed.getLang('advanced.colorpicker_delta_width', 0)),\r
1059                                 height : 250 + parseInt(ed.getLang('advanced.colorpicker_delta_height', 0)),\r
1060                                 close_previous : false,\r
1061                                 inline : true\r
1062                         }, {\r
1063                                 input_color : v.color,\r
1064                                 func : v.func,\r
1065                                 theme_url : this.url\r
1066                         });\r
1067                 },\r
1069                 _mceCodeEditor : function(ui, val) {\r
1070                         var ed = this.editor;\r
1072                         ed.windowManager.open({\r
1073                                 url : tinymce.baseURL + '/themes/advanced/source_editor.htm',\r
1074                                 width : parseInt(ed.getParam("theme_advanced_source_editor_width", 720)),\r
1075                                 height : parseInt(ed.getParam("theme_advanced_source_editor_height", 580)),\r
1076                                 inline : true,\r
1077                                 resizable : true,\r
1078                                 maximizable : true\r
1079                         }, {\r
1080                                 theme_url : this.url\r
1081                         });\r
1082                 },\r
1084                 _mceImage : function(ui, val) {\r
1085                         var ed = this.editor;\r
1087                         // Internal image object like a flash placeholder\r
1088                         if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1)\r
1089                                 return;\r
1091                         ed.windowManager.open({\r
1092                                 url : tinymce.baseURL + '/themes/advanced/image.htm',\r
1093                                 width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)),\r
1094                                 height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)),\r
1095                                 inline : true\r
1096                         }, {\r
1097                                 theme_url : this.url\r
1098                         });\r
1099                 },\r
1101                 _mceLink : function(ui, val) {\r
1102                         var ed = this.editor;\r
1104                         ed.windowManager.open({\r
1105                                 url : tinymce.baseURL + '/themes/advanced/link.htm',\r
1106                                 width : 310 + parseInt(ed.getLang('advanced.link_delta_width', 0)),\r
1107                                 height : 200 + parseInt(ed.getLang('advanced.link_delta_height', 0)),\r
1108                                 inline : true\r
1109                         }, {\r
1110                                 theme_url : this.url\r
1111                         });\r
1112                 },\r
1114                 _mceNewDocument : function() {\r
1115                         var ed = this.editor;\r
1117                         ed.windowManager.confirm('advanced.newdocument', function(s) {\r
1118                                 if (s)\r
1119                                         ed.execCommand('mceSetContent', false, '');\r
1120                         });\r
1121                 },\r
1123                 _mceForeColor : function() {\r
1124                         var t = this;\r
1126                         this._mceColorPicker(0, {\r
1127                                 color: t.fgColor,\r
1128                                 func : function(co) {\r
1129                                         t.fgColor = co;\r
1130                                         t.editor.execCommand('ForeColor', false, co);\r
1131                                 }\r
1132                         });\r
1133                 },\r
1135                 _mceBackColor : function() {\r
1136                         var t = this;\r
1138                         this._mceColorPicker(0, {\r
1139                                 color: t.bgColor,\r
1140                                 func : function(co) {\r
1141                                         t.bgColor = co;\r
1142                                         t.editor.execCommand('HiliteColor', false, co);\r
1143                                 }\r
1144                         });\r
1145                 },\r
1147                 _ufirst : function(s) {\r
1148                         return s.substring(0, 1).toUpperCase() + s.substring(1);\r
1149                 }\r
1150         });\r
1152         tinymce.ThemeManager.add('advanced', tinymce.themes.AdvancedTheme);\r
1153 }());