2 /* file:jscripts/tiny_mce/classes/TinyMCE_Engine.class.js */
4 function TinyMCE_Engine() {
7 this.majorVersion = "2";
8 this.minorVersion = "1.1.1";
9 this.releaseDate = "2007-05-14";
12 this.switchClassCache = [];
14 this.loadedFiles = [];
15 this.pendingFiles = [];
16 this.loadingIndex = 0;
18 this.currentConfig = 0;
19 this.eventHandlers = [];
23 this.typingUndoIndex = -1;
27 ua = navigator.userAgent;
28 this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
29 this.isMSIE5 = this.isMSIE && (ua.indexOf('MSIE 5') != -1);
30 this.isMSIE5_0 = this.isMSIE && (ua.indexOf('MSIE 5.0') != -1);
31 this.isMSIE7 = this.isMSIE && (ua.indexOf('MSIE 7') != -1);
32 this.isGecko = ua.indexOf('Gecko') != -1; // Will also be true on Safari
33 this.isSafari = ua.indexOf('Safari') != -1;
34 this.isOpera = window['opera'] && opera.buildNumber ? true : false;
35 this.isMac = ua.indexOf('Mac') != -1;
36 this.isNS7 = ua.indexOf('Netscape/7') != -1;
37 this.isNS71 = ua.indexOf('Netscape/7.1') != -1;
38 this.dialogCounter = 0;
42 this.loadedPlugins = [];
44 this.isLoaded = false;
46 // Fake MSIE on Opera and if Opera fakes IE, Gecko or Safari cancel those
50 this.isSafari = false;
53 this.isIE = this.isMSIE;
54 this.isRealIE = this.isMSIE && !this.isOpera;
56 // TinyMCE editor id instance counter
60 TinyMCE_Engine.prototype = {
61 init : function(settings) {
62 var theme, nl, baseHREF = "", i, cssPath, entities, h, p, src, elements = [], head;
64 // IE 5.0x is no longer supported since 5.5, 6.0 and 7.0 now exists. We can't support old browsers forever, sorry.
68 this.settings = settings;
70 // Check if valid browser has execcommand support
71 if (typeof(document.execCommand) == 'undefined')
74 // Get script base path
75 if (!tinyMCE.baseURL) {
76 // Search through head
77 head = document.getElementsByTagName('head')[0];
80 for (i=0, nl = head.getElementsByTagName('script'); i<nl.length; i++)
84 // Search through rest of document
85 for (i=0, nl = document.getElementsByTagName('script'); i<nl.length; i++)
88 // If base element found, add that infront of baseURL
89 nl = document.getElementsByTagName('base');
90 for (i=0; i<nl.length; i++) {
92 baseHREF = nl[i].href;
95 for (i=0; i<elements.length; i++) {
96 if (elements[i].src && (elements[i].src.indexOf("tiny_mce.js") != -1 || elements[i].src.indexOf("tiny_mce_dev.js") != -1 || elements[i].src.indexOf("tiny_mce_src.js") != -1 || elements[i].src.indexOf("tiny_mce_gzip") != -1)) {
97 src = elements[i].src;
99 tinyMCE.srcMode = (src.indexOf('_src') != -1 || src.indexOf('_dev') != -1) ? '_src' : '';
100 tinyMCE.gzipMode = src.indexOf('_gzip') != -1;
101 src = src.substring(0, src.lastIndexOf('/'));
103 if (settings.exec_mode == "src" || settings.exec_mode == "normal")
104 tinyMCE.srcMode = settings.exec_mode == "src" ? '_src' : '';
106 // Force it absolute if page has a base href
107 if (baseHREF !== '' && src.indexOf('://') == -1)
108 tinyMCE.baseURL = baseHREF + src;
110 tinyMCE.baseURL = src;
117 // Get document base path
118 this.documentBasePath = document.location.href;
119 if (this.documentBasePath.indexOf('?') != -1)
120 this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.indexOf('?'));
121 this.documentURL = this.documentBasePath;
122 this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.lastIndexOf('/'));
124 // If not HTTP absolute
125 if (tinyMCE.baseURL.indexOf('://') == -1 && tinyMCE.baseURL.charAt(0) != '/') {
127 tinyMCE.baseURL = this.documentBasePath + "/" + tinyMCE.baseURL;
130 // Set default values on settings
131 this._def("mode", "none");
132 this._def("theme", "advanced");
133 this._def("plugins", "", true);
134 this._def("language", "en");
135 this._def("docs_language", this.settings.language);
136 this._def("elements", "");
137 this._def("textarea_trigger", "mce_editable");
138 this._def("editor_selector", "");
139 this._def("editor_deselector", "mceNoEditor");
140 this._def("valid_elements", "+a[id|style|rel|rev|charset|hreflang|dir|lang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],-strong/-b[class|style],-em/-i[class|style],-strike[class|style],-u[class|style],#p[id|style|dir|class|align],-ol[class|style],-ul[class|style],-li[class|style],br,img[id|dir|lang|longdesc|usemap|style|class|src|onmouseover|onmouseout|border|alt=|title|hspace|vspace|width|height|align],-sub[style|class],-sup[style|class],-blockquote[dir|style],-table[border=0|cellspacing|cellpadding|width|height|class|align|summary|style|dir|id|lang|bgcolor|background|bordercolor],-tr[id|lang|dir|class|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor],tbody[id|class],thead[id|class],tfoot[id|class],#td[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|bgcolor|background|bordercolor|scope],-th[id|lang|dir|class|colspan|rowspan|width|height|align|valign|style|scope],caption[id|lang|dir|class|style],-div[id|dir|class|align|style],-span[style|class|align],-pre[class|align|style],address[class|align|style],-h1[id|style|dir|class|align],-h2[id|style|dir|class|align],-h3[id|style|dir|class|align],-h4[id|style|dir|class|align],-h5[id|style|dir|class|align],-h6[id|style|dir|class|align],hr[class|style],-font[face|size|style|id|class|dir|color],dd[id|class|title|style|dir|lang],dl[id|class|title|style|dir|lang],dt[id|class|title|style|dir|lang],cite[title|id|class|style|dir|lang],abbr[title|id|class|style|dir|lang],acronym[title|id|class|style|dir|lang],del[title|id|class|style|dir|lang|datetime|cite],ins[title|id|class|style|dir|lang|datetime|cite]");
141 this._def("extended_valid_elements", "");
142 this._def("invalid_elements", "");
143 this._def("encoding", "");
144 this._def("urlconverter_callback", tinyMCE.getParam("urlconvertor_callback", "TinyMCE_Engine.prototype.convertURL"));
145 this._def("save_callback", "");
146 this._def("force_br_newlines", false);
147 this._def("force_p_newlines", true);
148 this._def("add_form_submit_trigger", true);
149 this._def("relative_urls", true);
150 this._def("remove_script_host", true);
151 this._def("focus_alert", true);
152 this._def("document_base_url", this.documentURL);
153 this._def("visual", true);
154 this._def("visual_table_class", "mceVisualAid");
155 this._def("setupcontent_callback", "");
156 this._def("fix_content_duplication", true);
157 this._def("custom_undo_redo", true);
158 this._def("custom_undo_redo_levels", -1);
159 this._def("custom_undo_redo_keyboard_shortcuts", true);
160 this._def("custom_undo_redo_restore_selection", true);
161 this._def("custom_undo_redo_global", false);
162 this._def("verify_html", true);
163 this._def("apply_source_formatting", false);
164 this._def("directionality", "ltr");
165 this._def("cleanup_on_startup", false);
166 this._def("inline_styles", false);
167 this._def("convert_newlines_to_brs", false);
168 this._def("auto_reset_designmode", true);
169 this._def("entities", "39,#39,160,nbsp,161,iexcl,162,cent,163,pound,164,curren,165,yen,166,brvbar,167,sect,168,uml,169,copy,170,ordf,171,laquo,172,not,173,shy,174,reg,175,macr,176,deg,177,plusmn,178,sup2,179,sup3,180,acute,181,micro,182,para,183,middot,184,cedil,185,sup1,186,ordm,187,raquo,188,frac14,189,frac12,190,frac34,191,iquest,192,Agrave,193,Aacute,194,Acirc,195,Atilde,196,Auml,197,Aring,198,AElig,199,Ccedil,200,Egrave,201,Eacute,202,Ecirc,203,Euml,204,Igrave,205,Iacute,206,Icirc,207,Iuml,208,ETH,209,Ntilde,210,Ograve,211,Oacute,212,Ocirc,213,Otilde,214,Ouml,215,times,216,Oslash,217,Ugrave,218,Uacute,219,Ucirc,220,Uuml,221,Yacute,222,THORN,223,szlig,224,agrave,225,aacute,226,acirc,227,atilde,228,auml,229,aring,230,aelig,231,ccedil,232,egrave,233,eacute,234,ecirc,235,euml,236,igrave,237,iacute,238,icirc,239,iuml,240,eth,241,ntilde,242,ograve,243,oacute,244,ocirc,245,otilde,246,ouml,247,divide,248,oslash,249,ugrave,250,uacute,251,ucirc,252,uuml,253,yacute,254,thorn,255,yuml,402,fnof,913,Alpha,914,Beta,915,Gamma,916,Delta,917,Epsilon,918,Zeta,919,Eta,920,Theta,921,Iota,922,Kappa,923,Lambda,924,Mu,925,Nu,926,Xi,927,Omicron,928,Pi,929,Rho,931,Sigma,932,Tau,933,Upsilon,934,Phi,935,Chi,936,Psi,937,Omega,945,alpha,946,beta,947,gamma,948,delta,949,epsilon,950,zeta,951,eta,952,theta,953,iota,954,kappa,955,lambda,956,mu,957,nu,958,xi,959,omicron,960,pi,961,rho,962,sigmaf,963,sigma,964,tau,965,upsilon,966,phi,967,chi,968,psi,969,omega,977,thetasym,978,upsih,982,piv,8226,bull,8230,hellip,8242,prime,8243,Prime,8254,oline,8260,frasl,8472,weierp,8465,image,8476,real,8482,trade,8501,alefsym,8592,larr,8593,uarr,8594,rarr,8595,darr,8596,harr,8629,crarr,8656,lArr,8657,uArr,8658,rArr,8659,dArr,8660,hArr,8704,forall,8706,part,8707,exist,8709,empty,8711,nabla,8712,isin,8713,notin,8715,ni,8719,prod,8721,sum,8722,minus,8727,lowast,8730,radic,8733,prop,8734,infin,8736,ang,8743,and,8744,or,8745,cap,8746,cup,8747,int,8756,there4,8764,sim,8773,cong,8776,asymp,8800,ne,8801,equiv,8804,le,8805,ge,8834,sub,8835,sup,8836,nsub,8838,sube,8839,supe,8853,oplus,8855,otimes,8869,perp,8901,sdot,8968,lceil,8969,rceil,8970,lfloor,8971,rfloor,9001,lang,9002,rang,9674,loz,9824,spades,9827,clubs,9829,hearts,9830,diams,34,quot,38,amp,60,lt,62,gt,338,OElig,339,oelig,352,Scaron,353,scaron,376,Yuml,710,circ,732,tilde,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm,8211,ndash,8212,mdash,8216,lsquo,8217,rsquo,8218,sbquo,8220,ldquo,8221,rdquo,8222,bdquo,8224,dagger,8225,Dagger,8240,permil,8249,lsaquo,8250,rsaquo,8364,euro", true);
170 this._def("entity_encoding", "named");
171 this._def("cleanup_callback", "");
172 this._def("add_unload_trigger", true);
173 this._def("ask", false);
174 this._def("nowrap", false);
175 this._def("auto_resize", false);
176 this._def("auto_focus", false);
177 this._def("cleanup", true);
178 this._def("remove_linebreaks", true);
179 this._def("button_tile_map", false);
180 this._def("submit_patch", true);
181 this._def("browsers", "msie,safari,gecko,opera", true);
182 this._def("dialog_type", "window");
183 this._def("accessibility_warnings", true);
184 this._def("accessibility_focus", true);
185 this._def("merge_styles_invalid_parents", "");
186 this._def("force_hex_style_colors", true);
187 this._def("trim_span_elements", true);
188 this._def("convert_fonts_to_spans", false);
189 this._def("doctype", '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');
190 this._def("font_size_classes", '');
191 this._def("font_size_style_values", 'xx-small,x-small,small,medium,large,x-large,xx-large', true);
192 this._def("event_elements", 'a,img', true);
193 this._def("convert_urls", true);
194 this._def("table_inline_editing", false);
195 this._def("object_resizing", true);
196 this._def("custom_shortcuts", true);
197 this._def("convert_on_click", false);
198 this._def("content_css", '');
199 this._def("fix_list_elements", true);
200 this._def("fix_table_elements", false);
201 this._def("strict_loading_mode", document.contentType == 'application/xhtml+xml');
202 this._def("hidden_tab_class", '');
203 this._def("display_tab_class", '');
204 this._def("gecko_spellcheck", false);
205 this._def("hide_selects_on_submit", true);
206 this._def("forced_root_block", false);
207 this._def("remove_trailing_nbsp", false);
209 // Force strict loading mode to false on non Gecko browsers
210 if (this.isMSIE && !this.isOpera)
211 this.settings.strict_loading_mode = false;
214 if (this.isMSIE && this.settings.browsers.indexOf('msie') == -1)
217 // Browser check Gecko
218 if (this.isGecko && this.settings.browsers.indexOf('gecko') == -1)
221 // Browser check Safari
222 if (this.isSafari && this.settings.browsers.indexOf('safari') == -1)
225 // Browser check Opera
226 if (this.isOpera && this.settings.browsers.indexOf('opera') == -1)
229 // If not super absolute make it so
230 baseHREF = tinyMCE.settings.document_base_url;
231 h = document.location.href;
232 p = h.indexOf('://');
233 if (p > 0 && document.location.protocol != "file:") {
234 p = h.indexOf('/', p + 3);
235 h = h.substring(0, p);
237 if (baseHREF.indexOf('://') == -1)
238 baseHREF = h + baseHREF;
240 tinyMCE.settings.document_base_url = baseHREF;
241 tinyMCE.settings.document_base_prefix = h;
244 // Trim away query part
245 if (baseHREF.indexOf('?') != -1)
246 baseHREF = baseHREF.substring(0, baseHREF.indexOf('?'));
248 this.settings.base_href = baseHREF.substring(0, baseHREF.lastIndexOf('/')) + "/";
250 theme = this.settings.theme;
251 this.inlineStrict = 'A|BR|SPAN|BDO|MAP|OBJECT|IMG|TT|I|B|BIG|SMALL|EM|STRONG|DFN|CODE|Q|SAMP|KBD|VAR|CITE|ABBR|ACRONYM|SUB|SUP|#text|#comment';
252 this.inlineTransitional = 'A|BR|SPAN|BDO|OBJECT|APPLET|IMG|MAP|IFRAME|TT|I|B|U|S|STRIKE|BIG|SMALL|FONT|BASEFONT|EM|STRONG|DFN|CODE|Q|SAMP|KBD|VAR|CITE|ABBR|ACRONYM|SUB|SUP|INPUT|SELECT|TEXTAREA|LABEL|BUTTON|#text|#comment';
253 this.blockElms = 'H[1-6]|P|DIV|ADDRESS|PRE|FORM|TABLE|LI|OL|UL|TD|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|FORM|NOSCRIPT|NOFRAMES|MENU|ISINDEX|SAMP';
254 this.blockRegExp = new RegExp("^(" + this.blockElms + ")$", "i");
255 this.posKeyCodes = [13,45,36,35,33,34,37,38,39,40];
256 this.uniqueURL = 'javascript:void(091039730);'; // Make unique URL non real URL
257 this.uniqueTag = '<div id="mceTMPElement" style="display: none">TMP</div>';
258 this.callbacks = ['onInit', 'getInfo', 'getEditorTemplate', 'setupContent', 'onChange', 'onPageLoad', 'handleNodeChange', 'initInstance', 'execCommand', 'getControlHTML', 'handleEvent', 'cleanup', 'removeInstance'];
261 this.settings.theme_href = tinyMCE.baseURL + "/themes/" + theme;
263 if (!tinyMCE.isIE || tinyMCE.isOpera)
264 this.settings.force_br_newlines = false;
266 if (tinyMCE.getParam("popups_css", false)) {
267 cssPath = tinyMCE.getParam("popups_css", "");
270 if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
271 this.settings.popups_css = this.documentBasePath + "/" + cssPath;
273 this.settings.popups_css = cssPath;
275 this.settings.popups_css = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_popup.css";
277 if (tinyMCE.getParam("editor_css", false)) {
278 cssPath = tinyMCE.getParam("editor_css", "");
281 if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
282 this.settings.editor_css = this.documentBasePath + "/" + cssPath;
284 this.settings.editor_css = cssPath;
286 if (this.settings.editor_css !== '')
287 this.settings.editor_css = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css";
291 if (this.configs.length == 0) {
292 if (typeof(TinyMCECompressed) == "undefined") {
293 tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCE_Engine.prototype.onLoad);
295 if (tinyMCE.isRealIE) {
297 tinyMCE.addEvent(document.body, "readystatechange", TinyMCE_Engine.prototype.onLoad);
299 tinyMCE.addEvent(document, "readystatechange", TinyMCE_Engine.prototype.onLoad);
302 tinyMCE.addEvent(window, "load", TinyMCE_Engine.prototype.onLoad);
303 tinyMCE._addUnloadEvents();
307 this.loadScript(tinyMCE.baseURL + '/themes/' + this.settings.theme + '/editor_template' + tinyMCE.srcMode + '.js');
308 this.loadScript(tinyMCE.baseURL + '/langs/' + this.settings.language + '.js');
309 this.loadCSS(this.settings.editor_css);
312 p = tinyMCE.getParam('plugins', '', true, ',');
314 for (i=0; i<p.length; i++) {
315 if (p[i].charAt(0) != '-')
316 this.loadScript(tinyMCE.baseURL + '/plugins/' + p[i] + '/editor_plugin' + tinyMCE.srcMode + '.js');
321 if (tinyMCE.getParam('entity_encoding') == 'named') {
322 settings.cleanup_entities = [];
323 entities = tinyMCE.getParam('entities', '', true, ',');
324 for (i=0; i<entities.length; i+=2)
325 settings.cleanup_entities['c' + entities[i]] = entities[i+1];
328 // Save away this config
329 settings.index = this.configs.length;
330 this.configs[this.configs.length] = settings;
332 // Start loading first one in chain
333 this.loadNextScript();
335 // Force flicker free CSS backgrounds in IE
336 if (this.isIE && !this.isOpera) {
338 document.execCommand('BackgroundImageCache', false, true);
344 // Setup XML encoding regexps
345 this.xmlEncodeRe = new RegExp('[<>&"]', 'g');
348 _addUnloadEvents : function() {
349 var st = tinyMCE.settings.add_unload_trigger;
353 tinyMCE.addEvent(window, "unload", TinyMCE_Engine.prototype.unloadHandler);
354 tinyMCE.addEvent(window.document, "beforeunload", TinyMCE_Engine.prototype.unloadHandler);
358 tinyMCE.addEvent(window, "unload", function () {tinyMCE.triggerSave(true, true);});
362 _def : function(key, def_val, t) {
363 var v = tinyMCE.getParam(key, def_val);
365 v = t ? v.replace(/\s+/g, "") : v;
367 this.settings[key] = v;
370 hasPlugin : function(n) {
371 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;
374 addPlugin : function(n, p) {
375 var op = this.plugins[n];
377 // Use the previous plugin object base URL used when loading external plugins
378 p.baseURL = op ? op.baseURL : tinyMCE.baseURL + "/plugins/" + n;
381 this.loadNextScript();
384 setPluginBaseURL : function(n, u) {
385 var op = this.plugins[n];
390 this.plugins[n] = {baseURL : u};
393 loadPlugin : function(n, u) {
394 u = u.indexOf('.js') != -1 ? u.substring(0, u.lastIndexOf('/')) : u;
395 u = u.charAt(u.length-1) == '/' ? u.substring(0, u.length-1) : u;
396 this.plugins[n] = {baseURL : u};
397 this.loadScript(u + "/editor_plugin" + (tinyMCE.srcMode ? '_src' : '') + ".js");
400 hasTheme : function(n) {
401 return typeof(this.themes[n]) != "undefined" && this.themes[n] != null;
404 addTheme : function(n, t) {
407 this.loadNextScript();
410 addMenu : function(n, m) {
414 hasMenu : function(n) {
415 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;
418 loadScript : function(url) {
421 for (i=0; i<this.loadedFiles.length; i++) {
422 if (this.loadedFiles[i] == url)
426 if (tinyMCE.settings.strict_loading_mode)
427 this.pendingFiles[this.pendingFiles.length] = url;
429 document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></script>');
431 this.loadedFiles[this.loadedFiles.length] = url;
434 loadNextScript : function() {
435 var d = document, se;
437 if (!tinyMCE.settings.strict_loading_mode)
440 if (this.loadingIndex < this.pendingFiles.length) {
441 se = d.createElementNS('http://www.w3.org/1999/xhtml', 'script');
442 se.setAttribute('language', 'javascript');
443 se.setAttribute('type', 'text/javascript');
444 se.setAttribute('src', this.pendingFiles[this.loadingIndex++]);
446 d.getElementsByTagName("head")[0].appendChild(se);
448 this.loadingIndex = -1; // Done with loading
451 loadCSS : function(url) {
452 var ar = url.replace(/\s+/, '').split(',');
453 var lflen = 0, csslen = 0, skip = false;
454 var x = 0, i = 0, nl, le;
456 for (x = 0,csslen = ar.length; x<csslen; x++) {
457 if (ar[x] != null && ar[x] != 'null' && ar[x].length > 0) {
458 /* Make sure it doesn't exist. */
459 for (i=0, lflen=this.loadedFiles.length; i<lflen; i++) {
460 if (this.loadedFiles[i] == ar[x]) {
467 if (tinyMCE.settings.strict_loading_mode) {
468 nl = document.getElementsByTagName("head");
470 le = document.createElement('link');
471 le.setAttribute('href', ar[x]);
472 le.setAttribute('rel', 'stylesheet');
473 le.setAttribute('type', 'text/css');
475 nl[0].appendChild(le);
477 document.write('<link href="' + ar[x] + '" rel="stylesheet" type="text/css" />');
479 this.loadedFiles[this.loadedFiles.length] = ar[x];
485 importCSS : function(doc, css) {
486 var css_ary = css.replace(/\s+/, '').split(',');
487 var csslen, elm, headArr, x, css_file;
489 for (x = 0, csslen = css_ary.length; x<csslen; x++) {
490 css_file = css_ary[x];
492 if (css_file != null && css_file != 'null' && css_file.length > 0) {
493 // Is relative, make absolute
494 if (css_file.indexOf('://') == -1 && css_file.charAt(0) != '/')
495 css_file = this.documentBasePath + "/" + css_file;
497 if (typeof(doc.createStyleSheet) == "undefined") {
498 elm = doc.createElement("link");
500 elm.rel = "stylesheet";
503 if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0)
504 headArr[0].appendChild(elm);
506 doc.createStyleSheet(css_file);
511 confirmAdd : function(e, settings) {
512 var elm = tinyMCE.isIE ? event.srcElement : e.target;
513 var elementId = elm.name ? elm.name : elm.id;
515 tinyMCE.settings = settings;
517 if (tinyMCE.settings.convert_on_click || (!elm.getAttribute('mce_noask') && confirm(tinyMCELang.lang_edit_confirm)))
518 tinyMCE.addMCEControl(elm, elementId);
520 elm.setAttribute('mce_noask', 'true');
523 updateContent : function(form_element_name) {
524 var formElement, n, inst, doc;
526 // Find MCE instance linked to given form element and copy it's value
527 formElement = document.getElementById(form_element_name);
528 for (n in tinyMCE.instances) {
529 inst = tinyMCE.instances[n];
531 if (!tinyMCE.isInstance(inst))
534 inst.switchSettings();
536 if (inst.formElement == formElement) {
539 tinyMCE._setHTML(doc, inst.formElement.value);
542 doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid);
547 addMCEControl : function(replace_element, form_element_name, target_document) {
548 var id = "mce_editor_" + tinyMCE.idCounter++;
549 var inst = new TinyMCE_Control(tinyMCE.settings);
552 this.instances[id] = inst;
554 inst._onAdd(replace_element, form_element_name, target_document);
557 removeInstance : function(ti) {
560 // Remove from instances
561 for (n in tinyMCE.instances) {
562 i = tinyMCE.instances[n];
564 if (tinyMCE.isInstance(i) && ti != i)
568 tinyMCE.instances = t;
570 // Remove from global undo/redo
572 t = tinyMCE.undoLevels;
574 for (i=0; i<t.length; i++) {
579 tinyMCE.undoLevels = n;
580 tinyMCE.undoIndex = n.length;
582 // Dispatch remove instance call
583 tinyMCE.dispatchCallback(ti, 'remove_instance_callback', 'removeInstance', ti);
588 removeMCEControl : function(editor_id) {
589 var inst = tinyMCE.getInstanceById(editor_id), h, re, ot, tn;
592 inst.switchSettings();
594 editor_id = inst.editorId;
595 h = tinyMCE.getContent(editor_id);
597 this.removeInstance(inst);
599 tinyMCE.selectedElement = null;
600 tinyMCE.selectedInstance = null;
603 re = document.getElementById(editor_id + "_parent");
604 ot = inst.oldTargetElement;
605 tn = ot.nodeName.toLowerCase();
607 if (tn == "textarea" || tn == "input") {
608 re.parentNode.removeChild(re);
609 ot.style.display = "inline";
613 ot.style.display = 'block';
614 re.parentNode.insertBefore(ot, re);
615 re.parentNode.removeChild(re);
620 triggerSave : function(skip_cleanup, skip_callback) {
624 if (typeof(skip_cleanup) == "undefined")
625 skip_cleanup = false;
628 if (typeof(skip_callback) == "undefined")
629 skip_callback = false;
631 // Cleanup and set all form fields
632 for (n in tinyMCE.instances) {
633 inst = tinyMCE.instances[n];
635 if (!tinyMCE.isInstance(inst))
638 inst.triggerSave(skip_cleanup, skip_callback);
642 resetForm : function(form_index) {
643 var i, inst, n, formObj = document.forms[form_index];
645 for (n in tinyMCE.instances) {
646 inst = tinyMCE.instances[n];
648 if (!tinyMCE.isInstance(inst))
651 inst.switchSettings();
653 for (i=0; i<formObj.elements.length; i++) {
654 if (inst.formTargetElementId == formObj.elements[i].name)
655 inst.getBody().innerHTML = inst.startContent;
660 execInstanceCommand : function(editor_id, command, user_interface, value, focus) {
661 var inst = tinyMCE.getInstanceById(editor_id), r;
664 r = inst.selection.getRng();
666 if (typeof(focus) == "undefined")
669 // IE bug lost focus on images in absolute divs Bug #1534575
670 if (focus && (!r || !r.item))
671 inst.contentWindow.focus();
673 // Reset design mode if lost
674 inst.autoResetDesignMode();
676 this.selectedElement = inst.getFocusElement();
678 tinyMCE.execCommand(command, user_interface, value);
680 // Cancel event so it doesn't call onbeforeonunlaod
681 if (tinyMCE.isIE && window.event != null)
682 tinyMCE.cancelEvent(window.event);
686 execCommand : function(command, user_interface, value) {
687 var inst = tinyMCE.selectedInstance, n, pe, te;
690 user_interface = user_interface ? user_interface : false;
691 value = value ? value : null;
694 inst.switchSettings();
698 if (this.getParam('custom_undo_redo_global')) {
699 if (this.undoIndex > 0) {
700 tinyMCE.nextUndoRedoAction = 'Undo';
701 inst = this.undoLevels[--this.undoIndex];
704 if (!tinyMCE.nextUndoRedoInstanceId)
705 inst.execCommand('Undo');
708 inst.execCommand('Undo');
712 if (this.getParam('custom_undo_redo_global')) {
713 if (this.undoIndex <= this.undoLevels.length - 1) {
714 tinyMCE.nextUndoRedoAction = 'Redo';
715 inst = this.undoLevels[this.undoIndex++];
718 if (!tinyMCE.nextUndoRedoInstanceId)
719 inst.execCommand('Redo');
722 inst.execCommand('Redo');
727 inst = tinyMCE.getInstanceById(value);
730 inst.getWin().focus();
733 case "mceAddControl":
735 tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);
738 case "mceAddFrameControl":
739 tinyMCE.addMCEControl(tinyMCE._getElementById(value.element, value.document), value.element, value.document);
742 case "mceRemoveControl":
743 case "mceRemoveEditor":
744 tinyMCE.removeMCEControl(value);
747 case "mceToggleEditor":
748 inst = tinyMCE.getInstanceById(value);
751 pe = document.getElementById(inst.editorId + '_parent');
752 te = inst.oldTargetElement;
754 if (typeof(inst.enabled) == 'undefined')
757 inst.enabled = !inst.enabled;
760 pe.style.display = 'none';
762 if (te.nodeName == 'TEXTAREA' || te.nodeName == 'INPUT')
763 te.value = inst.getHTML();
765 te.innerHTML = inst.getHTML();
767 te.style.display = inst.oldTargetDisplay;
768 tinyMCE.dispatchCallback(inst, 'hide_instance_callback', 'hideInstance', inst);
770 pe.style.display = 'block';
771 te.style.display = 'none';
773 if (te.nodeName == 'TEXTAREA' || te.nodeName == 'INPUT')
774 inst.setHTML(te.value);
776 inst.setHTML(te.innerHTML);
779 tinyMCE.dispatchCallback(inst, 'show_instance_callback', 'showInstance', inst);
782 tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);
786 case "mceResetDesignMode":
787 // Resets the designmode state of the editors in Gecko
788 if (tinyMCE.isGecko) {
789 for (n in tinyMCE.instances) {
790 if (!tinyMCE.isInstance(tinyMCE.instances[n]))
794 tinyMCE.instances[n].getDoc().designMode = "off";
795 tinyMCE.instances[n].getDoc().designMode = "on";
796 tinyMCE.instances[n].useCSS = false;
807 inst.execCommand(command, user_interface, value);
808 } else if (tinyMCE.settings.focus_alert)
809 alert(tinyMCELang.lang_focus_alert);
812 _createIFrame : function(replace_element, doc, win) {
813 var iframe, id = replace_element.getAttribute("id");
816 if (typeof(doc) == "undefined")
819 if (typeof(win) == "undefined")
822 iframe = doc.createElement("iframe");
824 aw = "" + tinyMCE.settings.area_width;
825 ah = "" + tinyMCE.settings.area_height;
827 if (aw.indexOf('%') == -1) {
829 aw = (isNaN(aw) || aw < 0) ? 300 : aw;
833 if (ah.indexOf('%') == -1) {
835 ah = (isNaN(ah) || ah < 0) ? 240 : ah;
839 iframe.setAttribute("id", id);
840 iframe.setAttribute("name", id);
841 iframe.setAttribute("class", "mceEditorIframe");
842 iframe.setAttribute("border", "0");
843 iframe.setAttribute("frameBorder", "0");
844 iframe.setAttribute("marginWidth", "0");
845 iframe.setAttribute("marginHeight", "0");
846 iframe.setAttribute("leftMargin", "0");
847 iframe.setAttribute("topMargin", "0");
848 iframe.setAttribute("width", aw);
849 iframe.setAttribute("height", ah);
850 iframe.setAttribute("allowtransparency", "true");
851 iframe.className = 'mceEditorIframe';
853 if (tinyMCE.settings.auto_resize)
854 iframe.setAttribute("scrolling", "no");
856 // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs
857 if (tinyMCE.isRealIE)
858 iframe.setAttribute("src", this.settings.default_document);
860 iframe.style.width = aw;
861 iframe.style.height = ah;
863 // Ugly hack for Gecko problem in strict mode
864 if (tinyMCE.settings.strict_loading_mode)
865 iframe.style.marginBottom = '-5px';
868 if (tinyMCE.isRealIE)
869 replace_element.outerHTML = iframe.outerHTML;
871 replace_element.parentNode.replaceChild(iframe, replace_element);
873 if (tinyMCE.isRealIE)
874 return win.frames[id];
879 setupContent : function(editor_id) {
880 var inst = tinyMCE.instances[editor_id], i, doc = inst.getDoc(), head = doc.getElementsByTagName('head').item(0);
881 var content = inst.startContent, contentElement, body;
883 // HTML values get XML encoded in strict mode
884 if (tinyMCE.settings.strict_loading_mode) {
885 content = content.replace(/</g, '<');
886 content = content.replace(/>/g, '>');
887 content = content.replace(/"/g, '"');
888 content = content.replace(/&/g, '&');
891 tinyMCE.selectedInstance = inst;
892 inst.switchSettings();
894 // Not loaded correctly hit it again, Mozilla bug #997860
895 if (!tinyMCE.isIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") {
896 // This part will remove the designMode status
897 // Failes first time in Firefox 1.5b2 on Mac
898 try {doc.location.href = tinyMCE.baseURL + "/blank.htm";} catch (ex) {}
899 window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 1000);
903 // Wait for it to load
904 if (!head || !doc.body) {
905 window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10);
909 // Import theme specific content CSS the user specific
910 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/themes/" + inst.settings.theme + "/css/editor_content.css");
911 tinyMCE.importCSS(inst.getDoc(), inst.settings.content_css);
912 tinyMCE.dispatchCallback(inst, 'init_instance_callback', 'initInstance', inst);
914 // Setup keyboard shortcuts
915 if (tinyMCE.getParam('custom_undo_redo_keyboard_shortcuts')) {
916 inst.addShortcut('ctrl', 'z', 'lang_undo_desc', 'Undo');
917 inst.addShortcut('ctrl', 'y', 'lang_redo_desc', 'Redo');
920 // BlockFormat shortcuts keys
922 inst.addShortcut('ctrl', '' + i, '', 'FormatBlock', false, '<h' + i + '>');
924 inst.addShortcut('ctrl', '7', '', 'FormatBlock', false, '<p>');
925 inst.addShortcut('ctrl', '8', '', 'FormatBlock', false, '<div>');
926 inst.addShortcut('ctrl', '9', '', 'FormatBlock', false, '<address>');
928 // Add default shortcuts for gecko
929 if (tinyMCE.isGecko) {
930 inst.addShortcut('ctrl', 'b', 'lang_bold_desc', 'Bold');
931 inst.addShortcut('ctrl', 'i', 'lang_italic_desc', 'Italic');
932 inst.addShortcut('ctrl', 'u', 'lang_underline_desc', 'Underline');
936 if (tinyMCE.getParam("convert_fonts_to_spans"))
937 inst.getBody().setAttribute('id', 'mceSpanFonts');
939 if (tinyMCE.settings.nowrap)
940 doc.body.style.whiteSpace = "nowrap";
942 doc.body.dir = this.settings.directionality;
943 doc.editorId = editor_id;
945 // Add on document element in Mozilla
947 doc.documentElement.editorId = editor_id;
949 inst.setBaseHREF(tinyMCE.settings.base_href);
951 // Replace new line characters to BRs
952 if (tinyMCE.settings.convert_newlines_to_brs) {
953 content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi");
954 content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi");
955 content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi");
958 // Open closed anchors
959 // content = content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
961 // Call custom cleanup code
962 content = tinyMCE.storeAwayURLs(content);
963 content = tinyMCE._customCleanup(inst, "insert_to_editor", content);
967 window.setInterval('try{tinyMCE.getCSSClasses(tinyMCE.instances["' + editor_id + '"].getDoc(), "' + editor_id + '");}catch(e){}', 500);
969 if (tinyMCE.settings.force_br_newlines)
970 doc.styleSheets[0].addRule("p", "margin: 0;");
972 body = inst.getBody();
973 body.editorId = editor_id;
976 content = tinyMCE.cleanupHTMLCode(content);
978 // Fix for bug #958637
980 contentElement = inst.getDoc().createElement("body");
983 contentElement.innerHTML = content;
985 if (tinyMCE.settings.cleanup_on_startup)
986 tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement));
988 tinyMCE.setInnerHTML(inst.getBody(), content);
990 tinyMCE.convertAllRelativeURLs(inst.getBody());
992 if (tinyMCE.settings.cleanup_on_startup) {
993 tinyMCE._setHTML(inst.getDoc(), content);
995 // Produces permission denied error in MSIE 5.5
997 tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody()));
1002 tinyMCE._setHTML(inst.getDoc(), content);
1005 // Fix for bug #957681
1006 //inst.getDoc().designMode = inst.getDoc().designMode;
1008 tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings.visual, inst);
1009 tinyMCE.dispatchCallback(inst, 'setupcontent_callback', 'setupContent', editor_id, inst.getBody(), inst.getDoc());
1011 // Re-add design mode on mozilla
1013 tinyMCE.addEventHandlers(inst);
1017 tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE_Engine.prototype._eventPatch);
1018 tinyMCE.addEvent(inst.getBody(), "beforedeactivate", TinyMCE_Engine.prototype._eventPatch); // Bug #1439953
1020 // Workaround for drag drop/copy paste base href bug
1021 if (!tinyMCE.isOpera) {
1022 tinyMCE.addEvent(doc.body, "mousemove", TinyMCE_Engine.prototype.onMouseMove);
1023 tinyMCE.addEvent(doc.body, "beforepaste", TinyMCE_Engine.prototype._eventPatch);
1024 tinyMCE.addEvent(doc.body, "drop", TinyMCE_Engine.prototype._eventPatch);
1028 // Trigger node change, this call locks buttons for tables and so forth
1030 tinyMCE.selectedElement = inst.contentWindow.document.body;
1032 // Call custom DOM cleanup
1033 tinyMCE._customCleanup(inst, "insert_to_editor_dom", inst.getBody());
1034 tinyMCE._customCleanup(inst, "setup_content_dom", inst.getBody());
1035 tinyMCE._setEventsEnabled(inst.getBody(), false);
1036 tinyMCE.cleanupAnchors(inst.getDoc());
1038 if (tinyMCE.getParam("convert_fonts_to_spans"))
1039 tinyMCE.convertSpansToFonts(inst.getDoc());
1041 inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);
1042 inst.undoRedo.add({ content : inst.startContent });
1044 // Cleanup any mess left from storyAwayURLs
1045 if (tinyMCE.isGecko) {
1046 // Remove mce_src from textnodes and comments
1047 tinyMCE.selectNodes(inst.getBody(), function(n) {
1048 if (n.nodeType == 3 || n.nodeType == 8)
1049 n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), "");
1055 // Remove Gecko spellchecking
1056 if (tinyMCE.isGecko)
1057 inst.getBody().spellcheck = tinyMCE.getParam("gecko_spellcheck");
1059 // Cleanup any mess left from storyAwayURLs
1060 tinyMCE._removeInternal(inst.getBody());
1063 tinyMCE.triggerNodeChange(false, true);
1066 storeAwayURLs : function(s) {
1067 // Remove all mce_src, mce_href and replace them with new ones
1068 // s = s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
1069 // s = s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
1071 if (!s.match(/(mce_src|mce_href)/gi, s)) {
1072 s = s.replace(new RegExp('src\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'src="$1" mce_src="$1"');
1073 s = s.replace(new RegExp('href\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'href="$1" mce_href="$1"');
1079 _removeInternal : function(n) {
1080 if (tinyMCE.isGecko) {
1081 // Remove mce_src from textnodes and comments
1082 tinyMCE.selectNodes(n, function(n) {
1083 if (n.nodeType == 3 || n.nodeType == 8)
1084 n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), "");
1091 removeTinyMCEFormElements : function(form_obj) {
1094 // Skip form element removal
1095 if (!tinyMCE.getParam('hide_selects_on_submit'))
1098 // Check if form is valid
1099 if (typeof(form_obj) == "undefined" || form_obj == null)
1102 // If not a form, find the form
1103 if (form_obj.nodeName != "FORM") {
1105 form_obj = form_obj.form;
1107 form_obj = tinyMCE.getParentElement(form_obj, "form");
1111 if (form_obj == null)
1114 // Disable all UI form elements that TinyMCE created
1115 for (i=0; i<form_obj.elements.length; i++) {
1116 elementId = form_obj.elements[i].name ? form_obj.elements[i].name : form_obj.elements[i].id;
1118 if (elementId.indexOf('mce_editor_') == 0)
1119 form_obj.elements[i].disabled = true;
1123 handleEvent : function(e) {
1124 var inst = tinyMCE.selectedInstance, i, elm, keys;
1126 // Remove odd, error
1127 if (typeof(tinyMCE) == "undefined")
1130 //tinyMCE.debug(e.type + " " + e.target.nodeName + " " + (e.relatedTarget ? e.relatedTarget.nodeName : ""));
1132 if (tinyMCE.executeCallback(tinyMCE.selectedInstance, 'handle_event_callback', 'handleEvent', e))
1136 case "beforedeactivate": // Was added due to bug #1439953
1138 if (tinyMCE.selectedInstance)
1139 tinyMCE.selectedInstance.execCommand('mceEndTyping');
1141 tinyMCE.hideMenus();
1145 // Workaround for drag drop/copy paste base href bug
1148 if (tinyMCE.selectedInstance)
1149 tinyMCE.selectedInstance.setBaseHREF(null);
1151 // Fixes odd MSIE bug where drag/droping elements in a iframe with height 100% breaks
1152 // This logic forces the width/height to be in pixels while the user is drag/dropping
1153 if (tinyMCE.isRealIE) {
1154 var ife = tinyMCE.selectedInstance.iframeElement;
1156 /*if (ife.style.width.indexOf('%') != -1) {
1157 ife._oldWidth = ife.width.height;
1158 ife.style.width = ife.clientWidth;
1161 if (ife.style.height.indexOf('%') != -1) {
1162 ife._oldHeight = ife.style.height;
1163 ife.style.height = ife.clientHeight;
1167 window.setTimeout("tinyMCE.selectedInstance.setBaseHREF(tinyMCE.settings.base_href);tinyMCE._resetIframeHeight();", 1);
1171 tinyMCE.formSubmit(tinyMCE.isMSIE ? window.event.srcElement : e.target);
1175 var formObj = tinyMCE.isIE ? window.event.srcElement : e.target;
1177 for (i=0; i<document.forms.length; i++) {
1178 if (document.forms[i] == formObj)
1179 window.setTimeout('tinyMCE.resetForm(' + i + ');', 10);
1185 if (inst && inst.handleShortcut(e))
1188 if (e.target.editorId) {
1189 tinyMCE.instances[e.target.editorId].select();
1191 if (e.target.ownerDocument.editorId)
1192 tinyMCE.instances[e.target.ownerDocument.editorId].select();
1195 if (tinyMCE.selectedInstance)
1196 tinyMCE.selectedInstance.switchSettings();
1199 if ((tinyMCE.isGecko || tinyMCE.isOpera || tinyMCE.isSafari) && tinyMCE.settings.force_p_newlines && e.keyCode == 13 && !e.shiftKey) {
1200 // Insert P element instead of BR
1201 if (TinyMCE_ForceParagraphs._insertPara(tinyMCE.selectedInstance, e)) {
1203 tinyMCE.execCommand("mceAddUndoLevel");
1204 return tinyMCE.cancelEvent(e);
1209 if ((tinyMCE.isGecko && !tinyMCE.isSafari) && tinyMCE.settings.force_p_newlines && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
1210 // Insert P element instead of BR
1211 if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) {
1213 tinyMCE.execCommand("mceAddUndoLevel");
1214 return tinyMCE.cancelEvent(e);
1218 // Return key pressed
1219 if (tinyMCE.isIE && tinyMCE.settings.force_br_newlines && e.keyCode == 13) {
1220 if (e.target.editorId)
1221 tinyMCE.instances[e.target.editorId].select();
1223 if (tinyMCE.selectedInstance) {
1224 var sel = tinyMCE.selectedInstance.getDoc().selection;
1225 var rng = sel.createRange();
1227 if (tinyMCE.getParentElement(rng.parentElement(), "li") != null)
1231 e.returnValue = false;
1232 e.cancelBubble = true;
1234 // Insert BR element
1235 rng.pasteHTML("<br />");
1236 rng.collapse(false);
1239 tinyMCE.execCommand("mceAddUndoLevel");
1240 tinyMCE.triggerNodeChange(false);
1245 // Backspace or delete
1246 if (e.keyCode == 8 || e.keyCode == 46) {
1247 tinyMCE.selectedElement = e.target;
1248 tinyMCE.linkElement = tinyMCE.getParentElement(e.target, "a");
1249 tinyMCE.imgElement = tinyMCE.getParentElement(e.target, "img");
1250 tinyMCE.triggerNodeChange(false);
1257 tinyMCE.hideMenus();
1258 tinyMCE.hasMouseMoved = false;
1260 if (inst && inst.handleShortcut(e))
1263 inst._fixRootBlocks();
1265 if (inst.settings.remove_trailing_nbsp)
1266 inst._fixTrailingNbsp();
1268 if (e.target.editorId)
1269 tinyMCE.instances[e.target.editorId].select();
1271 if (tinyMCE.selectedInstance)
1272 tinyMCE.selectedInstance.switchSettings();
1274 inst = tinyMCE.selectedInstance;
1277 if (tinyMCE.isGecko && tinyMCE.settings.force_p_newlines && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
1278 // Insert P element instead of BR
1279 if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) {
1281 tinyMCE.execCommand("mceAddUndoLevel");
1287 tinyMCE.selectedElement = null;
1288 tinyMCE.selectedNode = null;
1289 elm = tinyMCE.selectedInstance.getFocusElement();
1290 tinyMCE.linkElement = tinyMCE.getParentElement(elm, "a");
1291 tinyMCE.imgElement = tinyMCE.getParentElement(elm, "img");
1292 tinyMCE.selectedElement = elm;
1294 // Update visualaids on tabs
1295 if (tinyMCE.isGecko && e.type == "keyup" && e.keyCode == 9)
1296 tinyMCE.handleVisualAid(tinyMCE.selectedInstance.getBody(), true, tinyMCE.settings.visual, tinyMCE.selectedInstance);
1298 // Fix empty elements on return/enter, check where enter occured
1299 if (tinyMCE.isIE && e.type == "keydown" && e.keyCode == 13)
1300 tinyMCE.enterKeyElement = tinyMCE.selectedInstance.getFocusElement();
1302 // Fix empty elements on return/enter
1303 if (tinyMCE.isIE && e.type == "keyup" && e.keyCode == 13) {
1304 elm = tinyMCE.enterKeyElement;
1306 var re = new RegExp('^HR|IMG|BR$','g'); // Skip these
1307 var dre = new RegExp('^H[1-6]$','g'); // Add double on these
1309 if (!elm.hasChildNodes() && !re.test(elm.nodeName)) {
1310 if (dre.test(elm.nodeName))
1311 elm.innerHTML = " ";
1313 elm.innerHTML = " ";
1318 // Check if it's a position key
1319 keys = tinyMCE.posKeyCodes;
1321 for (i=0; i<keys.length; i++) {
1322 if (keys[i] == e.keyCode) {
1328 // MSIE custom key handling
1329 if (tinyMCE.isIE && tinyMCE.settings.custom_undo_redo) {
1330 keys = [8, 46]; // Backspace,Delete
1332 for (i=0; i<keys.length; i++) {
1333 if (keys[i] == e.keyCode) {
1334 if (e.type == "keyup")
1335 tinyMCE.triggerNodeChange(false);
1341 if (e.keyCode == 17)
1344 // Handle Undo/Redo when typing content
1346 if (tinyMCE.isGecko) {
1347 // Start typing (not a position key or ctrl key, but ctrl+x and ctrl+p is ok)
1348 if (!posKey && e.type == "keyup" && !e.ctrlKey || (e.ctrlKey && (e.keyCode == 86 || e.keyCode == 88)))
1349 tinyMCE.execCommand("mceStartTyping");
1351 // IE seems to be working better with this setting
1352 if (!posKey && e.type == "keyup")
1353 tinyMCE.execCommand("mceStartTyping");
1356 // Store undo bookmark
1357 if (e.type == "keydown" && (posKey || e.ctrlKey) && inst)
1358 inst.undoBookmark = inst.selection.getBookmark();
1360 // End typing (position key) or some Ctrl event
1361 if (e.type == "keyup" && (posKey || e.ctrlKey))
1362 tinyMCE.execCommand("mceEndTyping");
1364 if (posKey && e.type == "keyup")
1365 tinyMCE.triggerNodeChange(false);
1367 if (tinyMCE.isIE && e.ctrlKey)
1368 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
1376 tinyMCE.hideMenus();
1378 if (tinyMCE.selectedInstance) {
1379 tinyMCE.selectedInstance.switchSettings();
1380 tinyMCE.selectedInstance.isFocused = true;
1383 // Check instance event trigged on
1384 var targetBody = tinyMCE.getParentElement(e.target, "html");
1385 for (var instanceName in tinyMCE.instances) {
1386 if (!tinyMCE.isInstance(tinyMCE.instances[instanceName]))
1389 inst = tinyMCE.instances[instanceName];
1391 // Reset design mode if lost (on everything just in case)
1392 inst.autoResetDesignMode();
1394 // Use HTML element since users might click outside of body element
1395 if (inst.getBody().parentNode == targetBody) {
1397 tinyMCE.selectedElement = e.target;
1398 tinyMCE.linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");
1399 tinyMCE.imgElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "img");
1404 // Add first bookmark location
1405 if (!tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark && (e.type == "mouseup" || e.type == "dblclick"))
1406 tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark = tinyMCE.selectedInstance.selection.getBookmark();
1408 // Reset selected node
1409 if (e.type != "focus")
1410 tinyMCE.selectedNode = null;
1412 tinyMCE.triggerNodeChange(false);
1413 tinyMCE.execCommand("mceEndTyping");
1415 if (e.type == "mouseup")
1416 tinyMCE.execCommand("mceAddUndoLevel");
1419 if (!tinyMCE.selectedInstance && e.target.editorId)
1420 tinyMCE.instances[e.target.editorId].select();
1426 getButtonHTML : function(id, lang, img, cmd, ui, val) {
1427 var h = '', m, x, io = '';
1429 cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\'';
1431 if (typeof(ui) != "undefined" && ui != null)
1434 if (typeof(val) != "undefined" && val != null)
1435 cmd += ",'" + val + "'";
1439 // Patch for IE7 bug with hover out not restoring correctly
1440 if (tinyMCE.isRealIE)
1441 io = 'onmouseover="tinyMCE.lastHover = this;"';
1443 // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled
1444 if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = this.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) {
1446 x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20);
1447 h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceTiledButton mceButtonNormal" target="_self">';
1448 h += '<img src="{$themeurl}/images/spacer.gif" style="background-position: ' + x + 'px 0" alt="{$'+lang+'}" title="{$' + lang + '}" />';
1452 h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceButtonNormal" target="_self">';
1453 h += '<img src="' + img + '" alt="{$'+lang+'}" title="{$' + lang + '}" />';
1460 getMenuButtonHTML : function(id, lang, img, mcmd, cmd, ui, val) {
1463 mcmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + mcmd + '\');';
1464 cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\'';
1466 if (typeof(ui) != "undefined" && ui != null)
1469 if (typeof(val) != "undefined" && val != null)
1470 cmd += ",'" + val + "'";
1474 // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled
1475 if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = tinyMCE.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) {
1476 x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20);
1478 if (tinyMCE.isRealIE)
1479 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">';
1481 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton">';
1483 h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceTiledButton mceMenuButtonNormal" target="_self">';
1484 h += '<img src="{$themeurl}/images/spacer.gif" style="width: 20px; height: 20px; background-position: ' + x + 'px 0" title="{$' + lang + '}" /></a>';
1485 h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />';
1488 if (tinyMCE.isRealIE)
1489 h += '<span id="{$editor_id}_' + id + '" dir="ltr" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">';
1491 h += '<span id="{$editor_id}_' + id + '" dir="ltr" class="mceMenuButton">';
1493 h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceMenuButtonNormal" target="_self">';
1494 h += '<img src="' + img + '" title="{$' + lang + '}" /></a>';
1495 h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />';
1502 _menuButtonEvent : function(e, o) {
1503 if (o.className == 'mceMenuButtonFocus')
1507 o.className = o.className + ' mceMenuHover';
1509 o.className = o.className.replace(/\s.*$/, '');
1512 addButtonMap : function(m) {
1513 var i, a = m.replace(/\s+/, '').split(',');
1515 for (i=0; i<a.length; i++)
1516 this.buttonMap[a[i]] = i;
1519 formSubmit : function(f, p) {
1520 var n, inst, found = false;
1525 // Is it a form that has a TinyMCE instance
1526 for (n in tinyMCE.instances) {
1527 inst = tinyMCE.instances[n];
1529 if (!tinyMCE.isInstance(inst))
1532 if (inst.formElement) {
1533 if (f == inst.formElement.form) {
1535 inst.isNotDirty = true;
1542 tinyMCE.removeTinyMCEFormElements(f);
1543 tinyMCE.triggerSave();
1547 if (f.mceOldSubmit && p)
1551 submitPatch : function() {
1552 tinyMCE.formSubmit(this, true);
1555 onLoad : function() {
1556 var r, i, c, mode, trigger, elements, element, settings, elementId, elm;
1557 var selector, deselector, elementRefAr, form;
1559 // Wait for everything to be loaded first
1560 if (tinyMCE.settings.strict_loading_mode && this.loadingIndex != -1) {
1561 window.setTimeout('tinyMCE.onLoad();', 1);
1565 if (tinyMCE.isRealIE && window.event.type == "readystatechange" && document.readyState != "complete")
1568 if (tinyMCE.isLoaded)
1571 tinyMCE.isLoaded = true;
1573 // IE produces JS error if TinyMCE is placed in a frame
1574 // It seems to have something to do with the selection not beeing
1575 // correctly initialized in IE so this hack solves the problem
1576 if (tinyMCE.isRealIE && document.body && window.location.href != window.top.location.href) {
1577 r = document.body.createTextRange();
1582 tinyMCE.dispatchCallback(null, 'onpageload', 'onPageLoad');
1584 for (c=0; c<tinyMCE.configs.length; c++) {
1585 tinyMCE.settings = tinyMCE.configs[c];
1587 selector = tinyMCE.getParam("editor_selector");
1588 deselector = tinyMCE.getParam("editor_deselector");
1591 // Add submit triggers
1592 if (document.forms && tinyMCE.settings.add_form_submit_trigger && !tinyMCE.submitTriggers) {
1593 for (i=0; i<document.forms.length; i++) {
1594 form = document.forms[i];
1596 tinyMCE.addEvent(form, "submit", TinyMCE_Engine.prototype.handleEvent);
1597 tinyMCE.addEvent(form, "reset", TinyMCE_Engine.prototype.handleEvent);
1598 tinyMCE.submitTriggers = true; // Do it only once
1600 // Patch the form.submit function
1601 if (tinyMCE.settings.submit_patch) {
1603 form.mceOldSubmit = form.submit;
1604 form.submit = TinyMCE_Engine.prototype.submitPatch;
1612 // Add editor instances based on mode
1613 mode = tinyMCE.settings.mode;
1616 elements = tinyMCE.getParam('elements', '', true, ',');
1618 for (i=0; i<elements.length; i++) {
1619 element = tinyMCE._getElementById(elements[i]);
1620 trigger = element ? element.getAttribute(tinyMCE.settings.textarea_trigger) : "";
1622 if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(element, "class")))
1625 if (trigger == "false")
1628 if ((tinyMCE.settings.ask || tinyMCE.settings.convert_on_click) && element) {
1629 elementRefAr[elementRefAr.length] = element;
1634 tinyMCE.addMCEControl(element, elements[i]);
1638 case "specific_textareas":
1640 elements = document.getElementsByTagName("textarea");
1642 for (i=0; i<elements.length; i++) {
1643 elm = elements.item(i);
1644 trigger = elm.getAttribute(tinyMCE.settings.textarea_trigger);
1646 if (selector !== '' && !new RegExp('\\b' + selector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
1649 if (selector !== '')
1650 trigger = selector !== '' ? "true" : "";
1652 if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
1655 if ((mode == "specific_textareas" && trigger == "true") || (mode == "textareas" && trigger != "false"))
1656 elementRefAr[elementRefAr.length] = elm;
1661 for (i=0; i<elementRefAr.length; i++) {
1662 element = elementRefAr[i];
1663 elementId = element.name ? element.name : element.id;
1665 if (tinyMCE.settings.ask || tinyMCE.settings.convert_on_click) {
1666 // Focus breaks in Mozilla
1667 if (tinyMCE.isGecko) {
1668 settings = tinyMCE.settings;
1670 tinyMCE.addEvent(element, "focus", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
1672 if (element.nodeName != "TEXTAREA" && element.nodeName != "INPUT")
1673 tinyMCE.addEvent(element, "click", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
1674 // tinyMCE.addEvent(element, "mouseover", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
1676 settings = tinyMCE.settings;
1678 tinyMCE.addEvent(element, "focus", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
1679 tinyMCE.addEvent(element, "click", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
1680 // tinyMCE.addEvent(element, "mouseenter", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
1683 tinyMCE.addMCEControl(element, elementId);
1686 // Handle auto focus
1687 if (tinyMCE.settings.auto_focus) {
1688 window.setTimeout(function () {
1689 var inst = tinyMCE.getInstanceById(tinyMCE.settings.auto_focus);
1690 inst.selection.selectNode(inst.getBody(), true, true);
1691 inst.contentWindow.focus();
1695 tinyMCE.dispatchCallback(null, 'oninit', 'onInit');
1699 isInstance : function(o) {
1700 return o != null && typeof(o) == "object" && o.isTinyMCE_Control;
1703 getParam : function(name, default_value, strip_whitespace, split_chr) {
1704 var i, outArray, value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
1707 if (value == "true" || value == "false")
1708 return (value == "true");
1710 if (strip_whitespace)
1711 value = tinyMCE.regexpReplace(value, "[ \t\r\n]", "");
1713 if (typeof(split_chr) != "undefined" && split_chr != null) {
1714 value = value.split(split_chr);
1717 for (i=0; i<value.length; i++) {
1718 if (value[i] && value[i] !== '')
1719 outArray[outArray.length] = value[i];
1728 getLang : function(name, default_value, parse_entities, va) {
1729 var v = (typeof(tinyMCELang[name]) == "undefined") ? default_value : tinyMCELang[name], n;
1732 v = tinyMCE.entityDecode(v);
1736 v = this.replaceVar(v, n, va[n]);
1742 entityDecode : function(s) {
1743 var e = document.createElement("div");
1747 return !e.firstChild ? s : e.firstChild.nodeValue;
1750 addToLang : function(prefix, ar) {
1754 if (typeof(ar[k]) == 'function')
1757 tinyMCELang[(k.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix !== '' ? (prefix + "_") : '') + k] = ar[k];
1760 this.loadNextScript();
1763 triggerNodeChange : function(focus, setup_content) {
1764 var elm, inst, editorId, undoIndex = -1, undoLevels = -1, doc, anySelection = false, st;
1766 if (tinyMCE.selectedInstance) {
1767 inst = tinyMCE.selectedInstance;
1768 elm = (typeof(setup_content) != "undefined" && setup_content) ? tinyMCE.selectedElement : inst.getFocusElement();
1770 /* if (elm == inst.lastTriggerEl)
1773 inst.lastTriggerEl = elm;*/
1775 editorId = inst.editorId;
1776 st = inst.selection.getSelectedText();
1778 if (tinyMCE.settings.auto_resize)
1779 inst.resizeToContent();
1781 if (setup_content && tinyMCE.isGecko && inst.isHidden())
1782 elm = inst.getBody();
1784 inst.switchSettings();
1786 if (tinyMCE.selectedElement)
1787 anySelection = (tinyMCE.selectedElement.nodeName.toLowerCase() == "img") || (st && st.length > 0);
1789 if (tinyMCE.settings.custom_undo_redo) {
1790 undoIndex = inst.undoRedo.undoIndex;
1791 undoLevels = inst.undoRedo.undoLevels.length;
1794 tinyMCE.dispatchCallback(inst, 'handle_node_change_callback', 'handleNodeChange', editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content);
1797 if (this.selectedInstance && (typeof(focus) == "undefined" || focus))
1798 this.selectedInstance.contentWindow.focus();
1801 _customCleanup : function(inst, type, content) {
1802 var pl, po, i, customCleanup;
1804 // Call custom cleanup
1805 customCleanup = tinyMCE.settings.cleanup_callback;
1806 if (customCleanup != '')
1807 content = tinyMCE.resolveDots(tinyMCE.settings.cleanup_callback, window)(type, content, inst);
1809 // Trigger theme cleanup
1810 po = tinyMCE.themes[tinyMCE.settings.theme];
1811 if (po && po.cleanup)
1812 content = po.cleanup(type, content, inst);
1814 // Trigger plugin cleanups
1816 for (i=0; i<pl.length; i++) {
1817 po = tinyMCE.plugins[pl[i]];
1819 if (po && po.cleanup)
1820 content = po.cleanup(type, content, inst);
1826 setContent : function(h) {
1827 if (tinyMCE.selectedInstance) {
1828 tinyMCE.selectedInstance.execCommand('mceSetContent', false, h);
1829 tinyMCE.selectedInstance.repaint();
1833 importThemeLanguagePack : function(name) {
1834 if (typeof(name) == "undefined")
1835 name = tinyMCE.settings.theme;
1837 tinyMCE.loadScript(tinyMCE.baseURL + '/themes/' + name + '/langs/' + tinyMCE.settings.language + '.js');
1840 importPluginLanguagePack : function(name) {
1841 var b = tinyMCE.baseURL + '/plugins/' + name;
1843 if (this.plugins[name])
1844 b = this.plugins[name].baseURL;
1846 tinyMCE.loadScript(b + '/langs/' + tinyMCE.settings.language + '.js');
1849 applyTemplate : function(h, ag) {
1850 return h.replace(new RegExp('\\{\\$([a-z0-9_]+)\\}', 'gi'), function(m, s) {
1851 if (s.indexOf('lang_') == 0 && tinyMCELang[s])
1852 return tinyMCELang[s];
1857 if (tinyMCE.settings[s])
1858 return tinyMCE.settings[s];
1860 if (m == 'themeurl')
1861 return tinyMCE.themeURL;
1867 replaceVar : function(h, r, v) {
1868 return h.replace(new RegExp('{\\\$' + r + '}', 'g'), v);
1871 openWindow : function(template, args) {
1872 var html, width, height, x, y, resizable, scrollbars, url, name, win, modal, features;
1874 args = !args ? {} : args;
1876 args.mce_template_file = template.file;
1877 args.mce_width = template.width;
1878 args.mce_height = template.height;
1879 tinyMCE.windowArgs = args;
1881 html = template.html;
1882 if (!(width = parseInt(template.width)))
1885 if (!(height = parseInt(template.height)))
1888 // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!!
1894 x = parseInt(screen.width / 2.0) - (width / 2.0);
1895 y = parseInt(screen.height / 2.0) - (height / 2.0);
1897 resizable = (args && args.resizable) ? args.resizable : "no";
1898 scrollbars = (args && args.scrollbars) ? args.scrollbars : "no";
1900 if (template.file.charAt(0) != '/' && template.file.indexOf('://') == -1)
1901 url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template.file;
1903 url = template.file;
1905 // Replace all args as variables in URL
1906 for (name in args) {
1907 if (typeof(args[name]) == 'function')
1910 url = tinyMCE.replaceVar(url, name, escape(args[name]));
1914 html = tinyMCE.replaceVar(html, "css", this.settings.popups_css);
1915 html = tinyMCE.applyTemplate(html, args);
1917 win = window.open("", "mcePopup" + new Date().getTime(), "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,minimizable=" + resizable + ",modal=yes,width=" + width + ",height=" + height + ",resizable=" + resizable);
1919 alert(tinyMCELang.lang_popup_blocked);
1923 win.document.write(html);
1924 win.document.close();
1925 win.resizeTo(width, height);
1928 if ((tinyMCE.isRealIE) && resizable != 'yes' && tinyMCE.settings.dialog_type == "modal") {
1931 features = "resizable:" + resizable + ";scroll:" + scrollbars + ";status:yes;center:yes;help:no;dialogWidth:" + width + "px;dialogHeight:" + height + "px;";
1933 window.showModalDialog(url, window, features);
1935 modal = (resizable == "yes") ? "no" : "yes";
1937 if (tinyMCE.isGecko && tinyMCE.isMac)
1940 if (template.close_previous != "no")
1941 try {tinyMCE.lastWindow.close();} catch (ex) {}
1943 win = window.open(url, "mcePopup" + new Date().getTime(), "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=" + modal + ",minimizable=" + resizable + ",modal=" + modal + ",width=" + width + ",height=" + height + ",resizable=" + resizable);
1945 alert(tinyMCELang.lang_popup_blocked);
1949 if (template.close_previous != "no")
1950 tinyMCE.lastWindow = win;
1953 win.resizeTo(width, height);
1958 // Make it bigger if statusbar is forced
1959 if (tinyMCE.isGecko) {
1960 if (win.document.defaultView.statusbar.visible)
1961 win.resizeBy(0, tinyMCE.isMac ? 10 : 24);
1969 closeWindow : function(win) {
1973 getVisualAidClass : function(class_name, state) {
1974 var i, classNames, ar, className, aidClass = tinyMCE.settings.visual_table_class;
1976 if (typeof(state) == "undefined")
1977 state = tinyMCE.settings.visual;
1981 ar = class_name.split(' ');
1982 for (i=0; i<ar.length; i++) {
1983 if (ar[i] == aidClass)
1987 classNames[classNames.length] = ar[i];
1991 classNames[classNames.length] = aidClass;
1995 for (i=0; i<classNames.length; i++) {
1999 className += classNames[i];
2005 handleVisualAid : function(el, deep, state, inst, skip_dispatch) {
2006 var i, x, y, tableElement, anchorName, oldW, oldH, bo, cn;
2012 tinyMCE.dispatchCallback(inst, 'handle_visual_aid_callback', 'handleVisualAid', el, deep, state, inst);
2014 tableElement = null;
2016 switch (el.nodeName) {
2018 oldW = el.style.width;
2019 oldH = el.style.height;
2020 bo = tinyMCE.getAttrib(el, "border");
2022 bo = bo == '' || bo == "0" ? true : false;
2024 tinyMCE.setAttrib(el, "class", tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el, "class"), state && bo));
2026 el.style.width = oldW;
2027 el.style.height = oldH;
2029 for (y=0; y<el.rows.length; y++) {
2030 for (x=0; x<el.rows[y].cells.length; x++) {
2031 cn = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el.rows[y].cells[x], "class"), state && bo);
2032 tinyMCE.setAttrib(el.rows[y].cells[x], "class", cn);
2039 anchorName = tinyMCE.getAttrib(el, "name");
2041 if (anchorName !== '' && state) {
2042 el.title = anchorName;
2043 tinyMCE.addCSSClass(el, 'mceItemAnchor');
2044 } else if (anchorName !== '' && !state)
2050 if (deep && el.hasChildNodes()) {
2051 for (i=0; i<el.childNodes.length; i++)
2052 tinyMCE.handleVisualAid(el.childNodes[i], deep, state, inst, true);
2056 fixGeckoBaseHREFBug : function(m, e, h) {
2059 if (tinyMCE.isGecko) {
2061 h = h.replace(/\ssrc=/gi, " mce_tsrc=");
2062 h = h.replace(/\shref=/gi, " mce_thref=");
2066 // Why bother if there is no src or href broken
2067 if (!new RegExp('(src|href)=', 'g').test(h))
2070 // Restore src and href that gets messed up by Gecko
2071 tinyMCE.selectElements(e, 'A,IMG,SELECT,AREA,IFRAME,BASE,INPUT,SCRIPT,EMBED,OBJECT,LINK', function (n) {
2072 xsrc = tinyMCE.getAttrib(n, "mce_tsrc");
2073 xhref = tinyMCE.getAttrib(n, "mce_thref");
2077 n.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, xsrc);
2079 // Ignore, Firefox cast exception if local file wasn't found
2082 n.removeAttribute("mce_tsrc");
2087 n.href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, xhref);
2089 // Ignore, Firefox cast exception if local file wasn't found
2092 n.removeAttribute("mce_thref");
2098 // Restore text/comment nodes
2099 tinyMCE.selectNodes(e, function(n) {
2100 if (n.nodeType == 3 || n.nodeType == 8) {
2101 n.nodeValue = n.nodeValue.replace(/\smce_tsrc=/gi, " src=");
2102 n.nodeValue = n.nodeValue.replace(/\smce_thref=/gi, " href=");
2113 _setHTML : function(doc, html_content) {
2114 var i, html, paras, node;
2116 // Force closed anchors open
2117 //html_content = html_content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
2119 html_content = tinyMCE.cleanupHTMLCode(html_content);
2121 // Try innerHTML if it fails use pasteHTML in MSIE
2123 tinyMCE.setInnerHTML(doc.body, html_content);
2126 doc.body.createTextRange().pasteHTML(html_content);
2129 // Content duplication bug fix
2130 if (tinyMCE.isIE && tinyMCE.settings.fix_content_duplication) {
2131 // Remove P elements in P elements
2132 paras = doc.getElementsByTagName("P");
2133 for (i=0; i<paras.length; i++) {
2136 while ((node = node.parentNode) != null) {
2137 if (node.nodeName == "P")
2138 node.outerHTML = node.innerHTML;
2142 // Content duplication bug fix (Seems to be word crap)
2143 html = doc.body.innerHTML;
2145 // Always set the htmlText output
2146 tinyMCE.setInnerHTML(doc.body, html);
2149 tinyMCE.cleanupAnchors(doc);
2151 if (tinyMCE.getParam("convert_fonts_to_spans"))
2152 tinyMCE.convertSpansToFonts(doc);
2155 getEditorId : function(form_element) {
2156 var inst = this.getInstanceById(form_element);
2161 return inst.editorId;
2164 getInstanceById : function(editor_id) {
2165 var inst = this.instances[editor_id], n;
2168 for (n in tinyMCE.instances) {
2169 inst = tinyMCE.instances[n];
2171 if (!tinyMCE.isInstance(inst))
2174 if (inst.formTargetElementId == editor_id)
2183 queryInstanceCommandValue : function(editor_id, command) {
2184 var inst = tinyMCE.getInstanceById(editor_id);
2187 return inst.queryCommandValue(command);
2192 queryInstanceCommandState : function(editor_id, command) {
2193 var inst = tinyMCE.getInstanceById(editor_id);
2196 return inst.queryCommandState(command);
2201 setWindowArg : function(n, v) {
2202 this.windowArgs[n] = v;
2205 getWindowArg : function(n, d) {
2206 return (typeof(this.windowArgs[n]) == "undefined") ? d : this.windowArgs[n];
2209 getCSSClasses : function(editor_id, doc) {
2210 var i, c, x, rule, styles, rules, csses, selectorText, inst = tinyMCE.getInstanceById(editor_id);
2211 var cssClass, addClass, p;
2214 inst = tinyMCE.selectedInstance;
2220 doc = inst.getDoc();
2222 // Is cached, use that
2223 if (inst && inst.cssClasses.length > 0)
2224 return inst.cssClasses;
2229 styles = doc.styleSheets;
2231 if (styles && styles.length > 0) {
2232 for (x=0; x<styles.length; x++) {
2236 csses = tinyMCE.isIE ? doc.styleSheets(x).rules : styles[x].cssRules;
2238 // Just ignore any errors I know this is ugly!!
2244 for (i=0; i<csses.length; i++) {
2245 selectorText = csses[i].selectorText;
2247 // Can be multiple rules per selector
2249 rules = selectorText.split(',');
2250 for (c=0; c<rules.length; c++) {
2253 // Strip spaces between selectors
2254 while (rule.indexOf(' ') == 0)
2255 rule = rule.substring(1);
2258 if (rule.indexOf(' ') != -1 || rule.indexOf(':') != -1 || rule.indexOf('mceItem') != -1)
2261 if (rule.indexOf(tinyMCE.settings.visual_table_class) != -1 || rule.indexOf('mceEditable') != -1 || rule.indexOf('mceNonEditable') != -1)
2265 if (rule.indexOf('.') != -1) {
2266 cssClass = rule.substring(rule.indexOf('.') + 1);
2269 for (p=0; p<inst.cssClasses.length && addClass; p++) {
2270 if (inst.cssClasses[p] == cssClass)
2275 inst.cssClasses[inst.cssClasses.length] = cssClass;
2283 return inst.cssClasses;
2286 regexpReplace : function(in_str, reg_exp, replace_str, opts) {
2292 if (typeof(opts) == "undefined")
2295 re = new RegExp(reg_exp, opts);
2297 return in_str.replace(re, replace_str);
2300 trim : function(s) {
2301 return s.replace(/^\s*|\s*$/g, "");
2304 cleanupEventStr : function(s) {
2306 s = s.replace('function anonymous()\n{\n', '');
2307 s = s.replace('\n}', '');
2308 s = s.replace(/^return true;/gi, ''); // Remove event blocker
2313 getControlHTML : function(c) {
2314 var i, l, n, o, v, rtl = tinyMCE.getLang('lang_dir') == 'rtl';
2316 l = tinyMCE.plugins;
2320 if (o.getControlHTML && (v = o.getControlHTML(c)) !== '') {
2322 return '<span dir="rtl">' + tinyMCE.replaceVar(v, "pluginurl", o.baseURL) + '</span>';
2324 return tinyMCE.replaceVar(v, "pluginurl", o.baseURL);
2328 o = tinyMCE.themes[tinyMCE.settings.theme];
2329 if (o.getControlHTML && (v = o.getControlHTML(c)) !== '') {
2331 return '<span dir="rtl">' + v + '</span>';
2339 evalFunc : function(f, idx, a, o) {
2340 o = !o ? window : o;
2341 f = typeof(f) == 'function' ? f : o[f];
2343 return f.apply(o, Array.prototype.slice.call(a, idx));
2346 dispatchCallback : function(i, p, n) {
2347 return this.callFunc(i, p, n, 0, this.dispatchCallback.arguments);
2350 executeCallback : function(i, p, n) {
2351 return this.callFunc(i, p, n, 1, this.executeCallback.arguments);
2354 execCommandCallback : function(i, p, n) {
2355 return this.callFunc(i, p, n, 2, this.execCommandCallback.arguments);
2358 callFunc : function(ins, p, n, m, a) {
2359 var l, i, on, o, s, v;
2363 l = tinyMCE.getParam(p, '');
2365 if (l !== '' && (v = tinyMCE.evalFunc(l, 3, a)) == s && m > 0)
2369 for (i=0, l = ins.plugins; i<l.length; i++) {
2370 o = tinyMCE.plugins[l[i]];
2372 if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0)
2381 if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0)
2388 resolveDots : function(s, o) {
2391 if (typeof(s) == 'string') {
2392 for (i=0, s=s.split('.'); i<s.length; i++)
2400 xmlEncode : function(s) {
2401 return s ? ('' + s).replace(this.xmlEncodeRe, function (c, b) {
2420 add : function(c, m) {
2424 c.prototype[n] = m[n];
2427 extend : function(p, np) {
2441 hideMenus : function() {
2442 var e = tinyMCE.lastSelectedMenuBtn;
2444 if (tinyMCE.lastMenu) {
2445 tinyMCE.lastMenu.hide();
2446 tinyMCE.lastMenu = null;
2450 tinyMCE.switchClass(e, tinyMCE.lastMenuBtnClass);
2451 tinyMCE.lastSelectedMenuBtn = null;
2458 var TinyMCE = TinyMCE_Engine; // Compatiblity with gzip compressors
2459 var tinyMCE = new TinyMCE_Engine();
2460 var tinyMCELang = {};
2462 /* file:jscripts/tiny_mce/classes/TinyMCE_Control.class.js */
2464 function TinyMCE_Control(settings) {
2465 var t, i, tos, fu, p, x, fn, fu, pn, s = settings;
2467 this.undoRedoLevel = true;
2468 this.isTinyMCE_Control = true;
2471 this.enabled = true;
2473 this.settings.theme = tinyMCE.getParam("theme", "default");
2474 this.settings.width = tinyMCE.getParam("width", -1);
2475 this.settings.height = tinyMCE.getParam("height", -1);
2476 this.selection = new TinyMCE_Selection(this);
2477 this.undoRedo = new TinyMCE_UndoRedo(this);
2478 this.cleanup = new TinyMCE_Cleanup();
2479 this.shortcuts = [];
2480 this.hasMouseMoved = false;
2481 this.foreColor = this.backColor = "#999999";
2483 this.cssClasses = [];
2486 valid_elements : s.valid_elements,
2487 extended_valid_elements : s.extended_valid_elements,
2488 valid_child_elements : s.valid_child_elements,
2489 entities : s.entities,
2490 entity_encoding : s.entity_encoding,
2491 debug : s.cleanup_debug,
2492 indent : s.apply_source_formatting,
2493 invalid_elements : s.invalid_elements,
2494 verify_html : s.verify_html,
2495 fix_content_duplication : s.fix_content_duplication,
2496 convert_fonts_to_spans : s.convert_fonts_to_spans
2500 t = this.settings.theme;
2501 if (!tinyMCE.hasTheme(t)) {
2502 fn = tinyMCE.callbacks;
2505 for (i=0; i<fn.length; i++) {
2506 if ((fu = window['TinyMCE_' + t + "_" + fn[i]]))
2510 tinyMCE.addTheme(t, tos);
2515 p = tinyMCE.getParam('plugins', '', true, ',');
2517 for (i=0; i<p.length; i++) {
2520 if (pn.charAt(0) == '-')
2521 pn = pn.substring(1);
2523 if (!tinyMCE.hasPlugin(pn)) {
2524 fn = tinyMCE.callbacks;
2527 for (x=0; x<fn.length; x++) {
2528 if ((fu = window['TinyMCE_' + pn + "_" + fn[x]]))
2532 tinyMCE.addPlugin(pn, tos);
2535 this.plugins[this.plugins.length] = pn;
2540 TinyMCE_Control.prototype = {
2547 getData : function(na) {
2548 var o = this.data[na];
2551 o = this.data[na] = {};
2556 hasPlugin : function(n) {
2559 for (i=0; i<this.plugins.length; i++) {
2560 if (this.plugins[i] == n)
2567 addPlugin : function(n, p) {
2568 if (!this.hasPlugin(n)) {
2569 tinyMCE.addPlugin(n, p);
2570 this.plugins[this.plugins.length] = n;
2574 repaint : function() {
2577 if (tinyMCE.isRealIE)
2582 b = s.getBookmark(true);
2583 this.getBody().style.display = 'none';
2584 this.getDoc().execCommand('selectall', false, null);
2585 this.getSel().collapseToStart();
2586 this.getBody().style.display = 'block';
2587 s.moveToBookmark(b);
2593 switchSettings : function() {
2594 if (tinyMCE.configs.length > 1 && tinyMCE.currentConfig != this.settings.index) {
2595 tinyMCE.settings = this.settings;
2596 tinyMCE.currentConfig = this.settings.index;
2600 select : function() {
2601 var oldInst = tinyMCE.selectedInstance;
2603 if (oldInst != this) {
2605 oldInst.execCommand('mceEndTyping');
2607 tinyMCE.dispatchCallback(this, 'select_instance_callback', 'selectInstance', this, oldInst);
2608 tinyMCE.selectedInstance = this;
2612 getBody : function() {
2613 return this.contentBody ? this.contentBody : this.getDoc().body;
2616 getDoc : function() {
2617 // return this.contentDocument ? this.contentDocument : this.contentWindow.document; // Removed due to IE 5.5 ?
2618 return this.contentWindow.document;
2621 getWin : function() {
2622 return this.contentWindow;
2625 getContainerWin : function() {
2626 return this.containerWindow ? this.containerWindow : window;
2629 getViewPort : function() {
2630 return tinyMCE.getViewPort(this.getWin());
2633 getParentNode : function(n, f) {
2634 return tinyMCE.getParentNode(n, f, this.getBody());
2637 getParentElement : function(n, na, f) {
2638 return tinyMCE.getParentElement(n, na, f, this.getBody());
2641 getParentBlockElement : function(n) {
2642 return tinyMCE.getParentBlockElement(n, this.getBody());
2645 resizeToContent : function() {
2646 var d = this.getDoc(), b = d.body, de = d.documentElement;
2648 this.iframeElement.style.height = (tinyMCE.isRealIE) ? b.scrollHeight : de.offsetHeight + 'px';
2651 addShortcut : function(m, k, d, cmd, ui, va) {
2652 var n = typeof(k) == "number", ie = tinyMCE.isIE, c, sc, i, scl = this.shortcuts;
2654 if (!tinyMCE.getParam('custom_shortcuts'))
2657 m = m.toLowerCase();
2658 k = ie && !n ? k.toUpperCase() : k;
2659 c = n ? null : k.charCodeAt(0);
2660 d = d && d.indexOf('lang_') == 0 ? tinyMCE.getLang(d) : d;
2663 alt : m.indexOf('alt') != -1,
2664 ctrl : m.indexOf('ctrl') != -1,
2665 shift : m.indexOf('shift') != -1,
2667 keyCode : n ? k : (ie ? c : null),
2674 for (i=0; i<scl.length; i++) {
2675 if (sc.alt == scl[i].alt && sc.ctrl == scl[i].ctrl && sc.shift == scl[i].shift
2676 && sc.charCode == scl[i].charCode && sc.keyCode == scl[i].keyCode) {
2681 scl[scl.length] = sc;
2686 handleShortcut : function(e) {
2689 // Normal key press, then ignore it
2690 if (!e.altKey && !e.ctrlKey)
2695 for (i=0; i<s.length; i++) {
2698 if (o.alt == e.altKey && o.ctrl == e.ctrlKey && (o.keyCode == e.keyCode || o.charCode == e.charCode)) {
2699 if (o.cmd && (e.type == "keydown" || (e.type == "keypress" && !tinyMCE.isOpera)))
2700 tinyMCE.execCommand(o.cmd, o.ui, o.val);
2702 tinyMCE.cancelEvent(e);
2710 autoResetDesignMode : function() {
2711 // Add fix for tab/style.display none/block problems in Gecko
2712 if (!tinyMCE.isIE && this.isHidden() && tinyMCE.getParam('auto_reset_designmode'))
2713 eval('try { this.getDoc().designMode = "On"; this.useCSS = false; } catch(e) {}');
2716 isHidden : function() {
2724 // Weird, wheres that cursor selection?
2725 return (!s || !s.rangeCount || s.rangeCount == 0);
2728 isDirty : function() {
2729 // Is content modified and not in a submit procedure
2730 return tinyMCE.trim(this.startContent) != tinyMCE.trim(this.getBody().innerHTML) && !this.isNotDirty;
2733 _mergeElements : function(scmd, pa, ch, override) {
2734 var st, stc, className, n;
2736 if (scmd == "removeformat") {
2738 pa.style.cssText = "";
2740 ch.style.cssText = "";
2744 st = tinyMCE.parseStyle(tinyMCE.getAttrib(pa, "style"));
2745 stc = tinyMCE.parseStyle(tinyMCE.getAttrib(ch, "style"));
2746 className = tinyMCE.getAttrib(pa, "class");
2748 // Removed class adding due to bug #1478272
2749 className = tinyMCE.getAttrib(ch, "class");
2753 if (typeof(st[n]) == 'function')
2760 if (typeof(stc[n]) == 'function')
2767 tinyMCE.setAttrib(pa, "style", tinyMCE.serializeStyle(st));
2768 tinyMCE.setAttrib(pa, "class", tinyMCE.trim(className));
2770 ch.style.cssText = "";
2771 ch.removeAttribute("class");
2772 ch.removeAttribute("style");
2775 _fixRootBlocks : function() {
2776 var rb, b, ne, be, nx, bm;
2778 rb = tinyMCE.getParam('forced_root_block');
2786 nx = ne.nextSibling;
2788 // If text node or inline element wrap it in a block element
2789 if (ne.nodeType == 3 || !tinyMCE.blockRegExp.test(ne.nodeName)) {
2791 bm = this.selection.getBookmark();
2794 be = this.getDoc().createElement(rb);
2795 be.appendChild(ne.cloneNode(true));
2796 b.replaceChild(be, ne);
2798 be.appendChild(ne.cloneNode(true));
2808 this.selection.moveToBookmark(bm);
2811 _fixTrailingNbsp : function() {
2812 var s = this.selection, e = s.getFocusElement(), bm, v;
2814 if (e && tinyMCE.blockRegExp.test(e.nodeName) && e.firstChild) {
2815 v = e.firstChild.nodeValue;
2817 if (v && v.length > 1 && /(^\u00a0|\u00a0$)/.test(v)) {
2818 e.firstChild.nodeValue = v.replace(/(^\u00a0|\u00a0$)/, '');
2819 s.selectNode(e.firstChild, true, false, false); // Select and collapse
2824 _setUseCSS : function(b) {
2825 var d = this.getDoc();
2827 try {d.execCommand("useCSS", false, !b);} catch (ex) {}
2828 try {d.execCommand("styleWithCSS", false, b);} catch (ex) {}
2830 if (!tinyMCE.getParam("table_inline_editing"))
2831 try {d.execCommand('enableInlineTableEditing', false, "false");} catch (ex) {}
2833 if (!tinyMCE.getParam("object_resizing"))
2834 try {d.execCommand('enableObjectResizing', false, "false");} catch (ex) {}
2837 execCommand : function(command, user_interface, value) {
2838 var i, x, z, align, img, div, doc = this.getDoc(), win = this.getWin(), focusElm = this.getFocusElement();
2840 // Is not a undo specific command
2841 if (!new RegExp('mceStartTyping|mceEndTyping|mceBeginUndoLevel|mceEndUndoLevel|mceAddUndoLevel', 'gi').test(command))
2842 this.undoBookmark = null;
2845 if (!tinyMCE.isIE && !this.useCSS) {
2846 this._setUseCSS(false);
2850 //debug("command: " + command + ", user_interface: " + user_interface + ", value: " + value);
2851 this.contentDocument = doc; // <-- Strange, unless this is applied Mozilla 1.3 breaks
2853 // Don't dispatch key commands
2854 if (!/mceStartTyping|mceEndTyping/.test(command)) {
2855 if (tinyMCE.execCommandCallback(this, 'execcommand_callback', 'execCommand', this.editorId, this.getBody(), command, user_interface, value))
2859 // Fix align on images
2860 if (focusElm && focusElm.nodeName == "IMG") {
2861 align = focusElm.getAttribute('align');
2862 img = command == "JustifyCenter" ? focusElm.cloneNode(false) : focusElm;
2866 if (align == 'left')
2867 img.removeAttribute('align');
2869 img.setAttribute('align', 'left');
2872 div = focusElm.parentNode;
2873 if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
2874 div.parentNode.replaceChild(img, div);
2876 this.selection.selectNode(img);
2878 tinyMCE.triggerNodeChange();
2881 case "JustifyCenter":
2882 img.removeAttribute('align');
2885 div = tinyMCE.getParentElement(focusElm, "div");
2886 if (div && div.style.textAlign == "center") {
2888 if (div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
2889 div.parentNode.replaceChild(img, div);
2892 div = this.getDoc().createElement("div");
2893 div.style.textAlign = 'center';
2894 div.appendChild(img);
2895 focusElm.parentNode.replaceChild(div, focusElm);
2898 this.selection.selectNode(img);
2900 tinyMCE.triggerNodeChange();
2903 case "JustifyRight":
2904 if (align == 'right')
2905 img.removeAttribute('align');
2907 img.setAttribute('align', 'right');
2910 div = focusElm.parentNode;
2911 if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
2912 div.parentNode.replaceChild(img, div);
2914 this.selection.selectNode(img);
2916 tinyMCE.triggerNodeChange();
2921 if (tinyMCE.settings.force_br_newlines) {
2922 var alignValue = "";
2924 if (doc.selection.type != "Control") {
2927 alignValue = "left";
2930 case "JustifyCenter":
2931 alignValue = "center";
2935 alignValue = "justify";
2938 case "JustifyRight":
2939 alignValue = "right";
2943 if (alignValue !== '') {
2944 var rng = doc.selection.createRange();
2946 if ((divElm = tinyMCE.getParentElement(rng.parentElement(), "div")) != null)
2947 divElm.setAttribute("align", alignValue);
2948 else if (rng.pasteHTML && rng.htmlText.length > 0)
2949 rng.pasteHTML('<div align="' + alignValue + '">' + rng.htmlText + "</div>");
2951 tinyMCE.triggerNodeChange();
2963 // Unlink if caret is inside link
2964 if (tinyMCE.isGecko && this.getSel().isCollapsed) {
2965 focusElm = tinyMCE.getParentElement(focusElm, 'A');
2968 this.selection.selectNode(focusElm, false);
2971 this.getDoc().execCommand(command, user_interface, value);
2973 tinyMCE.isGecko && this.getSel().collapseToEnd();
2975 tinyMCE.triggerNodeChange();
2979 case "InsertUnorderedList":
2980 case "InsertOrderedList":
2981 this.getDoc().execCommand(command, user_interface, value);
2982 tinyMCE.triggerNodeChange();
2985 case "Strikethrough":
2986 this.getDoc().execCommand(command, user_interface, value);
2987 tinyMCE.triggerNodeChange();
2990 case "mceSelectNode":
2991 this.selection.selectNode(value);
2992 tinyMCE.triggerNodeChange();
2993 tinyMCE.selectedNode = value;
2997 if (value == null || value == '') {
2998 var elm = tinyMCE.getParentElement(this.getFocusElement(), "p,div,h1,h2,h3,h4,h5,h6,pre,address,blockquote,dt,dl,dd,samp");
3001 this.execCommand("mceRemoveNode", false, elm);
3003 if (!this.cleanup.isValid(value))
3006 if (tinyMCE.isGecko && new RegExp('<(div|blockquote|code|dt|dd|dl|samp)>', 'gi').test(value))
3007 value = value.replace(/[^a-z]/gi, '');
3009 if (tinyMCE.isIE && new RegExp('blockquote|code|samp', 'gi').test(value)) {
3010 var b = this.selection.getBookmark();
3011 this.getDoc().execCommand("FormatBlock", false, '<p>');
3012 tinyMCE.renameElement(tinyMCE.getParentBlockElement(this.getFocusElement()), value);
3013 this.selection.moveToBookmark(b);
3015 this.getDoc().execCommand("FormatBlock", false, value);
3018 tinyMCE.triggerNodeChange();
3022 case "mceRemoveNode":
3024 value = tinyMCE.getParentElement(this.getFocusElement());
3027 value.outerHTML = value.innerHTML;
3029 var rng = value.ownerDocument.createRange();
3030 rng.setStartBefore(value);
3031 rng.setEndAfter(value);
3032 rng.deleteContents();
3033 rng.insertNode(rng.createContextualFragment(value.innerHTML));
3036 tinyMCE.triggerNodeChange();
3040 case "mceSelectNodeDepth":
3041 var parentNode = this.getFocusElement();
3042 for (i=0; parentNode; i++) {
3043 if (parentNode.nodeName.toLowerCase() == "body")
3046 if (parentNode.nodeName.toLowerCase() == "#text") {
3048 parentNode = parentNode.parentNode;
3053 this.selection.selectNode(parentNode, false);
3054 tinyMCE.triggerNodeChange();
3055 tinyMCE.selectedNode = parentNode;
3059 parentNode = parentNode.parentNode;
3064 case "mceSetStyleInfo":
3065 case "SetStyleInfo":
3066 var rng = this.getRng();
3067 var sel = this.getSel();
3068 var scmd = value.command;
3069 var sname = value.name;
3070 var svalue = value.value == null ? '' : value.value;
3071 //var svalue = value['value'] == null ? '' : value['value'];
3072 var wrapper = value.wrapper ? value.wrapper : "span";
3073 var parentElm = null;
3074 var invalidRe = new RegExp("^BODY|HTML$", "g");
3075 var invalidParentsRe = tinyMCE.settings.merge_styles_invalid_parents !== '' ? new RegExp(tinyMCE.settings.merge_styles_invalid_parents, "gi") : null;
3077 // Whole element selected check
3081 parentElm = rng.item(0);
3083 var pelm = rng.parentElement();
3084 var prng = doc.selection.createRange();
3085 prng.moveToElementText(pelm);
3087 if (rng.htmlText == prng.htmlText || rng.boundingWidth == 0) {
3088 if (invalidParentsRe == null || !invalidParentsRe.test(pelm.nodeName))
3093 var felm = this.getFocusElement();
3094 if (sel.isCollapsed || (new RegExp('td|tr|tbody|table|img', 'gi').test(felm.nodeName) && sel.anchorNode == felm.parentNode))
3098 // Whole element selected
3099 if (parentElm && !invalidRe.test(parentElm.nodeName)) {
3100 if (scmd == "setstyle")
3101 tinyMCE.setStyleAttrib(parentElm, sname, svalue);
3103 if (scmd == "setattrib")
3104 tinyMCE.setAttrib(parentElm, sname, svalue);
3106 if (scmd == "removeformat") {
3107 parentElm.style.cssText = '';
3108 tinyMCE.setAttrib(parentElm, 'class', '');
3111 // Remove style/attribs from all children
3112 var ch = tinyMCE.getNodeTree(parentElm, [], 1);
3113 for (z=0; z<ch.length; z++) {
3114 if (ch[z] == parentElm)
3117 if (scmd == "setstyle")
3118 tinyMCE.setStyleAttrib(ch[z], sname, '');
3120 if (scmd == "setattrib")
3121 tinyMCE.setAttrib(ch[z], sname, '');
3123 if (scmd == "removeformat") {
3124 ch[z].style.cssText = '';
3125 tinyMCE.setAttrib(ch[z], 'class', '');
3129 this._setUseCSS(false); // Bug in FF when running in fullscreen
3130 doc.execCommand("FontName", false, "#mce_temp_font#");
3131 var elementArray = tinyMCE.getElementsByAttributeValue(this.getBody(), "font", "face", "#mce_temp_font#");
3134 for (x=0; x<elementArray.length; x++) {
3135 elm = elementArray[x];
3137 var spanElm = doc.createElement(wrapper);
3139 if (scmd == "setstyle")
3140 tinyMCE.setStyleAttrib(spanElm, sname, svalue);
3142 if (scmd == "setattrib")
3143 tinyMCE.setAttrib(spanElm, sname, svalue);
3145 if (scmd == "removeformat") {
3146 spanElm.style.cssText = '';
3147 tinyMCE.setAttrib(spanElm, 'class', '');
3150 if (elm.hasChildNodes()) {
3151 for (i=0; i<elm.childNodes.length; i++)
3152 spanElm.appendChild(elm.childNodes[i].cloneNode(true));
3155 spanElm.setAttribute("mce_new", "true");
3156 elm.parentNode.replaceChild(spanElm, elm);
3158 // Remove style/attribs from all children
3159 var ch = tinyMCE.getNodeTree(spanElm, [], 1);
3160 for (z=0; z<ch.length; z++) {
3161 if (ch[z] == spanElm)
3164 if (scmd == "setstyle")
3165 tinyMCE.setStyleAttrib(ch[z], sname, '');
3167 if (scmd == "setattrib")
3168 tinyMCE.setAttrib(ch[z], sname, '');
3170 if (scmd == "removeformat") {
3171 ch[z].style.cssText = '';
3172 tinyMCE.setAttrib(ch[z], 'class', '');
3180 var nodes = doc.getElementsByTagName(wrapper);
3181 for (i=nodes.length-1; i>=0; i--) {
3183 var isNew = tinyMCE.getAttrib(elm, "mce_new") == "true";
3185 elm.removeAttribute("mce_new");
3187 // Is only child a element
3188 if (elm.childNodes && elm.childNodes.length == 1 && elm.childNodes[0].nodeType == 1) {
3189 //tinyMCE.debug("merge1" + isNew);
3190 this._mergeElements(scmd, elm, elm.childNodes[0], isNew);
3194 // Is I the only child
3195 if (elm.parentNode.childNodes.length == 1 && !invalidRe.test(elm.nodeName) && !invalidRe.test(elm.parentNode.nodeName)) {
3196 //tinyMCE.debug("merge2" + isNew + "," + elm.nodeName + "," + elm.parentNode.nodeName);
3197 if (invalidParentsRe == null || !invalidParentsRe.test(elm.parentNode.nodeName))
3198 this._mergeElements(scmd, elm.parentNode, elm, false);
3202 // Remove empty wrappers
3203 var nodes = doc.getElementsByTagName(wrapper);
3204 for (i=nodes.length-1; i>=0; i--) {
3205 var elm = nodes[i], isEmpty = true;
3207 // Check if it has any attribs
3208 var tmp = doc.createElement("body");
3209 tmp.appendChild(elm.cloneNode(false));
3211 // Is empty span, remove it
3212 tmp.innerHTML = tmp.innerHTML.replace(new RegExp('style=""|class=""', 'gi'), '');
3213 //tinyMCE.debug(tmp.innerHTML);
3214 if (new RegExp('<span>', 'gi').test(tmp.innerHTML)) {
3215 for (x=0; x<elm.childNodes.length; x++) {
3216 if (elm.parentNode != null)
3217 elm.parentNode.insertBefore(elm.childNodes[x].cloneNode(true), elm);
3220 elm.parentNode.removeChild(elm);
3224 // Re add the visual aids
3225 if (scmd == "removeformat")
3226 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
3228 tinyMCE.triggerNodeChange();
3233 if (value == null) {
3234 var s = this.getSel();
3236 // Find font and select it
3237 if (tinyMCE.isGecko && s.isCollapsed) {
3238 var f = tinyMCE.getParentElement(this.getFocusElement(), "font");
3241 this.selection.selectNode(f, false);
3245 this.getDoc().execCommand("RemoveFormat", false, null);
3247 // Collapse range if font was found
3248 if (f != null && tinyMCE.isGecko) {
3249 var r = this.getRng().cloneRange();
3251 s.removeAllRanges();
3255 this.getDoc().execCommand('FontName', false, value);
3257 if (tinyMCE.isGecko)
3258 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
3263 this.getDoc().execCommand('FontSize', false, value);
3265 if (tinyMCE.isGecko)
3266 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
3271 value = value == null ? this.foreColor : value;
3272 value = tinyMCE.trim(value);
3273 value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value;
3275 this.foreColor = value;
3276 this.getDoc().execCommand('forecolor', false, value);
3280 value = value == null ? this.backColor : value;
3281 value = tinyMCE.trim(value);
3282 value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value;
3283 this.backColor = value;
3285 if (tinyMCE.isGecko) {
3286 this._setUseCSS(true);
3287 this.getDoc().execCommand('hilitecolor', false, value);
3288 this._setUseCSS(false);
3290 this.getDoc().execCommand('BackColor', false, value);
3296 var cmdFailed = false;
3298 // Try executing command
3299 eval('try {this.getDoc().execCommand(command, user_interface, value);} catch (e) {cmdFailed = true;}');
3301 if (tinyMCE.isOpera && cmdFailed)
3302 alert('Currently not supported by your browser, use keyboard shortcuts instead.');
3304 // Alert error in gecko if command failed
3305 if (tinyMCE.isGecko && cmdFailed) {
3306 // Confirm more info
3307 if (confirm(tinyMCE.entityDecode(tinyMCE.getLang('lang_clipboard_msg'))))
3308 window.open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', 'mceExternal');
3312 tinyMCE.triggerNodeChange();
3315 case "mceSetContent":
3319 // Call custom cleanup code
3320 value = tinyMCE.storeAwayURLs(value);
3321 value = tinyMCE._customCleanup(this, "insert_to_editor", value);
3323 if (this.getBody().nodeName == 'BODY')
3324 tinyMCE._setHTML(doc, value);
3326 this.getBody().innerHTML = value;
3328 tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, doc, this.settings, this.getBody(), false, false, false, true));
3329 tinyMCE.convertAllRelativeURLs(this.getBody());
3331 // Cleanup any mess left from storyAwayURLs
3332 tinyMCE._removeInternal(this.getBody());
3334 // When editing always use fonts internaly
3335 if (tinyMCE.getParam("convert_fonts_to_spans"))
3336 tinyMCE.convertSpansToFonts(doc);
3338 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
3339 tinyMCE._setEventsEnabled(this.getBody(), false);
3345 var b = this.selection.getBookmark();
3346 tinyMCE._setHTML(this.contentDocument, this.getBody().innerHTML);
3347 tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, this.contentDocument, this.settings, this.getBody(), this.visualAid));
3348 tinyMCE.convertAllRelativeURLs(doc.body);
3350 // When editing always use fonts internaly
3351 if (tinyMCE.getParam("convert_fonts_to_spans"))
3352 tinyMCE.convertSpansToFonts(doc);
3354 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
3355 tinyMCE._setEventsEnabled(this.getBody(), false);
3358 this.selection.moveToBookmark(b);
3359 tinyMCE.triggerNodeChange();
3362 case "mceReplaceContent":
3363 // Force empty string
3367 this.getWin().focus();
3369 var selectedText = "";
3372 var rng = doc.selection.createRange();
3373 selectedText = rng.text;
3375 selectedText = this.getSel().toString();
3377 if (selectedText.length > 0) {
3378 value = tinyMCE.replaceVar(value, "selection", selectedText);
3379 tinyMCE.execCommand('mceInsertContent', false, value);
3383 tinyMCE.triggerNodeChange();
3386 case "mceSetAttribute":
3387 if (typeof(value) == 'object') {
3388 var targetElms = (typeof(value.targets) == "undefined") ? "p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address" : value.targets;
3389 var targetNode = tinyMCE.getParentElement(this.getFocusElement(), targetElms);
3392 targetNode.setAttribute(value.name, value.value);
3393 tinyMCE.triggerNodeChange();
3398 case "mceSetCSSClass":
3399 this.execCommand("mceSetStyleInfo", false, {command : "setattrib", name : "class", value : value});
3402 case "mceInsertRawHTML":
3403 var key = 'tiny_mce_marker';
3405 this.execCommand('mceBeginUndoLevel');
3407 // Insert marker key
3408 this.execCommand('mceInsertContent', false, key);
3410 // Store away scroll pos
3411 var scrollX = this.getBody().scrollLeft + this.getDoc().documentElement.scrollLeft;
3412 var scrollY = this.getBody().scrollTop + this.getDoc().documentElement.scrollTop;
3414 // Find marker and replace with RAW HTML
3415 var html = this.getBody().innerHTML;
3416 if ((pos = html.indexOf(key)) != -1)
3417 tinyMCE.setInnerHTML(this.getBody(), html.substring(0, pos) + value + html.substring(pos + key.length));
3419 // Restore scoll pos
3420 this.contentWindow.scrollTo(scrollX, scrollY);
3422 this.execCommand('mceEndUndoLevel');
3426 case "mceInsertContent":
3427 // Force empty string
3431 var insertHTMLFailed = false;
3433 // Removed since it produced problems in IE
3434 // this.getWin().focus();
3436 if (tinyMCE.isGecko || tinyMCE.isOpera) {
3438 // Is plain text or HTML, &, etc will be encoded wrong in FF
3439 if (value.indexOf('<') == -1 && !value.match(/(&| |<|>)/g)) {
3440 var r = this.getRng();
3441 var n = this.getDoc().createTextNode(tinyMCE.entityDecode(value));
3442 var s = this.getSel();
3443 var r2 = r.cloneRange();
3445 // Insert text at cursor position
3446 s.removeAllRanges();
3450 // Move the cursor to the end of text
3453 s.removeAllRanges();
3456 value = tinyMCE.fixGeckoBaseHREFBug(1, this.getDoc(), value);
3457 this.getDoc().execCommand('inserthtml', false, value);
3458 tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
3461 insertHTMLFailed = true;
3464 if (!insertHTMLFailed) {
3465 tinyMCE.triggerNodeChange();
3470 if (!tinyMCE.isIE) {
3471 var isHTML = value.indexOf('<') != -1;
3472 var sel = this.getSel();
3473 var rng = this.getRng();
3476 if (tinyMCE.isSafari) {
3477 var tmpRng = this.getDoc().createRange();
3479 tmpRng.setStart(this.getBody(), 0);
3480 tmpRng.setEnd(this.getBody(), 0);
3482 value = tmpRng.createContextualFragment(value);
3484 value = rng.createContextualFragment(value);
3487 value = doc.createTextNode(tinyMCE.entityDecode(value));
3490 // Insert plain text in Safari
3491 if (tinyMCE.isSafari && !isHTML) {
3492 this.execCommand('InsertText', false, value.nodeValue);
3493 tinyMCE.triggerNodeChange();
3495 } else if (tinyMCE.isSafari && isHTML) {
3496 rng.deleteContents();
3497 rng.insertNode(value);
3498 tinyMCE.triggerNodeChange();
3502 rng.deleteContents();
3504 // If target node is text do special treatment, (Mozilla 1.3 fix)
3505 if (rng.startContainer.nodeType == 3) {
3506 var node = rng.startContainer.splitText(rng.startOffset);
3507 node.parentNode.insertBefore(value, node);
3509 rng.insertNode(value);
3512 // Removes weird selection trails
3513 sel.selectAllChildren(doc.body);
3514 sel.removeAllRanges();
3516 // Move cursor to end of content
3517 var rng = doc.createRange();
3519 rng.selectNode(value);
3520 rng.collapse(false);
3524 rng.collapse(false);
3526 tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
3528 var rng = doc.selection.createRange(), tmpRng = null;
3529 var c = value.indexOf('<!--') != -1;
3531 // Fix comment bug, add tag before comments
3533 value = tinyMCE.uniqueTag + value;
3535 // tmpRng = rng.duplicate(); // Store away range (Fixes Undo bookmark bug in IE)
3538 rng.item(0).outerHTML = value;
3540 rng.pasteHTML(value);
3543 // tmpRng.select(); // Restore range (Fixes Undo bookmark bug in IE)
3545 // Remove unique tag
3547 var e = this.getDoc().getElementById('mceTMPElement');
3548 e.parentNode.removeChild(e);
3552 tinyMCE.execCommand("mceAddUndoLevel");
3553 tinyMCE.triggerNodeChange();
3556 case "mceStartTyping":
3557 if (tinyMCE.settings.custom_undo_redo && this.undoRedo.typingUndoIndex == -1) {
3558 this.undoRedo.typingUndoIndex = this.undoRedo.undoIndex;
3559 tinyMCE.typingUndoIndex = tinyMCE.undoIndex;
3560 this.execCommand('mceAddUndoLevel');
3564 case "mceEndTyping":
3565 if (tinyMCE.settings.custom_undo_redo && this.undoRedo.typingUndoIndex != -1) {
3566 this.execCommand('mceAddUndoLevel');
3567 this.undoRedo.typingUndoIndex = -1;
3570 tinyMCE.typingUndoIndex = -1;
3573 case "mceBeginUndoLevel":
3574 this.undoRedoLevel = false;
3577 case "mceEndUndoLevel":
3578 this.undoRedoLevel = true;
3579 this.execCommand('mceAddUndoLevel');
3582 case "mceAddUndoLevel":
3583 if (tinyMCE.settings.custom_undo_redo && this.undoRedoLevel) {
3584 if (this.undoRedo.add())
3585 tinyMCE.triggerNodeChange(false);
3590 if (tinyMCE.settings.custom_undo_redo) {
3591 tinyMCE.execCommand("mceEndTyping");
3592 this.undoRedo.undo();
3593 tinyMCE.triggerNodeChange();
3595 this.getDoc().execCommand(command, user_interface, value);
3599 if (tinyMCE.settings.custom_undo_redo) {
3600 tinyMCE.execCommand("mceEndTyping");
3601 this.undoRedo.redo();
3602 tinyMCE.triggerNodeChange();
3604 this.getDoc().execCommand(command, user_interface, value);
3607 case "mceToggleVisualAid":
3608 this.visualAid = !this.visualAid;
3609 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
3610 tinyMCE.triggerNodeChange();
3614 this.getDoc().execCommand(command, user_interface, value);
3615 tinyMCE.triggerNodeChange();
3618 var n = tinyMCE.getParentElement(this.getFocusElement(), "blockquote");
3620 if (n && n.nodeName == "BLOCKQUOTE") {
3621 n.removeAttribute("dir");
3622 n.removeAttribute("style");
3624 } while (n != null && (n = n.parentNode) != null);
3628 case "RemoveFormat":
3629 case "removeformat":
3630 var text = this.selection.getSelectedText();
3632 if (tinyMCE.isOpera) {
3633 this.getDoc().execCommand("RemoveFormat", false, null);
3639 var rng = doc.selection.createRange();
3640 rng.execCommand("RemoveFormat", false, null);
3645 this.execCommand("mceSetStyleInfo", false, {command : "removeformat"});
3647 this.getDoc().execCommand(command, user_interface, value);
3649 this.execCommand("mceSetStyleInfo", false, {command : "removeformat"});
3653 if (text.length == 0)
3654 this.execCommand("mceSetCSSClass", false, "");
3656 tinyMCE.triggerNodeChange();
3660 this.getDoc().execCommand(command, user_interface, value);
3662 if (tinyMCE.isGecko)
3663 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
3665 tinyMCE.triggerNodeChange();
3668 // Add undo level after modification
3669 if (command != "mceAddUndoLevel" && command != "Undo" && command != "Redo" && command != "mceStartTyping" && command != "mceEndTyping")
3670 tinyMCE.execCommand("mceAddUndoLevel");
3673 queryCommandValue : function(c) {
3675 return this.getDoc().queryCommandValue(c);
3681 queryCommandState : function(c) {
3682 return this.getDoc().queryCommandState(c);
3685 _addBogusBR : function() {
3686 var b = this.getBody();
3688 if (tinyMCE.isGecko && !b.hasChildNodes())
3689 b.innerHTML = '<br _moz_editor_bogus_node="TRUE" />';
3692 _onAdd : function(replace_element, form_element_name, target_document) {
3693 var hc, th, tos, editorTemplate, targetDoc, deltaWidth, deltaHeight, html, rng, fragment;
3694 var dynamicIFrame, tElm, doc, parentElm;
3696 th = this.settings.theme;
3697 tos = tinyMCE.themes[th];
3699 targetDoc = target_document ? target_document : document;
3701 this.targetDoc = targetDoc;
3703 tinyMCE.themeURL = tinyMCE.baseURL + "/themes/" + this.settings.theme;
3704 this.settings.themeurl = tinyMCE.themeURL;
3706 if (!replace_element) {
3707 alert("Error: Could not find the target element.");
3711 if (tos.getEditorTemplate)
3712 editorTemplate = tos.getEditorTemplate(this.settings, this.editorId);
3714 deltaWidth = editorTemplate.delta_width ? editorTemplate.delta_width : 0;
3715 deltaHeight = editorTemplate.delta_height ? editorTemplate.delta_height : 0;
3716 html = '<span id="' + this.editorId + '_parent" class="mceEditorContainer">' + editorTemplate.html;
3718 html = tinyMCE.replaceVar(html, "editor_id", this.editorId);
3720 if (!this.settings.default_document)
3721 this.settings.default_document = tinyMCE.baseURL + "/blank.htm";
3723 this.settings.old_width = this.settings.width;
3724 this.settings.old_height = this.settings.height;
3726 // Set default width, height
3727 if (this.settings.width == -1)
3728 this.settings.width = replace_element.offsetWidth;
3730 if (this.settings.height == -1)
3731 this.settings.height = replace_element.offsetHeight;
3733 // Try the style width
3734 if (this.settings.width == 0)
3735 this.settings.width = replace_element.style.width;
3737 // Try the style height
3738 if (this.settings.height == 0)
3739 this.settings.height = replace_element.style.height;
3741 // If no width/height then default to 320x240, better than nothing
3742 if (this.settings.width == 0)
3743 this.settings.width = 320;
3745 if (this.settings.height == 0)
3746 this.settings.height = 240;
3748 this.settings.area_width = parseInt(this.settings.width);
3749 this.settings.area_height = parseInt(this.settings.height);
3750 this.settings.area_width += deltaWidth;
3751 this.settings.area_height += deltaHeight;
3752 this.settings.width_style = "" + this.settings.width;
3753 this.settings.height_style = "" + this.settings.height;
3755 // Special % handling
3756 if (("" + this.settings.width).indexOf('%') != -1)
3757 this.settings.area_width = "100%";
3759 this.settings.width_style += 'px';
3761 if (("" + this.settings.height).indexOf('%') != -1)
3762 this.settings.area_height = "100%";
3764 this.settings.height_style += 'px';
3766 if (("" + replace_element.style.width).indexOf('%') != -1) {
3767 this.settings.width = replace_element.style.width;
3768 this.settings.area_width = "100%";
3769 this.settings.width_style = "100%";
3772 if (("" + replace_element.style.height).indexOf('%') != -1) {
3773 this.settings.height = replace_element.style.height;
3774 this.settings.area_height = "100%";
3775 this.settings.height_style = "100%";
3778 html = tinyMCE.applyTemplate(html);
3780 this.settings.width = this.settings.old_width;
3781 this.settings.height = this.settings.old_height;
3783 this.visualAid = this.settings.visual;
3784 this.formTargetElementId = form_element_name;
3786 // Get replace_element contents
3787 if (replace_element.nodeName == "TEXTAREA" || replace_element.nodeName == "INPUT")
3788 this.startContent = replace_element.value;
3790 this.startContent = replace_element.innerHTML;
3792 // If not text area or input
3793 if (replace_element.nodeName != "TEXTAREA" && replace_element.nodeName != "INPUT") {
3794 this.oldTargetElement = replace_element;
3797 hc = '<input type="hidden" id="' + form_element_name + '" name="' + form_element_name + '" />';
3798 this.oldTargetDisplay = tinyMCE.getStyle(this.oldTargetElement, 'display', 'inline');
3799 this.oldTargetElement.style.display = "none";
3803 if (tinyMCE.isGecko)
3808 // Output HTML and set editable
3809 if (tinyMCE.isGecko) {
3810 rng = replace_element.ownerDocument.createRange();
3811 rng.setStartBefore(replace_element);
3813 fragment = rng.createContextualFragment(html);
3814 tinyMCE.insertAfter(fragment, replace_element);
3816 replace_element.insertAdjacentHTML("beforeBegin", html);
3820 // Just hide the textarea element
3821 this.oldTargetElement = replace_element;
3823 this.oldTargetDisplay = tinyMCE.getStyle(this.oldTargetElement, 'display', 'inline');
3824 this.oldTargetElement.style.display = "none";
3826 // Output HTML and set editable
3827 if (tinyMCE.isGecko) {
3828 rng = replace_element.ownerDocument.createRange();
3829 rng.setStartBefore(replace_element);
3831 fragment = rng.createContextualFragment(html);
3832 tinyMCE.insertAfter(fragment, replace_element);
3834 replace_element.insertAdjacentHTML("beforeBegin", html);
3838 dynamicIFrame = false;
3839 tElm = targetDoc.getElementById(this.editorId);
3841 if (!tinyMCE.isIE) {
3842 // Node case is preserved in XML strict mode
3843 if (tElm && (tElm.nodeName == "SPAN" || tElm.nodeName == "span")) {
3844 tElm = tinyMCE._createIFrame(tElm, targetDoc);
3845 dynamicIFrame = true;
3848 this.targetElement = tElm;
3849 this.iframeElement = tElm;
3850 this.contentDocument = tElm.contentDocument;
3851 this.contentWindow = tElm.contentWindow;
3853 //this.getDoc().designMode = "on";
3855 if (tElm && tElm.nodeName == "SPAN")
3856 tElm = tinyMCE._createIFrame(tElm, targetDoc, targetDoc.parentWindow);
3858 tElm = targetDoc.frames[this.editorId];
3860 this.targetElement = tElm;
3861 this.iframeElement = targetDoc.getElementById(this.editorId);
3863 if (tinyMCE.isOpera) {
3864 this.contentDocument = this.iframeElement.contentDocument;
3865 this.contentWindow = this.iframeElement.contentWindow;
3866 dynamicIFrame = true;
3868 this.contentDocument = tElm.window.document;
3869 this.contentWindow = tElm.window;
3872 this.getDoc().designMode = "on";
3876 doc = this.contentDocument;
3877 if (dynamicIFrame) {
3878 html = tinyMCE.getParam('doctype') + '<html><head xmlns="http://www.w3.org/1999/xhtml"><base href="' + tinyMCE.settings.base_href + '" /><title>blank_page</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body class="mceContentBody"></body></html>';
3881 if (!this.isHidden())
3882 this.getDoc().designMode = "on";
3888 // Failed Mozilla 1.3
3889 this.getDoc().location.href = tinyMCE.baseURL + "/blank.htm";
3893 // This timeout is needed in MSIE 5.5 for some odd reason
3894 // it seems that the document.frames isn't initialized yet?
3896 window.setTimeout("tinyMCE.addEventHandlers(tinyMCE.instances[\"" + this.editorId + "\"]);", 1);
3898 // Setup element references
3899 parentElm = this.targetDoc.getElementById(this.editorId + '_parent');
3900 this.formElement = tinyMCE.isGecko ? parentElm.previousSibling : parentElm.nextSibling;
3902 tinyMCE.setupContent(this.editorId, true);
3907 setBaseHREF : function(u) {
3911 nl = d.getElementsByTagName("base");
3912 b = nl.length > 0 ? nl[0] : null;
3915 nl = d.getElementsByTagName("head");
3916 h = nl.length > 0 ? nl[0] : null;
3918 b = d.createElement("base");
3919 b.setAttribute('href', u);
3922 if (u == '' || u == null)
3923 b.parentNode.removeChild(b);
3925 b.setAttribute('href', u);
3929 getHTML : function(r) {
3930 var h, d = this.getDoc(), b = this.getBody();
3935 h = tinyMCE._cleanupHTML(this, d, this.settings, b, false, true, false, true);
3937 if (tinyMCE.getParam("convert_fonts_to_spans"))
3938 tinyMCE.convertSpansToFonts(d);
3943 setHTML : function(h) {
3944 this.execCommand('mceSetContent', false, h);
3948 getFocusElement : function() {
3949 return this.selection.getFocusElement();
3952 getSel : function() {
3953 return this.selection.getSel();
3956 getRng : function() {
3957 return this.selection.getRng();
3960 triggerSave : function(skip_cleanup, skip_callback) {
3961 var e, nl = [], i, s, content, htm;
3966 this.switchSettings();
3967 s = tinyMCE.settings;
3969 // Force hidden tabs visible while serializing
3970 if (tinyMCE.isRealIE) {
3971 e = this.iframeElement;
3974 if (e.style && e.style.display == 'none') {
3975 e.style.display = 'block';
3976 nl[nl.length] = {elm : e, type : 'style'};
3979 if (e.style && s.hidden_tab_class.length > 0 && e.className.indexOf(s.hidden_tab_class) != -1) {
3980 e.className = s.display_tab_class;
3981 nl[nl.length] = {elm : e, type : 'class'};
3983 } while ((e = e.parentNode) != null)
3986 tinyMCE.settings.preformatted = false;
3989 if (typeof(skip_cleanup) == "undefined")
3990 skip_cleanup = false;
3993 if (typeof(skip_callback) == "undefined")
3994 skip_callback = false;
3996 tinyMCE._setHTML(this.getDoc(), this.getBody().innerHTML);
3998 // Remove visual aids when cleanup is disabled
3999 if (this.settings.cleanup == false) {
4000 tinyMCE.handleVisualAid(this.getBody(), true, false, this);
4001 tinyMCE._setEventsEnabled(this.getBody(), true);
4004 tinyMCE._customCleanup(this, "submit_content_dom", this.contentWindow.document.body);
4005 htm = skip_cleanup ? this.getBody().innerHTML : tinyMCE._cleanupHTML(this, this.getDoc(), this.settings, this.getBody(), tinyMCE.visualAid, true, true);
4006 htm = tinyMCE._customCleanup(this, "submit_content", htm);
4008 if (!skip_callback && tinyMCE.settings.save_callback !== '')
4009 content = tinyMCE.resolveDots(tinyMCE.settings.save_callback, window)(this.formTargetElementId,htm,this.getBody());
4011 // Use callback content if available
4012 if ((typeof(content) != "undefined") && content != null)
4015 // Replace some weird entities (Bug: #1056343)
4016 htm = tinyMCE.regexpReplace(htm, "(", "(", "gi");
4017 htm = tinyMCE.regexpReplace(htm, ")", ")", "gi");
4018 htm = tinyMCE.regexpReplace(htm, ";", ";", "gi");
4019 htm = tinyMCE.regexpReplace(htm, """, """, "gi");
4020 htm = tinyMCE.regexpReplace(htm, "^", "^", "gi");
4022 if (this.formElement)
4023 this.formElement.value = htm;
4025 if (tinyMCE.isSafari && this.formElement)
4026 this.formElement.innerText = htm;
4028 // Hide them again (tabs in MSIE)
4029 for (i=0; i<nl.length; i++) {
4030 if (nl[i].type == 'style')
4031 nl[i].elm.style.display = 'none';
4033 nl[i].elm.className = s.hidden_tab_class;
4039 /* file:jscripts/tiny_mce/classes/TinyMCE_Cleanup.class.js */
4041 tinyMCE.add(TinyMCE_Engine, {
4042 cleanupHTMLCode : function(s) {
4043 s = s.replace(new RegExp('<p \\/>', 'gi'), '<p> </p>');
4044 s = s.replace(new RegExp('<p>\\s*<\\/p>', 'gi'), '<p> </p>');
4046 // Fix close BR elements
4047 s = s.replace(new RegExp('<br>\\s*<\\/br>', 'gi'), '<br />');
4049 // Open closed tags like <b/> to <b></b>
4050 s = s.replace(new RegExp('<(h[1-6]|p|div|address|pre|form|table|li|ol|ul|td|b|font|em|strong|i|strike|u|span|a|ul|ol|li|blockquote)([a-z]*)([^\\\\|>]*)\\/>', 'gi'), '<$1$2$3></$1$2>');
4052 // Remove trailing space <b > to <b>
4053 s = s.replace(new RegExp('\\s+></', 'gi'), '></');
4055 // Close tags <img></img> to <img/>
4056 s = s.replace(new RegExp('<(img|br|hr)([^>]*)><\\/(img|br|hr)>', 'gi'), '<$1$2 />');
4058 // Weird MSIE bug, <p><hr /></p> breaks runtime?
4060 s = s.replace(new RegExp('<p><hr \\/><\\/p>', 'gi'), "<hr>");
4062 // Weird tags will make IE error #bug: 1538495
4064 s = s.replace(/<!(\s*)\/>/g, '');
4066 // Convert relative anchors to absolute URLs ex: #something to file.htm#something
4067 // Removed: Since local document anchors should never be forced absolute example edit.php?id=something
4068 //if (tinyMCE.getParam('convert_urls'))
4069 // s = s.replace(new RegExp('(href=\"{0,1})(\\s*#)', 'gi'), '$1' + tinyMCE.settings.document_base_url + "#");
4074 parseStyle : function(str) {
4075 var ar = [], st, i, re, pa;
4080 st = str.split(';');
4082 tinyMCE.clearArray(ar);
4084 for (i=0; i<st.length; i++) {
4088 re = new RegExp('^\\s*([^:]*):\\s*(.*)\\s*$');
4089 pa = st[i].replace(re, '$1||$2').split('||');
4090 //tinyMCE.debug(str, pa[0] + "=" + pa[1], st[i].replace(re, '$1||$2'));
4092 ar[pa[0].toLowerCase()] = pa[1];
4098 compressStyle : function(ar, pr, sf, res) {
4101 box[0] = ar[pr + '-top' + sf];
4102 box[1] = ar[pr + '-left' + sf];
4103 box[2] = ar[pr + '-right' + sf];
4104 box[3] = ar[pr + '-bottom' + sf];
4106 for (i=0; i<box.length; i++) {
4110 for (a=0; a<box.length; a++) {
4111 if (box[a] != box[i])
4116 // They are all the same
4118 ar[pr + '-top' + sf] = null;
4119 ar[pr + '-left' + sf] = null;
4120 ar[pr + '-right' + sf] = null;
4121 ar[pr + '-bottom' + sf] = null;
4124 serializeStyle : function(ar) {
4125 var str = "", key, val, m;
4128 tinyMCE.compressStyle(ar, "border", "", "border");
4129 tinyMCE.compressStyle(ar, "border", "-width", "border-width");
4130 tinyMCE.compressStyle(ar, "border", "-color", "border-color");
4131 tinyMCE.compressStyle(ar, "border", "-style", "border-style");
4132 tinyMCE.compressStyle(ar, "padding", "", "padding");
4133 tinyMCE.compressStyle(ar, "margin", "", "margin");
4138 if (typeof(val) == 'function')
4141 if (key.indexOf('mso-') == 0)
4144 if (val != null && val !== '') {
4145 val = '' + val; // Force string
4148 val = val.replace(new RegExp("url\\(\\'?([^\\']*)\\'?\\)", 'gi'), "url('$1')");
4151 if (val.indexOf('url(') != -1 && tinyMCE.getParam('convert_urls')) {
4152 m = new RegExp("url\\('(.*?)'\\)").exec(val);
4155 val = "url('" + eval(tinyMCE.getParam('urlconverter_callback') + "(m[1], null, true);") + "')";
4159 if (tinyMCE.getParam("force_hex_style_colors"))
4160 val = tinyMCE.convertRGBToHex(val, true);
4162 val = val.replace(/\"/g, '\'');
4164 if (val != "url('')")
4165 str += key.toLowerCase() + ": " + val + "; ";
4169 if (new RegExp('; $').test(str))
4170 str = str.substring(0, str.length - 2);
4175 convertRGBToHex : function(s, k) {
4178 if (s.toLowerCase().indexOf('rgb') != -1) {
4179 re = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
4180 rgb = s.replace(re, "$1,$2,$3,$4,$5").split(',');
4182 if (rgb.length == 5) {
4183 r = parseInt(rgb[1]).toString(16);
4184 g = parseInt(rgb[2]).toString(16);
4185 b = parseInt(rgb[3]).toString(16);
4187 r = r.length == 1 ? '0' + r : r;
4188 g = g.length == 1 ? '0' + g : g;
4189 b = b.length == 1 ? '0' + b : b;
4191 s = "#" + r + g + b;
4194 s = rgb[0] + s + rgb[4];
4201 convertHexToRGB : function(s) {
4202 if (s.indexOf('#') != -1) {
4203 s = s.replace(new RegExp('[^0-9A-F]', 'gi'), '');
4204 return "rgb(" + parseInt(s.substring(0, 2), 16) + "," + parseInt(s.substring(2, 4), 16) + "," + parseInt(s.substring(4, 6), 16) + ")";
4210 convertSpansToFonts : function(doc) {
4211 var s, i, size, fSize, x, fFace, fColor, sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
4213 s = tinyMCE.selectElements(doc, 'span,font');
4214 for (i=0; i<s.length; i++) {
4215 size = tinyMCE.trim(s[i].style.fontSize).toLowerCase();
4218 for (x=0; x<sizes.length; x++) {
4219 if (sizes[x] == size) {
4226 tinyMCE.setAttrib(s[i], 'size', fSize);
4227 s[i].style.fontSize = '';
4230 fFace = s[i].style.fontFamily;
4231 if (fFace != null && fFace !== '') {
4232 tinyMCE.setAttrib(s[i], 'face', fFace);
4233 s[i].style.fontFamily = '';
4236 fColor = s[i].style.color;
4237 if (fColor != null && fColor !== '') {
4238 tinyMCE.setAttrib(s[i], 'color', tinyMCE.convertRGBToHex(fColor));
4239 s[i].style.color = '';
4244 convertFontsToSpans : function(doc) {
4245 var fsClasses, s, i, fSize, fFace, fColor, sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
4247 fsClasses = tinyMCE.getParam('font_size_classes');
4248 if (fsClasses !== '')
4249 fsClasses = fsClasses.replace(/\s+/, '').split(',');
4253 s = tinyMCE.selectElements(doc, 'span,font');
4254 for (i=0; i<s.length; i++) {
4255 fSize = tinyMCE.getAttrib(s[i], 'size');
4256 fFace = tinyMCE.getAttrib(s[i], 'face');
4257 fColor = tinyMCE.getAttrib(s[i], 'color');
4260 fSize = parseInt(fSize);
4262 if (fSize > 0 && fSize < 8) {
4263 if (fsClasses != null)
4264 tinyMCE.setAttrib(s[i], 'class', fsClasses[fSize-1]);
4266 s[i].style.fontSize = sizes[fSize-1];
4269 s[i].removeAttribute('size');
4273 s[i].style.fontFamily = fFace;
4274 s[i].removeAttribute('face');
4277 if (fColor !== '') {
4278 s[i].style.color = fColor;
4279 s[i].removeAttribute('color');
4284 cleanupAnchors : function(doc) {
4285 var i, cn, x, an = doc.getElementsByTagName("a");
4287 // Loops backwards due to bug #1467987
4288 for (i=an.length-1; i>=0; i--) {
4289 if (tinyMCE.getAttrib(an[i], "name") !== '' && tinyMCE.getAttrib(an[i], "href") == '') {
4290 cn = an[i].childNodes;
4292 for (x=cn.length-1; x>=0; x--)
4293 tinyMCE.insertAfter(cn[x], an[i]);
4298 getContent : function(editor_id) {
4299 if (typeof(editor_id) != "undefined")
4300 tinyMCE.getInstanceById(editor_id).select();
4302 if (tinyMCE.selectedInstance)
4303 return tinyMCE.selectedInstance.getHTML();
4308 _fixListElements : function(d) {
4309 var nl, x, a = ['ol', 'ul'], i, n, p, r = new RegExp('^(OL|UL)$'), np;
4311 for (x=0; x<a.length; x++) {
4312 nl = d.getElementsByTagName(a[x]);
4314 for (i=0; i<nl.length; i++) {
4318 if (r.test(p.nodeName)) {
4319 np = tinyMCE.prevNode(n, 'LI');
4322 np = d.createElement('li');
4323 np.innerHTML = ' ';
4325 p.insertBefore(np, p.firstChild);
4333 _fixTables : function(d) {
4334 var nl, i, n, p, np, x, t;
4336 nl = d.getElementsByTagName('table');
4337 for (i=0; i<nl.length; i++) {
4340 if ((p = tinyMCE.getParentElement(n, 'p,h1,h2,h3,h4,h5,h6')) != null) {
4341 np = p.cloneNode(false);
4342 np.removeAttribute('id');
4346 while ((n = n.nextSibling))
4349 tinyMCE.insertAfter(np, p);
4350 tinyMCE.insertAfter(t, p);
4355 _cleanupHTML : function(inst, doc, config, elm, visual, on_save, on_submit, inn) {
4356 var h, d, t1, t2, t3, t4, t5, c, s, nb;
4358 if (!tinyMCE.getParam('cleanup'))
4359 return elm.innerHTML;
4361 on_save = typeof(on_save) == 'undefined' ? false : on_save;
4365 d = c.settings.debug;
4368 t1 = new Date().getTime();
4370 inst._fixRootBlocks();
4372 if (tinyMCE.getParam("convert_fonts_to_spans"))
4373 tinyMCE.convertFontsToSpans(doc);
4375 if (tinyMCE.getParam("fix_list_elements"))
4376 tinyMCE._fixListElements(doc);
4378 if (tinyMCE.getParam("fix_table_elements"))
4379 tinyMCE._fixTables(doc);
4381 // Call custom cleanup code
4382 tinyMCE._customCleanup(inst, on_save ? "get_from_editor_dom" : "insert_to_editor_dom", doc.body);
4385 t2 = new Date().getTime();
4387 c.settings.on_save = on_save;
4390 c.serializationId = new Date().getTime().toString(32); // Unique ID needed for the content duplication bug
4391 c.serializedNodes = [];
4394 if (s.cleanup_serializer == "xml")
4395 h = c.serializeNodeAsXML(elm, inn);
4397 h = c.serializeNodeAsHTML(elm, inn);
4400 t3 = new Date().getTime();
4403 nb = tinyMCE.getParam('entity_encoding') == 'numeric' ? ' ' : ' ';
4404 h = h.replace(/<\/?(body|head|html)[^>]*>/gi, '');
4405 h = h.replace(new RegExp(' (rowspan="1"|colspan="1")', 'g'), '');
4406 h = h.replace(/<p><hr \/><\/p>/g, '<hr />');
4407 h = h.replace(/<p>( | )<\/p><hr \/><p>( | )<\/p>/g, '<hr />');
4408 h = h.replace(/<td>\s*<br \/>\s*<\/td>/g, '<td>' + nb + '</td>');
4409 h = h.replace(/<p>\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>');
4410 h = h.replace(/<br \/>$/, ''); // Remove last BR for Gecko
4411 h = h.replace(/<br \/><\/p>/g, '</p>'); // Remove last BR in P tags for Gecko
4412 h = h.replace(/<p>\s*( | )\s*<br \/>\s*( | )\s*<\/p>/g, '<p>' + nb + '</p>');
4413 h = h.replace(/<p>\s*( | )\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>');
4414 h = h.replace(/<p>\s*<br \/>\s* \s*<\/p>/g, '<p>' + nb + '</p>');
4415 h = h.replace(new RegExp('<a>(.*?)<\\/a>', 'g'), '$1');
4416 h = h.replace(/<p([^>]*)>\s*<\/p>/g, '<p$1>' + nb + '</p>');
4419 if (/^\s*(<br \/>|<p> <\/p>|<p> <\/p>|<p><\/p>)\s*$/.test(h))
4423 if (s.preformatted) {
4424 h = h.replace(/^<pre>/, '');
4425 h = h.replace(/<\/pre>$/, '');
4426 h = '<pre>' + h + '</pre>';
4429 // Gecko specific processing
4430 if (tinyMCE.isGecko) {
4431 // Makes no sence but FF generates it!!
4432 h = h.replace(/<br \/>\s*<\/li>/g, '</li>');
4433 h = h.replace(/ \s*<\/(dd|dt)>/g, '</$1>');
4434 h = h.replace(/<o:p _moz-userdefined="" \/>/g, '');
4435 h = h.replace(/<td([^>]*)>\s*<br \/>\s*<\/td>/g, '<td$1>' + nb + '</td>');
4438 if (s.force_br_newlines)
4439 h = h.replace(/<p>( | )<\/p>/g, '<br />');
4441 // Call custom cleanup code
4442 h = tinyMCE._customCleanup(inst, on_save ? "get_from_editor" : "insert_to_editor", h);
4444 // Remove internal classes
4446 h = h.replace(new RegExp(' ?(mceItem[a-zA-Z0-9]*|' + s.visual_table_class + ')', 'g'), '');
4447 h = h.replace(new RegExp(' ?class=""', 'g'), '');
4450 if (s.remove_linebreaks && !c.settings.indent)
4451 h = h.replace(/\n|\r/g, ' ');
4454 t4 = new Date().getTime();
4456 if (on_save && c.settings.indent)
4457 h = c.formatHTML(h);
4459 // If encoding (not recommended option)
4460 if (on_submit && (s.encoding == "xml" || s.encoding == "html"))
4464 t5 = new Date().getTime();
4466 if (c.settings.debug)
4467 tinyMCE.debug("Cleanup in ms: Pre=" + (t2-t1) + ", Serialize: " + (t3-t2) + ", Post: " + (t4-t3) + ", Format: " + (t5-t4) + ", Sum: " + (t5-t1) + ".");
4473 function TinyMCE_Cleanup() {
4474 this.isIE = (navigator.appName == "Microsoft Internet Explorer");
4475 this.rules = tinyMCE.clearArray([]);
4479 indent_elements : 'head,table,tbody,thead,tfoot,form,tr,ul,ol,blockquote,object',
4480 newline_before_elements : 'h1,h2,h3,h4,h5,h6,pre,address,div,ul,ol,li,meta,option,area,title,link,base,script,td',
4481 newline_after_elements : 'br,hr,p,pre,address,div,ul,ol,meta,option,area,link,base,script',
4482 newline_before_after_elements : 'html,head,body,table,thead,tbody,tfoot,tr,form,ul,ol,blockquote,p,object,param,hr,div',
4485 entity_encoding : 'raw',
4486 valid_elements : '*[*]',
4489 invalid_elements : '',
4493 this.vElements = tinyMCE.clearArray([]);
4494 this.vElementsRe = '';
4495 this.closeElementsRe = /^(IMG|BR|HR|LINK|META|BASE|INPUT|AREA)$/;
4496 this.codeElementsRe = /^(SCRIPT|STYLE)$/;
4497 this.serializationId = 0;
4505 TinyMCE_Cleanup.prototype = {
4506 init : function(s) {
4507 var n, a, i, ir, or, st;
4510 this.settings[n] = s[n];
4512 // Setup code formating
4516 this.inRe = this._arrayToRe(s.indent_elements.split(','), '', '^<(', ')[^>]*');
4517 this.ouRe = this._arrayToRe(s.indent_elements.split(','), '', '^<\\/(', ')[^>]*');
4518 this.nlBeforeRe = this._arrayToRe(s.newline_before_elements.split(','), 'gi', '<(', ')([^>]*)>');
4519 this.nlAfterRe = this._arrayToRe(s.newline_after_elements.split(','), 'gi', '<(', ')([^>]*)>');
4520 this.nlBeforeAfterRe = this._arrayToRe(s.newline_before_after_elements.split(','), 'gi', '<(\\/?)(', ')([^>]*)>');
4521 this.serializedNodes = [];
4523 if (s.invalid_elements !== '')
4524 this.iveRe = this._arrayToRe(s.invalid_elements.toUpperCase().split(','), 'g', '^(', ')$');
4530 for (i=0; i<s.indent_levels; i++)
4531 st += s.indent_char;
4535 // If verify_html if false force *[*]
4536 if (!s.verify_html) {
4537 s.valid_elements = '*[*]';
4538 s.extended_valid_elements = '';
4541 this.fillStr = s.entity_encoding == "named" ? " " : " ";
4543 this.xmlEncodeRe = new RegExp('[\u007F-\uFFFF<>&"]', 'g');
4546 addRuleStr : function(s) {
4547 var r = this.parseRuleStr(s), n;
4551 this.rules[n] = r[n];
4554 this.vElements = tinyMCE.clearArray([]);
4556 for (n in this.rules) {
4558 this.vElements[this.vElements.length] = this.rules[n].tag;
4561 this.vElementsRe = this._arrayToRe(this.vElements, '');
4564 isValid : function(n) {
4565 if (!this.rulesDone)
4566 this._setupRules(); // Will initialize cleanup rules
4568 // Empty is true since it removes formatting
4572 // Clean the name up a bit
4573 n = n.replace(/[^a-z0-9]+/gi, '').toUpperCase();
4575 return !tinyMCE.getParam('cleanup') || this.vElementsRe.test(n);
4578 addChildRemoveRuleStr : function(s) {
4579 var x, y, p, i, t, tn, ta, cl, r;
4585 for (x=0; x<ta.length; x++) {
4588 // Split tag/children
4589 p = this.split(/\[|\]/, s);
4590 if (p == null || p.length < 1)
4591 t = s.toUpperCase();
4593 t = p[0].toUpperCase();
4595 // Handle all tag names
4596 tn = this.split('/', t);
4597 for (y=0; y<tn.length; y++) {
4601 cl = this.split(/\|/, p[1]);
4602 for (i=0; i<cl.length; i++) {
4603 if (cl[i] == '%istrict')
4604 r += tinyMCE.inlineStrict;
4605 else if (cl[i] == '%itrans')
4606 r += tinyMCE.inlineTransitional;
4607 else if (cl[i] == '%istrict_na')
4608 r += tinyMCE.inlineStrict.substring(2);
4609 else if (cl[i] == '%itrans_na')
4610 r += tinyMCE.inlineTransitional.substring(2);
4611 else if (cl[i] == '%btrans')
4612 r += tinyMCE.blockElms;
4613 else if (cl[i] == '%strict')
4614 r += tinyMCE.blockStrict;
4616 r += (cl[i].charAt(0) != '#' ? cl[i].toUpperCase() : cl[i]);
4618 r += (i != cl.length - 1 ? '|' : '');
4623 if (this.childRules == null)
4624 this.childRules = tinyMCE.clearArray([]);
4626 this.childRules[tn[y]] = new RegExp(r);
4629 this.childRules[tn[y]].wrapTag = p[2];
4634 parseRuleStr : function(s) {
4635 var ta, p, r, a, i, x, px, t, tn, y, av, or = tinyMCE.clearArray([]), dv;
4637 if (s == null || s.length == 0)
4641 for (x=0; x<ta.length; x++) {
4647 p = this.split(/\[|\]/, s);
4648 if (p == null || p.length < 1)
4649 t = s.toUpperCase();
4651 t = p[0].toUpperCase();
4653 // Handle all tag names
4654 tn = this.split('/', t);
4655 for (y=0; y<tn.length; y++) {
4659 r.forceAttribs = null;
4660 r.defaultAttribs = null;
4661 r.validAttribValues = null;
4664 px = r.tag.charAt(0);
4665 r.forceOpen = px == '+';
4666 r.removeEmpty = px == '-';
4668 r.tag = r.tag.replace(/\+|-|#/g, '');
4669 r.oTagName = tn[0].replace(/\+|-|#/g, '').toLowerCase();
4670 r.isWild = new RegExp('\\*|\\?|\\+', 'g').test(r.tag);
4671 r.validRe = new RegExp(this._wildcardToRe('^' + r.tag + '$'));
4673 // Setup valid attributes
4675 r.vAttribsRe = '^(';
4676 a = this.split(/\|/, p[1]);
4678 for (i=0; i<a.length; i++) {
4681 if (t.charAt(0) == '!') {
4682 a[i] = t = t.substring(1);
4684 if (!r.reqAttribsRe)
4685 r.reqAttribsRe = '\\s+(' + t;
4687 r.reqAttribsRe += '|' + t;
4690 av = new RegExp('(=|:|<)(.*?)$').exec(t);
4691 t = t.replace(new RegExp('(=|:|<).*?$'), '');
4692 if (av && av.length > 0) {
4693 if (av[0].charAt(0) == ':') {
4694 if (!r.forceAttribs)
4695 r.forceAttribs = tinyMCE.clearArray([]);
4697 r.forceAttribs[t.toLowerCase()] = av[0].substring(1);
4698 } else if (av[0].charAt(0) == '=') {
4699 if (!r.defaultAttribs)
4700 r.defaultAttribs = tinyMCE.clearArray([]);
4702 dv = av[0].substring(1);
4704 r.defaultAttribs[t.toLowerCase()] = dv == '' ? "mce_empty" : dv;
4705 } else if (av[0].charAt(0) == '<') {
4706 if (!r.validAttribValues)
4707 r.validAttribValues = tinyMCE.clearArray([]);
4709 r.validAttribValues[t.toLowerCase()] = this._arrayToRe(this.split('?', av[0].substring(1)), 'i');
4713 r.vAttribsRe += '' + t.toLowerCase() + (i != a.length - 1 ? '|' : '');
4715 a[i] = t.toLowerCase();
4719 r.reqAttribsRe = new RegExp(r.reqAttribsRe + ')=\"', 'g');
4721 r.vAttribsRe += ')$';
4722 r.vAttribsRe = this._wildcardToRe(r.vAttribsRe);
4723 r.vAttribsReIsWild = new RegExp('\\*|\\?|\\+', 'g').test(r.vAttribsRe);
4724 r.vAttribsRe = new RegExp(r.vAttribsRe);
4725 r.vAttribs = a.reverse();
4727 //tinyMCE.debug(r.tag, r.oTagName, r.vAttribsRe, r.vAttribsReWC);
4730 r.vAttribs = tinyMCE.clearArray([]);
4731 r.vAttribsReIsWild = false;
4741 serializeNodeAsXML : function(n) {
4746 try {this.xmlDoc = new ActiveXObject('MSXML2.DOMDocument');} catch (e) {}
4749 try {this.xmlDoc = new ActiveXObject('Microsoft.XmlDom');} catch (e) {}
4751 this.xmlDoc = document.implementation.createDocument('', '', null);
4754 alert("Error XML Parser could not be found.");
4757 if (this.xmlDoc.firstChild)
4758 this.xmlDoc.removeChild(this.xmlDoc.firstChild);
4760 b = this.xmlDoc.createElement("html");
4761 b = this.xmlDoc.appendChild(b);
4763 this._convertToXML(n, b);
4766 return this.xmlDoc.xml;
4768 return new XMLSerializer().serializeToString(this.xmlDoc);
4771 _convertToXML : function(n, xn) {
4772 var xd, el, i, l, cn, at, no, hc = false;
4774 if (tinyMCE.isRealIE && this._isDuplicate(n))
4779 switch (n.nodeType) {
4781 hc = n.hasChildNodes();
4783 el = xd.createElement(n.nodeName.toLowerCase());
4786 for (i=at.length-1; i>-1; i--) {
4789 if (no.specified && no.nodeValue)
4790 el.setAttribute(no.nodeName.toLowerCase(), no.nodeValue);
4793 if (!hc && !this.closeElementsRe.test(n.nodeName))
4794 el.appendChild(xd.createTextNode(""));
4796 xn = xn.appendChild(el);
4800 xn.appendChild(xd.createTextNode(n.nodeValue));
4804 xn.appendChild(xd.createComment(n.nodeValue));
4811 for (i=0, l=cn.length; i<l; i++)
4812 this._convertToXML(cn[i], xn);
4816 serializeNodeAsHTML : function(n, inn) {
4817 var en, no, h = '', i, l, t, st, r, cn, va = false, f = false, at, hc, cr, nn;
4819 if (!this.rulesDone)
4820 this._setupRules(); // Will initialize cleanup rules
4822 if (tinyMCE.isRealIE && this._isDuplicate(n))
4825 // Skip non valid child elements
4826 if (n.parentNode && this.childRules != null) {
4827 cr = this.childRules[n.parentNode.nodeName];
4829 if (typeof(cr) != "undefined" && !cr.test(n.nodeName)) {
4835 switch (n.nodeType) {
4837 hc = n.hasChildNodes();
4844 if (tinyMCE.isRealIE) {
4845 // MSIE sometimes produces <//tag>
4846 if (n.nodeName.indexOf('/') != -1)
4849 // MSIE has it's NS in a separate attrib
4850 if (n.scopeName && n.scopeName != 'HTML')
4851 nn = n.scopeName.toUpperCase() + ':' + nn.toUpperCase();
4852 } else if (tinyMCE.isOpera && nn.indexOf(':') > 0)
4853 nn = nn.toUpperCase();
4855 // Convert fonts to spans
4856 if (this.settings.convert_fonts_to_spans) {
4857 // On get content FONT -> SPAN
4858 if (this.settings.on_save && nn == 'FONT')
4861 // On insert content SPAN -> FONT
4862 if (!this.settings.on_save && nn == 'SPAN')
4866 if (this.vElementsRe.test(nn) && (!this.iveRe || !this.iveRe.test(nn)) && !inn) {
4873 if (at[no] && at[no].validRe.test(nn)) {
4880 en = r.isWild ? nn.toLowerCase() : r.oTagName;
4883 if (r.removeEmpty && !hc)
4888 if (r.vAttribsReIsWild) {
4889 // Serialize wildcard attributes
4891 for (i=at.length-1; i>-1; i--) {
4893 if (no.specified && r.vAttribsRe.test(no.nodeName))
4894 t += this._serializeAttribute(n, r, no.nodeName);
4897 // Serialize specific attributes
4898 for (i=r.vAttribs.length-1; i>-1; i--)
4899 t += this._serializeAttribute(n, r, r.vAttribs[i]);
4902 // Serialize mce_ atts
4903 if (!this.settings.on_save) {
4904 at = this.mceAttribs;
4908 t += this._serializeAttribute(n, r, at[no]);
4912 // Check for required attribs
4913 if (r.reqAttribsRe && !t.match(r.reqAttribsRe))
4917 if (t != null && this.closeElementsRe.test(nn))
4923 if (this.isIE && this.codeElementsRe.test(nn))
4932 if (n.parentNode && this.codeElementsRe.test(n.parentNode.nodeName))
4933 return this.isIE ? '' : n.nodeValue;
4935 return this.xmlEncode(n.nodeValue);
4941 return "<!--" + this._trimComment(n.nodeValue) + "-->";
4947 for (i=0, l=cn.length; i<l; i++)
4948 h += this.serializeNodeAsHTML(cn[i]);
4956 if (t != null && va)
4957 h += '</' + en + '>';
4962 _serializeAttribute : function(n, r, an) {
4963 var av = '', t, os = this.settings.on_save;
4965 if (os && (an.indexOf('mce_') == 0 || an.indexOf('_moz') == 0))
4968 if (os && this.mceAttribs[an])
4969 av = this._getAttrib(n, this.mceAttribs[an]);
4972 av = this._getAttrib(n, an);
4974 if (av.length == 0 && r.defaultAttribs && (t = r.defaultAttribs[an])) {
4977 if (av == "mce_empty")
4978 return " " + an + '=""';
4981 if (r.forceAttribs && (t = r.forceAttribs[an]))
4984 if (os && av.length != 0 && /^(src|href|longdesc)$/.test(an))
4985 av = this._urlConverter(this, n, av);
4987 if (av.length != 0 && r.validAttribValues && r.validAttribValues[an] && !r.validAttribValues[an].test(av))
4990 if (av.length != 0 && av == "{$uid}")
4991 av = "uid_" + (this.idCount++);
4993 if (av.length != 0) {
4994 if (an.indexOf('on') != 0)
4995 av = this.xmlEncode(av, 1);
4997 return " " + an + "=" + '"' + av + '"';
5003 formatHTML : function(h) {
5004 var s = this.settings, p = '', i = 0, li = 0, o = '', l;
5006 // Replace BR in pre elements to \n
5007 h = h.replace(/<pre([^>]*)>(.*?)<\/pre>/gi, function (a, b, c) {
5008 c = c.replace(/<br\s*\/>/gi, '\n');
5009 return '<pre' + b + '>' + c + '</pre>';
5012 h = h.replace(/\r/g, ''); // Windows sux, isn't carriage return a thing of the past :)
5014 h = h.replace(new RegExp('\\n\\s+', 'gi'), '\n'); // Remove previous formatting
5015 h = h.replace(this.nlBeforeRe, '\n<$1$2>');
5016 h = h.replace(this.nlAfterRe, '<$1$2>\n');
5017 h = h.replace(this.nlBeforeAfterRe, '\n<$1$2$3>\n');
5022 while ((i = h.indexOf('\n', i + 1)) != -1) {
5023 if ((l = h.substring(li + 1, i)).length != 0) {
5024 if (this.ouRe.test(l) && p.length >= s.indent_levels)
5025 p = p.substring(s.indent_levels);
5029 if (this.inRe.test(l))
5041 xmlEncode : function(s) {
5042 var cl = this, re = this.xmlEncodeRe;
5044 if (!this.entitiesDone)
5045 this._setupEntities(); // Will intialize lookup table
5047 switch (this.settings.entity_encoding) {
5049 return tinyMCE.xmlEncode(s);
5052 return s.replace(re, function (c) {
5053 var b = cl.entities[c.charCodeAt(0)];
5055 return b ? '&' + b + ';' : c;
5059 return s.replace(re, function (c) {
5060 return '&#' + c.charCodeAt(0) + ';';
5067 split : function(re, s) {
5068 var i, l, o = [], c = s.split(re);
5070 for (i=0, l=c.length; i<l; i++) {
5078 _trimComment : function(s) {
5079 // Remove mce_src, mce_href
5080 s = s.replace(new RegExp('\\smce_src=\"[^\"]*\"', 'gi'), "");
5081 s = s.replace(new RegExp('\\smce_href=\"[^\"]*\"', 'gi'), "");
5086 _getAttrib : function(e, n, d) {
5089 if (typeof(d) == "undefined")
5092 if (!e || e.nodeType != 1)
5096 v = e.getAttribute(n, 0);
5098 // IE 7 may cast exception on invalid attributes
5099 v = e.getAttribute(n, 2);
5102 if (n == "class" && !v)
5106 if (n == "http-equiv")
5111 // Skip the default values that IE returns
5112 if (nn == "FORM" && n == "enctype" && v == "application/x-www-form-urlencoded")
5115 if (nn == "INPUT" && n == "size" && v == "20")
5118 if (nn == "INPUT" && n == "maxlength" && v == "2147483647")
5122 if (n == "width" || n == "height")
5123 v = e.getAttribute(n, 2);
5126 if (n == 'style' && v) {
5127 if (!tinyMCE.isOpera)
5128 v = e.style.cssText;
5130 v = tinyMCE.serializeStyle(tinyMCE.parseStyle(v));
5133 if (this.settings.on_save && n.indexOf('on') != -1 && this.settings.on_save && v && v !== '')
5134 v = tinyMCE.cleanupEventStr(v);
5136 return (v && v !== '') ? '' + v : d;
5139 _urlConverter : function(c, n, v) {
5140 if (!c.settings.on_save)
5141 return tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, v);
5142 else if (tinyMCE.getParam('convert_urls')) {
5143 if (!this.urlConverter)
5144 this.urlConverter = eval(tinyMCE.settings.urlconverter_callback);
5146 return this.urlConverter(v, n, true);
5152 _arrayToRe : function(a, op, be, af) {
5155 op = typeof(op) == "undefined" ? "gi" : op;
5156 be = typeof(be) == "undefined" ? "^(" : be;
5157 af = typeof(af) == "undefined" ? ")$" : af;
5161 for (i=0; i<a.length; i++)
5162 r += this._wildcardToRe(a[i]) + (i != a.length-1 ? "|" : "");
5166 return new RegExp(r, op);
5169 _wildcardToRe : function(s) {
5170 s = s.replace(/\?/g, '(\\S?)');
5171 s = s.replace(/\+/g, '(\\S+)');
5172 s = s.replace(/\*/g, '(\\S*)');
5177 _setupEntities : function() {
5178 var n, a, i, s = this.settings;
5181 if (s.entity_encoding == "named") {
5182 n = tinyMCE.clearArray([]);
5183 a = this.split(',', s.entities);
5184 for (i=0; i<a.length; i+=2)
5190 this.entitiesDone = true;
5193 _setupRules : function() {
5194 var s = this.settings;
5196 // Setup default rule
5197 this.addRuleStr(s.valid_elements);
5198 this.addRuleStr(s.extended_valid_elements);
5199 this.addChildRemoveRuleStr(s.valid_child_elements);
5201 this.rulesDone = true;
5204 _isDuplicate : function(n) {
5207 if (!this.settings.fix_content_duplication)
5210 if (tinyMCE.isRealIE && n.nodeType == 1) {
5212 if (n.mce_serialized == this.serializationId)
5215 n.setAttribute('mce_serialized', this.serializationId);
5217 sn = this.serializedNodes;
5219 // Search lookup table for text nodes and comments
5220 for (i=0, l = sn.length; i<l; i++) {
5233 /* file:jscripts/tiny_mce/classes/TinyMCE_DOMUtils.class.js */
5235 tinyMCE.add(TinyMCE_Engine, {
5236 createTagHTML : function(tn, a, h) {
5237 var o = '', f = tinyMCE.xmlEncode, n;
5243 if (typeof(a[n]) != 'function' && a[n] != null)
5244 o += ' ' + f(n) + '="' + f('' + a[n]) + '"';
5248 o += !h ? ' />' : '>' + h + '</' + tn + '>';
5253 createTag : function(d, tn, a, h) {
5254 var o = d.createElement(tn), n;
5258 if (typeof(a[n]) != 'function' && a[n] != null)
5259 tinyMCE.setAttrib(o, n, a[n]);
5269 getElementByAttributeValue : function(n, e, a, v) {
5270 return (n = this.getElementsByAttributeValue(n, e, a, v)).length == 0 ? null : n[0];
5273 getElementsByAttributeValue : function(n, e, a, v) {
5274 var i, nl = n.getElementsByTagName(e), o = [];
5276 for (i=0; i<nl.length; i++) {
5277 if (tinyMCE.getAttrib(nl[i], a).indexOf(v) != -1)
5278 o[o.length] = nl[i];
5284 isBlockElement : function(n) {
5285 return n != null && n.nodeType == 1 && this.blockRegExp.test(n.nodeName);
5288 getParentBlockElement : function(n, r) {
5289 return this.getParentNode(n, function(n) {
5290 return tinyMCE.isBlockElement(n);
5296 insertAfter : function(n, r){
5298 r.parentNode.insertBefore(n, r.nextSibling);
5300 r.parentNode.appendChild(n);
5303 setInnerHTML : function(e, h) {
5306 // Convert all strong/em to b/i in Gecko
5307 if (tinyMCE.isGecko) {
5308 h = h.replace(/<embed([^>]*)>/gi, '<tmpembed$1>');
5309 h = h.replace(/<em([^>]*)>/gi, '<i$1>');
5310 h = h.replace(/<tmpembed([^>]*)>/gi, '<embed$1>');
5311 h = h.replace(/<strong([^>]*)>/gi, '<b$1>');
5312 h = h.replace(/<\/strong>/gi, '</b>');
5313 h = h.replace(/<\/em>/gi, '</i>');
5316 if (tinyMCE.isRealIE) {
5317 // Since MSIE handles invalid HTML better that valid XHTML we
5318 // need to make some things invalid. <hr /> gets converted to <hr>.
5319 h = h.replace(/\s\/>/g, '>');
5321 // Since MSIE auto generated emtpy P tags some times we must tell it to keep the real ones
5322 h = h.replace(/<p([^>]*)>\u00A0?<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs
5323 h = h.replace(/<p([^>]*)>\s* \s*<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs
5324 h = h.replace(/<p([^>]*)>\s+<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs
5326 // Remove first comment
5327 e.innerHTML = tinyMCE.uniqueTag + h;
5328 e.firstChild.removeNode(true);
5330 // Remove weird auto generated empty paragraphs unless it's supposed to be there
5331 nl = e.getElementsByTagName("p");
5332 for (i=nl.length-1; i>=0; i--) {
5335 if (n.nodeName == 'P' && !n.hasChildNodes() && !n.mce_keep)
5336 n.parentNode.removeChild(n);
5339 h = this.fixGeckoBaseHREFBug(1, e, h);
5341 this.fixGeckoBaseHREFBug(2, e, h);
5345 getOuterHTML : function(e) {
5351 d = e.ownerDocument.createElement("body");
5352 d.appendChild(e.cloneNode(true));
5357 setOuterHTML : function(e, h, d) {
5358 var d = typeof(d) == "undefined" ? e.ownerDocument : d, i, nl, t;
5360 if (tinyMCE.isIE && e.nodeType == 1)
5363 t = d.createElement("body");
5366 for (i=0, nl=t.childNodes; i<nl.length; i++)
5367 e.parentNode.insertBefore(nl[i].cloneNode(true), e);
5369 e.parentNode.removeChild(e);
5373 _getElementById : function(id, d) {
5376 if (typeof(d) == "undefined")
5379 e = d.getElementById(id);
5383 for (i=0; i<f.length; i++) {
5384 for (j=0; j<f[i].elements.length; j++) {
5385 if (f[i].elements[j].name == id) {
5386 e = f[i].elements[j];
5396 getNodeTree : function(n, na, t, nn) {
5397 return this.selectNodes(n, function(n) {
5398 return (!t || n.nodeType == t) && (!nn || n.nodeName == nn);
5402 getParentElement : function(n, na, f, r) {
5403 var re = na ? new RegExp('^(' + na.toUpperCase().replace(/,/g, '|') + ')$') : 0, v;
5405 // Compatiblity with old scripts where f param was a attribute string
5406 if (f && typeof(f) == 'string')
5407 return this.getParentElement(n, na, function(no) {return tinyMCE.getAttrib(no, f) !== '';});
5409 return this.getParentNode(n, function(n) {
5410 return ((n.nodeType == 1 && !re) || (re && re.test(n.nodeName))) && (!f || f(n));
5414 getParentNode : function(n, f, r) {
5428 getAttrib : function(elm, name, dv) {
5431 if (typeof(dv) == "undefined")
5435 if (!elm || elm.nodeType != 1)
5439 v = elm.getAttribute(name, 0);
5441 // IE 7 may cast exception on invalid attributes
5442 v = elm.getAttribute(name, 2);
5445 // Try className for class attrib
5446 if (name == "class" && !v)
5449 // Workaround for a issue with Firefox 1.5rc2+
5450 if (tinyMCE.isGecko) {
5451 if (name == "src" && elm.src != null && elm.src !== '')
5454 // Workaround for a issue with Firefox 1.5rc2+
5455 if (name == "href" && elm.href != null && elm.href !== '')
5457 } else if (tinyMCE.isIE) {
5465 v = elm.getAttribute(name, 2);
5470 if (name == "style" && !tinyMCE.isOpera)
5471 v = elm.style.cssText;
5473 return (v && v !== '') ? v : dv;
5476 setAttrib : function(el, name, va, fix) {
5477 if (typeof(va) == "number" && va != null)
5484 va = va.replace(/[^0-9%]/g, '');
5487 if (name == "style")
5488 el.style.cssText = va;
5490 if (name == "class")
5493 if (va != null && va !== '' && va != -1)
5494 el.setAttribute(name, va);
5496 el.removeAttribute(name);
5499 setStyleAttrib : function(e, n, v) {
5502 // Style attrib deleted in IE
5503 if (tinyMCE.isIE && v == null || v == '') {
5504 v = tinyMCE.serializeStyle(tinyMCE.parseStyle(e.style.cssText));
5505 e.style.cssText = v;
5506 e.setAttribute("style", v);
5510 switchClass : function(ei, c) {
5513 if (tinyMCE.switchClassCache[ei])
5514 e = tinyMCE.switchClassCache[ei];
5516 e = tinyMCE.switchClassCache[ei] = document.getElementById(ei);
5520 if (tinyMCE.settings.button_tile_map && e.className && e.className.indexOf('mceTiledButton') == 0)
5521 c = 'mceTiledButton ' + c;
5527 getAbsPosition : function(n, cn) {
5530 while (n && n != cn) {
5536 return {absLeft : l, absTop : t};
5539 prevNode : function(e, n) {
5540 var a = n.split(','), i;
5542 while ((e = e.previousSibling) != null) {
5543 for (i=0; i<a.length; i++) {
5544 if (e.nodeName == a[i])
5552 nextNode : function(e, n) {
5553 var a = n.split(','), i;
5555 while ((e = e.nextSibling) != null) {
5556 for (i=0; i<a.length; i++) {
5557 if (e.nodeName == a[i])
5565 selectElements : function(n, na, f) {
5566 var i, a = [], nl, x;
5568 for (x=0, na = na.split(','); x<na.length; x++)
5569 for (i=0, nl = n.getElementsByTagName(na[x]); i<nl.length; i++)
5570 (!f || f(nl[i])) && a.push(nl[i]);
5575 selectNodes : function(n, f, a) {
5584 if (n.hasChildNodes()) {
5585 for (i=0; i<n.childNodes.length; i++)
5586 tinyMCE.selectNodes(n.childNodes[i], f, a);
5592 addCSSClass : function(e, c, b) {
5593 var o = this.removeCSSClass(e, c);
5594 return e.className = b ? c + (o !== '' ? (' ' + o) : '') : (o !== '' ? (o + ' ') : '') + c;
5597 removeCSSClass : function(e, c) {
5598 c = e.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' ');
5599 return e.className = c != ' ' ? c : '';
5602 hasCSSClass : function(n, c) {
5603 return new RegExp('\\b' + c + '\\b', 'g').test(n.className);
5606 renameElement : function(e, n, d) {
5609 d = typeof(d) == "undefined" ? tinyMCE.selectedInstance.getDoc() : d;
5612 ne = d.createElement(n);
5615 for (i=ar.length-1; i>-1; i--) {
5616 if (ar[i].specified && ar[i].nodeValue)
5617 ne.setAttribute(ar[i].nodeName.toLowerCase(), ar[i].nodeValue);
5621 for (i=0; i<ar.length; i++)
5622 ne.appendChild(ar[i].cloneNode(true));
5624 e.parentNode.replaceChild(ne, e);
5628 getViewPort : function(w) {
5629 var d = w.document, m = d.compatMode == 'CSS1Compat', b = d.body, de = d.documentElement;
5632 left : w.pageXOffset || (m ? de.scrollLeft : b.scrollLeft),
5633 top : w.pageYOffset || (m ? de.scrollTop : b.scrollTop),
5634 width : w.innerWidth || (m ? de.clientWidth : b.clientWidth),
5635 height : w.innerHeight || (m ? de.clientHeight : b.clientHeight)
5639 getStyle : function(n, na, d) {
5644 if (tinyMCE.isGecko && n.ownerDocument.defaultView) {
5646 return n.ownerDocument.defaultView.getComputedStyle(n, null).getPropertyValue(na);
5648 // Old safari might fail
5653 // Camelcase it, if needed
5654 na = na.replace(/-(\D)/g, function(a, b){
5655 return b.toUpperCase();
5660 return n.currentStyle[na];
5667 /* file:jscripts/tiny_mce/classes/TinyMCE_URL.class.js */
5669 tinyMCE.add(TinyMCE_Engine, {
5670 parseURL : function(url_str) {
5671 var urlParts = [], i, pos, lastPos, chr;
5674 // Parse protocol part
5675 pos = url_str.indexOf('://');
5677 urlParts.protocol = url_str.substring(0, pos);
5681 // Find port or path start
5682 for (i=lastPos; i<url_str.length; i++) {
5683 chr = url_str.charAt(i);
5694 urlParts.host = url_str.substring(lastPos, pos);
5699 if (url_str.charAt(pos) == ':') {
5700 pos = url_str.indexOf('/', lastPos);
5701 urlParts.port = url_str.substring(lastPos+1, pos);
5706 pos = url_str.indexOf('?', lastPos);
5709 pos = url_str.indexOf('#', lastPos);
5712 pos = url_str.length;
5714 urlParts.path = url_str.substring(lastPos, pos);
5718 if (url_str.charAt(pos) == '?') {
5719 pos = url_str.indexOf('#');
5720 pos = (pos == -1) ? url_str.length : pos;
5721 urlParts.query = url_str.substring(lastPos+1, pos);
5726 if (url_str.charAt(pos) == '#') {
5727 pos = url_str.length;
5728 urlParts.anchor = url_str.substring(lastPos+1, pos);
5735 serializeURL : function(up) {
5739 o += up.protocol + "://";
5751 o += "?" + up.query;
5754 o += "#" + up.anchor;
5759 convertAbsoluteURLToRelativeURL : function(base_url, url_to_relative) {
5760 var baseURL = this.parseURL(base_url), targetURL = this.parseURL(url_to_relative);
5761 var i, strTok1, strTok2, breakPoint = 0, outPath = "", forceSlash = false;
5764 if (targetURL.path == '')
5765 targetURL.path = "/";
5769 // Crop away last path part
5770 base_url = baseURL.path.substring(0, baseURL.path.lastIndexOf('/'));
5771 strTok1 = base_url.split('/');
5772 strTok2 = targetURL.path.split('/');
5774 if (strTok1.length >= strTok2.length) {
5775 for (i=0; i<strTok1.length; i++) {
5776 if (i >= strTok2.length || strTok1[i] != strTok2[i]) {
5783 if (strTok1.length < strTok2.length) {
5784 for (i=0; i<strTok2.length; i++) {
5785 if (i >= strTok1.length || strTok1[i] != strTok2[i]) {
5792 if (breakPoint == 1)
5793 return targetURL.path;
5795 for (i=0; i<(strTok1.length-(breakPoint-1)); i++)
5798 for (i=breakPoint-1; i<strTok2.length; i++) {
5799 if (i != (breakPoint-1))
5800 outPath += "/" + strTok2[i];
5802 outPath += strTok2[i];
5805 targetURL.protocol = null;
5806 targetURL.host = null;
5807 targetURL.port = null;
5808 targetURL.path = outPath == '' && forceSlash ? "/" : outPath;
5810 // Remove document prefix from local anchors
5811 fileName = baseURL.path;
5813 if ((pos = fileName.lastIndexOf('/')) != -1)
5814 fileName = fileName.substring(pos + 1);
5817 if (fileName == targetURL.path && targetURL.anchor !== '')
5818 targetURL.path = "";
5820 // If empty and not local anchor force filename or slash
5821 if (targetURL.path == '' && !targetURL.anchor)
5822 targetURL.path = fileName !== '' ? fileName : "/";
5824 return this.serializeURL(targetURL);
5827 convertRelativeToAbsoluteURL : function(base_url, relative_url) {
5828 var baseURL = this.parseURL(base_url), baseURLParts, relURLParts, newRelURLParts, numBack, relURL = this.parseURL(relative_url), i;
5829 var len, absPath, start, end, newBaseURLParts;
5831 if (relative_url == '' || relative_url.indexOf('://') != -1 || /^(mailto:|javascript:|#|\/)/.test(relative_url))
5832 return relative_url;
5835 baseURLParts = baseURL.path.split('/');
5836 relURLParts = relURL.path.split('/');
5838 // Remove empty chunks
5839 newBaseURLParts = [];
5840 for (i=baseURLParts.length-1; i>=0; i--) {
5841 if (baseURLParts[i].length == 0)
5844 newBaseURLParts[newBaseURLParts.length] = baseURLParts[i];
5846 baseURLParts = newBaseURLParts.reverse();
5848 // Merge relURLParts chunks
5849 newRelURLParts = [];
5851 for (i=relURLParts.length-1; i>=0; i--) {
5852 if (relURLParts[i].length == 0 || relURLParts[i] == ".")
5855 if (relURLParts[i] == '..') {
5865 newRelURLParts[newRelURLParts.length] = relURLParts[i];
5868 relURLParts = newRelURLParts.reverse();
5870 // Remove end from absolute path
5871 len = baseURLParts.length-numBack;
5872 absPath = (len <= 0 ? "" : "/") + baseURLParts.slice(0, len).join('/') + "/" + relURLParts.join('/');
5877 relURL.protocol = baseURL.protocol;
5878 relURL.host = baseURL.host;
5879 relURL.port = baseURL.port;
5881 // Re-add trailing slash if it's removed
5882 if (relURL.path.charAt(relURL.path.length-1) == "/")
5885 relURL.path = absPath;
5887 return this.serializeURL(relURL);
5890 convertURL : function(url, node, on_save) {
5891 var dl = document.location, start, portPart, urlParts, baseUrlParts, tmpUrlParts, curl;
5892 var prot = dl.protocol, host = dl.hostname, port = dl.port;
5894 // Pass through file protocol
5895 if (prot == "file:")
5898 // Something is wrong, remove weirdness
5899 url = tinyMCE.regexpReplace(url, '(http|https):///', '/');
5901 // Mailto link or anchor (Pass through)
5902 if (url.indexOf('mailto:') != -1 || url.indexOf('javascript:') != -1 || /^[ \t\r\n\+]*[#\?]/.test(url))
5905 // Fix relative/Mozilla
5906 if (!tinyMCE.isIE && !on_save && url.indexOf("://") == -1 && url.charAt(0) != '/')
5907 return tinyMCE.settings.base_href + url;
5909 // Handle relative URLs
5910 if (on_save && tinyMCE.getParam('relative_urls')) {
5911 curl = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, url);
5912 if (curl.charAt(0) == '/')
5913 curl = tinyMCE.settings.document_base_prefix + curl;
5915 urlParts = tinyMCE.parseURL(curl);
5916 tmpUrlParts = tinyMCE.parseURL(tinyMCE.settings.document_base_url);
5919 if (urlParts.host == tmpUrlParts.host && (urlParts.port == tmpUrlParts.port))
5920 return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings.document_base_url, curl);
5923 // Handle absolute URLs
5924 if (!tinyMCE.getParam('relative_urls')) {
5925 urlParts = tinyMCE.parseURL(url);
5926 baseUrlParts = tinyMCE.parseURL(tinyMCE.settings.base_href);
5928 // Force absolute URLs from relative URLs
5929 url = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, url);
5931 // If anchor and path is the same page
5932 if (urlParts.anchor && urlParts.path == baseUrlParts.path)
5933 return "#" + urlParts.anchor;
5936 // Remove current domain
5937 if (tinyMCE.getParam('remove_script_host')) {
5942 portPart = ":" + port;
5944 start = prot + "//" + host + portPart + "/";
5946 if (url.indexOf(start) == 0)
5947 url = url.substring(start.length-1);
5953 convertAllRelativeURLs : function(body) {
5954 var i, elms, src, href, mhref, msrc;
5956 // Convert all image URL:s to absolute URL
5957 elms = body.getElementsByTagName("img");
5958 for (i=0; i<elms.length; i++) {
5959 src = tinyMCE.getAttrib(elms[i], 'src');
5961 msrc = tinyMCE.getAttrib(elms[i], 'mce_src');
5966 src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, src);
5967 elms[i].setAttribute("src", src);
5971 // Convert all link URL:s to absolute URL
5972 elms = body.getElementsByTagName("a");
5973 for (i=0; i<elms.length; i++) {
5974 href = tinyMCE.getAttrib(elms[i], 'href');
5976 mhref = tinyMCE.getAttrib(elms[i], 'mce_href');
5980 if (href && href !== '') {
5981 href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, href);
5982 elms[i].setAttribute("href", href);
5989 /* file:jscripts/tiny_mce/classes/TinyMCE_Array.class.js */
5991 tinyMCE.add(TinyMCE_Engine, {
5992 clearArray : function(a) {
6001 explode : function(d, s) {
6002 var ar = s.split(d), oar = [], i;
6004 for (i = 0; i<ar.length; i++) {
6006 oar[oar.length] = ar[i];
6013 /* file:jscripts/tiny_mce/classes/TinyMCE_Event.class.js */
6015 tinyMCE.add(TinyMCE_Engine, {
6016 _setEventsEnabled : function(node, state) {
6017 var evs, x, y, elms, i, event;
6018 var events = ['onfocus','onblur','onclick','ondblclick',
6019 'onmousedown','onmouseup','onmouseover','onmousemove',
6020 'onmouseout','onkeypress','onkeydown','onkeydown','onkeyup'];
6022 evs = tinyMCE.settings.event_elements.split(',');
6023 for (y=0; y<evs.length; y++){
6024 elms = node.getElementsByTagName(evs[y]);
6025 for (i=0; i<elms.length; i++) {
6028 for (x=0; x<events.length; x++) {
6029 if ((event = tinyMCE.getAttrib(elms[i], events[x])) !== '') {
6030 event = tinyMCE.cleanupEventStr("" + event);
6033 event = "return true;" + event;
6035 event = event.replace(/^return true;/gi, '');
6037 elms[i].removeAttribute(events[x]);
6038 elms[i].setAttribute(events[x], event);
6045 _eventPatch : function(editor_id) {
6046 var n, inst, win, e;
6048 // Remove odd, error
6049 if (typeof(tinyMCE) == "undefined")
6053 // Try selected instance first
6054 if (tinyMCE.selectedInstance) {
6055 win = tinyMCE.selectedInstance.getWin();
6057 if (win && win.event) {
6061 e.target = e.srcElement;
6063 TinyMCE_Engine.prototype.handleEvent(e);
6069 for (n in tinyMCE.instances) {
6070 inst = tinyMCE.instances[n];
6072 if (!tinyMCE.isInstance(inst))
6076 win = inst.getWin();
6078 if (win && win.event) {
6082 e.target = e.srcElement;
6084 TinyMCE_Engine.prototype.handleEvent(e);
6089 // Ignore error if iframe is pointing to external URL
6093 findEvent : function(e) {
6099 for (n in tinyMCE.instances) {
6100 inst = tinyMCE.instances[n];
6102 if (tinyMCE.isInstance(inst) && inst.getWin().event)
6103 return inst.getWin().event;
6109 unloadHandler : function() {
6110 tinyMCE.triggerSave(true, true);
6113 addEventHandlers : function(inst) {
6114 this.setEventHandlers(inst, 1);
6117 setEventHandlers : function(inst, s) {
6118 var doc = inst.getDoc(), ie, ot, i, f = s ? tinyMCE.addEvent : tinyMCE.removeEvent;
6120 ie = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'controlselect', 'dblclick'];
6121 ot = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'focus', 'blur', 'dragdrop'];
6123 inst.switchSettings();
6126 for (i=0; i<ie.length; i++)
6127 f(doc, ie[i], TinyMCE_Engine.prototype._eventPatch);
6129 for (i=0; i<ot.length; i++)
6130 f(doc, ot[i], tinyMCE.handleEvent);
6134 doc.designMode = "On";
6141 onMouseMove : function() {
6144 // Fix for IE7 bug where it's not restoring hover on anchors correctly
6145 if (tinyMCE.lastHover) {
6146 lh = tinyMCE.lastHover;
6148 // Call out on menus and refresh class on normal buttons
6149 if (lh.className.indexOf('mceMenu') != -1)
6150 tinyMCE._menuButtonEvent('out', lh);
6152 lh.className = lh.className;
6154 tinyMCE.lastHover = null;
6157 if (!tinyMCE.hasMouseMoved) {
6158 inst = tinyMCE.selectedInstance;
6160 // Workaround for bug #1437457 (Odd MSIE bug)
6161 if (inst.isFocused) {
6162 inst.undoBookmark = inst.selection.getBookmark();
6163 tinyMCE.hasMouseMoved = true;
6167 // tinyMCE.cancelEvent(inst.getWin().event);
6171 cancelEvent : function(e) {
6176 e.returnValue = false;
6177 e.cancelBubble = true;
6180 e.stopPropagation && e.stopPropagation();
6186 addEvent : function(o, n, h) {
6187 // Add cleanup for all non unload events
6188 if (n != 'unload') {
6193 tinyMCE.removeEvent(o, n, h);
6194 tinyMCE.removeEvent(window, 'unload', clean);
6197 // IE may produce access denied exception on unload
6201 // Add memory cleaner
6202 tinyMCE.addEvent(window, 'unload', clean);
6206 o.attachEvent("on" + n, h);
6208 o.addEventListener(n, h, false);
6211 removeEvent : function(o, n, h) {
6213 o.detachEvent("on" + n, h);
6215 o.removeEventListener(n, h, false);
6218 addSelectAccessibility : function(e, s, w) {
6219 // Add event handlers
6220 if (!s._isAccessible) {
6221 s.onkeydown = tinyMCE.accessibleEventHandler;
6222 s.onblur = tinyMCE.accessibleEventHandler;
6223 s._isAccessible = true;
6230 accessibleEventHandler : function(e) {
6231 var elm, win = this._win;
6233 e = tinyMCE.isIE ? win.event : e;
6234 elm = tinyMCE.isIE ? e.srcElement : e.target;
6236 // Unpiggyback onchange on blur
6237 if (e.type == "blur") {
6238 if (elm.oldonchange) {
6239 elm.onchange = elm.oldonchange;
6240 elm.oldonchange = null;
6246 // Piggyback onchange
6247 if (elm.nodeName == "SELECT" && !elm.oldonchange) {
6248 elm.oldonchange = elm.onchange;
6249 elm.onchange = null;
6252 // Execute onchange and remove piggyback
6253 if (e.keyCode == 13 || e.keyCode == 32) {
6254 elm.onchange = elm.oldonchange;
6256 elm.oldonchange = null;
6258 tinyMCE.cancelEvent(e);
6265 _resetIframeHeight : function() {
6268 if (tinyMCE.isRealIE) {
6269 ife = tinyMCE.selectedInstance.iframeElement;
6271 /* if (ife._oldWidth) {
6272 ife.style.width = ife._oldWidth;
6273 ife.width = ife._oldWidth;
6276 if (ife._oldHeight) {
6277 ife.style.height = ife._oldHeight;
6278 ife.height = ife._oldHeight;
6285 /* file:jscripts/tiny_mce/classes/TinyMCE_Selection.class.js */
6287 function TinyMCE_Selection(inst) {
6288 this.instance = inst;
6291 TinyMCE_Selection.prototype = {
6292 getSelectedHTML : function() {
6293 var inst = this.instance, e, r = this.getRng(), h;
6298 e = document.createElement("body");
6300 if (r.cloneContents)
6301 e.appendChild(r.cloneContents());
6302 else if (typeof(r.item) != 'undefined' || typeof(r.htmlText) != 'undefined')
6303 e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText;
6305 e.innerHTML = r.toString(); // Failed, use text for now
6307 h = tinyMCE._cleanupHTML(inst, inst.contentDocument, inst.settings, e, e, false, true, false);
6309 // When editing always use fonts internaly
6310 //if (tinyMCE.getParam("convert_fonts_to_spans"))
6311 // tinyMCE.convertSpansToFonts(inst.getDoc());
6316 getSelectedText : function() {
6317 var inst = this.instance, d, r, s, t;
6322 if (d.selection.type == "Text") {
6323 r = d.selection.createRange();
6330 if (s && s.toString)
6339 getBookmark : function(simple) {
6340 var inst = this.instance, rng = this.getRng(), doc = inst.getDoc(), b = inst.getBody();
6341 var trng, sx, sy, xx = -999999999, vp = inst.getViewPort();
6342 var sp, le, s, e, nl, i, si, ei, w;
6348 return {rng : rng, scrollX : sx, scrollY : sy};
6350 if (tinyMCE.isRealIE) {
6354 nl = b.getElementsByTagName(e.nodeName);
6355 for (i=0; i<nl.length; i++) {
6369 trng = doc.body.createTextRange();
6370 trng.moveToElementText(inst.getBody());
6371 trng.collapse(true);
6372 bp = Math.abs(trng.move('character', xx));
6374 trng = rng.duplicate();
6375 trng.collapse(true);
6376 sp = Math.abs(trng.move('character', xx));
6378 trng = rng.duplicate();
6379 trng.collapse(false);
6380 le = Math.abs(trng.move('character', xx)) - sp;
6391 e = this.getFocusElement();
6396 if (e && e.nodeName == 'IMG') {
6397 /*nl = b.getElementsByTagName('IMG');
6398 for (i=0; i<nl.length; i++) {
6414 // Caret or selection
6415 if (s.anchorNode == s.focusNode && s.anchorOffset == s.focusOffset) {
6416 e = this._getPosText(b, s.anchorNode, s.focusNode);
6419 return {scrollX : sx, scrollY : sy};
6422 start : e.start + s.anchorOffset,
6423 end : e.end + s.focusOffset,
6428 e = this._getPosText(b, rng.startContainer, rng.endContainer);
6431 return {scrollX : sx, scrollY : sy};
6434 start : e.start + rng.startOffset,
6435 end : e.end + rng.endOffset,
6445 moveToBookmark : function(bookmark) {
6446 var inst = this.instance, rng, nl, i, ex, b = inst.getBody(), sd;
6447 var doc = inst.getDoc(), win = inst.getWin(), sel = this.getSel();
6452 if (tinyMCE.isSafari && bookmark.rng) {
6453 sel.setBaseAndExtent(bookmark.rng.startContainer, bookmark.rng.startOffset, bookmark.rng.endContainer, bookmark.rng.endOffset);
6457 if (tinyMCE.isRealIE) {
6460 bookmark.rng.select();
6471 rng = b.createControlRange();
6473 nl = b.getElementsByTagName(bookmark.tag);
6475 if (nl.length > bookmark.index) {
6477 rng.addElement(nl[bookmark.index]);
6479 // Might be thrown if the node no longer exists
6483 // Try/catch needed since this operation breaks when TinyMCE is placed in hidden divs/tabs
6485 // Incorrect bookmark
6486 if (bookmark.start < 0)
6489 rng = inst.getSel().createRange();
6490 rng.moveToElementText(inst.getBody());
6492 rng.moveStart('character', bookmark.start);
6493 rng.moveEnd('character', bookmark.length);
6501 win.scrollTo(bookmark.scrollX, bookmark.scrollY);
6505 if (tinyMCE.isGecko || tinyMCE.isOpera) {
6510 sel.removeAllRanges();
6511 sel.addRange(bookmark.rng);
6514 if (bookmark.start != -1 && bookmark.end != -1) {
6516 sd = this._getTextPos(b, bookmark.start, bookmark.end);
6517 rng = doc.createRange();
6518 rng.setStart(sd.startNode, sd.startOffset);
6519 rng.setEnd(sd.endNode, sd.endOffset);
6520 sel.removeAllRanges();
6523 if (!tinyMCE.isOpera)
6531 if (typeof(bookmark.index) != 'undefined') {
6532 tinyMCE.selectElements(b, 'IMG', function (n) {
6533 if (bookmark.index-- == 0) {
6534 // Select image in Gecko here
6542 win.scrollTo(bookmark.scrollX, bookmark.scrollY);
6549 _getPosText : function(r, sn, en) {
6550 var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {};
6552 while ((n = w.nextNode()) != null) {
6561 p += n.nodeValue ? n.nodeValue.length : 0;
6567 _getTextPos : function(r, sp, ep) {
6568 var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {};
6570 while ((n = w.nextNode()) != null) {
6571 p += n.nodeValue ? n.nodeValue.length : 0;
6573 if (p >= sp && !d.startNode) {
6575 d.startOffset = sp - (p - n.nodeValue.length);
6580 d.endOffset = ep - (p - n.nodeValue.length);
6589 selectNode : function(node, collapse, select_text_node, to_start) {
6590 var inst = this.instance, sel, rng, nodes;
6595 if (typeof(collapse) == "undefined")
6598 if (typeof(select_text_node) == "undefined")
6599 select_text_node = false;
6601 if (typeof(to_start) == "undefined")
6604 if (inst.settings.auto_resize)
6605 inst.resizeToContent();
6607 if (tinyMCE.isRealIE) {
6608 rng = inst.getDoc().body.createTextRange();
6611 rng.moveToElementText(node);
6614 rng.collapse(to_start);
6618 // Throws illigal agrument in MSIE some times
6621 sel = this.getSel();
6626 if (tinyMCE.isSafari) {
6627 sel.setBaseAndExtent(node, 0, node, node.innerText.length);
6631 sel.collapseToStart();
6633 sel.collapseToEnd();
6636 this.scrollToNode(node);
6641 rng = inst.getDoc().createRange();
6643 if (select_text_node) {
6644 // Find first textnode in tree
6645 nodes = tinyMCE.getNodeTree(node, [], 3);
6646 if (nodes.length > 0)
6647 rng.selectNodeContents(nodes[0]);
6649 rng.selectNodeContents(node);
6651 rng.selectNode(node);
6654 // Special treatment of textnode collapse
6655 if (!to_start && node.nodeType == 3) {
6656 rng.setStart(node, node.nodeValue.length);
6657 rng.setEnd(node, node.nodeValue.length);
6659 rng.collapse(to_start);
6662 sel.removeAllRanges();
6666 this.scrollToNode(node);
6668 // Set selected element
6669 tinyMCE.selectedElement = null;
6670 if (node.nodeType == 1)
6671 tinyMCE.selectedElement = node;
6674 scrollToNode : function(node) {
6675 var inst = this.instance, w = inst.getWin(), vp = inst.getViewPort(), pos = tinyMCE.getAbsPosition(node), cvp, p, cwin;
6677 // Only scroll if out of visible area
6678 if (pos.absLeft < vp.left || pos.absLeft > vp.left + vp.width || pos.absTop < vp.top || pos.absTop > vp.top + (vp.height-25))
6679 w.scrollTo(pos.absLeft, pos.absTop - vp.height + 25);
6681 // Scroll container window
6682 if (inst.settings.auto_resize) {
6683 cwin = inst.getContainerWin();
6684 cvp = tinyMCE.getViewPort(cwin);
6685 p = this.getAbsPosition(node);
6687 if (p.absLeft < cvp.left || p.absLeft > cvp.left + cvp.width || p.absTop < cvp.top || p.absTop > cvp.top + cvp.height)
6688 cwin.scrollTo(p.absLeft, p.absTop - cvp.height + 25);
6692 getAbsPosition : function(n) {
6693 var pos = tinyMCE.getAbsPosition(n), ipos = tinyMCE.getAbsPosition(this.instance.iframeElement);
6696 absLeft : ipos.absLeft + pos.absLeft,
6697 absTop : ipos.absTop + pos.absTop
6701 getSel : function() {
6702 var inst = this.instance;
6704 if (tinyMCE.isRealIE)
6705 return inst.getDoc().selection;
6707 return inst.contentWindow.getSelection();
6710 getRng : function() {
6711 var s = this.getSel();
6716 if (tinyMCE.isRealIE)
6717 return s.createRange();
6719 if (tinyMCE.isSafari && !s.getRangeAt)
6720 return '' + window.getSelection();
6722 if (s.rangeCount > 0)
6723 return s.getRangeAt(0);
6728 isCollapsed : function() {
6729 var r = this.getRng();
6734 return r.boundingWidth == 0 || this.getSel().isCollapsed;
6737 collapse : function(b) {
6738 var r = this.getRng(), s = this.getSel();
6745 s.collapseToStart();
6751 getFocusElement : function() {
6752 var inst = this.instance, doc, rng, sel, elm;
6754 if (tinyMCE.isRealIE) {
6755 doc = inst.getDoc();
6756 rng = doc.selection.createRange();
6758 // if (rng.collapse)
6759 // rng.collapse(true);
6761 elm = rng.item ? rng.item(0) : rng.parentElement();
6763 if (!tinyMCE.isSafari && inst.isHidden())
6764 return inst.getBody();
6766 sel = this.getSel();
6767 rng = this.getRng();
6772 elm = rng.commonAncestorContainer;
6773 //elm = (sel && sel.anchorNode) ? sel.anchorNode : null;
6775 // Handle selection a image or other control like element such as anchors
6776 if (!rng.collapsed) {
6777 // Is selection small
6778 if (rng.startContainer == rng.endContainer) {
6779 if (rng.startOffset - rng.endOffset < 2) {
6780 if (rng.startContainer.hasChildNodes())
6781 elm = rng.startContainer.childNodes[rng.startOffset];
6786 // Get the element parent of the node
6787 elm = tinyMCE.getParentElement(elm);
6789 //if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img")
6790 // elm = tinyMCE.selectedElement;
6798 /* file:jscripts/tiny_mce/classes/TinyMCE_UndoRedo.class.js */
6800 function TinyMCE_UndoRedo(inst) {
6801 this.instance = inst;
6802 this.undoLevels = [];
6804 this.typingUndoIndex = -1;
6805 this.undoRedo = true;
6808 TinyMCE_UndoRedo.prototype = {
6810 var b, customUndoLevels, newHTML, inst = this.instance, i, ul, ur;
6813 this.undoLevels[this.undoLevels.length] = l;
6817 if (this.typingUndoIndex != -1) {
6818 this.undoIndex = this.typingUndoIndex;
6820 if (tinyMCE.typingUndoIndex != -1)
6821 tinyMCE.undoIndex = tinyMCE.typingUndoIndex;
6824 newHTML = tinyMCE.trim(inst.getBody().innerHTML);
6825 if (this.undoLevels[this.undoIndex] && newHTML != this.undoLevels[this.undoIndex].content) {
6826 //tinyMCE.debug(newHTML, this.undoLevels[this.undoIndex].content);
6829 inst.isNotDirty = false;
6831 tinyMCE.dispatchCallback(inst, 'onchange_callback', 'onChange', inst);
6834 customUndoLevels = tinyMCE.settings.custom_undo_redo_levels;
6835 if (customUndoLevels != -1 && this.undoLevels.length > customUndoLevels) {
6836 for (i=0; i<this.undoLevels.length-1; i++)
6837 this.undoLevels[i] = this.undoLevels[i+1];
6839 this.undoLevels.length--;
6842 // Todo: Implement global undo/redo logic here
6845 b = inst.undoBookmark;
6848 b = inst.selection.getBookmark();
6851 this.undoLevels[this.undoIndex] = {
6856 // Remove all above from global undo/redo
6857 ul = tinyMCE.undoLevels;
6858 for (i=tinyMCE.undoIndex + 1; i<ul.length; i++) {
6859 ur = ul[i].undoRedo;
6861 if (ur.undoIndex == ur.undoLevels.length -1)
6864 ur.undoLevels.length--;
6867 // Add global undo level
6868 tinyMCE.undoLevels[tinyMCE.undoIndex++] = inst;
6869 tinyMCE.undoLevels.length = tinyMCE.undoIndex;
6871 this.undoLevels.length = this.undoIndex + 1;
6880 var inst = this.instance;
6883 if (this.undoIndex > 0) {
6886 tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);
6889 if (inst.settings.custom_undo_redo_restore_selection)
6890 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);
6895 var inst = this.instance;
6897 tinyMCE.execCommand("mceEndTyping");
6899 if (this.undoIndex < (this.undoLevels.length-1)) {
6902 tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);
6905 if (inst.settings.custom_undo_redo_restore_selection)
6906 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);
6909 tinyMCE.triggerNodeChange();
6914 /* file:jscripts/tiny_mce/classes/TinyMCE_ForceParagraphs.class.js */
6916 var TinyMCE_ForceParagraphs = {
6917 _insertPara : function(inst, e) {
6918 var doc = inst.getDoc(), sel = inst.getSel(), body = inst.getBody(), win = inst.contentWindow, rng = sel.getRangeAt(0);
6919 var rootElm = doc.documentElement, blockName = "P", startNode, endNode, startBlock, endBlock;
6920 var rngBefore, rngAfter, direct, startNode, startOffset, endNode, endOffset, b = tinyMCE.isOpera ? inst.selection.getBookmark() : null;
6921 var paraBefore, paraAfter, startChop, endChop, contents, i;
6923 function isEmpty(para) {
6926 function isEmptyHTML(html) {
6927 return html.replace(new RegExp('[ \t\r\n]+', 'g'), '').toLowerCase() == '';
6931 if (para.getElementsByTagName("img").length > 0)
6935 if (para.getElementsByTagName("table").length > 0)
6939 if (para.getElementsByTagName("hr").length > 0)
6942 // Check all textnodes
6943 nodes = tinyMCE.getNodeTree(para, [], 3);
6944 for (i=0; i<nodes.length; i++) {
6945 if (!isEmptyHTML(nodes[i].nodeValue))
6949 // No images, no tables, no hrs, no text content then it's empty
6953 // tinyMCE.debug(body.innerHTML);
6955 // debug(e.target, sel.anchorNode.nodeName, sel.focusNode.nodeName, rng.startContainer, rng.endContainer, rng.commonAncestorContainer, sel.anchorOffset, sel.focusOffset, rng.toString());
6957 // Setup before range
6958 rngBefore = doc.createRange();
6959 rngBefore.setStart(sel.anchorNode, sel.anchorOffset);
6960 rngBefore.collapse(true);
6962 // Setup after range
6963 rngAfter = doc.createRange();
6964 rngAfter.setStart(sel.focusNode, sel.focusOffset);
6965 rngAfter.collapse(true);
6967 // Setup start/end points
6968 direct = rngBefore.compareBoundaryPoints(rngBefore.START_TO_END, rngAfter) < 0;
6969 startNode = direct ? sel.anchorNode : sel.focusNode;
6970 startOffset = direct ? sel.anchorOffset : sel.focusOffset;
6971 endNode = direct ? sel.focusNode : sel.anchorNode;
6972 endOffset = direct ? sel.focusOffset : sel.anchorOffset;
6974 startNode = startNode.nodeName == "BODY" ? startNode.firstChild : startNode;
6975 endNode = endNode.nodeName == "BODY" ? endNode.firstChild : endNode;
6977 // Get block elements
6978 startBlock = inst.getParentBlockElement(startNode);
6979 endBlock = inst.getParentBlockElement(endNode);
6981 // If absolute force paragraph generation within
6982 if (startBlock && (startBlock.nodeName == 'CAPTION' || /absolute|relative|static/gi.test(startBlock.style.position)))
6985 if (endBlock && (endBlock.nodeName == 'CAPTION' || /absolute|relative|static/gi.test(endBlock.style.position)))
6988 // Use current block name
6989 if (startBlock != null) {
6990 blockName = startBlock.nodeName;
6993 if (/(TD|TABLE|TH|CAPTION)/.test(blockName) || (blockName == "DIV" && /left|right/gi.test(startBlock.style.cssFloat)))
6997 // Within a list use normal behaviour
6998 if (tinyMCE.getParentElement(startBlock, "OL,UL", null, body) != null)
7001 // Within a table create new paragraphs
7002 if ((startBlock != null && startBlock.nodeName == "TABLE") || (endBlock != null && endBlock.nodeName == "TABLE"))
7003 startBlock = endBlock = null;
7005 // Setup new paragraphs
7006 paraBefore = (startBlock != null && startBlock.nodeName == blockName) ? startBlock.cloneNode(false) : doc.createElement(blockName);
7007 paraAfter = (endBlock != null && endBlock.nodeName == blockName) ? endBlock.cloneNode(false) : doc.createElement(blockName);
7009 // Is header, then force paragraph under
7010 if (/^(H[1-6])$/.test(blockName))
7011 paraAfter = doc.createElement("p");
7014 startChop = startNode;
7017 // Get startChop node
7020 if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
7024 } while ((node = node.previousSibling ? node.previousSibling : node.parentNode));
7029 if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
7033 } while ((node = node.nextSibling ? node.nextSibling : node.parentNode));
7035 // Fix when only a image is within the TD
7036 if (startChop.nodeName == "TD")
7037 startChop = startChop.firstChild;
7039 if (endChop.nodeName == "TD")
7040 endChop = endChop.lastChild;
7042 // If not in a block element
7043 if (startBlock == null) {
7045 rng.deleteContents();
7047 if (!tinyMCE.isSafari)
7048 sel.removeAllRanges();
7050 if (startChop != rootElm && endChop != rootElm) {
7051 // Insert paragraph before
7052 rngBefore = rng.cloneRange();
7054 if (startChop == body)
7055 rngBefore.setStart(startChop, 0);
7057 rngBefore.setStartBefore(startChop);
7059 paraBefore.appendChild(rngBefore.cloneContents());
7061 // Insert paragraph after
7062 if (endChop.parentNode.nodeName == blockName)
7063 endChop = endChop.parentNode;
7065 // If not after image
7066 //if (rng.startContainer.nodeName != "BODY" && rng.endContainer.nodeName != "BODY")
7067 rng.setEndAfter(endChop);
7069 if (endChop.nodeName != "#text" && endChop.nodeName != "BODY")
7070 rngBefore.setEndAfter(endChop);
7072 contents = rng.cloneContents();
7073 if (contents.firstChild && (contents.firstChild.nodeName == blockName || contents.firstChild.nodeName == "BODY"))
7074 paraAfter.innerHTML = contents.firstChild.innerHTML;
7076 paraAfter.appendChild(contents);
7078 // Check if it's a empty paragraph
7079 if (isEmpty(paraBefore))
7080 paraBefore.innerHTML = " ";
7082 // Check if it's a empty paragraph
7083 if (isEmpty(paraAfter))
7084 paraAfter.innerHTML = " ";
7086 // Delete old contents
7087 rng.deleteContents();
7088 rngAfter.deleteContents();
7089 rngBefore.deleteContents();
7091 // Insert new paragraphs
7092 if (tinyMCE.isOpera) {
7093 paraBefore.normalize();
7094 rngBefore.insertNode(paraBefore);
7095 paraAfter.normalize();
7096 rngBefore.insertNode(paraAfter);
7098 paraAfter.normalize();
7099 rngBefore.insertNode(paraAfter);
7100 paraBefore.normalize();
7101 rngBefore.insertNode(paraBefore);
7104 //tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML);
7106 body.innerHTML = "<" + blockName + "> </" + blockName + "><" + blockName + "> </" + blockName + ">";
7107 paraAfter = body.childNodes[1];
7110 inst.selection.moveToBookmark(b);
7111 inst.selection.selectNode(paraAfter, true, true);
7116 // Place first part within new paragraph
7117 if (startChop.nodeName == blockName)
7118 rngBefore.setStart(startChop, 0);
7120 rngBefore.setStartBefore(startChop);
7122 rngBefore.setEnd(startNode, startOffset);
7123 paraBefore.appendChild(rngBefore.cloneContents());
7125 // Place secound part within new paragraph
7126 rngAfter.setEndAfter(endChop);
7127 rngAfter.setStart(endNode, endOffset);
7128 contents = rngAfter.cloneContents();
7130 if (contents.firstChild && contents.firstChild.nodeName == blockName) {
7131 /* var nodes = contents.firstChild.childNodes;
7132 for (i=0; i<nodes.length; i++) {
7133 //tinyMCE.debug(nodes[i].nodeName);
7134 if (nodes[i].nodeName != "BODY")
7135 paraAfter.appendChild(nodes[i]);
7138 paraAfter.innerHTML = contents.firstChild.innerHTML;
7140 paraAfter.appendChild(contents);
7142 // Check if it's a empty paragraph
7143 if (isEmpty(paraBefore))
7144 paraBefore.innerHTML = " ";
7146 // Check if it's a empty paragraph
7147 if (isEmpty(paraAfter))
7148 paraAfter.innerHTML = " ";
7150 // Create a range around everything
7151 rng = doc.createRange();
7153 if (!startChop.previousSibling && startChop.parentNode.nodeName.toUpperCase() == blockName) {
7154 rng.setStartBefore(startChop.parentNode);
7156 if (rngBefore.startContainer.nodeName.toUpperCase() == blockName && rngBefore.startOffset == 0)
7157 rng.setStartBefore(rngBefore.startContainer);
7159 rng.setStart(rngBefore.startContainer, rngBefore.startOffset);
7162 if (!endChop.nextSibling && endChop.parentNode.nodeName.toUpperCase() == blockName)
7163 rng.setEndAfter(endChop.parentNode);
7165 rng.setEnd(rngAfter.endContainer, rngAfter.endOffset);
7167 // Delete all contents and insert new paragraphs
7168 rng.deleteContents();
7170 if (tinyMCE.isOpera) {
7171 rng.insertNode(paraBefore);
7172 rng.insertNode(paraAfter);
7174 rng.insertNode(paraAfter);
7175 rng.insertNode(paraBefore);
7178 //tinyMCE.debug("2", paraBefore.innerHTML, paraAfter.innerHTML);
7181 paraAfter.normalize();
7182 paraBefore.normalize();
7184 inst.selection.moveToBookmark(b);
7185 inst.selection.selectNode(paraAfter, true, true);
7190 _handleBackSpace : function(inst) {
7191 var r = inst.getRng(), sn = r.startContainer, nv, s = false;
7193 // Added body check for bug #1527787
7194 if (sn && sn.nextSibling && sn.nextSibling.nodeName == "BR" && sn.parentNode.nodeName != "BODY") {
7197 // Handle if a backspace is pressed after a space character #bug 1466054 removed since fix for #1527787
7198 /*if (nv != null && nv.length >= r.startOffset && nv.charAt(r.startOffset - 1) == ' ')
7201 // Only remove BRs if we are at the end of line #bug 1464152
7202 if (nv != null && r.startOffset == nv.length)
7203 sn.nextSibling.parentNode.removeChild(sn.nextSibling);
7206 if (inst.settings.auto_resize)
7207 inst.resizeToContent();
7214 /* file:jscripts/tiny_mce/classes/TinyMCE_Layer.class.js */
7216 function TinyMCE_Layer(id, bm) {
7218 this.blockerElement = null;
7219 this.events = false;
7220 this.element = null;
7221 this.blockMode = typeof(bm) != 'undefined' ? bm : true;
7222 this.doc = document;
7225 TinyMCE_Layer.prototype = {
7226 moveRelativeTo : function(re, p) {
7227 var rep = this.getAbsPosition(re), e = this.getElement(), x, y;
7228 var w = parseInt(re.offsetWidth), h = parseInt(re.offsetHeight);
7229 var ew = parseInt(e.offsetWidth), eh = parseInt(e.offsetHeight);
7238 x = rep.absLeft + w;
7248 x = rep.absLeft + w;
7253 x = rep.absLeft + (w / 2) - (ew / 2);
7254 y = rep.absTop + (h / 2) - (eh / 2);
7261 moveBy : function(x, y) {
7262 var e = this.getElement();
7263 this.moveTo(parseInt(e.style.left) + x, parseInt(e.style.top) + y);
7266 moveTo : function(x, y) {
7267 var e = this.getElement();
7269 e.style.left = x + "px";
7270 e.style.top = y + "px";
7272 this.updateBlocker();
7275 resizeBy : function(w, h) {
7276 var e = this.getElement();
7277 this.resizeTo(parseInt(e.style.width) + w, parseInt(e.style.height) + h);
7280 resizeTo : function(w, h) {
7281 var e = this.getElement();
7284 e.style.width = w + "px";
7287 e.style.height = h + "px";
7289 this.updateBlocker();
7293 var el = this.getElement();
7296 el.style.display = 'block';
7297 this.updateBlocker();
7302 var el = this.getElement();
7305 el.style.display = 'none';
7306 this.updateBlocker();
7310 isVisible : function() {
7311 return this.getElement().style.display == 'block';
7314 getElement : function() {
7316 this.element = this.doc.getElementById(this.id);
7318 return this.element;
7321 setBlockMode : function(s) {
7325 updateBlocker : function() {
7326 var e, b, x, y, w, h;
7328 b = this.getBlocker();
7330 if (this.blockMode) {
7331 e = this.getElement();
7332 x = this.parseInt(e.style.left);
7333 y = this.parseInt(e.style.top);
7334 w = this.parseInt(e.offsetWidth);
7335 h = this.parseInt(e.offsetHeight);
7337 b.style.left = x + 'px';
7338 b.style.top = y + 'px';
7339 b.style.width = w + 'px';
7340 b.style.height = h + 'px';
7341 b.style.display = e.style.display;
7343 b.style.display = 'none';
7347 getBlocker : function() {
7350 if (!this.blockerElement && this.blockMode) {
7352 b = d.getElementById(this.id + "_blocker");
7355 b = d.createElement("iframe");
7357 b.setAttribute('id', this.id + "_blocker");
7358 b.style.cssText = 'display: none; position: absolute; left: 0; top: 0';
7359 b.src = 'javascript:false;';
7360 b.frameBorder = '0';
7363 d.body.appendChild(b);
7366 this.blockerElement = b;
7369 return this.blockerElement;
7372 getAbsPosition : function(n) {
7373 var p = {absLeft : 0, absTop : 0};
7376 p.absLeft += n.offsetLeft;
7377 p.absTop += n.offsetTop;
7384 create : function(n, c, p, h) {
7385 var d = this.doc, e = d.createElement(n);
7387 e.setAttribute('id', this.id);
7400 return this.element = e;
7403 exists : function() {
7404 return this.doc.getElementById(this.id) != null;
7407 parseInt : function(s) {
7408 if (s == null || s == '')
7414 remove : function() {
7415 var e = this.getElement(), b = this.getBlocker();
7418 e.parentNode.removeChild(e);
7421 b.parentNode.removeChild(b);
7426 /* file:jscripts/tiny_mce/classes/TinyMCE_Menu.class.js */
7428 function TinyMCE_Menu() {
7431 if (typeof(tinyMCE.menuCounter) == "undefined")
7432 tinyMCE.menuCounter = 0;
7434 id = "mc_menu_" + tinyMCE.menuCounter++;
7436 TinyMCE_Layer.call(this, id, true);
7440 this.needsUpdate = true;
7443 TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, {
7444 init : function(s) {
7449 separator_class : 'mceMenuSeparator',
7450 title_class : 'mceMenuTitle',
7451 disabled_class : 'mceMenuDisabled',
7452 menu_class : 'mceMenu',
7457 this.settings[n] = s[n];
7459 this.create('div', this.settings.menu_class);
7462 clear : function() {
7466 addTitle : function(t) {
7467 this.add({type : 'title', text : t});
7470 addDisabled : function(t) {
7471 this.add({type : 'disabled', text : t});
7474 addSeparator : function() {
7475 this.add({type : 'separator'});
7478 addItem : function(t, js) {
7479 this.add({text : t, js : js});
7482 add : function(mi) {
7483 this.items[this.items.length] = mi;
7484 this.needsUpdate = true;
7487 update : function() {
7488 var e = this.getElement(), h = '', i, t, m = this.items, s = this.settings;
7490 if (this.settings.drop_menu)
7491 h += '<span class="mceMenuLine"></span>';
7493 h += '<table border="0" cellpadding="0" cellspacing="0">';
7495 for (i=0; i<m.length; i++) {
7496 t = tinyMCE.xmlEncode(m[i].text);
7497 c = m[i].class_name ? ' class="' + m[i].class_name + '"' : '';
7499 switch (m[i].type) {
7501 h += '<tr class="' + s.separator_class + '"><td>';
7505 h += '<tr class="' + s.title_class + '"><td><span' + c +'>' + t + '</span>';
7509 h += '<tr class="' + s.disabled_class + '"><td><span' + c +'>' + t + '</span>';
7513 h += '<tr><td><a href="' + tinyMCE.xmlEncode(m[i].js) + '" onmousedown="' + tinyMCE.xmlEncode(m[i].js) + ';return tinyMCE.cancelEvent(event);" onclick="return tinyMCE.cancelEvent(event);" onmouseup="return tinyMCE.cancelEvent(event);"><span' + c +'>' + t + '</span></a>';
7523 this.needsUpdate = false;
7524 this.updateBlocker();
7530 if (tinyMCE.lastMenu == this)
7533 if (this.needsUpdate)
7536 if (tinyMCE.lastMenu && tinyMCE.lastMenu != this)
7537 tinyMCE.lastMenu.hide();
7539 TinyMCE_Layer.prototype.show.call(this);
7541 if (!tinyMCE.isOpera) {
7542 // Accessibility stuff
7543 /* nl = this.getElement().getElementsByTagName("a");
7548 tinyMCE.lastMenu = this;
7553 /* file:jscripts/tiny_mce/classes/TinyMCE_Debug.class.js */
7555 tinyMCE.add(TinyMCE_Engine, {
7556 debug : function() {
7557 var m = "", a, i, l = tinyMCE.log.length;
7559 for (i=0, a = this.debug.arguments; i<a.length; i++) {
7567 tinyMCE.log[l] = "[debug] " + m;