annotate static/js/tiny_mce/themes/advanced/editor_template_src.js @ 939:3782fa705821

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