comparison static/js/tiny_mce/themes/advanced/editor_template_src.js @ 312:88b2b9cb8c1f

Fixing #142; cut over to the django.contrib.staticfiles app.
author Brian Neal <bgneal@gmail.com>
date Thu, 27 Jan 2011 02:56:10 +0000
parents
children 6c182ceb7147
comparison
equal deleted inserted replaced
311:b1c39788e511 312:88b2b9cb8c1f
1 /**
2 * editor_template_src.js
3 *
4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
6 *
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
9 */
10
11 (function(tinymce) {
12 var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, each = tinymce.each, Cookie = tinymce.util.Cookie, lastExtID, explode = tinymce.explode;
13
14 // Tell it to load theme specific language pack(s)
15 tinymce.ThemeManager.requireLangPack('advanced');
16
17 tinymce.create('tinymce.themes.AdvancedTheme', {
18 sizes : [8, 10, 12, 14, 18, 24, 36],
19
20 // Control name lookup, format: title, command
21 controls : {
22 bold : ['bold_desc', 'Bold'],
23 italic : ['italic_desc', 'Italic'],
24 underline : ['underline_desc', 'Underline'],
25 strikethrough : ['striketrough_desc', 'Strikethrough'],
26 justifyleft : ['justifyleft_desc', 'JustifyLeft'],
27 justifycenter : ['justifycenter_desc', 'JustifyCenter'],
28 justifyright : ['justifyright_desc', 'JustifyRight'],
29 justifyfull : ['justifyfull_desc', 'JustifyFull'],
30 bullist : ['bullist_desc', 'InsertUnorderedList'],
31 numlist : ['numlist_desc', 'InsertOrderedList'],
32 outdent : ['outdent_desc', 'Outdent'],
33 indent : ['indent_desc', 'Indent'],
34 cut : ['cut_desc', 'Cut'],
35 copy : ['copy_desc', 'Copy'],
36 paste : ['paste_desc', 'Paste'],
37 undo : ['undo_desc', 'Undo'],
38 redo : ['redo_desc', 'Redo'],
39 link : ['link_desc', 'mceLink'],
40 unlink : ['unlink_desc', 'unlink'],
41 image : ['image_desc', 'mceImage'],
42 cleanup : ['cleanup_desc', 'mceCleanup'],
43 help : ['help_desc', 'mceHelp'],
44 code : ['code_desc', 'mceCodeEditor'],
45 hr : ['hr_desc', 'InsertHorizontalRule'],
46 removeformat : ['removeformat_desc', 'RemoveFormat'],
47 sub : ['sub_desc', 'subscript'],
48 sup : ['sup_desc', 'superscript'],
49 forecolor : ['forecolor_desc', 'ForeColor'],
50 forecolorpicker : ['forecolor_desc', 'mceForeColor'],
51 backcolor : ['backcolor_desc', 'HiliteColor'],
52 backcolorpicker : ['backcolor_desc', 'mceBackColor'],
53 charmap : ['charmap_desc', 'mceCharMap'],
54 visualaid : ['visualaid_desc', 'mceToggleVisualAid'],
55 anchor : ['anchor_desc', 'mceInsertAnchor'],
56 newdocument : ['newdocument_desc', 'mceNewDocument'],
57 blockquote : ['blockquote_desc', 'mceBlockQuote']
58 },
59
60 stateControls : ['bold', 'italic', 'underline', 'strikethrough', 'bullist', 'numlist', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'sub', 'sup', 'blockquote'],
61
62 init : function(ed, url) {
63 var t = this, s, v, o;
64
65 t.editor = ed;
66 t.url = url;
67 t.onResolveName = new tinymce.util.Dispatcher(this);
68
69 // Default settings
70 t.settings = s = extend({
71 theme_advanced_path : true,
72 theme_advanced_toolbar_location : 'bottom',
73 theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",
74 theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",
75 theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap",
76 theme_advanced_blockformats : "p,address,pre,h1,h2,h3,h4,h5,h6",
77 theme_advanced_toolbar_align : "center",
78 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",
79 theme_advanced_more_colors : 1,
80 theme_advanced_row_height : 23,
81 theme_advanced_resize_horizontal : 1,
82 theme_advanced_resizing_use_cookie : 1,
83 theme_advanced_font_sizes : "1,2,3,4,5,6,7",
84 readonly : ed.settings.readonly
85 }, ed.settings);
86
87 // Setup default font_size_style_values
88 if (!s.font_size_style_values)
89 s.font_size_style_values = "8pt,10pt,12pt,14pt,18pt,24pt,36pt";
90
91 if (tinymce.is(s.theme_advanced_font_sizes, 'string')) {
92 s.font_size_style_values = tinymce.explode(s.font_size_style_values);
93 s.font_size_classes = tinymce.explode(s.font_size_classes || '');
94
95 // Parse string value
96 o = {};
97 ed.settings.theme_advanced_font_sizes = s.theme_advanced_font_sizes;
98 each(ed.getParam('theme_advanced_font_sizes', '', 'hash'), function(v, k) {
99 var cl;
100
101 if (k == v && v >= 1 && v <= 7) {
102 k = v + ' (' + t.sizes[v - 1] + 'pt)';
103 cl = s.font_size_classes[v - 1];
104 v = s.font_size_style_values[v - 1] || (t.sizes[v - 1] + 'pt');
105 }
106
107 if (/^\s*\./.test(v))
108 cl = v.replace(/\./g, '');
109
110 o[k] = cl ? {'class' : cl} : {fontSize : v};
111 });
112
113 s.theme_advanced_font_sizes = o;
114 }
115
116 if ((v = s.theme_advanced_path_location) && v != 'none')
117 s.theme_advanced_statusbar_location = s.theme_advanced_path_location;
118
119 if (s.theme_advanced_statusbar_location == 'none')
120 s.theme_advanced_statusbar_location = 0;
121
122 // Init editor
123 ed.onInit.add(function() {
124 if (!ed.settings.readonly)
125 ed.onNodeChange.add(t._nodeChanged, t);
126
127 if (ed.settings.content_css !== false)
128 ed.dom.loadCSS(ed.baseURI.toAbsolute(url + "/skins/" + ed.settings.skin + "/content.css"));
129 });
130
131 ed.onSetProgressState.add(function(ed, b, ti) {
132 var co, id = ed.id, tb;
133
134 if (b) {
135 t.progressTimer = setTimeout(function() {
136 co = ed.getContainer();
137 co = co.insertBefore(DOM.create('DIV', {style : 'position:relative'}), co.firstChild);
138 tb = DOM.get(ed.id + '_tbl');
139
140 DOM.add(co, 'div', {id : id + '_blocker', 'class' : 'mceBlocker', style : {width : tb.clientWidth + 2, height : tb.clientHeight + 2}});
141 DOM.add(co, 'div', {id : id + '_progress', 'class' : 'mceProgress', style : {left : tb.clientWidth / 2, top : tb.clientHeight / 2}});
142 }, ti || 0);
143 } else {
144 DOM.remove(id + '_blocker');
145 DOM.remove(id + '_progress');
146 clearTimeout(t.progressTimer);
147 }
148 });
149
150 DOM.loadCSS(s.editor_css ? ed.documentBaseURI.toAbsolute(s.editor_css) : url + "/skins/" + ed.settings.skin + "/ui.css");
151
152 if (s.skin_variant)
153 DOM.loadCSS(url + "/skins/" + ed.settings.skin + "/ui_" + s.skin_variant + ".css");
154 },
155
156 createControl : function(n, cf) {
157 var cd, c;
158
159 if (c = cf.createControl(n))
160 return c;
161
162 switch (n) {
163 case "styleselect":
164 return this._createStyleSelect();
165
166 case "formatselect":
167 return this._createBlockFormats();
168
169 case "fontselect":
170 return this._createFontSelect();
171
172 case "fontsizeselect":
173 return this._createFontSizeSelect();
174
175 case "forecolor":
176 return this._createForeColorMenu();
177
178 case "backcolor":
179 return this._createBackColorMenu();
180 }
181
182 if ((cd = this.controls[n]))
183 return cf.createButton(n, {title : "advanced." + cd[0], cmd : cd[1], ui : cd[2], value : cd[3]});
184 },
185
186 execCommand : function(cmd, ui, val) {
187 var f = this['_' + cmd];
188
189 if (f) {
190 f.call(this, ui, val);
191 return true;
192 }
193
194 return false;
195 },
196
197 _importClasses : function(e) {
198 var ed = this.editor, ctrl = ed.controlManager.get('styleselect');
199
200 if (ctrl.getLength() == 0) {
201 each(ed.dom.getClasses(), function(o, idx) {
202 var name = 'style_' + idx;
203
204 ed.formatter.register(name, {
205 inline : 'span',
206 attributes : {'class' : o['class']},
207 selector : '*'
208 });
209
210 ctrl.add(o['class'], name);
211 });
212 }
213 },
214
215 _createStyleSelect : function(n) {
216 var t = this, ed = t.editor, ctrlMan = ed.controlManager, ctrl;
217
218 // Setup style select box
219 ctrl = ctrlMan.createListBox('styleselect', {
220 title : 'advanced.style_select',
221 onselect : function(name) {
222 var matches, formatNames = [];
223
224 each(ctrl.items, function(item) {
225 formatNames.push(item.value);
226 });
227
228 ed.focus();
229 ed.undoManager.add();
230
231 // Toggle off the current format
232 matches = ed.formatter.matchAll(formatNames);
233 if (!name || matches[0] == name)
234 ed.formatter.remove(matches[0]);
235 else
236 ed.formatter.apply(name);
237
238 ed.undoManager.add();
239 ed.nodeChanged();
240
241 return false; // No auto select
242 }
243 });
244
245 // Handle specified format
246 ed.onInit.add(function() {
247 var counter = 0, formats = ed.getParam('style_formats');
248
249 if (formats) {
250 each(formats, function(fmt) {
251 var name, keys = 0;
252
253 each(fmt, function() {keys++;});
254
255 if (keys > 1) {
256 name = fmt.name = fmt.name || 'style_' + (counter++);
257 ed.formatter.register(name, fmt);
258 ctrl.add(fmt.title, name);
259 } else
260 ctrl.add(fmt.title);
261 });
262 } else {
263 each(ed.getParam('theme_advanced_styles', '', 'hash'), function(val, key) {
264 var name;
265
266 if (val) {
267 name = 'style_' + (counter++);
268
269 ed.formatter.register(name, {
270 inline : 'span',
271 classes : val,
272 selector : '*'
273 });
274
275 ctrl.add(t.editor.translate(key), name);
276 }
277 });
278 }
279 });
280
281 // Auto import classes if the ctrl box is empty
282 if (ctrl.getLength() == 0) {
283 ctrl.onPostRender.add(function(ed, n) {
284 if (!ctrl.NativeListBox) {
285 Event.add(n.id + '_text', 'focus', t._importClasses, t);
286 Event.add(n.id + '_text', 'mousedown', t._importClasses, t);
287 Event.add(n.id + '_open', 'focus', t._importClasses, t);
288 Event.add(n.id + '_open', 'mousedown', t._importClasses, t);
289 } else
290 Event.add(n.id, 'focus', t._importClasses, t);
291 });
292 }
293
294 return ctrl;
295 },
296
297 _createFontSelect : function() {
298 var c, t = this, ed = t.editor;
299
300 c = ed.controlManager.createListBox('fontselect', {
301 title : 'advanced.fontdefault',
302 onselect : function(v) {
303 var cur = c.items[c.selectedIndex];
304
305 if (!v && cur) {
306 ed.execCommand('FontName', false, cur.value);
307 return;
308 }
309
310 ed.execCommand('FontName', false, v);
311
312 // Fake selection, execCommand will fire a nodeChange and update the selection
313 c.select(function(sv) {
314 return v == sv;
315 });
316
317 return false; // No auto select
318 }
319 });
320
321 if (c) {
322 each(ed.getParam('theme_advanced_fonts', t.settings.theme_advanced_fonts, 'hash'), function(v, k) {
323 c.add(ed.translate(k), v, {style : v.indexOf('dings') == -1 ? 'font-family:' + v : ''});
324 });
325 }
326
327 return c;
328 },
329
330 _createFontSizeSelect : function() {
331 var t = this, ed = t.editor, c, i = 0, cl = [];
332
333 c = ed.controlManager.createListBox('fontsizeselect', {title : 'advanced.font_size', onselect : function(v) {
334 var cur = c.items[c.selectedIndex];
335
336 if (!v && cur) {
337 cur = cur.value;
338
339 if (cur['class']) {
340 ed.formatter.toggle('fontsize_class', {value : cur['class']});
341 ed.undoManager.add();
342 ed.nodeChanged();
343 } else {
344 ed.execCommand('FontSize', false, cur.fontSize);
345 }
346
347 return;
348 }
349
350 if (v['class']) {
351 ed.focus();
352 ed.undoManager.add();
353 ed.formatter.toggle('fontsize_class', {value : v['class']});
354 ed.undoManager.add();
355 ed.nodeChanged();
356 } else
357 ed.execCommand('FontSize', false, v.fontSize);
358
359 // Fake selection, execCommand will fire a nodeChange and update the selection
360 c.select(function(sv) {
361 return v == sv;
362 });
363
364 return false; // No auto select
365 }});
366
367 if (c) {
368 each(t.settings.theme_advanced_font_sizes, function(v, k) {
369 var fz = v.fontSize;
370
371 if (fz >= 1 && fz <= 7)
372 fz = t.sizes[parseInt(fz) - 1] + 'pt';
373
374 c.add(k, v, {'style' : 'font-size:' + fz, 'class' : 'mceFontSize' + (i++) + (' ' + (v['class'] || ''))});
375 });
376 }
377
378 return c;
379 },
380
381 _createBlockFormats : function() {
382 var c, fmts = {
383 p : 'advanced.paragraph',
384 address : 'advanced.address',
385 pre : 'advanced.pre',
386 h1 : 'advanced.h1',
387 h2 : 'advanced.h2',
388 h3 : 'advanced.h3',
389 h4 : 'advanced.h4',
390 h5 : 'advanced.h5',
391 h6 : 'advanced.h6',
392 div : 'advanced.div',
393 blockquote : 'advanced.blockquote',
394 code : 'advanced.code',
395 dt : 'advanced.dt',
396 dd : 'advanced.dd',
397 samp : 'advanced.samp'
398 }, t = this;
399
400 c = t.editor.controlManager.createListBox('formatselect', {title : 'advanced.block', cmd : 'FormatBlock'});
401 if (c) {
402 each(t.editor.getParam('theme_advanced_blockformats', t.settings.theme_advanced_blockformats, 'hash'), function(v, k) {
403 c.add(t.editor.translate(k != v ? k : fmts[v]), v, {'class' : 'mce_formatPreview mce_' + v});
404 });
405 }
406
407 return c;
408 },
409
410 _createForeColorMenu : function() {
411 var c, t = this, s = t.settings, o = {}, v;
412
413 if (s.theme_advanced_more_colors) {
414 o.more_colors_func = function() {
415 t._mceColorPicker(0, {
416 color : c.value,
417 func : function(co) {
418 c.setColor(co);
419 }
420 });
421 };
422 }
423
424 if (v = s.theme_advanced_text_colors)
425 o.colors = v;
426
427 if (s.theme_advanced_default_foreground_color)
428 o.default_color = s.theme_advanced_default_foreground_color;
429
430 o.title = 'advanced.forecolor_desc';
431 o.cmd = 'ForeColor';
432 o.scope = this;
433
434 c = t.editor.controlManager.createColorSplitButton('forecolor', o);
435
436 return c;
437 },
438
439 _createBackColorMenu : function() {
440 var c, t = this, s = t.settings, o = {}, v;
441
442 if (s.theme_advanced_more_colors) {
443 o.more_colors_func = function() {
444 t._mceColorPicker(0, {
445 color : c.value,
446 func : function(co) {
447 c.setColor(co);
448 }
449 });
450 };
451 }
452
453 if (v = s.theme_advanced_background_colors)
454 o.colors = v;
455
456 if (s.theme_advanced_default_background_color)
457 o.default_color = s.theme_advanced_default_background_color;
458
459 o.title = 'advanced.backcolor_desc';
460 o.cmd = 'HiliteColor';
461 o.scope = this;
462
463 c = t.editor.controlManager.createColorSplitButton('backcolor', o);
464
465 return c;
466 },
467
468 renderUI : function(o) {
469 var n, ic, tb, t = this, ed = t.editor, s = t.settings, sc, p, nl;
470
471 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) : '')});
472
473 if (!DOM.boxModel)
474 n = DOM.add(n, 'div', {'class' : 'mceOldBoxModel'});
475
476 n = sc = DOM.add(n, 'table', {id : ed.id + '_tbl', 'class' : 'mceLayout', cellSpacing : 0, cellPadding : 0});
477 n = tb = DOM.add(n, 'tbody');
478
479 switch ((s.theme_advanced_layout_manager || '').toLowerCase()) {
480 case "rowlayout":
481 ic = t._rowLayout(s, tb, o);
482 break;
483
484 case "customlayout":
485 ic = ed.execCallback("theme_advanced_custom_layout", s, tb, o, p);
486 break;
487
488 default:
489 ic = t._simpleLayout(s, tb, o, p);
490 }
491
492 n = o.targetNode;
493
494 // Add classes to first and last TRs
495 nl = DOM.stdMode ? sc.getElementsByTagName('tr') : sc.rows; // Quick fix for IE 8
496 DOM.addClass(nl[0], 'mceFirst');
497 DOM.addClass(nl[nl.length - 1], 'mceLast');
498
499 // Add classes to first and last TDs
500 each(DOM.select('tr', tb), function(n) {
501 DOM.addClass(n.firstChild, 'mceFirst');
502 DOM.addClass(n.childNodes[n.childNodes.length - 1], 'mceLast');
503 });
504
505 if (DOM.get(s.theme_advanced_toolbar_container))
506 DOM.get(s.theme_advanced_toolbar_container).appendChild(p);
507 else
508 DOM.insertAfter(p, n);
509
510 Event.add(ed.id + '_path_row', 'click', function(e) {
511 e = e.target;
512
513 if (e.nodeName == 'A') {
514 t._sel(e.className.replace(/^.*mcePath_([0-9]+).*$/, '$1'));
515
516 return Event.cancel(e);
517 }
518 });
519 /*
520 if (DOM.get(ed.id + '_path_row')) {
521 Event.add(ed.id + '_tbl', 'mouseover', function(e) {
522 var re;
523
524 e = e.target;
525
526 if (e.nodeName == 'SPAN' && DOM.hasClass(e.parentNode, 'mceButton')) {
527 re = DOM.get(ed.id + '_path_row');
528 t.lastPath = re.innerHTML;
529 DOM.setHTML(re, e.parentNode.title);
530 }
531 });
532
533 Event.add(ed.id + '_tbl', 'mouseout', function(e) {
534 if (t.lastPath) {
535 DOM.setHTML(ed.id + '_path_row', t.lastPath);
536 t.lastPath = 0;
537 }
538 });
539 }
540 */
541
542 if (!ed.getParam('accessibility_focus'))
543 Event.add(DOM.add(p, 'a', {href : '#'}, '<!-- IE -->'), 'focus', function() {tinyMCE.get(ed.id).focus();});
544
545 if (s.theme_advanced_toolbar_location == 'external')
546 o.deltaHeight = 0;
547
548 t.deltaHeight = o.deltaHeight;
549 o.targetNode = null;
550
551 return {
552 iframeContainer : ic,
553 editorContainer : ed.id + '_parent',
554 sizeContainer : sc,
555 deltaHeight : o.deltaHeight
556 };
557 },
558
559 getInfo : function() {
560 return {
561 longname : 'Advanced theme',
562 author : 'Moxiecode Systems AB',
563 authorurl : 'http://tinymce.moxiecode.com',
564 version : tinymce.majorVersion + "." + tinymce.minorVersion
565 }
566 },
567
568 resizeBy : function(dw, dh) {
569 var e = DOM.get(this.editor.id + '_tbl');
570
571 this.resizeTo(e.clientWidth + dw, e.clientHeight + dh);
572 },
573
574 resizeTo : function(w, h) {
575 var ed = this.editor, s = this.settings, e = DOM.get(ed.id + '_tbl'), ifr = DOM.get(ed.id + '_ifr');
576
577 // Boundery fix box
578 w = Math.max(s.theme_advanced_resizing_min_width || 100, w);
579 h = Math.max(s.theme_advanced_resizing_min_height || 100, h);
580 w = Math.min(s.theme_advanced_resizing_max_width || 0xFFFF, w);
581 h = Math.min(s.theme_advanced_resizing_max_height || 0xFFFF, h);
582
583 // Resize iframe and container
584 DOM.setStyle(e, 'height', '');
585 DOM.setStyle(ifr, 'height', h);
586
587 if (s.theme_advanced_resize_horizontal) {
588 DOM.setStyle(e, 'width', '');
589 DOM.setStyle(ifr, 'width', w);
590
591 // Make sure that the size is never smaller than the over all ui
592 if (w < e.clientWidth)
593 DOM.setStyle(ifr, 'width', e.clientWidth);
594 }
595 },
596
597 destroy : function() {
598 var id = this.editor.id;
599
600 Event.clear(id + '_resize');
601 Event.clear(id + '_path_row');
602 Event.clear(id + '_external_close');
603 },
604
605 // Internal functions
606
607 _simpleLayout : function(s, tb, o, p) {
608 var t = this, ed = t.editor, lo = s.theme_advanced_toolbar_location, sl = s.theme_advanced_statusbar_location, n, ic, etb, c;
609
610 if (s.readonly) {
611 n = DOM.add(tb, 'tr');
612 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
613 return ic;
614 }
615
616 // Create toolbar container at top
617 if (lo == 'top')
618 t._addToolbars(tb, o);
619
620 // Create external toolbar
621 if (lo == 'external') {
622 n = c = DOM.create('div', {style : 'position:relative'});
623 n = DOM.add(n, 'div', {id : ed.id + '_external', 'class' : 'mceExternalToolbar'});
624 DOM.add(n, 'a', {id : ed.id + '_external_close', href : 'javascript:;', 'class' : 'mceExternalClose'});
625 n = DOM.add(n, 'table', {id : ed.id + '_tblext', cellSpacing : 0, cellPadding : 0});
626 etb = DOM.add(n, 'tbody');
627
628 if (p.firstChild.className == 'mceOldBoxModel')
629 p.firstChild.appendChild(c);
630 else
631 p.insertBefore(c, p.firstChild);
632
633 t._addToolbars(etb, o);
634
635 ed.onMouseUp.add(function() {
636 var e = DOM.get(ed.id + '_external');
637 DOM.show(e);
638
639 DOM.hide(lastExtID);
640
641 var f = Event.add(ed.id + '_external_close', 'click', function() {
642 DOM.hide(ed.id + '_external');
643 Event.remove(ed.id + '_external_close', 'click', f);
644 });
645
646 DOM.show(e);
647 DOM.setStyle(e, 'top', 0 - DOM.getRect(ed.id + '_tblext').h - 1);
648
649 // Fixes IE rendering bug
650 DOM.hide(e);
651 DOM.show(e);
652 e.style.filter = '';
653
654 lastExtID = ed.id + '_external';
655
656 e = null;
657 });
658 }
659
660 if (sl == 'top')
661 t._addStatusBar(tb, o);
662
663 // Create iframe container
664 if (!s.theme_advanced_toolbar_container) {
665 n = DOM.add(tb, 'tr');
666 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
667 }
668
669 // Create toolbar container at bottom
670 if (lo == 'bottom')
671 t._addToolbars(tb, o);
672
673 if (sl == 'bottom')
674 t._addStatusBar(tb, o);
675
676 return ic;
677 },
678
679 _rowLayout : function(s, tb, o) {
680 var t = this, ed = t.editor, dc, da, cf = ed.controlManager, n, ic, to, a;
681
682 dc = s.theme_advanced_containers_default_class || '';
683 da = s.theme_advanced_containers_default_align || 'center';
684
685 each(explode(s.theme_advanced_containers || ''), function(c, i) {
686 var v = s['theme_advanced_container_' + c] || '';
687
688 switch (v.toLowerCase()) {
689 case 'mceeditor':
690 n = DOM.add(tb, 'tr');
691 n = ic = DOM.add(n, 'td', {'class' : 'mceIframeContainer'});
692 break;
693
694 case 'mceelementpath':
695 t._addStatusBar(tb, o);
696 break;
697
698 default:
699 a = (s['theme_advanced_container_' + c + '_align'] || da).toLowerCase();
700 a = 'mce' + t._ufirst(a);
701
702 n = DOM.add(DOM.add(tb, 'tr'), 'td', {
703 'class' : 'mceToolbar ' + (s['theme_advanced_container_' + c + '_class'] || dc) + ' ' + a || da
704 });
705
706 to = cf.createToolbar("toolbar" + i);
707 t._addControls(v, to);
708 DOM.setHTML(n, to.renderHTML());
709 o.deltaHeight -= s.theme_advanced_row_height;
710 }
711 });
712
713 return ic;
714 },
715
716 _addControls : function(v, tb) {
717 var t = this, s = t.settings, di, cf = t.editor.controlManager;
718
719 if (s.theme_advanced_disable && !t._disabled) {
720 di = {};
721
722 each(explode(s.theme_advanced_disable), function(v) {
723 di[v] = 1;
724 });
725
726 t._disabled = di;
727 } else
728 di = t._disabled;
729
730 each(explode(v), function(n) {
731 var c;
732
733 if (di && di[n])
734 return;
735
736 // Compatiblity with 2.x
737 if (n == 'tablecontrols') {
738 each(["table","|","row_props","cell_props","|","row_before","row_after","delete_row","|","col_before","col_after","delete_col","|","split_cells","merge_cells"], function(n) {
739 n = t.createControl(n, cf);
740
741 if (n)
742 tb.add(n);
743 });
744
745 return;
746 }
747
748 c = t.createControl(n, cf);
749
750 if (c)
751 tb.add(c);
752 });
753 },
754
755 _addToolbars : function(c, o) {
756 var t = this, i, tb, ed = t.editor, s = t.settings, v, cf = ed.controlManager, di, n, h = [], a;
757
758 a = s.theme_advanced_toolbar_align.toLowerCase();
759 a = 'mce' + t._ufirst(a);
760
761 n = DOM.add(DOM.add(c, 'tr'), 'td', {'class' : 'mceToolbar ' + a});
762
763 if (!ed.getParam('accessibility_focus'))
764 h.push(DOM.createHTML('a', {href : '#', onfocus : 'tinyMCE.get(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));
765
766 h.push(DOM.createHTML('a', {href : '#', accesskey : 'q', title : ed.getLang("advanced.toolbar_focus")}, '<!-- IE -->'));
767
768 // Create toolbar and add the controls
769 for (i=1; (v = s['theme_advanced_buttons' + i]); i++) {
770 tb = cf.createToolbar("toolbar" + i, {'class' : 'mceToolbarRow' + i});
771
772 if (s['theme_advanced_buttons' + i + '_add'])
773 v += ',' + s['theme_advanced_buttons' + i + '_add'];
774
775 if (s['theme_advanced_buttons' + i + '_add_before'])
776 v = s['theme_advanced_buttons' + i + '_add_before'] + ',' + v;
777
778 t._addControls(v, tb);
779
780 //n.appendChild(n = tb.render());
781 h.push(tb.renderHTML());
782
783 o.deltaHeight -= s.theme_advanced_row_height;
784 }
785
786 h.push(DOM.createHTML('a', {href : '#', accesskey : 'z', title : ed.getLang("advanced.toolbar_focus"), onfocus : 'tinyMCE.getInstanceById(\'' + ed.id + '\').focus();'}, '<!-- IE -->'));
787 DOM.setHTML(n, h.join(''));
788 },
789
790 _addStatusBar : function(tb, o) {
791 var n, t = this, ed = t.editor, s = t.settings, r, mf, me, td;
792
793 n = DOM.add(tb, 'tr');
794 n = td = DOM.add(n, 'td', {'class' : 'mceStatusbar'});
795 n = DOM.add(n, 'div', {id : ed.id + '_path_row'}, s.theme_advanced_path ? ed.translate('advanced.path') + ': ' : '&#160;');
796 DOM.add(n, 'a', {href : '#', accesskey : 'x'});
797
798 if (s.theme_advanced_resizing) {
799 DOM.add(td, 'a', {id : ed.id + '_resize', href : 'javascript:;', onclick : "return false;", 'class' : 'mceResize'});
800
801 if (s.theme_advanced_resizing_use_cookie) {
802 ed.onPostRender.add(function() {
803 var o = Cookie.getHash("TinyMCE_" + ed.id + "_size"), c = DOM.get(ed.id + '_tbl');
804
805 if (!o)
806 return;
807
808 t.resizeTo(o.cw, o.ch);
809 });
810 }
811
812 ed.onPostRender.add(function() {
813 Event.add(ed.id + '_resize', 'mousedown', function(e) {
814 var mouseMoveHandler1, mouseMoveHandler2,
815 mouseUpHandler1, mouseUpHandler2,
816 startX, startY, startWidth, startHeight, width, height, ifrElm;
817
818 function resizeOnMove(e) {
819 width = startWidth + (e.screenX - startX);
820 height = startHeight + (e.screenY - startY);
821
822 t.resizeTo(width, height);
823 };
824
825 function endResize(e) {
826 // Stop listening
827 Event.remove(DOM.doc, 'mousemove', mouseMoveHandler1);
828 Event.remove(ed.getDoc(), 'mousemove', mouseMoveHandler2);
829 Event.remove(DOM.doc, 'mouseup', mouseUpHandler1);
830 Event.remove(ed.getDoc(), 'mouseup', mouseUpHandler2);
831
832 // Store away the size
833 if (s.theme_advanced_resizing_use_cookie) {
834 Cookie.setHash("TinyMCE_" + ed.id + "_size", {
835 cw : width,
836 ch : height
837 });
838 }
839 };
840
841 e.preventDefault();
842
843 // Get the current rect size
844 startX = e.screenX;
845 startY = e.screenY;
846 ifrElm = DOM.get(t.editor.id + '_ifr');
847 startWidth = width = ifrElm.clientWidth;
848 startHeight = height = ifrElm.clientHeight;
849
850 // Register envent handlers
851 mouseMoveHandler1 = Event.add(DOM.doc, 'mousemove', resizeOnMove);
852 mouseMoveHandler2 = Event.add(ed.getDoc(), 'mousemove', resizeOnMove);
853 mouseUpHandler1 = Event.add(DOM.doc, 'mouseup', endResize);
854 mouseUpHandler2 = Event.add(ed.getDoc(), 'mouseup', endResize);
855 });
856 });
857 }
858
859 o.deltaHeight -= 21;
860 n = tb = null;
861 },
862
863 _nodeChanged : function(ed, cm, n, co, ob) {
864 var t = this, p, de = 0, v, c, s = t.settings, cl, fz, fn, formatNames, matches;
865
866 tinymce.each(t.stateControls, function(c) {
867 cm.setActive(c, ed.queryCommandState(t.controls[c][1]));
868 });
869
870 function getParent(name) {
871 var i, parents = ob.parents, func = name;
872
873 if (typeof(name) == 'string') {
874 func = function(node) {
875 return node.nodeName == name;
876 };
877 }
878
879 for (i = 0; i < parents.length; i++) {
880 if (func(parents[i]))
881 return parents[i];
882 }
883 };
884
885 cm.setActive('visualaid', ed.hasVisual);
886 cm.setDisabled('undo', !ed.undoManager.hasUndo() && !ed.typing);
887 cm.setDisabled('redo', !ed.undoManager.hasRedo());
888 cm.setDisabled('outdent', !ed.queryCommandState('Outdent'));
889
890 p = getParent('A');
891 if (c = cm.get('link')) {
892 if (!p || !p.name) {
893 c.setDisabled(!p && co);
894 c.setActive(!!p);
895 }
896 }
897
898 if (c = cm.get('unlink')) {
899 c.setDisabled(!p && co);
900 c.setActive(!!p && !p.name);
901 }
902
903 if (c = cm.get('anchor')) {
904 c.setActive(!!p && p.name);
905 }
906
907 p = getParent('IMG');
908 if (c = cm.get('image'))
909 c.setActive(!!p && n.className.indexOf('mceItem') == -1);
910
911 if (c = cm.get('styleselect')) {
912 t._importClasses();
913
914 formatNames = [];
915 each(c.items, function(item) {
916 formatNames.push(item.value);
917 });
918
919 matches = ed.formatter.matchAll(formatNames);
920 c.select(matches[0]);
921 }
922
923 if (c = cm.get('formatselect')) {
924 p = getParent(DOM.isBlock);
925
926 if (p)
927 c.select(p.nodeName.toLowerCase());
928 }
929
930 // Find out current fontSize, fontFamily and fontClass
931 getParent(function(n) {
932 if (n.nodeName === 'SPAN') {
933 if (!cl && n.className)
934 cl = n.className;
935
936 if (!fz && n.style.fontSize)
937 fz = n.style.fontSize;
938
939 if (!fn && n.style.fontFamily)
940 fn = n.style.fontFamily.replace(/[\"\']+/g, '').replace(/^([^,]+).*/, '$1').toLowerCase();
941 }
942
943 return false;
944 });
945
946 if (c = cm.get('fontselect')) {
947 c.select(function(v) {
948 return v.replace(/^([^,]+).*/, '$1').toLowerCase() == fn;
949 });
950 }
951
952 // Select font size
953 if (c = cm.get('fontsizeselect')) {
954 // Use computed style
955 if (s.theme_advanced_runtime_fontsize && !fz && !cl)
956 fz = ed.dom.getStyle(n, 'fontSize', true);
957
958 c.select(function(v) {
959 if (v.fontSize && v.fontSize === fz)
960 return true;
961
962 if (v['class'] && v['class'] === cl)
963 return true;
964 });
965 }
966
967 if (s.theme_advanced_path && s.theme_advanced_statusbar_location) {
968 p = DOM.get(ed.id + '_path') || DOM.add(ed.id + '_path_row', 'span', {id : ed.id + '_path'});
969 DOM.setHTML(p, '');
970
971 getParent(function(n) {
972 var na = n.nodeName.toLowerCase(), u, pi, ti = '';
973
974 /*if (n.getAttribute('_mce_bogus'))
975 return;
976 */
977 // Ignore non element and hidden elements
978 if (n.nodeType != 1 || n.nodeName === 'BR' || (DOM.hasClass(n, 'mceItemHidden') || DOM.hasClass(n, 'mceItemRemoved')))
979 return;
980
981 // Fake name
982 if (v = DOM.getAttrib(n, 'mce_name'))
983 na = v;
984
985 // Handle prefix
986 if (tinymce.isIE && n.scopeName !== 'HTML')
987 na = n.scopeName + ':' + na;
988
989 // Remove internal prefix
990 na = na.replace(/mce\:/g, '');
991
992 // Handle node name
993 switch (na) {
994 case 'b':
995 na = 'strong';
996 break;
997
998 case 'i':
999 na = 'em';
1000 break;
1001
1002 case 'img':
1003 if (v = DOM.getAttrib(n, 'src'))
1004 ti += 'src: ' + v + ' ';
1005
1006 break;
1007
1008 case 'a':
1009 if (v = DOM.getAttrib(n, 'name')) {
1010 ti += 'name: ' + v + ' ';
1011 na += '#' + v;
1012 }
1013
1014 if (v = DOM.getAttrib(n, 'href'))
1015 ti += 'href: ' + v + ' ';
1016
1017 break;
1018
1019 case 'font':
1020 if (v = DOM.getAttrib(n, 'face'))
1021 ti += 'font: ' + v + ' ';
1022
1023 if (v = DOM.getAttrib(n, 'size'))
1024 ti += 'size: ' + v + ' ';
1025
1026 if (v = DOM.getAttrib(n, 'color'))
1027 ti += 'color: ' + v + ' ';
1028
1029 break;
1030
1031 case 'span':
1032 if (v = DOM.getAttrib(n, 'style'))
1033 ti += 'style: ' + v + ' ';
1034
1035 break;
1036 }
1037
1038 if (v = DOM.getAttrib(n, 'id'))
1039 ti += 'id: ' + v + ' ';
1040
1041 if (v = n.className) {
1042 v = v.replace(/\b\s*(webkit|mce|Apple-)\w+\s*\b/g, '')
1043
1044 if (v) {
1045 ti += 'class: ' + v + ' ';
1046
1047 if (DOM.isBlock(n) || na == 'img' || na == 'span')
1048 na += '.' + v;
1049 }
1050 }
1051
1052 na = na.replace(/(html:)/g, '');
1053 na = {name : na, node : n, title : ti};
1054 t.onResolveName.dispatch(t, na);
1055 ti = na.title;
1056 na = na.name;
1057
1058 //u = "javascript:tinymce.EditorManager.get('" + ed.id + "').theme._sel('" + (de++) + "');";
1059 pi = DOM.create('a', {'href' : "javascript:;", onmousedown : "return false;", title : ti, 'class' : 'mcePath_' + (de++)}, na);
1060
1061 if (p.hasChildNodes()) {
1062 p.insertBefore(DOM.doc.createTextNode(' \u00bb '), p.firstChild);
1063 p.insertBefore(pi, p.firstChild);
1064 } else
1065 p.appendChild(pi);
1066 }, ed.getBody());
1067 }
1068 },
1069
1070 // Commands gets called by execCommand
1071
1072 _sel : function(v) {
1073 this.editor.execCommand('mceSelectNodeDepth', false, v);
1074 },
1075
1076 _mceInsertAnchor : function(ui, v) {
1077 var ed = this.editor;
1078
1079 ed.windowManager.open({
1080 url : this.url + '/anchor.htm',
1081 width : 320 + parseInt(ed.getLang('advanced.anchor_delta_width', 0)),
1082 height : 90 + parseInt(ed.getLang('advanced.anchor_delta_height', 0)),
1083 inline : true
1084 }, {
1085 theme_url : this.url
1086 });
1087 },
1088
1089 _mceCharMap : function() {
1090 var ed = this.editor;
1091
1092 ed.windowManager.open({
1093 url : this.url + '/charmap.htm',
1094 width : 550 + parseInt(ed.getLang('advanced.charmap_delta_width', 0)),
1095 height : 250 + parseInt(ed.getLang('advanced.charmap_delta_height', 0)),
1096 inline : true
1097 }, {
1098 theme_url : this.url
1099 });
1100 },
1101
1102 _mceHelp : function() {
1103 var ed = this.editor;
1104
1105 ed.windowManager.open({
1106 url : this.url + '/about.htm',
1107 width : 480,
1108 height : 380,
1109 inline : true
1110 }, {
1111 theme_url : this.url
1112 });
1113 },
1114
1115 _mceColorPicker : function(u, v) {
1116 var ed = this.editor;
1117
1118 v = v || {};
1119
1120 ed.windowManager.open({
1121 url : this.url + '/color_picker.htm',
1122 width : 375 + parseInt(ed.getLang('advanced.colorpicker_delta_width', 0)),
1123 height : 250 + parseInt(ed.getLang('advanced.colorpicker_delta_height', 0)),
1124 close_previous : false,
1125 inline : true
1126 }, {
1127 input_color : v.color,
1128 func : v.func,
1129 theme_url : this.url
1130 });
1131 },
1132
1133 _mceCodeEditor : function(ui, val) {
1134 var ed = this.editor;
1135
1136 ed.windowManager.open({
1137 url : this.url + '/source_editor.htm',
1138 width : parseInt(ed.getParam("theme_advanced_source_editor_width", 720)),
1139 height : parseInt(ed.getParam("theme_advanced_source_editor_height", 580)),
1140 inline : true,
1141 resizable : true,
1142 maximizable : true
1143 }, {
1144 theme_url : this.url
1145 });
1146 },
1147
1148 _mceImage : function(ui, val) {
1149 var ed = this.editor;
1150
1151 // Internal image object like a flash placeholder
1152 if (ed.dom.getAttrib(ed.selection.getNode(), 'class').indexOf('mceItem') != -1)
1153 return;
1154
1155 ed.windowManager.open({
1156 url : this.url + '/image.htm',
1157 width : 355 + parseInt(ed.getLang('advanced.image_delta_width', 0)),
1158 height : 275 + parseInt(ed.getLang('advanced.image_delta_height', 0)),
1159 inline : true
1160 }, {
1161 theme_url : this.url
1162 });
1163 },
1164
1165 _mceLink : function(ui, val) {
1166 var ed = this.editor;
1167
1168 ed.windowManager.open({
1169 url : this.url + '/link.htm',
1170 width : 310 + parseInt(ed.getLang('advanced.link_delta_width', 0)),
1171 height : 200 + parseInt(ed.getLang('advanced.link_delta_height', 0)),
1172 inline : true
1173 }, {
1174 theme_url : this.url
1175 });
1176 },
1177
1178 _mceNewDocument : function() {
1179 var ed = this.editor;
1180
1181 ed.windowManager.confirm('advanced.newdocument', function(s) {
1182 if (s)
1183 ed.execCommand('mceSetContent', false, '');
1184 });
1185 },
1186
1187 _mceForeColor : function() {
1188 var t = this;
1189
1190 this._mceColorPicker(0, {
1191 color: t.fgColor,
1192 func : function(co) {
1193 t.fgColor = co;
1194 t.editor.execCommand('ForeColor', false, co);
1195 }
1196 });
1197 },
1198
1199 _mceBackColor : function() {
1200 var t = this;
1201
1202 this._mceColorPicker(0, {
1203 color: t.bgColor,
1204 func : function(co) {
1205 t.bgColor = co;
1206 t.editor.execCommand('HiliteColor', false, co);
1207 }
1208 });
1209 },
1210
1211 _ufirst : function(s) {
1212 return s.substring(0, 1).toUpperCase() + s.substring(1);
1213 }
1214 });
1215
1216 tinymce.ThemeManager.add('advanced', tinymce.themes.AdvancedTheme);
1217 }(tinymce));