applied my changes - initial import
[boxroom-stian.git] / public / javascripts / tiny_mce / tiny_mce_src.js
blob2a8be73835f1257dd0d14ceb3a6e48eebeefce7d
1 \r
2 /* file:jscripts/tiny_mce/classes/TinyMCE_Engine.class.js */\r
3 \r
4 function TinyMCE_Engine() {\r
5         var ua;\r
6 \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
22         this.undoIndex = 0;\r
23         this.typingUndoIndex = -1;\r
25         // Browser check\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
46         if (this.isOpera) {\r
47                 this.isMSIE = true;\r
48                 this.isGecko = false;\r
49                 this.isSafari =  false;\r
50         }\r
52         this.isIE = this.isMSIE;\r
53         this.isRealIE = this.isMSIE && !this.isOpera;\r
55         // TinyMCE editor id instance counter\r
56         this.idCounter = 0;\r
57 };\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
64                 if (this.isMSIE5_0)\r
65                         return;\r
67                 this.settings = settings;\r
69                 // Check if valid browser has execcommand support\r
70                 if (typeof(document.execCommand) == 'undefined')\r
71                         return;\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
80                                 if (nl[i].href)\r
81                                         baseHREF = nl[i].href;\r
82                         }\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
98                                         else\r
99                                                 tinyMCE.baseURL = src;\r
101                                         break;\r
102                                 }\r
103                         }\r
104                 }\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
117                 }\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
202                         return;\r
204                 // Browser check Gecko\r
205                 if (this.isGecko && this.settings['browsers'].indexOf('gecko') == -1)\r
206                         return;\r
208                 // Browser check Safari\r
209                 if (this.isSafari && this.settings['browsers'].indexOf('safari') == -1)\r
210                         return;\r
212                 // Browser check Opera\r
213                 if (this.isOpera && this.settings['browsers'].indexOf('opera') == -1)\r
214                         return;\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
229                 }\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
247                 // Theme url\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
256                         // Is relative\r
257                         if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')\r
258                                 this.settings['popups_css'] = this.documentBasePath + "/" + cssPath;\r
259                         else\r
260                                 this.settings['popups_css'] = cssPath;\r
261                 } else\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
267                         // Is relative\r
268                         if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')\r
269                                 this.settings['editor_css'] = this.documentBasePath + "/" + cssPath;\r
270                         else\r
271                                 this.settings['editor_css'] = cssPath;\r
272                 } else {\r
273                         if (this.settings.editor_css != '')\r
274                                 this.settings['editor_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css";\r
275                 }\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
286                         alert(msg);\r
287                 }\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
295                                         if (document.body)\r
296                                                 tinyMCE.addEvent(document.body, "readystatechange", TinyMCE_Engine.prototype.onLoad);\r
297                                         else\r
298                                                 tinyMCE.addEvent(document, "readystatechange", TinyMCE_Engine.prototype.onLoad);\r
299                                 }\r
301                                 tinyMCE.addEvent(window, "load", TinyMCE_Engine.prototype.onLoad);\r
302                                 tinyMCE._addUnloadEvents();\r
303                         }\r
304                 }\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
310                 // Add plugins\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
316                         }\r
317                 }\r
319                 // Setup entities\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
325                 }\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
336                         try {\r
337                                 document.execCommand('BackgroundImageCache', false, true);\r
338                         } catch (e) {\r
339                         }\r
340                 }\r
341         },\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
348                         }\r
349                 } else {\r
350                         if (tinyMCE.settings['add_unload_trigger'])\r
351                                 tinyMCE.addEvent(window, "unload", function () {tinyMCE.triggerSave(true, true);});\r
352                 }\r
353         },\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
361         },\r
363         hasPlugin : function(n) {\r
364                 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;\r
365         },\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
375         },\r
377         setPluginBaseURL : function(n, u) {\r
378                 var op = this.plugins[n];\r
380                 if (op)\r
381                         op.baseURL = u;\r
382                 else\r
383                         this.plugins[n] = {baseURL : u};\r
384         },\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
391         },\r
393         hasTheme : function(n) {\r
394                 return typeof(this.themes[n]) != "undefined" && this.themes[n] != null;\r
395         },\r
397         addTheme : function(n, t) {\r
398                 this.themes[n] = t;\r
400                 this.loadNextScript();\r
401         },\r
403         addMenu : function(n, m) {\r
404                 this.menus[n] = m;\r
405         },\r
407         hasMenu : function(n) {\r
408                 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;\r
409         },\r
411         loadScript : function(url) {\r
412                 var i;\r
414                 for (i=0; i<this.loadedFiles.length; i++) {\r
415                         if (this.loadedFiles[i] == url)\r
416                                 return;\r
417                 }\r
419                 if (tinyMCE.settings.strict_loading_mode)\r
420                         this.pendingFiles[this.pendingFiles.length] = url;\r
421                 else\r
422                         document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></script>');\r
424                 this.loadedFiles[this.loadedFiles.length] = url;\r
425         },\r
427         loadNextScript : function() {\r
428                 var d = document, se;\r
430                 if (!tinyMCE.settings.strict_loading_mode)\r
431                         return;\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
440                 } else\r
441                         this.loadingIndex = -1; // Done with loading\r
442         },\r
444         loadCSS : function(url) {\r
445                 var ar = url.replace(/\s+/, '').split(',');\r
446                 var lflen = 0, csslen = 0;\r
447                 var skip = false;\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
455                                                 skip = true;\r
456                                                 break;\r
457                                         }\r
458                                 }\r
460                                 if (!skip) {\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
470                                         } else\r
471                                                 document.write('<link href="' + ar[x] + '" rel="stylesheet" type="text/css" />');\r
473                                         this.loadedFiles[this.loadedFiles.length] = ar[x];\r
474                                 }\r
475                         }\r
476                 }\r
477         },\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
499                                 } else\r
500                                         doc.createStyleSheet(css_file);\r
501                         }\r
502                 }\r
503         },\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
515         },\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
523                                 continue;\r
525                         inst.switchSettings();\r
527                         if (inst.formElement == formElement) {\r
528                                 var doc = inst.getDoc();\r
529                 \r
530                                 tinyMCE._setHTML(doc, inst.formElement.value);\r
532                                 if (!tinyMCE.isIE)\r
533                                         doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid);\r
534                         }\r
535                 }\r
536         },\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
546         },\r
548         removeInstance : function(ti) {\r
549                 var t = [], n, i;\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
556                                         t[n] = i;\r
557                 }\r
559                 tinyMCE.instances = t;\r
561                 // Remove from global undo/redo\r
562                 n = [];\r
563                 t = tinyMCE.undoLevels;\r
565                 for (i=0; i<t.length; i++) {\r
566                         if (t[i] != ti)\r
567                                 n.push(t[i]);\r
568                 }\r
570                 tinyMCE.undoLevels = n;\r
571                 tinyMCE.undoIndex = n.length;\r
573                 return ti;\r
574         },\r
576         removeMCEControl : function(editor_id) {\r
577                 var inst = tinyMCE.getInstanceById(editor_id), h, re, ot, tn;\r
579                 if (inst) {\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
590                         // Remove element\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
598                                 ot.value = h;\r
599                         } else {\r
600                                 ot.innerHTML = h;\r
601                                 ot.style.display = 'block';\r
602                                 re.parentNode.insertBefore(ot, re);\r
603                                 re.parentNode.removeChild(re);\r
604                         }\r
605                 }\r
606         },\r
608         triggerSave : function(skip_cleanup, skip_callback) {\r
609                 var inst, n;\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
624                                 continue;\r
626                         inst.triggerSave(skip_cleanup, skip_callback);\r
627                 }\r
628         },\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
637                                 continue;\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
644                         }\r
645                 }\r
646         },\r
648         execInstanceCommand : function(editor_id, command, user_interface, value, focus) {\r
649                 var inst = tinyMCE.getInstanceById(editor_id), r;\r
651                 if (inst) {\r
652                         r = inst.selection.getRng();\r
654                         if (typeof(focus) == "undefined")\r
655                                 focus = true;\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
665                         inst.select();\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
671                 }\r
672         },\r
674         execCommand : function(command, user_interface, value) {\r
675                 var inst = tinyMCE.selectedInstance;\r
677                 // Default input\r
678                 user_interface = user_interface ? user_interface : false;\r
679                 value = value ? value : null;\r
681                 if (inst)\r
682                         inst.switchSettings();\r
684                 switch (command) {\r
685                         case "Undo":\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
690                                                 inst.select();\r
692                                                 if (!tinyMCE.nextUndoRedoInstanceId)\r
693                                                         inst.execCommand('Undo');\r
694                                         }\r
695                                 } else\r
696                                         inst.execCommand('Undo');\r
697                                 return true;\r
699                         case "Redo":\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
704                                                 inst.select();\r
706                                                 if (!tinyMCE.nextUndoRedoInstanceId)\r
707                                                         inst.execCommand('Redo');\r
708                                         }\r
709                                 } else\r
710                                         inst.execCommand('Redo');\r
712                                 return true;\r
714                         case 'mceFocus':\r
715                                 var inst = tinyMCE.getInstanceById(value);\r
716                                 if (inst)\r
717                                         inst.getWin().focus();\r
718                         return;\r
720                         case "mceAddControl":\r
721                         case "mceAddEditor":\r
722                                 tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);\r
723                                 return;\r
725                         case "mceAddFrameControl":\r
726                                 tinyMCE.addMCEControl(tinyMCE._getElementById(value['element'], value['document']), value['element'], value['document']);\r
727                                 return;\r
729                         case "mceRemoveControl":\r
730                         case "mceRemoveEditor":\r
731                                 tinyMCE.removeMCEControl(value);\r
732                                 return;\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
739                                                         continue;\r
741                                                 try {\r
742                                                         tinyMCE.instances[n].getDoc().designMode = "on";\r
743                                                 } catch (e) {\r
744                                                         // Ignore any errors\r
745                                                 }\r
746                                         }\r
747                                 }\r
749                                 return;\r
750                 }\r
752                 if (inst) {\r
753                         inst.execCommand(command, user_interface, value);\r
754                 } else if (tinyMCE.settings['focus_alert'])\r
755                         alert(tinyMCELang['lang_focus_alert']);\r
756         },\r
758         _createIFrame : function(replace_element, doc, win) {\r
759                 var iframe, id = replace_element.getAttribute("id");\r
760                 var aw, ah;\r
762                 if (typeof(doc) == "undefined")\r
763                         doc = document;\r
765                 if (typeof(win) == "undefined")\r
766                         win = window;\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
774                         aw = parseInt(aw);\r
775                         aw = (isNaN(aw) || aw < 0) ? 300 : aw;\r
776                         aw = aw + "px";\r
777                 }\r
779                 if (ah.indexOf('%') == -1) {\r
780                         ah = parseInt(ah);\r
781                         ah = (isNaN(ah) || ah < 0) ? 240 : ah;\r
782                         ah = ah + "px";\r
783                 }\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
813                 // MSIE 5.0 issue\r
814                 if (tinyMCE.isRealIE)\r
815                         replace_element.outerHTML = iframe.outerHTML;\r
816                 else\r
817                         replace_element.parentNode.replaceChild(iframe, replace_element);\r
819                 if (tinyMCE.isRealIE)\r
820                         return win.frames[id];\r
821                 else\r
822                         return iframe;\r
823         },\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(/&lt;/g, '<');\r
834                         content = content.replace(/&gt;/g, '>');\r
835                         content = content.replace(/&quot;/g, '"');\r
836                         content = content.replace(/&amp;/g, '&');\r
837                 }\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
847                         return;\r
848                 }\r
850                 if (!head) {\r
851                         window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10);\r
852                         return;\r
853                 }\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
864                 }\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
879                 }\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
892                 if (!tinyMCE.isIE)\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
902                 }\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
912                         // Ugly!!!\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
920                 }\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('&lt;&gt;', 'g'), "");\r
935                         if (tinyMCE.settings['cleanup_on_startup'])\r
936                                 tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement));\r
937                         else\r
938                                 tinyMCE.setInnerHTML(inst.getBody(), content);\r
940                         tinyMCE.convertAllRelativeURLs(inst.getBody());\r
941                 } else {\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
947                         } else\r
948                                 tinyMCE._setHTML(inst.getDoc(), content);\r
949                 }\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
962                 if (!tinyMCE.isIE)\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
975                         }\r
976                 }\r
978                 // Trigger node change, this call locks buttons for tables and so forth\r
979                 inst.select();\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
1001                                 return false;\r
1002                         });\r
1003                 }\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
1012                 inst.select();\r
1013                 tinyMCE.triggerNodeChange(false, true);\r
1014         },\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
1024                 }\r
1026                 return s;\r
1027         },\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
1036                                 return false;\r
1037                         });\r
1038                 }\r
1039         },\r
1041         handleEvent : function(e) {\r
1042                 var inst = tinyMCE.selectedInstance;\r
1044                 // Remove odd, error\r
1045                 if (typeof(tinyMCE) == "undefined")\r
1046                         return true;\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
1051                         return false;\r
1053                 switch (e.type) {\r
1054                         case "beforedeactivate": // Was added due to bug #1439953\r
1055                         case "blur":\r
1056                                 if (tinyMCE.selectedInstance)\r
1057                                         tinyMCE.selectedInstance.execCommand('mceEndTyping');\r
1059                                 tinyMCE.hideMenus();\r
1061                                 return;\r
1063                         // Workaround for drag drop/copy paste base href bug\r
1064                         case "drop":\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
1077                                         }*/\r
1079                                         if (ife.style.height.indexOf('%') != -1) {\r
1080                                                 ife._oldHeight = ife.style.height;\r
1081                                                 ife.style.height = ife.clientHeight;\r
1082                                         }\r
1083                                 }\r
1085                                 window.setTimeout("tinyMCE.selectedInstance.setBaseHREF(tinyMCE.settings['base_href']);tinyMCE._resetIframeHeight();", 1);\r
1086                                 return;\r
1088                         case "submit":\r
1089                                 tinyMCE.triggerSave();\r
1090                                 tinyMCE.isNotDirty = true;\r
1091                                 return;\r
1093                         case "reset":\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
1099                                 }\r
1101                                 return;\r
1103                         case "keypress":\r
1104                                 if (inst && inst.handleShortcut(e))\r
1105                                         return false;\r
1107                                 if (e.target.editorId) {\r
1108                                         tinyMCE.instances[e.target.editorId].select();\r
1109                                 } else {\r
1110                                         if (e.target.ownerDocument.editorId)\r
1111                                                 tinyMCE.instances[e.target.ownerDocument.editorId].select();\r
1112                                 }\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
1121                                                 // Cancel event\r
1122                                                 tinyMCE.execCommand("mceAddUndoLevel");\r
1123                                                 return tinyMCE.cancelEvent(e);\r
1124                                         }\r
1125                                 }\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
1131                                                 // Cancel event\r
1132                                                 tinyMCE.execCommand("mceAddUndoLevel");\r
1133                                                 return tinyMCE.cancelEvent(e);\r
1134                                         }\r
1135                                 }\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
1147                                                         return false;\r
1149                                                 // Cancel event\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
1156                                                 rng.select();\r
1158                                                 tinyMCE.execCommand("mceAddUndoLevel");\r
1159                                                 tinyMCE.triggerNodeChange(false);\r
1160                                                 return false;\r
1161                                         }\r
1162                                 }\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
1170                                 }\r
1172                                 return false;\r
1173                         break;\r
1175                         case "keyup":\r
1176                         case "keydown":\r
1177                                 tinyMCE.hideMenus();\r
1178                                 tinyMCE.hasMouseMoved = false;\r
1180                                 if (inst && inst.handleShortcut(e))\r
1181                                         return false;\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
1195                                                 // Cancel event\r
1196                                                 tinyMCE.execCommand("mceAddUndoLevel");\r
1197                                                 e.preventDefault();\r
1198                                                 return false;\r
1199                                         }\r
1200                                 }\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
1220                                         if (elm) {\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 = "&nbsp;&nbsp;";\r
1227                                                         else\r
1228                                                                 elm.innerHTML = "&nbsp;";\r
1229                                                 }\r
1230                                         }\r
1231                                 }\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
1238                                                 posKey = true;\r
1239                                                 break;\r
1240                                         }\r
1241                                 }\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
1251                                                 }\r
1252                                         }\r
1253                                 }\r
1255                                 // If Ctrl key\r
1256                                 if (e.keyCode == 17)\r
1257                                         return true;\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
1265                                 } else {\r
1266                                         // IE seems to be working better with this setting\r
1267                                         if (!posKey && e.type == "keyup")\r
1268                                                 tinyMCE.execCommand("mceStartTyping");\r
1269                                 }\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
1284                         break;\r
1286                         case "mousedown":\r
1287                         case "mouseup":\r
1288                         case "click":\r
1289                         case "dblclick":\r
1290                         case "focus":\r
1291                                 tinyMCE.hideMenus();\r
1293                                 if (tinyMCE.selectedInstance) {\r
1294                                         tinyMCE.selectedInstance.switchSettings();\r
1295                                         tinyMCE.selectedInstance.isFocused = true;\r
1296                                 }\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
1302                                                 continue;\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
1311                                                 inst.select();\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
1315                                                 break;\r
1316                                         }\r
1317                                 }\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
1333                                 // Just in case\r
1334                                 if (!tinyMCE.selectedInstance && e.target.editorId)\r
1335                                         tinyMCE.instances[e.target.editorId].select();\r
1337                                 return false;\r
1338                         break;\r
1339                 }\r
1340         },\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
1348                         cmd += ',' + ui;\r
1350                 if (typeof(val) != "undefined" && val != null)\r
1351                         cmd += ",'" + val + "'";\r
1353                 cmd += ');';\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
1361                         // Tiled button\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
1365                         h += '</a>';\r
1366                 } else {\r
1367                         // Normal button\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
1370                         h += '</a>';\r
1371                 }\r
1373                 return h;\r
1374         },\r
1376         getMenuButtonHTML : function(id, lang, img, mcmd, cmd, ui, val) {\r
1377                 var h = '', m, x;\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
1383                         cmd += ',' + ui;\r
1385                 if (typeof(val) != "undefined" && val != null)\r
1386                         cmd += ",'" + val + "'";\r
1388                 cmd += ');';\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
1396                         else\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
1403                 } else {\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
1406                         else\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
1413                 }\r
1415                 return h;\r
1416         },\r
1418         _menuButtonEvent : function(e, o) {\r
1419                 if (o.className == 'mceMenuButtonFocus')\r
1420                         return;\r
1422                 if (e == 'over')\r
1423                         o.className = o.className + ' mceMenuHover';\r
1424                 else\r
1425                         o.className = o.className.replace(/\s.*$/, '');\r
1426         },\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
1433         },\r
1435         submitPatch : function() {\r
1436                 tinyMCE.triggerSave();\r
1437                 tinyMCE.isNotDirty = true;\r
1438                 this.mceOldSubmit();\r
1439         },\r
1441         onLoad : function() {\r
1442                 var r;\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
1447                         return;\r
1448                 }\r
1450                 if (tinyMCE.isRealIE && window.event.type == "readystatechange" && document.readyState != "complete")\r
1451                         return true;\r
1453                 if (tinyMCE.isLoaded)\r
1454                         return true;\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
1463                         r.collapse(true);\r
1464                         r.select();\r
1465                 }\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
1487                                                 try {\r
1488                                                         form.mceOldSubmit = form.submit;\r
1489                                                         form.submit = TinyMCE_Engine.prototype.submitPatch;\r
1490                                                 } catch (e) {\r
1491                                                         // Do nothing\r
1492                                                 }\r
1493                                         }\r
1494                                 }\r
1495                         }\r
1497                         // Add editor instances based on mode\r
1498                         var mode = tinyMCE.settings['mode'];\r
1499                         switch (mode) {\r
1500                                 case "exact":\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
1508                                                         continue;\r
1510                                                 if (trigger == "false")\r
1511                                                         continue;\r
1513                                                 if ((tinyMCE.settings['ask'] || tinyMCE.settings['convert_on_click']) && element) {\r
1514                                                         elementRefAr[elementRefAr.length] = element;\r
1515                                                         continue;\r
1516                                                 }\r
1518                                                 if (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
1522                                         }\r
1523                                 break;\r
1525                                 case "specific_textareas":\r
1526                                 case "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
1534                                                         continue;\r
1536                                                 if (selector != '')\r
1537                                                         trigger = selector != "" ? "true" : "";\r
1539                                                 if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(elm, "class")))\r
1540                                                         continue;\r
1542                                                 if ((mode == "specific_textareas" && trigger == "true") || (mode == "textareas" && trigger != "false"))\r
1543                                                         elementRefAr[elementRefAr.length] = elm;\r
1544                                         }\r
1545                                 break;\r
1546                         }\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
1562                                         } else {\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
1568                                         }\r
1569                                 } else\r
1570                                         tinyMCE.addMCEControl(element, elementId);\r
1571                         }\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
1579                                 }, 100);\r
1580                         }\r
1582                         tinyMCE.dispatchCallback(null, 'oninit', 'onInit');\r
1583                 }\r
1584         },\r
1586         isInstance : function(o) {\r
1587                 return o != null && typeof(o) == "object" && o.isTinyMCE_Control;\r
1588         },\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
1607                         }\r
1609                         value = outArray;\r
1610                 }\r
1612                 return value;\r
1613         },\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
1621                 if (va) {\r
1622                         for (n in va)\r
1623                                 v = this.replaceVar(v, n, va[n]);\r
1624                 }\r
1626                 return v;\r
1627         },\r
1629         entityDecode : function(s) {\r
1630                 var e = document.createElement("div");\r
1632                 e.innerHTML = s;\r
1634                 return e.firstChild.nodeValue;\r
1635         },\r
1637         addToLang : function(prefix, ar) {\r
1638                 for (var key in ar) {\r
1639                         if (typeof(ar[key]) == 'function')\r
1640                                 continue;\r
1642                         tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = ar[key];\r
1643                 }\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
1649         },\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
1675                         }\r
1677                         tinyMCE.dispatchCallback(inst, 'handle_node_change_callback', 'handleNodeChange', editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content);\r
1678                 }\r
1680                 if (this.selectedInstance && (typeof(focus) == "undefined" || focus))\r
1681                         this.selectedInstance.contentWindow.focus();\r
1682         },\r
1684         _customCleanup : function(inst, type, content) {\r
1685                 var pl, po, i;\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
1704                 }\r
1706                 return content;\r
1707         },\r
1709         setContent : function(h) {\r
1710                 if (tinyMCE.selectedInstance) {\r
1711                         tinyMCE.selectedInstance.execCommand('mceSetContent', false, h);\r
1712                         tinyMCE.selectedInstance.repaint();\r
1713                 }\r
1714         },\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
1721         },\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
1730         },\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
1737                         if (as && as[s])\r
1738                                 return as[s];\r
1740                         if (tinyMCE.settings[s])\r
1741                                 return tinyMCE.settings[s];\r
1743                         if (m == 'themeurl')\r
1744                                 return tinyMCE.themeURL;\r
1746                         return m;\r
1747                 });\r
1748         },\r
1750         replaceVar : function(h, r, v) {\r
1751                 return h.replace(new RegExp('{\\\$' + r + '}', 'g'), v);\r
1752         },\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
1764                         width = 320;\r
1766                 if (!(height = parseInt(template['height'])))\r
1767                         height = 200;\r
1769                 // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!!\r
1770                 if (tinyMCE.isIE)\r
1771                         height += 40;\r
1772                 else\r
1773                         height += 20;\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
1783                 else\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
1789                                 continue;\r
1791                         url = tinyMCE.replaceVar(url, name, escape(args[name]));\r
1792                 }\r
1794                 if (html) {\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
1801                                 return;\r
1802                         }\r
1804                         win.document.write(html);\r
1805                         win.document.close();\r
1806                         win.resizeTo(width, height);\r
1807                         win.focus();\r
1808                 } else {\r
1809                         if ((tinyMCE.isRealIE) && resizable != 'yes' && tinyMCE.settings["dialog_type"] == "modal") {\r
1810                                 height += 10;\r
1812                                 var features = "resizable:" + resizable \r
1813                                         + ";scroll:"\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
1818                         } else {\r
1819                                 var modal = (resizable == "yes") ? "no" : "yes";\r
1821                                 if (tinyMCE.isGecko && tinyMCE.isMac)\r
1822                                         modal = "no";\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
1830                                         return;\r
1831                                 }\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
1842                                 }\r
1844                                 win.focus();\r
1845                         }\r
1846                 }\r
1847         },\r
1849         closeWindow : function(win) {\r
1850                 win.close();\r
1851         },\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
1859                 // Split\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
1864                                 ar[i] = "";\r
1866                         if (ar[i] != "")\r
1867                                 classNames[classNames.length] = ar[i];\r
1868                 }\r
1870                 if (state)\r
1871                         classNames[classNames.length] = aidClass;\r
1873                 // Glue\r
1874                 var className = "";\r
1875                 for (var i=0; i<classNames.length; i++) {\r
1876                         if (i > 0)\r
1877                                 className += " ";\r
1879                         className += classNames[i];\r
1880                 }\r
1882                 return className;\r
1883         },\r
1885         handleVisualAid : function(el, deep, state, inst, skip_dispatch) {\r
1886                 if (!el)\r
1887                         return;\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
1895                         case "TABLE":\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
1911                                         }\r
1912                                 }\r
1914                                 break;\r
1916                         case "A":\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
1925                                 break;\r
1926                 }\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
1931                 }\r
1932         },\r
1934         /*\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
1940                         if (s != "")\r
1941                                 tinyMCE.setAttrib(f[i], 'class', "mceItemFont" + s);\r
1942                 }\r
1944                 if (typeof(size) != "undefined") {\r
1945                         var css = "";\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
1951                                                 break;\r
1952                                         }\r
1953                                 }\r
1955                                 if (css != "")\r
1956                                         break;\r
1957                         }\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
1963                 }\r
1964         },\r
1965         */\r
1967         fixGeckoBaseHREFBug : function(m, e, h) {\r
1968                 var xsrc, xhref;\r
1970                 if (tinyMCE.isGecko) {\r
1971                         if (m == 1) {\r
1972                                 h = h.replace(/\ssrc=/gi, " mce_tsrc=");\r
1973                                 h = h.replace(/\shref=/gi, " mce_thref=");\r
1975                                 return h;\r
1976                         } else {\r
1977                                 // Why bother if there is no src or href broken\r
1978                                 if (!new RegExp('(src|href)=', 'g').test(h))\r
1979                                         return 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
1986                                         if (xsrc != "") {\r
1987                                                 try {\r
1988                                                         n.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xsrc);\r
1989                                                 } catch (e) {\r
1990                                                         // Ignore, Firefox cast exception if local file wasn't found\r
1991                                                 }\r
1993                                                 n.removeAttribute("mce_tsrc");\r
1994                                         }\r
1996                                         if (xhref != "") {\r
1997                                                 try {\r
1998                                                         n.href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xhref);\r
1999                                                 } catch (e) {\r
2000                                                         // Ignore, Firefox cast exception if local file wasn't found\r
2001                                                 }\r
2003                                                 n.removeAttribute("mce_thref");\r
2004                                         }\r
2006                                         return false;\r
2007                                 });\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
2014                                         }\r
2016                                         return false;\r
2017                                 });\r
2018                         }\r
2019                 }\r
2021                 return h;\r
2022         },\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
2031                 try {\r
2032                         tinyMCE.setInnerHTML(doc.body, html_content);\r
2033                 } catch (e) {\r
2034                         if (this.isMSIE)\r
2035                                 doc.body.createTextRange().pasteHTML(html_content);\r
2036                 }\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
2047                                 }\r
2048                         }\r
2050                         // Content duplication bug fix (Seems to be word crap)\r
2051                         var html = doc.body.innerHTML;\r
2052 /*\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
2058                                 }\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>&nbsp;<\/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>&nbsp;<\/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
2069                         }*/\r
2071                         // Always set the htmlText output\r
2072                         tinyMCE.setInnerHTML(doc.body, html);\r
2073                 }\r
2075                 tinyMCE.cleanupAnchors(doc);\r
2077                 if (tinyMCE.getParam("convert_fonts_to_spans"))\r
2078                         tinyMCE.convertSpansToFonts(doc);\r
2079         },\r
2081         getEditorId : function(form_element) {\r
2082                 var inst = this.getInstanceById(form_element);\r
2083                 if (!inst)\r
2084                         return null;\r
2086                 return inst.editorId;\r
2087         },\r
2089         getInstanceById : function(editor_id) {\r
2090                 var inst = this.instances[editor_id];\r
2091                 if (!inst) {\r
2092                         for (var n in tinyMCE.instances) {\r
2093                                 var instance = tinyMCE.instances[n];\r
2094                                 if (!tinyMCE.isInstance(instance))\r
2095                                         continue;\r
2097                                 if (instance.formTargetElementId == editor_id) {\r
2098                                         inst = instance;\r
2099                                         break;\r
2100                                 }\r
2101                         }\r
2102                 }\r
2104                 return inst;\r
2105         },\r
2107         queryInstanceCommandValue : function(editor_id, command) {\r
2108                 var inst = tinyMCE.getInstanceById(editor_id);\r
2109                 if (inst)\r
2110                         return inst.queryCommandValue(command);\r
2112                 return false;\r
2113         },\r
2115         queryInstanceCommandState : function(editor_id, command) {\r
2116                 var inst = tinyMCE.getInstanceById(editor_id);\r
2117                 if (inst)\r
2118                         return inst.queryCommandState(command);\r
2120                 return null;\r
2121         },\r
2123         setWindowArg : function(n, v) {\r
2124                 this.windowArgs[n] = v;\r
2125         },\r
2127         getWindowArg : function(n, d) {\r
2128                 return (typeof(this.windowArgs[n]) == "undefined") ? d : this.windowArgs[n];\r
2129         },\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
2139                         var instance;\r
2141                         for (var instanceName in tinyMCE.instances) {\r
2142                                 instance = tinyMCE.instances[instanceName];\r
2143                                 if (!tinyMCE.isInstance(instance))\r
2144                                         continue;\r
2146                                 break;\r
2147                         }\r
2149                         doc = instance.getDoc();\r
2150                 }\r
2152                 if (typeof(doc) == "undefined") {\r
2153                         var instance = tinyMCE.getInstanceById(editor_id);\r
2154                         doc = instance.getDoc();\r
2155                 }\r
2157                 if (doc) {\r
2158                         var styles = doc.styleSheets;\r
2160                         if (styles && styles.length > 0) {\r
2161                                 for (var x=0; x<styles.length; x++) {\r
2162                                         var csses = null;\r
2164                                         // Just ignore any errors\r
2165                                         eval("try {var csses = tinyMCE.isIE ? doc.styleSheets(" + x + ").rules : styles[" + x + "].cssRules;} catch(e) {}");\r
2166                                         if (!csses)\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
2182                                                                 // Invalid rule\r
2183                                                                 if (rule.indexOf(' ') != -1 || rule.indexOf(':') != -1 || rule.indexOf('mceItem') != -1)\r
2184                                                                         continue;\r
2186                                                                 if (rule.indexOf(tinyMCE.settings['visual_table_class']) != -1 || rule.indexOf('mceEditable') != -1 || rule.indexOf('mceNonEditable') != -1)\r
2187                                                                         continue;\r
2189                                                                 // Is class rule\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
2196                                                                                         addClass = false;\r
2197                                                                         }\r
2199                                                                         if (addClass)\r
2200                                                                                 output[output.length] = cssClass;\r
2201                                                                 }\r
2202                                                         }\r
2203                                                 }\r
2204                                         }\r
2205                                 }\r
2206                         }\r
2207                 }\r
2209                 // Cache em\r
2210                 if (output.length > 0)\r
2211                         tinyMCE.cssClasses = output;\r
2213                 return output;\r
2214         },\r
2216         regexpReplace : function(in_str, reg_exp, replace_str, opts) {\r
2217                 if (in_str == null)\r
2218                         return in_str;\r
2220                 if (typeof(opts) == "undefined")\r
2221                         opts = 'g';\r
2223                 var re = new RegExp(reg_exp, opts);\r
2224                 return in_str.replace(re, replace_str);\r
2225         },\r
2227         trim : function(s) {\r
2228                 return s.replace(/^\s*|\s*$/g, "");\r
2229         },\r
2231         cleanupEventStr : function(s) {\r
2232                 s = "" + 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
2237                 return s;\r
2238         },\r
2240         getControlHTML : function(c) {\r
2241                 var i, l, n, o, v;\r
2243                 l = tinyMCE.plugins;\r
2244                 for (n in l) {\r
2245                         o = l[n];\r
2247                         if (o.getControlHTML && (v = o.getControlHTML(c)) != '')\r
2248                                 return tinyMCE.replaceVar(v, "pluginurl", o.baseURL);\r
2249                 }\r
2251                 o = tinyMCE.themes[tinyMCE.settings['theme']];\r
2252                 if (o.getControlHTML && (v = o.getControlHTML(c)) != '')\r
2253                         return v;\r
2255                 return '';\r
2256         },\r
2258         evalFunc : function(f, idx, a, o) {\r
2259                 var s = '(', i;\r
2261                 for (i=idx; i<a.length; i++) {\r
2262                         s += 'a[' + i + ']';\r
2264                         if (i < a.length-1)\r
2265                                 s += ',';\r
2266                 }\r
2268                 s += ');';\r
2270                 return o ? eval("o." + f + s) : eval("f" + s);\r
2271         },\r
2273         dispatchCallback : function(i, p, n) {\r
2274                 return this.callFunc(i, p, n, 0, this.dispatchCallback.arguments);\r
2275         },\r
2277         executeCallback : function(i, p, n) {\r
2278                 return this.callFunc(i, p, n, 1, this.executeCallback.arguments);\r
2279         },\r
2281         execCommandCallback : function(i, p, n) {\r
2282                 return this.callFunc(i, p, n, 2, this.execCommandCallback.arguments);\r
2283         },\r
2285         callFunc : function(ins, p, n, m, a) {\r
2286                 var l, i, on, o, s, v;\r
2288                 s = m == 2;\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
2293                         return true;\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
2300                                         return true;\r
2301                         }\r
2302                 }\r
2304                 l = tinyMCE.themes;\r
2305                 for (on in l) {\r
2306                         o = l[on];\r
2308                         if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0)\r
2309                                 return true;\r
2310                 }\r
2312                 return false;\r
2313         },\r
2315         xmlEncode : function(s) {\r
2316                 return s ? ('' + s).replace(new RegExp('[<>&"\']', 'g'), function (c, b) {\r
2317                         switch (c) {\r
2318                                 case '&':\r
2319                                         return '&amp;';\r
2321                                 case '"':\r
2322                                         return '&quot;';\r
2324                                 case '\'':\r
2325                                         return '&#39;'; // &apos; is not working in MSIE\r
2327                                 case '<':\r
2328                                         return '&lt;';\r
2330                                 case '>':\r
2331                                         return '&gt;';\r
2332                         }\r
2334                         return c;\r
2335                 }) : s;\r
2336         },\r
2338         extend : function(p, np) {\r
2339                 var o = {};\r
2341                 o.parent = p;\r
2343                 for (n in p)\r
2344                         o[n] = p[n];\r
2346                 for (n in np)\r
2347                         o[n] = np[n];\r
2349                 return o;\r
2350         },\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
2358                 }\r
2360                 if (e) {\r
2361                         tinyMCE.switchClass(e, tinyMCE.lastMenuBtnClass);\r
2362                         tinyMCE.lastSelectedMenuBtn = null;\r
2363                 }\r
2364         }\r
2366         };\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
2392         this.data = {};\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
2406         });\r
2408         // Wrap old theme\r
2409         t = this.settings['theme'];\r
2410         if (!tinyMCE.hasTheme(t)) {\r
2411                 fn = tinyMCE.callbacks;\r
2412                 to = {};\r
2414                 for (i=0; i<fn.length; i++) {\r
2415                         if ((fu = window['TinyMCE_' + t + "_" + fn[i]]))\r
2416                                 to[fn[i]] = fu;\r
2417                 }\r
2419                 tinyMCE.addTheme(t, to);\r
2420         }\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
2427                         pn = p[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
2434                                 to = {};\r
2436                                 for (x=0; x<fn.length; x++) {\r
2437                                         if ((fu = window['TinyMCE_' + pn + "_" + fn[x]]))\r
2438                                                 to[fn[x]] = fu;\r
2439                                 }\r
2441                                 tinyMCE.addPlugin(pn, to);\r
2442                         }\r
2444                         this.plugins[this.plugins.length] = pn; \r
2445                 }\r
2446         }\r
2447 };\r
2449 TinyMCE_Control.prototype = {\r
2450         selection : null,\r
2452         settings : null,\r
2454         cleanup : null,\r
2456         getData : function(na) {\r
2457                 var o = this.data[na];\r
2459                 if (!o)\r
2460                         o = this.data[na] = {};\r
2462                 return o;\r
2463         },\r
2465         hasPlugin : function(n) {\r
2466                 var i;\r
2468                 for (i=0; i<this.plugins.length; i++) {\r
2469                         if (this.plugins[i] == n)\r
2470                                 return true;\r
2471                 }\r
2473                 return false;\r
2474         },\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
2480                 }\r
2481         },\r
2483         repaint : function() {\r
2484                 var s, b, ex;\r
2486                 if (tinyMCE.isRealIE)\r
2487                         return;\r
2489                 try {\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
2497                 } catch (ex) {\r
2498                         // Ignore\r
2499                 }\r
2500         },\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
2506                 }\r
2507         },\r
2509         select : function() {\r
2510                 var oldInst = tinyMCE.selectedInstance;\r
2512                 if (oldInst != this) {\r
2513                         if (oldInst)\r
2514                                 oldInst.execCommand('mceEndTyping');\r
2516                         tinyMCE.dispatchCallback(this, 'select_instance_callback', 'selectInstance', this, oldInst);\r
2517                         tinyMCE.selectedInstance = this;\r
2518                 }\r
2519         },\r
2521         getBody : function() {\r
2522                 return this.contentBody ? this.contentBody : this.getDoc().body;\r
2523         },\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
2528         },\r
2530         getWin : function() {\r
2531                 return this.contentWindow;\r
2532         },\r
2534         getContainerWin : function() {\r
2535                 return this.containerWindow ? this.containerWindow : window;\r
2536         },\r
2538         getViewPort : function() {\r
2539                 return tinyMCE.getViewPort(this.getWin());\r
2540         },\r
2542         getParentNode : function(n, f) {\r
2543                 return tinyMCE.getParentNode(n, f, this.getBody());\r
2544         },\r
2546         getParentElement : function(n, na, f) {\r
2547                 return tinyMCE.getParentElement(n, na, f, this.getBody());\r
2548         },\r
2550         getParentBlockElement : function(n) {\r
2551                 return tinyMCE.getParentBlockElement(n, this.getBody());\r
2552         },\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
2558         },\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
2564                         return false;\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
2571                 sc = {\r
2572                         alt : m.indexOf('alt') != -1,\r
2573                         ctrl : m.indexOf('ctrl') != -1,\r
2574                         shift : m.indexOf('shift') != -1,\r
2575                         charCode : c,\r
2576                         keyCode : n ? k : (ie ? c : null),\r
2577                         desc : d,\r
2578                         cmd : cmd,\r
2579                         ui : ui,\r
2580                         val : va\r
2581                 };\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
2586                                 return false;\r
2587                         }\r
2588                 }\r
2590                 scl[scl.length] = sc;\r
2592                 return true;\r
2593         },\r
2595         handleShortcut : function(e) {\r
2596                 var i, s = this.shortcuts, o;\r
2598                 for (i=0; i<s.length; i++) {\r
2599                         o = s[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
2606                                 return true;\r
2607                         }\r
2608                 }\r
2610                 return false;\r
2611         },\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
2617         },\r
2619         isHidden : function() {\r
2620                 var s;\r
2622                 if (tinyMCE.isIE)\r
2623                         return false;\r
2625                 s = this.getSel();\r
2627                 // Weird, wheres that cursor selection?\r
2628                 return (!s || !s.rangeCount || s.rangeCount == 0);\r
2629         },\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
2634         },\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
2642                         return;\r
2643                 }\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
2652                 if (override) {\r
2653                         for (var n in st) {\r
2654                                 if (typeof(st[n]) == 'function')\r
2655                                         continue;\r
2657                                 stc[n] = st[n];\r
2658                         }\r
2659                 } else {\r
2660                         for (var n in stc) {\r
2661                                 if (typeof(stc[n]) == 'function')\r
2662                                         continue;\r
2664                                 st[n] = stc[n];\r
2665                         }\r
2666                 }\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
2674         },\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
2687         },\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
2696                 // Mozilla issue\r
2697                 if (!tinyMCE.isIE && !this.useCSS) {\r
2698                         this._setUseCSS(false);\r
2699                         this.useCSS = true;\r
2700                 }\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
2706                         return;\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
2717                                         else\r
2718                                                 img.setAttribute('align', 'left');\r
2720                                         // Remove the div\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
2726                                         this.repaint();\r
2727                                         tinyMCE.triggerNodeChange();\r
2728                                         return;\r
2730                                 case "JustifyCenter":\r
2731                                         img.removeAttribute('align');\r
2733                                         // Is centered\r
2734                                         var div = tinyMCE.getParentElement(focusElm, "div");\r
2735                                         if (div && div.style.textAlign == "center") {\r
2736                                                 // Remove div\r
2737                                                 if (div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)\r
2738                                                         div.parentNode.replaceChild(img, div);\r
2739                                         } else {\r
2740                                                 // Add 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
2745                                         }\r
2747                                         this.selection.selectNode(img);\r
2748                                         this.repaint();\r
2749                                         tinyMCE.triggerNodeChange();\r
2750                                         return;\r
2752                                 case "JustifyRight":\r
2753                                         if (align == 'right')\r
2754                                                 img.removeAttribute('align');\r
2755                                         else\r
2756                                                 img.setAttribute('align', 'right');\r
2758                                         // Remove the div\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
2764                                         this.repaint();\r
2765                                         tinyMCE.triggerNodeChange();\r
2766                                         return;\r
2767                         }\r
2768                 }\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
2777                                                         break;\r
2779                                                 case "JustifyCenter":\r
2780                                                         alignValue = "center";\r
2781                                                         break;\r
2783                                                 case "JustifyFull":\r
2784                                                         alignValue = "justify";\r
2785                                                         break;\r
2787                                                 case "JustifyRight":\r
2788                                                         alignValue = "right";\r
2789                                                         break;\r
2790                                 }\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
2801                                         return;\r
2802                                 }\r
2803                         }\r
2804                 }\r
2806                 switch (command) {\r
2807                         case "mceRepaint":\r
2808                                 this.repaint();\r
2809                                 return true;\r
2811                         case "unlink":\r
2812                                 // Unlink if caret is inside link\r
2813                                 if (tinyMCE.isGecko && this.getSel().isCollapsed) {\r
2814                                         focusElm = tinyMCE.getParentElement(focusElm, 'A');\r
2816                                         if (focusElm)\r
2817                                                 this.selection.selectNode(focusElm, false);\r
2818                                 }\r
2820                                 this.getDoc().execCommand(command, user_interface, value);\r
2822                                 tinyMCE.isGecko && this.getSel().collapseToEnd();\r
2824                                 tinyMCE.triggerNodeChange();\r
2826                                 return true;\r
2828                         case "FormatBlock":\r
2829                                 if (!this.cleanup.isValid(value))\r
2830                                         return true;\r
2832                                 this.getDoc().execCommand(command, user_interface, value);\r
2833                                 tinyMCE.triggerNodeChange();\r
2834                                 break;\r
2836                         case "InsertUnorderedList":\r
2837                         case "InsertOrderedList":\r
2838                                 this.getDoc().execCommand(command, user_interface, value);\r
2839                                 tinyMCE.triggerNodeChange();\r
2840                                 break;\r
2842                         case "Strikethrough":\r
2843                                 this.getDoc().execCommand(command, user_interface, value);\r
2844                                 tinyMCE.triggerNodeChange();\r
2845                                 break;\r
2847                         case "mceSelectNode":\r
2848                                 this.selection.selectNode(value);\r
2849                                 tinyMCE.triggerNodeChange();\r
2850                                 tinyMCE.selectedNode = value;\r
2851                                 break;\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
2857                                         if (elm)\r
2858                                                 this.execCommand("mceRemoveNode", false, elm);\r
2859                                 } else {\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
2868                                         } else\r
2869                                                 this.getDoc().execCommand("FormatBlock", false, value);\r
2870                                 }\r
2872                                 tinyMCE.triggerNodeChange();\r
2874                                 break;\r
2876                         case "mceRemoveNode":\r
2877                                 if (!value)\r
2878                                         value = tinyMCE.getParentElement(this.getFocusElement());\r
2880                                 if (tinyMCE.isIE) {\r
2881                                         value.outerHTML = value.innerHTML;\r
2882                                 } else {\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
2888                                 }\r
2890                                 tinyMCE.triggerNodeChange();\r
2892                                 break;\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
2898                                                 break;\r
2900                                         if (parentNode.nodeName.toLowerCase() == "#text") {\r
2901                                                 i--;\r
2902                                                 parentNode = parentNode.parentNode;\r
2903                                                 continue;\r
2904                                         }\r
2906                                         if (i == value) {\r
2907                                                 this.selection.selectNode(parentNode, false);\r
2908                                                 tinyMCE.triggerNodeChange();\r
2909                                                 tinyMCE.selectedNode = parentNode;\r
2910                                                 return;\r
2911                                         }\r
2913                                         parentNode = parentNode.parentNode;\r
2914                                 }\r
2916                                 break;\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
2932                                         // Control range\r
2933                                         if (rng.item)\r
2934                                                 parentElm = rng.item(0);\r
2935                                         else {\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
2942                                                                 parentElm = pelm;\r
2943                                                 }\r
2944                                         }\r
2945                                 } else {\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
2948                                                 parentElm = felm;\r
2949                                 }\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
2962                                         }\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
2968                                                         continue;\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
2979                                                 }\r
2980                                         }\r
2981                                 } else {\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
2989                                                 if (elm) {\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
3001                                                         }\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
3006                                                         }\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
3015                                                                         continue;\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
3026                                                                 }\r
3027                                                         }\r
3028                                                 }\r
3029                                         }\r
3030                                 }\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
3044                                                 continue;\r
3045                                         }\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
3052                                         }\r
3053                                 }\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
3072                                                 }\r
3074                                                 elm.parentNode.removeChild(elm);\r
3075                                         }\r
3076                                 }\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
3084                                 break;\r
3086                         case "FontName":\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
3094                                                 if (f != null)\r
3095                                                         this.selection.selectNode(f, false);\r
3096                                         }\r
3098                                         // Remove format\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
3104                                                 r.collapse(true);\r
3105                                                 s.removeAllRanges();\r
3106                                                 s.addRange(r);\r
3107                                         }\r
3108                                 } else\r
3109                                         this.getDoc().execCommand('FontName', false, value);\r
3111                                 if (tinyMCE.isGecko)\r
3112                                         window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);\r
3114                                 return;\r
3116                         case "FontSize":\r
3117                                 this.getDoc().execCommand('FontSize', false, value);\r
3119                                 if (tinyMCE.isGecko)\r
3120                                         window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);\r
3122                                 return;\r
3124                         case "forecolor":\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
3131                                 break;\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
3143                                 } else\r
3144                                         this.getDoc().execCommand('BackColor', false, value);\r
3145                                 break;\r
3147                         case "Cut":\r
3148                         case "Copy":\r
3149                         case "Paste":\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
3164                                         return;\r
3165                                 } else\r
3166                                         tinyMCE.triggerNodeChange();\r
3167                         break;\r
3169                         case "mceSetContent":\r
3170                                 if (!value)\r
3171                                         value = "";\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
3179                                 else\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
3194                                 return true;\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
3208                                 this.repaint();\r
3209                                 this.selection.moveToBookmark(b);\r
3210                                 tinyMCE.triggerNodeChange();\r
3211                         break;\r
3213                         case "mceReplaceContent":\r
3214                                 // Force empty string\r
3215                                 if (!value)\r
3216                                         value = '';\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
3225                                 } else\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
3231                                 }\r
3233                                 tinyMCE.triggerNodeChange();\r
3234                         break;\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
3241                                         if (targetNode) {\r
3242                                                 targetNode.setAttribute(value['name'], value['value']);\r
3243                                                 tinyMCE.triggerNodeChange();\r
3244                                         }\r
3245                                 }\r
3246                         break;\r
3248                         case "mceSetCSSClass":\r
3249                                 this.execCommand("SetStyleInfo", false, {command : "setattrib", name : "class", value : value});\r
3250                         break;\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
3274                                 break;\r
3276                         case "mceInsertContent":\r
3277                                 // Force empty string\r
3278                                 if (!value)\r
3279                                         value = '';\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
3287                                         try {\r
3288                                                 // Is plain text or HTML, &amp;, &nbsp; etc will be encoded wrong in FF\r
3289                                                 if (value.indexOf('<') == -1 && !value.match(/(&#38;|&#160;|&#60;|&#62;)/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
3298                                                         r.insertNode(n);\r
3300                                                         // Move the cursor to the end of text\r
3301                                                         r2.selectNode(n);\r
3302                                                         r2.collapse(false);\r
3303                                                         s.removeAllRanges();\r
3304                                                         s.addRange(r2);\r
3305                                                 } else {\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
3309                                                 }\r
3310                                         } catch (ex) {\r
3311                                                 insertHTMLFailed = true;\r
3312                                         }\r
3314                                         if (!insertHTMLFailed) {\r
3315                                                 tinyMCE.triggerNodeChange();\r
3316                                                 return;\r
3317                                         }\r
3318                                 }\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
3325                                         if (isHTML) {\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
3333                                                 } else\r
3334                                                         value = rng.createContextualFragment(value);\r
3335                                         } else {\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
3341                                         }\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
3347                                                 return true;\r
3348                                         } else if (tinyMCE.isSafari && isHTML) {\r
3349                                                 rng.deleteContents();\r
3350                                                 rng.insertNode(value);\r
3351                                                 tinyMCE.triggerNodeChange();\r
3352                                                 return true;\r
3353                                         }\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
3361                                         } else\r
3362                                                 rng.insertNode(value);\r
3364                                         if (!isHTML) {\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
3376                                         } else\r
3377                                                 rng.collapse(false);\r
3379                                         tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);\r
3380                                 } else {\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
3385                                         if (c)\r
3386                                                 value = tinyMCE.uniqueTag + value;\r
3388                                         //      tmpRng = rng.duplicate(); // Store away range (Fixes Undo bookmark bug in IE)\r
3390                                         if (rng.item)\r
3391                                                 rng.item(0).outerHTML = value;\r
3392                                         else\r
3393                                                 rng.pasteHTML(value);\r
3395                                         //if (tmpRng)\r
3396                                         //      tmpRng.select(); // Restore range  (Fixes Undo bookmark bug in IE)\r
3398                                         // Remove unique tag\r
3399                                         if (c) {\r
3400                                                 var e = this.getDoc().getElementById('mceTMPElement');\r
3401                                                 e.parentNode.removeChild(e);\r
3402                                         }\r
3403                                 }\r
3405                                 tinyMCE.execCommand("mceAddUndoLevel");\r
3406                                 tinyMCE.triggerNodeChange();\r
3407                         break;\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
3414                                 }\r
3415                                 break;\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
3421                                 }\r
3423                                 tinyMCE.typingUndoIndex = -1;\r
3424                                 break;\r
3426                         case "mceBeginUndoLevel":\r
3427                                 this.undoRedoLevel = false;\r
3428                                 break;\r
3430                         case "mceEndUndoLevel":\r
3431                                 this.undoRedoLevel = true;\r
3432                                 this.execCommand('mceAddUndoLevel');\r
3433                                 break;\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
3439                                 }\r
3440                                 break;\r
3442                         case "Undo":\r
3443                                 if (tinyMCE.settings['custom_undo_redo']) {\r
3444                                         tinyMCE.execCommand("mceEndTyping");\r
3445                                         this.undoRedo.undo();\r
3446                                         tinyMCE.triggerNodeChange();\r
3447                                 } else\r
3448                                         this.getDoc().execCommand(command, user_interface, value);\r
3449                                 break;\r
3451                         case "Redo":\r
3452                                 if (tinyMCE.settings['custom_undo_redo']) {\r
3453                                         tinyMCE.execCommand("mceEndTyping");\r
3454                                         this.undoRedo.redo();\r
3455                                         tinyMCE.triggerNodeChange();\r
3456                                 } else\r
3457                                         this.getDoc().execCommand(command, user_interface, value);\r
3458                                 break;\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
3464                                 break;\r
3466                         case "Indent":\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
3472                                         do {\r
3473                                                 if (n && n.nodeName == "BLOCKQUOTE") {\r
3474                                                         n.removeAttribute("dir");\r
3475                                                         n.removeAttribute("style");\r
3476                                                 }\r
3477                                         } while (n != null && (n = n.parentNode) != null);\r
3478                                 }\r
3479                                 break;\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
3486                                         return;\r
3487                                 }\r
3489                                 if (tinyMCE.isIE) {\r
3490                                         try {\r
3491                                                 var rng = doc.selection.createRange();\r
3492                                                 rng.execCommand("RemoveFormat", false, null);\r
3493                                         } catch (e) {\r
3494                                                 // Do nothing\r
3495                                         }\r
3497                                         this.execCommand("SetStyleInfo", false, {command : "removeformat"});\r
3498                                 } else {\r
3499                                         this.getDoc().execCommand(command, user_interface, value);\r
3501                                         this.execCommand("SetStyleInfo", false, {command : "removeformat"});\r
3502                                 }\r
3504                                 // Remove class\r
3505                                 if (text.length == 0)\r
3506                                         this.execCommand("mceSetCSSClass", false, "");\r
3508                                 tinyMCE.triggerNodeChange();\r
3509                                 break;\r
3511                         default:\r
3512                                 this.getDoc().execCommand(command, user_interface, value);\r
3514                                 if (tinyMCE.isGecko)\r
3515                                         window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);\r
3516                                 else\r
3517                                         tinyMCE.triggerNodeChange();\r
3518                 }\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
3523         },\r
3525         queryCommandValue : function(c) {\r
3526                 try {\r
3527                         return this.getDoc().queryCommandValue(c);\r
3528                 } catch (e) {\r
3529                         return null;\r
3530                 }\r
3531         },\r
3533         queryCommandState : function(c) {\r
3534                 return this.getDoc().queryCommandState(c);\r
3535         },\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
3552                         return false;\r
3553                 }\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
3601                 else\r
3602                         this.settings['width_style'] += 'px';\r
3604                 if (("" + this.settings['height']).indexOf('%') != -1)\r
3605                         this.settings['area_height'] = "100%";\r
3606                 else\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
3613                 }\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
3619                 }\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
3632                 else\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
3639                         // Debug mode\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
3642                         } else {\r
3643                                 hc = '<input type="hidden" id="' + form_element_name + '" name="' + form_element_name + '" />';\r
3644                                 this.oldTargetElement.style.display = "none";\r
3645                         }\r
3647                         html += '</span>';\r
3649                         if (tinyMCE.isGecko)\r
3650                                 html = hc + html;\r
3651                         else\r
3652                                 html += hc;\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
3661                         } else\r
3662                                 replace_element.insertAdjacentHTML("beforeBegin", html);\r
3663                 } else {\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
3679                         } else\r
3680                                 replace_element.insertAdjacentHTML("beforeBegin", html);\r
3681                 }\r
3683                 // Setup iframe\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
3692                         }\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
3700                 } else {\r
3701                         if (tElm && tElm.nodeName == "SPAN")\r
3702                                 tElm = tinyMCE._createIFrame(tElm, targetDoc, targetDoc.parentWindow);\r
3703                         else\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
3713                         } else {\r
3714                                 this.contentDocument = tElm.window.document;\r
3715                                 this.contentWindow = tElm.window;\r
3716                         }\r
3718                         this.getDoc().designMode = "on";\r
3719                 }\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
3726                         try {\r
3727                                 if (!this.isHidden())\r
3728                                         this.getDoc().designMode = "on";\r
3730                                 doc.open();\r
3731                                 doc.write(html);\r
3732                                 doc.close();\r
3733                         } catch (e) {\r
3734                                 // Failed Mozilla 1.3\r
3735                                 this.getDoc().location.href = tinyMCE.baseURL + "/blank.htm";\r
3736                         }\r
3737                 }\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
3741                 if (tinyMCE.isIE)\r
3742                         window.setTimeout("tinyMCE.addEventHandlers(tinyMCE.instances[\"" + this.editorId + "\"]);", 1);\r
3744                 tinyMCE.setupContent(this.editorId, true);\r
3746                 return true;\r
3747         },\r
3749         setBaseHREF : function(u) {\r
3750                 var h, b, d, nl;\r
3752                 d = this.getDoc();\r
3753                 nl = d.getElementsByTagName("base");\r
3754                 b = nl.length > 0 ? nl[0] : null;\r
3756                 if (!b) {\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
3762                         h.appendChild(b);\r
3763                 } else {\r
3764                         if (u == "" || u == null)\r
3765                                 b.parentNode.removeChild(b);\r
3766                         else\r
3767                                 b.setAttribute('href', u);\r
3768                 }\r
3769         },\r
3771         getHTML : function(r) {\r
3772                 var h, d = this.getDoc(), b = this.getBody();\r
3774                 if (r)\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
3782                 return h;\r
3783         },\r
3785         setHTML : function(h) {\r
3786                 this.execCommand('mceSetContent', false, h);\r
3787                 this.repaint();\r
3788         },\r
3790         getFocusElement : function() {\r
3791                 return this.selection.getFocusElement();\r
3792         },\r
3794         getSel : function() {\r
3795                 return this.selection.getSel();\r
3796         },\r
3798         getRng : function() {\r
3799                 return this.selection.getRng();\r
3800         },\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
3812                         do {\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
3816                                 }\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
3821                                 }\r
3822                         } while ((e = e.parentNode) != null)\r
3823                 }\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
3841                 }\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
3852                         htm = content;\r
3854                 // Replace some weird entities (Bug: #1056343)\r
3855                 htm = tinyMCE.regexpReplace(htm, "&#40;", "(", "gi");\r
3856                 htm = tinyMCE.regexpReplace(htm, "&#41;", ")", "gi");\r
3857                 htm = tinyMCE.regexpReplace(htm, "&#59;", ";", "gi");\r
3858                 htm = tinyMCE.regexpReplace(htm, "&#34;", "&quot;", "gi");\r
3859                 htm = tinyMCE.regexpReplace(htm, "&#94;", "^", "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
3871                         else\r
3872                                 nl[i].elm.className = s.hidden_tab_class;\r
3873                 }\r
3874         }\r
3876         };\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>&nbsp;</p>');\r
3882         s = s.replace(new RegExp('<p>\\s*<\\/p>', 'gi'), '<p>&nbsp;</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
3897         if (tinyMCE.isIE)\r
3898                 s = s.replace(new RegExp('<p><hr \\/><\\/p>', 'gi'), "<hr>");\r
3900         // Weird tags will make IE error #bug: 1538495\r
3901         if (tinyMCE.isIE)\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
3909         return s;\r
3910 };\r
3912 TinyMCE_Engine.prototype.parseStyle = function(str) {\r
3913         var ar = new Array();\r
3915         if (str == null)\r
3916                 return ar;\r
3918         var st = str.split(';');\r
3920         tinyMCE.clearArray(ar);\r
3922         for (var i=0; i<st.length; i++) {\r
3923                 if (st[i] == '')\r
3924                         continue;\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
3931         }\r
3933         return ar;\r
3934 };\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
3946                         return;\r
3948                 for (var a=0; a<box.length; a++) {\r
3949                         if (box[a] != box[i])\r
3950                                 return;\r
3951                 }\r
3952         }\r
3954         // They are all the same\r
3955         ar[res] = box[0];\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
3960 };\r
3962 TinyMCE_Engine.prototype.serializeStyle = function(ar) {\r
3963         var str = "";\r
3965         // Compress box\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
3977                         continue;\r
3979                 if (key.indexOf('mso-') == 0)\r
3980                         continue;\r
3982                 if (val != null && val != '') {\r
3983                         val = '' + val; // Force string\r
3985                         // Fix style URL\r
3986                         val = val.replace(new RegExp("url\\(\\'?([^\\']*)\\'?\\)", 'gi'), "url('$1')");\r
3988                         // Convert URL\r
3989                         if (val.indexOf('url(') != -1 && tinyMCE.getParam('convert_urls')) {\r
3990                                 var m = new RegExp("url\\('(.*?)'\\)").exec(val);\r
3992                                 if (m.length > 1)\r
3993                                         val = "url('" + eval(tinyMCE.getParam('urlconverter_callback') + "(m[1], null, true);") + "')";\r
3994                         }\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
4002                 }\r
4003         }\r
4005         if (new RegExp('; $').test(str))\r
4006                 str = str.substring(0, str.length - 2);\r
4008         return str;\r
4009 };\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
4026                         if (k)\r
4027                                 s = rgb[0] + s + rgb[4];\r
4028                 }\r
4029         }\r
4031         return s;\r
4032 };\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
4038         }\r
4040         return s;\r
4041 };\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
4054                 var fSize = 0;\r
4056                 for (var x=0; x<sizes.length; x++) {\r
4057                         if (sizes[x] == size) {\r
4058                                 fSize = x + 1;\r
4059                                 break;\r
4060                         }\r
4061                 }\r
4063                 if (fSize > 0) {\r
4064                         tinyMCE.setAttrib(s[i], 'size', fSize);\r
4065                         s[i].style.fontSize = '';\r
4066                 }\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
4072                 }\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
4078                 }\r
4079         }\r
4080 };\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
4093         else\r
4094                 fsClasses = null;\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
4110                                 else\r
4111                                         s[i].style.fontSize = sizes[fSize-1];\r
4112                         }\r
4114                         s[i].removeAttribute('size');\r
4115                 }\r
4117                 if (fFace != "") {\r
4118                         s[i].style.fontFamily = fFace;\r
4119                         s[i].removeAttribute('face');\r
4120                 }\r
4122                 if (fColor != "") {\r
4123                         s[i].style.color = fColor;\r
4124                         s[i].removeAttribute('color');\r
4125                 }\r
4126         }\r
4127 };\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
4139                 }\r
4140         }\r
4141 };\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
4150         return null;\r
4151 };\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
4160                         n = nl[i];\r
4161                         p = n.parentNode;\r
4163                         if (r.test(p.nodeName)) {\r
4164                                 np = tinyMCE.prevNode(n, 'LI');\r
4166                                 if (!np) {\r
4167                                         np = d.createElement('li');\r
4168                                         np.innerHTML = '&nbsp;';\r
4169                                         np.appendChild(n);\r
4170                                         p.insertBefore(np, p.firstChild);\r
4171                                 } else\r
4172                                         np.appendChild(n);\r
4173                         }\r
4174                 }\r
4175         }\r
4176 };\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
4183                 n = nl[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
4189                         t = n;\r
4191                         while ((n = n.nextSibling))\r
4192                                 np.appendChild(n);\r
4194                         tinyMCE.insertAfter(np, p);\r
4195                         tinyMCE.insertAfter(t, p);\r
4196                 }\r
4197         }\r
4198 };\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
4208         c = inst.cleanup;\r
4209         s = inst.settings;\r
4210         d = c.settings.debug;\r
4212         if (d)\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
4227         if (d)\r
4228                 t2 = new Date().getTime();\r
4230         c.settings.on_save = on_save;\r
4231         //for (var i=0; i<100; i++)\r
4233         c.idCount = 0;\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
4240         else\r
4241                 h = c.serializeNodeAsHTML(elm, inn);\r
4243         if (d)\r
4244                 t3 = new Date().getTime();\r
4246         // Post processing\r
4247         nb = tinyMCE.getParam('entity_encoding') == 'numeric' ? '&#160;' : '&nbsp;';\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>(&nbsp;|&#160;)<\/p><hr \/><p>(&nbsp;|&#160;)<\/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*(&nbsp;|&#160;)\s*<br \/>\s*(&nbsp;|&#160;)\s*<\/p>/g, '<p>' + nb + '</p>');\r
4257         h = h.replace(/<p>\s*(&nbsp;|&#160;)\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>');\r
4258         h = h.replace(/<p>\s*<br \/>\s*&nbsp;\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
4262         // Clean body\r
4263         if (/^\s*(<br \/>|<p>&nbsp;<\/p>|<p>&#160;<\/p>|<p><\/p>)\s*$/.test(h))\r
4264                 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
4271         }\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
4277         }\r
4279         if (s.force_br_newlines)\r
4280                 h = h.replace(/<p>(&nbsp;|&#160;)<\/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
4286         if (on_save) {\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
4289         }\r
4291         if (s.remove_linebreaks && !c.settings.indent)\r
4292                 h = h.replace(/\n|\r/g, ' ');\r
4294         if (d)\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
4304         if (d)\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
4310         return h;\r
4311 };\r
4313 function TinyMCE_Cleanup() {\r
4314         this.isIE = (navigator.appName == "Microsoft Internet Explorer");\r
4315         this.rules = tinyMCE.clearArray(new Array());\r
4317         // Default config\r
4318         this.settings = {\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
4327                 entities : '',\r
4328                 url_converter : '',\r
4329                 invalid_elements : '',\r
4330                 verify_html : false\r
4331         };\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
4340                 src : 'mce_src',\r
4341                 type : 'mce_type'\r
4342         };\r
4345 TinyMCE_Cleanup.prototype = {\r
4346         init : function(s) {\r
4347                 var n, a, i, ir, or, st;\r
4349                 for (n in s)\r
4350                         this.settings[n] = s[n];\r
4352                 // Setup code formating\r
4353                 s = this.settings;\r
4355                 // Setup regexps\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
4365                 else\r
4366                         this.iveRe = null;\r
4368                 // Setup separator\r
4369                 st = '';\r
4370                 for (i=0; i<s.indent_levels; i++)\r
4371                         st += s.indent_char;\r
4373                 this.inStr = st;\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
4379                 }\r
4381                 this.fillStr = s.entity_encoding == "named" ? "&nbsp;" : "&#160;";\r
4382                 this.idCount = 0;\r
4383         },\r
4385         addRuleStr : function(s) {\r
4386                 var r = this.parseRuleStr(s);\r
4387                 var n;\r
4389                 for (n in r) {\r
4390                         if (r[n])\r
4391                                 this.rules[n] = r[n];\r
4392                 }\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
4399                 }\r
4401                 this.vElementsRe = this._arrayToRe(this.vElements, '');\r
4402         },\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
4411         },\r
4413         addChildRemoveRuleStr : function(s) {\r
4414                 var x, y, p, i, t, tn, ta, cl, r;\r
4416                 if (!s)\r
4417                         return;\r
4419                 ta = s.split(',');\r
4420                 for (x=0; x<ta.length; x++) {\r
4421                         s = ta[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
4427                         else\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
4433                                 r = "^(";\r
4435                                 // Build regex\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
4450                                         else\r
4451                                                 r += (cl[i].charAt(0) != '#' ? cl[i].toUpperCase() : cl[i]);\r
4453                                         r += (i != cl.length - 1 ? '|' : '');\r
4454                                 }\r
4456                                 r += ')$';\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
4463                                 if (p.length > 1)\r
4464                                         this.childRules[tn[y]].wrapTag = p[2];\r
4465                         }\r
4466                 }\r
4467         },\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
4473                         return or;\r
4475                 ta = s.split(',');\r
4476                 for (x=0; x<ta.length; x++) {\r
4477                         s = ta[x];\r
4478                         if (s.length == 0)\r
4479                                 continue;\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
4485                         else\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
4491                                 r = {};\r
4493                                 r.tag = tn[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
4514                                                 t = a[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
4521                                                         else\r
4522                                                                 r.reqAttribsRe += '|' + t;\r
4523                                                 }\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
4545                                                         }\r
4546                                                 }\r
4548                                                 r.vAttribsRe += '' + t.toLowerCase() + (i != a.length - 1 ? '|' : '');\r
4550                                                 a[i] = t.toLowerCase();\r
4551                                         }\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
4563                                 } else {\r
4564                                         r.vAttribsRe = '';\r
4565                                         r.vAttribs = tinyMCE.clearArray(new Array());\r
4566                                         r.vAttribsReIsWild = false;\r
4567                                 }\r
4569                                 or[r.tag] = r;\r
4570                         }\r
4571                 }\r
4573                 return or;\r
4574         },\r
4576         serializeNodeAsXML : function(n) {\r
4577                 var s, b;\r
4579                 if (!this.xmlDoc) {\r
4580                         if (this.isIE) {\r
4581                                 try {this.xmlDoc = new ActiveXObject('MSXML2.DOMDocument');} catch (e) {}\r
4583                                 if (!this.xmlDoc)\r
4584                                         try {this.xmlDoc = new ActiveXObject('Microsoft.XmlDom');} catch (e) {}\r
4585                         } else\r
4586                                 this.xmlDoc = document.implementation.createDocument('', '', null);\r
4588                         if (!this.xmlDoc)\r
4589                                 alert("Error XML Parser could not be found.");\r
4590                 }\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
4600                 if (this.isIE)\r
4601                         return this.xmlDoc.xml;\r
4602                 else\r
4603                         return new XMLSerializer().serializeToString(this.xmlDoc);\r
4604         },\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
4610                         return;\r
4612                 xd = this.xmlDoc;\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
4622                                         no = at[i];\r
4624                                         if (no.specified && no.nodeValue)\r
4625                                                 el.setAttribute(no.nodeName.toLowerCase(), no.nodeValue);\r
4626                                 }\r
4628                                 if (!hc && !this.closeElementsRe.test(n.nodeName))\r
4629                                         el.appendChild(xd.createTextNode(""));\r
4631                                 xn = xn.appendChild(el);\r
4632                                 break;\r
4634                         case 3: // Text\r
4635                                 xn.appendChild(xd.createTextNode(n.nodeValue));\r
4636                                 return;\r
4638                         case 8: // Comment\r
4639                                 xn.appendChild(xd.createComment(n.nodeValue));\r
4640                                 return;\r
4641                 }\r
4643                 if (hc) {\r
4644                         cn = n.childNodes;\r
4646                         for (i=0, l=cn.length; i<l; i++)\r
4647                                 this._convertToXML(cn[i], xn);\r
4648                 }\r
4649         },\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
4657                         return '';\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
4664                                 st = true;\r
4665                                 t = null;\r
4666                         }\r
4667                 }\r
4669                 switch (n.nodeType) {\r
4670                         case 1: // Element\r
4671                                 hc = n.hasChildNodes();\r
4673                                 if (st)\r
4674                                         break;\r
4676                                 // MSIE sometimes produces <//tag>\r
4677                                 if ((tinyMCE.isRealIE) && n.nodeName.indexOf('/') != -1)\r
4678                                         break;\r
4680                                 if (this.vElementsRe.test(n.nodeName) && (!this.iveRe || !this.iveRe.test(n.nodeName)) && !inn) {\r
4681                                         va = true;\r
4683                                         r = this.rules[n.nodeName];\r
4684                                         if (!r) {\r
4685                                                 at = this.rules;\r
4686                                                 for (no in at) {\r
4687                                                         if (at[no] && at[no].validRe.test(n.nodeName)) {\r
4688                                                                 r = at[no];\r
4689                                                                 break;\r
4690                                                         }\r
4691                                                 }\r
4692                                         }\r
4694                                         en = r.isWild ? n.nodeName.toLowerCase() : r.oTagName;\r
4695                                         f = r.fill;\r
4697                                         if (r.removeEmpty && !hc)\r
4698                                                 return "";\r
4700                                         t = '<' + en;\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
4706                                                         no = at[i];\r
4707                                                         if (no.specified && r.vAttribsRe.test(no.nodeName))\r
4708                                                                 t += this._serializeAttribute(n, r, no.nodeName);\r
4709                                                 }\r
4710                                         } else {\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
4714                                         }\r
4716                                         // Serialize mce_ atts\r
4717                                         if (!this.settings.on_save) {\r
4718                                                 at = this.mceAttribs;\r
4720                                                 for (no in at) {\r
4721                                                         if (at[no])\r
4722                                                                 t += this._serializeAttribute(n, r, at[no]);\r
4723                                                 }\r
4724                                         }\r
4726                                         // Check for required attribs\r
4727                                         if (r.reqAttribsRe && !t.match(r.reqAttribsRe))\r
4728                                                 t = null;\r
4730                                         // Close these\r
4731                                         if (t != null && this.closeElementsRe.test(n.nodeName))\r
4732                                                 return t + ' />';\r
4734                                         if (t != null)\r
4735                                                 h += t + '>';\r
4737                                         if (this.isIE && this.codeElementsRe.test(n.nodeName))\r
4738                                                 h += n.innerHTML;\r
4739                                 }\r
4740                         break;\r
4742                         case 3: // Text\r
4743                                 if (st)\r
4744                                         break;\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
4752                                 if (st)\r
4753                                         break;\r
4755                                 return "<!--" + this._trimComment(n.nodeValue) + "-->";\r
4756                 }\r
4758                 if (hc) {\r
4759                         cn = n.childNodes;\r
4761                         for (i=0, l=cn.length; i<l; i++)\r
4762                                 h += this.serializeNodeAsHTML(cn[i]);\r
4763                 }\r
4765                 // Fill empty nodes\r
4766                 if (f && !hc)\r
4767                         h += this.fillStr;\r
4769                 // End element\r
4770                 if (t != null && va)\r
4771                         h += '</' + en + '>';\r
4773                 return h;\r
4774         },\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
4780                         return '';\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
4789                         av = t;\r
4791                         if (av == "mce_empty")\r
4792                                 return " " + an + '=""';\r
4793                 }\r
4795                 if (r.forceAttribs && (t = r.forceAttribs[an]))\r
4796                         av = t;\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
4802                         return "";\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
4812                 }\r
4814                 return "";\r
4815         },\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
4824                 });\r
4826                 h = h.replace(/\r/g, ''); // Windows sux, isn't carriage return a thing of the past :)\r
4827                 h = '\n' + h;\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
4832                 h += '\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
4842         \r
4843                                 if (this.inRe.test(l))\r
4844                                         p += this.inStr;\r
4845                         }\r
4847                         li = i;\r
4848                 }\r
4850                 //tinyMCE.debug(h);\r
4852                 return o;\r
4853         },\r
4855         xmlEncode : function(s) {\r
4856                 var cl = this;\r
4858                 this._setupEntities(); // Will intialize lookup table\r
4860                 switch (this.settings.entity_encoding) {\r
4861                         case "raw":\r
4862                                 return tinyMCE.xmlEncode(s);\r
4864                         case "named":\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
4869                                 });\r
4871                         case "numeric":\r
4872                                 return s.replace(new RegExp('[\u007F-\uFFFF<>&"\']', 'g'), function (c, b) {\r
4873                                         return b ? '&#' + c.charCodeAt(0) + ';' : c;\r
4874                                 });\r
4875                 }\r
4877                 return s;\r
4878         },\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
4885                         if (c[i] != '')\r
4886                                 o[i] = c[i];\r
4887                 }\r
4889                 return o;\r
4890         },\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
4897                 return s;\r
4898         },\r
4900         _getAttrib : function(e, n, d) {\r
4901                 if (typeof(d) == "undefined")\r
4902                         d = "";\r
4904                 if (!e || e.nodeType != 1)\r
4905                         return d;\r
4907                 var v = e.getAttribute(n, 0);\r
4909                 if (n == "class" && !v)\r
4910                         v = e.className;\r
4912                 if (this.isIE && n == "http-equiv")\r
4913                         v = e.httpEquiv;\r
4915                 if (this.isIE && e.nodeName == "FORM" && n == "enctype" && v == "application/x-www-form-urlencoded")\r
4916                         v = "";\r
4918                 if (this.isIE && e.nodeName == "INPUT" && n == "size" && v == "20")\r
4919                         v = "";\r
4921                 if (this.isIE && e.nodeName == "INPUT" && n == "maxlength" && v == "2147483647")\r
4922                         v = "";\r
4924                 if (n == "style" && !tinyMCE.isOpera)\r
4925                         v = e.style.cssText;\r
4927                 if (n == 'style')\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
4934         },\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
4942                 return v;\r
4943         },\r
4945         _arrayToRe : function(a, op, be, af) {\r
4946                 var i, r;\r
4948                 op = typeof(op) == "undefined" ? "gi" : op;\r
4949                 be = typeof(be) == "undefined" ? "^(" : be;\r
4950                 af = typeof(af) == "undefined" ? ")$" : af;\r
4952                 r = be;\r
4954                 for (i=0; i<a.length; i++)\r
4955                         r += this._wildcardToRe(a[i]) + (i != a.length-1 ? "|" : "");\r
4957                 r += af;\r
4959                 return new RegExp(r, op);\r
4960         },\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
4967                 return s;\r
4968         },\r
4970         _setupEntities : function() {\r
4971                 var n, a, i, s = this.settings;\r
4973                 // Setup entities\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
4979                                         n[a[i]] = a[i+1];\r
4981                                 this.entities = n;\r
4982                         }\r
4984                         this.entitiesDone = true;\r
4985                 }\r
4986         },\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
4998                 }\r
4999         },\r
5001         _isDuplicate : function(n) {\r
5002                 var i;\r
5004                 if (!this.settings.fix_content_duplication)\r
5005                         return false;\r
5007                 if (tinyMCE.isRealIE && n.nodeType == 1) {\r
5008                         // Mark elements\r
5009                         if (n.mce_serialized == this.serializationId)\r
5010                                 return true;\r
5012                         n.setAttribute('mce_serialized', this.serializationId);\r
5013                 } else {\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
5017                                         return true;\r
5018                         }\r
5020                         this.serializedNodes[this.serializedNodes.length] = n;\r
5021                 }\r
5023                 return false;\r
5024         }\r
5026         };\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
5033         o = '<' + tn;\r
5035         if (a) {\r
5036                 for (n in a) {\r
5037                         if (typeof(a[n]) != 'function' && a[n] != null)\r
5038                                 o += ' ' + f(n) + '="' + f('' + a[n]) + '"';\r
5039                 }\r
5040         }\r
5042         o += !h ? ' />' : '>' + h + '</' + tn + '>';\r
5044         return o;\r
5045 };\r
5047 TinyMCE_Engine.prototype.createTag = function(d, tn, a, h) {\r
5048         var o = d.createElement(tn);\r
5050         if (a) {\r
5051                 for (n in a) {\r
5052                         if (typeof(a[n]) != 'function' && a[n] != null)\r
5053                                 tinyMCE.setAttrib(o, n, a[n]);\r
5054                 }\r
5055         }\r
5057         if (h)\r
5058                 o.innerHTML = h;\r
5060         return o;\r
5061 };\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
5065 };\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
5073         }\r
5075         return o;\r
5076 };\r
5078 TinyMCE_Engine.prototype.isBlockElement = function(n) {\r
5079         return n != null && n.nodeType == 1 && this.blockRegExp.test(n.nodeName);\r
5080 };\r
5082 TinyMCE_Engine.prototype.getParentBlockElement = function(n, r) {\r
5083         return this.getParentNode(n, function(n) {\r
5084                 return tinyMCE.isBlockElement(n);\r
5085         }, r);\r
5087         return null;\r
5088 };\r
5090 TinyMCE_Engine.prototype.insertAfter = function(n, r){\r
5091         if (r.nextSibling)\r
5092                 r.parentNode.insertBefore(n, r.nextSibling);\r
5093         else\r
5094                 r.parentNode.appendChild(n);\r
5095 };\r
5097 TinyMCE_Engine.prototype.setInnerHTML = function(e, h) {\r
5098         var i, nl, n;\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
5107         }\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">&nbsp;</p>'); // Keep empty paragraphs\r
5116                 h = h.replace(/<p([^>]*)>\s*&nbsp;\s*<\/p>/gi, '<p$1 mce_keep="true">&nbsp;</p>'); // Keep empty paragraphs\r
5117                 h = h.replace(/<p([^>]*)>\s+<\/p>/gi, '<p$1 mce_keep="true">&nbsp;</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
5126                         n = nl[i];\r
5128                         if (n.nodeName == 'P' && !n.hasChildNodes() && !n.mce_keep)\r
5129                                 n.parentNode.removeChild(n);\r
5130                 }\r
5131         } else {\r
5132                 h = this.fixGeckoBaseHREFBug(1, e, h);\r
5133                 e.innerHTML = h;\r
5134                 this.fixGeckoBaseHREFBug(2, e, h);\r
5135         }\r
5136 };\r
5138 TinyMCE_Engine.prototype.getOuterHTML = function(e) {\r
5139         if (tinyMCE.isIE)\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
5145 };\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
5151                 e.outerHTML = h;\r
5152         else {\r
5153                 t = d.createElement("body");\r
5154                 t.innerHTML = h;\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
5160         }\r
5161 };\r
5163 TinyMCE_Engine.prototype._getElementById = function(id, d) {\r
5164         var e, i, j, f;\r
5166         if (typeof(d) == "undefined")\r
5167                 d = document;\r
5169         e = d.getElementById(id);\r
5170         if (!e) {\r
5171                 f = d.forms;\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
5177                                         break;\r
5178                                 }\r
5179                         }\r
5180                 }\r
5181         }\r
5183         return e;\r
5184 };\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
5190 };\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
5201         }, r);\r
5202 };\r
5204 TinyMCE_Engine.prototype.getParentNode = function(n, f, r) {\r
5205         while (n) {\r
5206                 if (n == r)\r
5207                         return null;\r
5209                 if (f(n))\r
5210                         return n;\r
5212                 n = n.parentNode;\r
5213         }\r
5215         return null;\r
5216 };\r
5218 TinyMCE_Engine.prototype.getAttrib = function(elm, name, dv) {\r
5219         var v;\r
5221         if (typeof(dv) == "undefined")\r
5222                 dv = "";\r
5224         // Not a element\r
5225         if (!elm || elm.nodeType != 1)\r
5226                 return dv;\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
5236                 v = 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
5240                 v = 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
5249 };\r
5251 TinyMCE_Engine.prototype.setAttrib = function(el, name, va, fix) {\r
5252         if (typeof(va) == "number" && va != null)\r
5253                 va = "" + va;\r
5255         if (fix) {\r
5256                 if (va == null)\r
5257                         va = "";\r
5259                 va = va.replace(/[^0-9%]/g, '');\r
5260         }\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
5270         else\r
5271                 el.removeAttribute(name);\r
5272 };\r
5274 TinyMCE_Engine.prototype.setStyleAttrib = function(e, n, v) {\r
5275         e.style[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
5282         }\r
5283 };\r
5285 TinyMCE_Engine.prototype.switchClass = function(ei, c) {\r
5286         var e;\r
5288         if (tinyMCE.switchClassCache[ei])\r
5289                 e = tinyMCE.switchClassCache[ei];\r
5290         else\r
5291                 e = tinyMCE.switchClassCache[ei] = document.getElementById(ei);\r
5293         if (e) {\r
5294                 // Keep tile mode\r
5295                 if (tinyMCE.settings.button_tile_map && e.className && e.className.indexOf('mceTiledButton') == 0)\r
5296                         c = 'mceTiledButton ' + c;\r
5298                 e.className = c;\r
5299         }\r
5300 };\r
5302 TinyMCE_Engine.prototype.getAbsPosition = function(n, cn) {\r
5303         var l = 0, t = 0;\r
5305         while (n && n != cn) {\r
5306                 l += n.offsetLeft;\r
5307                 t += n.offsetTop;\r
5308                 n = n.offsetParent;\r
5309         }\r
5311         return {absLeft : l, absTop : t};\r
5312 };\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
5320                                 return e;\r
5321                 }\r
5322         }\r
5324         return null;\r
5325 };\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
5333                                 return e;\r
5334                 }\r
5335         }\r
5337         return null;\r
5338 };\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
5347         return a;\r
5348 };\r
5350 TinyMCE_Engine.prototype.selectNodes = function(n, f, a) {\r
5351         var i;\r
5353         if (!a)\r
5354                 a = new Array();\r
5356         if (f(n))\r
5357                 a[a.length] = n;\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
5362         }\r
5364         return a;\r
5365 };\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
5370 };\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
5375 };\r
5377 TinyMCE_Engine.prototype.hasCSSClass = function(n, c) {\r
5378         return new RegExp('\\b' + c + '\\b', 'g').test(n.className);\r
5379 };\r
5381 TinyMCE_Engine.prototype.renameElement = function(e, n, d) {\r
5382         var ne, i, ar;\r
5384         d = typeof(d) == "undefined" ? tinyMCE.selectedInstance.getDoc() : d;\r
5386         if (e) {\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
5393                 }\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
5400         }\r
5401 };\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
5406         return {\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
5411         };\r
5412 };\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
5419         if (url_str) {\r
5420                 var pos, lastPos;\r
5422                 // Parse protocol part\r
5423                 pos = url_str.indexOf('://');\r
5424                 if (pos != -1) {\r
5425                         urlParts['protocol'] = url_str.substring(0, pos);\r
5426                         lastPos = pos + 3;\r
5427                 }\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
5433                         if (chr == ':')\r
5434                                 break;\r
5436                         if (chr == '/')\r
5437                                 break;\r
5438                 }\r
5439                 pos = i;\r
5441                 // Get host\r
5442                 urlParts['host'] = url_str.substring(lastPos, pos);\r
5444                 // Get port\r
5445                 urlParts['port'] = "";\r
5446                 lastPos = pos;\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
5450                 }\r
5452                 // Get path\r
5453                 lastPos = pos;\r
5454                 pos = url_str.indexOf('?', lastPos);\r
5456                 if (pos == -1)\r
5457                         pos = url_str.indexOf('#', lastPos);\r
5459                 if (pos == -1)\r
5460                         pos = url_str.length;\r
5462                 urlParts['path'] = url_str.substring(lastPos, pos);\r
5464                 // Get query\r
5465                 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
5470                 }\r
5472                 // Get anchor\r
5473                 lastPos = 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
5477                 }\r
5478         }\r
5480         return urlParts;\r
5481 };\r
5483 TinyMCE_Engine.prototype.serializeURL = function(up) {\r
5484         var o = "";\r
5486         if (up['protocol'])\r
5487                 o += up['protocol'] + "://";\r
5489         if (up['host'])\r
5490                 o += up['host'];\r
5492         if (up['port'])\r
5493                 o += ":" + up['port'];\r
5495         if (up['path'])\r
5496                 o += up['path'];\r
5498         if (up['query'])\r
5499                 o += "?" + up['query'];\r
5501         if (up['anchor'])\r
5502                 o += "#" + up['anchor'];\r
5504         return o;\r
5505 };\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
5510         var strTok1;\r
5511         var strTok2;\r
5512         var breakPoint = 0;\r
5513         var outPath = "";\r
5514         var forceSlash = false;\r
5516         if (targetURL.path == "")\r
5517                 targetURL.path = "/";\r
5518         else\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
5530                                 break;\r
5531                         }\r
5532                 }\r
5533         }\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
5539                                 break;\r
5540                         }\r
5541                 }\r
5542         }\r
5544         if (breakPoint == 1)\r
5545                 return targetURL.path;\r
5547         for (var i=0; i<(strTok1.length-(breakPoint-1)); i++)\r
5548                 outPath += "../";\r
5550         for (var i=breakPoint-1; i<strTok2.length; i++) {\r
5551                 if (i != (breakPoint-1))\r
5552                         outPath += "/" + strTok2[i];\r
5553                 else\r
5554                         outPath += strTok2[i];\r
5555         }\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
5564         var pos;\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
5578 };\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
5587         // Split parts\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
5595                         continue;\r
5597                 newBaseURLParts[newBaseURLParts.length] = baseURLParts[i];\r
5598         }\r
5599         baseURLParts = newBaseURLParts.reverse();\r
5601         // Merge relURLParts chunks\r
5602         var newRelURLParts = new Array();\r
5603         var numBack = 0;\r
5604         for (var i=relURLParts.length-1; i>=0; i--) {\r
5605                 if (relURLParts[i].length == 0 || relURLParts[i] == ".")\r
5606                         continue;\r
5608                 if (relURLParts[i] == '..') {\r
5609                         numBack++;\r
5610                         continue;\r
5611                 }\r
5613                 if (numBack > 0) {\r
5614                         numBack--;\r
5615                         continue;\r
5616                 }\r
5618                 newRelURLParts[newRelURLParts.length] = relURLParts[i];\r
5619         }\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
5635                 absPath += "/";\r
5637         relURL.path = absPath;\r
5639         return this.serializeURL(relURL);\r
5640 };\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
5649                 return url;\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
5656                 return url;\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
5671                 // Force relative\r
5672                 if (urlParts['host'] == tmpUrlParts['host'] && (urlParts['port'] == tmpUrlParts['port']))\r
5673                         return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings['document_base_url'], curl);\r
5674         }\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
5687         }\r
5689         // Remove current domain\r
5690         if (tinyMCE.getParam('remove_script_host')) {\r
5691                 var start = "", portPart = "";\r
5693                 if (port != "")\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
5700         }\r
5702         return url;\r
5703 };\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
5714                 if (msrc != "")\r
5715                         src = msrc;\r
5717                 if (src != "") {\r
5718                         src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);\r
5719                         elms[i].setAttribute("src", src);\r
5720                 }\r
5721         }\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
5729                 if (mhref != "")\r
5730                         href = mhref;\r
5732                 if (href && href != "") {\r
5733                         href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], href);\r
5734                         elms[i].setAttribute("href", href);\r
5735                 }\r
5736         }\r
5737 };\r
5739 /* file:jscripts/tiny_mce/classes/TinyMCE_Array.class.js */\r
5741 TinyMCE_Engine.prototype.clearArray = function(a) {\r
5742         var n;\r
5744         for (n in a)\r
5745                 a[n] = null;\r
5747         return a;\r
5748 };\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
5754                 if (ar[i] != "")\r
5755                         oar[oar.length] = ar[i];\r
5756         }\r
5758         return oar;\r
5759 };\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
5773                         event = "";\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
5779                                         if (!state)\r
5780                                                 event = "return true;" + event;\r
5781                                         else\r
5782                                                 event = event.replace(/^return true;/gi, '');\r
5784                                         elms[i].removeAttribute(events[x]);\r
5785                                         elms[i].setAttribute(events[x], event);\r
5786                                 }\r
5787                         }\r
5788                 }\r
5789         }\r
5790 };\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
5797                 return true;\r
5799         try {\r
5800                 // Try selected instance first\r
5801                 if (tinyMCE.selectedInstance) {\r
5802                         win = tinyMCE.selectedInstance.getWin();\r
5804                         if (win && win.event) {\r
5805                                 e = win.event;\r
5807                                 if (!e.target)\r
5808                                         e.target = e.srcElement;\r
5810                                 TinyMCE_Engine.prototype.handleEvent(e);\r
5811                                 return;\r
5812                         }\r
5813                 }\r
5815                 // Search for it\r
5816                 for (n in tinyMCE.instances) {\r
5817                         inst = tinyMCE.instances[n];\r
5819                         if (!tinyMCE.isInstance(inst))\r
5820                                 continue;\r
5822                         inst.select();\r
5823                         win = inst.getWin();\r
5825                         if (win && win.event) {\r
5826                                 e = win.event;\r
5828                                 if (!e.target)\r
5829                                         e.target = e.srcElement;\r
5831                                 TinyMCE_Engine.prototype.handleEvent(e);\r
5832                                 return;\r
5833                         }\r
5834                 }\r
5835         } catch (ex) {\r
5836                 // Ignore error if iframe is pointing to external URL\r
5837         }\r
5838 };\r
5840 TinyMCE_Engine.prototype.findEvent = function(e) {\r
5841         var n, inst;\r
5843         if (e)\r
5844                 return 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
5851         }\r
5853         return null;\r
5854 };\r
5856 TinyMCE_Engine.prototype.unloadHandler = function() {\r
5857         tinyMCE.triggerSave(true, true);\r
5858 };\r
5860 TinyMCE_Engine.prototype.addEventHandlers = function(inst) {\r
5861         this.setEventHandlers(inst, 1);\r
5862 };\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
5875         } else {\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
5880         }\r
5881 };\r
5883 TinyMCE_Engine.prototype.onMouseMove = function() {\r
5884         var inst, lh;\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
5893                 else\r
5894                         lh.className = lh.className;\r
5896                 tinyMCE.lastHover = null;\r
5897         }\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
5906                 }\r
5907         }\r
5909 //      tinyMCE.cancelEvent(inst.getWin().event);\r
5910 //      return false;\r
5911 };\r
5913 TinyMCE_Engine.prototype.cancelEvent = function(e) {\r
5914         if (!e)\r
5915                 return false;\r
5917         if (tinyMCE.isIE) {\r
5918                 e.returnValue = false;\r
5919                 e.cancelBubble = true;\r
5920         } else {\r
5921                 e.preventDefault();\r
5922                 e.stopPropagation && e.stopPropagation();\r
5923         }\r
5925         return false;\r
5926 };\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
5932                         var ex;\r
5934                         try {\r
5935                                 tinyMCE.removeEvent(o, n, h);\r
5936                                 tinyMCE.removeEvent(window, 'unload', clean);\r
5937                                 o = n = h = null;\r
5938                         } catch (ex) {\r
5939                                 // IE may produce access denied exception on unload\r
5940                         }\r
5941                 }\r
5943                 // Add memory cleaner\r
5944                 tinyMCE.addEvent(window, 'unload', clean);\r
5945         }\r
5947         if (o.attachEvent)\r
5948                 o.attachEvent("on" + n, h);\r
5949         else\r
5950                 o.addEventListener(n, h, false);\r
5951 };\r
5953 TinyMCE_Engine.prototype.removeEvent = function(o, n, h) {\r
5954         if (o.detachEvent)\r
5955                 o.detachEvent("on" + n, h);\r
5956         else\r
5957                 o.removeEventListener(n, h, false);\r
5958 };\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
5966                 s._win = w;\r
5967         }\r
5969         return false;\r
5970 };\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
5982                 }\r
5984                 return true;\r
5985         }\r
5987         // Piggyback onchange\r
5988         if (elm.nodeName == "SELECT" && !elm.oldonchange) {\r
5989                 elm.oldonchange = elm.onchange;\r
5990                 elm.onchange = null;\r
5991         }\r
5993         // Execute onchange and remove piggyback\r
5994         if (e.keyCode == 13 || e.keyCode == 32) {\r
5995                 elm.onchange = elm.oldonchange;\r
5996                 elm.onchange();\r
5997                 elm.oldonchange = null;\r
5999                 tinyMCE.cancelEvent(e);\r
6000                 return false;\r
6001         }\r
6003         return true;\r
6004 };\r
6006 TinyMCE_Engine.prototype._resetIframeHeight = function() {\r
6007         var ife;\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
6015                 }*/\r
6017                 if (ife._oldHeight) {\r
6018                         ife.style.height = ife._oldHeight;\r
6019                         ife.height = ife._oldHeight;\r
6020                 }\r
6021         }\r
6022 };\r
6024 /* file:jscripts/tiny_mce/classes/TinyMCE_Selection.class.js */\r
6026 function TinyMCE_Selection(inst) {\r
6027         this.instance = inst;\r
6028 };\r
6030 TinyMCE_Selection.prototype = {\r
6031         getSelectedHTML : function() {\r
6032                 var inst = this.instance;\r
6033                 var e, r = this.getRng(), h;\r
6035                 if (!r)\r
6036                         return null;\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
6044                 else\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
6053                 return h;\r
6054         },\r
6056         getSelectedText : function() {\r
6057                 var inst = this.instance;\r
6058                 var d, r, s, t;\r
6060                 if (tinyMCE.isIE) {\r
6061                         d = inst.getDoc();\r
6063                         if (d.selection.type == "Text") {\r
6064                                 r = d.selection.createRange();\r
6065                                 t = r.text;\r
6066                         } else\r
6067                                 t = '';\r
6068                 } else {\r
6069                         s = this.getSel();\r
6071                         if (s && s.toString)\r
6072                                 t = s.toString();\r
6073                         else\r
6074                                 t = '';\r
6075                 }\r
6077                 return t;\r
6078         },\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
6087                 sx = vp.left;\r
6088                 sy = vp.top;\r
6090                 if (tinyMCE.isSafari || tinyMCE.isOpera || simple)\r
6091                         return {rng : rng, scrollX : sx, scrollY : sy};\r
6093                 if (tinyMCE.isIE) {\r
6094                         if (rng.item) {\r
6095                                 e = rng.item(0);\r
6097                                 nl = b.getElementsByTagName(e.nodeName);\r
6098                                 for (i=0; i<nl.length; i++) {\r
6099                                         if (e == nl[i]) {\r
6100                                                 sp = i;\r
6101                                                 break;\r
6102                                         }\r
6103                                 }\r
6105                                 return {\r
6106                                         tag : e.nodeName,\r
6107                                         index : sp,\r
6108                                         scrollX : sx,\r
6109                                         scrollY : sy\r
6110                                 };\r
6111                         } else {\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
6125                                 return {\r
6126                                         start : sp - bp,\r
6127                                         length : le,\r
6128                                         scrollX : sx,\r
6129                                         scrollY : sy\r
6130                                 };\r
6131                         }\r
6132                 }\r
6134                 if (tinyMCE.isGecko) {\r
6135                         s = this.getSel();\r
6136                         e = this.getFocusElement();\r
6138                         if (!s)\r
6139                                 return null;\r
6141                         if (e && e.nodeName == 'IMG') {\r
6142                                 /*nl = b.getElementsByTagName('IMG');\r
6143                                 for (i=0; i<nl.length; i++) {\r
6144                                         if (e == nl[i]) {\r
6145                                                 sp = i;\r
6146                                                 break;\r
6147                                         }\r
6148                                 }*/\r
6150                                 return {\r
6151                                         start : -1,\r
6152                                         end : -1,\r
6153                                         index : sp,\r
6154                                         scrollX : sx,\r
6155                                         scrollY : sy\r
6156                                 };\r
6157                         }\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
6163                                 if (!e)\r
6164                                         return {scrollX : sx, scrollY : sy};\r
6166                                 return {\r
6167                                         start : e.start + s.anchorOffset,\r
6168                                         end : e.end + s.focusOffset,\r
6169                                         scrollX : sx,\r
6170                                         scrollY : sy\r
6171                                 };\r
6172                         } else {\r
6173                                 e = this._getPosText(b, rng.startContainer, rng.endContainer);\r
6175                                 if (!e)\r
6176                                         return {scrollX : sx, scrollY : sy};\r
6178                                 return {\r
6179                                         start : e.start + rng.startOffset,\r
6180                                         end : e.end + rng.endOffset,\r
6181                                         scrollX : sx,\r
6182                                         scrollY : sy\r
6183                                 };\r
6184                         }\r
6185                 }\r
6187                 return null;\r
6188         },\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
6197                 if (!bookmark)\r
6198                         return false;\r
6200                 if (tinyMCE.isSafari) {\r
6201                         sel.setBaseAndExtent(bookmark.rng.startContainer, bookmark.rng.startOffset, bookmark.rng.endContainer, bookmark.rng.endOffset);\r
6202                         return true;\r
6203                 }\r
6205                 if (tinyMCE.isRealIE) {\r
6206                         if (bookmark.rng) {\r
6207                                 try {\r
6208                                         bookmark.rng.select();\r
6209                                 } catch (ex) {\r
6210                                         // Ignore\r
6211                                 }\r
6213                                 return true;\r
6214                         }\r
6216                         win.focus();\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
6224                                         try {\r
6225                                                 rng.addElement(nl[bookmark.index]);\r
6226                                         } catch (ex) {\r
6227                                                 // Might be thrown if the node no longer exists\r
6228                                         }\r
6229                                 }\r
6230                         } else {\r
6231                                 // Try/catch needed since this operation breaks when TinyMCE is placed in hidden divs/tabs\r
6232                                 try {\r
6233                                         // Incorrect bookmark\r
6234                                         if (bookmark.start < 0)\r
6235                                                 return true;\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
6242                                 } catch (ex) {\r
6243                                         return true;\r
6244                                 }\r
6245                         }\r
6247                         rng.select();\r
6249                         win.scrollTo(bookmark.scrollX, bookmark.scrollY);\r
6250                         return true;\r
6251                 }\r
6253                 if (tinyMCE.isGecko || tinyMCE.isOpera) {\r
6254                         if (bookmark.rng) {\r
6255                                 sel.removeAllRanges();\r
6256                                 sel.addRange(bookmark.rng);\r
6257                         }\r
6259                         if (bookmark.start != -1 && bookmark.end != -1) {\r
6260                                 try {\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
6267                                         win.focus();\r
6268                                 } catch (ex) {\r
6269                                         // Ignore\r
6270                                 }\r
6271                         }\r
6273                         /*\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
6278                                         }\r
6280                                         return false;\r
6281                                 });\r
6282                         }\r
6283                         */\r
6285                         win.scrollTo(bookmark.scrollX, bookmark.scrollY);\r
6286                         return true;\r
6287                 }\r
6289                 return false;\r
6290         },\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
6296                         if (n == sn)\r
6297                                 d.start = p;\r
6299                         if (n == en) {\r
6300                                 d.end = p;\r
6301                                 return d;\r
6302                         }\r
6304                         p += n.nodeValue ? n.nodeValue.length : 0;\r
6305                 }\r
6307                 return null;\r
6308         },\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
6317                                 d.startNode = n;\r
6318                                 d.startOffset = sp - (p - n.nodeValue.length);\r
6319                         }\r
6321                         if (p >= ep) {\r
6322                                 d.endNode = n;\r
6323                                 d.endOffset = ep - (p - n.nodeValue.length);\r
6325                                 return d;\r
6326                         }\r
6327                 }\r
6329                 return null;\r
6330         },\r
6332         selectNode : function(node, collapse, select_text_node, to_start) {\r
6333                 var inst = this.instance, sel, rng, nodes;\r
6335                 if (!node)\r
6336                         return;\r
6338                 if (typeof(collapse) == "undefined")\r
6339                         collapse = true;\r
6341                 if (typeof(select_text_node) == "undefined")\r
6342                         select_text_node = false;\r
6344                 if (typeof(to_start) == "undefined")\r
6345                         to_start = true;\r
6347                 if (inst.settings.auto_resize)\r
6348                         inst.resizeToContent();\r
6350                 if (tinyMCE.isRealIE) {\r
6351                         rng = inst.getDoc().body.createTextRange();\r
6353                         try {\r
6354                                 rng.moveToElementText(node);\r
6356                                 if (collapse)\r
6357                                         rng.collapse(to_start);\r
6359                                 rng.select();\r
6360                         } catch (e) {\r
6361                                 // Throws illigal agrument in MSIE some times\r
6362                         }\r
6363                 } else {\r
6364                         sel = this.getSel();\r
6366                         if (!sel)\r
6367                                 return;\r
6369                         if (tinyMCE.isSafari) {\r
6370                                 sel.setBaseAndExtent(node, 0, node, node.innerText.length);\r
6372                                 if (collapse) {\r
6373                                         if (to_start)\r
6374                                                 sel.collapseToStart();\r
6375                                         else\r
6376                                                 sel.collapseToEnd();\r
6377                                 }\r
6379                                 this.scrollToNode(node);\r
6381                                 return;\r
6382                         }\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
6391                                 else\r
6392                                         rng.selectNodeContents(node);\r
6393                         } else\r
6394                                 rng.selectNode(node);\r
6396                         if (collapse) {\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
6401                                 } else\r
6402                                         rng.collapse(to_start);\r
6403                         }\r
6405                         sel.removeAllRanges();\r
6406                         sel.addRange(rng);\r
6407                 }\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
6415         },\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
6432                 }\r
6433         },\r
6435         getAbsPosition : function(n) {\r
6436                 var pos = tinyMCE.getAbsPosition(n), ipos = tinyMCE.getAbsPosition(this.instance.iframeElement);\r
6438                 return {\r
6439                         absLeft : ipos.absLeft + pos.absLeft,\r
6440                         absTop : ipos.absTop + pos.absTop\r
6441                 };\r
6442         },\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
6451         },\r
6453         getRng : function() {\r
6454                 var s = this.getSel();\r
6456                 if (s == null)\r
6457                         return null;\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
6466         },\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
6479                 } else {\r
6480                         if (!tinyMCE.isSafari && inst.isHidden())\r
6481                                 return inst.getBody();\r
6483                         sel = this.getSel();\r
6484                         rng = this.getRng();\r
6486                         if (!sel || !rng)\r
6487                                 return null;\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
6499                                         }\r
6500                                 }\r
6501                         }\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
6508                 }\r
6510                 return elm;\r
6511         }\r
6513         };\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
6523 };\r
6525 TinyMCE_UndoRedo.prototype = {\r
6526         add : function(l) {\r
6527                 var b, customUndoLevels, newHTML, inst = this.instance, i, ul, ur;\r
6529                 if (l) {\r
6530                         this.undoLevels[this.undoLevels.length] = l;\r
6531                         return true;\r
6532                 }\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
6539                 }\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
6554                                 this.undoIndex--;\r
6556                                 // Todo: Implement global undo/redo logic here\r
6557                         }\r
6559                         b = inst.undoBookmark;\r
6561                         if (!b)\r
6562                                 b = inst.selection.getBookmark();\r
6564                         this.undoIndex++;\r
6565                         this.undoLevels[this.undoIndex] = {\r
6566                                 content : newHTML,\r
6567                                 bookmark : b\r
6568                         };\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
6576                                         ur.undoIndex--;\r
6578                                 ur.undoLevels.length--;\r
6579                         }\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
6587                         return true;\r
6588                 }\r
6590                 return false;\r
6591         },\r
6593         undo : function() {\r
6594                 var inst = this.instance;\r
6596                 // Do undo\r
6597                 if (this.undoIndex > 0) {\r
6598                         this.undoIndex--;\r
6600                         tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);\r
6601                         inst.repaint();\r
6603                         if (inst.settings.custom_undo_redo_restore_selection)\r
6604                                 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);\r
6605                 }\r
6606         },\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
6614                         this.undoIndex++;\r
6616                         tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);\r
6617                         inst.repaint();\r
6619                         if (inst.settings.custom_undo_redo_restore_selection)\r
6620                                 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);\r
6621                 }\r
6623                 tinyMCE.triggerNodeChange();\r
6624         }\r
6626         };\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
6640                         }\r
6642                         // Check for images\r
6643                         if (para.getElementsByTagName("img").length > 0)\r
6644                                 return false;\r
6646                         // Check for tables\r
6647                         if (para.getElementsByTagName("table").length > 0)\r
6648                                 return false;\r
6650                         // Check for HRs\r
6651                         if (para.getElementsByTagName("hr").length > 0)\r
6652                                 return false;\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
6658                                         return false;\r
6659                         }\r
6661                         // No images, no tables, no hrs, no text content then it's empty\r
6662                         return true;\r
6663                 }\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
6698                         endBlock = null;\r
6700                 // Use current block name\r
6701                 if (startBlock != null) {\r
6702                         blockName = startBlock.nodeName;\r
6704                         // Use P instead\r
6705                         if (blockName == "TD" || blockName == "TABLE" || (blockName == "DIV" && new RegExp('left|right', 'gi').test(startBlock.style.cssFloat)))\r
6706                                 blockName = "P";\r
6707                 }\r
6709                 // Within a list use normal behaviour\r
6710                 if (tinyMCE.getParentElement(startBlock, "OL,UL", null, body) != null)\r
6711                         return false;\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
6730                 node = startChop;\r
6731                 do {\r
6732                         if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))\r
6733                                 break;\r
6735                         startChop = node;\r
6736                 } while ((node = node.previousSibling ? node.previousSibling : node.parentNode));\r
6738                 // Get endChop node\r
6739                 node = endChop;\r
6740                 do {\r
6741                         if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))\r
6742                                 break;\r
6744                         endChop = 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
6768                                 else\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
6787                                 else\r
6788                                         paraAfter.appendChild(contents);\r
6790                                 // Check if it's a empty paragraph\r
6791                                 if (isEmpty(paraBefore))\r
6792                                         paraBefore.innerHTML = "&nbsp;";\r
6794                                 // Check if it's a empty paragraph\r
6795                                 if (isEmpty(paraAfter))\r
6796                                         paraAfter.innerHTML = "&nbsp;";\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
6809                                 } else {\r
6810                                         paraAfter.normalize();\r
6811                                         rngBefore.insertNode(paraAfter);\r
6812                                         paraBefore.normalize();\r
6813                                         rngBefore.insertNode(paraBefore);\r
6814                                 }\r
6816                                 //tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML);\r
6817                         } else {\r
6818                                 body.innerHTML = "<" + blockName + ">&nbsp;</" + blockName + "><" + blockName + ">&nbsp;</" + blockName + ">";\r
6819                                 paraAfter = body.childNodes[1];\r
6820                         }\r
6822                         inst.selection.moveToBookmark(b);\r
6823                         inst.selection.selectNode(paraAfter, true, true);\r
6825                         return true;\r
6826                 }\r
6828                 // Place first part within new paragraph\r
6829                 if (startChop.nodeName == blockName)\r
6830                         rngBefore.setStart(startChop, 0);\r
6831                 else\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
6848                         }\r
6849         */\r
6850                         paraAfter.innerHTML = contents.firstChild.innerHTML;\r
6851                 } else\r
6852                         paraAfter.appendChild(contents);\r
6854                 // Check if it's a empty paragraph\r
6855                 if (isEmpty(paraBefore))\r
6856                         paraBefore.innerHTML = "&nbsp;";\r
6858                 // Check if it's a empty paragraph\r
6859                 if (isEmpty(paraAfter))\r
6860                         paraAfter.innerHTML = "&nbsp;";\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
6867                 } else {\r
6868                         if (rngBefore.startContainer.nodeName.toUpperCase() == blockName && rngBefore.startOffset == 0)\r
6869                                 rng.setStartBefore(rngBefore.startContainer);\r
6870                         else\r
6871                                 rng.setStart(rngBefore.startContainer, rngBefore.startOffset);\r
6872                 }\r
6874                 if (!endChop.nextSibling && endChop.parentNode.nodeName.toUpperCase() == blockName)\r
6875                         rng.setEndAfter(endChop.parentNode);\r
6876                 else\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
6885                 } else {\r
6886                         rng.insertNode(paraAfter);\r
6887                         rng.insertNode(paraBefore);\r
6888                 }\r
6890                 //tinyMCE.debug("2", paraBefore.innerHTML, paraAfter.innerHTML);\r
6892                 // Normalize\r
6893                 paraAfter.normalize();\r
6894                 paraBefore.normalize();\r
6896                 inst.selection.moveToBookmark(b);\r
6897                 inst.selection.selectNode(paraAfter, true, true);\r
6899                 return true;\r
6900         },\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
6911                                 s = true;*/\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
6916                 }\r
6918                 if (inst.settings.auto_resize)\r
6919                         inst.resizeToContent();\r
6921                 return s;\r
6922         }\r
6924         };\r
6926 /* file:jscripts/tiny_mce/classes/TinyMCE_Layer.class.js */\r
6928 function TinyMCE_Layer(id, bm) {\r
6929         this.id = id;\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
6935 };\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
6945                 var x, y;\r
6947                 switch (p) {\r
6948                         case "tl":\r
6949                                 x = rep.absLeft;\r
6950                                 y = rep.absTop;\r
6951                                 break;\r
6953                         case "tr":\r
6954                                 x = rep.absLeft + w;\r
6955                                 y = rep.absTop;\r
6956                                 break;\r
6958                         case "bl":\r
6959                                 x = rep.absLeft;\r
6960                                 y = rep.absTop + h;\r
6961                                 break;\r
6963                         case "br":\r
6964                                 x = rep.absLeft + w;\r
6965                                 y = rep.absTop + h;\r
6966                                 break;\r
6968                         case "cc":\r
6969                                 x = rep.absLeft + (w / 2) - (ew / 2);\r
6970                                 y = rep.absTop + (h / 2) - (eh / 2);\r
6971                                 break;\r
6972                 }\r
6974                 this.moveTo(x, y);\r
6975         },\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
6980         },\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
6989         },\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
6994         },\r
6996         resizeTo : function(w, h) {\r
6997                 var e = this.getElement();\r
6999                 if (w != null)\r
7000                         e.style.width = w + "px";\r
7002                 if (h != null)\r
7003                         e.style.height = h + "px";\r
7005                 this.updateBlocker();\r
7006         },\r
7008         show : function() {\r
7009                 this.getElement().style.display = 'block';\r
7010                 this.updateBlocker();\r
7011         },\r
7013         hide : function() {\r
7014                 this.getElement().style.display = 'none';\r
7015                 this.updateBlocker();\r
7016         },\r
7018         isVisible : function() {\r
7019                 return this.getElement().style.display == 'block';\r
7020         },\r
7022         getElement : function() {\r
7023                 if (!this.element)\r
7024                         this.element = this.doc.getElementById(this.id);\r
7026                 return this.element;\r
7027         },\r
7029         setBlockMode : function(s) {\r
7030                 this.blockMode = s;\r
7031         },\r
7033         updateBlocker : function() {\r
7034                 var e, b, x, y, w, h;\r
7036                 b = this.getBlocker();\r
7037                 if (b) {\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
7050                         } else\r
7051                                 b.style.display = 'none';\r
7052                 }\r
7053         },\r
7055         getBlocker : function() {\r
7056                 var d, b;\r
7058                 if (!this.blockerElement && this.blockMode) {\r
7059                         d = this.doc;\r
7060                         b = d.getElementById(this.id + "_blocker");\r
7062                         if (!b) {\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
7070         \r
7071                                 d.body.appendChild(b);\r
7072                         }\r
7074                         this.blockerElement = b;\r
7075                 }\r
7077                 return this.blockerElement;\r
7078         },\r
7080         getAbsPosition : function(n) {\r
7081                 var p = {absLeft : 0, absTop : 0};\r
7083                 while (n) {\r
7084                         p.absLeft += n.offsetLeft;\r
7085                         p.absTop += n.offsetTop;\r
7086                         n = n.offsetParent;\r
7087                 }\r
7089                 return p;\r
7090         },\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
7097                 if (c)\r
7098                         e.className = c;\r
7100                 if (!p)\r
7101                         p = d.body;\r
7103                 if (h)\r
7104                         e.innerHTML = h;\r
7106                 p.appendChild(e);\r
7108                 return this.element = e;\r
7109         },\r
7111         exists : function() {\r
7112                 return this.doc.getElementById(this.id) != null;\r
7113         },\r
7115         parseInt : function(s) {\r
7116                 if (s == null || s == '')\r
7117                         return 0;\r
7119                 return parseInt(s);\r
7120         }\r
7122         };\r
7124 /* file:jscripts/tiny_mce/classes/TinyMCE_Menu.class.js */\r
7126 function TinyMCE_Menu() {\r
7127         var id;\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
7136         this.id = id;\r
7137         this.items = new Array();\r
7138         this.needsUpdate = true;\r
7139 };\r
7141 TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, {\r
7142         init : function(s) {\r
7143                 var n;\r
7145                 // Default params\r
7146                 this.settings = {\r
7147                         separator_class : 'mceMenuSeparator',\r
7148                         title_class : 'mceMenuTitle',\r
7149                         disabled_class : 'mceMenuDisabled',\r
7150                         menu_class : 'mceMenu',\r
7151                         drop_menu : true\r
7152                 };\r
7154                 for (n in s)\r
7155                         this.settings[n] = s[n];\r
7157                 this.create('div', this.settings.menu_class);\r
7158         },\r
7160         clear : function() {\r
7161                 this.items = new Array();\r
7162         },\r
7164         addTitle : function(t) {\r
7165                 this.add({type : 'title', text : t});\r
7166         },\r
7168         addDisabled : function(t) {\r
7169                 this.add({type : 'disabled', text : t});\r
7170         },\r
7172         addSeparator : function() {\r
7173                 this.add({type : 'separator'});\r
7174         },\r
7176         addItem : function(t, js) {\r
7177                 this.add({text : t, js : js});\r
7178         },\r
7180         add : function(mi) {\r
7181                 this.items[this.items.length] = mi;\r
7182                 this.needsUpdate = true;\r
7183         },\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
7198                                 case 'separator':\r
7199                                         h += '<tr class="' + s.separator_class + '"><td>';\r
7200                                         break;\r
7202                                 case 'title':\r
7203                                         h += '<tr class="' + s.title_class + '"><td><span' + c +'>' + t + '</span>';\r
7204                                         break;\r
7206                                 case 'disabled':\r
7207                                         h += '<tr class="' + s.disabled_class + '"><td><span' + c +'>' + t + '</span>';\r
7208                                         break;\r
7210                                 default:\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
7212                         }\r
7214                         h += '</td></tr>';\r
7215                 }\r
7217                 h += '</table>';\r
7219                 e.innerHTML = h;\r
7221                 this.needsUpdate = false;\r
7222                 this.updateBlocker();\r
7223         },\r
7225         show : function() {\r
7226                 var nl, i;\r
7228                 if (tinyMCE.lastMenu == this)\r
7229                         return;\r
7231                 if (this.needsUpdate)\r
7232                         this.update();\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
7243                                 nl[0].focus();*/\r
7244                 }\r
7246                 tinyMCE.lastMenu = this;\r
7247         }\r
7249         });\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
7260                 o = s._fu;\r
7261                 s._fu = this;\r
7262                 r = eval('s._fu(' + as + ')');\r
7263                 s._fu = o;\r
7265                 return r;\r
7266         };\r
7267 };\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
7275                 m += a[i];\r
7277                 if (i<a.length-1)\r
7278                         m += ', ';\r
7279         }\r
7281         if (l < 1000)\r
7282                 tinyMCE.log[l] = "[debug] " + m;\r
7283 };\r