annotate media/js/tiny_mce/themes/advanced/editor_template_src.js @ 294:254db4cb6a86

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