annotate static/js/tiny_mce/themes/advanced/editor_template_src.js @ 412:639cfdf59167

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