2 /* file:jscripts/tiny_mce/classes/TinyMCE_Engine.class.js */
\r
4 function TinyMCE_Engine() {
\r
7 this.majorVersion = "2";
\r
8 this.minorVersion = "0.8";
\r
9 this.releaseDate = "2006-10-23";
\r
11 this.instances = new Array();
\r
12 this.switchClassCache = new Array();
\r
13 this.windowArgs = new Array();
\r
14 this.loadedFiles = new Array();
\r
15 this.pendingFiles = new Array();
\r
16 this.loadingIndex = 0;
\r
17 this.configs = new Array();
\r
18 this.currentConfig = 0;
\r
19 this.eventHandlers = new Array();
\r
20 this.log = new Array();
\r
21 this.undoLevels = [];
\r
23 this.typingUndoIndex = -1;
\r
26 ua = navigator.userAgent;
\r
27 this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
\r
28 this.isMSIE5 = this.isMSIE && (ua.indexOf('MSIE 5') != -1);
\r
29 this.isMSIE5_0 = this.isMSIE && (ua.indexOf('MSIE 5.0') != -1);
\r
30 this.isMSIE7 = this.isMSIE && (ua.indexOf('MSIE 7') != -1);
\r
31 this.isGecko = ua.indexOf('Gecko') != -1;
\r
32 this.isSafari = ua.indexOf('Safari') != -1;
\r
33 this.isOpera = ua.indexOf('Opera') != -1;
\r
34 this.isMac = ua.indexOf('Mac') != -1;
\r
35 this.isNS7 = ua.indexOf('Netscape/7') != -1;
\r
36 this.isNS71 = ua.indexOf('Netscape/7.1') != -1;
\r
37 this.dialogCounter = 0;
\r
38 this.plugins = new Array();
\r
39 this.themes = new Array();
\r
40 this.menus = new Array();
\r
41 this.loadedPlugins = new Array();
\r
42 this.buttonMap = new Array();
\r
43 this.isLoaded = false;
\r
45 // Fake MSIE on Opera and if Opera fakes IE, Gecko or Safari cancel those
\r
48 this.isGecko = false;
\r
49 this.isSafari = false;
\r
52 this.isIE = this.isMSIE;
\r
53 this.isRealIE = this.isMSIE && !this.isOpera;
\r
55 // TinyMCE editor id instance counter
\r
59 TinyMCE_Engine.prototype = {
\r
60 init : function(settings) {
\r
61 var theme, nl, baseHREF = "", i;
\r
63 // 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.
\r
67 this.settings = settings;
\r
69 // Check if valid browser has execcommand support
\r
70 if (typeof(document.execCommand) == 'undefined')
\r
73 // Get script base path
\r
74 if (!tinyMCE.baseURL) {
\r
75 var elements = document.getElementsByTagName('script');
\r
77 // If base element found, add that infront of baseURL
\r
78 nl = document.getElementsByTagName('base');
\r
79 for (i=0; i<nl.length; i++) {
\r
81 baseHREF = nl[i].href;
\r
84 for (var i=0; i<elements.length; i++) {
\r
85 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)) {
\r
86 var src = elements[i].src;
\r
88 tinyMCE.srcMode = (src.indexOf('_src') != -1 || src.indexOf('_dev') != -1) ? '_src' : '';
\r
89 tinyMCE.gzipMode = src.indexOf('_gzip') != -1;
\r
90 src = src.substring(0, src.lastIndexOf('/'));
\r
92 if (settings.exec_mode == "src" || settings.exec_mode == "normal")
\r
93 tinyMCE.srcMode = settings.exec_mode == "src" ? '_src' : '';
\r
95 // Force it absolute if page has a base href
\r
96 if (baseHREF != "" && src.indexOf('://') == -1)
\r
97 tinyMCE.baseURL = baseHREF + src;
\r
99 tinyMCE.baseURL = src;
\r
106 // Get document base path
\r
107 this.documentBasePath = document.location.href;
\r
108 if (this.documentBasePath.indexOf('?') != -1)
\r
109 this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.indexOf('?'));
\r
110 this.documentURL = this.documentBasePath;
\r
111 this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.lastIndexOf('/'));
\r
113 // If not HTTP absolute
\r
114 if (tinyMCE.baseURL.indexOf('://') == -1 && tinyMCE.baseURL.charAt(0) != '/') {
\r
115 // If site absolute
\r
116 tinyMCE.baseURL = this.documentBasePath + "/" + tinyMCE.baseURL;
\r
119 // Set default values on settings
\r
120 this._def("mode", "none");
\r
121 this._def("theme", "advanced");
\r
122 this._def("plugins", "", true);
\r
123 this._def("language", "en");
\r
124 this._def("docs_language", this.settings['language']);
\r
125 this._def("elements", "");
\r
126 this._def("textarea_trigger", "mce_editable");
\r
127 this._def("editor_selector", "");
\r
128 this._def("editor_deselector", "mceNoEditor");
\r
129 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]");
\r
130 this._def("extended_valid_elements", "");
\r
131 this._def("invalid_elements", "");
\r
132 this._def("encoding", "");
\r
133 this._def("urlconverter_callback", tinyMCE.getParam("urlconvertor_callback", "TinyMCE_Engine.prototype.convertURL"));
\r
134 this._def("save_callback", "");
\r
135 this._def("debug", false);
\r
136 this._def("force_br_newlines", false);
\r
137 this._def("force_p_newlines", true);
\r
138 this._def("add_form_submit_trigger", true);
\r
139 this._def("relative_urls", true);
\r
140 this._def("remove_script_host", true);
\r
141 this._def("focus_alert", true);
\r
142 this._def("document_base_url", this.documentURL);
\r
143 this._def("visual", true);
\r
144 this._def("visual_table_class", "mceVisualAid");
\r
145 this._def("setupcontent_callback", "");
\r
146 this._def("fix_content_duplication", true);
\r
147 this._def("custom_undo_redo", true);
\r
148 this._def("custom_undo_redo_levels", -1);
\r
149 this._def("custom_undo_redo_keyboard_shortcuts", true);
\r
150 this._def("custom_undo_redo_restore_selection", true);
\r
151 this._def("custom_undo_redo_global", false);
\r
152 this._def("verify_html", true);
\r
153 this._def("apply_source_formatting", false);
\r
154 this._def("directionality", "ltr");
\r
155 this._def("cleanup_on_startup", false);
\r
156 this._def("inline_styles", false);
\r
157 this._def("convert_newlines_to_brs", false);
\r
158 this._def("auto_reset_designmode", true);
\r
159 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);
\r
160 this._def("entity_encoding", "named");
\r
161 this._def("cleanup_callback", "");
\r
162 this._def("add_unload_trigger", true);
\r
163 this._def("ask", false);
\r
164 this._def("nowrap", false);
\r
165 this._def("auto_resize", false);
\r
166 this._def("auto_focus", false);
\r
167 this._def("cleanup", true);
\r
168 this._def("remove_linebreaks", true);
\r
169 this._def("button_tile_map", false);
\r
170 this._def("submit_patch", true);
\r
171 this._def("browsers", "msie,safari,gecko,opera", true);
\r
172 this._def("dialog_type", "window");
\r
173 this._def("accessibility_warnings", true);
\r
174 this._def("accessibility_focus", true);
\r
175 this._def("merge_styles_invalid_parents", "");
\r
176 this._def("force_hex_style_colors", true);
\r
177 this._def("trim_span_elements", true);
\r
178 this._def("convert_fonts_to_spans", false);
\r
179 this._def("doctype", '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');
\r
180 this._def("font_size_classes", '');
\r
181 this._def("font_size_style_values", 'xx-small,x-small,small,medium,large,x-large,xx-large', true);
\r
182 this._def("event_elements", 'a,img', true);
\r
183 this._def("convert_urls", true);
\r
184 this._def("table_inline_editing", false);
\r
185 this._def("object_resizing", true);
\r
186 this._def("custom_shortcuts", true);
\r
187 this._def("convert_on_click", false);
\r
188 this._def("content_css", '');
\r
189 this._def("fix_list_elements", false);
\r
190 this._def("fix_table_elements", false);
\r
191 this._def("strict_loading_mode", document.contentType == 'application/xhtml+xml');
\r
192 this._def("hidden_tab_class", '');
\r
193 this._def("display_tab_class", '');
\r
194 this._def("gecko_spellcheck", false);
\r
196 // Force strict loading mode to false on non Gecko browsers
\r
197 if (this.isMSIE && !this.isOpera)
\r
198 this.settings.strict_loading_mode = false;
\r
200 // Browser check IE
\r
201 if (this.isMSIE && this.settings['browsers'].indexOf('msie') == -1)
\r
204 // Browser check Gecko
\r
205 if (this.isGecko && this.settings['browsers'].indexOf('gecko') == -1)
\r
208 // Browser check Safari
\r
209 if (this.isSafari && this.settings['browsers'].indexOf('safari') == -1)
\r
212 // Browser check Opera
\r
213 if (this.isOpera && this.settings['browsers'].indexOf('opera') == -1)
\r
216 // If not super absolute make it so
\r
217 baseHREF = tinyMCE.settings['document_base_url'];
\r
218 var h = document.location.href;
\r
219 var p = h.indexOf('://');
\r
220 if (p > 0 && document.location.protocol != "file:") {
\r
221 p = h.indexOf('/', p + 3);
\r
222 h = h.substring(0, p);
\r
224 if (baseHREF.indexOf('://') == -1)
\r
225 baseHREF = h + baseHREF;
\r
227 tinyMCE.settings['document_base_url'] = baseHREF;
\r
228 tinyMCE.settings['document_base_prefix'] = h;
\r
231 // Trim away query part
\r
232 if (baseHREF.indexOf('?') != -1)
\r
233 baseHREF = baseHREF.substring(0, baseHREF.indexOf('?'));
\r
235 this.settings['base_href'] = baseHREF.substring(0, baseHREF.lastIndexOf('/')) + "/";
\r
237 theme = this.settings['theme'];
\r
238 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';
\r
239 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';
\r
240 this.blockElms = 'H[1-6]|P|DIV|ADDRESS|PRE|FORM|TABLE|LI|OL|UL|TD|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|FORM|NOSCRIPT|NOFRAMES|MENU|ISINDEX|SAMP';
\r
241 this.blockRegExp = new RegExp("^(" + this.blockElms + ")$", "i");
\r
242 this.posKeyCodes = new Array(13,45,36,35,33,34,37,38,39,40);
\r
243 this.uniqueURL = 'javascript:TINYMCE_UNIQUEURL();'; // Make unique URL non real URL
\r
244 this.uniqueTag = '<div id="mceTMPElement" style="display: none">TMP</div>';
\r
245 this.callbacks = new Array('onInit', 'getInfo', 'getEditorTemplate', 'setupContent', 'onChange', 'onPageLoad', 'handleNodeChange', 'initInstance', 'execCommand', 'getControlHTML', 'handleEvent', 'cleanup');
\r
248 this.settings['theme_href'] = tinyMCE.baseURL + "/themes/" + theme;
\r
250 if (!tinyMCE.isIE || tinyMCE.isOpera)
\r
251 this.settings['force_br_newlines'] = false;
\r
253 if (tinyMCE.getParam("popups_css", false)) {
\r
254 var cssPath = tinyMCE.getParam("popups_css", "");
\r
257 if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
\r
258 this.settings['popups_css'] = this.documentBasePath + "/" + cssPath;
\r
260 this.settings['popups_css'] = cssPath;
\r
262 this.settings['popups_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_popup.css";
\r
264 if (tinyMCE.getParam("editor_css", false)) {
\r
265 var cssPath = tinyMCE.getParam("editor_css", "");
\r
268 if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
\r
269 this.settings['editor_css'] = this.documentBasePath + "/" + cssPath;
\r
271 this.settings['editor_css'] = cssPath;
\r
273 if (this.settings.editor_css != '')
\r
274 this.settings['editor_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css";
\r
277 if (tinyMCE.settings['debug']) {
\r
278 var msg = "Debug: \n";
\r
280 msg += "baseURL: " + this.baseURL + "\n";
\r
281 msg += "documentBasePath: " + this.documentBasePath + "\n";
\r
282 msg += "content_css: " + this.settings['content_css'] + "\n";
\r
283 msg += "popups_css: " + this.settings['popups_css'] + "\n";
\r
284 msg += "editor_css: " + this.settings['editor_css'] + "\n";
\r
289 // Only do this once
\r
290 if (this.configs.length == 0) {
\r
291 if (typeof(TinyMCECompressed) == "undefined") {
\r
292 tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCE_Engine.prototype.onLoad);
\r
294 if (tinyMCE.isRealIE) {
\r
296 tinyMCE.addEvent(document.body, "readystatechange", TinyMCE_Engine.prototype.onLoad);
\r
298 tinyMCE.addEvent(document, "readystatechange", TinyMCE_Engine.prototype.onLoad);
\r
301 tinyMCE.addEvent(window, "load", TinyMCE_Engine.prototype.onLoad);
\r
302 tinyMCE._addUnloadEvents();
\r
306 this.loadScript(tinyMCE.baseURL + '/themes/' + this.settings['theme'] + '/editor_template' + tinyMCE.srcMode + '.js');
\r
307 this.loadScript(tinyMCE.baseURL + '/langs/' + this.settings['language'] + '.js');
\r
308 this.loadCSS(this.settings['editor_css']);
\r
311 var p = tinyMCE.getParam('plugins', '', true, ',');
\r
312 if (p.length > 0) {
\r
313 for (var i=0; i<p.length; i++) {
\r
314 if (p[i].charAt(0) != '-')
\r
315 this.loadScript(tinyMCE.baseURL + '/plugins/' + p[i] + '/editor_plugin' + tinyMCE.srcMode + '.js');
\r
320 if (tinyMCE.getParam('entity_encoding') == 'named') {
\r
321 settings['cleanup_entities'] = new Array();
\r
322 var entities = tinyMCE.getParam('entities', '', true, ',');
\r
323 for (var i=0; i<entities.length; i+=2)
\r
324 settings['cleanup_entities']['c' + entities[i]] = entities[i+1];
\r
327 // Save away this config
\r
328 settings['index'] = this.configs.length;
\r
329 this.configs[this.configs.length] = settings;
\r
331 // Start loading first one in chain
\r
332 this.loadNextScript();
\r
334 // Force flicker free CSS backgrounds in IE
\r
335 if (this.isIE && !this.isOpera) {
\r
337 document.execCommand('BackgroundImageCache', false, true);
\r
343 _addUnloadEvents : function() {
\r
344 if (tinyMCE.isIE) {
\r
345 if (tinyMCE.settings['add_unload_trigger']) {
\r
346 tinyMCE.addEvent(window, "unload", TinyMCE_Engine.prototype.unloadHandler);
\r
347 tinyMCE.addEvent(window.document, "beforeunload", TinyMCE_Engine.prototype.unloadHandler);
\r
350 if (tinyMCE.settings['add_unload_trigger'])
\r
351 tinyMCE.addEvent(window, "unload", function () {tinyMCE.triggerSave(true, true);});
\r
355 _def : function(key, def_val, t) {
\r
356 var v = tinyMCE.getParam(key, def_val);
\r
358 v = t ? v.replace(/\s+/g, "") : v;
\r
360 this.settings[key] = v;
\r
363 hasPlugin : function(n) {
\r
364 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;
\r
367 addPlugin : function(n, p) {
\r
368 var op = this.plugins[n];
\r
370 // Use the previous plugin object base URL used when loading external plugins
\r
371 p.baseURL = op ? op.baseURL : tinyMCE.baseURL + "/plugins/" + n;
\r
372 this.plugins[n] = p;
\r
374 this.loadNextScript();
\r
377 setPluginBaseURL : function(n, u) {
\r
378 var op = this.plugins[n];
\r
383 this.plugins[n] = {baseURL : u};
\r
386 loadPlugin : function(n, u) {
\r
387 u = u.indexOf('.js') != -1 ? u.substring(0, u.lastIndexOf('/')) : u;
\r
388 u = u.charAt(u.length-1) == '/' ? u.substring(0, u.length-1) : u;
\r
389 this.plugins[n] = {baseURL : u};
\r
390 this.loadScript(u + "/editor_plugin" + (tinyMCE.srcMode ? '_src' : '') + ".js");
\r
393 hasTheme : function(n) {
\r
394 return typeof(this.themes[n]) != "undefined" && this.themes[n] != null;
\r
397 addTheme : function(n, t) {
\r
398 this.themes[n] = t;
\r
400 this.loadNextScript();
\r
403 addMenu : function(n, m) {
\r
407 hasMenu : function(n) {
\r
408 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;
\r
411 loadScript : function(url) {
\r
414 for (i=0; i<this.loadedFiles.length; i++) {
\r
415 if (this.loadedFiles[i] == url)
\r
419 if (tinyMCE.settings.strict_loading_mode)
\r
420 this.pendingFiles[this.pendingFiles.length] = url;
\r
422 document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></script>');
\r
424 this.loadedFiles[this.loadedFiles.length] = url;
\r
427 loadNextScript : function() {
\r
428 var d = document, se;
\r
430 if (!tinyMCE.settings.strict_loading_mode)
\r
433 if (this.loadingIndex < this.pendingFiles.length) {
\r
434 se = d.createElementNS('http://www.w3.org/1999/xhtml', 'script');
\r
435 se.setAttribute('language', 'javascript');
\r
436 se.setAttribute('type', 'text/javascript');
\r
437 se.setAttribute('src', this.pendingFiles[this.loadingIndex++]);
\r
439 d.getElementsByTagName("head")[0].appendChild(se);
\r
441 this.loadingIndex = -1; // Done with loading
\r
444 loadCSS : function(url) {
\r
445 var ar = url.replace(/\s+/, '').split(',');
\r
446 var lflen = 0, csslen = 0;
\r
448 var x = 0, i = 0, nl, le;
\r
450 for (x = 0,csslen = ar.length; x<csslen; x++) {
\r
451 if (ar[x] != null && ar[x] != 'null' && ar[x].length > 0) {
\r
452 /* Make sure it doesn't exist. */
\r
453 for (i=0, lflen=this.loadedFiles.length; i<lflen; i++) {
\r
454 if (this.loadedFiles[i] == ar[x]) {
\r
461 if (tinyMCE.settings.strict_loading_mode) {
\r
462 nl = document.getElementsByTagName("head");
\r
464 le = document.createElement('link');
\r
465 le.setAttribute('href', ar[x]);
\r
466 le.setAttribute('rel', 'stylesheet');
\r
467 le.setAttribute('type', 'text/css');
\r
469 nl[0].appendChild(le);
\r
471 document.write('<link href="' + ar[x] + '" rel="stylesheet" type="text/css" />');
\r
473 this.loadedFiles[this.loadedFiles.length] = ar[x];
\r
479 importCSS : function(doc, css) {
\r
480 var css_ary = css.replace(/\s+/, '').split(',');
\r
481 var csslen, elm, headArr, x, css_file;
\r
483 for (x = 0, csslen = css_ary.length; x<csslen; x++) {
\r
484 css_file = css_ary[x];
\r
486 if (css_file != null && css_file != 'null' && css_file.length > 0) {
\r
487 // Is relative, make absolute
\r
488 if (css_file.indexOf('://') == -1 && css_file.charAt(0) != '/')
\r
489 css_file = this.documentBasePath + "/" + css_file;
\r
491 if (typeof(doc.createStyleSheet) == "undefined") {
\r
492 elm = doc.createElement("link");
\r
494 elm.rel = "stylesheet";
\r
495 elm.href = css_file;
\r
497 if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0)
\r
498 headArr[0].appendChild(elm);
\r
500 doc.createStyleSheet(css_file);
\r
505 confirmAdd : function(e, settings) {
\r
506 var elm = tinyMCE.isIE ? event.srcElement : e.target;
\r
507 var elementId = elm.name ? elm.name : elm.id;
\r
509 tinyMCE.settings = settings;
\r
511 if (tinyMCE.settings['convert_on_click'] || (!elm.getAttribute('mce_noask') && confirm(tinyMCELang['lang_edit_confirm'])))
\r
512 tinyMCE.addMCEControl(elm, elementId);
\r
514 elm.setAttribute('mce_noask', 'true');
\r
517 updateContent : function(form_element_name) {
\r
518 // Find MCE instance linked to given form element and copy it's value
\r
519 var formElement = document.getElementById(form_element_name);
\r
520 for (var n in tinyMCE.instances) {
\r
521 var inst = tinyMCE.instances[n];
\r
522 if (!tinyMCE.isInstance(inst))
\r
525 inst.switchSettings();
\r
527 if (inst.formElement == formElement) {
\r
528 var doc = inst.getDoc();
\r
530 tinyMCE._setHTML(doc, inst.formElement.value);
\r
533 doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid);
\r
538 addMCEControl : function(replace_element, form_element_name, target_document) {
\r
539 var id = "mce_editor_" + tinyMCE.idCounter++;
\r
540 var inst = new TinyMCE_Control(tinyMCE.settings);
\r
542 inst.editorId = id;
\r
543 this.instances[id] = inst;
\r
545 inst._onAdd(replace_element, form_element_name, target_document);
\r
548 removeInstance : function(ti) {
\r
551 // Remove from instances
\r
552 for (n in tinyMCE.instances) {
\r
553 i = tinyMCE.instances[n];
\r
555 if (tinyMCE.isInstance(i) && ti != i)
\r
559 tinyMCE.instances = t;
\r
561 // Remove from global undo/redo
\r
563 t = tinyMCE.undoLevels;
\r
565 for (i=0; i<t.length; i++) {
\r
570 tinyMCE.undoLevels = n;
\r
571 tinyMCE.undoIndex = n.length;
\r
576 removeMCEControl : function(editor_id) {
\r
577 var inst = tinyMCE.getInstanceById(editor_id), h, re, ot, tn;
\r
580 inst.switchSettings();
\r
582 editor_id = inst.editorId;
\r
583 h = tinyMCE.getContent(editor_id);
\r
585 this.removeInstance(inst);
\r
587 tinyMCE.selectedElement = null;
\r
588 tinyMCE.selectedInstance = null;
\r
591 re = document.getElementById(editor_id + "_parent");
\r
592 ot = inst.oldTargetElement;
\r
593 tn = ot.nodeName.toLowerCase();
\r
595 if (tn == "textarea" || tn == "input") {
\r
596 re.parentNode.removeChild(re);
\r
597 ot.style.display = "inline";
\r
601 ot.style.display = 'block';
\r
602 re.parentNode.insertBefore(ot, re);
\r
603 re.parentNode.removeChild(re);
\r
608 triggerSave : function(skip_cleanup, skip_callback) {
\r
611 // Default to false
\r
612 if (typeof(skip_cleanup) == "undefined")
\r
613 skip_cleanup = false;
\r
615 // Default to false
\r
616 if (typeof(skip_callback) == "undefined")
\r
617 skip_callback = false;
\r
619 // Cleanup and set all form fields
\r
620 for (n in tinyMCE.instances) {
\r
621 inst = tinyMCE.instances[n];
\r
623 if (!tinyMCE.isInstance(inst))
\r
626 inst.triggerSave(skip_cleanup, skip_callback);
\r
630 resetForm : function(form_index) {
\r
631 var i, inst, n, formObj = document.forms[form_index];
\r
633 for (n in tinyMCE.instances) {
\r
634 inst = tinyMCE.instances[n];
\r
636 if (!tinyMCE.isInstance(inst))
\r
639 inst.switchSettings();
\r
641 for (i=0; i<formObj.elements.length; i++) {
\r
642 if (inst.formTargetElementId == formObj.elements[i].name)
\r
643 inst.getBody().innerHTML = inst.startContent;
\r
648 execInstanceCommand : function(editor_id, command, user_interface, value, focus) {
\r
649 var inst = tinyMCE.getInstanceById(editor_id), r;
\r
652 r = inst.selection.getRng();
\r
654 if (typeof(focus) == "undefined")
\r
657 // IE bug lost focus on images in absolute divs Bug #1534575
\r
658 if (focus && (!r || !r.item))
\r
659 inst.contentWindow.focus();
\r
661 // Reset design mode if lost
\r
662 inst.autoResetDesignMode();
\r
664 this.selectedElement = inst.getFocusElement();
\r
666 tinyMCE.execCommand(command, user_interface, value);
\r
668 // Cancel event so it doesn't call onbeforeonunlaod
\r
669 if (tinyMCE.isIE && window.event != null)
\r
670 tinyMCE.cancelEvent(window.event);
\r
674 execCommand : function(command, user_interface, value) {
\r
675 var inst = tinyMCE.selectedInstance;
\r
678 user_interface = user_interface ? user_interface : false;
\r
679 value = value ? value : null;
\r
682 inst.switchSettings();
\r
686 if (this.getParam('custom_undo_redo_global')) {
\r
687 if (this.undoIndex > 0) {
\r
688 tinyMCE.nextUndoRedoAction = 'Undo';
\r
689 inst = this.undoLevels[--this.undoIndex];
\r
692 if (!tinyMCE.nextUndoRedoInstanceId)
\r
693 inst.execCommand('Undo');
\r
696 inst.execCommand('Undo');
\r
700 if (this.getParam('custom_undo_redo_global')) {
\r
701 if (this.undoIndex <= this.undoLevels.length - 1) {
\r
702 tinyMCE.nextUndoRedoAction = 'Redo';
\r
703 inst = this.undoLevels[this.undoIndex++];
\r
706 if (!tinyMCE.nextUndoRedoInstanceId)
\r
707 inst.execCommand('Redo');
\r
710 inst.execCommand('Redo');
\r
715 var inst = tinyMCE.getInstanceById(value);
\r
717 inst.getWin().focus();
\r
720 case "mceAddControl":
\r
721 case "mceAddEditor":
\r
722 tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);
\r
725 case "mceAddFrameControl":
\r
726 tinyMCE.addMCEControl(tinyMCE._getElementById(value['element'], value['document']), value['element'], value['document']);
\r
729 case "mceRemoveControl":
\r
730 case "mceRemoveEditor":
\r
731 tinyMCE.removeMCEControl(value);
\r
734 case "mceResetDesignMode":
\r
735 // Resets the designmode state of the editors in Gecko
\r
736 if (!tinyMCE.isIE) {
\r
737 for (var n in tinyMCE.instances) {
\r
738 if (!tinyMCE.isInstance(tinyMCE.instances[n]))
\r
742 tinyMCE.instances[n].getDoc().designMode = "on";
\r
744 // Ignore any errors
\r
753 inst.execCommand(command, user_interface, value);
\r
754 } else if (tinyMCE.settings['focus_alert'])
\r
755 alert(tinyMCELang['lang_focus_alert']);
\r
758 _createIFrame : function(replace_element, doc, win) {
\r
759 var iframe, id = replace_element.getAttribute("id");
\r
762 if (typeof(doc) == "undefined")
\r
765 if (typeof(win) == "undefined")
\r
768 iframe = doc.createElement("iframe");
\r
770 aw = "" + tinyMCE.settings['area_width'];
\r
771 ah = "" + tinyMCE.settings['area_height'];
\r
773 if (aw.indexOf('%') == -1) {
\r
775 aw = (isNaN(aw) || aw < 0) ? 300 : aw;
\r
779 if (ah.indexOf('%') == -1) {
\r
781 ah = (isNaN(ah) || ah < 0) ? 240 : ah;
\r
785 iframe.setAttribute("id", id);
\r
786 iframe.setAttribute("name", id);
\r
787 iframe.setAttribute("class", "mceEditorIframe");
\r
788 iframe.setAttribute("border", "0");
\r
789 iframe.setAttribute("frameBorder", "0");
\r
790 iframe.setAttribute("marginWidth", "0");
\r
791 iframe.setAttribute("marginHeight", "0");
\r
792 iframe.setAttribute("leftMargin", "0");
\r
793 iframe.setAttribute("topMargin", "0");
\r
794 iframe.setAttribute("width", aw);
\r
795 iframe.setAttribute("height", ah);
\r
796 iframe.setAttribute("allowtransparency", "true");
\r
797 iframe.className = 'mceEditorIframe';
\r
799 if (tinyMCE.settings["auto_resize"])
\r
800 iframe.setAttribute("scrolling", "no");
\r
802 // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs
\r
803 if (tinyMCE.isRealIE)
\r
804 iframe.setAttribute("src", this.settings['default_document']);
\r
806 iframe.style.width = aw;
\r
807 iframe.style.height = ah;
\r
809 // Ugly hack for Gecko problem in strict mode
\r
810 if (tinyMCE.settings.strict_loading_mode)
\r
811 iframe.style.marginBottom = '-5px';
\r
814 if (tinyMCE.isRealIE)
\r
815 replace_element.outerHTML = iframe.outerHTML;
\r
817 replace_element.parentNode.replaceChild(iframe, replace_element);
\r
819 if (tinyMCE.isRealIE)
\r
820 return win.frames[id];
\r
825 setupContent : function(editor_id) {
\r
826 var inst = tinyMCE.instances[editor_id], i;
\r
827 var doc = inst.getDoc();
\r
828 var head = doc.getElementsByTagName('head').item(0);
\r
829 var content = inst.startContent;
\r
831 // HTML values get XML encoded in strict mode
\r
832 if (tinyMCE.settings.strict_loading_mode) {
\r
833 content = content.replace(/</g, '<');
\r
834 content = content.replace(/>/g, '>');
\r
835 content = content.replace(/"/g, '"');
\r
836 content = content.replace(/&/g, '&');
\r
839 inst.switchSettings();
\r
841 // Not loaded correctly hit it again, Mozilla bug #997860
\r
842 if (!tinyMCE.isIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") {
\r
843 // This part will remove the designMode status
\r
844 // Failes first time in Firefox 1.5b2 on Mac
\r
845 try {doc.location.href = tinyMCE.baseURL + "/blank.htm";} catch (ex) {}
\r
846 window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 1000);
\r
851 window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10);
\r
855 // Import theme specific content CSS the user specific
\r
856 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/themes/" + inst.settings['theme'] + "/css/editor_content.css");
\r
857 tinyMCE.importCSS(inst.getDoc(), inst.settings['content_css']);
\r
858 tinyMCE.dispatchCallback(inst, 'init_instance_callback', 'initInstance', inst);
\r
860 // Setup keyboard shortcuts
\r
861 if (tinyMCE.getParam('custom_undo_redo_keyboard_shortcuts')) {
\r
862 inst.addShortcut('ctrl', 'z', 'lang_undo_desc', 'Undo');
\r
863 inst.addShortcut('ctrl', 'y', 'lang_redo_desc', 'Redo');
\r
866 // BlockFormat shortcuts keys
\r
867 for (i=1; i<=6; i++)
\r
868 inst.addShortcut('ctrl', '' + i, '', 'FormatBlock', false, '<h' + i + '>');
\r
870 inst.addShortcut('ctrl', '7', '', 'FormatBlock', false, '<p>');
\r
871 inst.addShortcut('ctrl', '8', '', 'FormatBlock', false, '<div>');
\r
872 inst.addShortcut('ctrl', '9', '', 'FormatBlock', false, '<address>');
\r
874 // Add default shortcuts for gecko
\r
875 if (tinyMCE.isGecko) {
\r
876 inst.addShortcut('ctrl', 'b', 'lang_bold_desc', 'Bold');
\r
877 inst.addShortcut('ctrl', 'i', 'lang_italic_desc', 'Italic');
\r
878 inst.addShortcut('ctrl', 'u', 'lang_underline_desc', 'Underline');
\r
881 // Setup span styles
\r
882 if (tinyMCE.getParam("convert_fonts_to_spans"))
\r
883 inst.getBody().setAttribute('id', 'mceSpanFonts');
\r
885 if (tinyMCE.settings['nowrap'])
\r
886 doc.body.style.whiteSpace = "nowrap";
\r
888 doc.body.dir = this.settings['directionality'];
\r
889 doc.editorId = editor_id;
\r
891 // Add on document element in Mozilla
\r
893 doc.documentElement.editorId = editor_id;
\r
895 inst.setBaseHREF(tinyMCE.settings['base_href']);
\r
897 // Replace new line characters to BRs
\r
898 if (tinyMCE.settings['convert_newlines_to_brs']) {
\r
899 content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi");
\r
900 content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi");
\r
901 content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi");
\r
904 // Open closed anchors
\r
905 // content = content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
\r
907 // Call custom cleanup code
\r
908 content = tinyMCE.storeAwayURLs(content);
\r
909 content = tinyMCE._customCleanup(inst, "insert_to_editor", content);
\r
911 if (tinyMCE.isIE) {
\r
913 window.setInterval('try{tinyMCE.getCSSClasses(tinyMCE.instances["' + editor_id + '"].getDoc(), "' + editor_id + '");}catch(e){}', 500);
\r
915 if (tinyMCE.settings["force_br_newlines"])
\r
916 doc.styleSheets[0].addRule("p", "margin: 0;");
\r
918 var body = inst.getBody();
\r
919 body.editorId = editor_id;
\r
922 content = tinyMCE.cleanupHTMLCode(content);
\r
924 // Fix for bug #958637
\r
925 if (!tinyMCE.isIE) {
\r
926 var contentElement = inst.getDoc().createElement("body");
\r
927 var doc = inst.getDoc();
\r
929 contentElement.innerHTML = content;
\r
931 // Remove weridness!
\r
932 if (tinyMCE.isGecko && tinyMCE.settings['remove_lt_gt'])
\r
933 content = content.replace(new RegExp('<>', 'g'), "");
\r
935 if (tinyMCE.settings['cleanup_on_startup'])
\r
936 tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement));
\r
938 tinyMCE.setInnerHTML(inst.getBody(), content);
\r
940 tinyMCE.convertAllRelativeURLs(inst.getBody());
\r
942 if (tinyMCE.settings['cleanup_on_startup']) {
\r
943 tinyMCE._setHTML(inst.getDoc(), content);
\r
945 // Produces permission denied error in MSIE 5.5
\r
946 eval('try {tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody()));} catch(e) {}');
\r
948 tinyMCE._setHTML(inst.getDoc(), content);
\r
951 // Fix for bug #957681
\r
952 //inst.getDoc().designMode = inst.getDoc().designMode;
\r
954 // Setup element references
\r
955 var parentElm = inst.targetDoc.getElementById(inst.editorId + '_parent');
\r
956 inst.formElement = tinyMCE.isGecko ? parentElm.previousSibling : parentElm.nextSibling;
\r
958 tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings['visual'], inst);
\r
959 tinyMCE.dispatchCallback(inst, 'setupcontent_callback', 'setupContent', editor_id, inst.getBody(), inst.getDoc());
\r
961 // Re-add design mode on mozilla
\r
963 tinyMCE.addEventHandlers(inst);
\r
965 // Add blur handler
\r
966 if (tinyMCE.isIE) {
\r
967 tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE_Engine.prototype._eventPatch);
\r
968 tinyMCE.addEvent(inst.getBody(), "beforedeactivate", TinyMCE_Engine.prototype._eventPatch); // Bug #1439953
\r
970 // Workaround for drag drop/copy paste base href bug
\r
971 if (!tinyMCE.isOpera) {
\r
972 tinyMCE.addEvent(doc.body, "mousemove", TinyMCE_Engine.prototype.onMouseMove);
\r
973 tinyMCE.addEvent(doc.body, "beforepaste", TinyMCE_Engine.prototype._eventPatch);
\r
974 tinyMCE.addEvent(doc.body, "drop", TinyMCE_Engine.prototype._eventPatch);
\r
978 // Trigger node change, this call locks buttons for tables and so forth
\r
980 tinyMCE.selectedElement = inst.contentWindow.document.body;
\r
982 // Call custom DOM cleanup
\r
983 tinyMCE._customCleanup(inst, "insert_to_editor_dom", inst.getBody());
\r
984 tinyMCE._customCleanup(inst, "setup_content_dom", inst.getBody());
\r
985 tinyMCE._setEventsEnabled(inst.getBody(), false);
\r
986 tinyMCE.cleanupAnchors(inst.getDoc());
\r
988 if (tinyMCE.getParam("convert_fonts_to_spans"))
\r
989 tinyMCE.convertSpansToFonts(inst.getDoc());
\r
991 inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);
\r
992 inst.undoRedo.add({ content : inst.startContent });
\r
994 // Cleanup any mess left from storyAwayURLs
\r
995 if (tinyMCE.isGecko) {
\r
996 // Remove mce_src from textnodes and comments
\r
997 tinyMCE.selectNodes(inst.getBody(), function(n) {
\r
998 if (n.nodeType == 3 || n.nodeType == 8)
\r
999 n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), "");
\r
1005 // Remove Gecko spellchecking
\r
1006 if (tinyMCE.isGecko)
\r
1007 inst.getBody().spellcheck = tinyMCE.getParam("gecko_spellcheck");
\r
1009 // Cleanup any mess left from storyAwayURLs
\r
1010 tinyMCE._removeInternal(inst.getBody());
\r
1013 tinyMCE.triggerNodeChange(false, true);
\r
1016 storeAwayURLs : function(s) {
\r
1017 // Remove all mce_src, mce_href and replace them with new ones
\r
1018 // s = s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
\r
1019 // s = s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
\r
1021 if (!s.match(/(mce_src|mce_href)/gi, s)) {
\r
1022 s = s.replace(new RegExp('src\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'src="$1" mce_src="$1"');
\r
1023 s = s.replace(new RegExp('href\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'href="$1" mce_href="$1"');
\r
1029 _removeInternal : function(n) {
\r
1030 if (tinyMCE.isGecko) {
\r
1031 // Remove mce_src from textnodes and comments
\r
1032 tinyMCE.selectNodes(n, function(n) {
\r
1033 if (n.nodeType == 3 || n.nodeType == 8)
\r
1034 n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), "");
\r
1041 handleEvent : function(e) {
\r
1042 var inst = tinyMCE.selectedInstance;
\r
1044 // Remove odd, error
\r
1045 if (typeof(tinyMCE) == "undefined")
\r
1048 //tinyMCE.debug(e.type + " " + e.target.nodeName + " " + (e.relatedTarget ? e.relatedTarget.nodeName : ""));
\r
1050 if (tinyMCE.executeCallback(tinyMCE.selectedInstance, 'handle_event_callback', 'handleEvent', e))
\r
1054 case "beforedeactivate": // Was added due to bug #1439953
\r
1056 if (tinyMCE.selectedInstance)
\r
1057 tinyMCE.selectedInstance.execCommand('mceEndTyping');
\r
1059 tinyMCE.hideMenus();
\r
1063 // Workaround for drag drop/copy paste base href bug
\r
1065 case "beforepaste":
\r
1066 if (tinyMCE.selectedInstance)
\r
1067 tinyMCE.selectedInstance.setBaseHREF(null);
\r
1069 // Fixes odd MSIE bug where drag/droping elements in a iframe with height 100% breaks
\r
1070 // This logic forces the width/height to be in pixels while the user is drag/dropping
\r
1071 if (tinyMCE.isRealIE) {
\r
1072 var ife = tinyMCE.selectedInstance.iframeElement;
\r
1074 /*if (ife.style.width.indexOf('%') != -1) {
\r
1075 ife._oldWidth = ife.width.height;
\r
1076 ife.style.width = ife.clientWidth;
\r
1079 if (ife.style.height.indexOf('%') != -1) {
\r
1080 ife._oldHeight = ife.style.height;
\r
1081 ife.style.height = ife.clientHeight;
\r
1085 window.setTimeout("tinyMCE.selectedInstance.setBaseHREF(tinyMCE.settings['base_href']);tinyMCE._resetIframeHeight();", 1);
\r
1089 tinyMCE.triggerSave();
\r
1090 tinyMCE.isNotDirty = true;
\r
1094 var formObj = tinyMCE.isIE ? window.event.srcElement : e.target;
\r
1096 for (var i=0; i<document.forms.length; i++) {
\r
1097 if (document.forms[i] == formObj)
\r
1098 window.setTimeout('tinyMCE.resetForm(' + i + ');', 10);
\r
1104 if (inst && inst.handleShortcut(e))
\r
1107 if (e.target.editorId) {
\r
1108 tinyMCE.instances[e.target.editorId].select();
\r
1110 if (e.target.ownerDocument.editorId)
\r
1111 tinyMCE.instances[e.target.ownerDocument.editorId].select();
\r
1114 if (tinyMCE.selectedInstance)
\r
1115 tinyMCE.selectedInstance.switchSettings();
\r
1117 // Insert P element
\r
1118 if ((tinyMCE.isGecko || tinyMCE.isOpera || tinyMCE.isSafari) && tinyMCE.settings['force_p_newlines'] && e.keyCode == 13 && !e.shiftKey) {
\r
1119 // Insert P element instead of BR
\r
1120 if (TinyMCE_ForceParagraphs._insertPara(tinyMCE.selectedInstance, e)) {
\r
1122 tinyMCE.execCommand("mceAddUndoLevel");
\r
1123 return tinyMCE.cancelEvent(e);
\r
1127 // Handle backspace
\r
1128 if ((tinyMCE.isGecko && !tinyMCE.isSafari) && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
\r
1129 // Insert P element instead of BR
\r
1130 if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) {
\r
1132 tinyMCE.execCommand("mceAddUndoLevel");
\r
1133 return tinyMCE.cancelEvent(e);
\r
1137 // Return key pressed
\r
1138 if (tinyMCE.isIE && tinyMCE.settings['force_br_newlines'] && e.keyCode == 13) {
\r
1139 if (e.target.editorId)
\r
1140 tinyMCE.instances[e.target.editorId].select();
\r
1142 if (tinyMCE.selectedInstance) {
\r
1143 var sel = tinyMCE.selectedInstance.getDoc().selection;
\r
1144 var rng = sel.createRange();
\r
1146 if (tinyMCE.getParentElement(rng.parentElement(), "li") != null)
\r
1150 e.returnValue = false;
\r
1151 e.cancelBubble = true;
\r
1153 // Insert BR element
\r
1154 rng.pasteHTML("<br />");
\r
1155 rng.collapse(false);
\r
1158 tinyMCE.execCommand("mceAddUndoLevel");
\r
1159 tinyMCE.triggerNodeChange(false);
\r
1164 // Backspace or delete
\r
1165 if (e.keyCode == 8 || e.keyCode == 46) {
\r
1166 tinyMCE.selectedElement = e.target;
\r
1167 tinyMCE.linkElement = tinyMCE.getParentElement(e.target, "a");
\r
1168 tinyMCE.imgElement = tinyMCE.getParentElement(e.target, "img");
\r
1169 tinyMCE.triggerNodeChange(false);
\r
1177 tinyMCE.hideMenus();
\r
1178 tinyMCE.hasMouseMoved = false;
\r
1180 if (inst && inst.handleShortcut(e))
\r
1183 if (e.target.editorId)
\r
1184 tinyMCE.instances[e.target.editorId].select();
\r
1186 if (tinyMCE.selectedInstance)
\r
1187 tinyMCE.selectedInstance.switchSettings();
\r
1189 var inst = tinyMCE.selectedInstance;
\r
1191 // Handle backspace
\r
1192 if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
\r
1193 // Insert P element instead of BR
\r
1194 if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) {
\r
1196 tinyMCE.execCommand("mceAddUndoLevel");
\r
1197 e.preventDefault();
\r
1202 tinyMCE.selectedElement = null;
\r
1203 tinyMCE.selectedNode = null;
\r
1204 var elm = tinyMCE.selectedInstance.getFocusElement();
\r
1205 tinyMCE.linkElement = tinyMCE.getParentElement(elm, "a");
\r
1206 tinyMCE.imgElement = tinyMCE.getParentElement(elm, "img");
\r
1207 tinyMCE.selectedElement = elm;
\r
1209 // Update visualaids on tabs
\r
1210 if (tinyMCE.isGecko && e.type == "keyup" && e.keyCode == 9)
\r
1211 tinyMCE.handleVisualAid(tinyMCE.selectedInstance.getBody(), true, tinyMCE.settings['visual'], tinyMCE.selectedInstance);
\r
1213 // Fix empty elements on return/enter, check where enter occured
\r
1214 if (tinyMCE.isIE && e.type == "keydown" && e.keyCode == 13)
\r
1215 tinyMCE.enterKeyElement = tinyMCE.selectedInstance.getFocusElement();
\r
1217 // Fix empty elements on return/enter
\r
1218 if (tinyMCE.isIE && e.type == "keyup" && e.keyCode == 13) {
\r
1219 var elm = tinyMCE.enterKeyElement;
\r
1221 var re = new RegExp('^HR|IMG|BR$','g'); // Skip these
\r
1222 var dre = new RegExp('^H[1-6]$','g'); // Add double on these
\r
1224 if (!elm.hasChildNodes() && !re.test(elm.nodeName)) {
\r
1225 if (dre.test(elm.nodeName))
\r
1226 elm.innerHTML = " ";
\r
1228 elm.innerHTML = " ";
\r
1233 // Check if it's a position key
\r
1234 var keys = tinyMCE.posKeyCodes;
\r
1235 var posKey = false;
\r
1236 for (var i=0; i<keys.length; i++) {
\r
1237 if (keys[i] == e.keyCode) {
\r
1243 // MSIE custom key handling
\r
1244 if (tinyMCE.isIE && tinyMCE.settings['custom_undo_redo']) {
\r
1245 var keys = new Array(8,46); // Backspace,Delete
\r
1247 for (var i=0; i<keys.length; i++) {
\r
1248 if (keys[i] == e.keyCode) {
\r
1249 if (e.type == "keyup")
\r
1250 tinyMCE.triggerNodeChange(false);
\r
1256 if (e.keyCode == 17)
\r
1259 // Handle Undo/Redo when typing content
\r
1261 if (tinyMCE.isGecko) {
\r
1262 // Start typing (not a position key or ctrl key, but ctrl+x and ctrl+p is ok)
\r
1263 if (!posKey && e.type == "keyup" && !e.ctrlKey || (e.ctrlKey && (e.keyCode == 86 || e.keyCode == 88)))
\r
1264 tinyMCE.execCommand("mceStartTyping");
\r
1266 // IE seems to be working better with this setting
\r
1267 if (!posKey && e.type == "keyup")
\r
1268 tinyMCE.execCommand("mceStartTyping");
\r
1271 // Store undo bookmark
\r
1272 if (e.type == "keydown" && (posKey || e.ctrlKey) && inst)
\r
1273 inst.undoBookmark = inst.selection.getBookmark();
\r
1275 // End typing (position key) or some Ctrl event
\r
1276 if (e.type == "keyup" && (posKey || e.ctrlKey))
\r
1277 tinyMCE.execCommand("mceEndTyping");
\r
1279 if (posKey && e.type == "keyup")
\r
1280 tinyMCE.triggerNodeChange(false);
\r
1282 if (tinyMCE.isIE && e.ctrlKey)
\r
1283 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
\r
1291 tinyMCE.hideMenus();
\r
1293 if (tinyMCE.selectedInstance) {
\r
1294 tinyMCE.selectedInstance.switchSettings();
\r
1295 tinyMCE.selectedInstance.isFocused = true;
\r
1298 // Check instance event trigged on
\r
1299 var targetBody = tinyMCE.getParentElement(e.target, "html");
\r
1300 for (var instanceName in tinyMCE.instances) {
\r
1301 if (!tinyMCE.isInstance(tinyMCE.instances[instanceName]))
\r
1304 var inst = tinyMCE.instances[instanceName];
\r
1306 // Reset design mode if lost (on everything just in case)
\r
1307 inst.autoResetDesignMode();
\r
1309 // Use HTML element since users might click outside of body element
\r
1310 if (inst.getBody().parentNode == targetBody) {
\r
1312 tinyMCE.selectedElement = e.target;
\r
1313 tinyMCE.linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");
\r
1314 tinyMCE.imgElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "img");
\r
1319 // Add first bookmark location
\r
1320 if (!tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark && (e.type == "mouseup" || e.type == "dblclick"))
\r
1321 tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark = tinyMCE.selectedInstance.selection.getBookmark();
\r
1323 // Reset selected node
\r
1324 if (e.type != "focus")
\r
1325 tinyMCE.selectedNode = null;
\r
1327 tinyMCE.triggerNodeChange(false);
\r
1328 tinyMCE.execCommand("mceEndTyping");
\r
1330 if (e.type == "mouseup")
\r
1331 tinyMCE.execCommand("mceAddUndoLevel");
\r
1334 if (!tinyMCE.selectedInstance && e.target.editorId)
\r
1335 tinyMCE.instances[e.target.editorId].select();
\r
1342 getButtonHTML : function(id, lang, img, cmd, ui, val) {
\r
1343 var h = '', m, x, io = '';
\r
1345 cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\'';
\r
1347 if (typeof(ui) != "undefined" && ui != null)
\r
1350 if (typeof(val) != "undefined" && val != null)
\r
1351 cmd += ",'" + val + "'";
\r
1355 // Patch for IE7 bug with hover out not restoring correctly
\r
1356 if (tinyMCE.isRealIE)
\r
1357 io = 'onmouseover="tinyMCE.lastHover = this;"';
\r
1359 // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled
\r
1360 if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = this.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) {
\r
1362 x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20);
\r
1363 h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceTiledButton mceButtonNormal" target="_self">';
\r
1364 h += '<img src="{$themeurl}/images/spacer.gif" style="background-position: ' + x + 'px 0" title="{$' + lang + '}" />';
\r
1368 h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceButtonNormal" target="_self">';
\r
1369 h += '<img src="' + img + '" title="{$' + lang + '}" />';
\r
1376 getMenuButtonHTML : function(id, lang, img, mcmd, cmd, ui, val) {
\r
1379 mcmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + mcmd + '\');';
\r
1380 cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\'';
\r
1382 if (typeof(ui) != "undefined" && ui != null)
\r
1385 if (typeof(val) != "undefined" && val != null)
\r
1386 cmd += ",'" + val + "'";
\r
1390 // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled
\r
1391 if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = tinyMCE.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) {
\r
1392 x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20);
\r
1394 if (tinyMCE.isRealIE)
\r
1395 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">';
\r
1397 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton">';
\r
1399 h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceTiledButton mceMenuButtonNormal" target="_self">';
\r
1400 h += '<img src="{$themeurl}/images/spacer.gif" style="width: 20px; height: 20px; background-position: ' + x + 'px 0" title="{$' + lang + '}" /></a>';
\r
1401 h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />';
\r
1402 h += '</a></span>';
\r
1404 if (tinyMCE.isRealIE)
\r
1405 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">';
\r
1407 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton">';
\r
1409 h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceMenuButtonNormal" target="_self">';
\r
1410 h += '<img src="' + img + '" title="{$' + lang + '}" /></a>';
\r
1411 h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />';
\r
1412 h += '</a></span>';
\r
1418 _menuButtonEvent : function(e, o) {
\r
1419 if (o.className == 'mceMenuButtonFocus')
\r
1423 o.className = o.className + ' mceMenuHover';
\r
1425 o.className = o.className.replace(/\s.*$/, '');
\r
1428 addButtonMap : function(m) {
\r
1429 var i, a = m.replace(/\s+/, '').split(',');
\r
1431 for (i=0; i<a.length; i++)
\r
1432 this.buttonMap[a[i]] = i;
\r
1435 submitPatch : function() {
\r
1436 tinyMCE.triggerSave();
\r
1437 tinyMCE.isNotDirty = true;
\r
1438 this.mceOldSubmit();
\r
1441 onLoad : function() {
\r
1444 // Wait for everything to be loaded first
\r
1445 if (tinyMCE.settings.strict_loading_mode && this.loadingIndex != -1) {
\r
1446 window.setTimeout('tinyMCE.onLoad();', 1);
\r
1450 if (tinyMCE.isRealIE && window.event.type == "readystatechange" && document.readyState != "complete")
\r
1453 if (tinyMCE.isLoaded)
\r
1456 tinyMCE.isLoaded = true;
\r
1458 // IE produces JS error if TinyMCE is placed in a frame
\r
1459 // It seems to have something to do with the selection not beeing
\r
1460 // correctly initialized in IE so this hack solves the problem
\r
1461 if (tinyMCE.isRealIE && document.body) {
\r
1462 r = document.body.createTextRange();
\r
1467 tinyMCE.dispatchCallback(null, 'onpageload', 'onPageLoad');
\r
1469 for (var c=0; c<tinyMCE.configs.length; c++) {
\r
1470 tinyMCE.settings = tinyMCE.configs[c];
\r
1472 var selector = tinyMCE.getParam("editor_selector");
\r
1473 var deselector = tinyMCE.getParam("editor_deselector");
\r
1474 var elementRefAr = new Array();
\r
1476 // Add submit triggers
\r
1477 if (document.forms && tinyMCE.settings['add_form_submit_trigger'] && !tinyMCE.submitTriggers) {
\r
1478 for (var i=0; i<document.forms.length; i++) {
\r
1479 var form = document.forms[i];
\r
1481 tinyMCE.addEvent(form, "submit", TinyMCE_Engine.prototype.handleEvent);
\r
1482 tinyMCE.addEvent(form, "reset", TinyMCE_Engine.prototype.handleEvent);
\r
1483 tinyMCE.submitTriggers = true; // Do it only once
\r
1485 // Patch the form.submit function
\r
1486 if (tinyMCE.settings['submit_patch']) {
\r
1488 form.mceOldSubmit = form.submit;
\r
1489 form.submit = TinyMCE_Engine.prototype.submitPatch;
\r
1497 // Add editor instances based on mode
\r
1498 var mode = tinyMCE.settings['mode'];
\r
1501 var elements = tinyMCE.getParam('elements', '', true, ',');
\r
1503 for (var i=0; i<elements.length; i++) {
\r
1504 var element = tinyMCE._getElementById(elements[i]);
\r
1505 var trigger = element ? element.getAttribute(tinyMCE.settings['textarea_trigger']) : "";
\r
1507 if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(element, "class")))
\r
1510 if (trigger == "false")
\r
1513 if ((tinyMCE.settings['ask'] || tinyMCE.settings['convert_on_click']) && element) {
\r
1514 elementRefAr[elementRefAr.length] = element;
\r
1519 tinyMCE.addMCEControl(element, elements[i]);
\r
1520 else if (tinyMCE.settings['debug'])
\r
1521 alert("Error: Could not find element by id or name: " + elements[i]);
\r
1525 case "specific_textareas":
\r
1527 var nodeList = document.getElementsByTagName("textarea");
\r
1529 for (var i=0; i<nodeList.length; i++) {
\r
1530 var elm = nodeList.item(i);
\r
1531 var trigger = elm.getAttribute(tinyMCE.settings['textarea_trigger']);
\r
1533 if (selector != '' && !new RegExp('\\b' + selector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
\r
1536 if (selector != '')
\r
1537 trigger = selector != "" ? "true" : "";
\r
1539 if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
\r
1542 if ((mode == "specific_textareas" && trigger == "true") || (mode == "textareas" && trigger != "false"))
\r
1543 elementRefAr[elementRefAr.length] = elm;
\r
1548 for (var i=0; i<elementRefAr.length; i++) {
\r
1549 var element = elementRefAr[i];
\r
1550 var elementId = element.name ? element.name : element.id;
\r
1552 if (tinyMCE.settings['ask'] || tinyMCE.settings['convert_on_click']) {
\r
1553 // Focus breaks in Mozilla
\r
1554 if (tinyMCE.isGecko) {
\r
1555 var settings = tinyMCE.settings;
\r
1557 tinyMCE.addEvent(element, "focus", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
\r
1559 if (element.nodeName != "TEXTAREA" && element.nodeName != "INPUT")
\r
1560 tinyMCE.addEvent(element, "click", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
\r
1561 // tinyMCE.addEvent(element, "mouseover", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
\r
1563 var settings = tinyMCE.settings;
\r
1565 tinyMCE.addEvent(element, "focus", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
\r
1566 tinyMCE.addEvent(element, "click", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
\r
1567 // tinyMCE.addEvent(element, "mouseenter", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
\r
1570 tinyMCE.addMCEControl(element, elementId);
\r
1573 // Handle auto focus
\r
1574 if (tinyMCE.settings['auto_focus']) {
\r
1575 window.setTimeout(function () {
\r
1576 var inst = tinyMCE.getInstanceById(tinyMCE.settings['auto_focus']);
\r
1577 inst.selection.selectNode(inst.getBody(), true, true);
\r
1578 inst.contentWindow.focus();
\r
1582 tinyMCE.dispatchCallback(null, 'oninit', 'onInit');
\r
1586 isInstance : function(o) {
\r
1587 return o != null && typeof(o) == "object" && o.isTinyMCE_Control;
\r
1590 getParam : function(name, default_value, strip_whitespace, split_chr) {
\r
1591 var value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
\r
1593 // Fix bool values
\r
1594 if (value == "true" || value == "false")
\r
1595 return (value == "true");
\r
1597 if (strip_whitespace)
\r
1598 value = tinyMCE.regexpReplace(value, "[ \t\r\n]", "");
\r
1600 if (typeof(split_chr) != "undefined" && split_chr != null) {
\r
1601 value = value.split(split_chr);
\r
1602 var outArray = new Array();
\r
1604 for (var i=0; i<value.length; i++) {
\r
1605 if (value[i] && value[i] != "")
\r
1606 outArray[outArray.length] = value[i];
\r
1615 getLang : function(name, default_value, parse_entities, va) {
\r
1616 var v = (typeof(tinyMCELang[name]) == "undefined") ? default_value : tinyMCELang[name], n;
\r
1618 if (parse_entities)
\r
1619 v = tinyMCE.entityDecode(v);
\r
1623 v = this.replaceVar(v, n, va[n]);
\r
1629 entityDecode : function(s) {
\r
1630 var e = document.createElement("div");
\r
1634 return e.firstChild.nodeValue;
\r
1637 addToLang : function(prefix, ar) {
\r
1638 for (var key in ar) {
\r
1639 if (typeof(ar[key]) == 'function')
\r
1642 tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = ar[key];
\r
1645 this.loadNextScript();
\r
1647 // for (var key in ar)
\r
1648 // tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = "|" + ar[key] + "|";
\r
1651 triggerNodeChange : function(focus, setup_content) {
\r
1652 if (tinyMCE.selectedInstance) {
\r
1653 var inst = tinyMCE.selectedInstance;
\r
1654 var editorId = inst.editorId;
\r
1655 var elm = (typeof(setup_content) != "undefined" && setup_content) ? tinyMCE.selectedElement : inst.getFocusElement();
\r
1656 var undoIndex = -1, doc;
\r
1657 var undoLevels = -1;
\r
1658 var anySelection = false;
\r
1659 var selectedText = inst.selection.getSelectedText();
\r
1661 if (tinyMCE.settings.auto_resize)
\r
1662 inst.resizeToContent();
\r
1664 if (setup_content && tinyMCE.isGecko && inst.isHidden())
\r
1665 elm = inst.getBody();
\r
1667 inst.switchSettings();
\r
1669 if (tinyMCE.selectedElement)
\r
1670 anySelection = (tinyMCE.selectedElement.nodeName.toLowerCase() == "img") || (selectedText && selectedText.length > 0);
\r
1672 if (tinyMCE.settings['custom_undo_redo']) {
\r
1673 undoIndex = inst.undoRedo.undoIndex;
\r
1674 undoLevels = inst.undoRedo.undoLevels.length;
\r
1677 tinyMCE.dispatchCallback(inst, 'handle_node_change_callback', 'handleNodeChange', editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content);
\r
1680 if (this.selectedInstance && (typeof(focus) == "undefined" || focus))
\r
1681 this.selectedInstance.contentWindow.focus();
\r
1684 _customCleanup : function(inst, type, content) {
\r
1687 // Call custom cleanup
\r
1688 var customCleanup = tinyMCE.settings['cleanup_callback'];
\r
1689 if (customCleanup != "" && eval("typeof(" + customCleanup + ")") != "undefined")
\r
1690 content = eval(customCleanup + "(type, content, inst);");
\r
1692 // Trigger theme cleanup
\r
1693 po = tinyMCE.themes[tinyMCE.settings['theme']];
\r
1694 if (po && po.cleanup)
\r
1695 content = po.cleanup(type, content, inst);
\r
1697 // Trigger plugin cleanups
\r
1698 pl = inst.plugins;
\r
1699 for (i=0; i<pl.length; i++) {
\r
1700 po = tinyMCE.plugins[pl[i]];
\r
1702 if (po && po.cleanup)
\r
1703 content = po.cleanup(type, content, inst);
\r
1709 setContent : function(h) {
\r
1710 if (tinyMCE.selectedInstance) {
\r
1711 tinyMCE.selectedInstance.execCommand('mceSetContent', false, h);
\r
1712 tinyMCE.selectedInstance.repaint();
\r
1716 importThemeLanguagePack : function(name) {
\r
1717 if (typeof(name) == "undefined")
\r
1718 name = tinyMCE.settings['theme'];
\r
1720 tinyMCE.loadScript(tinyMCE.baseURL + '/themes/' + name + '/langs/' + tinyMCE.settings['language'] + '.js');
\r
1723 importPluginLanguagePack : function(name) {
\r
1724 var b = tinyMCE.baseURL + '/plugins/' + name;
\r
1726 if (this.plugins[name])
\r
1727 b = this.plugins[name].baseURL;
\r
1729 tinyMCE.loadScript(b + '/langs/' + tinyMCE.settings['language'] + '.js');
\r
1732 applyTemplate : function(h, as) {
\r
1733 return h.replace(new RegExp('\\{\\$([a-z0-9_]+)\\}', 'gi'), function(m, s) {
\r
1734 if (s.indexOf('lang_') == 0 && tinyMCELang[s])
\r
1735 return tinyMCELang[s];
\r
1740 if (tinyMCE.settings[s])
\r
1741 return tinyMCE.settings[s];
\r
1743 if (m == 'themeurl')
\r
1744 return tinyMCE.themeURL;
\r
1750 replaceVar : function(h, r, v) {
\r
1751 return h.replace(new RegExp('{\\\$' + r + '}', 'g'), v);
\r
1754 openWindow : function(template, args) {
\r
1755 var html, width, height, x, y, resizable, scrollbars, url;
\r
1757 args['mce_template_file'] = template['file'];
\r
1758 args['mce_width'] = template['width'];
\r
1759 args['mce_height'] = template['height'];
\r
1760 tinyMCE.windowArgs = args;
\r
1762 html = template['html'];
\r
1763 if (!(width = parseInt(template['width'])))
\r
1766 if (!(height = parseInt(template['height'])))
\r
1769 // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!!
\r
1775 x = parseInt(screen.width / 2.0) - (width / 2.0);
\r
1776 y = parseInt(screen.height / 2.0) - (height / 2.0);
\r
1778 resizable = (args && args['resizable']) ? args['resizable'] : "no";
\r
1779 scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no";
\r
1781 if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1)
\r
1782 url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file'];
\r
1784 url = template['file'];
\r
1786 // Replace all args as variables in URL
\r
1787 for (var name in args) {
\r
1788 if (typeof(args[name]) == 'function')
\r
1791 url = tinyMCE.replaceVar(url, name, escape(args[name]));
\r
1795 html = tinyMCE.replaceVar(html, "css", this.settings['popups_css']);
\r
1796 html = tinyMCE.applyTemplate(html, args);
\r
1798 var 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);
\r
1799 if (win == null) {
\r
1800 alert(tinyMCELang['lang_popup_blocked']);
\r
1804 win.document.write(html);
\r
1805 win.document.close();
\r
1806 win.resizeTo(width, height);
\r
1809 if ((tinyMCE.isRealIE) && resizable != 'yes' && tinyMCE.settings["dialog_type"] == "modal") {
\r
1812 var features = "resizable:" + resizable
\r
1814 + scrollbars + ";status:yes;center:yes;help:no;dialogWidth:"
\r
1815 + width + "px;dialogHeight:" + height + "px;";
\r
1817 window.showModalDialog(url, window, features);
\r
1819 var modal = (resizable == "yes") ? "no" : "yes";
\r
1821 if (tinyMCE.isGecko && tinyMCE.isMac)
\r
1824 if (template['close_previous'] != "no")
\r
1825 try {tinyMCE.lastWindow.close();} catch (ex) {}
\r
1827 var 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);
\r
1828 if (win == null) {
\r
1829 alert(tinyMCELang['lang_popup_blocked']);
\r
1833 if (template['close_previous'] != "no")
\r
1834 tinyMCE.lastWindow = win;
\r
1836 eval('try { win.resizeTo(width, height); } catch(e) { }');
\r
1838 // Make it bigger if statusbar is forced
\r
1839 if (tinyMCE.isGecko) {
\r
1840 if (win.document.defaultView.statusbar.visible)
\r
1841 win.resizeBy(0, tinyMCE.isMac ? 10 : 24);
\r
1849 closeWindow : function(win) {
\r
1853 getVisualAidClass : function(class_name, state) {
\r
1854 var aidClass = tinyMCE.settings['visual_table_class'];
\r
1856 if (typeof(state) == "undefined")
\r
1857 state = tinyMCE.settings['visual'];
\r
1860 var classNames = new Array();
\r
1861 var ar = class_name.split(' ');
\r
1862 for (var i=0; i<ar.length; i++) {
\r
1863 if (ar[i] == aidClass)
\r
1867 classNames[classNames.length] = ar[i];
\r
1871 classNames[classNames.length] = aidClass;
\r
1874 var className = "";
\r
1875 for (var i=0; i<classNames.length; i++) {
\r
1879 className += classNames[i];
\r
1885 handleVisualAid : function(el, deep, state, inst, skip_dispatch) {
\r
1889 if (!skip_dispatch)
\r
1890 tinyMCE.dispatchCallback(inst, 'handle_visual_aid_callback', 'handleVisualAid', el, deep, state, inst);
\r
1892 var tableElement = null;
\r
1894 switch (el.nodeName) {
\r
1896 var oldW = el.style.width;
\r
1897 var oldH = el.style.height;
\r
1898 var bo = tinyMCE.getAttrib(el, "border");
\r
1900 bo = bo == "" || bo == "0" ? true : false;
\r
1902 tinyMCE.setAttrib(el, "class", tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el, "class"), state && bo));
\r
1904 el.style.width = oldW;
\r
1905 el.style.height = oldH;
\r
1907 for (var y=0; y<el.rows.length; y++) {
\r
1908 for (var x=0; x<el.rows[y].cells.length; x++) {
\r
1909 var cn = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el.rows[y].cells[x], "class"), state && bo);
\r
1910 tinyMCE.setAttrib(el.rows[y].cells[x], "class", cn);
\r
1917 var anchorName = tinyMCE.getAttrib(el, "name");
\r
1919 if (anchorName != '' && state) {
\r
1920 el.title = anchorName;
\r
1921 tinyMCE.addCSSClass(el, 'mceItemAnchor');
\r
1922 } else if (anchorName != '' && !state)
\r
1923 el.className = '';
\r
1928 if (deep && el.hasChildNodes()) {
\r
1929 for (var i=0; i<el.childNodes.length; i++)
\r
1930 tinyMCE.handleVisualAid(el.childNodes[i], deep, state, inst, true);
\r
1935 applyClassesToFonts : function(doc, size) {
\r
1936 var f = doc.getElementsByTagName("font");
\r
1937 for (var i=0; i<f.length; i++) {
\r
1938 var s = tinyMCE.getAttrib(f[i], "size");
\r
1941 tinyMCE.setAttrib(f[i], 'class', "mceItemFont" + s);
\r
1944 if (typeof(size) != "undefined") {
\r
1947 for (var x=0; x<doc.styleSheets.length; x++) {
\r
1948 for (var i=0; i<doc.styleSheets[x].rules.length; i++) {
\r
1949 if (doc.styleSheets[x].rules[i].selectorText == '#mceSpanFonts .mceItemFont' + size) {
\r
1950 css = doc.styleSheets[x].rules[i].style.cssText;
\r
1959 if (doc.styleSheets[0].rules[0].selectorText == "FONT")
\r
1960 doc.styleSheets[0].removeRule(0);
\r
1962 doc.styleSheets[0].addRule("FONT", css, 0);
\r
1967 fixGeckoBaseHREFBug : function(m, e, h) {
\r
1970 if (tinyMCE.isGecko) {
\r
1972 h = h.replace(/\ssrc=/gi, " mce_tsrc=");
\r
1973 h = h.replace(/\shref=/gi, " mce_thref=");
\r
1977 // Why bother if there is no src or href broken
\r
1978 if (!new RegExp('(src|href)=', 'g').test(h))
\r
1981 // Restore src and href that gets messed up by Gecko
\r
1982 tinyMCE.selectElements(e, 'A,IMG,SELECT,AREA,IFRAME,BASE,INPUT,SCRIPT,EMBED,OBJECT,LINK', function (n) {
\r
1983 xsrc = tinyMCE.getAttrib(n, "mce_tsrc");
\r
1984 xhref = tinyMCE.getAttrib(n, "mce_thref");
\r
1988 n.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xsrc);
\r
1990 // Ignore, Firefox cast exception if local file wasn't found
\r
1993 n.removeAttribute("mce_tsrc");
\r
1996 if (xhref != "") {
\r
1998 n.href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xhref);
\r
2000 // Ignore, Firefox cast exception if local file wasn't found
\r
2003 n.removeAttribute("mce_thref");
\r
2009 // Restore text/comment nodes
\r
2010 tinyMCE.selectNodes(e, function(n) {
\r
2011 if (n.nodeType == 3 || n.nodeType == 8) {
\r
2012 n.nodeValue = n.nodeValue.replace(/\smce_tsrc=/gi, " src=");
\r
2013 n.nodeValue = n.nodeValue.replace(/\smce_thref=/gi, " href=");
\r
2024 _setHTML : function(doc, html_content) {
\r
2025 // Force closed anchors open
\r
2026 //html_content = html_content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
\r
2028 html_content = tinyMCE.cleanupHTMLCode(html_content);
\r
2030 // Try innerHTML if it fails use pasteHTML in MSIE
\r
2032 tinyMCE.setInnerHTML(doc.body, html_content);
\r
2035 doc.body.createTextRange().pasteHTML(html_content);
\r
2038 // Content duplication bug fix
\r
2039 if (tinyMCE.isIE && tinyMCE.settings['fix_content_duplication']) {
\r
2040 // Remove P elements in P elements
\r
2041 var paras = doc.getElementsByTagName("P");
\r
2042 for (var i=0; i<paras.length; i++) {
\r
2043 var node = paras[i];
\r
2044 while ((node = node.parentNode) != null) {
\r
2045 if (node.nodeName == "P")
\r
2046 node.outerHTML = node.innerHTML;
\r
2050 // Content duplication bug fix (Seems to be word crap)
\r
2051 var html = doc.body.innerHTML;
\r
2053 if (html.indexOf('="mso') != -1) {
\r
2054 for (var i=0; i<doc.body.all.length; i++) {
\r
2055 var el = doc.body.all[i];
\r
2056 el.removeAttribute("className","",0);
\r
2057 el.removeAttribute("style","",0);
\r
2060 html = doc.body.innerHTML;
\r
2061 html = tinyMCE.regexpReplace(html, "<o:p><\/o:p>", "<br />");
\r
2062 html = tinyMCE.regexpReplace(html, "<o:p> <\/o:p>", "");
\r
2063 html = tinyMCE.regexpReplace(html, "<st1:.*?>", "");
\r
2064 html = tinyMCE.regexpReplace(html, "<p><\/p>", "");
\r
2065 html = tinyMCE.regexpReplace(html, "<p><\/p>\r\n<p><\/p>", "");
\r
2066 html = tinyMCE.regexpReplace(html, "<p> <\/p>", "<br />");
\r
2067 html = tinyMCE.regexpReplace(html, "<p>\s*(<p>\s*)?", "<p>");
\r
2068 html = tinyMCE.regexpReplace(html, "<\/p>\s*(<\/p>\s*)?", "</p>");
\r
2071 // Always set the htmlText output
\r
2072 tinyMCE.setInnerHTML(doc.body, html);
\r
2075 tinyMCE.cleanupAnchors(doc);
\r
2077 if (tinyMCE.getParam("convert_fonts_to_spans"))
\r
2078 tinyMCE.convertSpansToFonts(doc);
\r
2081 getEditorId : function(form_element) {
\r
2082 var inst = this.getInstanceById(form_element);
\r
2086 return inst.editorId;
\r
2089 getInstanceById : function(editor_id) {
\r
2090 var inst = this.instances[editor_id];
\r
2092 for (var n in tinyMCE.instances) {
\r
2093 var instance = tinyMCE.instances[n];
\r
2094 if (!tinyMCE.isInstance(instance))
\r
2097 if (instance.formTargetElementId == editor_id) {
\r
2107 queryInstanceCommandValue : function(editor_id, command) {
\r
2108 var inst = tinyMCE.getInstanceById(editor_id);
\r
2110 return inst.queryCommandValue(command);
\r
2115 queryInstanceCommandState : function(editor_id, command) {
\r
2116 var inst = tinyMCE.getInstanceById(editor_id);
\r
2118 return inst.queryCommandState(command);
\r
2123 setWindowArg : function(n, v) {
\r
2124 this.windowArgs[n] = v;
\r
2127 getWindowArg : function(n, d) {
\r
2128 return (typeof(this.windowArgs[n]) == "undefined") ? d : this.windowArgs[n];
\r
2131 getCSSClasses : function(editor_id, doc) {
\r
2132 var output = new Array();
\r
2134 // Is cached, use that
\r
2135 if (typeof(tinyMCE.cssClasses) != "undefined")
\r
2136 return tinyMCE.cssClasses;
\r
2138 if (typeof(editor_id) == "undefined" && typeof(doc) == "undefined") {
\r
2141 for (var instanceName in tinyMCE.instances) {
\r
2142 instance = tinyMCE.instances[instanceName];
\r
2143 if (!tinyMCE.isInstance(instance))
\r
2149 doc = instance.getDoc();
\r
2152 if (typeof(doc) == "undefined") {
\r
2153 var instance = tinyMCE.getInstanceById(editor_id);
\r
2154 doc = instance.getDoc();
\r
2158 var styles = doc.styleSheets;
\r
2160 if (styles && styles.length > 0) {
\r
2161 for (var x=0; x<styles.length; x++) {
\r
2164 // Just ignore any errors
\r
2165 eval("try {var csses = tinyMCE.isIE ? doc.styleSheets(" + x + ").rules : styles[" + x + "].cssRules;} catch(e) {}");
\r
2167 return new Array();
\r
2169 for (var i=0; i<csses.length; i++) {
\r
2170 var selectorText = csses[i].selectorText;
\r
2172 // Can be multiple rules per selector
\r
2173 if (selectorText) {
\r
2174 var rules = selectorText.split(',');
\r
2175 for (var c=0; c<rules.length; c++) {
\r
2176 var rule = rules[c];
\r
2178 // Strip spaces between selectors
\r
2179 while (rule.indexOf(' ') == 0)
\r
2180 rule = rule.substring(1);
\r
2183 if (rule.indexOf(' ') != -1 || rule.indexOf(':') != -1 || rule.indexOf('mceItem') != -1)
\r
2186 if (rule.indexOf(tinyMCE.settings['visual_table_class']) != -1 || rule.indexOf('mceEditable') != -1 || rule.indexOf('mceNonEditable') != -1)
\r
2190 if (rule.indexOf('.') != -1) {
\r
2191 var cssClass = rule.substring(rule.indexOf('.') + 1);
\r
2192 var addClass = true;
\r
2194 for (var p=0; p<output.length && addClass; p++) {
\r
2195 if (output[p] == cssClass)
\r
2200 output[output.length] = cssClass;
\r
2210 if (output.length > 0)
\r
2211 tinyMCE.cssClasses = output;
\r
2216 regexpReplace : function(in_str, reg_exp, replace_str, opts) {
\r
2217 if (in_str == null)
\r
2220 if (typeof(opts) == "undefined")
\r
2223 var re = new RegExp(reg_exp, opts);
\r
2224 return in_str.replace(re, replace_str);
\r
2227 trim : function(s) {
\r
2228 return s.replace(/^\s*|\s*$/g, "");
\r
2231 cleanupEventStr : function(s) {
\r
2233 s = s.replace('function anonymous()\n{\n', '');
\r
2234 s = s.replace('\n}', '');
\r
2235 s = s.replace(/^return true;/gi, ''); // Remove event blocker
\r
2240 getControlHTML : function(c) {
\r
2241 var i, l, n, o, v;
\r
2243 l = tinyMCE.plugins;
\r
2247 if (o.getControlHTML && (v = o.getControlHTML(c)) != '')
\r
2248 return tinyMCE.replaceVar(v, "pluginurl", o.baseURL);
\r
2251 o = tinyMCE.themes[tinyMCE.settings['theme']];
\r
2252 if (o.getControlHTML && (v = o.getControlHTML(c)) != '')
\r
2258 evalFunc : function(f, idx, a, o) {
\r
2261 for (i=idx; i<a.length; i++) {
\r
2262 s += 'a[' + i + ']';
\r
2264 if (i < a.length-1)
\r
2270 return o ? eval("o." + f + s) : eval("f" + s);
\r
2273 dispatchCallback : function(i, p, n) {
\r
2274 return this.callFunc(i, p, n, 0, this.dispatchCallback.arguments);
\r
2277 executeCallback : function(i, p, n) {
\r
2278 return this.callFunc(i, p, n, 1, this.executeCallback.arguments);
\r
2281 execCommandCallback : function(i, p, n) {
\r
2282 return this.callFunc(i, p, n, 2, this.execCommandCallback.arguments);
\r
2285 callFunc : function(ins, p, n, m, a) {
\r
2286 var l, i, on, o, s, v;
\r
2290 l = tinyMCE.getParam(p, '');
\r
2292 if (l != '' && (v = tinyMCE.evalFunc(typeof(l) == "function" ? l : eval(l), 3, a)) == s && m > 0)
\r
2295 if (ins != null) {
\r
2296 for (i=0, l = ins.plugins; i<l.length; i++) {
\r
2297 o = tinyMCE.plugins[l[i]];
\r
2299 if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0)
\r
2304 l = tinyMCE.themes;
\r
2308 if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0)
\r
2315 xmlEncode : function(s) {
\r
2316 return s ? ('' + s).replace(new RegExp('[<>&"\']', 'g'), function (c, b) {
\r
2325 return '''; // ' is not working in MSIE
\r
2338 extend : function(p, np) {
\r
2352 hideMenus : function() {
\r
2353 var e = tinyMCE.lastSelectedMenuBtn;
\r
2355 if (tinyMCE.lastMenu) {
\r
2356 tinyMCE.lastMenu.hide();
\r
2357 tinyMCE.lastMenu = null;
\r
2361 tinyMCE.switchClass(e, tinyMCE.lastMenuBtnClass);
\r
2362 tinyMCE.lastSelectedMenuBtn = null;
\r
2368 // Global instances
\r
2369 var TinyMCE = TinyMCE_Engine; // Compatiblity with gzip compressors
\r
2370 var tinyMCE = new TinyMCE_Engine();
\r
2371 var tinyMCELang = {};
\r
2373 /* file:jscripts/tiny_mce/classes/TinyMCE_Control.class.js */
\r
2375 function TinyMCE_Control(settings) {
\r
2376 var t, i, to, fu, p, x, fn, fu, pn, s = settings;
\r
2378 this.undoRedoLevel = true;
\r
2379 this.isTinyMCE_Control = true;
\r
2381 // Default settings
\r
2382 this.settings = s;
\r
2383 this.settings['theme'] = tinyMCE.getParam("theme", "default");
\r
2384 this.settings['width'] = tinyMCE.getParam("width", -1);
\r
2385 this.settings['height'] = tinyMCE.getParam("height", -1);
\r
2386 this.selection = new TinyMCE_Selection(this);
\r
2387 this.undoRedo = new TinyMCE_UndoRedo(this);
\r
2388 this.cleanup = new TinyMCE_Cleanup();
\r
2389 this.shortcuts = new Array();
\r
2390 this.hasMouseMoved = false;
\r
2391 this.foreColor = this.backColor = "#999999";
\r
2394 this.cleanup.init({
\r
2395 valid_elements : s.valid_elements,
\r
2396 extended_valid_elements : s.extended_valid_elements,
\r
2397 valid_child_elements : s.valid_child_elements,
\r
2398 entities : s.entities,
\r
2399 entity_encoding : s.entity_encoding,
\r
2400 debug : s.cleanup_debug,
\r
2401 url_converter : 'TinyMCE_Cleanup.prototype._urlConverter',
\r
2402 indent : s.apply_source_formatting,
\r
2403 invalid_elements : s.invalid_elements,
\r
2404 verify_html : s.verify_html,
\r
2405 fix_content_duplication : s.fix_content_duplication
\r
2409 t = this.settings['theme'];
\r
2410 if (!tinyMCE.hasTheme(t)) {
\r
2411 fn = tinyMCE.callbacks;
\r
2414 for (i=0; i<fn.length; i++) {
\r
2415 if ((fu = window['TinyMCE_' + t + "_" + fn[i]]))
\r
2419 tinyMCE.addTheme(t, to);
\r
2422 // Wrap old plugins
\r
2423 this.plugins = new Array();
\r
2424 p = tinyMCE.getParam('plugins', '', true, ',');
\r
2425 if (p.length > 0) {
\r
2426 for (i=0; i<p.length; i++) {
\r
2429 if (pn.charAt(0) == '-')
\r
2430 pn = pn.substring(1);
\r
2432 if (!tinyMCE.hasPlugin(pn)) {
\r
2433 fn = tinyMCE.callbacks;
\r
2436 for (x=0; x<fn.length; x++) {
\r
2437 if ((fu = window['TinyMCE_' + pn + "_" + fn[x]]))
\r
2441 tinyMCE.addPlugin(pn, to);
\r
2444 this.plugins[this.plugins.length] = pn;
\r
2449 TinyMCE_Control.prototype = {
\r
2456 getData : function(na) {
\r
2457 var o = this.data[na];
\r
2460 o = this.data[na] = {};
\r
2465 hasPlugin : function(n) {
\r
2468 for (i=0; i<this.plugins.length; i++) {
\r
2469 if (this.plugins[i] == n)
\r
2476 addPlugin : function(n, p) {
\r
2477 if (!this.hasPlugin(n)) {
\r
2478 tinyMCE.addPlugin(n, p);
\r
2479 this.plugins[this.plugins.length] = n;
\r
2483 repaint : function() {
\r
2486 if (tinyMCE.isRealIE)
\r
2490 s = this.selection;
\r
2491 b = s.getBookmark(true);
\r
2492 this.getBody().style.display = 'none';
\r
2493 this.getDoc().execCommand('selectall', false, null);
\r
2494 this.getSel().collapseToStart();
\r
2495 this.getBody().style.display = 'block';
\r
2496 s.moveToBookmark(b);
\r
2502 switchSettings : function() {
\r
2503 if (tinyMCE.configs.length > 1 && tinyMCE.currentConfig != this.settings['index']) {
\r
2504 tinyMCE.settings = this.settings;
\r
2505 tinyMCE.currentConfig = this.settings['index'];
\r
2509 select : function() {
\r
2510 var oldInst = tinyMCE.selectedInstance;
\r
2512 if (oldInst != this) {
\r
2514 oldInst.execCommand('mceEndTyping');
\r
2516 tinyMCE.dispatchCallback(this, 'select_instance_callback', 'selectInstance', this, oldInst);
\r
2517 tinyMCE.selectedInstance = this;
\r
2521 getBody : function() {
\r
2522 return this.contentBody ? this.contentBody : this.getDoc().body;
\r
2525 getDoc : function() {
\r
2526 // return this.contentDocument ? this.contentDocument : this.contentWindow.document; // Removed due to IE 5.5 ?
\r
2527 return this.contentWindow.document;
\r
2530 getWin : function() {
\r
2531 return this.contentWindow;
\r
2534 getContainerWin : function() {
\r
2535 return this.containerWindow ? this.containerWindow : window;
\r
2538 getViewPort : function() {
\r
2539 return tinyMCE.getViewPort(this.getWin());
\r
2542 getParentNode : function(n, f) {
\r
2543 return tinyMCE.getParentNode(n, f, this.getBody());
\r
2546 getParentElement : function(n, na, f) {
\r
2547 return tinyMCE.getParentElement(n, na, f, this.getBody());
\r
2550 getParentBlockElement : function(n) {
\r
2551 return tinyMCE.getParentBlockElement(n, this.getBody());
\r
2554 resizeToContent : function() {
\r
2555 var d = this.getDoc(), b = d.body, de = d.documentElement;
\r
2557 this.iframeElement.style.height = (tinyMCE.isRealIE) ? b.scrollHeight : de.offsetHeight + 'px';
\r
2560 addShortcut : function(m, k, d, cmd, ui, va) {
\r
2561 var n = typeof(k) == "number", ie = tinyMCE.isIE, c, sc, i, scl = this.shortcuts;
\r
2563 if (!tinyMCE.getParam('custom_shortcuts'))
\r
2566 m = m.toLowerCase();
\r
2567 k = ie && !n ? k.toUpperCase() : k;
\r
2568 c = n ? null : k.charCodeAt(0);
\r
2569 d = d && d.indexOf('lang_') == 0 ? tinyMCE.getLang(d) : d;
\r
2572 alt : m.indexOf('alt') != -1,
\r
2573 ctrl : m.indexOf('ctrl') != -1,
\r
2574 shift : m.indexOf('shift') != -1,
\r
2576 keyCode : n ? k : (ie ? c : null),
\r
2583 for (i=0; i<scl.length; i++) {
\r
2584 if (sc.alt == scl[i].alt && sc.ctrl == scl[i].ctrl && sc.shift == scl[i].shift
\r
2585 && sc.charCode == scl[i].charCode && sc.keyCode == scl[i].keyCode) {
\r
2590 scl[scl.length] = sc;
\r
2595 handleShortcut : function(e) {
\r
2596 var i, s = this.shortcuts, o;
\r
2598 for (i=0; i<s.length; i++) {
\r
2601 if (o.alt == e.altKey && o.ctrl == e.ctrlKey && (o.keyCode == e.keyCode || o.charCode == e.charCode)) {
\r
2602 if (o.cmd && (e.type == "keydown" || (e.type == "keypress" && !tinyMCE.isOpera)))
\r
2603 tinyMCE.execCommand(o.cmd, o.ui, o.val);
\r
2605 tinyMCE.cancelEvent(e);
\r
2613 autoResetDesignMode : function() {
\r
2614 // Add fix for tab/style.display none/block problems in Gecko
\r
2615 if (!tinyMCE.isIE && this.isHidden() && tinyMCE.getParam('auto_reset_designmode'))
\r
2616 eval('try { this.getDoc().designMode = "On"; this.useCSS = false; } catch(e) {}');
\r
2619 isHidden : function() {
\r
2625 s = this.getSel();
\r
2627 // Weird, wheres that cursor selection?
\r
2628 return (!s || !s.rangeCount || s.rangeCount == 0);
\r
2631 isDirty : function() {
\r
2632 // Is content modified and not in a submit procedure
\r
2633 return tinyMCE.trim(this.startContent) != tinyMCE.trim(this.getBody().innerHTML) && !tinyMCE.isNotDirty;
\r
2636 _mergeElements : function(scmd, pa, ch, override) {
\r
2637 if (scmd == "removeformat") {
\r
2638 pa.className = "";
\r
2639 pa.style.cssText = "";
\r
2640 ch.className = "";
\r
2641 ch.style.cssText = "";
\r
2645 var st = tinyMCE.parseStyle(tinyMCE.getAttrib(pa, "style"));
\r
2646 var stc = tinyMCE.parseStyle(tinyMCE.getAttrib(ch, "style"));
\r
2647 var className = tinyMCE.getAttrib(pa, "class");
\r
2649 // Removed class adding due to bug #1478272
\r
2650 className = tinyMCE.getAttrib(ch, "class");
\r
2653 for (var n in st) {
\r
2654 if (typeof(st[n]) == 'function')
\r
2660 for (var n in stc) {
\r
2661 if (typeof(stc[n]) == 'function')
\r
2668 tinyMCE.setAttrib(pa, "style", tinyMCE.serializeStyle(st));
\r
2669 tinyMCE.setAttrib(pa, "class", tinyMCE.trim(className));
\r
2670 ch.className = "";
\r
2671 ch.style.cssText = "";
\r
2672 ch.removeAttribute("class");
\r
2673 ch.removeAttribute("style");
\r
2676 _setUseCSS : function(b) {
\r
2677 var d = this.getDoc();
\r
2679 try {d.execCommand("useCSS", false, !b);} catch (ex) {}
\r
2680 try {d.execCommand("styleWithCSS", false, b);} catch (ex) {}
\r
2682 if (!tinyMCE.getParam("table_inline_editing"))
\r
2683 try {d.execCommand('enableInlineTableEditing', false, "false");} catch (ex) {}
\r
2685 if (!tinyMCE.getParam("object_resizing"))
\r
2686 try {d.execCommand('enableObjectResizing', false, "false");} catch (ex) {}
\r
2689 execCommand : function(command, user_interface, value) {
\r
2690 var doc = this.getDoc(), win = this.getWin(), focusElm = this.getFocusElement();
\r
2692 // Is not a undo specific command
\r
2693 if (!new RegExp('mceStartTyping|mceEndTyping|mceBeginUndoLevel|mceEndUndoLevel|mceAddUndoLevel', 'gi').test(command))
\r
2694 this.undoBookmark = null;
\r
2697 if (!tinyMCE.isIE && !this.useCSS) {
\r
2698 this._setUseCSS(false);
\r
2699 this.useCSS = true;
\r
2702 //debug("command: " + command + ", user_interface: " + user_interface + ", value: " + value);
\r
2703 this.contentDocument = doc; // <-- Strange, unless this is applied Mozilla 1.3 breaks
\r
2705 if (tinyMCE.execCommandCallback(this, 'execcommand_callback', 'execCommand', this.editorId, this.getBody(), command, user_interface, value))
\r
2708 // Fix align on images
\r
2709 if (focusElm && focusElm.nodeName == "IMG") {
\r
2710 var align = focusElm.getAttribute('align');
\r
2711 var img = command == "JustifyCenter" ? focusElm.cloneNode(false) : focusElm;
\r
2713 switch (command) {
\r
2714 case "JustifyLeft":
\r
2715 if (align == 'left')
\r
2716 img.removeAttribute('align');
\r
2718 img.setAttribute('align', 'left');
\r
2721 var div = focusElm.parentNode;
\r
2722 if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
\r
2723 div.parentNode.replaceChild(img, div);
\r
2725 this.selection.selectNode(img);
\r
2727 tinyMCE.triggerNodeChange();
\r
2730 case "JustifyCenter":
\r
2731 img.removeAttribute('align');
\r
2734 var div = tinyMCE.getParentElement(focusElm, "div");
\r
2735 if (div && div.style.textAlign == "center") {
\r
2737 if (div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
\r
2738 div.parentNode.replaceChild(img, div);
\r
2741 var div = this.getDoc().createElement("div");
\r
2742 div.style.textAlign = 'center';
\r
2743 div.appendChild(img);
\r
2744 focusElm.parentNode.replaceChild(div, focusElm);
\r
2747 this.selection.selectNode(img);
\r
2749 tinyMCE.triggerNodeChange();
\r
2752 case "JustifyRight":
\r
2753 if (align == 'right')
\r
2754 img.removeAttribute('align');
\r
2756 img.setAttribute('align', 'right');
\r
2759 var div = focusElm.parentNode;
\r
2760 if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
\r
2761 div.parentNode.replaceChild(img, div);
\r
2763 this.selection.selectNode(img);
\r
2765 tinyMCE.triggerNodeChange();
\r
2770 if (tinyMCE.settings['force_br_newlines']) {
\r
2771 var alignValue = "";
\r
2773 if (doc.selection.type != "Control") {
\r
2774 switch (command) {
\r
2775 case "JustifyLeft":
\r
2776 alignValue = "left";
\r
2779 case "JustifyCenter":
\r
2780 alignValue = "center";
\r
2783 case "JustifyFull":
\r
2784 alignValue = "justify";
\r
2787 case "JustifyRight":
\r
2788 alignValue = "right";
\r
2792 if (alignValue != "") {
\r
2793 var rng = doc.selection.createRange();
\r
2795 if ((divElm = tinyMCE.getParentElement(rng.parentElement(), "div")) != null)
\r
2796 divElm.setAttribute("align", alignValue);
\r
2797 else if (rng.pasteHTML && rng.htmlText.length > 0)
\r
2798 rng.pasteHTML('<div align="' + alignValue + '">' + rng.htmlText + "</div>");
\r
2800 tinyMCE.triggerNodeChange();
\r
2806 switch (command) {
\r
2807 case "mceRepaint":
\r
2812 // Unlink if caret is inside link
\r
2813 if (tinyMCE.isGecko && this.getSel().isCollapsed) {
\r
2814 focusElm = tinyMCE.getParentElement(focusElm, 'A');
\r
2817 this.selection.selectNode(focusElm, false);
\r
2820 this.getDoc().execCommand(command, user_interface, value);
\r
2822 tinyMCE.isGecko && this.getSel().collapseToEnd();
\r
2824 tinyMCE.triggerNodeChange();
\r
2828 case "FormatBlock":
\r
2829 if (!this.cleanup.isValid(value))
\r
2832 this.getDoc().execCommand(command, user_interface, value);
\r
2833 tinyMCE.triggerNodeChange();
\r
2836 case "InsertUnorderedList":
\r
2837 case "InsertOrderedList":
\r
2838 this.getDoc().execCommand(command, user_interface, value);
\r
2839 tinyMCE.triggerNodeChange();
\r
2842 case "Strikethrough":
\r
2843 this.getDoc().execCommand(command, user_interface, value);
\r
2844 tinyMCE.triggerNodeChange();
\r
2847 case "mceSelectNode":
\r
2848 this.selection.selectNode(value);
\r
2849 tinyMCE.triggerNodeChange();
\r
2850 tinyMCE.selectedNode = value;
\r
2853 case "FormatBlock":
\r
2854 if (value == null || value == "") {
\r
2855 var elm = tinyMCE.getParentElement(this.getFocusElement(), "p,div,h1,h2,h3,h4,h5,h6,pre,address,blockquote,dt,dl,dd,samp");
\r
2858 this.execCommand("mceRemoveNode", false, elm);
\r
2860 if (tinyMCE.isGecko && new RegExp('<(div|blockquote|code|dt|dd|dl|samp)>', 'gi').test(value))
\r
2861 value = value.replace(/[^a-z]/gi, '');
\r
2863 if (tinyMCE.isIE && new RegExp('blockquote|code|samp', 'gi').test(value)) {
\r
2864 var b = this.selection.getBookmark();
\r
2865 this.getDoc().execCommand("FormatBlock", false, '<p>');
\r
2866 tinyMCE.renameElement(tinyMCE.getParentBlockElement(this.getFocusElement()), value);
\r
2867 this.selection.moveToBookmark(b);
\r
2869 this.getDoc().execCommand("FormatBlock", false, value);
\r
2872 tinyMCE.triggerNodeChange();
\r
2876 case "mceRemoveNode":
\r
2878 value = tinyMCE.getParentElement(this.getFocusElement());
\r
2880 if (tinyMCE.isIE) {
\r
2881 value.outerHTML = value.innerHTML;
\r
2883 var rng = value.ownerDocument.createRange();
\r
2884 rng.setStartBefore(value);
\r
2885 rng.setEndAfter(value);
\r
2886 rng.deleteContents();
\r
2887 rng.insertNode(rng.createContextualFragment(value.innerHTML));
\r
2890 tinyMCE.triggerNodeChange();
\r
2894 case "mceSelectNodeDepth":
\r
2895 var parentNode = this.getFocusElement();
\r
2896 for (var i=0; parentNode; i++) {
\r
2897 if (parentNode.nodeName.toLowerCase() == "body")
\r
2900 if (parentNode.nodeName.toLowerCase() == "#text") {
\r
2902 parentNode = parentNode.parentNode;
\r
2907 this.selection.selectNode(parentNode, false);
\r
2908 tinyMCE.triggerNodeChange();
\r
2909 tinyMCE.selectedNode = parentNode;
\r
2913 parentNode = parentNode.parentNode;
\r
2918 case "SetStyleInfo":
\r
2919 var rng = this.getRng();
\r
2920 var sel = this.getSel();
\r
2921 var scmd = value['command'];
\r
2922 var sname = value['name'];
\r
2923 var svalue = value['value'] == null ? '' : value['value'];
\r
2924 //var svalue = value['value'] == null ? '' : value['value'];
\r
2925 var wrapper = value['wrapper'] ? value['wrapper'] : "span";
\r
2926 var parentElm = null;
\r
2927 var invalidRe = new RegExp("^BODY|HTML$", "g");
\r
2928 var invalidParentsRe = tinyMCE.settings['merge_styles_invalid_parents'] != '' ? new RegExp(tinyMCE.settings['merge_styles_invalid_parents'], "gi") : null;
\r
2930 // Whole element selected check
\r
2931 if (tinyMCE.isIE) {
\r
2934 parentElm = rng.item(0);
\r
2936 var pelm = rng.parentElement();
\r
2937 var prng = doc.selection.createRange();
\r
2938 prng.moveToElementText(pelm);
\r
2940 if (rng.htmlText == prng.htmlText || rng.boundingWidth == 0) {
\r
2941 if (invalidParentsRe == null || !invalidParentsRe.test(pelm.nodeName))
\r
2946 var felm = this.getFocusElement();
\r
2947 if (sel.isCollapsed || (new RegExp('td|tr|tbody|table', 'gi').test(felm.nodeName) && sel.anchorNode == felm.parentNode))
\r
2951 // Whole element selected
\r
2952 if (parentElm && !invalidRe.test(parentElm.nodeName)) {
\r
2953 if (scmd == "setstyle")
\r
2954 tinyMCE.setStyleAttrib(parentElm, sname, svalue);
\r
2956 if (scmd == "setattrib")
\r
2957 tinyMCE.setAttrib(parentElm, sname, svalue);
\r
2959 if (scmd == "removeformat") {
\r
2960 parentElm.style.cssText = '';
\r
2961 tinyMCE.setAttrib(parentElm, 'class', '');
\r
2964 // Remove style/attribs from all children
\r
2965 var ch = tinyMCE.getNodeTree(parentElm, new Array(), 1);
\r
2966 for (var z=0; z<ch.length; z++) {
\r
2967 if (ch[z] == parentElm)
\r
2970 if (scmd == "setstyle")
\r
2971 tinyMCE.setStyleAttrib(ch[z], sname, '');
\r
2973 if (scmd == "setattrib")
\r
2974 tinyMCE.setAttrib(ch[z], sname, '');
\r
2976 if (scmd == "removeformat") {
\r
2977 ch[z].style.cssText = '';
\r
2978 tinyMCE.setAttrib(ch[z], 'class', '');
\r
2982 this._setUseCSS(false); // Bug in FF when running in fullscreen
\r
2983 doc.execCommand("FontName", false, "#mce_temp_font#");
\r
2984 var elementArray = tinyMCE.getElementsByAttributeValue(this.getBody(), "font", "face", "#mce_temp_font#");
\r
2986 // Change them all
\r
2987 for (var x=0; x<elementArray.length; x++) {
\r
2988 elm = elementArray[x];
\r
2990 var spanElm = doc.createElement(wrapper);
\r
2992 if (scmd == "setstyle")
\r
2993 tinyMCE.setStyleAttrib(spanElm, sname, svalue);
\r
2995 if (scmd == "setattrib")
\r
2996 tinyMCE.setAttrib(spanElm, sname, svalue);
\r
2998 if (scmd == "removeformat") {
\r
2999 spanElm.style.cssText = '';
\r
3000 tinyMCE.setAttrib(spanElm, 'class', '');
\r
3003 if (elm.hasChildNodes()) {
\r
3004 for (var i=0; i<elm.childNodes.length; i++)
\r
3005 spanElm.appendChild(elm.childNodes[i].cloneNode(true));
\r
3008 spanElm.setAttribute("mce_new", "true");
\r
3009 elm.parentNode.replaceChild(spanElm, elm);
\r
3011 // Remove style/attribs from all children
\r
3012 var ch = tinyMCE.getNodeTree(spanElm, new Array(), 1);
\r
3013 for (var z=0; z<ch.length; z++) {
\r
3014 if (ch[z] == spanElm)
\r
3017 if (scmd == "setstyle")
\r
3018 tinyMCE.setStyleAttrib(ch[z], sname, '');
\r
3020 if (scmd == "setattrib")
\r
3021 tinyMCE.setAttrib(ch[z], sname, '');
\r
3023 if (scmd == "removeformat") {
\r
3024 ch[z].style.cssText = '';
\r
3025 tinyMCE.setAttrib(ch[z], 'class', '');
\r
3032 // Cleaup wrappers
\r
3033 var nodes = doc.getElementsByTagName(wrapper);
\r
3034 for (var i=nodes.length-1; i>=0; i--) {
\r
3035 var elm = nodes[i];
\r
3036 var isNew = tinyMCE.getAttrib(elm, "mce_new") == "true";
\r
3038 elm.removeAttribute("mce_new");
\r
3040 // Is only child a element
\r
3041 if (elm.childNodes && elm.childNodes.length == 1 && elm.childNodes[0].nodeType == 1) {
\r
3042 //tinyMCE.debug("merge1" + isNew);
\r
3043 this._mergeElements(scmd, elm, elm.childNodes[0], isNew);
\r
3047 // Is I the only child
\r
3048 if (elm.parentNode.childNodes.length == 1 && !invalidRe.test(elm.nodeName) && !invalidRe.test(elm.parentNode.nodeName)) {
\r
3049 //tinyMCE.debug("merge2" + isNew + "," + elm.nodeName + "," + elm.parentNode.nodeName);
\r
3050 if (invalidParentsRe == null || !invalidParentsRe.test(elm.parentNode.nodeName))
\r
3051 this._mergeElements(scmd, elm.parentNode, elm, false);
\r
3055 // Remove empty wrappers
\r
3056 var nodes = doc.getElementsByTagName(wrapper);
\r
3057 for (var i=nodes.length-1; i>=0; i--) {
\r
3058 var elm = nodes[i];
\r
3059 var isEmpty = true;
\r
3061 // Check if it has any attribs
\r
3062 var tmp = doc.createElement("body");
\r
3063 tmp.appendChild(elm.cloneNode(false));
\r
3065 // Is empty span, remove it
\r
3066 tmp.innerHTML = tmp.innerHTML.replace(new RegExp('style=""|class=""', 'gi'), '');
\r
3067 //tinyMCE.debug(tmp.innerHTML);
\r
3068 if (new RegExp('<span>', 'gi').test(tmp.innerHTML)) {
\r
3069 for (var x=0; x<elm.childNodes.length; x++) {
\r
3070 if (elm.parentNode != null)
\r
3071 elm.parentNode.insertBefore(elm.childNodes[x].cloneNode(true), elm);
\r
3074 elm.parentNode.removeChild(elm);
\r
3078 // Re add the visual aids
\r
3079 if (scmd == "removeformat")
\r
3080 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
\r
3082 tinyMCE.triggerNodeChange();
\r
3087 if (value == null) {
\r
3088 var s = this.getSel();
\r
3090 // Find font and select it
\r
3091 if (tinyMCE.isGecko && s.isCollapsed) {
\r
3092 var f = tinyMCE.getParentElement(this.getFocusElement(), "font");
\r
3095 this.selection.selectNode(f, false);
\r
3099 this.getDoc().execCommand("RemoveFormat", false, null);
\r
3101 // Collapse range if font was found
\r
3102 if (f != null && tinyMCE.isGecko) {
\r
3103 var r = this.getRng().cloneRange();
\r
3105 s.removeAllRanges();
\r
3109 this.getDoc().execCommand('FontName', false, value);
\r
3111 if (tinyMCE.isGecko)
\r
3112 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
\r
3117 this.getDoc().execCommand('FontSize', false, value);
\r
3119 if (tinyMCE.isGecko)
\r
3120 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
\r
3125 value = value == null ? this.foreColor : value;
\r
3126 value = tinyMCE.trim(value);
\r
3127 value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value;
\r
3129 this.foreColor = value;
\r
3130 this.getDoc().execCommand('forecolor', false, value);
\r
3133 case "HiliteColor":
\r
3134 value = value == null ? this.backColor : value;
\r
3135 value = tinyMCE.trim(value);
\r
3136 value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value;
\r
3137 this.backColor = value;
\r
3139 if (tinyMCE.isGecko) {
\r
3140 this._setUseCSS(true);
\r
3141 this.getDoc().execCommand('hilitecolor', false, value);
\r
3142 this._setUseCSS(false);
\r
3144 this.getDoc().execCommand('BackColor', false, value);
\r
3150 var cmdFailed = false;
\r
3152 // Try executing command
\r
3153 eval('try {this.getDoc().execCommand(command, user_interface, value);} catch (e) {cmdFailed = true;}');
\r
3155 if (tinyMCE.isOpera && cmdFailed)
\r
3156 alert('Currently not supported by your browser, use keyboard shortcuts instead.');
\r
3158 // Alert error in gecko if command failed
\r
3159 if (tinyMCE.isGecko && cmdFailed) {
\r
3160 // Confirm more info
\r
3161 if (confirm(tinyMCE.entityDecode(tinyMCE.getLang('lang_clipboard_msg'))))
\r
3162 window.open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', 'mceExternal');
\r
3166 tinyMCE.triggerNodeChange();
\r
3169 case "mceSetContent":
\r
3173 // Call custom cleanup code
\r
3174 value = tinyMCE.storeAwayURLs(value);
\r
3175 value = tinyMCE._customCleanup(this, "insert_to_editor", value);
\r
3177 if (this.getBody().nodeName == 'BODY')
\r
3178 tinyMCE._setHTML(doc, value);
\r
3180 this.getBody().innerHTML = value;
\r
3182 tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, doc, this.settings, this.getBody(), false, false, false, true));
\r
3183 tinyMCE.convertAllRelativeURLs(this.getBody());
\r
3185 // Cleanup any mess left from storyAwayURLs
\r
3186 tinyMCE._removeInternal(this.getBody());
\r
3188 // When editing always use fonts internaly
\r
3189 if (tinyMCE.getParam("convert_fonts_to_spans"))
\r
3190 tinyMCE.convertSpansToFonts(doc);
\r
3192 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
\r
3193 tinyMCE._setEventsEnabled(this.getBody(), false);
\r
3196 case "mceCleanup":
\r
3197 var b = this.selection.getBookmark();
\r
3198 tinyMCE._setHTML(this.contentDocument, this.getBody().innerHTML);
\r
3199 tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, this.contentDocument, this.settings, this.getBody(), this.visualAid));
\r
3200 tinyMCE.convertAllRelativeURLs(doc.body);
\r
3202 // When editing always use fonts internaly
\r
3203 if (tinyMCE.getParam("convert_fonts_to_spans"))
\r
3204 tinyMCE.convertSpansToFonts(doc);
\r
3206 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
\r
3207 tinyMCE._setEventsEnabled(this.getBody(), false);
\r
3209 this.selection.moveToBookmark(b);
\r
3210 tinyMCE.triggerNodeChange();
\r
3213 case "mceReplaceContent":
\r
3214 // Force empty string
\r
3218 this.getWin().focus();
\r
3220 var selectedText = "";
\r
3222 if (tinyMCE.isIE) {
\r
3223 var rng = doc.selection.createRange();
\r
3224 selectedText = rng.text;
\r
3226 selectedText = this.getSel().toString();
\r
3228 if (selectedText.length > 0) {
\r
3229 value = tinyMCE.replaceVar(value, "selection", selectedText);
\r
3230 tinyMCE.execCommand('mceInsertContent', false, value);
\r
3233 tinyMCE.triggerNodeChange();
\r
3236 case "mceSetAttribute":
\r
3237 if (typeof(value) == 'object') {
\r
3238 var targetElms = (typeof(value['targets']) == "undefined") ? "p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address" : value['targets'];
\r
3239 var targetNode = tinyMCE.getParentElement(this.getFocusElement(), targetElms);
\r
3242 targetNode.setAttribute(value['name'], value['value']);
\r
3243 tinyMCE.triggerNodeChange();
\r
3248 case "mceSetCSSClass":
\r
3249 this.execCommand("SetStyleInfo", false, {command : "setattrib", name : "class", value : value});
\r
3252 case "mceInsertRawHTML":
\r
3253 var key = 'tiny_mce_marker';
\r
3255 this.execCommand('mceBeginUndoLevel');
\r
3257 // Insert marker key
\r
3258 this.execCommand('mceInsertContent', false, key);
\r
3260 // Store away scroll pos
\r
3261 var scrollX = this.getBody().scrollLeft + this.getDoc().documentElement.scrollLeft;
\r
3262 var scrollY = this.getBody().scrollTop + this.getDoc().documentElement.scrollTop;
\r
3264 // Find marker and replace with RAW HTML
\r
3265 var html = this.getBody().innerHTML;
\r
3266 if ((pos = html.indexOf(key)) != -1)
\r
3267 tinyMCE.setInnerHTML(this.getBody(), html.substring(0, pos) + value + html.substring(pos + key.length));
\r
3269 // Restore scoll pos
\r
3270 this.contentWindow.scrollTo(scrollX, scrollY);
\r
3272 this.execCommand('mceEndUndoLevel');
\r
3276 case "mceInsertContent":
\r
3277 // Force empty string
\r
3281 var insertHTMLFailed = false;
\r
3283 // Removed since it produced problems in IE
\r
3284 // this.getWin().focus();
\r
3286 if (tinyMCE.isGecko || tinyMCE.isOpera) {
\r
3288 // Is plain text or HTML, &, etc will be encoded wrong in FF
\r
3289 if (value.indexOf('<') == -1 && !value.match(/(&| |<|>)/g)) {
\r
3290 var r = this.getRng();
\r
3291 var n = this.getDoc().createTextNode(tinyMCE.entityDecode(value));
\r
3292 var s = this.getSel();
\r
3293 var r2 = r.cloneRange();
\r
3295 // Insert text at cursor position
\r
3296 s.removeAllRanges();
\r
3297 r.deleteContents();
\r
3300 // Move the cursor to the end of text
\r
3302 r2.collapse(false);
\r
3303 s.removeAllRanges();
\r
3306 value = tinyMCE.fixGeckoBaseHREFBug(1, this.getDoc(), value);
\r
3307 this.getDoc().execCommand('inserthtml', false, value);
\r
3308 tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
\r
3311 insertHTMLFailed = true;
\r
3314 if (!insertHTMLFailed) {
\r
3315 tinyMCE.triggerNodeChange();
\r
3320 if (!tinyMCE.isIE) {
\r
3321 var isHTML = value.indexOf('<') != -1;
\r
3322 var sel = this.getSel();
\r
3323 var rng = this.getRng();
\r
3326 if (tinyMCE.isSafari) {
\r
3327 var tmpRng = this.getDoc().createRange();
\r
3329 tmpRng.setStart(this.getBody(), 0);
\r
3330 tmpRng.setEnd(this.getBody(), 0);
\r
3332 value = tmpRng.createContextualFragment(value);
\r
3334 value = rng.createContextualFragment(value);
\r
3336 // Setup text node
\r
3337 var el = document.createElement("div");
\r
3338 el.innerHTML = value;
\r
3339 value = el.firstChild.nodeValue;
\r
3340 value = doc.createTextNode(value);
\r
3343 // Insert plain text in Safari
\r
3344 if (tinyMCE.isSafari && !isHTML) {
\r
3345 this.execCommand('InsertText', false, value.nodeValue);
\r
3346 tinyMCE.triggerNodeChange();
\r
3348 } else if (tinyMCE.isSafari && isHTML) {
\r
3349 rng.deleteContents();
\r
3350 rng.insertNode(value);
\r
3351 tinyMCE.triggerNodeChange();
\r
3355 rng.deleteContents();
\r
3357 // If target node is text do special treatment, (Mozilla 1.3 fix)
\r
3358 if (rng.startContainer.nodeType == 3) {
\r
3359 var node = rng.startContainer.splitText(rng.startOffset);
\r
3360 node.parentNode.insertBefore(value, node);
\r
3362 rng.insertNode(value);
\r
3365 // Removes weird selection trails
\r
3366 sel.selectAllChildren(doc.body);
\r
3367 sel.removeAllRanges();
\r
3369 // Move cursor to end of content
\r
3370 var rng = doc.createRange();
\r
3372 rng.selectNode(value);
\r
3373 rng.collapse(false);
\r
3375 sel.addRange(rng);
\r
3377 rng.collapse(false);
\r
3379 tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
\r
3381 var rng = doc.selection.createRange(), tmpRng = null;
\r
3382 var c = value.indexOf('<!--') != -1;
\r
3384 // Fix comment bug, add tag before comments
\r
3386 value = tinyMCE.uniqueTag + value;
\r
3388 // tmpRng = rng.duplicate(); // Store away range (Fixes Undo bookmark bug in IE)
\r
3391 rng.item(0).outerHTML = value;
\r
3393 rng.pasteHTML(value);
\r
3396 // tmpRng.select(); // Restore range (Fixes Undo bookmark bug in IE)
\r
3398 // Remove unique tag
\r
3400 var e = this.getDoc().getElementById('mceTMPElement');
\r
3401 e.parentNode.removeChild(e);
\r
3405 tinyMCE.execCommand("mceAddUndoLevel");
\r
3406 tinyMCE.triggerNodeChange();
\r
3409 case "mceStartTyping":
\r
3410 if (tinyMCE.settings['custom_undo_redo'] && this.undoRedo.typingUndoIndex == -1) {
\r
3411 this.undoRedo.typingUndoIndex = this.undoRedo.undoIndex;
\r
3412 tinyMCE.typingUndoIndex = tinyMCE.undoIndex;
\r
3413 this.execCommand('mceAddUndoLevel');
\r
3417 case "mceEndTyping":
\r
3418 if (tinyMCE.settings['custom_undo_redo'] && this.undoRedo.typingUndoIndex != -1) {
\r
3419 this.execCommand('mceAddUndoLevel');
\r
3420 this.undoRedo.typingUndoIndex = -1;
\r
3423 tinyMCE.typingUndoIndex = -1;
\r
3426 case "mceBeginUndoLevel":
\r
3427 this.undoRedoLevel = false;
\r
3430 case "mceEndUndoLevel":
\r
3431 this.undoRedoLevel = true;
\r
3432 this.execCommand('mceAddUndoLevel');
\r
3435 case "mceAddUndoLevel":
\r
3436 if (tinyMCE.settings['custom_undo_redo'] && this.undoRedoLevel) {
\r
3437 if (this.undoRedo.add())
\r
3438 tinyMCE.triggerNodeChange(false);
\r
3443 if (tinyMCE.settings['custom_undo_redo']) {
\r
3444 tinyMCE.execCommand("mceEndTyping");
\r
3445 this.undoRedo.undo();
\r
3446 tinyMCE.triggerNodeChange();
\r
3448 this.getDoc().execCommand(command, user_interface, value);
\r
3452 if (tinyMCE.settings['custom_undo_redo']) {
\r
3453 tinyMCE.execCommand("mceEndTyping");
\r
3454 this.undoRedo.redo();
\r
3455 tinyMCE.triggerNodeChange();
\r
3457 this.getDoc().execCommand(command, user_interface, value);
\r
3460 case "mceToggleVisualAid":
\r
3461 this.visualAid = !this.visualAid;
\r
3462 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
\r
3463 tinyMCE.triggerNodeChange();
\r
3467 this.getDoc().execCommand(command, user_interface, value);
\r
3468 tinyMCE.triggerNodeChange();
\r
3470 if (tinyMCE.isIE) {
\r
3471 var n = tinyMCE.getParentElement(this.getFocusElement(), "blockquote");
\r
3473 if (n && n.nodeName == "BLOCKQUOTE") {
\r
3474 n.removeAttribute("dir");
\r
3475 n.removeAttribute("style");
\r
3477 } while (n != null && (n = n.parentNode) != null);
\r
3481 case "removeformat":
\r
3482 var text = this.selection.getSelectedText();
\r
3484 if (tinyMCE.isOpera) {
\r
3485 this.getDoc().execCommand("RemoveFormat", false, null);
\r
3489 if (tinyMCE.isIE) {
\r
3491 var rng = doc.selection.createRange();
\r
3492 rng.execCommand("RemoveFormat", false, null);
\r
3497 this.execCommand("SetStyleInfo", false, {command : "removeformat"});
\r
3499 this.getDoc().execCommand(command, user_interface, value);
\r
3501 this.execCommand("SetStyleInfo", false, {command : "removeformat"});
\r
3505 if (text.length == 0)
\r
3506 this.execCommand("mceSetCSSClass", false, "");
\r
3508 tinyMCE.triggerNodeChange();
\r
3512 this.getDoc().execCommand(command, user_interface, value);
\r
3514 if (tinyMCE.isGecko)
\r
3515 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
\r
3517 tinyMCE.triggerNodeChange();
\r
3520 // Add undo level after modification
\r
3521 if (command != "mceAddUndoLevel" && command != "Undo" && command != "Redo" && command != "mceStartTyping" && command != "mceEndTyping")
\r
3522 tinyMCE.execCommand("mceAddUndoLevel");
\r
3525 queryCommandValue : function(c) {
\r
3527 return this.getDoc().queryCommandValue(c);
\r
3533 queryCommandState : function(c) {
\r
3534 return this.getDoc().queryCommandState(c);
\r
3537 _onAdd : function(replace_element, form_element_name, target_document) {
\r
3538 var hc, th, to, editorTemplate;
\r
3540 th = this.settings['theme'];
\r
3541 to = tinyMCE.themes[th];
\r
3543 var targetDoc = target_document ? target_document : document;
\r
3545 this.targetDoc = targetDoc;
\r
3547 tinyMCE.themeURL = tinyMCE.baseURL + "/themes/" + this.settings['theme'];
\r
3548 this.settings['themeurl'] = tinyMCE.themeURL;
\r
3550 if (!replace_element) {
\r
3551 alert("Error: Could not find the target element.");
\r
3555 if (to.getEditorTemplate)
\r
3556 editorTemplate = to.getEditorTemplate(this.settings, this.editorId);
\r
3558 var deltaWidth = editorTemplate['delta_width'] ? editorTemplate['delta_width'] : 0;
\r
3559 var deltaHeight = editorTemplate['delta_height'] ? editorTemplate['delta_height'] : 0;
\r
3560 var html = '<span id="' + this.editorId + '_parent" class="mceEditorContainer">' + editorTemplate['html'];
\r
3562 html = tinyMCE.replaceVar(html, "editor_id", this.editorId);
\r
3563 this.settings['default_document'] = tinyMCE.baseURL + "/blank.htm";
\r
3565 this.settings['old_width'] = this.settings['width'];
\r
3566 this.settings['old_height'] = this.settings['height'];
\r
3568 // Set default width, height
\r
3569 if (this.settings['width'] == -1)
\r
3570 this.settings['width'] = replace_element.offsetWidth;
\r
3572 if (this.settings['height'] == -1)
\r
3573 this.settings['height'] = replace_element.offsetHeight;
\r
3575 // Try the style width
\r
3576 if (this.settings['width'] == 0)
\r
3577 this.settings['width'] = replace_element.style.width;
\r
3579 // Try the style height
\r
3580 if (this.settings['height'] == 0)
\r
3581 this.settings['height'] = replace_element.style.height;
\r
3583 // If no width/height then default to 320x240, better than nothing
\r
3584 if (this.settings['width'] == 0)
\r
3585 this.settings['width'] = 320;
\r
3587 if (this.settings['height'] == 0)
\r
3588 this.settings['height'] = 240;
\r
3590 this.settings['area_width'] = parseInt(this.settings['width']);
\r
3591 this.settings['area_height'] = parseInt(this.settings['height']);
\r
3592 this.settings['area_width'] += deltaWidth;
\r
3593 this.settings['area_height'] += deltaHeight;
\r
3595 this.settings['width_style'] = "" + this.settings['width'];
\r
3596 this.settings['height_style'] = "" + this.settings['height'];
\r
3598 // Special % handling
\r
3599 if (("" + this.settings['width']).indexOf('%') != -1)
\r
3600 this.settings['area_width'] = "100%";
\r
3602 this.settings['width_style'] += 'px';
\r
3604 if (("" + this.settings['height']).indexOf('%') != -1)
\r
3605 this.settings['area_height'] = "100%";
\r
3607 this.settings['height_style'] += 'px';
\r
3609 if (("" + replace_element.style.width).indexOf('%') != -1) {
\r
3610 this.settings['width'] = replace_element.style.width;
\r
3611 this.settings['area_width'] = "100%";
\r
3612 this.settings['width_style'] = "100%";
\r
3615 if (("" + replace_element.style.height).indexOf('%') != -1) {
\r
3616 this.settings['height'] = replace_element.style.height;
\r
3617 this.settings['area_height'] = "100%";
\r
3618 this.settings['height_style'] = "100%";
\r
3621 html = tinyMCE.applyTemplate(html);
\r
3623 this.settings['width'] = this.settings['old_width'];
\r
3624 this.settings['height'] = this.settings['old_height'];
\r
3626 this.visualAid = this.settings['visual'];
\r
3627 this.formTargetElementId = form_element_name;
\r
3629 // Get replace_element contents
\r
3630 if (replace_element.nodeName == "TEXTAREA" || replace_element.nodeName == "INPUT")
\r
3631 this.startContent = replace_element.value;
\r
3633 this.startContent = replace_element.innerHTML;
\r
3635 // If not text area or input
\r
3636 if (replace_element.nodeName != "TEXTAREA" && replace_element.nodeName != "INPUT") {
\r
3637 this.oldTargetElement = replace_element;
\r
3640 if (tinyMCE.settings['debug']) {
\r
3641 hc = '<textarea wrap="off" id="' + form_element_name + '" name="' + form_element_name + '" cols="100" rows="15"></textarea>';
\r
3643 hc = '<input type="hidden" id="' + form_element_name + '" name="' + form_element_name + '" />';
\r
3644 this.oldTargetElement.style.display = "none";
\r
3647 html += '</span>';
\r
3649 if (tinyMCE.isGecko)
\r
3654 // Output HTML and set editable
\r
3655 if (tinyMCE.isGecko) {
\r
3656 var rng = replace_element.ownerDocument.createRange();
\r
3657 rng.setStartBefore(replace_element);
\r
3659 var fragment = rng.createContextualFragment(html);
\r
3660 tinyMCE.insertAfter(fragment, replace_element);
\r
3662 replace_element.insertAdjacentHTML("beforeBegin", html);
\r
3664 html += '</span>';
\r
3666 // Just hide the textarea element
\r
3667 this.oldTargetElement = replace_element;
\r
3669 if (!tinyMCE.settings['debug'])
\r
3670 this.oldTargetElement.style.display = "none";
\r
3672 // Output HTML and set editable
\r
3673 if (tinyMCE.isGecko) {
\r
3674 var rng = replace_element.ownerDocument.createRange();
\r
3675 rng.setStartBefore(replace_element);
\r
3677 var fragment = rng.createContextualFragment(html);
\r
3678 tinyMCE.insertAfter(fragment, replace_element);
\r
3680 replace_element.insertAdjacentHTML("beforeBegin", html);
\r
3684 var dynamicIFrame = false;
\r
3685 var tElm = targetDoc.getElementById(this.editorId);
\r
3687 if (!tinyMCE.isIE) {
\r
3688 // Node case is preserved in XML strict mode
\r
3689 if (tElm && (tElm.nodeName == "SPAN" || tElm.nodeName == "span")) {
\r
3690 tElm = tinyMCE._createIFrame(tElm, targetDoc);
\r
3691 dynamicIFrame = true;
\r
3694 this.targetElement = tElm;
\r
3695 this.iframeElement = tElm;
\r
3696 this.contentDocument = tElm.contentDocument;
\r
3697 this.contentWindow = tElm.contentWindow;
\r
3699 //this.getDoc().designMode = "on";
\r
3701 if (tElm && tElm.nodeName == "SPAN")
\r
3702 tElm = tinyMCE._createIFrame(tElm, targetDoc, targetDoc.parentWindow);
\r
3704 tElm = targetDoc.frames[this.editorId];
\r
3706 this.targetElement = tElm;
\r
3707 this.iframeElement = targetDoc.getElementById(this.editorId);
\r
3709 if (tinyMCE.isOpera) {
\r
3710 this.contentDocument = this.iframeElement.contentDocument;
\r
3711 this.contentWindow = this.iframeElement.contentWindow;
\r
3712 dynamicIFrame = true;
\r
3714 this.contentDocument = tElm.window.document;
\r
3715 this.contentWindow = tElm.window;
\r
3718 this.getDoc().designMode = "on";
\r
3721 // Setup base HTML
\r
3722 var doc = this.contentDocument;
\r
3723 if (dynamicIFrame) {
\r
3724 var 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>';
\r
3727 if (!this.isHidden())
\r
3728 this.getDoc().designMode = "on";
\r
3734 // Failed Mozilla 1.3
\r
3735 this.getDoc().location.href = tinyMCE.baseURL + "/blank.htm";
\r
3739 // This timeout is needed in MSIE 5.5 for some odd reason
\r
3740 // it seems that the document.frames isn't initialized yet?
\r
3742 window.setTimeout("tinyMCE.addEventHandlers(tinyMCE.instances[\"" + this.editorId + "\"]);", 1);
\r
3744 tinyMCE.setupContent(this.editorId, true);
\r
3749 setBaseHREF : function(u) {
\r
3752 d = this.getDoc();
\r
3753 nl = d.getElementsByTagName("base");
\r
3754 b = nl.length > 0 ? nl[0] : null;
\r
3757 nl = d.getElementsByTagName("head");
\r
3758 h = nl.length > 0 ? nl[0] : null;
\r
3760 b = d.createElement("base");
\r
3761 b.setAttribute('href', u);
\r
3764 if (u == "" || u == null)
\r
3765 b.parentNode.removeChild(b);
\r
3767 b.setAttribute('href', u);
\r
3771 getHTML : function(r) {
\r
3772 var h, d = this.getDoc(), b = this.getBody();
\r
3775 return b.innerHTML;
\r
3777 h = tinyMCE._cleanupHTML(this, d, this.settings, b, false, true, false, true);
\r
3779 if (tinyMCE.getParam("convert_fonts_to_spans"))
\r
3780 tinyMCE.convertSpansToFonts(d);
\r
3785 setHTML : function(h) {
\r
3786 this.execCommand('mceSetContent', false, h);
\r
3790 getFocusElement : function() {
\r
3791 return this.selection.getFocusElement();
\r
3794 getSel : function() {
\r
3795 return this.selection.getSel();
\r
3798 getRng : function() {
\r
3799 return this.selection.getRng();
\r
3802 triggerSave : function(skip_cleanup, skip_callback) {
\r
3803 var e, nl = [], i, s;
\r
3805 this.switchSettings();
\r
3806 s = tinyMCE.settings;
\r
3808 // Force hidden tabs visible while serializing
\r
3809 if (tinyMCE.isRealIE) {
\r
3810 e = this.iframeElement;
\r
3813 if (e.style && e.style.display == 'none') {
\r
3814 e.style.display = 'block';
\r
3815 nl[nl.length] = {elm : e, type : 'style'};
\r
3818 if (e.style && s.hidden_tab_class.length > 0 && e.className.indexOf(s.hidden_tab_class) != -1) {
\r
3819 e.className = s.display_tab_class;
\r
3820 nl[nl.length] = {elm : e, type : 'class'};
\r
3822 } while ((e = e.parentNode) != null)
\r
3825 tinyMCE.settings['preformatted'] = false;
\r
3827 // Default to false
\r
3828 if (typeof(skip_cleanup) == "undefined")
\r
3829 skip_cleanup = false;
\r
3831 // Default to false
\r
3832 if (typeof(skip_callback) == "undefined")
\r
3833 skip_callback = false;
\r
3835 tinyMCE._setHTML(this.getDoc(), this.getBody().innerHTML);
\r
3837 // Remove visual aids when cleanup is disabled
\r
3838 if (this.settings['cleanup'] == false) {
\r
3839 tinyMCE.handleVisualAid(this.getBody(), true, false, this);
\r
3840 tinyMCE._setEventsEnabled(this.getBody(), true);
\r
3843 tinyMCE._customCleanup(this, "submit_content_dom", this.contentWindow.document.body);
\r
3844 var htm = skip_cleanup ? this.getBody().innerHTML : tinyMCE._cleanupHTML(this, this.getDoc(), this.settings, this.getBody(), tinyMCE.visualAid, true, true);
\r
3845 htm = tinyMCE._customCleanup(this, "submit_content", htm);
\r
3847 if (!skip_callback && tinyMCE.settings['save_callback'] != "")
\r
3848 var content = eval(tinyMCE.settings['save_callback'] + "(this.formTargetElementId,htm,this.getBody());");
\r
3850 // Use callback content if available
\r
3851 if ((typeof(content) != "undefined") && content != null)
\r
3854 // Replace some weird entities (Bug: #1056343)
\r
3855 htm = tinyMCE.regexpReplace(htm, "(", "(", "gi");
\r
3856 htm = tinyMCE.regexpReplace(htm, ")", ")", "gi");
\r
3857 htm = tinyMCE.regexpReplace(htm, ";", ";", "gi");
\r
3858 htm = tinyMCE.regexpReplace(htm, """, """, "gi");
\r
3859 htm = tinyMCE.regexpReplace(htm, "^", "^", "gi");
\r
3861 if (this.formElement)
\r
3862 this.formElement.value = htm;
\r
3864 if (tinyMCE.isSafari && this.formElement)
\r
3865 this.formElement.innerText = htm;
\r
3867 // Hide them again (tabs in MSIE)
\r
3868 for (i=0; i<nl.length; i++) {
\r
3869 if (nl[i].type == 'style')
\r
3870 nl[i].elm.style.display = 'none';
\r
3872 nl[i].elm.className = s.hidden_tab_class;
\r
3878 /* file:jscripts/tiny_mce/classes/TinyMCE_Cleanup.class.js */
\r
3880 TinyMCE_Engine.prototype.cleanupHTMLCode = function(s) {
\r
3881 s = s.replace(new RegExp('<p \\/>', 'gi'), '<p> </p>');
\r
3882 s = s.replace(new RegExp('<p>\\s*<\\/p>', 'gi'), '<p> </p>');
\r
3884 // Fix close BR elements
\r
3885 s = s.replace(new RegExp('<br>\\s*<\\/br>', 'gi'), '<br />');
\r
3887 // Open closed tags like <b/> to <b></b>
\r
3888 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>');
\r
3890 // Remove trailing space <b > to <b>
\r
3891 s = s.replace(new RegExp('\\s+></', 'gi'), '></');
\r
3893 // Close tags <img></img> to <img/>
\r
3894 s = s.replace(new RegExp('<(img|br|hr)([^>]*)><\\/(img|br|hr)>', 'gi'), '<$1$2 />');
\r
3896 // Weird MSIE bug, <p><hr /></p> breaks runtime?
\r
3898 s = s.replace(new RegExp('<p><hr \\/><\\/p>', 'gi'), "<hr>");
\r
3900 // Weird tags will make IE error #bug: 1538495
\r
3902 s = s.replace(/<!(\s*)\/>/g, '');
\r
3904 // Convert relative anchors to absolute URLs ex: #something to file.htm#something
\r
3905 // Removed: Since local document anchors should never be forced absolute example edit.php?id=something
\r
3906 //if (tinyMCE.getParam('convert_urls'))
\r
3907 // s = s.replace(new RegExp('(href=\"{0,1})(\\s*#)', 'gi'), '$1' + tinyMCE.settings['document_base_url'] + "#");
\r
3912 TinyMCE_Engine.prototype.parseStyle = function(str) {
\r
3913 var ar = new Array();
\r
3918 var st = str.split(';');
\r
3920 tinyMCE.clearArray(ar);
\r
3922 for (var i=0; i<st.length; i++) {
\r
3926 var re = new RegExp('^\\s*([^:]*):\\s*(.*)\\s*$');
\r
3927 var pa = st[i].replace(re, '$1||$2').split('||');
\r
3928 //tinyMCE.debug(str, pa[0] + "=" + pa[1], st[i].replace(re, '$1||$2'));
\r
3929 if (pa.length == 2)
\r
3930 ar[pa[0].toLowerCase()] = pa[1];
\r
3936 TinyMCE_Engine.prototype.compressStyle = function(ar, pr, sf, res) {
\r
3937 var box = new Array();
\r
3939 box[0] = ar[pr + '-top' + sf];
\r
3940 box[1] = ar[pr + '-left' + sf];
\r
3941 box[2] = ar[pr + '-right' + sf];
\r
3942 box[3] = ar[pr + '-bottom' + sf];
\r
3944 for (var i=0; i<box.length; i++) {
\r
3945 if (box[i] == null)
\r
3948 for (var a=0; a<box.length; a++) {
\r
3949 if (box[a] != box[i])
\r
3954 // They are all the same
\r
3956 ar[pr + '-top' + sf] = null;
\r
3957 ar[pr + '-left' + sf] = null;
\r
3958 ar[pr + '-right' + sf] = null;
\r
3959 ar[pr + '-bottom' + sf] = null;
\r
3962 TinyMCE_Engine.prototype.serializeStyle = function(ar) {
\r
3966 tinyMCE.compressStyle(ar, "border", "", "border");
\r
3967 tinyMCE.compressStyle(ar, "border", "-width", "border-width");
\r
3968 tinyMCE.compressStyle(ar, "border", "-color", "border-color");
\r
3969 tinyMCE.compressStyle(ar, "border", "-style", "border-style");
\r
3970 tinyMCE.compressStyle(ar, "padding", "", "padding");
\r
3971 tinyMCE.compressStyle(ar, "margin", "", "margin");
\r
3973 for (var key in ar) {
\r
3974 var val = ar[key];
\r
3976 if (typeof(val) == 'function')
\r
3979 if (key.indexOf('mso-') == 0)
\r
3982 if (val != null && val != '') {
\r
3983 val = '' + val; // Force string
\r
3986 val = val.replace(new RegExp("url\\(\\'?([^\\']*)\\'?\\)", 'gi'), "url('$1')");
\r
3989 if (val.indexOf('url(') != -1 && tinyMCE.getParam('convert_urls')) {
\r
3990 var m = new RegExp("url\\('(.*?)'\\)").exec(val);
\r
3993 val = "url('" + eval(tinyMCE.getParam('urlconverter_callback') + "(m[1], null, true);") + "')";
\r
3996 // Force HEX colors
\r
3997 if (tinyMCE.getParam("force_hex_style_colors"))
\r
3998 val = tinyMCE.convertRGBToHex(val, true);
\r
4000 if (val != "url('')")
\r
4001 str += key.toLowerCase() + ": " + val + "; ";
\r
4005 if (new RegExp('; $').test(str))
\r
4006 str = str.substring(0, str.length - 2);
\r
4011 TinyMCE_Engine.prototype.convertRGBToHex = function(s, k) {
\r
4012 if (s.toLowerCase().indexOf('rgb') != -1) {
\r
4013 var re = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
\r
4014 var rgb = s.replace(re, "$1,$2,$3,$4,$5").split(',');
\r
4015 if (rgb.length == 5) {
\r
4016 r = parseInt(rgb[1]).toString(16);
\r
4017 g = parseInt(rgb[2]).toString(16);
\r
4018 b = parseInt(rgb[3]).toString(16);
\r
4020 r = r.length == 1 ? '0' + r : r;
\r
4021 g = g.length == 1 ? '0' + g : g;
\r
4022 b = b.length == 1 ? '0' + b : b;
\r
4024 s = "#" + r + g + b;
\r
4027 s = rgb[0] + s + rgb[4];
\r
4034 TinyMCE_Engine.prototype.convertHexToRGB = function(s) {
\r
4035 if (s.indexOf('#') != -1) {
\r
4036 s = s.replace(new RegExp('[^0-9A-F]', 'gi'), '');
\r
4037 return "rgb(" + parseInt(s.substring(0, 2), 16) + "," + parseInt(s.substring(2, 4), 16) + "," + parseInt(s.substring(4, 6), 16) + ")";
\r
4043 TinyMCE_Engine.prototype.convertSpansToFonts = function(doc) {
\r
4044 var sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
\r
4046 var h = doc.body.innerHTML;
\r
4047 h = h.replace(/<span/gi, '<font');
\r
4048 h = h.replace(/<\/span/gi, '</font');
\r
4049 tinyMCE.setInnerHTML(doc.body, h);
\r
4051 var s = doc.getElementsByTagName("font");
\r
4052 for (var i=0; i<s.length; i++) {
\r
4053 var size = tinyMCE.trim(s[i].style.fontSize).toLowerCase();
\r
4056 for (var x=0; x<sizes.length; x++) {
\r
4057 if (sizes[x] == size) {
\r
4064 tinyMCE.setAttrib(s[i], 'size', fSize);
\r
4065 s[i].style.fontSize = '';
\r
4068 var fFace = s[i].style.fontFamily;
\r
4069 if (fFace != null && fFace != "") {
\r
4070 tinyMCE.setAttrib(s[i], 'face', fFace);
\r
4071 s[i].style.fontFamily = '';
\r
4074 var fColor = s[i].style.color;
\r
4075 if (fColor != null && fColor != "") {
\r
4076 tinyMCE.setAttrib(s[i], 'color', tinyMCE.convertRGBToHex(fColor));
\r
4077 s[i].style.color = '';
\r
4082 TinyMCE_Engine.prototype.convertFontsToSpans = function(doc) {
\r
4083 var sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
\r
4085 var h = doc.body.innerHTML;
\r
4086 h = h.replace(/<font/gi, '<span');
\r
4087 h = h.replace(/<\/font/gi, '</span');
\r
4088 tinyMCE.setInnerHTML(doc.body, h);
\r
4090 var fsClasses = tinyMCE.getParam('font_size_classes');
\r
4091 if (fsClasses != '')
\r
4092 fsClasses = fsClasses.replace(/\s+/, '').split(',');
\r
4096 var s = doc.getElementsByTagName("span");
\r
4097 for (var i=0; i<s.length; i++) {
\r
4098 var fSize, fFace, fColor;
\r
4100 fSize = tinyMCE.getAttrib(s[i], 'size');
\r
4101 fFace = tinyMCE.getAttrib(s[i], 'face');
\r
4102 fColor = tinyMCE.getAttrib(s[i], 'color');
\r
4104 if (fSize != "") {
\r
4105 fSize = parseInt(fSize);
\r
4107 if (fSize > 0 && fSize < 8) {
\r
4108 if (fsClasses != null)
\r
4109 tinyMCE.setAttrib(s[i], 'class', fsClasses[fSize-1]);
\r
4111 s[i].style.fontSize = sizes[fSize-1];
\r
4114 s[i].removeAttribute('size');
\r
4117 if (fFace != "") {
\r
4118 s[i].style.fontFamily = fFace;
\r
4119 s[i].removeAttribute('face');
\r
4122 if (fColor != "") {
\r
4123 s[i].style.color = fColor;
\r
4124 s[i].removeAttribute('color');
\r
4129 TinyMCE_Engine.prototype.cleanupAnchors = function(doc) {
\r
4130 var i, cn, x, an = doc.getElementsByTagName("a");
\r
4132 // Loops backwards due to bug #1467987
\r
4133 for (i=an.length-1; i>=0; i--) {
\r
4134 if (tinyMCE.getAttrib(an[i], "name") != "" && tinyMCE.getAttrib(an[i], "href") == "") {
\r
4135 cn = an[i].childNodes;
\r
4137 for (x=cn.length-1; x>=0; x--)
\r
4138 tinyMCE.insertAfter(cn[x], an[i]);
\r
4143 TinyMCE_Engine.prototype.getContent = function(editor_id) {
\r
4144 if (typeof(editor_id) != "undefined")
\r
4145 tinyMCE.getInstanceById(editor_id).select();
\r
4147 if (tinyMCE.selectedInstance)
\r
4148 return tinyMCE.selectedInstance.getHTML();
\r
4153 TinyMCE_Engine.prototype._fixListElements = function(d) {
\r
4154 var nl, x, a = ['ol', 'ul'], i, n, p, r = new RegExp('^(OL|UL)$'), np;
\r
4156 for (x=0; x<a.length; x++) {
\r
4157 nl = d.getElementsByTagName(a[x]);
\r
4159 for (i=0; i<nl.length; i++) {
\r
4163 if (r.test(p.nodeName)) {
\r
4164 np = tinyMCE.prevNode(n, 'LI');
\r
4167 np = d.createElement('li');
\r
4168 np.innerHTML = ' ';
\r
4169 np.appendChild(n);
\r
4170 p.insertBefore(np, p.firstChild);
\r
4172 np.appendChild(n);
\r
4178 TinyMCE_Engine.prototype._fixTables = function(d) {
\r
4179 var nl, i, n, p, np, x, t;
\r
4181 nl = d.getElementsByTagName('table');
\r
4182 for (i=0; i<nl.length; i++) {
\r
4185 if ((p = tinyMCE.getParentElement(n, 'p,div,h1,h2,h3,h4,h5,h6')) != null) {
\r
4186 np = p.cloneNode(false);
\r
4187 np.removeAttribute('id');
\r
4191 while ((n = n.nextSibling))
\r
4192 np.appendChild(n);
\r
4194 tinyMCE.insertAfter(np, p);
\r
4195 tinyMCE.insertAfter(t, p);
\r
4200 TinyMCE_Engine.prototype._cleanupHTML = function(inst, doc, config, elm, visual, on_save, on_submit, inn) {
\r
4201 var h, d, t1, t2, t3, t4, t5, c, s, nb;
\r
4203 if (!tinyMCE.getParam('cleanup'))
\r
4204 return elm.innerHTML;
\r
4206 on_save = typeof(on_save) == 'undefined' ? false : on_save;
\r
4209 s = inst.settings;
\r
4210 d = c.settings.debug;
\r
4213 t1 = new Date().getTime();
\r
4215 if (tinyMCE.getParam("convert_fonts_to_spans"))
\r
4216 tinyMCE.convertFontsToSpans(doc);
\r
4218 if (tinyMCE.getParam("fix_list_elements"))
\r
4219 tinyMCE._fixListElements(doc);
\r
4221 if (tinyMCE.getParam("fix_table_elements"))
\r
4222 tinyMCE._fixTables(doc);
\r
4224 // Call custom cleanup code
\r
4225 tinyMCE._customCleanup(inst, on_save ? "get_from_editor_dom" : "insert_to_editor_dom", doc.body);
\r
4228 t2 = new Date().getTime();
\r
4230 c.settings.on_save = on_save;
\r
4231 //for (var i=0; i<100; i++)
\r
4234 c.serializationId++;
\r
4235 c.serializedNodes = new Array();
\r
4236 c.sourceIndex = -1;
\r
4238 if (s.cleanup_serializer == "xml")
\r
4239 h = c.serializeNodeAsXML(elm, inn);
\r
4241 h = c.serializeNodeAsHTML(elm, inn);
\r
4244 t3 = new Date().getTime();
\r
4246 // Post processing
\r
4247 nb = tinyMCE.getParam('entity_encoding') == 'numeric' ? ' ' : ' ';
\r
4248 h = h.replace(/<\/?(body|head|html)[^>]*>/gi, '');
\r
4249 h = h.replace(new RegExp(' (rowspan="1"|colspan="1")', 'g'), '');
\r
4250 h = h.replace(/<p><hr \/><\/p>/g, '<hr />');
\r
4251 h = h.replace(/<p>( | )<\/p><hr \/><p>( | )<\/p>/g, '<hr />');
\r
4252 h = h.replace(/<td>\s*<br \/>\s*<\/td>/g, '<td>' + nb + '</td>');
\r
4253 h = h.replace(/<p>\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>');
\r
4254 h = h.replace(/<br \/>$/, ''); // Remove last BR for Gecko
\r
4255 h = h.replace(/<br \/><\/p>/g, '</p>'); // Remove last BR in P tags for Gecko
\r
4256 h = h.replace(/<p>\s*( | )\s*<br \/>\s*( | )\s*<\/p>/g, '<p>' + nb + '</p>');
\r
4257 h = h.replace(/<p>\s*( | )\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>');
\r
4258 h = h.replace(/<p>\s*<br \/>\s* \s*<\/p>/g, '<p>' + nb + '</p>');
\r
4259 h = h.replace(new RegExp('<a>(.*?)<\\/a>', 'g'), '$1');
\r
4260 h = h.replace(/<p([^>]*)>\s*<\/p>/g, '<p$1>' + nb + '</p>');
\r
4263 if (/^\s*(<br \/>|<p> <\/p>|<p> <\/p>|<p><\/p>)\s*$/.test(h))
\r
4266 // If preformatted
\r
4267 if (s.preformatted) {
\r
4268 h = h.replace(/^<pre>/, '');
\r
4269 h = h.replace(/<\/pre>$/, '');
\r
4270 h = '<pre>' + h + '</pre>';
\r
4273 // Gecko specific processing
\r
4274 if (tinyMCE.isGecko) {
\r
4275 h = h.replace(/<o:p _moz-userdefined="" \/>/g, '');
\r
4276 h = h.replace(/<td([^>]*)>\s*<br \/>\s*<\/td>/g, '<td$1>' + nb + '</td>');
\r
4279 if (s.force_br_newlines)
\r
4280 h = h.replace(/<p>( | )<\/p>/g, '<br />');
\r
4282 // Call custom cleanup code
\r
4283 h = tinyMCE._customCleanup(inst, on_save ? "get_from_editor" : "insert_to_editor", h);
\r
4285 // Remove internal classes
\r
4287 h = h.replace(new RegExp(' ?(mceItem[a-zA-Z0-9]*|' + s.visual_table_class + ')', 'g'), '');
\r
4288 h = h.replace(new RegExp(' ?class=""', 'g'), '');
\r
4291 if (s.remove_linebreaks && !c.settings.indent)
\r
4292 h = h.replace(/\n|\r/g, ' ');
\r
4295 t4 = new Date().getTime();
\r
4297 if (on_save && c.settings.indent)
\r
4298 h = c.formatHTML(h);
\r
4300 // If encoding (not recommended option)
\r
4301 if (on_submit && (s.encoding == "xml" || s.encoding == "html"))
\r
4302 h = c.xmlEncode(h);
\r
4305 t5 = new Date().getTime();
\r
4307 if (c.settings.debug)
\r
4308 tinyMCE.debug("Cleanup in ms: Pre=" + (t2-t1) + ", Serialize: " + (t3-t2) + ", Post: " + (t4-t3) + ", Format: " + (t5-t4) + ", Sum: " + (t5-t1) + ".");
\r
4313 function TinyMCE_Cleanup() {
\r
4314 this.isIE = (navigator.appName == "Microsoft Internet Explorer");
\r
4315 this.rules = tinyMCE.clearArray(new Array());
\r
4319 indent_elements : 'head,table,tbody,thead,tfoot,form,tr,ul,ol,blockquote,object',
\r
4320 newline_before_elements : 'h1,h2,h3,h4,h5,h6,pre,address,div,ul,ol,li,meta,option,area,title,link,base,script,td',
\r
4321 newline_after_elements : 'br,hr,p,pre,address,div,ul,ol,meta,option,area,link,base,script',
\r
4322 newline_before_after_elements : 'html,head,body,table,thead,tbody,tfoot,tr,form,ul,ol,blockquote,p,object,param,hr,div',
\r
4323 indent_char : '\t',
\r
4324 indent_levels : 1,
\r
4325 entity_encoding : 'raw',
\r
4326 valid_elements : '*[*]',
\r
4328 url_converter : '',
\r
4329 invalid_elements : '',
\r
4330 verify_html : false
\r
4333 this.vElements = tinyMCE.clearArray(new Array());
\r
4334 this.vElementsRe = '';
\r
4335 this.closeElementsRe = /^(IMG|BR|HR|LINK|META|BASE|INPUT|AREA)$/;
\r
4336 this.codeElementsRe = /^(SCRIPT|STYLE)$/;
\r
4337 this.serializationId = 0;
\r
4338 this.mceAttribs = {
\r
4339 href : 'mce_href',
\r
4345 TinyMCE_Cleanup.prototype = {
\r
4346 init : function(s) {
\r
4347 var n, a, i, ir, or, st;
\r
4350 this.settings[n] = s[n];
\r
4352 // Setup code formating
\r
4353 s = this.settings;
\r
4356 this.inRe = this._arrayToRe(s.indent_elements.split(','), '', '^<(', ')[^>]*');
\r
4357 this.ouRe = this._arrayToRe(s.indent_elements.split(','), '', '^<\\/(', ')[^>]*');
\r
4358 this.nlBeforeRe = this._arrayToRe(s.newline_before_elements.split(','), 'gi', '<(', ')([^>]*)>');
\r
4359 this.nlAfterRe = this._arrayToRe(s.newline_after_elements.split(','), 'gi', '<(', ')([^>]*)>');
\r
4360 this.nlBeforeAfterRe = this._arrayToRe(s.newline_before_after_elements.split(','), 'gi', '<(\\/?)(', ')([^>]*)>');
\r
4361 this.serializedNodes = [];
\r
4363 if (s.invalid_elements != '')
\r
4364 this.iveRe = this._arrayToRe(s.invalid_elements.toUpperCase().split(','), 'g', '^(', ')$');
\r
4366 this.iveRe = null;
\r
4368 // Setup separator
\r
4370 for (i=0; i<s.indent_levels; i++)
\r
4371 st += s.indent_char;
\r
4375 // If verify_html if false force *[*]
\r
4376 if (!s.verify_html) {
\r
4377 s.valid_elements = '*[*]';
\r
4378 s.extended_valid_elements = '';
\r
4381 this.fillStr = s.entity_encoding == "named" ? " " : " ";
\r
4385 addRuleStr : function(s) {
\r
4386 var r = this.parseRuleStr(s);
\r
4391 this.rules[n] = r[n];
\r
4394 this.vElements = tinyMCE.clearArray(new Array());
\r
4396 for (n in this.rules) {
\r
4397 if (this.rules[n])
\r
4398 this.vElements[this.vElements.length] = this.rules[n].tag;
\r
4401 this.vElementsRe = this._arrayToRe(this.vElements, '');
\r
4404 isValid : function(n) {
\r
4405 this._setupRules(); // Will initialize cleanup rules
\r
4407 // Clean the name up a bit
\r
4408 n = n.replace(/[^a-z0-9]+/gi, '').toUpperCase();
\r
4410 return !tinyMCE.getParam('cleanup') || this.vElementsRe.test(n);
\r
4413 addChildRemoveRuleStr : function(s) {
\r
4414 var x, y, p, i, t, tn, ta, cl, r;
\r
4419 ta = s.split(',');
\r
4420 for (x=0; x<ta.length; x++) {
\r
4423 // Split tag/children
\r
4424 p = this.split(/\[|\]/, s);
\r
4425 if (p == null || p.length < 1)
\r
4426 t = s.toUpperCase();
\r
4428 t = p[0].toUpperCase();
\r
4430 // Handle all tag names
\r
4431 tn = this.split('/', t);
\r
4432 for (y=0; y<tn.length; y++) {
\r
4436 cl = this.split(/\|/, p[1]);
\r
4437 for (i=0; i<cl.length; i++) {
\r
4438 if (cl[i] == '%istrict')
\r
4439 r += tinyMCE.inlineStrict;
\r
4440 else if (cl[i] == '%itrans')
\r
4441 r += tinyMCE.inlineTransitional;
\r
4442 else if (cl[i] == '%istrict_na')
\r
4443 r += tinyMCE.inlineStrict.substring(2);
\r
4444 else if (cl[i] == '%itrans_na')
\r
4445 r += tinyMCE.inlineTransitional.substring(2);
\r
4446 else if (cl[i] == '%btrans')
\r
4447 r += tinyMCE.blockElms;
\r
4448 else if (cl[i] == '%strict')
\r
4449 r += tinyMCE.blockStrict;
\r
4451 r += (cl[i].charAt(0) != '#' ? cl[i].toUpperCase() : cl[i]);
\r
4453 r += (i != cl.length - 1 ? '|' : '');
\r
4457 //tinyMCE.debug(t + "=" + r);
\r
4458 if (this.childRules == null)
\r
4459 this.childRules = tinyMCE.clearArray(new Array());
\r
4461 this.childRules[tn[y]] = new RegExp(r);
\r
4464 this.childRules[tn[y]].wrapTag = p[2];
\r
4469 parseRuleStr : function(s) {
\r
4470 var ta, p, r, a, i, x, px, t, tn, y, av, or = tinyMCE.clearArray(new Array()), dv;
\r
4472 if (s == null || s.length == 0)
\r
4475 ta = s.split(',');
\r
4476 for (x=0; x<ta.length; x++) {
\r
4478 if (s.length == 0)
\r
4481 // Split tag/attrs
\r
4482 p = this.split(/\[|\]/, s);
\r
4483 if (p == null || p.length < 1)
\r
4484 t = s.toUpperCase();
\r
4486 t = p[0].toUpperCase();
\r
4488 // Handle all tag names
\r
4489 tn = this.split('/', t);
\r
4490 for (y=0; y<tn.length; y++) {
\r
4494 r.forceAttribs = null;
\r
4495 r.defaultAttribs = null;
\r
4496 r.validAttribValues = null;
\r
4498 // Handle prefixes
\r
4499 px = r.tag.charAt(0);
\r
4500 r.forceOpen = px == '+';
\r
4501 r.removeEmpty = px == '-';
\r
4502 r.fill = px == '#';
\r
4503 r.tag = r.tag.replace(/\+|-|#/g, '');
\r
4504 r.oTagName = tn[0].replace(/\+|-|#/g, '').toLowerCase();
\r
4505 r.isWild = new RegExp('\\*|\\?|\\+', 'g').test(r.tag);
\r
4506 r.validRe = new RegExp(this._wildcardToRe('^' + r.tag + '$'));
\r
4508 // Setup valid attributes
\r
4509 if (p.length > 1) {
\r
4510 r.vAttribsRe = '^(';
\r
4511 a = this.split(/\|/, p[1]);
\r
4513 for (i=0; i<a.length; i++) {
\r
4516 if (t.charAt(0) == '!') {
\r
4517 a[i] = t = t.substring(1);
\r
4519 if (!r.reqAttribsRe)
\r
4520 r.reqAttribsRe = '\\s+(' + t;
\r
4522 r.reqAttribsRe += '|' + t;
\r
4525 av = new RegExp('(=|:|<)(.*?)$').exec(t);
\r
4526 t = t.replace(new RegExp('(=|:|<).*?$'), '');
\r
4527 if (av && av.length > 0) {
\r
4528 if (av[0].charAt(0) == ':') {
\r
4529 if (!r.forceAttribs)
\r
4530 r.forceAttribs = tinyMCE.clearArray(new Array());
\r
4532 r.forceAttribs[t.toLowerCase()] = av[0].substring(1);
\r
4533 } else if (av[0].charAt(0) == '=') {
\r
4534 if (!r.defaultAttribs)
\r
4535 r.defaultAttribs = tinyMCE.clearArray(new Array());
\r
4537 dv = av[0].substring(1);
\r
4539 r.defaultAttribs[t.toLowerCase()] = dv == "" ? "mce_empty" : dv;
\r
4540 } else if (av[0].charAt(0) == '<') {
\r
4541 if (!r.validAttribValues)
\r
4542 r.validAttribValues = tinyMCE.clearArray(new Array());
\r
4544 r.validAttribValues[t.toLowerCase()] = this._arrayToRe(this.split('?', av[0].substring(1)), 'i');
\r
4548 r.vAttribsRe += '' + t.toLowerCase() + (i != a.length - 1 ? '|' : '');
\r
4550 a[i] = t.toLowerCase();
\r
4553 if (r.reqAttribsRe)
\r
4554 r.reqAttribsRe = new RegExp(r.reqAttribsRe + ')=\"', 'g');
\r
4556 r.vAttribsRe += ')$';
\r
4557 r.vAttribsRe = this._wildcardToRe(r.vAttribsRe);
\r
4558 r.vAttribsReIsWild = new RegExp('\\*|\\?|\\+', 'g').test(r.vAttribsRe);
\r
4559 r.vAttribsRe = new RegExp(r.vAttribsRe);
\r
4560 r.vAttribs = a.reverse();
\r
4562 //tinyMCE.debug(r.tag, r.oTagName, r.vAttribsRe, r.vAttribsReWC);
\r
4564 r.vAttribsRe = '';
\r
4565 r.vAttribs = tinyMCE.clearArray(new Array());
\r
4566 r.vAttribsReIsWild = false;
\r
4576 serializeNodeAsXML : function(n) {
\r
4579 if (!this.xmlDoc) {
\r
4581 try {this.xmlDoc = new ActiveXObject('MSXML2.DOMDocument');} catch (e) {}
\r
4584 try {this.xmlDoc = new ActiveXObject('Microsoft.XmlDom');} catch (e) {}
\r
4586 this.xmlDoc = document.implementation.createDocument('', '', null);
\r
4589 alert("Error XML Parser could not be found.");
\r
4592 if (this.xmlDoc.firstChild)
\r
4593 this.xmlDoc.removeChild(this.xmlDoc.firstChild);
\r
4595 b = this.xmlDoc.createElement("html");
\r
4596 b = this.xmlDoc.appendChild(b);
\r
4598 this._convertToXML(n, b);
\r
4601 return this.xmlDoc.xml;
\r
4603 return new XMLSerializer().serializeToString(this.xmlDoc);
\r
4606 _convertToXML : function(n, xn) {
\r
4607 var xd, el, i, l, cn, at, no, hc = false;
\r
4609 if (this._isDuplicate(n))
\r
4614 switch (n.nodeType) {
\r
4615 case 1: // Element
\r
4616 hc = n.hasChildNodes();
\r
4618 el = xd.createElement(n.nodeName.toLowerCase());
\r
4620 at = n.attributes;
\r
4621 for (i=at.length-1; i>-1; i--) {
\r
4624 if (no.specified && no.nodeValue)
\r
4625 el.setAttribute(no.nodeName.toLowerCase(), no.nodeValue);
\r
4628 if (!hc && !this.closeElementsRe.test(n.nodeName))
\r
4629 el.appendChild(xd.createTextNode(""));
\r
4631 xn = xn.appendChild(el);
\r
4635 xn.appendChild(xd.createTextNode(n.nodeValue));
\r
4638 case 8: // Comment
\r
4639 xn.appendChild(xd.createComment(n.nodeValue));
\r
4644 cn = n.childNodes;
\r
4646 for (i=0, l=cn.length; i<l; i++)
\r
4647 this._convertToXML(cn[i], xn);
\r
4651 serializeNodeAsHTML : function(n, inn) {
\r
4652 var en, no, h = '', i, l, t, st, r, cn, va = false, f = false, at, hc, cr;
\r
4654 this._setupRules(); // Will initialize cleanup rules
\r
4656 if (this._isDuplicate(n))
\r
4659 // Skip non valid child elements
\r
4660 if (n.parentNode && this.childRules != null) {
\r
4661 cr = this.childRules[n.parentNode.nodeName];
\r
4663 if (typeof(cr) != "undefined" && !cr.test(n.nodeName)) {
\r
4669 switch (n.nodeType) {
\r
4670 case 1: // Element
\r
4671 hc = n.hasChildNodes();
\r
4676 // MSIE sometimes produces <//tag>
\r
4677 if ((tinyMCE.isRealIE) && n.nodeName.indexOf('/') != -1)
\r
4680 if (this.vElementsRe.test(n.nodeName) && (!this.iveRe || !this.iveRe.test(n.nodeName)) && !inn) {
\r
4683 r = this.rules[n.nodeName];
\r
4687 if (at[no] && at[no].validRe.test(n.nodeName)) {
\r
4694 en = r.isWild ? n.nodeName.toLowerCase() : r.oTagName;
\r
4697 if (r.removeEmpty && !hc)
\r
4702 if (r.vAttribsReIsWild) {
\r
4703 // Serialize wildcard attributes
\r
4704 at = n.attributes;
\r
4705 for (i=at.length-1; i>-1; i--) {
\r
4707 if (no.specified && r.vAttribsRe.test(no.nodeName))
\r
4708 t += this._serializeAttribute(n, r, no.nodeName);
\r
4711 // Serialize specific attributes
\r
4712 for (i=r.vAttribs.length-1; i>-1; i--)
\r
4713 t += this._serializeAttribute(n, r, r.vAttribs[i]);
\r
4716 // Serialize mce_ atts
\r
4717 if (!this.settings.on_save) {
\r
4718 at = this.mceAttribs;
\r
4722 t += this._serializeAttribute(n, r, at[no]);
\r
4726 // Check for required attribs
\r
4727 if (r.reqAttribsRe && !t.match(r.reqAttribsRe))
\r
4731 if (t != null && this.closeElementsRe.test(n.nodeName))
\r
4737 if (this.isIE && this.codeElementsRe.test(n.nodeName))
\r
4746 if (n.parentNode && this.codeElementsRe.test(n.parentNode.nodeName))
\r
4747 return this.isIE ? '' : n.nodeValue;
\r
4749 return this.xmlEncode(n.nodeValue);
\r
4751 case 8: // Comment
\r
4755 return "<!--" + this._trimComment(n.nodeValue) + "-->";
\r
4759 cn = n.childNodes;
\r
4761 for (i=0, l=cn.length; i<l; i++)
\r
4762 h += this.serializeNodeAsHTML(cn[i]);
\r
4765 // Fill empty nodes
\r
4767 h += this.fillStr;
\r
4770 if (t != null && va)
\r
4771 h += '</' + en + '>';
\r
4776 _serializeAttribute : function(n, r, an) {
\r
4777 var av = '', t, os = this.settings.on_save;
\r
4779 if (os && (an.indexOf('mce_') == 0 || an.indexOf('_moz') == 0))
\r
4782 if (os && this.mceAttribs[an])
\r
4783 av = this._getAttrib(n, this.mceAttribs[an]);
\r
4785 if (av.length == 0)
\r
4786 av = this._getAttrib(n, an);
\r
4788 if (av.length == 0 && r.defaultAttribs && (t = r.defaultAttribs[an])) {
\r
4791 if (av == "mce_empty")
\r
4792 return " " + an + '=""';
\r
4795 if (r.forceAttribs && (t = r.forceAttribs[an]))
\r
4798 if (os && av.length != 0 && this.settings.url_converter.length != 0 && /^(src|href|longdesc)$/.test(an))
\r
4799 av = eval(this.settings.url_converter + '(this, n, av)');
\r
4801 if (av.length != 0 && r.validAttribValues && r.validAttribValues[an] && !r.validAttribValues[an].test(av))
\r
4804 if (av.length != 0 && av == "{$uid}")
\r
4805 av = "uid_" + (this.idCount++);
\r
4807 if (av.length != 0) {
\r
4808 if (an.indexOf('on') != 0)
\r
4809 av = this.xmlEncode(av);
\r
4811 return " " + an + "=" + '"' + av + '"';
\r
4817 formatHTML : function(h) {
\r
4818 var s = this.settings, p = '', i = 0, li = 0, o = '', l;
\r
4820 // Replace BR in pre elements to \n
\r
4821 h = h.replace(/<pre([^>]*)>(.*?)<\/pre>/gi, function (a, b, c) {
\r
4822 c = c.replace(/<br\s*\/>/gi, '\n');
\r
4823 return '<pre' + b + '>' + c + '</pre>';
\r
4826 h = h.replace(/\r/g, ''); // Windows sux, isn't carriage return a thing of the past :)
\r
4828 h = h.replace(new RegExp('\\n\\s+', 'gi'), '\n'); // Remove previous formatting
\r
4829 h = h.replace(this.nlBeforeRe, '\n<$1$2>');
\r
4830 h = h.replace(this.nlAfterRe, '<$1$2>\n');
\r
4831 h = h.replace(this.nlBeforeAfterRe, '\n<$1$2$3>\n');
\r
4834 //tinyMCE.debug(h);
\r
4836 while ((i = h.indexOf('\n', i + 1)) != -1) {
\r
4837 if ((l = h.substring(li + 1, i)).length != 0) {
\r
4838 if (this.ouRe.test(l) && p.length >= s.indent_levels)
\r
4839 p = p.substring(s.indent_levels);
\r
4841 o += p + l + '\n';
\r
4843 if (this.inRe.test(l))
\r
4850 //tinyMCE.debug(h);
\r
4855 xmlEncode : function(s) {
\r
4858 this._setupEntities(); // Will intialize lookup table
\r
4860 switch (this.settings.entity_encoding) {
\r
4862 return tinyMCE.xmlEncode(s);
\r
4865 return s.replace(new RegExp('[\u007F-\uFFFF<>&"\']', 'g'), function (c, b) {
\r
4866 b = cl.entities[c.charCodeAt(0)];
\r
4868 return b ? '&' + b + ';' : c;
\r
4872 return s.replace(new RegExp('[\u007F-\uFFFF<>&"\']', 'g'), function (c, b) {
\r
4873 return b ? '&#' + c.charCodeAt(0) + ';' : c;
\r
4880 split : function(re, s) {
\r
4881 var c = s.split(re);
\r
4882 var i, l, o = new Array();
\r
4884 for (i=0, l=c.length; i<l; i++) {
\r
4892 _trimComment : function(s) {
\r
4893 // Remove mce_src, mce_href
\r
4894 s = s.replace(new RegExp('\\smce_src=\"[^\"]*\"', 'gi'), "");
\r
4895 s = s.replace(new RegExp('\\smce_href=\"[^\"]*\"', 'gi'), "");
\r
4900 _getAttrib : function(e, n, d) {
\r
4901 if (typeof(d) == "undefined")
\r
4904 if (!e || e.nodeType != 1)
\r
4907 var v = e.getAttribute(n, 0);
\r
4909 if (n == "class" && !v)
\r
4912 if (this.isIE && n == "http-equiv")
\r
4915 if (this.isIE && e.nodeName == "FORM" && n == "enctype" && v == "application/x-www-form-urlencoded")
\r
4918 if (this.isIE && e.nodeName == "INPUT" && n == "size" && v == "20")
\r
4921 if (this.isIE && e.nodeName == "INPUT" && n == "maxlength" && v == "2147483647")
\r
4924 if (n == "style" && !tinyMCE.isOpera)
\r
4925 v = e.style.cssText;
\r
4928 v = tinyMCE.serializeStyle(tinyMCE.parseStyle(v));
\r
4930 if (this.settings.on_save && n.indexOf('on') != -1 && this.settings.on_save && v && v != "")
\r
4931 v = tinyMCE.cleanupEventStr(v);
\r
4933 return (v && v != "") ? '' + v : d;
\r
4936 _urlConverter : function(c, n, v) {
\r
4937 if (!c.settings.on_save)
\r
4938 return tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, v);
\r
4939 else if (tinyMCE.getParam('convert_urls'))
\r
4940 return eval(tinyMCE.settings.urlconverter_callback + "(v, n, true);");
\r
4945 _arrayToRe : function(a, op, be, af) {
\r
4948 op = typeof(op) == "undefined" ? "gi" : op;
\r
4949 be = typeof(be) == "undefined" ? "^(" : be;
\r
4950 af = typeof(af) == "undefined" ? ")$" : af;
\r
4954 for (i=0; i<a.length; i++)
\r
4955 r += this._wildcardToRe(a[i]) + (i != a.length-1 ? "|" : "");
\r
4959 return new RegExp(r, op);
\r
4962 _wildcardToRe : function(s) {
\r
4963 s = s.replace(/\?/g, '(\\S?)');
\r
4964 s = s.replace(/\+/g, '(\\S+)');
\r
4965 s = s.replace(/\*/g, '(\\S*)');
\r
4970 _setupEntities : function() {
\r
4971 var n, a, i, s = this.settings;
\r
4974 if (!this.entitiesDone) {
\r
4975 if (s.entity_encoding == "named") {
\r
4976 n = tinyMCE.clearArray(new Array());
\r
4977 a = this.split(',', s.entities);
\r
4978 for (i=0; i<a.length; i+=2)
\r
4981 this.entities = n;
\r
4984 this.entitiesDone = true;
\r
4988 _setupRules : function() {
\r
4989 var s = this.settings;
\r
4991 // Setup default rule
\r
4992 if (!this.rulesDone) {
\r
4993 this.addRuleStr(s.valid_elements);
\r
4994 this.addRuleStr(s.extended_valid_elements);
\r
4995 this.addChildRemoveRuleStr(s.valid_child_elements);
\r
4997 this.rulesDone = true;
\r
5001 _isDuplicate : function(n) {
\r
5004 if (!this.settings.fix_content_duplication)
\r
5007 if (tinyMCE.isRealIE && n.nodeType == 1) {
\r
5009 if (n.mce_serialized == this.serializationId)
\r
5012 n.setAttribute('mce_serialized', this.serializationId);
\r
5014 // Search lookup table for text nodes and comments
\r
5015 for (i=0; i<this.serializedNodes.length; i++) {
\r
5016 if (this.serializedNodes[i] == n)
\r
5020 this.serializedNodes[this.serializedNodes.length] = n;
\r
5028 /* file:jscripts/tiny_mce/classes/TinyMCE_DOMUtils.class.js */
\r
5030 TinyMCE_Engine.prototype.createTagHTML = function(tn, a, h) {
\r
5031 var o = '', f = tinyMCE.xmlEncode;
\r
5037 if (typeof(a[n]) != 'function' && a[n] != null)
\r
5038 o += ' ' + f(n) + '="' + f('' + a[n]) + '"';
\r
5042 o += !h ? ' />' : '>' + h + '</' + tn + '>';
\r
5047 TinyMCE_Engine.prototype.createTag = function(d, tn, a, h) {
\r
5048 var o = d.createElement(tn);
\r
5052 if (typeof(a[n]) != 'function' && a[n] != null)
\r
5053 tinyMCE.setAttrib(o, n, a[n]);
\r
5063 TinyMCE_Engine.prototype.getElementByAttributeValue = function(n, e, a, v) {
\r
5064 return (n = this.getElementsByAttributeValue(n, e, a, v)).length == 0 ? null : n[0];
\r
5067 TinyMCE_Engine.prototype.getElementsByAttributeValue = function(n, e, a, v) {
\r
5068 var i, nl = n.getElementsByTagName(e), o = new Array();
\r
5070 for (i=0; i<nl.length; i++) {
\r
5071 if (tinyMCE.getAttrib(nl[i], a).indexOf(v) != -1)
\r
5072 o[o.length] = nl[i];
\r
5078 TinyMCE_Engine.prototype.isBlockElement = function(n) {
\r
5079 return n != null && n.nodeType == 1 && this.blockRegExp.test(n.nodeName);
\r
5082 TinyMCE_Engine.prototype.getParentBlockElement = function(n, r) {
\r
5083 return this.getParentNode(n, function(n) {
\r
5084 return tinyMCE.isBlockElement(n);
\r
5090 TinyMCE_Engine.prototype.insertAfter = function(n, r){
\r
5091 if (r.nextSibling)
\r
5092 r.parentNode.insertBefore(n, r.nextSibling);
\r
5094 r.parentNode.appendChild(n);
\r
5097 TinyMCE_Engine.prototype.setInnerHTML = function(e, h) {
\r
5100 // Convert all strong/em to b/i in Gecko
\r
5101 if (tinyMCE.isGecko) {
\r
5102 h = h.replace(/<strong/gi, '<b');
\r
5103 h = h.replace(/<em(\/?)/gi, '<i');
\r
5104 h = h.replace(/<em /gi, '<i');
\r
5105 h = h.replace(/<\/strong>/gi, '</b>');
\r
5106 h = h.replace(/<\/em>/gi, '</i>');
\r
5109 if (tinyMCE.isRealIE) {
\r
5110 // Since MSIE handles invalid HTML better that valid XHTML we
\r
5111 // need to make some things invalid. <hr /> gets converted to <hr>.
\r
5112 h = h.replace(/\s\/>/g, '>');
\r
5114 // Since MSIE auto generated emtpy P tags some times we must tell it to keep the real ones
\r
5115 h = h.replace(/<p([^>]*)>\u00A0?<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs
\r
5116 h = h.replace(/<p([^>]*)>\s* \s*<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs
\r
5117 h = h.replace(/<p([^>]*)>\s+<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs
\r
5119 // Remove first comment
\r
5120 e.innerHTML = tinyMCE.uniqueTag + h;
\r
5121 e.firstChild.removeNode(true);
\r
5123 // Remove weird auto generated empty paragraphs unless it's supposed to be there
\r
5124 nl = e.getElementsByTagName("p");
\r
5125 for (i=nl.length-1; i>=0; i--) {
\r
5128 if (n.nodeName == 'P' && !n.hasChildNodes() && !n.mce_keep)
\r
5129 n.parentNode.removeChild(n);
\r
5132 h = this.fixGeckoBaseHREFBug(1, e, h);
\r
5134 this.fixGeckoBaseHREFBug(2, e, h);
\r
5138 TinyMCE_Engine.prototype.getOuterHTML = function(e) {
\r
5140 return e.outerHTML;
\r
5142 var d = e.ownerDocument.createElement("body");
\r
5143 d.appendChild(e.cloneNode(true));
\r
5144 return d.innerHTML;
\r
5147 TinyMCE_Engine.prototype.setOuterHTML = function(e, h, d) {
\r
5148 var d = typeof(d) == "undefined" ? e.ownerDocument : d, i, nl, t;
\r
5150 if (tinyMCE.isIE && e.nodeType == 1)
\r
5153 t = d.createElement("body");
\r
5156 for (i=0, nl=t.childNodes; i<nl.length; i++)
\r
5157 e.parentNode.insertBefore(nl[i].cloneNode(true), e);
\r
5159 e.parentNode.removeChild(e);
\r
5163 TinyMCE_Engine.prototype._getElementById = function(id, d) {
\r
5166 if (typeof(d) == "undefined")
\r
5169 e = d.getElementById(id);
\r
5173 for (i=0; i<f.length; i++) {
\r
5174 for (j=0; j<f[i].elements.length; j++) {
\r
5175 if (f[i].elements[j].name == id) {
\r
5176 e = f[i].elements[j];
\r
5186 TinyMCE_Engine.prototype.getNodeTree = function(n, na, t, nn) {
\r
5187 return this.selectNodes(n, function(n) {
\r
5188 return (!t || n.nodeType == t) && (!nn || n.nodeName == nn);
\r
5189 }, na ? na : new Array());
\r
5192 TinyMCE_Engine.prototype.getParentElement = function(n, na, f, r) {
\r
5193 var re = na ? new RegExp('^(' + na.toUpperCase().replace(/,/g, '|') + ')$') : 0, v;
\r
5195 // Compatiblity with old scripts where f param was a attribute string
\r
5196 if (f && typeof(f) == 'string')
\r
5197 return this.getParentElement(n, na, function(no) {return tinyMCE.getAttrib(no, f) != '';});
\r
5199 return this.getParentNode(n, function(n) {
\r
5200 return ((n.nodeType == 1 && !re) || (re && re.test(n.nodeName))) && (!f || f(n));
\r
5204 TinyMCE_Engine.prototype.getParentNode = function(n, f, r) {
\r
5218 TinyMCE_Engine.prototype.getAttrib = function(elm, name, dv) {
\r
5221 if (typeof(dv) == "undefined")
\r
5225 if (!elm || elm.nodeType != 1)
\r
5228 v = elm.getAttribute(name);
\r
5230 // Try className for class attrib
\r
5231 if (name == "class" && !v)
\r
5232 v = elm.className;
\r
5234 // Workaround for a issue with Firefox 1.5rc2+
\r
5235 if (tinyMCE.isGecko && name == "src" && elm.src != null && elm.src != "")
\r
5238 // Workaround for a issue with Firefox 1.5rc2+
\r
5239 if (tinyMCE.isGecko && name == "href" && elm.href != null && elm.href != "")
\r
5242 if (name == "http-equiv" && tinyMCE.isIE)
\r
5243 v = elm.httpEquiv;
\r
5245 if (name == "style" && !tinyMCE.isOpera)
\r
5246 v = elm.style.cssText;
\r
5248 return (v && v != "") ? v : dv;
\r
5251 TinyMCE_Engine.prototype.setAttrib = function(el, name, va, fix) {
\r
5252 if (typeof(va) == "number" && va != null)
\r
5259 va = va.replace(/[^0-9%]/g, '');
\r
5262 if (name == "style")
\r
5263 el.style.cssText = va;
\r
5265 if (name == "class")
\r
5266 el.className = va;
\r
5268 if (va != null && va != "" && va != -1)
\r
5269 el.setAttribute(name, va);
\r
5271 el.removeAttribute(name);
\r
5274 TinyMCE_Engine.prototype.setStyleAttrib = function(e, n, v) {
\r
5277 // Style attrib deleted in IE
\r
5278 if (tinyMCE.isIE && v == null || v == '') {
\r
5279 v = tinyMCE.serializeStyle(tinyMCE.parseStyle(e.style.cssText));
\r
5280 e.style.cssText = v;
\r
5281 e.setAttribute("style", v);
\r
5285 TinyMCE_Engine.prototype.switchClass = function(ei, c) {
\r
5288 if (tinyMCE.switchClassCache[ei])
\r
5289 e = tinyMCE.switchClassCache[ei];
\r
5291 e = tinyMCE.switchClassCache[ei] = document.getElementById(ei);
\r
5295 if (tinyMCE.settings.button_tile_map && e.className && e.className.indexOf('mceTiledButton') == 0)
\r
5296 c = 'mceTiledButton ' + c;
\r
5302 TinyMCE_Engine.prototype.getAbsPosition = function(n, cn) {
\r
5305 while (n && n != cn) {
\r
5306 l += n.offsetLeft;
\r
5308 n = n.offsetParent;
\r
5311 return {absLeft : l, absTop : t};
\r
5314 TinyMCE_Engine.prototype.prevNode = function(e, n) {
\r
5315 var a = n.split(','), i;
\r
5317 while ((e = e.previousSibling) != null) {
\r
5318 for (i=0; i<a.length; i++) {
\r
5319 if (e.nodeName == a[i])
\r
5327 TinyMCE_Engine.prototype.nextNode = function(e, n) {
\r
5328 var a = n.split(','), i;
\r
5330 while ((e = e.nextSibling) != null) {
\r
5331 for (i=0; i<a.length; i++) {
\r
5332 if (e.nodeName == a[i])
\r
5340 TinyMCE_Engine.prototype.selectElements = function(n, na, f) {
\r
5341 var i, a = [], nl, x;
\r
5343 for (x=0, na = na.split(','); x<na.length; x++)
\r
5344 for (i=0, nl = n.getElementsByTagName(na[x]); i<nl.length; i++)
\r
5345 (!f || f(nl[i])) && a.push(nl[i]);
\r
5350 TinyMCE_Engine.prototype.selectNodes = function(n, f, a) {
\r
5359 if (n.hasChildNodes()) {
\r
5360 for (i=0; i<n.childNodes.length; i++)
\r
5361 tinyMCE.selectNodes(n.childNodes[i], f, a);
\r
5367 TinyMCE_Engine.prototype.addCSSClass = function(e, c, b) {
\r
5368 var o = this.removeCSSClass(e, c);
\r
5369 return e.className = b ? c + (o != '' ? (' ' + o) : '') : (o != '' ? (o + ' ') : '') + c;
\r
5372 TinyMCE_Engine.prototype.removeCSSClass = function(e, c) {
\r
5373 c = e.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' ');
\r
5374 return e.className = c != ' ' ? c : '';
\r
5377 TinyMCE_Engine.prototype.hasCSSClass = function(n, c) {
\r
5378 return new RegExp('\\b' + c + '\\b', 'g').test(n.className);
\r
5381 TinyMCE_Engine.prototype.renameElement = function(e, n, d) {
\r
5384 d = typeof(d) == "undefined" ? tinyMCE.selectedInstance.getDoc() : d;
\r
5387 ne = d.createElement(n);
\r
5389 ar = e.attributes;
\r
5390 for (i=ar.length-1; i>-1; i--) {
\r
5391 if (ar[i].specified && ar[i].nodeValue)
\r
5392 ne.setAttribute(ar[i].nodeName.toLowerCase(), ar[i].nodeValue);
\r
5395 ar = e.childNodes;
\r
5396 for (i=0; i<ar.length; i++)
\r
5397 ne.appendChild(ar[i].cloneNode(true));
\r
5399 e.parentNode.replaceChild(ne, e);
\r
5403 TinyMCE_Engine.prototype.getViewPort = function(w) {
\r
5404 var d = w.document, m = d.compatMode == 'CSS1Compat', b = d.body, de = d.documentElement;
\r
5407 left : w.pageXOffset || (m ? de.scrollLeft : b.scrollLeft),
\r
5408 top : w.pageYOffset || (m ? de.scrollTop : b.scrollTop),
\r
5409 width : w.innerWidth || (m ? de.clientWidth : b.clientWidth),
\r
5410 height : w.innerHeight || (m ? de.clientHeight : b.clientHeight)
\r
5414 /* file:jscripts/tiny_mce/classes/TinyMCE_URL.class.js */
\r
5416 TinyMCE_Engine.prototype.parseURL = function(url_str) {
\r
5417 var urlParts = new Array();
\r
5422 // Parse protocol part
\r
5423 pos = url_str.indexOf('://');
\r
5425 urlParts['protocol'] = url_str.substring(0, pos);
\r
5426 lastPos = pos + 3;
\r
5429 // Find port or path start
\r
5430 for (var i=lastPos; i<url_str.length; i++) {
\r
5431 var chr = url_str.charAt(i);
\r
5442 urlParts['host'] = url_str.substring(lastPos, pos);
\r
5445 urlParts['port'] = "";
\r
5447 if (url_str.charAt(pos) == ':') {
\r
5448 pos = url_str.indexOf('/', lastPos);
\r
5449 urlParts['port'] = url_str.substring(lastPos+1, pos);
\r
5454 pos = url_str.indexOf('?', lastPos);
\r
5457 pos = url_str.indexOf('#', lastPos);
\r
5460 pos = url_str.length;
\r
5462 urlParts['path'] = url_str.substring(lastPos, pos);
\r
5466 if (url_str.charAt(pos) == '?') {
\r
5467 pos = url_str.indexOf('#');
\r
5468 pos = (pos == -1) ? url_str.length : pos;
\r
5469 urlParts['query'] = url_str.substring(lastPos+1, pos);
\r
5474 if (url_str.charAt(pos) == '#') {
\r
5475 pos = url_str.length;
\r
5476 urlParts['anchor'] = url_str.substring(lastPos+1, pos);
\r
5483 TinyMCE_Engine.prototype.serializeURL = function(up) {
\r
5486 if (up['protocol'])
\r
5487 o += up['protocol'] + "://";
\r
5493 o += ":" + up['port'];
\r
5499 o += "?" + up['query'];
\r
5502 o += "#" + up['anchor'];
\r
5507 TinyMCE_Engine.prototype.convertAbsoluteURLToRelativeURL = function(base_url, url_to_relative) {
\r
5508 var baseURL = this.parseURL(base_url);
\r
5509 var targetURL = this.parseURL(url_to_relative);
\r
5512 var breakPoint = 0;
\r
5514 var forceSlash = false;
\r
5516 if (targetURL.path == "")
\r
5517 targetURL.path = "/";
\r
5519 forceSlash = true;
\r
5521 // Crop away last path part
\r
5522 base_url = baseURL.path.substring(0, baseURL.path.lastIndexOf('/'));
\r
5523 strTok1 = base_url.split('/');
\r
5524 strTok2 = targetURL.path.split('/');
\r
5526 if (strTok1.length >= strTok2.length) {
\r
5527 for (var i=0; i<strTok1.length; i++) {
\r
5528 if (i >= strTok2.length || strTok1[i] != strTok2[i]) {
\r
5529 breakPoint = i + 1;
\r
5535 if (strTok1.length < strTok2.length) {
\r
5536 for (var i=0; i<strTok2.length; i++) {
\r
5537 if (i >= strTok1.length || strTok1[i] != strTok2[i]) {
\r
5538 breakPoint = i + 1;
\r
5544 if (breakPoint == 1)
\r
5545 return targetURL.path;
\r
5547 for (var i=0; i<(strTok1.length-(breakPoint-1)); i++)
\r
5550 for (var i=breakPoint-1; i<strTok2.length; i++) {
\r
5551 if (i != (breakPoint-1))
\r
5552 outPath += "/" + strTok2[i];
\r
5554 outPath += strTok2[i];
\r
5557 targetURL.protocol = null;
\r
5558 targetURL.host = null;
\r
5559 targetURL.port = null;
\r
5560 targetURL.path = outPath == "" && forceSlash ? "/" : outPath;
\r
5562 // Remove document prefix from local anchors
\r
5563 var fileName = baseURL.path;
\r
5566 if ((pos = fileName.lastIndexOf('/')) != -1)
\r
5567 fileName = fileName.substring(pos + 1);
\r
5569 // Is local anchor
\r
5570 if (fileName == targetURL.path && targetURL.anchor != "")
\r
5571 targetURL.path = "";
\r
5573 // If empty and not local anchor force filename or slash
\r
5574 if (targetURL.path == "" && !targetURL.anchor)
\r
5575 targetURL.path = fileName != "" ? fileName : "/";
\r
5577 return this.serializeURL(targetURL);
\r
5580 TinyMCE_Engine.prototype.convertRelativeToAbsoluteURL = function(base_url, relative_url) {
\r
5581 var baseURL = this.parseURL(base_url), baseURLParts, relURLParts;
\r
5582 var relURL = this.parseURL(relative_url);
\r
5584 if (relative_url == "" || relative_url.indexOf('://') != -1 || /^(mailto:|javascript:|#|\/)/.test(relative_url))
\r
5585 return relative_url;
\r
5588 baseURLParts = baseURL['path'].split('/');
\r
5589 relURLParts = relURL['path'].split('/');
\r
5591 // Remove empty chunks
\r
5592 var newBaseURLParts = new Array();
\r
5593 for (var i=baseURLParts.length-1; i>=0; i--) {
\r
5594 if (baseURLParts[i].length == 0)
\r
5597 newBaseURLParts[newBaseURLParts.length] = baseURLParts[i];
\r
5599 baseURLParts = newBaseURLParts.reverse();
\r
5601 // Merge relURLParts chunks
\r
5602 var newRelURLParts = new Array();
\r
5604 for (var i=relURLParts.length-1; i>=0; i--) {
\r
5605 if (relURLParts[i].length == 0 || relURLParts[i] == ".")
\r
5608 if (relURLParts[i] == '..') {
\r
5613 if (numBack > 0) {
\r
5618 newRelURLParts[newRelURLParts.length] = relURLParts[i];
\r
5621 relURLParts = newRelURLParts.reverse();
\r
5623 // Remove end from absolute path
\r
5624 var len = baseURLParts.length-numBack;
\r
5625 var absPath = (len <= 0 ? "" : "/") + baseURLParts.slice(0, len).join('/') + "/" + relURLParts.join('/');
\r
5626 var start = "", end = "";
\r
5628 // Build output URL
\r
5629 relURL.protocol = baseURL.protocol;
\r
5630 relURL.host = baseURL.host;
\r
5631 relURL.port = baseURL.port;
\r
5633 // Re-add trailing slash if it's removed
\r
5634 if (relURL.path.charAt(relURL.path.length-1) == "/")
\r
5637 relURL.path = absPath;
\r
5639 return this.serializeURL(relURL);
\r
5642 TinyMCE_Engine.prototype.convertURL = function(url, node, on_save) {
\r
5643 var prot = document.location.protocol;
\r
5644 var host = document.location.hostname;
\r
5645 var port = document.location.port;
\r
5647 // Pass through file protocol
\r
5648 if (prot == "file:")
\r
5651 // Something is wrong, remove weirdness
\r
5652 url = tinyMCE.regexpReplace(url, '(http|https):///', '/');
\r
5654 // Mailto link or anchor (Pass through)
\r
5655 if (url.indexOf('mailto:') != -1 || url.indexOf('javascript:') != -1 || tinyMCE.regexpReplace(url,'[ \t\r\n\+]|%20','').charAt(0) == "#")
\r
5658 // Fix relative/Mozilla
\r
5659 if (!tinyMCE.isIE && !on_save && url.indexOf("://") == -1 && url.charAt(0) != '/')
\r
5660 return tinyMCE.settings['base_href'] + url;
\r
5662 // Handle relative URLs
\r
5663 if (on_save && tinyMCE.getParam('relative_urls')) {
\r
5664 var curl = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], url);
\r
5665 if (curl.charAt(0) == '/')
\r
5666 curl = tinyMCE.settings['document_base_prefix'] + curl;
\r
5668 var urlParts = tinyMCE.parseURL(curl);
\r
5669 var tmpUrlParts = tinyMCE.parseURL(tinyMCE.settings['document_base_url']);
\r
5672 if (urlParts['host'] == tmpUrlParts['host'] && (urlParts['port'] == tmpUrlParts['port']))
\r
5673 return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings['document_base_url'], curl);
\r
5676 // Handle absolute URLs
\r
5677 if (!tinyMCE.getParam('relative_urls')) {
\r
5678 var urlParts = tinyMCE.parseURL(url);
\r
5679 var baseUrlParts = tinyMCE.parseURL(tinyMCE.settings['base_href']);
\r
5681 // Force absolute URLs from relative URLs
\r
5682 url = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], url);
\r
5684 // If anchor and path is the same page
\r
5685 if (urlParts['anchor'] && urlParts['path'] == baseUrlParts['path'])
\r
5686 return "#" + urlParts['anchor'];
\r
5689 // Remove current domain
\r
5690 if (tinyMCE.getParam('remove_script_host')) {
\r
5691 var start = "", portPart = "";
\r
5694 portPart = ":" + port;
\r
5696 start = prot + "//" + host + portPart + "/";
\r
5698 if (url.indexOf(start) == 0)
\r
5699 url = url.substring(start.length-1);
\r
5705 TinyMCE_Engine.prototype.convertAllRelativeURLs = function(body) {
\r
5706 var i, elms, src, href, mhref, msrc;
\r
5708 // Convert all image URL:s to absolute URL
\r
5709 elms = body.getElementsByTagName("img");
\r
5710 for (i=0; i<elms.length; i++) {
\r
5711 src = tinyMCE.getAttrib(elms[i], 'src');
\r
5713 msrc = tinyMCE.getAttrib(elms[i], 'mce_src');
\r
5718 src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);
\r
5719 elms[i].setAttribute("src", src);
\r
5723 // Convert all link URL:s to absolute URL
\r
5724 elms = body.getElementsByTagName("a");
\r
5725 for (i=0; i<elms.length; i++) {
\r
5726 href = tinyMCE.getAttrib(elms[i], 'href');
\r
5728 mhref = tinyMCE.getAttrib(elms[i], 'mce_href');
\r
5732 if (href && href != "") {
\r
5733 href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], href);
\r
5734 elms[i].setAttribute("href", href);
\r
5739 /* file:jscripts/tiny_mce/classes/TinyMCE_Array.class.js */
\r
5741 TinyMCE_Engine.prototype.clearArray = function(a) {
\r
5750 TinyMCE_Engine.prototype.explode = function(d, s) {
\r
5751 var ar = s.split(d), oar = new Array(), i;
\r
5753 for (i = 0; i<ar.length; i++) {
\r
5755 oar[oar.length] = ar[i];
\r
5761 /* file:jscripts/tiny_mce/classes/TinyMCE_Event.class.js */
\r
5763 TinyMCE_Engine.prototype._setEventsEnabled = function(node, state) {
\r
5764 var evs, x, y, elms, i, event;
\r
5765 var events = ['onfocus','onblur','onclick','ondblclick',
\r
5766 'onmousedown','onmouseup','onmouseover','onmousemove',
\r
5767 'onmouseout','onkeypress','onkeydown','onkeydown','onkeyup'];
\r
5769 evs = tinyMCE.settings['event_elements'].split(',');
\r
5770 for (y=0; y<evs.length; y++){
\r
5771 elms = node.getElementsByTagName(evs[y]);
\r
5772 for (i=0; i<elms.length; i++) {
\r
5775 for (x=0; x<events.length; x++) {
\r
5776 if ((event = tinyMCE.getAttrib(elms[i], events[x])) != '') {
\r
5777 event = tinyMCE.cleanupEventStr("" + event);
\r
5780 event = "return true;" + event;
\r
5782 event = event.replace(/^return true;/gi, '');
\r
5784 elms[i].removeAttribute(events[x]);
\r
5785 elms[i].setAttribute(events[x], event);
\r
5792 TinyMCE_Engine.prototype._eventPatch = function(editor_id) {
\r
5793 var n, inst, win, e;
\r
5795 // Remove odd, error
\r
5796 if (typeof(tinyMCE) == "undefined")
\r
5800 // Try selected instance first
\r
5801 if (tinyMCE.selectedInstance) {
\r
5802 win = tinyMCE.selectedInstance.getWin();
\r
5804 if (win && win.event) {
\r
5808 e.target = e.srcElement;
\r
5810 TinyMCE_Engine.prototype.handleEvent(e);
\r
5816 for (n in tinyMCE.instances) {
\r
5817 inst = tinyMCE.instances[n];
\r
5819 if (!tinyMCE.isInstance(inst))
\r
5823 win = inst.getWin();
\r
5825 if (win && win.event) {
\r
5829 e.target = e.srcElement;
\r
5831 TinyMCE_Engine.prototype.handleEvent(e);
\r
5836 // Ignore error if iframe is pointing to external URL
\r
5840 TinyMCE_Engine.prototype.findEvent = function(e) {
\r
5846 for (n in tinyMCE.instances) {
\r
5847 inst = tinyMCE.instances[n];
\r
5849 if (tinyMCE.isInstance(inst) && inst.getWin().event)
\r
5850 return inst.getWin().event;
\r
5856 TinyMCE_Engine.prototype.unloadHandler = function() {
\r
5857 tinyMCE.triggerSave(true, true);
\r
5860 TinyMCE_Engine.prototype.addEventHandlers = function(inst) {
\r
5861 this.setEventHandlers(inst, 1);
\r
5864 TinyMCE_Engine.prototype.setEventHandlers = function(inst, s) {
\r
5865 var doc = inst.getDoc(), ie, ot, i, f = s ? tinyMCE.addEvent : tinyMCE.removeEvent;
\r
5867 ie = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'controlselect', 'dblclick'];
\r
5868 ot = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'focus', 'blur', 'dragdrop'];
\r
5870 inst.switchSettings();
\r
5872 if (tinyMCE.isIE) {
\r
5873 for (i=0; i<ie.length; i++)
\r
5874 f(doc, ie[i], TinyMCE_Engine.prototype._eventPatch);
\r
5876 for (i=0; i<ot.length; i++)
\r
5877 f(doc, ot[i], tinyMCE.handleEvent);
\r
5879 eval('try { doc.designMode = "On"; } catch(e) {}'); // Force designmode
\r
5883 TinyMCE_Engine.prototype.onMouseMove = function() {
\r
5886 // Fix for IE7 bug where it's not restoring hover on anchors correctly
\r
5887 if (tinyMCE.lastHover) {
\r
5888 lh = tinyMCE.lastHover;
\r
5890 // Call out on menus and refresh class on normal buttons
\r
5891 if (lh.className.indexOf('mceMenu') != -1)
\r
5892 tinyMCE._menuButtonEvent('out', lh);
\r
5894 lh.className = lh.className;
\r
5896 tinyMCE.lastHover = null;
\r
5899 if (!tinyMCE.hasMouseMoved) {
\r
5900 inst = tinyMCE.selectedInstance;
\r
5902 // Workaround for bug #1437457 (Odd MSIE bug)
\r
5903 if (inst.isFocused) {
\r
5904 inst.undoBookmark = inst.selection.getBookmark();
\r
5905 tinyMCE.hasMouseMoved = true;
\r
5909 // tinyMCE.cancelEvent(inst.getWin().event);
\r
5913 TinyMCE_Engine.prototype.cancelEvent = function(e) {
\r
5917 if (tinyMCE.isIE) {
\r
5918 e.returnValue = false;
\r
5919 e.cancelBubble = true;
\r
5921 e.preventDefault();
\r
5922 e.stopPropagation && e.stopPropagation();
\r
5928 TinyMCE_Engine.prototype.addEvent = function(o, n, h) {
\r
5929 // Add cleanup for all non unload events
\r
5930 if (n != 'unload') {
\r
5931 function clean() {
\r
5935 tinyMCE.removeEvent(o, n, h);
\r
5936 tinyMCE.removeEvent(window, 'unload', clean);
\r
5939 // IE may produce access denied exception on unload
\r
5943 // Add memory cleaner
\r
5944 tinyMCE.addEvent(window, 'unload', clean);
\r
5947 if (o.attachEvent)
\r
5948 o.attachEvent("on" + n, h);
\r
5950 o.addEventListener(n, h, false);
\r
5953 TinyMCE_Engine.prototype.removeEvent = function(o, n, h) {
\r
5954 if (o.detachEvent)
\r
5955 o.detachEvent("on" + n, h);
\r
5957 o.removeEventListener(n, h, false);
\r
5960 TinyMCE_Engine.prototype.addSelectAccessibility = function(e, s, w) {
\r
5961 // Add event handlers
\r
5962 if (!s._isAccessible) {
\r
5963 s.onkeydown = tinyMCE.accessibleEventHandler;
\r
5964 s.onblur = tinyMCE.accessibleEventHandler;
\r
5965 s._isAccessible = true;
\r
5972 TinyMCE_Engine.prototype.accessibleEventHandler = function(e) {
\r
5973 var win = this._win;
\r
5974 e = tinyMCE.isIE ? win.event : e;
\r
5975 var elm = tinyMCE.isIE ? e.srcElement : e.target;
\r
5977 // Unpiggyback onchange on blur
\r
5978 if (e.type == "blur") {
\r
5979 if (elm.oldonchange) {
\r
5980 elm.onchange = elm.oldonchange;
\r
5981 elm.oldonchange = null;
\r
5987 // Piggyback onchange
\r
5988 if (elm.nodeName == "SELECT" && !elm.oldonchange) {
\r
5989 elm.oldonchange = elm.onchange;
\r
5990 elm.onchange = null;
\r
5993 // Execute onchange and remove piggyback
\r
5994 if (e.keyCode == 13 || e.keyCode == 32) {
\r
5995 elm.onchange = elm.oldonchange;
\r
5997 elm.oldonchange = null;
\r
5999 tinyMCE.cancelEvent(e);
\r
6006 TinyMCE_Engine.prototype._resetIframeHeight = function() {
\r
6009 if (tinyMCE.isRealIE) {
\r
6010 ife = tinyMCE.selectedInstance.iframeElement;
\r
6012 /* if (ife._oldWidth) {
\r
6013 ife.style.width = ife._oldWidth;
\r
6014 ife.width = ife._oldWidth;
\r
6017 if (ife._oldHeight) {
\r
6018 ife.style.height = ife._oldHeight;
\r
6019 ife.height = ife._oldHeight;
\r
6024 /* file:jscripts/tiny_mce/classes/TinyMCE_Selection.class.js */
\r
6026 function TinyMCE_Selection(inst) {
\r
6027 this.instance = inst;
\r
6030 TinyMCE_Selection.prototype = {
\r
6031 getSelectedHTML : function() {
\r
6032 var inst = this.instance;
\r
6033 var e, r = this.getRng(), h;
\r
6038 e = document.createElement("body");
\r
6040 if (r.cloneContents)
\r
6041 e.appendChild(r.cloneContents());
\r
6042 else if (typeof(r.item) != 'undefined' || typeof(r.htmlText) != 'undefined')
\r
6043 e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText;
\r
6045 e.innerHTML = r.toString(); // Failed, use text for now
\r
6047 h = tinyMCE._cleanupHTML(inst, inst.contentDocument, inst.settings, e, e, false, true, false);
\r
6049 // When editing always use fonts internaly
\r
6050 if (tinyMCE.getParam("convert_fonts_to_spans"))
\r
6051 tinyMCE.convertSpansToFonts(inst.getDoc());
\r
6056 getSelectedText : function() {
\r
6057 var inst = this.instance;
\r
6060 if (tinyMCE.isIE) {
\r
6061 d = inst.getDoc();
\r
6063 if (d.selection.type == "Text") {
\r
6064 r = d.selection.createRange();
\r
6069 s = this.getSel();
\r
6071 if (s && s.toString)
\r
6080 getBookmark : function(simple) {
\r
6081 var inst = this.instance;
\r
6082 var rng = this.getRng();
\r
6083 var doc = inst.getDoc(), b = inst.getBody();
\r
6084 var sp, le, s, e, nl, i, si, ei, w;
\r
6085 var trng, sx, sy, xx = -999999999, vp = inst.getViewPort();
\r
6090 if (tinyMCE.isSafari || tinyMCE.isOpera || simple)
\r
6091 return {rng : rng, scrollX : sx, scrollY : sy};
\r
6093 if (tinyMCE.isIE) {
\r
6097 nl = b.getElementsByTagName(e.nodeName);
\r
6098 for (i=0; i<nl.length; i++) {
\r
6112 trng = doc.body.createTextRange();
\r
6113 trng.moveToElementText(inst.getBody());
\r
6114 trng.collapse(true);
\r
6115 bp = Math.abs(trng.move('character', xx));
\r
6117 trng = rng.duplicate();
\r
6118 trng.collapse(true);
\r
6119 sp = Math.abs(trng.move('character', xx));
\r
6121 trng = rng.duplicate();
\r
6122 trng.collapse(false);
\r
6123 le = Math.abs(trng.move('character', xx)) - sp;
\r
6134 if (tinyMCE.isGecko) {
\r
6135 s = this.getSel();
\r
6136 e = this.getFocusElement();
\r
6141 if (e && e.nodeName == 'IMG') {
\r
6142 /*nl = b.getElementsByTagName('IMG');
\r
6143 for (i=0; i<nl.length; i++) {
\r
6159 // Caret or selection
\r
6160 if (s.anchorNode == s.focusNode && s.anchorOffset == s.focusOffset) {
\r
6161 e = this._getPosText(b, s.anchorNode, s.focusNode);
\r
6164 return {scrollX : sx, scrollY : sy};
\r
6167 start : e.start + s.anchorOffset,
\r
6168 end : e.end + s.focusOffset,
\r
6173 e = this._getPosText(b, rng.startContainer, rng.endContainer);
\r
6176 return {scrollX : sx, scrollY : sy};
\r
6179 start : e.start + rng.startOffset,
\r
6180 end : e.end + rng.endOffset,
\r
6190 moveToBookmark : function(bookmark) {
\r
6191 var inst = this.instance;
\r
6192 var rng, nl, i, ex, b = inst.getBody(), sd;
\r
6193 var doc = inst.getDoc();
\r
6194 var win = inst.getWin();
\r
6195 var sel = this.getSel();
\r
6200 if (tinyMCE.isSafari) {
\r
6201 sel.setBaseAndExtent(bookmark.rng.startContainer, bookmark.rng.startOffset, bookmark.rng.endContainer, bookmark.rng.endOffset);
\r
6205 if (tinyMCE.isRealIE) {
\r
6206 if (bookmark.rng) {
\r
6208 bookmark.rng.select();
\r
6218 if (bookmark.tag) {
\r
6219 rng = b.createControlRange();
\r
6221 nl = b.getElementsByTagName(bookmark.tag);
\r
6223 if (nl.length > bookmark.index) {
\r
6225 rng.addElement(nl[bookmark.index]);
\r
6227 // Might be thrown if the node no longer exists
\r
6231 // Try/catch needed since this operation breaks when TinyMCE is placed in hidden divs/tabs
\r
6233 // Incorrect bookmark
\r
6234 if (bookmark.start < 0)
\r
6237 rng = inst.getSel().createRange();
\r
6238 rng.moveToElementText(inst.getBody());
\r
6239 rng.collapse(true);
\r
6240 rng.moveStart('character', bookmark.start);
\r
6241 rng.moveEnd('character', bookmark.length);
\r
6249 win.scrollTo(bookmark.scrollX, bookmark.scrollY);
\r
6253 if (tinyMCE.isGecko || tinyMCE.isOpera) {
\r
6254 if (bookmark.rng) {
\r
6255 sel.removeAllRanges();
\r
6256 sel.addRange(bookmark.rng);
\r
6259 if (bookmark.start != -1 && bookmark.end != -1) {
\r
6261 sd = this._getTextPos(b, bookmark.start, bookmark.end);
\r
6262 rng = doc.createRange();
\r
6263 rng.setStart(sd.startNode, sd.startOffset);
\r
6264 rng.setEnd(sd.endNode, sd.endOffset);
\r
6265 sel.removeAllRanges();
\r
6266 sel.addRange(rng);
\r
6274 if (typeof(bookmark.index) != 'undefined') {
\r
6275 tinyMCE.selectElements(b, 'IMG', function (n) {
\r
6276 if (bookmark.index-- == 0) {
\r
6277 // Select image in Gecko here
\r
6285 win.scrollTo(bookmark.scrollX, bookmark.scrollY);
\r
6292 _getPosText : function(r, sn, en) {
\r
6293 var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {};
\r
6295 while ((n = w.nextNode()) != null) {
\r
6304 p += n.nodeValue ? n.nodeValue.length : 0;
\r
6310 _getTextPos : function(r, sp, ep) {
\r
6311 var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {};
\r
6313 while ((n = w.nextNode()) != null) {
\r
6314 p += n.nodeValue ? n.nodeValue.length : 0;
\r
6316 if (p >= sp && !d.startNode) {
\r
6318 d.startOffset = sp - (p - n.nodeValue.length);
\r
6323 d.endOffset = ep - (p - n.nodeValue.length);
\r
6332 selectNode : function(node, collapse, select_text_node, to_start) {
\r
6333 var inst = this.instance, sel, rng, nodes;
\r
6338 if (typeof(collapse) == "undefined")
\r
6341 if (typeof(select_text_node) == "undefined")
\r
6342 select_text_node = false;
\r
6344 if (typeof(to_start) == "undefined")
\r
6347 if (inst.settings.auto_resize)
\r
6348 inst.resizeToContent();
\r
6350 if (tinyMCE.isRealIE) {
\r
6351 rng = inst.getDoc().body.createTextRange();
\r
6354 rng.moveToElementText(node);
\r
6357 rng.collapse(to_start);
\r
6361 // Throws illigal agrument in MSIE some times
\r
6364 sel = this.getSel();
\r
6369 if (tinyMCE.isSafari) {
\r
6370 sel.setBaseAndExtent(node, 0, node, node.innerText.length);
\r
6374 sel.collapseToStart();
\r
6376 sel.collapseToEnd();
\r
6379 this.scrollToNode(node);
\r
6384 rng = inst.getDoc().createRange();
\r
6386 if (select_text_node) {
\r
6387 // Find first textnode in tree
\r
6388 nodes = tinyMCE.getNodeTree(node, new Array(), 3);
\r
6389 if (nodes.length > 0)
\r
6390 rng.selectNodeContents(nodes[0]);
\r
6392 rng.selectNodeContents(node);
\r
6394 rng.selectNode(node);
\r
6397 // Special treatment of textnode collapse
\r
6398 if (!to_start && node.nodeType == 3) {
\r
6399 rng.setStart(node, node.nodeValue.length);
\r
6400 rng.setEnd(node, node.nodeValue.length);
\r
6402 rng.collapse(to_start);
\r
6405 sel.removeAllRanges();
\r
6406 sel.addRange(rng);
\r
6409 this.scrollToNode(node);
\r
6411 // Set selected element
\r
6412 tinyMCE.selectedElement = null;
\r
6413 if (node.nodeType == 1)
\r
6414 tinyMCE.selectedElement = node;
\r
6417 scrollToNode : function(node) {
\r
6418 var inst = this.instance, w = inst.getWin(), vp = inst.getViewPort(), pos = tinyMCE.getAbsPosition(node), cvp, p, cwin;
\r
6420 // Only scroll if out of visible area
\r
6421 if (pos.absLeft < vp.left || pos.absLeft > vp.left + vp.width || pos.absTop < vp.top || pos.absTop > vp.top + (vp.height-25))
\r
6422 w.scrollTo(pos.absLeft, pos.absTop - vp.height + 25);
\r
6424 // Scroll container window
\r
6425 if (inst.settings.auto_resize) {
\r
6426 cwin = inst.getContainerWin();
\r
6427 cvp = tinyMCE.getViewPort(cwin);
\r
6428 p = this.getAbsPosition(node);
\r
6430 if (p.absLeft < cvp.left || p.absLeft > cvp.left + cvp.width || p.absTop < cvp.top || p.absTop > cvp.top + cvp.height)
\r
6431 cwin.scrollTo(p.absLeft, p.absTop - cvp.height + 25);
\r
6435 getAbsPosition : function(n) {
\r
6436 var pos = tinyMCE.getAbsPosition(n), ipos = tinyMCE.getAbsPosition(this.instance.iframeElement);
\r
6439 absLeft : ipos.absLeft + pos.absLeft,
\r
6440 absTop : ipos.absTop + pos.absTop
\r
6444 getSel : function() {
\r
6445 var inst = this.instance;
\r
6447 if (tinyMCE.isRealIE)
\r
6448 return inst.getDoc().selection;
\r
6450 return inst.contentWindow.getSelection();
\r
6453 getRng : function() {
\r
6454 var s = this.getSel();
\r
6459 if (tinyMCE.isRealIE)
\r
6460 return s.createRange();
\r
6462 if (tinyMCE.isSafari && !s.getRangeAt)
\r
6463 return '' + window.getSelection();
\r
6465 return s.getRangeAt(0);
\r
6468 getFocusElement : function() {
\r
6469 var inst = this.instance, doc, rng, sel, elm;
\r
6471 if (tinyMCE.isRealIE) {
\r
6472 doc = inst.getDoc();
\r
6473 rng = doc.selection.createRange();
\r
6475 // if (rng.collapse)
\r
6476 // rng.collapse(true);
\r
6478 elm = rng.item ? rng.item(0) : rng.parentElement();
\r
6480 if (!tinyMCE.isSafari && inst.isHidden())
\r
6481 return inst.getBody();
\r
6483 sel = this.getSel();
\r
6484 rng = this.getRng();
\r
6489 elm = rng.commonAncestorContainer;
\r
6490 //elm = (sel && sel.anchorNode) ? sel.anchorNode : null;
\r
6492 // Handle selection a image or other control like element such as anchors
\r
6493 if (!rng.collapsed) {
\r
6494 // Is selection small
\r
6495 if (rng.startContainer == rng.endContainer) {
\r
6496 if (rng.startOffset - rng.endOffset < 2) {
\r
6497 if (rng.startContainer.hasChildNodes())
\r
6498 elm = rng.startContainer.childNodes[rng.startOffset];
\r
6503 // Get the element parent of the node
\r
6504 elm = tinyMCE.getParentElement(elm);
\r
6506 //if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img")
\r
6507 // elm = tinyMCE.selectedElement;
\r
6515 /* file:jscripts/tiny_mce/classes/TinyMCE_UndoRedo.class.js */
\r
6517 function TinyMCE_UndoRedo(inst) {
\r
6518 this.instance = inst;
\r
6519 this.undoLevels = new Array();
\r
6520 this.undoIndex = 0;
\r
6521 this.typingUndoIndex = -1;
\r
6522 this.undoRedo = true;
\r
6525 TinyMCE_UndoRedo.prototype = {
\r
6526 add : function(l) {
\r
6527 var b, customUndoLevels, newHTML, inst = this.instance, i, ul, ur;
\r
6530 this.undoLevels[this.undoLevels.length] = l;
\r
6534 if (this.typingUndoIndex != -1) {
\r
6535 this.undoIndex = this.typingUndoIndex;
\r
6537 if (tinyMCE.typingUndoIndex != -1)
\r
6538 tinyMCE.undoIndex = tinyMCE.typingUndoIndex;
\r
6541 newHTML = tinyMCE.trim(inst.getBody().innerHTML);
\r
6542 if (this.undoLevels[this.undoIndex] && newHTML != this.undoLevels[this.undoIndex].content) {
\r
6543 //tinyMCE.debug(newHTML, this.undoLevels[this.undoIndex].content);
\r
6545 tinyMCE.dispatchCallback(inst, 'onchange_callback', 'onChange', inst);
\r
6547 // Time to compress
\r
6548 customUndoLevels = tinyMCE.settings['custom_undo_redo_levels'];
\r
6549 if (customUndoLevels != -1 && this.undoLevels.length > customUndoLevels) {
\r
6550 for (i=0; i<this.undoLevels.length-1; i++)
\r
6551 this.undoLevels[i] = this.undoLevels[i+1];
\r
6553 this.undoLevels.length--;
\r
6556 // Todo: Implement global undo/redo logic here
\r
6559 b = inst.undoBookmark;
\r
6562 b = inst.selection.getBookmark();
\r
6565 this.undoLevels[this.undoIndex] = {
\r
6566 content : newHTML,
\r
6570 // Remove all above from global undo/redo
\r
6571 ul = tinyMCE.undoLevels;
\r
6572 for (i=tinyMCE.undoIndex + 1; i<ul.length; i++) {
\r
6573 ur = ul[i].undoRedo;
\r
6575 if (ur.undoIndex == ur.undoLevels.length -1)
\r
6578 ur.undoLevels.length--;
\r
6581 // Add global undo level
\r
6582 tinyMCE.undoLevels[tinyMCE.undoIndex++] = inst;
\r
6583 tinyMCE.undoLevels.length = tinyMCE.undoIndex;
\r
6585 this.undoLevels.length = this.undoIndex + 1;
\r
6593 undo : function() {
\r
6594 var inst = this.instance;
\r
6597 if (this.undoIndex > 0) {
\r
6600 tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);
\r
6603 if (inst.settings.custom_undo_redo_restore_selection)
\r
6604 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);
\r
6608 redo : function() {
\r
6609 var inst = this.instance;
\r
6611 tinyMCE.execCommand("mceEndTyping");
\r
6613 if (this.undoIndex < (this.undoLevels.length-1)) {
\r
6616 tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);
\r
6619 if (inst.settings.custom_undo_redo_restore_selection)
\r
6620 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);
\r
6623 tinyMCE.triggerNodeChange();
\r
6628 /* file:jscripts/tiny_mce/classes/TinyMCE_ForceParagraphs.class.js */
\r
6630 var TinyMCE_ForceParagraphs = {
\r
6631 _insertPara : function(inst, e) {
\r
6632 var doc = inst.getDoc(), sel = inst.getSel(), body = inst.getBody(), win = inst.contentWindow, rng = sel.getRangeAt(0);
\r
6633 var rootElm = doc.documentElement, blockName = "P", startNode, endNode, startBlock, endBlock;
\r
6634 var rngBefore, rngAfter, direct, startNode, startOffset, endNode, endOffset, b = tinyMCE.isOpera ? inst.selection.getBookmark() : null;
\r
6635 var paraBefore, paraAfter, startChop, endChop, contents;
\r
6637 function isEmpty(para) {
\r
6638 function isEmptyHTML(html) {
\r
6639 return html.replace(new RegExp('[ \t\r\n]+', 'g'), '').toLowerCase() == "";
\r
6642 // Check for images
\r
6643 if (para.getElementsByTagName("img").length > 0)
\r
6646 // Check for tables
\r
6647 if (para.getElementsByTagName("table").length > 0)
\r
6651 if (para.getElementsByTagName("hr").length > 0)
\r
6654 // Check all textnodes
\r
6655 var nodes = tinyMCE.getNodeTree(para, new Array(), 3);
\r
6656 for (var i=0; i<nodes.length; i++) {
\r
6657 if (!isEmptyHTML(nodes[i].nodeValue))
\r
6661 // No images, no tables, no hrs, no text content then it's empty
\r
6665 // tinyMCE.debug(body.innerHTML);
\r
6667 // debug(e.target, sel.anchorNode.nodeName, sel.focusNode.nodeName, rng.startContainer, rng.endContainer, rng.commonAncestorContainer, sel.anchorOffset, sel.focusOffset, rng.toString());
\r
6669 // Setup before range
\r
6670 rngBefore = doc.createRange();
\r
6671 rngBefore.setStart(sel.anchorNode, sel.anchorOffset);
\r
6672 rngBefore.collapse(true);
\r
6674 // Setup after range
\r
6675 rngAfter = doc.createRange();
\r
6676 rngAfter.setStart(sel.focusNode, sel.focusOffset);
\r
6677 rngAfter.collapse(true);
\r
6679 // Setup start/end points
\r
6680 direct = rngBefore.compareBoundaryPoints(rngBefore.START_TO_END, rngAfter) < 0;
\r
6681 startNode = direct ? sel.anchorNode : sel.focusNode;
\r
6682 startOffset = direct ? sel.anchorOffset : sel.focusOffset;
\r
6683 endNode = direct ? sel.focusNode : sel.anchorNode;
\r
6684 endOffset = direct ? sel.focusOffset : sel.anchorOffset;
\r
6686 startNode = startNode.nodeName == "BODY" ? startNode.firstChild : startNode;
\r
6687 endNode = endNode.nodeName == "BODY" ? endNode.firstChild : endNode;
\r
6689 // Get block elements
\r
6690 startBlock = inst.getParentBlockElement(startNode);
\r
6691 endBlock = inst.getParentBlockElement(endNode);
\r
6693 // If absolute force paragraph generation within
\r
6694 if (startBlock && new RegExp('absolute|relative|static', 'gi').test(startBlock.style.position))
\r
6695 startBlock = null;
\r
6697 if (endBlock && new RegExp('absolute|relative|static', 'gi').test(endBlock.style.position))
\r
6700 // Use current block name
\r
6701 if (startBlock != null) {
\r
6702 blockName = startBlock.nodeName;
\r
6705 if (blockName == "TD" || blockName == "TABLE" || (blockName == "DIV" && new RegExp('left|right', 'gi').test(startBlock.style.cssFloat)))
\r
6709 // Within a list use normal behaviour
\r
6710 if (tinyMCE.getParentElement(startBlock, "OL,UL", null, body) != null)
\r
6713 // Within a table create new paragraphs
\r
6714 if ((startBlock != null && startBlock.nodeName == "TABLE") || (endBlock != null && endBlock.nodeName == "TABLE"))
\r
6715 startBlock = endBlock = null;
\r
6717 // Setup new paragraphs
\r
6718 paraBefore = (startBlock != null && startBlock.nodeName == blockName) ? startBlock.cloneNode(false) : doc.createElement(blockName);
\r
6719 paraAfter = (endBlock != null && endBlock.nodeName == blockName) ? endBlock.cloneNode(false) : doc.createElement(blockName);
\r
6721 // Is header, then force paragraph under
\r
6722 if (/^(H[1-6])$/.test(blockName))
\r
6723 paraAfter = doc.createElement("p");
\r
6725 // Setup chop nodes
\r
6726 startChop = startNode;
\r
6727 endChop = endNode;
\r
6729 // Get startChop node
\r
6732 if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
\r
6736 } while ((node = node.previousSibling ? node.previousSibling : node.parentNode));
\r
6738 // Get endChop node
\r
6741 if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
\r
6745 } while ((node = node.nextSibling ? node.nextSibling : node.parentNode));
\r
6747 // Fix when only a image is within the TD
\r
6748 if (startChop.nodeName == "TD")
\r
6749 startChop = startChop.firstChild;
\r
6751 if (endChop.nodeName == "TD")
\r
6752 endChop = endChop.lastChild;
\r
6754 // If not in a block element
\r
6755 if (startBlock == null) {
\r
6756 // Delete selection
\r
6757 rng.deleteContents();
\r
6759 if (!tinyMCE.isSafari)
\r
6760 sel.removeAllRanges();
\r
6762 if (startChop != rootElm && endChop != rootElm) {
\r
6763 // Insert paragraph before
\r
6764 rngBefore = rng.cloneRange();
\r
6766 if (startChop == body)
\r
6767 rngBefore.setStart(startChop, 0);
\r
6769 rngBefore.setStartBefore(startChop);
\r
6771 paraBefore.appendChild(rngBefore.cloneContents());
\r
6773 // Insert paragraph after
\r
6774 if (endChop.parentNode.nodeName == blockName)
\r
6775 endChop = endChop.parentNode;
\r
6777 // If not after image
\r
6778 //if (rng.startContainer.nodeName != "BODY" && rng.endContainer.nodeName != "BODY")
\r
6779 rng.setEndAfter(endChop);
\r
6781 if (endChop.nodeName != "#text" && endChop.nodeName != "BODY")
\r
6782 rngBefore.setEndAfter(endChop);
\r
6784 contents = rng.cloneContents();
\r
6785 if (contents.firstChild && (contents.firstChild.nodeName == blockName || contents.firstChild.nodeName == "BODY"))
\r
6786 paraAfter.innerHTML = contents.firstChild.innerHTML;
\r
6788 paraAfter.appendChild(contents);
\r
6790 // Check if it's a empty paragraph
\r
6791 if (isEmpty(paraBefore))
\r
6792 paraBefore.innerHTML = " ";
\r
6794 // Check if it's a empty paragraph
\r
6795 if (isEmpty(paraAfter))
\r
6796 paraAfter.innerHTML = " ";
\r
6798 // Delete old contents
\r
6799 rng.deleteContents();
\r
6800 rngAfter.deleteContents();
\r
6801 rngBefore.deleteContents();
\r
6803 // Insert new paragraphs
\r
6804 if (tinyMCE.isOpera) {
\r
6805 paraBefore.normalize();
\r
6806 rngBefore.insertNode(paraBefore);
\r
6807 paraAfter.normalize();
\r
6808 rngBefore.insertNode(paraAfter);
\r
6810 paraAfter.normalize();
\r
6811 rngBefore.insertNode(paraAfter);
\r
6812 paraBefore.normalize();
\r
6813 rngBefore.insertNode(paraBefore);
\r
6816 //tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML);
\r
6818 body.innerHTML = "<" + blockName + "> </" + blockName + "><" + blockName + "> </" + blockName + ">";
\r
6819 paraAfter = body.childNodes[1];
\r
6822 inst.selection.moveToBookmark(b);
\r
6823 inst.selection.selectNode(paraAfter, true, true);
\r
6828 // Place first part within new paragraph
\r
6829 if (startChop.nodeName == blockName)
\r
6830 rngBefore.setStart(startChop, 0);
\r
6832 rngBefore.setStartBefore(startChop);
\r
6834 rngBefore.setEnd(startNode, startOffset);
\r
6835 paraBefore.appendChild(rngBefore.cloneContents());
\r
6837 // Place secound part within new paragraph
\r
6838 rngAfter.setEndAfter(endChop);
\r
6839 rngAfter.setStart(endNode, endOffset);
\r
6840 contents = rngAfter.cloneContents();
\r
6842 if (contents.firstChild && contents.firstChild.nodeName == blockName) {
\r
6843 /* var nodes = contents.firstChild.childNodes;
\r
6844 for (var i=0; i<nodes.length; i++) {
\r
6845 //tinyMCE.debug(nodes[i].nodeName);
\r
6846 if (nodes[i].nodeName != "BODY")
\r
6847 paraAfter.appendChild(nodes[i]);
\r
6850 paraAfter.innerHTML = contents.firstChild.innerHTML;
\r
6852 paraAfter.appendChild(contents);
\r
6854 // Check if it's a empty paragraph
\r
6855 if (isEmpty(paraBefore))
\r
6856 paraBefore.innerHTML = " ";
\r
6858 // Check if it's a empty paragraph
\r
6859 if (isEmpty(paraAfter))
\r
6860 paraAfter.innerHTML = " ";
\r
6862 // Create a range around everything
\r
6863 rng = doc.createRange();
\r
6865 if (!startChop.previousSibling && startChop.parentNode.nodeName.toUpperCase() == blockName) {
\r
6866 rng.setStartBefore(startChop.parentNode);
\r
6868 if (rngBefore.startContainer.nodeName.toUpperCase() == blockName && rngBefore.startOffset == 0)
\r
6869 rng.setStartBefore(rngBefore.startContainer);
\r
6871 rng.setStart(rngBefore.startContainer, rngBefore.startOffset);
\r
6874 if (!endChop.nextSibling && endChop.parentNode.nodeName.toUpperCase() == blockName)
\r
6875 rng.setEndAfter(endChop.parentNode);
\r
6877 rng.setEnd(rngAfter.endContainer, rngAfter.endOffset);
\r
6879 // Delete all contents and insert new paragraphs
\r
6880 rng.deleteContents();
\r
6882 if (tinyMCE.isOpera) {
\r
6883 rng.insertNode(paraBefore);
\r
6884 rng.insertNode(paraAfter);
\r
6886 rng.insertNode(paraAfter);
\r
6887 rng.insertNode(paraBefore);
\r
6890 //tinyMCE.debug("2", paraBefore.innerHTML, paraAfter.innerHTML);
\r
6893 paraAfter.normalize();
\r
6894 paraBefore.normalize();
\r
6896 inst.selection.moveToBookmark(b);
\r
6897 inst.selection.selectNode(paraAfter, true, true);
\r
6902 _handleBackSpace : function(inst) {
\r
6903 var r = inst.getRng(), sn = r.startContainer, nv, s = false;
\r
6905 // Added body check for bug #1527787
\r
6906 if (sn && sn.nextSibling && sn.nextSibling.nodeName == "BR" && sn.parentNode.nodeName != "BODY") {
\r
6907 nv = sn.nodeValue;
\r
6909 // Handle if a backspace is pressed after a space character #bug 1466054 removed since fix for #1527787
\r
6910 /*if (nv != null && nv.length >= r.startOffset && nv.charAt(r.startOffset - 1) == ' ')
\r
6913 // Only remove BRs if we are at the end of line #bug 1464152
\r
6914 if (nv != null && r.startOffset == nv.length)
\r
6915 sn.nextSibling.parentNode.removeChild(sn.nextSibling);
\r
6918 if (inst.settings.auto_resize)
\r
6919 inst.resizeToContent();
\r
6926 /* file:jscripts/tiny_mce/classes/TinyMCE_Layer.class.js */
\r
6928 function TinyMCE_Layer(id, bm) {
\r
6930 this.blockerElement = null;
\r
6931 this.events = false;
\r
6932 this.element = null;
\r
6933 this.blockMode = typeof(bm) != 'undefined' ? bm : true;
\r
6934 this.doc = document;
\r
6937 TinyMCE_Layer.prototype = {
\r
6938 moveRelativeTo : function(re, p) {
\r
6939 var rep = this.getAbsPosition(re);
\r
6940 var w = parseInt(re.offsetWidth);
\r
6941 var h = parseInt(re.offsetHeight);
\r
6942 var e = this.getElement();
\r
6943 var ew = parseInt(e.offsetWidth);
\r
6944 var eh = parseInt(e.offsetHeight);
\r
6954 x = rep.absLeft + w;
\r
6960 y = rep.absTop + h;
\r
6964 x = rep.absLeft + w;
\r
6965 y = rep.absTop + h;
\r
6969 x = rep.absLeft + (w / 2) - (ew / 2);
\r
6970 y = rep.absTop + (h / 2) - (eh / 2);
\r
6974 this.moveTo(x, y);
\r
6977 moveBy : function(x, y) {
\r
6978 var e = this.getElement();
\r
6979 this.moveTo(parseInt(e.style.left) + x, parseInt(e.style.top) + y);
\r
6982 moveTo : function(x, y) {
\r
6983 var e = this.getElement();
\r
6985 e.style.left = x + "px";
\r
6986 e.style.top = y + "px";
\r
6988 this.updateBlocker();
\r
6991 resizeBy : function(w, h) {
\r
6992 var e = this.getElement();
\r
6993 this.resizeTo(parseInt(e.style.width) + w, parseInt(e.style.height) + h);
\r
6996 resizeTo : function(w, h) {
\r
6997 var e = this.getElement();
\r
7000 e.style.width = w + "px";
\r
7003 e.style.height = h + "px";
\r
7005 this.updateBlocker();
\r
7008 show : function() {
\r
7009 this.getElement().style.display = 'block';
\r
7010 this.updateBlocker();
\r
7013 hide : function() {
\r
7014 this.getElement().style.display = 'none';
\r
7015 this.updateBlocker();
\r
7018 isVisible : function() {
\r
7019 return this.getElement().style.display == 'block';
\r
7022 getElement : function() {
\r
7023 if (!this.element)
\r
7024 this.element = this.doc.getElementById(this.id);
\r
7026 return this.element;
\r
7029 setBlockMode : function(s) {
\r
7030 this.blockMode = s;
\r
7033 updateBlocker : function() {
\r
7034 var e, b, x, y, w, h;
\r
7036 b = this.getBlocker();
\r
7038 if (this.blockMode) {
\r
7039 e = this.getElement();
\r
7040 x = this.parseInt(e.style.left);
\r
7041 y = this.parseInt(e.style.top);
\r
7042 w = this.parseInt(e.offsetWidth);
\r
7043 h = this.parseInt(e.offsetHeight);
\r
7045 b.style.left = x + 'px';
\r
7046 b.style.top = y + 'px';
\r
7047 b.style.width = w + 'px';
\r
7048 b.style.height = h + 'px';
\r
7049 b.style.display = e.style.display;
\r
7051 b.style.display = 'none';
\r
7055 getBlocker : function() {
\r
7058 if (!this.blockerElement && this.blockMode) {
\r
7060 b = d.getElementById(this.id + "_blocker");
\r
7063 b = d.createElement("iframe");
\r
7065 b.setAttribute('id', this.id + "_blocker");
\r
7066 b.style.cssText = 'display: none; position: absolute; left: 0; top: 0';
\r
7067 b.src = 'javascript:false;';
\r
7068 b.frameBorder = '0';
\r
7069 b.scrolling = 'no';
\r
7071 d.body.appendChild(b);
\r
7074 this.blockerElement = b;
\r
7077 return this.blockerElement;
\r
7080 getAbsPosition : function(n) {
\r
7081 var p = {absLeft : 0, absTop : 0};
\r
7084 p.absLeft += n.offsetLeft;
\r
7085 p.absTop += n.offsetTop;
\r
7086 n = n.offsetParent;
\r
7092 create : function(n, c, p, h) {
\r
7093 var d = this.doc, e = d.createElement(n);
\r
7095 e.setAttribute('id', this.id);
\r
7108 return this.element = e;
\r
7111 exists : function() {
\r
7112 return this.doc.getElementById(this.id) != null;
\r
7115 parseInt : function(s) {
\r
7116 if (s == null || s == '')
\r
7119 return parseInt(s);
\r
7124 /* file:jscripts/tiny_mce/classes/TinyMCE_Menu.class.js */
\r
7126 function TinyMCE_Menu() {
\r
7129 if (typeof(tinyMCE.menuCounter) == "undefined")
\r
7130 tinyMCE.menuCounter = 0;
\r
7132 id = "mc_menu_" + tinyMCE.menuCounter++;
\r
7134 TinyMCE_Layer.call(this, id, true);
\r
7137 this.items = new Array();
\r
7138 this.needsUpdate = true;
\r
7141 TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, {
\r
7142 init : function(s) {
\r
7147 separator_class : 'mceMenuSeparator',
\r
7148 title_class : 'mceMenuTitle',
\r
7149 disabled_class : 'mceMenuDisabled',
\r
7150 menu_class : 'mceMenu',
\r
7155 this.settings[n] = s[n];
\r
7157 this.create('div', this.settings.menu_class);
\r
7160 clear : function() {
\r
7161 this.items = new Array();
\r
7164 addTitle : function(t) {
\r
7165 this.add({type : 'title', text : t});
\r
7168 addDisabled : function(t) {
\r
7169 this.add({type : 'disabled', text : t});
\r
7172 addSeparator : function() {
\r
7173 this.add({type : 'separator'});
\r
7176 addItem : function(t, js) {
\r
7177 this.add({text : t, js : js});
\r
7180 add : function(mi) {
\r
7181 this.items[this.items.length] = mi;
\r
7182 this.needsUpdate = true;
\r
7185 update : function() {
\r
7186 var e = this.getElement(), h = '', i, t, m = this.items, s = this.settings;
\r
7188 if (this.settings.drop_menu)
\r
7189 h += '<span class="mceMenuLine"></span>';
\r
7191 h += '<table border="0" cellpadding="0" cellspacing="0">';
\r
7193 for (i=0; i<m.length; i++) {
\r
7194 t = tinyMCE.xmlEncode(m[i].text);
\r
7195 c = m[i].class_name ? ' class="' + m[i].class_name + '"' : '';
\r
7197 switch (m[i].type) {
\r
7199 h += '<tr class="' + s.separator_class + '"><td>';
\r
7203 h += '<tr class="' + s.title_class + '"><td><span' + c +'>' + t + '</span>';
\r
7207 h += '<tr class="' + s.disabled_class + '"><td><span' + c +'>' + t + '</span>';
\r
7211 h += '<tr><td><a href="#" onclick="return tinyMCE.cancelEvent(event);" onmousedown="return tinyMCE.cancelEvent(event);" onmouseup="' + tinyMCE.xmlEncode(m[i].js) + ';return tinyMCE.cancelEvent(event);"><span' + c +'>' + t + '</span></a>';
\r
7214 h += '</td></tr>';
\r
7221 this.needsUpdate = false;
\r
7222 this.updateBlocker();
\r
7225 show : function() {
\r
7228 if (tinyMCE.lastMenu == this)
\r
7231 if (this.needsUpdate)
\r
7234 if (tinyMCE.lastMenu && tinyMCE.lastMenu != this)
\r
7235 tinyMCE.lastMenu.hide();
\r
7237 TinyMCE_Layer.prototype.show.call(this);
\r
7239 if (!tinyMCE.isOpera) {
\r
7240 // Accessibility stuff
\r
7241 /* nl = this.getElement().getElementsByTagName("a");
\r
7242 if (nl.length > 0)
\r
7246 tinyMCE.lastMenu = this;
\r
7251 /* file:jscripts/tiny_mce/classes/TinyMCE_Compatibility.class.js */
\r
7253 if (!Function.prototype.call) {
\r
7254 Function.prototype.call = function() {
\r
7255 var a = arguments, s = a[0], i, as = '', r, o;
\r
7257 for (i=1; i<a.length; i++)
\r
7258 as += (i > 1 ? ',' : '') + 'a[' + i + ']';
\r
7262 r = eval('s._fu(' + as + ')');
\r
7269 /* file:jscripts/tiny_mce/classes/TinyMCE_Debug.class.js */
\r
7271 TinyMCE_Engine.prototype.debug = function() {
\r
7272 var m = "", a, i, l = tinyMCE.log.length;
\r
7274 for (i=0, a = this.debug.arguments; i<a.length; i++) {
\r
7282 tinyMCE.log[l] = "[debug] " + m;
\r