[ Index ] |
|
Code source de LifeType 1.2.4 |
1 2 /* file:jscripts/tiny_mce/classes/TinyMCE_Engine.class.js */ 3 4 function TinyMCE_Engine() { 5 var ua; 6 7 this.majorVersion = "2"; 8 this.minorVersion = "1.0"; 9 this.releaseDate = "2007-02-13"; 10 11 this.instances = new Array(); 12 this.switchClassCache = new Array(); 13 this.windowArgs = new Array(); 14 this.loadedFiles = new Array(); 15 this.pendingFiles = new Array(); 16 this.loadingIndex = 0; 17 this.configs = new Array(); 18 this.currentConfig = 0; 19 this.eventHandlers = new Array(); 20 this.log = new Array(); 21 this.undoLevels = []; 22 this.undoIndex = 0; 23 this.typingUndoIndex = -1; 24 25 // Browser check 26 ua = navigator.userAgent; 27 this.isMSIE = (navigator.appName == "Microsoft Internet Explorer"); 28 this.isMSIE5 = this.isMSIE && (ua.indexOf('MSIE 5') != -1); 29 this.isMSIE5_0 = this.isMSIE && (ua.indexOf('MSIE 5.0') != -1); 30 this.isMSIE7 = this.isMSIE && (ua.indexOf('MSIE 7') != -1); 31 this.isGecko = ua.indexOf('Gecko') != -1; 32 this.isSafari = ua.indexOf('Safari') != -1; 33 this.isOpera = ua.indexOf('Opera') != -1; 34 this.isMac = ua.indexOf('Mac') != -1; 35 this.isNS7 = ua.indexOf('Netscape/7') != -1; 36 this.isNS71 = ua.indexOf('Netscape/7.1') != -1; 37 this.dialogCounter = 0; 38 this.plugins = new Array(); 39 this.themes = new Array(); 40 this.menus = new Array(); 41 this.loadedPlugins = new Array(); 42 this.buttonMap = new Array(); 43 this.isLoaded = false; 44 45 // Fake MSIE on Opera and if Opera fakes IE, Gecko or Safari cancel those 46 if (this.isOpera) { 47 this.isMSIE = true; 48 this.isGecko = false; 49 this.isSafari = false; 50 } 51 52 this.isIE = this.isMSIE; 53 this.isRealIE = this.isMSIE && !this.isOpera; 54 55 // TinyMCE editor id instance counter 56 this.idCounter = 0; 57 }; 58 59 TinyMCE_Engine.prototype = { 60 init : function(settings) { 61 var theme, nl, baseHREF = "", i; 62 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. 64 if (this.isMSIE5_0) 65 return; 66 67 this.settings = settings; 68 69 // Check if valid browser has execcommand support 70 if (typeof(document.execCommand) == 'undefined') 71 return; 72 73 // Get script base path 74 if (!tinyMCE.baseURL) { 75 var elements = document.getElementsByTagName('script'); 76 77 // If base element found, add that infront of baseURL 78 nl = document.getElementsByTagName('base'); 79 for (i=0; i<nl.length; i++) { 80 if (nl[i].href) 81 baseHREF = nl[i].href; 82 } 83 84 for (var i=0; i<elements.length; i++) { 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)) { 86 var src = elements[i].src; 87 88 tinyMCE.srcMode = (src.indexOf('_src') != -1 || src.indexOf('_dev') != -1) ? '_src' : ''; 89 tinyMCE.gzipMode = src.indexOf('_gzip') != -1; 90 src = src.substring(0, src.lastIndexOf('/')); 91 92 if (settings.exec_mode == "src" || settings.exec_mode == "normal") 93 tinyMCE.srcMode = settings.exec_mode == "src" ? '_src' : ''; 94 95 // Force it absolute if page has a base href 96 if (baseHREF != "" && src.indexOf('://') == -1) 97 tinyMCE.baseURL = baseHREF + src; 98 else 99 tinyMCE.baseURL = src; 100 101 break; 102 } 103 } 104 } 105 106 // Get document base path 107 this.documentBasePath = document.location.href; 108 if (this.documentBasePath.indexOf('?') != -1) 109 this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.indexOf('?')); 110 this.documentURL = this.documentBasePath; 111 this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.lastIndexOf('/')); 112 113 // If not HTTP absolute 114 if (tinyMCE.baseURL.indexOf('://') == -1 && tinyMCE.baseURL.charAt(0) != '/') { 115 // If site absolute 116 tinyMCE.baseURL = this.documentBasePath + "/" + tinyMCE.baseURL; 117 } 118 119 // Set default values on settings 120 this._def("mode", "none"); 121 this._def("theme", "advanced"); 122 this._def("plugins", "", true); 123 this._def("language", "en"); 124 this._def("docs_language", this.settings['language']); 125 this._def("elements", ""); 126 this._def("textarea_trigger", "mce_editable"); 127 this._def("editor_selector", ""); 128 this._def("editor_deselector", "mceNoEditor"); 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]"); 130 this._def("extended_valid_elements", ""); 131 this._def("invalid_elements", ""); 132 this._def("encoding", ""); 133 this._def("urlconverter_callback", tinyMCE.getParam("urlconvertor_callback", "TinyMCE_Engine.prototype.convertURL")); 134 this._def("save_callback", ""); 135 this._def("debug", false); 136 this._def("force_br_newlines", false); 137 this._def("force_p_newlines", true); 138 this._def("add_form_submit_trigger", true); 139 this._def("relative_urls", true); 140 this._def("remove_script_host", true); 141 this._def("focus_alert", true); 142 this._def("document_base_url", this.documentURL); 143 this._def("visual", true); 144 this._def("visual_table_class", "mceVisualAid"); 145 this._def("setupcontent_callback", ""); 146 this._def("fix_content_duplication", true); 147 this._def("custom_undo_redo", true); 148 this._def("custom_undo_redo_levels", -1); 149 this._def("custom_undo_redo_keyboard_shortcuts", true); 150 this._def("custom_undo_redo_restore_selection", true); 151 this._def("custom_undo_redo_global", false); 152 this._def("verify_html", true); 153 this._def("apply_source_formatting", false); 154 this._def("directionality", "ltr"); 155 this._def("cleanup_on_startup", false); 156 this._def("inline_styles", false); 157 this._def("convert_newlines_to_brs", false); 158 this._def("auto_reset_designmode", true); 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); 160 this._def("entity_encoding", "named"); 161 this._def("cleanup_callback", ""); 162 this._def("add_unload_trigger", true); 163 this._def("ask", false); 164 this._def("nowrap", false); 165 this._def("auto_resize", false); 166 this._def("auto_focus", false); 167 this._def("cleanup", true); 168 this._def("remove_linebreaks", true); 169 this._def("button_tile_map", false); 170 this._def("submit_patch", true); 171 this._def("browsers", "msie,safari,gecko,opera", true); 172 this._def("dialog_type", "window"); 173 this._def("accessibility_warnings", true); 174 this._def("accessibility_focus", true); 175 this._def("merge_styles_invalid_parents", ""); 176 this._def("force_hex_style_colors", true); 177 this._def("trim_span_elements", true); 178 this._def("convert_fonts_to_spans", false); 179 this._def("doctype", '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'); 180 this._def("font_size_classes", ''); 181 this._def("font_size_style_values", 'xx-small,x-small,small,medium,large,x-large,xx-large', true); 182 this._def("event_elements", 'a,img', true); 183 this._def("convert_urls", true); 184 this._def("table_inline_editing", false); 185 this._def("object_resizing", true); 186 this._def("custom_shortcuts", true); 187 this._def("convert_on_click", false); 188 this._def("content_css", ''); 189 this._def("fix_list_elements", true); 190 this._def("fix_table_elements", false); 191 this._def("strict_loading_mode", document.contentType == 'application/xhtml+xml'); 192 this._def("hidden_tab_class", ''); 193 this._def("display_tab_class", ''); 194 this._def("gecko_spellcheck", false); 195 this._def("hide_selects_on_submit", true); 196 197 // Force strict loading mode to false on non Gecko browsers 198 if (this.isMSIE && !this.isOpera) 199 this.settings.strict_loading_mode = false; 200 201 // Browser check IE 202 if (this.isMSIE && this.settings['browsers'].indexOf('msie') == -1) 203 return; 204 205 // Browser check Gecko 206 if (this.isGecko && this.settings['browsers'].indexOf('gecko') == -1) 207 return; 208 209 // Browser check Safari 210 if (this.isSafari && this.settings['browsers'].indexOf('safari') == -1) 211 return; 212 213 // Browser check Opera 214 if (this.isOpera && this.settings['browsers'].indexOf('opera') == -1) 215 return; 216 217 // If not super absolute make it so 218 baseHREF = tinyMCE.settings['document_base_url']; 219 var h = document.location.href; 220 var p = h.indexOf('://'); 221 if (p > 0 && document.location.protocol != "file:") { 222 p = h.indexOf('/', p + 3); 223 h = h.substring(0, p); 224 225 if (baseHREF.indexOf('://') == -1) 226 baseHREF = h + baseHREF; 227 228 tinyMCE.settings['document_base_url'] = baseHREF; 229 tinyMCE.settings['document_base_prefix'] = h; 230 } 231 232 // Trim away query part 233 if (baseHREF.indexOf('?') != -1) 234 baseHREF = baseHREF.substring(0, baseHREF.indexOf('?')); 235 236 this.settings['base_href'] = baseHREF.substring(0, baseHREF.lastIndexOf('/')) + "/"; 237 238 theme = this.settings['theme']; 239 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'; 240 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'; 241 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'; 242 this.blockRegExp = new RegExp("^(" + this.blockElms + ")$", "i"); 243 this.posKeyCodes = new Array(13,45,36,35,33,34,37,38,39,40); 244 this.uniqueURL = 'javascript:void(091039730);'; // Make unique URL non real URL 245 this.uniqueTag = '<div id="mceTMPElement" style="display: none">TMP</div>'; 246 this.callbacks = new Array('onInit', 'getInfo', 'getEditorTemplate', 'setupContent', 'onChange', 'onPageLoad', 'handleNodeChange', 'initInstance', 'execCommand', 'getControlHTML', 'handleEvent', 'cleanup', 'removeInstance'); 247 248 // Theme url 249 this.settings['theme_href'] = tinyMCE.baseURL + "/themes/" + theme; 250 251 if (!tinyMCE.isIE || tinyMCE.isOpera) 252 this.settings['force_br_newlines'] = false; 253 254 if (tinyMCE.getParam("popups_css", false)) { 255 var cssPath = tinyMCE.getParam("popups_css", ""); 256 257 // Is relative 258 if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/') 259 this.settings['popups_css'] = this.documentBasePath + "/" + cssPath; 260 else 261 this.settings['popups_css'] = cssPath; 262 } else 263 this.settings['popups_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_popup.css"; 264 265 if (tinyMCE.getParam("editor_css", false)) { 266 var cssPath = tinyMCE.getParam("editor_css", ""); 267 268 // Is relative 269 if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/') 270 this.settings['editor_css'] = this.documentBasePath + "/" + cssPath; 271 else 272 this.settings['editor_css'] = cssPath; 273 } else { 274 if (this.settings.editor_css != '') 275 this.settings['editor_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css"; 276 } 277 278 if (tinyMCE.settings['debug']) { 279 var msg = "Debug: \n"; 280 281 msg += "baseURL: " + this.baseURL + "\n"; 282 msg += "documentBasePath: " + this.documentBasePath + "\n"; 283 msg += "content_css: " + this.settings['content_css'] + "\n"; 284 msg += "popups_css: " + this.settings['popups_css'] + "\n"; 285 msg += "editor_css: " + this.settings['editor_css'] + "\n"; 286 287 alert(msg); 288 } 289 290 // Only do this once 291 if (this.configs.length == 0) { 292 if (typeof(TinyMCECompressed) == "undefined") { 293 tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCE_Engine.prototype.onLoad); 294 295 if (tinyMCE.isRealIE) { 296 if (document.body) 297 tinyMCE.addEvent(document.body, "readystatechange", TinyMCE_Engine.prototype.onLoad); 298 else 299 tinyMCE.addEvent(document, "readystatechange", TinyMCE_Engine.prototype.onLoad); 300 } 301 302 tinyMCE.addEvent(window, "load", TinyMCE_Engine.prototype.onLoad); 303 tinyMCE._addUnloadEvents(); 304 } 305 } 306 307 this.loadScript(tinyMCE.baseURL + '/themes/' + this.settings['theme'] + '/editor_template' + tinyMCE.srcMode + '.js'); 308 this.loadScript(tinyMCE.baseURL + '/langs/' + this.settings['language'] + '.js'); 309 this.loadCSS(this.settings['editor_css']); 310 311 // Add plugins 312 var p = tinyMCE.getParam('plugins', '', true, ','); 313 if (p.length > 0) { 314 for (var i=0; i<p.length; i++) { 315 if (p[i].charAt(0) != '-') 316 this.loadScript(tinyMCE.baseURL + '/plugins/' + p[i] + '/editor_plugin' + tinyMCE.srcMode + '.js'); 317 } 318 } 319 320 // Setup entities 321 if (tinyMCE.getParam('entity_encoding') == 'named') { 322 settings['cleanup_entities'] = new Array(); 323 var entities = tinyMCE.getParam('entities', '', true, ','); 324 for (var i=0; i<entities.length; i+=2) 325 settings['cleanup_entities']['c' + entities[i]] = entities[i+1]; 326 } 327 328 // Save away this config 329 settings['index'] = this.configs.length; 330 this.configs[this.configs.length] = settings; 331 332 // Start loading first one in chain 333 this.loadNextScript(); 334 335 // Force flicker free CSS backgrounds in IE 336 if (this.isIE && !this.isOpera) { 337 try { 338 document.execCommand('BackgroundImageCache', false, true); 339 } catch (e) { 340 } 341 } 342 343 // Setup XML encoding regexps 344 this.xmlEncodeAposRe = new RegExp('[<>&"\']', 'g'); 345 this.xmlEncodeRe = new RegExp('[<>&"]', 'g'); 346 // this.xmlEncodeEnts = {'&':'&','"':'"',"'":''','<':'<','>':'>'}; 347 }, 348 349 _addUnloadEvents : function() { 350 if (tinyMCE.isIE) { 351 if (tinyMCE.settings['add_unload_trigger']) { 352 tinyMCE.addEvent(window, "unload", TinyMCE_Engine.prototype.unloadHandler); 353 tinyMCE.addEvent(window.document, "beforeunload", TinyMCE_Engine.prototype.unloadHandler); 354 } 355 } else { 356 if (tinyMCE.settings['add_unload_trigger']) 357 tinyMCE.addEvent(window, "unload", function () {tinyMCE.triggerSave(true, true);}); 358 } 359 }, 360 361 _def : function(key, def_val, t) { 362 var v = tinyMCE.getParam(key, def_val); 363 364 v = t ? v.replace(/\s+/g, "") : v; 365 366 this.settings[key] = v; 367 }, 368 369 hasPlugin : function(n) { 370 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null; 371 }, 372 373 addPlugin : function(n, p) { 374 var op = this.plugins[n]; 375 376 // Use the previous plugin object base URL used when loading external plugins 377 p.baseURL = op ? op.baseURL : tinyMCE.baseURL + "/plugins/" + n; 378 this.plugins[n] = p; 379 380 this.loadNextScript(); 381 }, 382 383 setPluginBaseURL : function(n, u) { 384 var op = this.plugins[n]; 385 386 if (op) 387 op.baseURL = u; 388 else 389 this.plugins[n] = {baseURL : u}; 390 }, 391 392 loadPlugin : function(n, u) { 393 u = u.indexOf('.js') != -1 ? u.substring(0, u.lastIndexOf('/')) : u; 394 u = u.charAt(u.length-1) == '/' ? u.substring(0, u.length-1) : u; 395 this.plugins[n] = {baseURL : u}; 396 this.loadScript(u + "/editor_plugin" + (tinyMCE.srcMode ? '_src' : '') + ".js"); 397 }, 398 399 hasTheme : function(n) { 400 return typeof(this.themes[n]) != "undefined" && this.themes[n] != null; 401 }, 402 403 addTheme : function(n, t) { 404 this.themes[n] = t; 405 406 this.loadNextScript(); 407 }, 408 409 addMenu : function(n, m) { 410 this.menus[n] = m; 411 }, 412 413 hasMenu : function(n) { 414 return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null; 415 }, 416 417 loadScript : function(url) { 418 var i; 419 420 for (i=0; i<this.loadedFiles.length; i++) { 421 if (this.loadedFiles[i] == url) 422 return; 423 } 424 425 if (tinyMCE.settings.strict_loading_mode) 426 this.pendingFiles[this.pendingFiles.length] = url; 427 else 428 document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></script>'); 429 430 this.loadedFiles[this.loadedFiles.length] = url; 431 }, 432 433 loadNextScript : function() { 434 var d = document, se; 435 436 if (!tinyMCE.settings.strict_loading_mode) 437 return; 438 439 if (this.loadingIndex < this.pendingFiles.length) { 440 se = d.createElementNS('http://www.w3.org/1999/xhtml', 'script'); 441 se.setAttribute('language', 'javascript'); 442 se.setAttribute('type', 'text/javascript'); 443 se.setAttribute('src', this.pendingFiles[this.loadingIndex++]); 444 445 d.getElementsByTagName("head")[0].appendChild(se); 446 } else 447 this.loadingIndex = -1; // Done with loading 448 }, 449 450 loadCSS : function(url) { 451 var ar = url.replace(/\s+/, '').split(','); 452 var lflen = 0, csslen = 0; 453 var skip = false; 454 var x = 0, i = 0, nl, le; 455 456 for (x = 0,csslen = ar.length; x<csslen; x++) { 457 if (ar[x] != null && ar[x] != 'null' && ar[x].length > 0) { 458 /* Make sure it doesn't exist. */ 459 for (i=0, lflen=this.loadedFiles.length; i<lflen; i++) { 460 if (this.loadedFiles[i] == ar[x]) { 461 skip = true; 462 break; 463 } 464 } 465 466 if (!skip) { 467 if (tinyMCE.settings.strict_loading_mode) { 468 nl = document.getElementsByTagName("head"); 469 470 le = document.createElement('link'); 471 le.setAttribute('href', ar[x]); 472 le.setAttribute('rel', 'stylesheet'); 473 le.setAttribute('type', 'text/css'); 474 475 nl[0].appendChild(le); 476 } else 477 document.write('<link href="' + ar[x] + '" rel="stylesheet" type="text/css" />'); 478 479 this.loadedFiles[this.loadedFiles.length] = ar[x]; 480 } 481 } 482 } 483 }, 484 485 importCSS : function(doc, css) { 486 var css_ary = css.replace(/\s+/, '').split(','); 487 var csslen, elm, headArr, x, css_file; 488 489 for (x = 0, csslen = css_ary.length; x<csslen; x++) { 490 css_file = css_ary[x]; 491 492 if (css_file != null && css_file != 'null' && css_file.length > 0) { 493 // Is relative, make absolute 494 if (css_file.indexOf('://') == -1 && css_file.charAt(0) != '/') 495 css_file = this.documentBasePath + "/" + css_file; 496 497 if (typeof(doc.createStyleSheet) == "undefined") { 498 elm = doc.createElement("link"); 499 500 elm.rel = "stylesheet"; 501 elm.href = css_file; 502 503 if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0) 504 headArr[0].appendChild(elm); 505 } else 506 doc.createStyleSheet(css_file); 507 } 508 } 509 }, 510 511 confirmAdd : function(e, settings) { 512 var elm = tinyMCE.isIE ? event.srcElement : e.target; 513 var elementId = elm.name ? elm.name : elm.id; 514 515 tinyMCE.settings = settings; 516 517 if (tinyMCE.settings['convert_on_click'] || (!elm.getAttribute('mce_noask') && confirm(tinyMCELang['lang_edit_confirm']))) 518 tinyMCE.addMCEControl(elm, elementId); 519 520 elm.setAttribute('mce_noask', 'true'); 521 }, 522 523 updateContent : function(form_element_name) { 524 // Find MCE instance linked to given form element and copy it's value 525 var formElement = document.getElementById(form_element_name); 526 for (var n in tinyMCE.instances) { 527 var inst = tinyMCE.instances[n]; 528 if (!tinyMCE.isInstance(inst)) 529 continue; 530 531 inst.switchSettings(); 532 533 if (inst.formElement == formElement) { 534 var doc = inst.getDoc(); 535 536 tinyMCE._setHTML(doc, inst.formElement.value); 537 538 if (!tinyMCE.isIE) 539 doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid); 540 } 541 } 542 }, 543 544 addMCEControl : function(replace_element, form_element_name, target_document) { 545 var id = "mce_editor_" + tinyMCE.idCounter++; 546 var inst = new TinyMCE_Control(tinyMCE.settings); 547 548 inst.editorId = id; 549 this.instances[id] = inst; 550 551 inst._onAdd(replace_element, form_element_name, target_document); 552 }, 553 554 removeInstance : function(ti) { 555 var t = [], n, i; 556 557 // Remove from instances 558 for (n in tinyMCE.instances) { 559 i = tinyMCE.instances[n]; 560 561 if (tinyMCE.isInstance(i) && ti != i) 562 t[n] = i; 563 } 564 565 tinyMCE.instances = t; 566 567 // Remove from global undo/redo 568 n = []; 569 t = tinyMCE.undoLevels; 570 571 for (i=0; i<t.length; i++) { 572 if (t[i] != ti) 573 n.push(t[i]); 574 } 575 576 tinyMCE.undoLevels = n; 577 tinyMCE.undoIndex = n.length; 578 579 // Dispatch remove instance call 580 tinyMCE.dispatchCallback(ti, 'remove_instance_callback', 'removeInstance', ti); 581 582 return ti; 583 }, 584 585 removeMCEControl : function(editor_id) { 586 var inst = tinyMCE.getInstanceById(editor_id), h, re, ot, tn; 587 588 if (inst) { 589 inst.switchSettings(); 590 591 editor_id = inst.editorId; 592 h = tinyMCE.getContent(editor_id); 593 594 this.removeInstance(inst); 595 596 tinyMCE.selectedElement = null; 597 tinyMCE.selectedInstance = null; 598 599 // Remove element 600 re = document.getElementById(editor_id + "_parent"); 601 ot = inst.oldTargetElement; 602 tn = ot.nodeName.toLowerCase(); 603 604 if (tn == "textarea" || tn == "input") { 605 re.parentNode.removeChild(re); 606 ot.style.display = "inline"; 607 ot.value = h; 608 } else { 609 ot.innerHTML = h; 610 ot.style.display = 'block'; 611 re.parentNode.insertBefore(ot, re); 612 re.parentNode.removeChild(re); 613 } 614 } 615 }, 616 617 triggerSave : function(skip_cleanup, skip_callback) { 618 var inst, n; 619 620 // Default to false 621 if (typeof(skip_cleanup) == "undefined") 622 skip_cleanup = false; 623 624 // Default to false 625 if (typeof(skip_callback) == "undefined") 626 skip_callback = false; 627 628 // Cleanup and set all form fields 629 for (n in tinyMCE.instances) { 630 inst = tinyMCE.instances[n]; 631 632 if (!tinyMCE.isInstance(inst)) 633 continue; 634 635 inst.triggerSave(skip_cleanup, skip_callback); 636 } 637 }, 638 639 resetForm : function(form_index) { 640 var i, inst, n, formObj = document.forms[form_index]; 641 642 for (n in tinyMCE.instances) { 643 inst = tinyMCE.instances[n]; 644 645 if (!tinyMCE.isInstance(inst)) 646 continue; 647 648 inst.switchSettings(); 649 650 for (i=0; i<formObj.elements.length; i++) { 651 if (inst.formTargetElementId == formObj.elements[i].name) 652 inst.getBody().innerHTML = inst.startContent; 653 } 654 } 655 }, 656 657 execInstanceCommand : function(editor_id, command, user_interface, value, focus) { 658 var inst = tinyMCE.getInstanceById(editor_id), r; 659 660 if (inst) { 661 r = inst.selection.getRng(); 662 663 if (typeof(focus) == "undefined") 664 focus = true; 665 666 // IE bug lost focus on images in absolute divs Bug #1534575 667 if (focus && (!r || !r.item)) 668 inst.contentWindow.focus(); 669 670 // Reset design mode if lost 671 inst.autoResetDesignMode(); 672 673 this.selectedElement = inst.getFocusElement(); 674 inst.select(); 675 tinyMCE.execCommand(command, user_interface, value); 676 677 // Cancel event so it doesn't call onbeforeonunlaod 678 if (tinyMCE.isIE && window.event != null) 679 tinyMCE.cancelEvent(window.event); 680 } 681 }, 682 683 execCommand : function(command, user_interface, value) { 684 var inst = tinyMCE.selectedInstance; 685 686 // Default input 687 user_interface = user_interface ? user_interface : false; 688 value = value ? value : null; 689 690 if (inst) 691 inst.switchSettings(); 692 693 switch (command) { 694 case "Undo": 695 if (this.getParam('custom_undo_redo_global')) { 696 if (this.undoIndex > 0) { 697 tinyMCE.nextUndoRedoAction = 'Undo'; 698 inst = this.undoLevels[--this.undoIndex]; 699 inst.select(); 700 701 if (!tinyMCE.nextUndoRedoInstanceId) 702 inst.execCommand('Undo'); 703 } 704 } else 705 inst.execCommand('Undo'); 706 return true; 707 708 case "Redo": 709 if (this.getParam('custom_undo_redo_global')) { 710 if (this.undoIndex <= this.undoLevels.length - 1) { 711 tinyMCE.nextUndoRedoAction = 'Redo'; 712 inst = this.undoLevels[this.undoIndex++]; 713 inst.select(); 714 715 if (!tinyMCE.nextUndoRedoInstanceId) 716 inst.execCommand('Redo'); 717 } 718 } else 719 inst.execCommand('Redo'); 720 721 return true; 722 723 case 'mceFocus': 724 var inst = tinyMCE.getInstanceById(value); 725 if (inst) 726 inst.getWin().focus(); 727 return; 728 729 case "mceAddControl": 730 case "mceAddEditor": 731 tinyMCE.addMCEControl(tinyMCE._getElementById(value), value); 732 return; 733 734 case "mceAddFrameControl": 735 tinyMCE.addMCEControl(tinyMCE._getElementById(value['element'], value['document']), value['element'], value['document']); 736 return; 737 738 case "mceRemoveControl": 739 case "mceRemoveEditor": 740 tinyMCE.removeMCEControl(value); 741 return; 742 743 case "mceToggleEditor": 744 var inst = tinyMCE.getInstanceById(value), pe, te; 745 746 if (inst) { 747 pe = document.getElementById(inst.editorId + '_parent'); 748 te = inst.oldTargetElement; 749 750 if (typeof(inst.enabled) == 'undefined') 751 inst.enabled = true; 752 753 inst.enabled = !inst.enabled; 754 755 if (!inst.enabled) { 756 pe.style.display = 'none'; 757 te.value = inst.getHTML(); 758 te.style.display = inst.oldTargetDisplay; 759 tinyMCE.dispatchCallback(inst, 'hide_instance_callback', 'hideInstance', inst); 760 } else { 761 pe.style.display = 'block'; 762 te.style.display = 'none'; 763 inst.setHTML(te.value); 764 inst.useCSS = false; 765 tinyMCE.dispatchCallback(inst, 'show_instance_callback', 'showInstance', inst); 766 } 767 } else 768 tinyMCE.addMCEControl(tinyMCE._getElementById(value), value); 769 770 return; 771 772 case "mceResetDesignMode": 773 // Resets the designmode state of the editors in Gecko 774 if (!tinyMCE.isIE) { 775 for (var n in tinyMCE.instances) { 776 if (!tinyMCE.isInstance(tinyMCE.instances[n])) 777 continue; 778 779 try { 780 tinyMCE.instances[n].getDoc().designMode = "on"; 781 } catch (e) { 782 // Ignore any errors 783 } 784 } 785 } 786 787 return; 788 } 789 790 if (inst) { 791 inst.execCommand(command, user_interface, value); 792 } else if (tinyMCE.settings['focus_alert']) 793 alert(tinyMCELang['lang_focus_alert']); 794 }, 795 796 _createIFrame : function(replace_element, doc, win) { 797 var iframe, id = replace_element.getAttribute("id"); 798 var aw, ah; 799 800 if (typeof(doc) == "undefined") 801 doc = document; 802 803 if (typeof(win) == "undefined") 804 win = window; 805 806 iframe = doc.createElement("iframe"); 807 808 aw = "" + tinyMCE.settings['area_width']; 809 ah = "" + tinyMCE.settings['area_height']; 810 811 if (aw.indexOf('%') == -1) { 812 aw = parseInt(aw); 813 aw = (isNaN(aw) || aw < 0) ? 300 : aw; 814 aw = aw + "px"; 815 } 816 817 if (ah.indexOf('%') == -1) { 818 ah = parseInt(ah); 819 ah = (isNaN(ah) || ah < 0) ? 240 : ah; 820 ah = ah + "px"; 821 } 822 823 iframe.setAttribute("id", id); 824 iframe.setAttribute("name", id); 825 iframe.setAttribute("class", "mceEditorIframe"); 826 iframe.setAttribute("border", "0"); 827 iframe.setAttribute("frameBorder", "0"); 828 iframe.setAttribute("marginWidth", "0"); 829 iframe.setAttribute("marginHeight", "0"); 830 iframe.setAttribute("leftMargin", "0"); 831 iframe.setAttribute("topMargin", "0"); 832 iframe.setAttribute("width", aw); 833 iframe.setAttribute("height", ah); 834 iframe.setAttribute("allowtransparency", "true"); 835 iframe.className = 'mceEditorIframe'; 836 837 if (tinyMCE.settings["auto_resize"]) 838 iframe.setAttribute("scrolling", "no"); 839 840 // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs 841 if (tinyMCE.isRealIE) 842 iframe.setAttribute("src", this.settings['default_document']); 843 844 iframe.style.width = aw; 845 iframe.style.height = ah; 846 847 // Ugly hack for Gecko problem in strict mode 848 if (tinyMCE.settings.strict_loading_mode) 849 iframe.style.marginBottom = '-5px'; 850 851 // MSIE 5.0 issue 852 if (tinyMCE.isRealIE) 853 replace_element.outerHTML = iframe.outerHTML; 854 else 855 replace_element.parentNode.replaceChild(iframe, replace_element); 856 857 if (tinyMCE.isRealIE) 858 return win.frames[id]; 859 else 860 return iframe; 861 }, 862 863 setupContent : function(editor_id) { 864 var inst = tinyMCE.instances[editor_id], i; 865 var doc = inst.getDoc(); 866 var head = doc.getElementsByTagName('head').item(0); 867 var content = inst.startContent; 868 869 // HTML values get XML encoded in strict mode 870 if (tinyMCE.settings.strict_loading_mode) { 871 content = content.replace(/</g, '<'); 872 content = content.replace(/>/g, '>'); 873 content = content.replace(/"/g, '"'); 874 content = content.replace(/&/g, '&'); 875 } 876 877 tinyMCE.selectedInstance = inst; 878 inst.switchSettings(); 879 880 // Not loaded correctly hit it again, Mozilla bug #997860 881 if (!tinyMCE.isIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") { 882 // This part will remove the designMode status 883 // Failes first time in Firefox 1.5b2 on Mac 884 try {doc.location.href = tinyMCE.baseURL + "/blank.htm";} catch (ex) {} 885 window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 1000); 886 return; 887 } 888 889 if (!head) { 890 window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10); 891 return; 892 } 893 894 // Import theme specific content CSS the user specific 895 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/themes/" + inst.settings['theme'] + "/css/editor_content.css"); 896 tinyMCE.importCSS(inst.getDoc(), inst.settings['content_css']); 897 tinyMCE.dispatchCallback(inst, 'init_instance_callback', 'initInstance', inst); 898 899 // Setup keyboard shortcuts 900 if (tinyMCE.getParam('custom_undo_redo_keyboard_shortcuts')) { 901 inst.addShortcut('ctrl', 'z', 'lang_undo_desc', 'Undo'); 902 inst.addShortcut('ctrl', 'y', 'lang_redo_desc', 'Redo'); 903 } 904 905 // BlockFormat shortcuts keys 906 for (i=1; i<=6; i++) 907 inst.addShortcut('ctrl', '' + i, '', 'FormatBlock', false, '<h' + i + '>'); 908 909 inst.addShortcut('ctrl', '7', '', 'FormatBlock', false, '<p>'); 910 inst.addShortcut('ctrl', '8', '', 'FormatBlock', false, '<div>'); 911 inst.addShortcut('ctrl', '9', '', 'FormatBlock', false, '<address>'); 912 913 // Add default shortcuts for gecko 914 if (tinyMCE.isGecko) { 915 inst.addShortcut('ctrl', 'b', 'lang_bold_desc', 'Bold'); 916 inst.addShortcut('ctrl', 'i', 'lang_italic_desc', 'Italic'); 917 inst.addShortcut('ctrl', 'u', 'lang_underline_desc', 'Underline'); 918 } 919 920 // Setup span styles 921 if (tinyMCE.getParam("convert_fonts_to_spans")) 922 inst.getBody().setAttribute('id', 'mceSpanFonts'); 923 924 if (tinyMCE.settings['nowrap']) 925 doc.body.style.whiteSpace = "nowrap"; 926 927 doc.body.dir = this.settings['directionality']; 928 doc.editorId = editor_id; 929 930 // Add on document element in Mozilla 931 if (!tinyMCE.isIE) 932 doc.documentElement.editorId = editor_id; 933 934 inst.setBaseHREF(tinyMCE.settings['base_href']); 935 936 // Replace new line characters to BRs 937 if (tinyMCE.settings['convert_newlines_to_brs']) { 938 content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi"); 939 content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi"); 940 content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi"); 941 } 942 943 // Open closed anchors 944 // content = content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>'); 945 946 // Call custom cleanup code 947 content = tinyMCE.storeAwayURLs(content); 948 content = tinyMCE._customCleanup(inst, "insert_to_editor", content); 949 950 if (tinyMCE.isIE) { 951 // Ugly!!! 952 window.setInterval('try{tinyMCE.getCSSClasses(tinyMCE.instances["' + editor_id + '"].getDoc(), "' + editor_id + '");}catch(e){}', 500); 953 954 if (tinyMCE.settings["force_br_newlines"]) 955 doc.styleSheets[0].addRule("p", "margin: 0;"); 956 957 var body = inst.getBody(); 958 body.editorId = editor_id; 959 } 960 961 content = tinyMCE.cleanupHTMLCode(content); 962 963 // Fix for bug #958637 964 if (!tinyMCE.isIE) { 965 var contentElement = inst.getDoc().createElement("body"); 966 var doc = inst.getDoc(); 967 968 contentElement.innerHTML = content; 969 970 // Remove weridness! 971 if (tinyMCE.isGecko && tinyMCE.settings['remove_lt_gt']) 972 content = content.replace(new RegExp('<>', 'g'), ""); 973 974 if (tinyMCE.settings['cleanup_on_startup']) 975 tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement)); 976 else 977 tinyMCE.setInnerHTML(inst.getBody(), content); 978 979 tinyMCE.convertAllRelativeURLs(inst.getBody()); 980 } else { 981 if (tinyMCE.settings['cleanup_on_startup']) { 982 tinyMCE._setHTML(inst.getDoc(), content); 983 984 // Produces permission denied error in MSIE 5.5 985 eval('try {tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody()));} catch(e) {}'); 986 } else 987 tinyMCE._setHTML(inst.getDoc(), content); 988 } 989 990 // Fix for bug #957681 991 //inst.getDoc().designMode = inst.getDoc().designMode; 992 993 tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings['visual'], inst); 994 tinyMCE.dispatchCallback(inst, 'setupcontent_callback', 'setupContent', editor_id, inst.getBody(), inst.getDoc()); 995 996 // Re-add design mode on mozilla 997 if (!tinyMCE.isIE) 998 tinyMCE.addEventHandlers(inst); 999 1000 // Add blur handler 1001 if (tinyMCE.isIE) { 1002 tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE_Engine.prototype._eventPatch); 1003 tinyMCE.addEvent(inst.getBody(), "beforedeactivate", TinyMCE_Engine.prototype._eventPatch); // Bug #1439953 1004 1005 // Workaround for drag drop/copy paste base href bug 1006 if (!tinyMCE.isOpera) { 1007 tinyMCE.addEvent(doc.body, "mousemove", TinyMCE_Engine.prototype.onMouseMove); 1008 tinyMCE.addEvent(doc.body, "beforepaste", TinyMCE_Engine.prototype._eventPatch); 1009 tinyMCE.addEvent(doc.body, "drop", TinyMCE_Engine.prototype._eventPatch); 1010 } 1011 } 1012 1013 // Trigger node change, this call locks buttons for tables and so forth 1014 inst.select(); 1015 tinyMCE.selectedElement = inst.contentWindow.document.body; 1016 1017 // Call custom DOM cleanup 1018 tinyMCE._customCleanup(inst, "insert_to_editor_dom", inst.getBody()); 1019 tinyMCE._customCleanup(inst, "setup_content_dom", inst.getBody()); 1020 tinyMCE._setEventsEnabled(inst.getBody(), false); 1021 tinyMCE.cleanupAnchors(inst.getDoc()); 1022 1023 if (tinyMCE.getParam("convert_fonts_to_spans")) 1024 tinyMCE.convertSpansToFonts(inst.getDoc()); 1025 1026 inst.startContent = tinyMCE.trim(inst.getBody().innerHTML); 1027 inst.undoRedo.add({ content : inst.startContent }); 1028 1029 // Cleanup any mess left from storyAwayURLs 1030 if (tinyMCE.isGecko) { 1031 // Remove mce_src from textnodes and comments 1032 tinyMCE.selectNodes(inst.getBody(), function(n) { 1033 if (n.nodeType == 3 || n.nodeType == 8) 1034 n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), ""); 1035 1036 return false; 1037 }); 1038 } 1039 1040 // Remove Gecko spellchecking 1041 if (tinyMCE.isGecko) 1042 inst.getBody().spellcheck = tinyMCE.getParam("gecko_spellcheck"); 1043 1044 // Cleanup any mess left from storyAwayURLs 1045 tinyMCE._removeInternal(inst.getBody()); 1046 1047 inst.select(); 1048 tinyMCE.triggerNodeChange(false, true); 1049 }, 1050 1051 storeAwayURLs : function(s) { 1052 // Remove all mce_src, mce_href and replace them with new ones 1053 // s = s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), ''); 1054 // s = s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), ''); 1055 1056 if (!s.match(/(mce_src|mce_href)/gi, s)) { 1057 s = s.replace(new RegExp('src\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'src="$1" mce_src="$1"'); 1058 s = s.replace(new RegExp('href\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'href="$1" mce_href="$1"'); 1059 } 1060 1061 return s; 1062 }, 1063 1064 _removeInternal : function(n) { 1065 if (tinyMCE.isGecko) { 1066 // Remove mce_src from textnodes and comments 1067 tinyMCE.selectNodes(n, function(n) { 1068 if (n.nodeType == 3 || n.nodeType == 8) 1069 n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), ""); 1070 1071 return false; 1072 }); 1073 } 1074 }, 1075 1076 removeTinyMCEFormElements : function(form_obj) { 1077 var i, elementId; 1078 1079 // Skip form element removal 1080 if (!tinyMCE.getParam('hide_selects_on_submit')) 1081 return; 1082 1083 // Check if form is valid 1084 if (typeof(form_obj) == "undefined" || form_obj == null) 1085 return; 1086 1087 // If not a form, find the form 1088 if (form_obj.nodeName != "FORM") { 1089 if (form_obj.form) 1090 form_obj = form_obj.form; 1091 else 1092 form_obj = tinyMCE.getParentElement(form_obj, "form"); 1093 } 1094 1095 // Still nothing 1096 if (form_obj == null) 1097 return; 1098 1099 // Disable all UI form elements that TinyMCE created 1100 for (i=0; i<form_obj.elements.length; i++) { 1101 elementId = form_obj.elements[i].name ? form_obj.elements[i].name : form_obj.elements[i].id; 1102 1103 if (elementId.indexOf('mce_editor_') == 0) 1104 form_obj.elements[i].disabled = true; 1105 } 1106 }, 1107 1108 handleEvent : function(e) { 1109 var inst = tinyMCE.selectedInstance; 1110 1111 // Remove odd, error 1112 if (typeof(tinyMCE) == "undefined") 1113 return true; 1114 1115 //tinyMCE.debug(e.type + " " + e.target.nodeName + " " + (e.relatedTarget ? e.relatedTarget.nodeName : "")); 1116 1117 if (tinyMCE.executeCallback(tinyMCE.selectedInstance, 'handle_event_callback', 'handleEvent', e)) 1118 return false; 1119 1120 switch (e.type) { 1121 case "beforedeactivate": // Was added due to bug #1439953 1122 case "blur": 1123 if (tinyMCE.selectedInstance) 1124 tinyMCE.selectedInstance.execCommand('mceEndTyping'); 1125 1126 tinyMCE.hideMenus(); 1127 1128 return; 1129 1130 // Workaround for drag drop/copy paste base href bug 1131 case "drop": 1132 case "beforepaste": 1133 if (tinyMCE.selectedInstance) 1134 tinyMCE.selectedInstance.setBaseHREF(null); 1135 1136 // Fixes odd MSIE bug where drag/droping elements in a iframe with height 100% breaks 1137 // This logic forces the width/height to be in pixels while the user is drag/dropping 1138 if (tinyMCE.isRealIE) { 1139 var ife = tinyMCE.selectedInstance.iframeElement; 1140 1141 /*if (ife.style.width.indexOf('%') != -1) { 1142 ife._oldWidth = ife.width.height; 1143 ife.style.width = ife.clientWidth; 1144 }*/ 1145 1146 if (ife.style.height.indexOf('%') != -1) { 1147 ife._oldHeight = ife.style.height; 1148 ife.style.height = ife.clientHeight; 1149 } 1150 } 1151 1152 window.setTimeout("tinyMCE.selectedInstance.setBaseHREF(tinyMCE.settings['base_href']);tinyMCE._resetIframeHeight();", 1); 1153 return; 1154 1155 case "submit": 1156 tinyMCE.removeTinyMCEFormElements(tinyMCE.isMSIE ? window.event.srcElement : e.target); 1157 tinyMCE.triggerSave(); 1158 tinyMCE.isNotDirty = true; 1159 return; 1160 1161 case "reset": 1162 var formObj = tinyMCE.isIE ? window.event.srcElement : e.target; 1163 1164 for (var i=0; i<document.forms.length; i++) { 1165 if (document.forms[i] == formObj) 1166 window.setTimeout('tinyMCE.resetForm(' + i + ');', 10); 1167 } 1168 1169 return; 1170 1171 case "keypress": 1172 if (inst && inst.handleShortcut(e)) 1173 return false; 1174 1175 if (e.target.editorId) { 1176 tinyMCE.instances[e.target.editorId].select(); 1177 } else { 1178 if (e.target.ownerDocument.editorId) 1179 tinyMCE.instances[e.target.ownerDocument.editorId].select(); 1180 } 1181 1182 if (tinyMCE.selectedInstance) 1183 tinyMCE.selectedInstance.switchSettings(); 1184 1185 // Insert P element 1186 if ((tinyMCE.isGecko || tinyMCE.isOpera || tinyMCE.isSafari) && tinyMCE.settings['force_p_newlines'] && e.keyCode == 13 && !e.shiftKey) { 1187 // Insert P element instead of BR 1188 if (TinyMCE_ForceParagraphs._insertPara(tinyMCE.selectedInstance, e)) { 1189 // Cancel event 1190 tinyMCE.execCommand("mceAddUndoLevel"); 1191 return tinyMCE.cancelEvent(e); 1192 } 1193 } 1194 1195 // Handle backspace 1196 if ((tinyMCE.isGecko && !tinyMCE.isSafari) && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) { 1197 // Insert P element instead of BR 1198 if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) { 1199 // Cancel event 1200 tinyMCE.execCommand("mceAddUndoLevel"); 1201 return tinyMCE.cancelEvent(e); 1202 } 1203 } 1204 1205 // Return key pressed 1206 if (tinyMCE.isIE && tinyMCE.settings['force_br_newlines'] && e.keyCode == 13) { 1207 if (e.target.editorId) 1208 tinyMCE.instances[e.target.editorId].select(); 1209 1210 if (tinyMCE.selectedInstance) { 1211 var sel = tinyMCE.selectedInstance.getDoc().selection; 1212 var rng = sel.createRange(); 1213 1214 if (tinyMCE.getParentElement(rng.parentElement(), "li") != null) 1215 return false; 1216 1217 // Cancel event 1218 e.returnValue = false; 1219 e.cancelBubble = true; 1220 1221 // Insert BR element 1222 rng.pasteHTML("<br />"); 1223 rng.collapse(false); 1224 rng.select(); 1225 1226 tinyMCE.execCommand("mceAddUndoLevel"); 1227 tinyMCE.triggerNodeChange(false); 1228 return false; 1229 } 1230 } 1231 1232 // Backspace or delete 1233 if (e.keyCode == 8 || e.keyCode == 46) { 1234 tinyMCE.selectedElement = e.target; 1235 tinyMCE.linkElement = tinyMCE.getParentElement(e.target, "a"); 1236 tinyMCE.imgElement = tinyMCE.getParentElement(e.target, "img"); 1237 tinyMCE.triggerNodeChange(false); 1238 } 1239 1240 return false; 1241 break; 1242 1243 case "keyup": 1244 case "keydown": 1245 tinyMCE.hideMenus(); 1246 tinyMCE.hasMouseMoved = false; 1247 1248 if (inst && inst.handleShortcut(e)) 1249 return false; 1250 1251 if (e.target.editorId) 1252 tinyMCE.instances[e.target.editorId].select(); 1253 1254 if (tinyMCE.selectedInstance) 1255 tinyMCE.selectedInstance.switchSettings(); 1256 1257 var inst = tinyMCE.selectedInstance; 1258 1259 // Handle backspace 1260 if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) { 1261 // Insert P element instead of BR 1262 if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) { 1263 // Cancel event 1264 tinyMCE.execCommand("mceAddUndoLevel"); 1265 e.preventDefault(); 1266 return false; 1267 } 1268 } 1269 1270 tinyMCE.selectedElement = null; 1271 tinyMCE.selectedNode = null; 1272 var elm = tinyMCE.selectedInstance.getFocusElement(); 1273 tinyMCE.linkElement = tinyMCE.getParentElement(elm, "a"); 1274 tinyMCE.imgElement = tinyMCE.getParentElement(elm, "img"); 1275 tinyMCE.selectedElement = elm; 1276 1277 // Update visualaids on tabs 1278 if (tinyMCE.isGecko && e.type == "keyup" && e.keyCode == 9) 1279 tinyMCE.handleVisualAid(tinyMCE.selectedInstance.getBody(), true, tinyMCE.settings['visual'], tinyMCE.selectedInstance); 1280 1281 // Fix empty elements on return/enter, check where enter occured 1282 if (tinyMCE.isIE && e.type == "keydown" && e.keyCode == 13) 1283 tinyMCE.enterKeyElement = tinyMCE.selectedInstance.getFocusElement(); 1284 1285 // Fix empty elements on return/enter 1286 if (tinyMCE.isIE && e.type == "keyup" && e.keyCode == 13) { 1287 var elm = tinyMCE.enterKeyElement; 1288 if (elm) { 1289 var re = new RegExp('^HR|IMG|BR$','g'); // Skip these 1290 var dre = new RegExp('^H[1-6]$','g'); // Add double on these 1291 1292 if (!elm.hasChildNodes() && !re.test(elm.nodeName)) { 1293 if (dre.test(elm.nodeName)) 1294 elm.innerHTML = " "; 1295 else 1296 elm.innerHTML = " "; 1297 } 1298 } 1299 } 1300 1301 // Check if it's a position key 1302 var keys = tinyMCE.posKeyCodes; 1303 var posKey = false; 1304 for (var i=0; i<keys.length; i++) { 1305 if (keys[i] == e.keyCode) { 1306 posKey = true; 1307 break; 1308 } 1309 } 1310 1311 // MSIE custom key handling 1312 if (tinyMCE.isIE && tinyMCE.settings['custom_undo_redo']) { 1313 var keys = new Array(8,46); // Backspace,Delete 1314 1315 for (var i=0; i<keys.length; i++) { 1316 if (keys[i] == e.keyCode) { 1317 if (e.type == "keyup") 1318 tinyMCE.triggerNodeChange(false); 1319 } 1320 } 1321 } 1322 1323 // If Ctrl key 1324 if (e.keyCode == 17) 1325 return true; 1326 1327 // Handle Undo/Redo when typing content 1328 1329 if (tinyMCE.isGecko) { 1330 // Start typing (not a position key or ctrl key, but ctrl+x and ctrl+p is ok) 1331 if (!posKey && e.type == "keyup" && !e.ctrlKey || (e.ctrlKey && (e.keyCode == 86 || e.keyCode == 88))) 1332 tinyMCE.execCommand("mceStartTyping"); 1333 } else { 1334 // IE seems to be working better with this setting 1335 if (!posKey && e.type == "keyup") 1336 tinyMCE.execCommand("mceStartTyping"); 1337 } 1338 1339 // Store undo bookmark 1340 if (e.type == "keydown" && (posKey || e.ctrlKey) && inst) 1341 inst.undoBookmark = inst.selection.getBookmark(); 1342 1343 // End typing (position key) or some Ctrl event 1344 if (e.type == "keyup" && (posKey || e.ctrlKey)) 1345 tinyMCE.execCommand("mceEndTyping"); 1346 1347 if (posKey && e.type == "keyup") 1348 tinyMCE.triggerNodeChange(false); 1349 1350 if (tinyMCE.isIE && e.ctrlKey) 1351 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1); 1352 break; 1353 1354 case "mousedown": 1355 case "mouseup": 1356 case "click": 1357 case "dblclick": 1358 case "focus": 1359 tinyMCE.hideMenus(); 1360 1361 if (tinyMCE.selectedInstance) { 1362 tinyMCE.selectedInstance.switchSettings(); 1363 tinyMCE.selectedInstance.isFocused = true; 1364 } 1365 1366 // Check instance event trigged on 1367 var targetBody = tinyMCE.getParentElement(e.target, "html"); 1368 for (var instanceName in tinyMCE.instances) { 1369 if (!tinyMCE.isInstance(tinyMCE.instances[instanceName])) 1370 continue; 1371 1372 var inst = tinyMCE.instances[instanceName]; 1373 1374 // Reset design mode if lost (on everything just in case) 1375 inst.autoResetDesignMode(); 1376 1377 // Use HTML element since users might click outside of body element 1378 if (inst.getBody().parentNode == targetBody) { 1379 inst.select(); 1380 tinyMCE.selectedElement = e.target; 1381 tinyMCE.linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a"); 1382 tinyMCE.imgElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "img"); 1383 break; 1384 } 1385 } 1386 1387 // Add first bookmark location 1388 if (!tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark && (e.type == "mouseup" || e.type == "dblclick")) 1389 tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark = tinyMCE.selectedInstance.selection.getBookmark(); 1390 1391 // Reset selected node 1392 if (e.type != "focus") 1393 tinyMCE.selectedNode = null; 1394 1395 tinyMCE.triggerNodeChange(false); 1396 tinyMCE.execCommand("mceEndTyping"); 1397 1398 if (e.type == "mouseup") 1399 tinyMCE.execCommand("mceAddUndoLevel"); 1400 1401 // Just in case 1402 if (!tinyMCE.selectedInstance && e.target.editorId) 1403 tinyMCE.instances[e.target.editorId].select(); 1404 1405 return false; 1406 break; 1407 } 1408 }, 1409 1410 getButtonHTML : function(id, lang, img, cmd, ui, val) { 1411 var h = '', m, x, io = ''; 1412 1413 cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\''; 1414 1415 if (typeof(ui) != "undefined" && ui != null) 1416 cmd += ',' + ui; 1417 1418 if (typeof(val) != "undefined" && val != null) 1419 cmd += ",'" + val + "'"; 1420 1421 cmd += ');'; 1422 1423 // Patch for IE7 bug with hover out not restoring correctly 1424 if (tinyMCE.isRealIE) 1425 io = 'onmouseover="tinyMCE.lastHover = this;"'; 1426 1427 // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled 1428 if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = this.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) { 1429 // Tiled button 1430 x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20); 1431 h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceTiledButton mceButtonNormal" target="_self">'; 1432 h += '<img src="{$themeurl}/images/spacer.gif" style="background-position: ' + x + 'px 0" title="{$' + lang + '}" />'; 1433 h += '</a>'; 1434 } else { 1435 // Normal button 1436 h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceButtonNormal" target="_self">'; 1437 h += '<img src="' + img + '" title="{$' + lang + '}" />'; 1438 h += '</a>'; 1439 } 1440 1441 return h; 1442 }, 1443 1444 getMenuButtonHTML : function(id, lang, img, mcmd, cmd, ui, val) { 1445 var h = '', m, x; 1446 1447 mcmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + mcmd + '\');'; 1448 cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\''; 1449 1450 if (typeof(ui) != "undefined" && ui != null) 1451 cmd += ',' + ui; 1452 1453 if (typeof(val) != "undefined" && val != null) 1454 cmd += ",'" + val + "'"; 1455 1456 cmd += ');'; 1457 1458 // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled 1459 if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = tinyMCE.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) { 1460 x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20); 1461 1462 if (tinyMCE.isRealIE) 1463 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">'; 1464 else 1465 h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton">'; 1466 1467 h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceTiledButton mceMenuButtonNormal" target="_self">'; 1468 h += '<img src="{$themeurl}/images/spacer.gif" style="width: 20px; height: 20px; background-position: ' + x + 'px 0" title="{$' + lang + '}" /></a>'; 1469 h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />'; 1470 h += '</a></span>'; 1471 } else { 1472 if (tinyMCE.isRealIE) 1473 h += '<span id="{$editor_id}_' + id + '" dir="ltr" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">'; 1474 else 1475 h += '<span id="{$editor_id}_' + id + '" dir="ltr" class="mceMenuButton">'; 1476 1477 h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceMenuButtonNormal" target="_self">'; 1478 h += '<img src="' + img + '" title="{$' + lang + '}" /></a>'; 1479 h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />'; 1480 h += '</a></span>'; 1481 } 1482 1483 return h; 1484 }, 1485 1486 _menuButtonEvent : function(e, o) { 1487 if (o.className == 'mceMenuButtonFocus') 1488 return; 1489 1490 if (e == 'over') 1491 o.className = o.className + ' mceMenuHover'; 1492 else 1493 o.className = o.className.replace(/\s.*$/, ''); 1494 }, 1495 1496 addButtonMap : function(m) { 1497 var i, a = m.replace(/\s+/, '').split(','); 1498 1499 for (i=0; i<a.length; i++) 1500 this.buttonMap[a[i]] = i; 1501 }, 1502 1503 submitPatch : function() { 1504 tinyMCE.removeTinyMCEFormElements(this); 1505 tinyMCE.triggerSave(); 1506 tinyMCE.isNotDirty = true; 1507 this.mceOldSubmit(); 1508 }, 1509 1510 onLoad : function() { 1511 var r; 1512 1513 // Wait for everything to be loaded first 1514 if (tinyMCE.settings.strict_loading_mode && this.loadingIndex != -1) { 1515 window.setTimeout('tinyMCE.onLoad();', 1); 1516 return; 1517 } 1518 1519 if (tinyMCE.isRealIE && window.event.type == "readystatechange" && document.readyState != "complete") 1520 return true; 1521 1522 if (tinyMCE.isLoaded) 1523 return true; 1524 1525 tinyMCE.isLoaded = true; 1526 1527 // IE produces JS error if TinyMCE is placed in a frame 1528 // It seems to have something to do with the selection not beeing 1529 // correctly initialized in IE so this hack solves the problem 1530 if (tinyMCE.isRealIE && document.body) { 1531 r = document.body.createTextRange(); 1532 r.collapse(true); 1533 r.select(); 1534 } 1535 1536 tinyMCE.dispatchCallback(null, 'onpageload', 'onPageLoad'); 1537 1538 for (var c=0; c<tinyMCE.configs.length; c++) { 1539 tinyMCE.settings = tinyMCE.configs[c]; 1540 1541 var selector = tinyMCE.getParam("editor_selector"); 1542 var deselector = tinyMCE.getParam("editor_deselector"); 1543 var elementRefAr = new Array(); 1544 1545 // Add submit triggers 1546 if (document.forms && tinyMCE.settings['add_form_submit_trigger'] && !tinyMCE.submitTriggers) { 1547 for (var i=0; i<document.forms.length; i++) { 1548 var form = document.forms[i]; 1549 1550 tinyMCE.addEvent(form, "submit", TinyMCE_Engine.prototype.handleEvent); 1551 tinyMCE.addEvent(form, "reset", TinyMCE_Engine.prototype.handleEvent); 1552 tinyMCE.submitTriggers = true; // Do it only once 1553 1554 // Patch the form.submit function 1555 if (tinyMCE.settings['submit_patch']) { 1556 try { 1557 form.mceOldSubmit = form.submit; 1558 form.submit = TinyMCE_Engine.prototype.submitPatch; 1559 } catch (e) { 1560 // Do nothing 1561 } 1562 } 1563 } 1564 } 1565 1566 // Add editor instances based on mode 1567 var mode = tinyMCE.settings['mode']; 1568 switch (mode) { 1569 case "exact": 1570 var elements = tinyMCE.getParam('elements', '', true, ','); 1571 1572 for (var i=0; i<elements.length; i++) { 1573 var element = tinyMCE._getElementById(elements[i]); 1574 var trigger = element ? element.getAttribute(tinyMCE.settings['textarea_trigger']) : ""; 1575 1576 if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(element, "class"))) 1577 continue; 1578 1579 if (trigger == "false") 1580 continue; 1581 1582 if ((tinyMCE.settings['ask'] || tinyMCE.settings['convert_on_click']) && element) { 1583 elementRefAr[elementRefAr.length] = element; 1584 continue; 1585 } 1586 1587 if (element) 1588 tinyMCE.addMCEControl(element, elements[i]); 1589 else if (tinyMCE.settings['debug']) 1590 alert("Error: Could not find element by id or name: " + elements[i]); 1591 } 1592 break; 1593 1594 case "specific_textareas": 1595 case "textareas": 1596 var nodeList = document.getElementsByTagName("textarea"); 1597 1598 for (var i=0; i<nodeList.length; i++) { 1599 var elm = nodeList.item(i); 1600 var trigger = elm.getAttribute(tinyMCE.settings['textarea_trigger']); 1601 1602 if (selector != '' && !new RegExp('\\b' + selector + '\\b').test(tinyMCE.getAttrib(elm, "class"))) 1603 continue; 1604 1605 if (selector != '') 1606 trigger = selector != "" ? "true" : ""; 1607 1608 if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(elm, "class"))) 1609 continue; 1610 1611 if ((mode == "specific_textareas" && trigger == "true") || (mode == "textareas" && trigger != "false")) 1612 elementRefAr[elementRefAr.length] = elm; 1613 } 1614 break; 1615 } 1616 1617 for (var i=0; i<elementRefAr.length; i++) { 1618 var element = elementRefAr[i]; 1619 var elementId = element.name ? element.name : element.id; 1620 1621 if (tinyMCE.settings['ask'] || tinyMCE.settings['convert_on_click']) { 1622 // Focus breaks in Mozilla 1623 if (tinyMCE.isGecko) { 1624 var settings = tinyMCE.settings; 1625 1626 tinyMCE.addEvent(element, "focus", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);}); 1627 1628 if (element.nodeName != "TEXTAREA" && element.nodeName != "INPUT") 1629 tinyMCE.addEvent(element, "click", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);}); 1630 // tinyMCE.addEvent(element, "mouseover", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);}); 1631 } else { 1632 var settings = tinyMCE.settings; 1633 1634 tinyMCE.addEvent(element, "focus", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); }); 1635 tinyMCE.addEvent(element, "click", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); }); 1636 // tinyMCE.addEvent(element, "mouseenter", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); }); 1637 } 1638 } else 1639 tinyMCE.addMCEControl(element, elementId); 1640 } 1641 1642 // Handle auto focus 1643 if (tinyMCE.settings['auto_focus']) { 1644 window.setTimeout(function () { 1645 var inst = tinyMCE.getInstanceById(tinyMCE.settings['auto_focus']); 1646 inst.selection.selectNode(inst.getBody(), true, true); 1647 inst.contentWindow.focus(); 1648 }, 100); 1649 } 1650 1651 tinyMCE.dispatchCallback(null, 'oninit', 'onInit'); 1652 } 1653 }, 1654 1655 isInstance : function(o) { 1656 return o != null && typeof(o) == "object" && o.isTinyMCE_Control; 1657 }, 1658 1659 getParam : function(name, default_value, strip_whitespace, split_chr) { 1660 var value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name]; 1661 1662 // Fix bool values 1663 if (value == "true" || value == "false") 1664 return (value == "true"); 1665 1666 if (strip_whitespace) 1667 value = tinyMCE.regexpReplace(value, "[ \t\r\n]", ""); 1668 1669 if (typeof(split_chr) != "undefined" && split_chr != null) { 1670 value = value.split(split_chr); 1671 var outArray = new Array(); 1672 1673 for (var i=0; i<value.length; i++) { 1674 if (value[i] && value[i] != "") 1675 outArray[outArray.length] = value[i]; 1676 } 1677 1678 value = outArray; 1679 } 1680 1681 return value; 1682 }, 1683 1684 getLang : function(name, default_value, parse_entities, va) { 1685 var v = (typeof(tinyMCELang[name]) == "undefined") ? default_value : tinyMCELang[name], n; 1686 1687 if (parse_entities) 1688 v = tinyMCE.entityDecode(v); 1689 1690 if (va) { 1691 for (n in va) 1692 v = this.replaceVar(v, n, va[n]); 1693 } 1694 1695 return v; 1696 }, 1697 1698 entityDecode : function(s) { 1699 var e = document.createElement("div"); 1700 1701 e.innerHTML = s; 1702 1703 return e.firstChild.nodeValue; 1704 }, 1705 1706 addToLang : function(prefix, ar) { 1707 for (var key in ar) { 1708 if (typeof(ar[key]) == 'function') 1709 continue; 1710 1711 tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = ar[key]; 1712 } 1713 1714 this.loadNextScript(); 1715 1716 // for (var key in ar) 1717 // tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = "|" + ar[key] + "|"; 1718 }, 1719 1720 triggerNodeChange : function(focus, setup_content) { 1721 var elm, inst, editorId, undoIndex = -1, undoLevels = -1, doc, anySelection = false, st; 1722 1723 if (tinyMCE.selectedInstance) { 1724 inst = tinyMCE.selectedInstance; 1725 elm = (typeof(setup_content) != "undefined" && setup_content) ? tinyMCE.selectedElement : inst.getFocusElement(); 1726 1727 /* if (elm == inst.lastTriggerEl) 1728 return; 1729 1730 inst.lastTriggerEl = elm;*/ 1731 1732 editorId = inst.editorId; 1733 st = inst.selection.getSelectedText(); 1734 1735 if (tinyMCE.settings.auto_resize) 1736 inst.resizeToContent(); 1737 1738 if (setup_content && tinyMCE.isGecko && inst.isHidden()) 1739 elm = inst.getBody(); 1740 1741 inst.switchSettings(); 1742 1743 if (tinyMCE.selectedElement) 1744 anySelection = (tinyMCE.selectedElement.nodeName.toLowerCase() == "img") || (st && st.length > 0); 1745 1746 if (tinyMCE.settings['custom_undo_redo']) { 1747 undoIndex = inst.undoRedo.undoIndex; 1748 undoLevels = inst.undoRedo.undoLevels.length; 1749 } 1750 1751 tinyMCE.dispatchCallback(inst, 'handle_node_change_callback', 'handleNodeChange', editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content); 1752 } 1753 1754 if (this.selectedInstance && (typeof(focus) == "undefined" || focus)) 1755 this.selectedInstance.contentWindow.focus(); 1756 }, 1757 1758 _customCleanup : function(inst, type, content) { 1759 var pl, po, i; 1760 1761 // Call custom cleanup 1762 var customCleanup = tinyMCE.settings['cleanup_callback']; 1763 if (customCleanup != "" && eval("typeof(" + customCleanup + ")") != "undefined") 1764 content = eval(customCleanup + "(type, content, inst);"); 1765 1766 // Trigger theme cleanup 1767 po = tinyMCE.themes[tinyMCE.settings['theme']]; 1768 if (po && po.cleanup) 1769 content = po.cleanup(type, content, inst); 1770 1771 // Trigger plugin cleanups 1772 pl = inst.plugins; 1773 for (i=0; i<pl.length; i++) { 1774 po = tinyMCE.plugins[pl[i]]; 1775 1776 if (po && po.cleanup) 1777 content = po.cleanup(type, content, inst); 1778 } 1779 1780 return content; 1781 }, 1782 1783 setContent : function(h) { 1784 if (tinyMCE.selectedInstance) { 1785 tinyMCE.selectedInstance.execCommand('mceSetContent', false, h); 1786 tinyMCE.selectedInstance.repaint(); 1787 } 1788 }, 1789 1790 importThemeLanguagePack : function(name) { 1791 if (typeof(name) == "undefined") 1792 name = tinyMCE.settings['theme']; 1793 1794 tinyMCE.loadScript(tinyMCE.baseURL + '/themes/' + name + '/langs/' + tinyMCE.settings['language'] + '.js'); 1795 }, 1796 1797 importPluginLanguagePack : function(name) { 1798 var b = tinyMCE.baseURL + '/plugins/' + name; 1799 1800 if (this.plugins[name]) 1801 b = this.plugins[name].baseURL; 1802 1803 tinyMCE.loadScript(b + '/langs/' + tinyMCE.settings['language'] + '.js'); 1804 }, 1805 1806 applyTemplate : function(h, as) { 1807 return h.replace(new RegExp('\\{\\$([a-z0-9_]+)\\}', 'gi'), function(m, s) { 1808 if (s.indexOf('lang_') == 0 && tinyMCELang[s]) 1809 return tinyMCELang[s]; 1810 1811 if (as && as[s]) 1812 return as[s]; 1813 1814 if (tinyMCE.settings[s]) 1815 return tinyMCE.settings[s]; 1816 1817 if (m == 'themeurl') 1818 return tinyMCE.themeURL; 1819 1820 return m; 1821 }); 1822 }, 1823 1824 replaceVar : function(h, r, v) { 1825 return h.replace(new RegExp('{\\\$' + r + '}', 'g'), v); 1826 }, 1827 1828 openWindow : function(template, args) { 1829 var html, width, height, x, y, resizable, scrollbars, url; 1830 1831 args = !args ? {} : args; 1832 1833 args['mce_template_file'] = template['file']; 1834 args['mce_width'] = template['width']; 1835 args['mce_height'] = template['height']; 1836 tinyMCE.windowArgs = args; 1837 1838 html = template['html']; 1839 if (!(width = parseInt(template['width']))) 1840 width = 320; 1841 1842 if (!(height = parseInt(template['height']))) 1843 height = 200; 1844 1845 // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!! 1846 if (tinyMCE.isIE) 1847 height += 40; 1848 else 1849 height += 20; 1850 1851 x = parseInt(screen.width / 2.0) - (width / 2.0); 1852 y = parseInt(screen.height / 2.0) - (height / 2.0); 1853 1854 resizable = (args && args['resizable']) ? args['resizable'] : "no"; 1855 scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no"; 1856 1857 if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1) 1858 url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file']; 1859 else 1860 url = template['file']; 1861 1862 // Replace all args as variables in URL 1863 for (var name in args) { 1864 if (typeof(args[name]) == 'function') 1865 continue; 1866 1867 url = tinyMCE.replaceVar(url, name, escape(args[name])); 1868 } 1869 1870 if (html) { 1871 html = tinyMCE.replaceVar(html, "css", this.settings['popups_css']); 1872 html = tinyMCE.applyTemplate(html, args); 1873 1874 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); 1875 if (win == null) { 1876 alert(tinyMCELang['lang_popup_blocked']); 1877 return; 1878 } 1879 1880 win.document.write(html); 1881 win.document.close(); 1882 win.resizeTo(width, height); 1883 win.focus(); 1884 } else { 1885 if ((tinyMCE.isRealIE) && resizable != 'yes' && tinyMCE.settings["dialog_type"] == "modal") { 1886 height += 10; 1887 1888 var features = "resizable:" + resizable 1889 + ";scroll:" 1890 + scrollbars + ";status:yes;center:yes;help:no;dialogWidth:" 1891 + width + "px;dialogHeight:" + height + "px;"; 1892 1893 window.showModalDialog(url, window, features); 1894 } else { 1895 var modal = (resizable == "yes") ? "no" : "yes"; 1896 1897 if (tinyMCE.isGecko && tinyMCE.isMac) 1898 modal = "no"; 1899 1900 if (template['close_previous'] != "no") 1901 try {tinyMCE.lastWindow.close();} catch (ex) {} 1902 1903 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); 1904 if (win == null) { 1905 alert(tinyMCELang['lang_popup_blocked']); 1906 return; 1907 } 1908 1909 if (template['close_previous'] != "no") 1910 tinyMCE.lastWindow = win; 1911 1912 eval('try { win.resizeTo(width, height); } catch(e) { }'); 1913 1914 // Make it bigger if statusbar is forced 1915 if (tinyMCE.isGecko) { 1916 if (win.document.defaultView.statusbar.visible) 1917 win.resizeBy(0, tinyMCE.isMac ? 10 : 24); 1918 } 1919 1920 win.focus(); 1921 } 1922 } 1923 }, 1924 1925 closeWindow : function(win) { 1926 win.close(); 1927 }, 1928 1929 getVisualAidClass : function(class_name, state) { 1930 var aidClass = tinyMCE.settings['visual_table_class']; 1931 1932 if (typeof(state) == "undefined") 1933 state = tinyMCE.settings['visual']; 1934 1935 // Split 1936 var classNames = new Array(); 1937 var ar = class_name.split(' '); 1938 for (var i=0; i<ar.length; i++) { 1939 if (ar[i] == aidClass) 1940 ar[i] = ""; 1941 1942 if (ar[i] != "") 1943 classNames[classNames.length] = ar[i]; 1944 } 1945 1946 if (state) 1947 classNames[classNames.length] = aidClass; 1948 1949 // Glue 1950 var className = ""; 1951 for (var i=0; i<classNames.length; i++) { 1952 if (i > 0) 1953 className += " "; 1954 1955 className += classNames[i]; 1956 } 1957 1958 return className; 1959 }, 1960 1961 handleVisualAid : function(el, deep, state, inst, skip_dispatch) { 1962 if (!el) 1963 return; 1964 1965 if (!skip_dispatch) 1966 tinyMCE.dispatchCallback(inst, 'handle_visual_aid_callback', 'handleVisualAid', el, deep, state, inst); 1967 1968 var tableElement = null; 1969 1970 switch (el.nodeName) { 1971 case "TABLE": 1972 var oldW = el.style.width; 1973 var oldH = el.style.height; 1974 var bo = tinyMCE.getAttrib(el, "border"); 1975 1976 bo = bo == "" || bo == "0" ? true : false; 1977 1978 tinyMCE.setAttrib(el, "class", tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el, "class"), state && bo)); 1979 1980 el.style.width = oldW; 1981 el.style.height = oldH; 1982 1983 for (var y=0; y<el.rows.length; y++) { 1984 for (var x=0; x<el.rows[y].cells.length; x++) { 1985 var cn = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el.rows[y].cells[x], "class"), state && bo); 1986 tinyMCE.setAttrib(el.rows[y].cells[x], "class", cn); 1987 } 1988 } 1989 1990 break; 1991 1992 case "A": 1993 var anchorName = tinyMCE.getAttrib(el, "name"); 1994 1995 if (anchorName != '' && state) { 1996 el.title = anchorName; 1997 tinyMCE.addCSSClass(el, 'mceItemAnchor'); 1998 } else if (anchorName != '' && !state) 1999 el.className = ''; 2000 2001 break; 2002 } 2003 2004 if (deep && el.hasChildNodes()) { 2005 for (var i=0; i<el.childNodes.length; i++) 2006 tinyMCE.handleVisualAid(el.childNodes[i], deep, state, inst, true); 2007 } 2008 }, 2009 2010 /* 2011 applyClassesToFonts : function(doc, size) { 2012 var f = doc.getElementsByTagName("font"); 2013 for (var i=0; i<f.length; i++) { 2014 var s = tinyMCE.getAttrib(f[i], "size"); 2015 2016 if (s != "") 2017 tinyMCE.setAttrib(f[i], 'class', "mceItemFont" + s); 2018 } 2019 2020 if (typeof(size) != "undefined") { 2021 var css = ""; 2022 2023 for (var x=0; x<doc.styleSheets.length; x++) { 2024 for (var i=0; i<doc.styleSheets[x].rules.length; i++) { 2025 if (doc.styleSheets[x].rules[i].selectorText == '#mceSpanFonts .mceItemFont' + size) { 2026 css = doc.styleSheets[x].rules[i].style.cssText; 2027 break; 2028 } 2029 } 2030 2031 if (css != "") 2032 break; 2033 } 2034 2035 if (doc.styleSheets[0].rules[0].selectorText == "FONT") 2036 doc.styleSheets[0].removeRule(0); 2037 2038 doc.styleSheets[0].addRule("FONT", css, 0); 2039 } 2040 }, 2041 */ 2042 2043 fixGeckoBaseHREFBug : function(m, e, h) { 2044 var xsrc, xhref; 2045 2046 if (tinyMCE.isGecko) { 2047 if (m == 1) { 2048 h = h.replace(/\ssrc=/gi, " mce_tsrc="); 2049 h = h.replace(/\shref=/gi, " mce_thref="); 2050 2051 return h; 2052 } else { 2053 // Why bother if there is no src or href broken 2054 if (!new RegExp('(src|href)=', 'g').test(h)) 2055 return h; 2056 2057 // Restore src and href that gets messed up by Gecko 2058 tinyMCE.selectElements(e, 'A,IMG,SELECT,AREA,IFRAME,BASE,INPUT,SCRIPT,EMBED,OBJECT,LINK', function (n) { 2059 xsrc = tinyMCE.getAttrib(n, "mce_tsrc"); 2060 xhref = tinyMCE.getAttrib(n, "mce_thref"); 2061 2062 if (xsrc != "") { 2063 try { 2064 n.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xsrc); 2065 } catch (e) { 2066 // Ignore, Firefox cast exception if local file wasn't found 2067 } 2068 2069 n.removeAttribute("mce_tsrc"); 2070 } 2071 2072 if (xhref != "") { 2073 try { 2074 n.href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xhref); 2075 } catch (e) { 2076 // Ignore, Firefox cast exception if local file wasn't found 2077 } 2078 2079 n.removeAttribute("mce_thref"); 2080 } 2081 2082 return false; 2083 }); 2084 2085 // Restore text/comment nodes 2086 tinyMCE.selectNodes(e, function(n) { 2087 if (n.nodeType == 3 || n.nodeType == 8) { 2088 n.nodeValue = n.nodeValue.replace(/\smce_tsrc=/gi, " src="); 2089 n.nodeValue = n.nodeValue.replace(/\smce_thref=/gi, " href="); 2090 } 2091 2092 return false; 2093 }); 2094 } 2095 } 2096 2097 return h; 2098 }, 2099 2100 _setHTML : function(doc, html_content) { 2101 // Force closed anchors open 2102 //html_content = html_content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>'); 2103 2104 html_content = tinyMCE.cleanupHTMLCode(html_content); 2105 2106 // Try innerHTML if it fails use pasteHTML in MSIE 2107 try { 2108 tinyMCE.setInnerHTML(doc.body, html_content); 2109 } catch (e) { 2110 if (this.isMSIE) 2111 doc.body.createTextRange().pasteHTML(html_content); 2112 } 2113 2114 // Content duplication bug fix 2115 if (tinyMCE.isIE && tinyMCE.settings['fix_content_duplication']) { 2116 // Remove P elements in P elements 2117 var paras = doc.getElementsByTagName("P"); 2118 for (var i=0; i<paras.length; i++) { 2119 var node = paras[i]; 2120 while ((node = node.parentNode) != null) { 2121 if (node.nodeName == "P") 2122 node.outerHTML = node.innerHTML; 2123 } 2124 } 2125 2126 // Content duplication bug fix (Seems to be word crap) 2127 var html = doc.body.innerHTML; 2128 /* 2129 if (html.indexOf('="mso') != -1) { 2130 for (var i=0; i<doc.body.all.length; i++) { 2131 var el = doc.body.all[i]; 2132 el.removeAttribute("className","",0); 2133 el.removeAttribute("style","",0); 2134 } 2135 2136 html = doc.body.innerHTML; 2137 html = tinyMCE.regexpReplace(html, "<o:p><\/o:p>", "<br />"); 2138 html = tinyMCE.regexpReplace(html, "<o:p> <\/o:p>", ""); 2139 html = tinyMCE.regexpReplace(html, "<st1:.*?>", ""); 2140 html = tinyMCE.regexpReplace(html, "<p><\/p>", ""); 2141 html = tinyMCE.regexpReplace(html, "<p><\/p>\r\n<p><\/p>", ""); 2142 html = tinyMCE.regexpReplace(html, "<p> <\/p>", "<br />"); 2143 html = tinyMCE.regexpReplace(html, "<p>\s*(<p>\s*)?", "<p>"); 2144 html = tinyMCE.regexpReplace(html, "<\/p>\s*(<\/p>\s*)?", "</p>"); 2145 }*/ 2146 2147 // Always set the htmlText output 2148 tinyMCE.setInnerHTML(doc.body, html); 2149 } 2150 2151 tinyMCE.cleanupAnchors(doc); 2152 2153 if (tinyMCE.getParam("convert_fonts_to_spans")) 2154 tinyMCE.convertSpansToFonts(doc); 2155 }, 2156 2157 getEditorId : function(form_element) { 2158 var inst = this.getInstanceById(form_element); 2159 if (!inst) 2160 return null; 2161 2162 return inst.editorId; 2163 }, 2164 2165 getInstanceById : function(editor_id) { 2166 var inst = this.instances[editor_id]; 2167 if (!inst) { 2168 for (var n in tinyMCE.instances) { 2169 var instance = tinyMCE.instances[n]; 2170 if (!tinyMCE.isInstance(instance)) 2171 continue; 2172 2173 if (instance.formTargetElementId == editor_id) { 2174 inst = instance; 2175 break; 2176 } 2177 } 2178 } 2179 2180 return inst; 2181 }, 2182 2183 queryInstanceCommandValue : function(editor_id, command) { 2184 var inst = tinyMCE.getInstanceById(editor_id); 2185 if (inst) 2186 return inst.queryCommandValue(command); 2187 2188 return false; 2189 }, 2190 2191 queryInstanceCommandState : function(editor_id, command) { 2192 var inst = tinyMCE.getInstanceById(editor_id); 2193 if (inst) 2194 return inst.queryCommandState(command); 2195 2196 return null; 2197 }, 2198 2199 setWindowArg : function(n, v) { 2200 this.windowArgs[n] = v; 2201 }, 2202 2203 getWindowArg : function(n, d) { 2204 return (typeof(this.windowArgs[n]) == "undefined") ? d : this.windowArgs[n]; 2205 }, 2206 2207 getCSSClasses : function(editor_id, doc) { 2208 var inst = tinyMCE.getInstanceById(editor_id); 2209 2210 // Is cached, use that 2211 if (inst && inst.cssClasses.length > 0) 2212 return inst.cssClasses; 2213 2214 if (typeof(editor_id) == "undefined" && typeof(doc) == "undefined") { 2215 var instance; 2216 2217 for (var instanceName in tinyMCE.instances) { 2218 instance = tinyMCE.instances[instanceName]; 2219 if (!tinyMCE.isInstance(instance)) 2220 continue; 2221 2222 break; 2223 } 2224 2225 doc = instance.getDoc(); 2226 } 2227 2228 if (typeof(doc) == "undefined") { 2229 var instance = tinyMCE.getInstanceById(editor_id); 2230 doc = instance.getDoc(); 2231 } 2232 2233 if (doc) { 2234 var styles = doc.styleSheets; 2235 2236 if (styles && styles.length > 0) { 2237 for (var x=0; x<styles.length; x++) { 2238 var csses = null; 2239 2240 // Just ignore any errors 2241 eval("try {var csses = tinyMCE.isIE ? doc.styleSheets(" + x + ").rules : styles[" + x + "].cssRules;} catch(e) {}"); 2242 if (!csses) 2243 return new Array(); 2244 2245 for (var i=0; i<csses.length; i++) { 2246 var selectorText = csses[i].selectorText; 2247 2248 // Can be multiple rules per selector 2249 if (selectorText) { 2250 var rules = selectorText.split(','); 2251 for (var c=0; c<rules.length; c++) { 2252 var rule = rules[c]; 2253 2254 // Strip spaces between selectors 2255 while (rule.indexOf(' ') == 0) 2256 rule = rule.substring(1); 2257 2258 // Invalid rule 2259 if (rule.indexOf(' ') != -1 || rule.indexOf(':') != -1 || rule.indexOf('mceItem') != -1) 2260 continue; 2261 2262 if (rule.indexOf(tinyMCE.settings['visual_table_class']) != -1 || rule.indexOf('mceEditable') != -1 || rule.indexOf('mceNonEditable') != -1) 2263 continue; 2264 2265 // Is class rule 2266 if (rule.indexOf('.') != -1) { 2267 var cssClass = rule.substring(rule.indexOf('.') + 1); 2268 var addClass = true; 2269 2270 for (var p=0; p<inst.cssClasses.length && addClass; p++) { 2271 if (inst.cssClasses[p] == cssClass) 2272 addClass = false; 2273 } 2274 2275 if (addClass) 2276 inst.cssClasses[inst.cssClasses.length] = cssClass; 2277 } 2278 } 2279 } 2280 } 2281 } 2282 } 2283 } 2284 2285 return inst.cssClasses; 2286 }, 2287 2288 regexpReplace : function(in_str, reg_exp, replace_str, opts) { 2289 if (in_str == null) 2290 return in_str; 2291 2292 if (typeof(opts) == "undefined") 2293 opts = 'g'; 2294 2295 var re = new RegExp(reg_exp, opts); 2296 return in_str.replace(re, replace_str); 2297 }, 2298 2299 trim : function(s) { 2300 return s.replace(/^\s*|\s*$/g, ""); 2301 }, 2302 2303 cleanupEventStr : function(s) { 2304 s = "" + s; 2305 s = s.replace('function anonymous()\n{\n', ''); 2306 s = s.replace('\n}', ''); 2307 s = s.replace(/^return true;/gi, ''); // Remove event blocker 2308 2309 return s; 2310 }, 2311 2312 getControlHTML : function(c) { 2313 var i, l, n, o, v, rtl = tinyMCE.getLang('lang_dir') == 'rtl'; 2314 2315 l = tinyMCE.plugins; 2316 for (n in l) { 2317 o = l[n]; 2318 2319 if (o.getControlHTML && (v = o.getControlHTML(c)) != '') { 2320 if (rtl) 2321 return '<span dir="rtl">' + tinyMCE.replaceVar(v, "pluginurl", o.baseURL) + '</span>'; 2322 2323 return tinyMCE.replaceVar(v, "pluginurl", o.baseURL); 2324 } 2325 } 2326 2327 o = tinyMCE.themes[tinyMCE.settings['theme']]; 2328 if (o.getControlHTML && (v = o.getControlHTML(c)) != '') { 2329 if (rtl) 2330 return '<span dir="rtl">' + v + '</span>'; 2331 2332 return v; 2333 } 2334 2335 return ''; 2336 }, 2337 2338 evalFunc : function(f, idx, a, o) { 2339 o = !o ? window : o; 2340 f = typeof(f) == 'function' ? f : o[f]; 2341 2342 return f.apply(o, Array.prototype.slice.call(a, idx)); 2343 }, 2344 2345 dispatchCallback : function(i, p, n) { 2346 return this.callFunc(i, p, n, 0, this.dispatchCallback.arguments); 2347 }, 2348 2349 executeCallback : function(i, p, n) { 2350 return this.callFunc(i, p, n, 1, this.executeCallback.arguments); 2351 }, 2352 2353 execCommandCallback : function(i, p, n) { 2354 return this.callFunc(i, p, n, 2, this.execCommandCallback.arguments); 2355 }, 2356 2357 callFunc : function(ins, p, n, m, a) { 2358 var l, i, on, o, s, v; 2359 2360 s = m == 2; 2361 2362 l = tinyMCE.getParam(p, ''); 2363 2364 if (l != '' && (v = tinyMCE.evalFunc(l, 3, a)) == s && m > 0) 2365 return true; 2366 2367 if (ins != null) { 2368 for (i=0, l = ins.plugins; i<l.length; i++) { 2369 o = tinyMCE.plugins[l[i]]; 2370 2371 if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0) 2372 return true; 2373 } 2374 } 2375 2376 l = tinyMCE.themes; 2377 for (on in l) { 2378 o = l[on]; 2379 2380 if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0) 2381 return true; 2382 } 2383 2384 return false; 2385 }, 2386 2387 xmlEncode : function(s, skip_apos) { 2388 return s ? ('' + s).replace(!skip_apos ? this.xmlEncodeAposRe : this.xmlEncodeRe, function (c, b) { 2389 switch (c) { 2390 case '&': 2391 return '&'; 2392 2393 case '"': 2394 return '"'; 2395 2396 case '\'': 2397 return '''; // ' is not working in MSIE 2398 2399 case '<': 2400 return '<'; 2401 2402 case '>': 2403 return '>'; 2404 } 2405 2406 return c; 2407 }) : s; 2408 }, 2409 2410 extend : function(p, np) { 2411 var o = {}; 2412 2413 o.parent = p; 2414 2415 for (n in p) 2416 o[n] = p[n]; 2417 2418 for (n in np) 2419 o[n] = np[n]; 2420 2421 return o; 2422 }, 2423 2424 hideMenus : function() { 2425 var e = tinyMCE.lastSelectedMenuBtn; 2426 2427 if (tinyMCE.lastMenu) { 2428 tinyMCE.lastMenu.hide(); 2429 tinyMCE.lastMenu = null; 2430 } 2431 2432 if (e) { 2433 tinyMCE.switchClass(e, tinyMCE.lastMenuBtnClass); 2434 tinyMCE.lastSelectedMenuBtn = null; 2435 } 2436 } 2437 2438 }; 2439 2440 // Global instances 2441 var TinyMCE = TinyMCE_Engine; // Compatiblity with gzip compressors 2442 var tinyMCE = new TinyMCE_Engine(); 2443 var tinyMCELang = {}; 2444 2445 /* file:jscripts/tiny_mce/classes/TinyMCE_Control.class.js */ 2446 2447 function TinyMCE_Control(settings) { 2448 var t, i, to, fu, p, x, fn, fu, pn, s = settings; 2449 2450 this.undoRedoLevel = true; 2451 this.isTinyMCE_Control = true; 2452 2453 // Default settings 2454 this.settings = s; 2455 this.settings['theme'] = tinyMCE.getParam("theme", "default"); 2456 this.settings['width'] = tinyMCE.getParam("width", -1); 2457 this.settings['height'] = tinyMCE.getParam("height", -1); 2458 this.selection = new TinyMCE_Selection(this); 2459 this.undoRedo = new TinyMCE_UndoRedo(this); 2460 this.cleanup = new TinyMCE_Cleanup(); 2461 this.shortcuts = new Array(); 2462 this.hasMouseMoved = false; 2463 this.foreColor = this.backColor = "#999999"; 2464 this.data = {}; 2465 this.cssClasses = []; 2466 2467 this.cleanup.init({ 2468 valid_elements : s.valid_elements, 2469 extended_valid_elements : s.extended_valid_elements, 2470 valid_child_elements : s.valid_child_elements, 2471 entities : s.entities, 2472 entity_encoding : s.entity_encoding, 2473 debug : s.cleanup_debug, 2474 indent : s.apply_source_formatting, 2475 invalid_elements : s.invalid_elements, 2476 verify_html : s.verify_html, 2477 fix_content_duplication : s.fix_content_duplication, 2478 convert_fonts_to_spans : s.convert_fonts_to_spans 2479 }); 2480 2481 // Wrap old theme 2482 t = this.settings['theme']; 2483 if (!tinyMCE.hasTheme(t)) { 2484 fn = tinyMCE.callbacks; 2485 to = {}; 2486 2487 for (i=0; i<fn.length; i++) { 2488 if ((fu = window['TinyMCE_' + t + "_" + fn[i]])) 2489 to[fn[i]] = fu; 2490 } 2491 2492 tinyMCE.addTheme(t, to); 2493 } 2494 2495 // Wrap old plugins 2496 this.plugins = new Array(); 2497 p = tinyMCE.getParam('plugins', '', true, ','); 2498 if (p.length > 0) { 2499 for (i=0; i<p.length; i++) { 2500 pn = p[i]; 2501 2502 if (pn.charAt(0) == '-') 2503 pn = pn.substring(1); 2504 2505 if (!tinyMCE.hasPlugin(pn)) { 2506 fn = tinyMCE.callbacks; 2507 to = {}; 2508 2509 for (x=0; x<fn.length; x++) { 2510 if ((fu = window['TinyMCE_' + pn + "_" + fn[x]])) 2511 to[fn[x]] = fu; 2512 } 2513 2514 tinyMCE.addPlugin(pn, to); 2515 } 2516 2517 this.plugins[this.plugins.length] = pn; 2518 } 2519 } 2520 }; 2521 2522 TinyMCE_Control.prototype = { 2523 selection : null, 2524 2525 settings : null, 2526 2527 cleanup : null, 2528 2529 getData : function(na) { 2530 var o = this.data[na]; 2531 2532 if (!o) 2533 o = this.data[na] = {}; 2534 2535 return o; 2536 }, 2537 2538 hasPlugin : function(n) { 2539 var i; 2540 2541 for (i=0; i<this.plugins.length; i++) { 2542 if (this.plugins[i] == n) 2543 return true; 2544 } 2545 2546 return false; 2547 }, 2548 2549 addPlugin : function(n, p) { 2550 if (!this.hasPlugin(n)) { 2551 tinyMCE.addPlugin(n, p); 2552 this.plugins[this.plugins.length] = n; 2553 } 2554 }, 2555 2556 repaint : function() { 2557 var s, b, ex; 2558 2559 if (tinyMCE.isRealIE) 2560 return; 2561 2562 try { 2563 s = this.selection; 2564 b = s.getBookmark(true); 2565 this.getBody().style.display = 'none'; 2566 this.getDoc().execCommand('selectall', false, null); 2567 this.getSel().collapseToStart(); 2568 this.getBody().style.display = 'block'; 2569 s.moveToBookmark(b); 2570 } catch (ex) { 2571 // Ignore 2572 } 2573 }, 2574 2575 switchSettings : function() { 2576 if (tinyMCE.configs.length > 1 && tinyMCE.currentConfig != this.settings['index']) { 2577 tinyMCE.settings = this.settings; 2578 tinyMCE.currentConfig = this.settings['index']; 2579 } 2580 }, 2581 2582 select : function() { 2583 var oldInst = tinyMCE.selectedInstance; 2584 2585 if (oldInst != this) { 2586 if (oldInst) 2587 oldInst.execCommand('mceEndTyping'); 2588 2589 tinyMCE.dispatchCallback(this, 'select_instance_callback', 'selectInstance', this, oldInst); 2590 tinyMCE.selectedInstance = this; 2591 } 2592 }, 2593 2594 getBody : function() { 2595 return this.contentBody ? this.contentBody : this.getDoc().body; 2596 }, 2597 2598 getDoc : function() { 2599 // return this.contentDocument ? this.contentDocument : this.contentWindow.document; // Removed due to IE 5.5 ? 2600 return this.contentWindow.document; 2601 }, 2602 2603 getWin : function() { 2604 return this.contentWindow; 2605 }, 2606 2607 getContainerWin : function() { 2608 return this.containerWindow ? this.containerWindow : window; 2609 }, 2610 2611 getViewPort : function() { 2612 return tinyMCE.getViewPort(this.getWin()); 2613 }, 2614 2615 getParentNode : function(n, f) { 2616 return tinyMCE.getParentNode(n, f, this.getBody()); 2617 }, 2618 2619 getParentElement : function(n, na, f) { 2620 return tinyMCE.getParentElement(n, na, f, this.getBody()); 2621 }, 2622 2623 getParentBlockElement : function(n) { 2624 return tinyMCE.getParentBlockElement(n, this.getBody()); 2625 }, 2626 2627 resizeToContent : function() { 2628 var d = this.getDoc(), b = d.body, de = d.documentElement; 2629 2630 this.iframeElement.style.height = (tinyMCE.isRealIE) ? b.scrollHeight : de.offsetHeight + 'px'; 2631 }, 2632 2633 addShortcut : function(m, k, d, cmd, ui, va) { 2634 var n = typeof(k) == "number", ie = tinyMCE.isIE, c, sc, i, scl = this.shortcuts; 2635 2636 if (!tinyMCE.getParam('custom_shortcuts')) 2637 return false; 2638 2639 m = m.toLowerCase(); 2640 k = ie && !n ? k.toUpperCase() : k; 2641 c = n ? null : k.charCodeAt(0); 2642 d = d && d.indexOf('lang_') == 0 ? tinyMCE.getLang(d) : d; 2643 2644 sc = { 2645 alt : m.indexOf('alt') != -1, 2646 ctrl : m.indexOf('ctrl') != -1, 2647 shift : m.indexOf('shift') != -1, 2648 charCode : c, 2649 keyCode : n ? k : (ie ? c : null), 2650 desc : d, 2651 cmd : cmd, 2652 ui : ui, 2653 val : va 2654 }; 2655 2656 for (i=0; i<scl.length; i++) { 2657 if (sc.alt == scl[i].alt && sc.ctrl == scl[i].ctrl && sc.shift == scl[i].shift 2658 && sc.charCode == scl[i].charCode && sc.keyCode == scl[i].keyCode) { 2659 return false; 2660 } 2661 } 2662 2663 scl[scl.length] = sc; 2664 2665 return true; 2666 }, 2667 2668 handleShortcut : function(e) { 2669 var i, s, o; 2670 2671 // Normal key press, then ignore it 2672 if (!e.altKey && !e.ctrlKey) 2673 return false; 2674 2675 s = this.shortcuts; 2676 2677 for (i=0; i<s.length; i++) { 2678 o = s[i]; 2679 2680 if (o.alt == e.altKey && o.ctrl == e.ctrlKey && (o.keyCode == e.keyCode || o.charCode == e.charCode)) { 2681 if (o.cmd && (e.type == "keydown" || (e.type == "keypress" && !tinyMCE.isOpera))) 2682 tinyMCE.execCommand(o.cmd, o.ui, o.val); 2683 2684 tinyMCE.cancelEvent(e); 2685 return true; 2686 } 2687 } 2688 2689 return false; 2690 }, 2691 2692 autoResetDesignMode : function() { 2693 // Add fix for tab/style.display none/block problems in Gecko 2694 if (!tinyMCE.isIE && this.isHidden() && tinyMCE.getParam('auto_reset_designmode')) 2695 eval('try { this.getDoc().designMode = "On"; this.useCSS = false; } catch(e) {}'); 2696 }, 2697 2698 isHidden : function() { 2699 var s; 2700 2701 if (tinyMCE.isIE) 2702 return false; 2703 2704 s = this.getSel(); 2705 2706 // Weird, wheres that cursor selection? 2707 return (!s || !s.rangeCount || s.rangeCount == 0); 2708 }, 2709 2710 isDirty : function() { 2711 // Is content modified and not in a submit procedure 2712 return tinyMCE.trim(this.startContent) != tinyMCE.trim(this.getBody().innerHTML) && !tinyMCE.isNotDirty; 2713 }, 2714 2715 _mergeElements : function(scmd, pa, ch, override) { 2716 if (scmd == "removeformat") { 2717 pa.className = ""; 2718 pa.style.cssText = ""; 2719 ch.className = ""; 2720 ch.style.cssText = ""; 2721 return; 2722 } 2723 2724 var st = tinyMCE.parseStyle(tinyMCE.getAttrib(pa, "style")); 2725 var stc = tinyMCE.parseStyle(tinyMCE.getAttrib(ch, "style")); 2726 var className = tinyMCE.getAttrib(pa, "class"); 2727 2728 // Removed class adding due to bug #1478272 2729 className = tinyMCE.getAttrib(ch, "class"); 2730 2731 if (override) { 2732 for (var n in st) { 2733 if (typeof(st[n]) == 'function') 2734 continue; 2735 2736 stc[n] = st[n]; 2737 } 2738 } else { 2739 for (var n in stc) { 2740 if (typeof(stc[n]) == 'function') 2741 continue; 2742 2743 st[n] = stc[n]; 2744 } 2745 } 2746 2747 tinyMCE.setAttrib(pa, "style", tinyMCE.serializeStyle(st)); 2748 tinyMCE.setAttrib(pa, "class", tinyMCE.trim(className)); 2749 ch.className = ""; 2750 ch.style.cssText = ""; 2751 ch.removeAttribute("class"); 2752 ch.removeAttribute("style"); 2753 }, 2754 2755 _setUseCSS : function(b) { 2756 var d = this.getDoc(); 2757 2758 try {d.execCommand("useCSS", false, !b);} catch (ex) {} 2759 try {d.execCommand("styleWithCSS", false, b);} catch (ex) {} 2760 2761 if (!tinyMCE.getParam("table_inline_editing")) 2762 try {d.execCommand('enableInlineTableEditing', false, "false");} catch (ex) {} 2763 2764 if (!tinyMCE.getParam("object_resizing")) 2765 try {d.execCommand('enableObjectResizing', false, "false");} catch (ex) {} 2766 }, 2767 2768 execCommand : function(command, user_interface, value) { 2769 var doc = this.getDoc(), win = this.getWin(), focusElm = this.getFocusElement(); 2770 2771 // Is not a undo specific command 2772 if (!new RegExp('mceStartTyping|mceEndTyping|mceBeginUndoLevel|mceEndUndoLevel|mceAddUndoLevel', 'gi').test(command)) 2773 this.undoBookmark = null; 2774 2775 // Mozilla issue 2776 if (!tinyMCE.isIE && !this.useCSS) { 2777 this._setUseCSS(false); 2778 this.useCSS = true; 2779 } 2780 2781 //debug("command: " + command + ", user_interface: " + user_interface + ", value: " + value); 2782 this.contentDocument = doc; // <-- Strange, unless this is applied Mozilla 1.3 breaks 2783 2784 // Don't dispatch key commands 2785 if (!/mceStartTyping|mceEndTyping/.test(command)) { 2786 if (tinyMCE.execCommandCallback(this, 'execcommand_callback', 'execCommand', this.editorId, this.getBody(), command, user_interface, value)) 2787 return; 2788 } 2789 2790 // Fix align on images 2791 if (focusElm && focusElm.nodeName == "IMG") { 2792 var align = focusElm.getAttribute('align'); 2793 var img = command == "JustifyCenter" ? focusElm.cloneNode(false) : focusElm; 2794 2795 switch (command) { 2796 case "JustifyLeft": 2797 if (align == 'left') 2798 img.removeAttribute('align'); 2799 else 2800 img.setAttribute('align', 'left'); 2801 2802 // Remove the div 2803 var div = focusElm.parentNode; 2804 if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode) 2805 div.parentNode.replaceChild(img, div); 2806 2807 this.selection.selectNode(img); 2808 this.repaint(); 2809 tinyMCE.triggerNodeChange(); 2810 return; 2811 2812 case "JustifyCenter": 2813 img.removeAttribute('align'); 2814 2815 // Is centered 2816 var div = tinyMCE.getParentElement(focusElm, "div"); 2817 if (div && div.style.textAlign == "center") { 2818 // Remove div 2819 if (div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode) 2820 div.parentNode.replaceChild(img, div); 2821 } else { 2822 // Add div 2823 var div = this.getDoc().createElement("div"); 2824 div.style.textAlign = 'center'; 2825 div.appendChild(img); 2826 focusElm.parentNode.replaceChild(div, focusElm); 2827 } 2828 2829 this.selection.selectNode(img); 2830 this.repaint(); 2831 tinyMCE.triggerNodeChange(); 2832 return; 2833 2834 case "JustifyRight": 2835 if (align == 'right') 2836 img.removeAttribute('align'); 2837 else 2838 img.setAttribute('align', 'right'); 2839 2840 // Remove the div 2841 var div = focusElm.parentNode; 2842 if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode) 2843 div.parentNode.replaceChild(img, div); 2844 2845 this.selection.selectNode(img); 2846 this.repaint(); 2847 tinyMCE.triggerNodeChange(); 2848 return; 2849 } 2850 } 2851 2852 if (tinyMCE.settings['force_br_newlines']) { 2853 var alignValue = ""; 2854 2855 if (doc.selection.type != "Control") { 2856 switch (command) { 2857 case "JustifyLeft": 2858 alignValue = "left"; 2859 break; 2860 2861 case "JustifyCenter": 2862 alignValue = "center"; 2863 break; 2864 2865 case "JustifyFull": 2866 alignValue = "justify"; 2867 break; 2868 2869 case "JustifyRight": 2870 alignValue = "right"; 2871 break; 2872 } 2873 2874 if (alignValue != "") { 2875 var rng = doc.selection.createRange(); 2876 2877 if ((divElm = tinyMCE.getParentElement(rng.parentElement(), "div")) != null) 2878 divElm.setAttribute("align", alignValue); 2879 else if (rng.pasteHTML && rng.htmlText.length > 0) 2880 rng.pasteHTML('<div align="' + alignValue + '">' + rng.htmlText + "</div>"); 2881 2882 tinyMCE.triggerNodeChange(); 2883 return; 2884 } 2885 } 2886 } 2887 2888 switch (command) { 2889 case "mceRepaint": 2890 this.repaint(); 2891 return true; 2892 2893 case "unlink": 2894 // Unlink if caret is inside link 2895 if (tinyMCE.isGecko && this.getSel().isCollapsed) { 2896 focusElm = tinyMCE.getParentElement(focusElm, 'A'); 2897 2898 if (focusElm) 2899 this.selection.selectNode(focusElm, false); 2900 } 2901 2902 this.getDoc().execCommand(command, user_interface, value); 2903 2904 tinyMCE.isGecko && this.getSel().collapseToEnd(); 2905 2906 tinyMCE.triggerNodeChange(); 2907 2908 return true; 2909 2910 case "InsertUnorderedList": 2911 case "InsertOrderedList": 2912 this.getDoc().execCommand(command, user_interface, value); 2913 tinyMCE.triggerNodeChange(); 2914 break; 2915 2916 case "Strikethrough": 2917 this.getDoc().execCommand(command, user_interface, value); 2918 tinyMCE.triggerNodeChange(); 2919 break; 2920 2921 case "mceSelectNode": 2922 this.selection.selectNode(value); 2923 tinyMCE.triggerNodeChange(); 2924 tinyMCE.selectedNode = value; 2925 break; 2926 2927 case "FormatBlock": 2928 if (value == null || value == "") { 2929 var elm = tinyMCE.getParentElement(this.getFocusElement(), "p,div,h1,h2,h3,h4,h5,h6,pre,address,blockquote,dt,dl,dd,samp"); 2930 2931 if (elm) 2932 this.execCommand("mceRemoveNode", false, elm); 2933 } else { 2934 if (!this.cleanup.isValid(value)) 2935 return true; 2936 2937 if (tinyMCE.isGecko && new RegExp('<(div|blockquote|code|dt|dd|dl|samp)>', 'gi').test(value)) 2938 value = value.replace(/[^a-z]/gi, ''); 2939 2940 if (tinyMCE.isIE && new RegExp('blockquote|code|samp', 'gi').test(value)) { 2941 var b = this.selection.getBookmark(); 2942 this.getDoc().execCommand("FormatBlock", false, '<p>'); 2943 tinyMCE.renameElement(tinyMCE.getParentBlockElement(this.getFocusElement()), value); 2944 this.selection.moveToBookmark(b); 2945 } else 2946 this.getDoc().execCommand("FormatBlock", false, value); 2947 } 2948 2949 tinyMCE.triggerNodeChange(); 2950 2951 break; 2952 2953 case "mceRemoveNode": 2954 if (!value) 2955 value = tinyMCE.getParentElement(this.getFocusElement()); 2956 2957 if (tinyMCE.isIE) { 2958 value.outerHTML = value.innerHTML; 2959 } else { 2960 var rng = value.ownerDocument.createRange(); 2961 rng.setStartBefore(value); 2962 rng.setEndAfter(value); 2963 rng.deleteContents(); 2964 rng.insertNode(rng.createContextualFragment(value.innerHTML)); 2965 } 2966 2967 tinyMCE.triggerNodeChange(); 2968 2969 break; 2970 2971 case "mceSelectNodeDepth": 2972 var parentNode = this.getFocusElement(); 2973 for (var i=0; parentNode; i++) { 2974 if (parentNode.nodeName.toLowerCase() == "body") 2975 break; 2976 2977 if (parentNode.nodeName.toLowerCase() == "#text") { 2978 i--; 2979 parentNode = parentNode.parentNode; 2980 continue; 2981 } 2982 2983 if (i == value) { 2984 this.selection.selectNode(parentNode, false); 2985 tinyMCE.triggerNodeChange(); 2986 tinyMCE.selectedNode = parentNode; 2987 return; 2988 } 2989 2990 parentNode = parentNode.parentNode; 2991 } 2992 2993 break; 2994 2995 case "mceSetStyleInfo": 2996 case "SetStyleInfo": 2997 var rng = this.getRng(); 2998 var sel = this.getSel(); 2999 var scmd = value['command']; 3000 var sname = value['name']; 3001 var svalue = value['value'] == null ? '' : value['value']; 3002 //var svalue = value['value'] == null ? '' : value['value']; 3003 var wrapper = value['wrapper'] ? value['wrapper'] : "span"; 3004 var parentElm = null; 3005 var invalidRe = new RegExp("^BODY|HTML$", "g"); 3006 var invalidParentsRe = tinyMCE.settings['merge_styles_invalid_parents'] != '' ? new RegExp(tinyMCE.settings['merge_styles_invalid_parents'], "gi") : null; 3007 3008 // Whole element selected check 3009 if (tinyMCE.isIE) { 3010 // Control range 3011 if (rng.item) 3012 parentElm = rng.item(0); 3013 else { 3014 var pelm = rng.parentElement(); 3015 var prng = doc.selection.createRange(); 3016 prng.moveToElementText(pelm); 3017 3018 if (rng.htmlText == prng.htmlText || rng.boundingWidth == 0) { 3019 if (invalidParentsRe == null || !invalidParentsRe.test(pelm.nodeName)) 3020 parentElm = pelm; 3021 } 3022 } 3023 } else { 3024 var felm = this.getFocusElement(); 3025 if (sel.isCollapsed || (new RegExp('td|tr|tbody|table', 'gi').test(felm.nodeName) && sel.anchorNode == felm.parentNode)) 3026 parentElm = felm; 3027 } 3028 3029 // Whole element selected 3030 if (parentElm && !invalidRe.test(parentElm.nodeName)) { 3031 if (scmd == "setstyle") 3032 tinyMCE.setStyleAttrib(parentElm, sname, svalue); 3033 3034 if (scmd == "setattrib") 3035 tinyMCE.setAttrib(parentElm, sname, svalue); 3036 3037 if (scmd == "removeformat") { 3038 parentElm.style.cssText = ''; 3039 tinyMCE.setAttrib(parentElm, 'class', ''); 3040 } 3041 3042 // Remove style/attribs from all children 3043 var ch = tinyMCE.getNodeTree(parentElm, new Array(), 1); 3044 for (var z=0; z<ch.length; z++) { 3045 if (ch[z] == parentElm) 3046 continue; 3047 3048 if (scmd == "setstyle") 3049 tinyMCE.setStyleAttrib(ch[z], sname, ''); 3050 3051 if (scmd == "setattrib") 3052 tinyMCE.setAttrib(ch[z], sname, ''); 3053 3054 if (scmd == "removeformat") { 3055 ch[z].style.cssText = ''; 3056 tinyMCE.setAttrib(ch[z], 'class', ''); 3057 } 3058 } 3059 } else { 3060 this._setUseCSS(false); // Bug in FF when running in fullscreen 3061 doc.execCommand("FontName", false, "#mce_temp_font#"); 3062 var elementArray = tinyMCE.getElementsByAttributeValue(this.getBody(), "font", "face", "#mce_temp_font#"); 3063 3064 // Change them all 3065 for (var x=0; x<elementArray.length; x++) { 3066 elm = elementArray[x]; 3067 if (elm) { 3068 var spanElm = doc.createElement(wrapper); 3069 3070 if (scmd == "setstyle") 3071 tinyMCE.setStyleAttrib(spanElm, sname, svalue); 3072 3073 if (scmd == "setattrib") 3074 tinyMCE.setAttrib(spanElm, sname, svalue); 3075 3076 if (scmd == "removeformat") { 3077 spanElm.style.cssText = ''; 3078 tinyMCE.setAttrib(spanElm, 'class', ''); 3079 } 3080 3081 if (elm.hasChildNodes()) { 3082 for (var i=0; i<elm.childNodes.length; i++) 3083 spanElm.appendChild(elm.childNodes[i].cloneNode(true)); 3084 } 3085 3086 spanElm.setAttribute("mce_new", "true"); 3087 elm.parentNode.replaceChild(spanElm, elm); 3088 3089 // Remove style/attribs from all children 3090 var ch = tinyMCE.getNodeTree(spanElm, new Array(), 1); 3091 for (var z=0; z<ch.length; z++) { 3092 if (ch[z] == spanElm) 3093 continue; 3094 3095 if (scmd == "setstyle") 3096 tinyMCE.setStyleAttrib(ch[z], sname, ''); 3097 3098 if (scmd == "setattrib") 3099 tinyMCE.setAttrib(ch[z], sname, ''); 3100 3101 if (scmd == "removeformat") { 3102 ch[z].style.cssText = ''; 3103 tinyMCE.setAttrib(ch[z], 'class', ''); 3104 } 3105 } 3106 } 3107 } 3108 } 3109 3110 // Cleaup wrappers 3111 var nodes = doc.getElementsByTagName(wrapper); 3112 for (var i=nodes.length-1; i>=0; i--) { 3113 var elm = nodes[i]; 3114 var isNew = tinyMCE.getAttrib(elm, "mce_new") == "true"; 3115 3116 elm.removeAttribute("mce_new"); 3117 3118 // Is only child a element 3119 if (elm.childNodes && elm.childNodes.length == 1 && elm.childNodes[0].nodeType == 1) { 3120 //tinyMCE.debug("merge1" + isNew); 3121 this._mergeElements(scmd, elm, elm.childNodes[0], isNew); 3122 continue; 3123 } 3124 3125 // Is I the only child 3126 if (elm.parentNode.childNodes.length == 1 && !invalidRe.test(elm.nodeName) && !invalidRe.test(elm.parentNode.nodeName)) { 3127 //tinyMCE.debug("merge2" + isNew + "," + elm.nodeName + "," + elm.parentNode.nodeName); 3128 if (invalidParentsRe == null || !invalidParentsRe.test(elm.parentNode.nodeName)) 3129 this._mergeElements(scmd, elm.parentNode, elm, false); 3130 } 3131 } 3132 3133 // Remove empty wrappers 3134 var nodes = doc.getElementsByTagName(wrapper); 3135 for (var i=nodes.length-1; i>=0; i--) { 3136 var elm = nodes[i]; 3137 var isEmpty = true; 3138 3139 // Check if it has any attribs 3140 var tmp = doc.createElement("body"); 3141 tmp.appendChild(elm.cloneNode(false)); 3142 3143 // Is empty span, remove it 3144 tmp.innerHTML = tmp.innerHTML.replace(new RegExp('style=""|class=""', 'gi'), ''); 3145 //tinyMCE.debug(tmp.innerHTML); 3146 if (new RegExp('<span>', 'gi').test(tmp.innerHTML)) { 3147 for (var x=0; x<elm.childNodes.length; x++) { 3148 if (elm.parentNode != null) 3149 elm.parentNode.insertBefore(elm.childNodes[x].cloneNode(true), elm); 3150 } 3151 3152 elm.parentNode.removeChild(elm); 3153 } 3154 } 3155 3156 // Re add the visual aids 3157 if (scmd == "removeformat") 3158 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this); 3159 3160 tinyMCE.triggerNodeChange(); 3161 3162 break; 3163 3164 case "FontName": 3165 if (value == null) { 3166 var s = this.getSel(); 3167 3168 // Find font and select it 3169 if (tinyMCE.isGecko && s.isCollapsed) { 3170 var f = tinyMCE.getParentElement(this.getFocusElement(), "font"); 3171 3172 if (f != null) 3173 this.selection.selectNode(f, false); 3174 } 3175 3176 // Remove format 3177 this.getDoc().execCommand("RemoveFormat", false, null); 3178 3179 // Collapse range if font was found 3180 if (f != null && tinyMCE.isGecko) { 3181 var r = this.getRng().cloneRange(); 3182 r.collapse(true); 3183 s.removeAllRanges(); 3184 s.addRange(r); 3185 } 3186 } else 3187 this.getDoc().execCommand('FontName', false, value); 3188 3189 if (tinyMCE.isGecko) 3190 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1); 3191 3192 return; 3193 3194 case "FontSize": 3195 this.getDoc().execCommand('FontSize', false, value); 3196 3197 if (tinyMCE.isGecko) 3198 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1); 3199 3200 return; 3201 3202 case "forecolor": 3203 value = value == null ? this.foreColor : value; 3204 value = tinyMCE.trim(value); 3205 value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value; 3206 3207 this.foreColor = value; 3208 this.getDoc().execCommand('forecolor', false, value); 3209 break; 3210 3211 case "HiliteColor": 3212 value = value == null ? this.backColor : value; 3213 value = tinyMCE.trim(value); 3214 value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value; 3215 this.backColor = value; 3216 3217 if (tinyMCE.isGecko) { 3218 this._setUseCSS(true); 3219 this.getDoc().execCommand('hilitecolor', false, value); 3220 this._setUseCSS(false); 3221 } else 3222 this.getDoc().execCommand('BackColor', false, value); 3223 break; 3224 3225 case "Cut": 3226 case "Copy": 3227 case "Paste": 3228 var cmdFailed = false; 3229 3230 // Try executing command 3231 eval('try {this.getDoc().execCommand(command, user_interface, value);} catch (e) {cmdFailed = true;}'); 3232 3233 if (tinyMCE.isOpera && cmdFailed) 3234 alert('Currently not supported by your browser, use keyboard shortcuts instead.'); 3235 3236 // Alert error in gecko if command failed 3237 if (tinyMCE.isGecko && cmdFailed) { 3238 // Confirm more info 3239 if (confirm(tinyMCE.entityDecode(tinyMCE.getLang('lang_clipboard_msg')))) 3240 window.open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', 'mceExternal'); 3241 3242 return; 3243 } else 3244 tinyMCE.triggerNodeChange(); 3245 break; 3246 3247 case "mceSetContent": 3248 if (!value) 3249 value = ""; 3250 3251 // Call custom cleanup code 3252 value = tinyMCE.storeAwayURLs(value); 3253 value = tinyMCE._customCleanup(this, "insert_to_editor", value); 3254 3255 if (this.getBody().nodeName == 'BODY') 3256 tinyMCE._setHTML(doc, value); 3257 else 3258 this.getBody().innerHTML = value; 3259 3260 tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, doc, this.settings, this.getBody(), false, false, false, true)); 3261 tinyMCE.convertAllRelativeURLs(this.getBody()); 3262 3263 // Cleanup any mess left from storyAwayURLs 3264 tinyMCE._removeInternal(this.getBody()); 3265 3266 // When editing always use fonts internaly 3267 if (tinyMCE.getParam("convert_fonts_to_spans")) 3268 tinyMCE.convertSpansToFonts(doc); 3269 3270 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this); 3271 tinyMCE._setEventsEnabled(this.getBody(), false); 3272 return true; 3273 3274 case "mceCleanup": 3275 var b = this.selection.getBookmark(); 3276 tinyMCE._setHTML(this.contentDocument, this.getBody().innerHTML); 3277 tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, this.contentDocument, this.settings, this.getBody(), this.visualAid)); 3278 tinyMCE.convertAllRelativeURLs(doc.body); 3279 3280 // When editing always use fonts internaly 3281 if (tinyMCE.getParam("convert_fonts_to_spans")) 3282 tinyMCE.convertSpansToFonts(doc); 3283 3284 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this); 3285 tinyMCE._setEventsEnabled(this.getBody(), false); 3286 this.repaint(); 3287 this.selection.moveToBookmark(b); 3288 tinyMCE.triggerNodeChange(); 3289 break; 3290 3291 case "mceReplaceContent": 3292 // Force empty string 3293 if (!value) 3294 value = ''; 3295 3296 this.getWin().focus(); 3297 3298 var selectedText = ""; 3299 3300 if (tinyMCE.isIE) { 3301 var rng = doc.selection.createRange(); 3302 selectedText = rng.text; 3303 } else 3304 selectedText = this.getSel().toString(); 3305 3306 if (selectedText.length > 0) { 3307 value = tinyMCE.replaceVar(value, "selection", selectedText); 3308 tinyMCE.execCommand('mceInsertContent', false, value); 3309 } 3310 3311 tinyMCE.triggerNodeChange(); 3312 break; 3313 3314 case "mceSetAttribute": 3315 if (typeof(value) == 'object') { 3316 var targetElms = (typeof(value['targets']) == "undefined") ? "p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address" : value['targets']; 3317 var targetNode = tinyMCE.getParentElement(this.getFocusElement(), targetElms); 3318 3319 if (targetNode) { 3320 targetNode.setAttribute(value['name'], value['value']); 3321 tinyMCE.triggerNodeChange(); 3322 } 3323 } 3324 break; 3325 3326 case "mceSetCSSClass": 3327 this.execCommand("mceSetStyleInfo", false, {command : "setattrib", name : "class", value : value}); 3328 break; 3329 3330 case "mceInsertRawHTML": 3331 var key = 'tiny_mce_marker'; 3332 3333 this.execCommand('mceBeginUndoLevel'); 3334 3335 // Insert marker key 3336 this.execCommand('mceInsertContent', false, key); 3337 3338 // Store away scroll pos 3339 var scrollX = this.getBody().scrollLeft + this.getDoc().documentElement.scrollLeft; 3340 var scrollY = this.getBody().scrollTop + this.getDoc().documentElement.scrollTop; 3341 3342 // Find marker and replace with RAW HTML 3343 var html = this.getBody().innerHTML; 3344 if ((pos = html.indexOf(key)) != -1) 3345 tinyMCE.setInnerHTML(this.getBody(), html.substring(0, pos) + value + html.substring(pos + key.length)); 3346 3347 // Restore scoll pos 3348 this.contentWindow.scrollTo(scrollX, scrollY); 3349 3350 this.execCommand('mceEndUndoLevel'); 3351 3352 break; 3353 3354 case "mceInsertContent": 3355 // Force empty string 3356 if (!value) 3357 value = ''; 3358 3359 var insertHTMLFailed = false; 3360 3361 // Removed since it produced problems in IE 3362 // this.getWin().focus(); 3363 3364 if (tinyMCE.isGecko || tinyMCE.isOpera) { 3365 try { 3366 // Is plain text or HTML, &, etc will be encoded wrong in FF 3367 if (value.indexOf('<') == -1 && !value.match(/(&| |<|>)/g)) { 3368 var r = this.getRng(); 3369 var n = this.getDoc().createTextNode(tinyMCE.entityDecode(value)); 3370 var s = this.getSel(); 3371 var r2 = r.cloneRange(); 3372 3373 // Insert text at cursor position 3374 s.removeAllRanges(); 3375 r.deleteContents(); 3376 r.insertNode(n); 3377 3378 // Move the cursor to the end of text 3379 r2.selectNode(n); 3380 r2.collapse(false); 3381 s.removeAllRanges(); 3382 s.addRange(r2); 3383 } else { 3384 value = tinyMCE.fixGeckoBaseHREFBug(1, this.getDoc(), value); 3385 this.getDoc().execCommand('inserthtml', false, value); 3386 tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value); 3387 } 3388 } catch (ex) { 3389 insertHTMLFailed = true; 3390 } 3391 3392 if (!insertHTMLFailed) { 3393 tinyMCE.triggerNodeChange(); 3394 return; 3395 } 3396 } 3397 3398 if (!tinyMCE.isIE) { 3399 var isHTML = value.indexOf('<') != -1; 3400 var sel = this.getSel(); 3401 var rng = this.getRng(); 3402 3403 if (isHTML) { 3404 if (tinyMCE.isSafari) { 3405 var tmpRng = this.getDoc().createRange(); 3406 3407 tmpRng.setStart(this.getBody(), 0); 3408 tmpRng.setEnd(this.getBody(), 0); 3409 3410 value = tmpRng.createContextualFragment(value); 3411 } else 3412 value = rng.createContextualFragment(value); 3413 } else { 3414 // Setup text node 3415 var el = document.createElement("div"); 3416 el.innerHTML = value; 3417 value = el.firstChild.nodeValue; 3418 value = doc.createTextNode(value); 3419 } 3420 3421 // Insert plain text in Safari 3422 if (tinyMCE.isSafari && !isHTML) { 3423 this.execCommand('InsertText', false, value.nodeValue); 3424 tinyMCE.triggerNodeChange(); 3425 return true; 3426 } else if (tinyMCE.isSafari && isHTML) { 3427 rng.deleteContents(); 3428 rng.insertNode(value); 3429 tinyMCE.triggerNodeChange(); 3430 return true; 3431 } 3432 3433 rng.deleteContents(); 3434 3435 // If target node is text do special treatment, (Mozilla 1.3 fix) 3436 if (rng.startContainer.nodeType == 3) { 3437 var node = rng.startContainer.splitText(rng.startOffset); 3438 node.parentNode.insertBefore(value, node); 3439 } else 3440 rng.insertNode(value); 3441 3442 if (!isHTML) { 3443 // Removes weird selection trails 3444 sel.selectAllChildren(doc.body); 3445 sel.removeAllRanges(); 3446 3447 // Move cursor to end of content 3448 var rng = doc.createRange(); 3449 3450 rng.selectNode(value); 3451 rng.collapse(false); 3452 3453 sel.addRange(rng); 3454 } else 3455 rng.collapse(false); 3456 3457 tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value); 3458 } else { 3459 var rng = doc.selection.createRange(), tmpRng = null; 3460 var c = value.indexOf('<!--') != -1; 3461 3462 // Fix comment bug, add tag before comments 3463 if (c) 3464 value = tinyMCE.uniqueTag + value; 3465 3466 // tmpRng = rng.duplicate(); // Store away range (Fixes Undo bookmark bug in IE) 3467 3468 if (rng.item) 3469 rng.item(0).outerHTML = value; 3470 else 3471 rng.pasteHTML(value); 3472 3473 //if (tmpRng) 3474 // tmpRng.select(); // Restore range (Fixes Undo bookmark bug in IE) 3475 3476 // Remove unique tag 3477 if (c) { 3478 var e = this.getDoc().getElementById('mceTMPElement'); 3479 e.parentNode.removeChild(e); 3480 } 3481 } 3482 3483 tinyMCE.execCommand("mceAddUndoLevel"); 3484 tinyMCE.triggerNodeChange(); 3485 break; 3486 3487 case "mceStartTyping": 3488 if (tinyMCE.settings['custom_undo_redo'] && this.undoRedo.typingUndoIndex == -1) { 3489 this.undoRedo.typingUndoIndex = this.undoRedo.undoIndex; 3490 tinyMCE.typingUndoIndex = tinyMCE.undoIndex; 3491 this.execCommand('mceAddUndoLevel'); 3492 } 3493 break; 3494 3495 case "mceEndTyping": 3496 if (tinyMCE.settings['custom_undo_redo'] && this.undoRedo.typingUndoIndex != -1) { 3497 this.execCommand('mceAddUndoLevel'); 3498 this.undoRedo.typingUndoIndex = -1; 3499 } 3500 3501 tinyMCE.typingUndoIndex = -1; 3502 break; 3503 3504 case "mceBeginUndoLevel": 3505 this.undoRedoLevel = false; 3506 break; 3507 3508 case "mceEndUndoLevel": 3509 this.undoRedoLevel = true; 3510 this.execCommand('mceAddUndoLevel'); 3511 break; 3512 3513 case "mceAddUndoLevel": 3514 if (tinyMCE.settings['custom_undo_redo'] && this.undoRedoLevel) { 3515 if (this.undoRedo.add()) 3516 tinyMCE.triggerNodeChange(false); 3517 } 3518 break; 3519 3520 case "Undo": 3521 if (tinyMCE.settings['custom_undo_redo']) { 3522 tinyMCE.execCommand("mceEndTyping"); 3523 this.undoRedo.undo(); 3524 tinyMCE.triggerNodeChange(); 3525 } else 3526 this.getDoc().execCommand(command, user_interface, value); 3527 break; 3528 3529 case "Redo": 3530 if (tinyMCE.settings['custom_undo_redo']) { 3531 tinyMCE.execCommand("mceEndTyping"); 3532 this.undoRedo.redo(); 3533 tinyMCE.triggerNodeChange(); 3534 } else 3535 this.getDoc().execCommand(command, user_interface, value); 3536 break; 3537 3538 case "mceToggleVisualAid": 3539 this.visualAid = !this.visualAid; 3540 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this); 3541 tinyMCE.triggerNodeChange(); 3542 break; 3543 3544 case "Indent": 3545 this.getDoc().execCommand(command, user_interface, value); 3546 tinyMCE.triggerNodeChange(); 3547 3548 if (tinyMCE.isIE) { 3549 var n = tinyMCE.getParentElement(this.getFocusElement(), "blockquote"); 3550 do { 3551 if (n && n.nodeName == "BLOCKQUOTE") { 3552 n.removeAttribute("dir"); 3553 n.removeAttribute("style"); 3554 } 3555 } while (n != null && (n = n.parentNode) != null); 3556 } 3557 break; 3558 3559 case "RemoveFormat": 3560 case "removeformat": 3561 var text = this.selection.getSelectedText(); 3562 3563 if (tinyMCE.isOpera) { 3564 this.getDoc().execCommand("RemoveFormat", false, null); 3565 return; 3566 } 3567 3568 if (tinyMCE.isIE) { 3569 try { 3570 var rng = doc.selection.createRange(); 3571 rng.execCommand("RemoveFormat", false, null); 3572 } catch (e) { 3573 // Do nothing 3574 } 3575 3576 this.execCommand("mceSetStyleInfo", false, {command : "removeformat"}); 3577 } else { 3578 this.getDoc().execCommand(command, user_interface, value); 3579 3580 this.execCommand("mceSetStyleInfo", false, {command : "removeformat"}); 3581 } 3582 3583 // Remove class 3584 if (text.length == 0) 3585 this.execCommand("mceSetCSSClass", false, ""); 3586 3587 tinyMCE.triggerNodeChange(); 3588 break; 3589 3590 default: 3591 this.getDoc().execCommand(command, user_interface, value); 3592 3593 if (tinyMCE.isGecko) 3594 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1); 3595 else 3596 tinyMCE.triggerNodeChange(); 3597 } 3598 3599 // Add undo level after modification 3600 if (command != "mceAddUndoLevel" && command != "Undo" && command != "Redo" && command != "mceStartTyping" && command != "mceEndTyping") 3601 tinyMCE.execCommand("mceAddUndoLevel"); 3602 }, 3603 3604 queryCommandValue : function(c) { 3605 try { 3606 return this.getDoc().queryCommandValue(c); 3607 } catch (e) { 3608 return null; 3609 } 3610 }, 3611 3612 queryCommandState : function(c) { 3613 return this.getDoc().queryCommandState(c); 3614 }, 3615 3616 _onAdd : function(replace_element, form_element_name, target_document) { 3617 var hc, th, to, editorTemplate; 3618 3619 th = this.settings['theme']; 3620 to = tinyMCE.themes[th]; 3621 3622 var targetDoc = target_document ? target_document : document; 3623 3624 this.targetDoc = targetDoc; 3625 3626 tinyMCE.themeURL = tinyMCE.baseURL + "/themes/" + this.settings['theme']; 3627 this.settings['themeurl'] = tinyMCE.themeURL; 3628 3629 if (!replace_element) { 3630 alert("Error: Could not find the target element."); 3631 return false; 3632 } 3633 3634 if (to.getEditorTemplate) 3635 editorTemplate = to.getEditorTemplate(this.settings, this.editorId); 3636 3637 var deltaWidth = editorTemplate['delta_width'] ? editorTemplate['delta_width'] : 0; 3638 var deltaHeight = editorTemplate['delta_height'] ? editorTemplate['delta_height'] : 0; 3639 var html = '<span id="' + this.editorId + '_parent" class="mceEditorContainer">' + editorTemplate['html']; 3640 3641 html = tinyMCE.replaceVar(html, "editor_id", this.editorId); 3642 this.settings['default_document'] = tinyMCE.baseURL + "/blank.htm"; 3643 3644 this.settings['old_width'] = this.settings['width']; 3645 this.settings['old_height'] = this.settings['height']; 3646 3647 // Set default width, height 3648 if (this.settings['width'] == -1) 3649 this.settings['width'] = replace_element.offsetWidth; 3650 3651 if (this.settings['height'] == -1) 3652 this.settings['height'] = replace_element.offsetHeight; 3653 3654 // Try the style width 3655 if (this.settings['width'] == 0) 3656 this.settings['width'] = replace_element.style.width; 3657 3658 // Try the style height 3659 if (this.settings['height'] == 0) 3660 this.settings['height'] = replace_element.style.height; 3661 3662 // If no width/height then default to 320x240, better than nothing 3663 if (this.settings['width'] == 0) 3664 this.settings['width'] = 320; 3665 3666 if (this.settings['height'] == 0) 3667 this.settings['height'] = 240; 3668 3669 this.settings['area_width'] = parseInt(this.settings['width']); 3670 this.settings['area_height'] = parseInt(this.settings['height']); 3671 this.settings['area_width'] += deltaWidth; 3672 this.settings['area_height'] += deltaHeight; 3673 3674 this.settings['width_style'] = "" + this.settings['width']; 3675 this.settings['height_style'] = "" + this.settings['height']; 3676 3677 // Special % handling 3678 if (("" + this.settings['width']).indexOf('%') != -1) 3679 this.settings['area_width'] = "100%"; 3680 else 3681 this.settings['width_style'] += 'px'; 3682 3683 if (("" + this.settings['height']).indexOf('%') != -1) 3684 this.settings['area_height'] = "100%"; 3685 else 3686 this.settings['height_style'] += 'px'; 3687 3688 if (("" + replace_element.style.width).indexOf('%') != -1) { 3689 this.settings['width'] = replace_element.style.width; 3690 this.settings['area_width'] = "100%"; 3691 this.settings['width_style'] = "100%"; 3692 } 3693 3694 if (("" + replace_element.style.height).indexOf('%') != -1) { 3695 this.settings['height'] = replace_element.style.height; 3696 this.settings['area_height'] = "100%"; 3697 this.settings['height_style'] = "100%"; 3698 } 3699 3700 html = tinyMCE.applyTemplate(html); 3701 3702 this.settings['width'] = this.settings['old_width']; 3703 this.settings['height'] = this.settings['old_height']; 3704 3705 this.visualAid = this.settings['visual']; 3706 this.formTargetElementId = form_element_name; 3707 3708 // Get replace_element contents 3709 if (replace_element.nodeName == "TEXTAREA" || replace_element.nodeName == "INPUT") 3710 this.startContent = replace_element.value; 3711 else 3712 this.startContent = replace_element.innerHTML; 3713 3714 // If not text area or input 3715 if (replace_element.nodeName != "TEXTAREA" && replace_element.nodeName != "INPUT") { 3716 this.oldTargetElement = replace_element; 3717 3718 // Debug mode 3719 if (tinyMCE.settings['debug']) { 3720 hc = '<textarea wrap="off" id="' + form_element_name + '" name="' + form_element_name + '" cols="100" rows="15"></textarea>'; 3721 } else { 3722 hc = '<input type="hidden" id="' + form_element_name + '" name="' + form_element_name + '" />'; 3723 this.oldTargetDisplay = tinyMCE.getStyle(this.oldTargetElement, 'display', 'inline'); 3724 this.oldTargetElement.style.display = "none"; 3725 } 3726 3727 html += '</span>'; 3728 3729 if (tinyMCE.isGecko) 3730 html = hc + html; 3731 else 3732 html += hc; 3733 3734 // Output HTML and set editable 3735 if (tinyMCE.isGecko) { 3736 var rng = replace_element.ownerDocument.createRange(); 3737 rng.setStartBefore(replace_element); 3738 3739 var fragment = rng.createContextualFragment(html); 3740 tinyMCE.insertAfter(fragment, replace_element); 3741 } else 3742 replace_element.insertAdjacentHTML("beforeBegin", html); 3743 } else { 3744 html += '</span>'; 3745 3746 // Just hide the textarea element 3747 this.oldTargetElement = replace_element; 3748 3749 if (!tinyMCE.settings['debug']) { 3750 this.oldTargetDisplay = tinyMCE.getStyle(this.oldTargetElement, 'display', 'inline'); 3751 this.oldTargetElement.style.display = "none"; 3752 } 3753 3754 // Output HTML and set editable 3755 if (tinyMCE.isGecko) { 3756 var rng = replace_element.ownerDocument.createRange(); 3757 rng.setStartBefore(replace_element); 3758 3759 var fragment = rng.createContextualFragment(html); 3760 tinyMCE.insertAfter(fragment, replace_element); 3761 } else 3762 replace_element.insertAdjacentHTML("beforeBegin", html); 3763 } 3764 3765 // Setup iframe 3766 var dynamicIFrame = false; 3767 var tElm = targetDoc.getElementById(this.editorId); 3768 3769 if (!tinyMCE.isIE) { 3770 // Node case is preserved in XML strict mode 3771 if (tElm && (tElm.nodeName == "SPAN" || tElm.nodeName == "span")) { 3772 tElm = tinyMCE._createIFrame(tElm, targetDoc); 3773 dynamicIFrame = true; 3774 } 3775 3776 this.targetElement = tElm; 3777 this.iframeElement = tElm; 3778 this.contentDocument = tElm.contentDocument; 3779 this.contentWindow = tElm.contentWindow; 3780 3781 //this.getDoc().designMode = "on"; 3782 } else { 3783 if (tElm && tElm.nodeName == "SPAN") 3784 tElm = tinyMCE._createIFrame(tElm, targetDoc, targetDoc.parentWindow); 3785 else 3786 tElm = targetDoc.frames[this.editorId]; 3787 3788 this.targetElement = tElm; 3789 this.iframeElement = targetDoc.getElementById(this.editorId); 3790 3791 if (tinyMCE.isOpera) { 3792 this.contentDocument = this.iframeElement.contentDocument; 3793 this.contentWindow = this.iframeElement.contentWindow; 3794 dynamicIFrame = true; 3795 } else { 3796 this.contentDocument = tElm.window.document; 3797 this.contentWindow = tElm.window; 3798 } 3799 3800 this.getDoc().designMode = "on"; 3801 } 3802 3803 // Setup base HTML 3804 var doc = this.contentDocument; 3805 if (dynamicIFrame) { 3806 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>'; 3807 3808 try { 3809 if (!this.isHidden()) 3810 this.getDoc().designMode = "on"; 3811 3812 doc.open(); 3813 doc.write(html); 3814 doc.close(); 3815 } catch (e) { 3816 // Failed Mozilla 1.3 3817 this.getDoc().location.href = tinyMCE.baseURL + "/blank.htm"; 3818 } 3819 } 3820 3821 // This timeout is needed in MSIE 5.5 for some odd reason 3822 // it seems that the document.frames isn't initialized yet? 3823 if (tinyMCE.isIE) 3824 window.setTimeout("tinyMCE.addEventHandlers(tinyMCE.instances[\"" + this.editorId + "\"]);", 1); 3825 3826 // Setup element references 3827 var parentElm = this.targetDoc.getElementById(this.editorId + '_parent'); 3828 this.formElement = tinyMCE.isGecko ? parentElm.previousSibling : parentElm.nextSibling; 3829 3830 tinyMCE.setupContent(this.editorId, true); 3831 3832 return true; 3833 }, 3834 3835 setBaseHREF : function(u) { 3836 var h, b, d, nl; 3837 3838 d = this.getDoc(); 3839 nl = d.getElementsByTagName("base"); 3840 b = nl.length > 0 ? nl[0] : null; 3841 3842 if (!b) { 3843 nl = d.getElementsByTagName("head"); 3844 h = nl.length > 0 ? nl[0] : null; 3845 3846 b = d.createElement("base"); 3847 b.setAttribute('href', u); 3848 h.appendChild(b); 3849 } else { 3850 if (u == "" || u == null) 3851 b.parentNode.removeChild(b); 3852 else 3853 b.setAttribute('href', u); 3854 } 3855 }, 3856 3857 getHTML : function(r) { 3858 var h, d = this.getDoc(), b = this.getBody(); 3859 3860 if (r) 3861 return b.innerHTML; 3862 3863 h = tinyMCE._cleanupHTML(this, d, this.settings, b, false, true, false, true); 3864 3865 if (tinyMCE.getParam("convert_fonts_to_spans")) 3866 tinyMCE.convertSpansToFonts(d); 3867 3868 return h; 3869 }, 3870 3871 setHTML : function(h) { 3872 this.execCommand('mceSetContent', false, h); 3873 this.repaint(); 3874 }, 3875 3876 getFocusElement : function() { 3877 return this.selection.getFocusElement(); 3878 }, 3879 3880 getSel : function() { 3881 return this.selection.getSel(); 3882 }, 3883 3884 getRng : function() { 3885 return this.selection.getRng(); 3886 }, 3887 3888 triggerSave : function(skip_cleanup, skip_callback) { 3889 var e, nl = [], i, s; 3890 3891 this.switchSettings(); 3892 s = tinyMCE.settings; 3893 3894 // Force hidden tabs visible while serializing 3895 if (tinyMCE.isRealIE) { 3896 e = this.iframeElement; 3897 3898 do { 3899 if (e.style && e.style.display == 'none') { 3900 e.style.display = 'block'; 3901 nl[nl.length] = {elm : e, type : 'style'}; 3902 } 3903 3904 if (e.style && s.hidden_tab_class.length > 0 && e.className.indexOf(s.hidden_tab_class) != -1) { 3905 e.className = s.display_tab_class; 3906 nl[nl.length] = {elm : e, type : 'class'}; 3907 } 3908 } while ((e = e.parentNode) != null) 3909 } 3910 3911 tinyMCE.settings['preformatted'] = false; 3912 3913 // Default to false 3914 if (typeof(skip_cleanup) == "undefined") 3915 skip_cleanup = false; 3916 3917 // Default to false 3918 if (typeof(skip_callback) == "undefined") 3919 skip_callback = false; 3920 3921 tinyMCE._setHTML(this.getDoc(), this.getBody().innerHTML); 3922 3923 // Remove visual aids when cleanup is disabled 3924 if (this.settings['cleanup'] == false) { 3925 tinyMCE.handleVisualAid(this.getBody(), true, false, this); 3926 tinyMCE._setEventsEnabled(this.getBody(), true); 3927 } 3928 3929 tinyMCE._customCleanup(this, "submit_content_dom", this.contentWindow.document.body); 3930 var htm = skip_cleanup ? this.getBody().innerHTML : tinyMCE._cleanupHTML(this, this.getDoc(), this.settings, this.getBody(), tinyMCE.visualAid, true, true); 3931 htm = tinyMCE._customCleanup(this, "submit_content", htm); 3932 3933 if (!skip_callback && tinyMCE.settings['save_callback'] != "") 3934 var content = eval(tinyMCE.settings['save_callback'] + "(this.formTargetElementId,htm,this.getBody());"); 3935 3936 // Use callback content if available 3937 if ((typeof(content) != "undefined") && content != null) 3938 htm = content; 3939 3940 // Replace some weird entities (Bug: #1056343) 3941 htm = tinyMCE.regexpReplace(htm, "(", "(", "gi"); 3942 htm = tinyMCE.regexpReplace(htm, ")", ")", "gi"); 3943 htm = tinyMCE.regexpReplace(htm, ";", ";", "gi"); 3944 htm = tinyMCE.regexpReplace(htm, """, """, "gi"); 3945 htm = tinyMCE.regexpReplace(htm, "^", "^", "gi"); 3946 3947 if (this.formElement) 3948 this.formElement.value = htm; 3949 3950 if (tinyMCE.isSafari && this.formElement) 3951 this.formElement.innerText = htm; 3952 3953 // Hide them again (tabs in MSIE) 3954 for (i=0; i<nl.length; i++) { 3955 if (nl[i].type == 'style') 3956 nl[i].elm.style.display = 'none'; 3957 else 3958 nl[i].elm.className = s.hidden_tab_class; 3959 } 3960 } 3961 3962 }; 3963 3964 /* file:jscripts/tiny_mce/classes/TinyMCE_Cleanup.class.js */ 3965 3966 TinyMCE_Engine.prototype.cleanupHTMLCode = function(s) { 3967 s = s.replace(new RegExp('<p \\/>', 'gi'), '<p> </p>'); 3968 s = s.replace(new RegExp('<p>\\s*<\\/p>', 'gi'), '<p> </p>'); 3969 3970 // Fix close BR elements 3971 s = s.replace(new RegExp('<br>\\s*<\\/br>', 'gi'), '<br />'); 3972 3973 // Open closed tags like <b/> to <b></b> 3974 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>'); 3975 3976 // Remove trailing space <b > to <b> 3977 s = s.replace(new RegExp('\\s+></', 'gi'), '></'); 3978 3979 // Close tags <img></img> to <img/> 3980 s = s.replace(new RegExp('<(img|br|hr)([^>]*)><\\/(img|br|hr)>', 'gi'), '<$1$2 />'); 3981 3982 // Weird MSIE bug, <p><hr /></p> breaks runtime? 3983 if (tinyMCE.isIE) 3984 s = s.replace(new RegExp('<p><hr \\/><\\/p>', 'gi'), "<hr>"); 3985 3986 // Weird tags will make IE error #bug: 1538495 3987 if (tinyMCE.isIE) 3988 s = s.replace(/<!(\s*)\/>/g, ''); 3989 3990 // Convert relative anchors to absolute URLs ex: #something to file.htm#something 3991 // Removed: Since local document anchors should never be forced absolute example edit.php?id=something 3992 //if (tinyMCE.getParam('convert_urls')) 3993 // s = s.replace(new RegExp('(href=\"{0,1})(\\s*#)', 'gi'), '$1' + tinyMCE.settings['document_base_url'] + "#"); 3994 3995 return s; 3996 }; 3997 3998 TinyMCE_Engine.prototype.parseStyle = function(str) { 3999 var ar = new Array(); 4000 4001 if (str == null) 4002 return ar; 4003 4004 var st = str.split(';'); 4005 4006 tinyMCE.clearArray(ar); 4007 4008 for (var i=0; i<st.length; i++) { 4009 if (st[i] == '') 4010 continue; 4011 4012 var re = new RegExp('^\\s*([^:]*):\\s*(.*)\\s*$'); 4013 var pa = st[i].replace(re, '$1||$2').split('||'); 4014 //tinyMCE.debug(str, pa[0] + "=" + pa[1], st[i].replace(re, '$1||$2')); 4015 if (pa.length == 2) 4016 ar[pa[0].toLowerCase()] = pa[1]; 4017 } 4018 4019 return ar; 4020 }; 4021 4022 TinyMCE_Engine.prototype.compressStyle = function(ar, pr, sf, res) { 4023 var box = new Array(); 4024 4025 box[0] = ar[pr + '-top' + sf]; 4026 box[1] = ar[pr + '-left' + sf]; 4027 box[2] = ar[pr + '-right' + sf]; 4028 box[3] = ar[pr + '-bottom' + sf]; 4029 4030 for (var i=0; i<box.length; i++) { 4031 if (box[i] == null) 4032 return; 4033 4034 for (var a=0; a<box.length; a++) { 4035 if (box[a] != box[i]) 4036 return; 4037 } 4038 } 4039 4040 // They are all the same 4041 ar[res] = box[0]; 4042 ar[pr + '-top' + sf] = null; 4043 ar[pr + '-left' + sf] = null; 4044 ar[pr + '-right' + sf] = null; 4045 ar[pr + '-bottom' + sf] = null; 4046 }; 4047 4048 TinyMCE_Engine.prototype.serializeStyle = function(ar) { 4049 var str = ""; 4050 4051 // Compress box 4052 tinyMCE.compressStyle(ar, "border", "", "border"); 4053 tinyMCE.compressStyle(ar, "border", "-width", "border-width"); 4054 tinyMCE.compressStyle(ar, "border", "-color", "border-color"); 4055 tinyMCE.compressStyle(ar, "border", "-style", "border-style"); 4056 tinyMCE.compressStyle(ar, "padding", "", "padding"); 4057 tinyMCE.compressStyle(ar, "margin", "", "margin"); 4058 4059 for (var key in ar) { 4060 var val = ar[key]; 4061 4062 if (typeof(val) == 'function') 4063 continue; 4064 4065 if (key.indexOf('mso-') == 0) 4066 continue; 4067 4068 if (val != null && val != '') { 4069 val = '' + val; // Force string 4070 4071 // Fix style URL 4072 val = val.replace(new RegExp("url\\(\\'?([^\\']*)\\'?\\)", 'gi'), "url('$1')"); 4073 4074 // Convert URL 4075 if (val.indexOf('url(') != -1 && tinyMCE.getParam('convert_urls')) { 4076 var m = new RegExp("url\\('(.*?)'\\)").exec(val); 4077 4078 if (m.length > 1) 4079 val = "url('" + eval(tinyMCE.getParam('urlconverter_callback') + "(m[1], null, true);") + "')"; 4080 } 4081 4082 // Force HEX colors 4083 if (tinyMCE.getParam("force_hex_style_colors")) 4084 val = tinyMCE.convertRGBToHex(val, true); 4085 4086 val = val.replace(/\"/g, '\''); 4087 4088 if (val != "url('')") 4089 str += key.toLowerCase() + ": " + val + "; "; 4090 } 4091 } 4092 4093 if (new RegExp('; $').test(str)) 4094 str = str.substring(0, str.length - 2); 4095 4096 return str; 4097 }; 4098 4099 TinyMCE_Engine.prototype.convertRGBToHex = function(s, k) { 4100 if (s.toLowerCase().indexOf('rgb') != -1) { 4101 var re = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi"); 4102 var rgb = s.replace(re, "$1,$2,$3,$4,$5").split(','); 4103 if (rgb.length == 5) { 4104 r = parseInt(rgb[1]).toString(16); 4105 g = parseInt(rgb[2]).toString(16); 4106 b = parseInt(rgb[3]).toString(16); 4107 4108 r = r.length == 1 ? '0' + r : r; 4109 g = g.length == 1 ? '0' + g : g; 4110 b = b.length == 1 ? '0' + b : b; 4111 4112 s = "#" + r + g + b; 4113 4114 if (k) 4115 s = rgb[0] + s + rgb[4]; 4116 } 4117 } 4118 4119 return s; 4120 }; 4121 4122 TinyMCE_Engine.prototype.convertHexToRGB = function(s) { 4123 if (s.indexOf('#') != -1) { 4124 s = s.replace(new RegExp('[^0-9A-F]', 'gi'), ''); 4125 return "rgb(" + parseInt(s.substring(0, 2), 16) + "," + parseInt(s.substring(2, 4), 16) + "," + parseInt(s.substring(4, 6), 16) + ")"; 4126 } 4127 4128 return s; 4129 }; 4130 4131 TinyMCE_Engine.prototype.convertSpansToFonts = function(doc) { 4132 var sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(','); 4133 4134 /*var h = doc.body.innerHTML; 4135 h = h.replace(/<span/gi, '<font'); 4136 h = h.replace(/<\/span/gi, '</font'); 4137 tinyMCE.setInnerHTML(doc.body, h);*/ 4138 4139 var s = tinyMCE.selectElements(doc, 'span,font'); 4140 for (var i=0; i<s.length; i++) { 4141 var size = tinyMCE.trim(s[i].style.fontSize).toLowerCase(); 4142 var fSize = 0; 4143 4144 for (var x=0; x<sizes.length; x++) { 4145 if (sizes[x] == size) { 4146 fSize = x + 1; 4147 break; 4148 } 4149 } 4150 4151 if (fSize > 0) { 4152 tinyMCE.setAttrib(s[i], 'size', fSize); 4153 s[i].style.fontSize = ''; 4154 } 4155 4156 var fFace = s[i].style.fontFamily; 4157 if (fFace != null && fFace != "") { 4158 tinyMCE.setAttrib(s[i], 'face', fFace); 4159 s[i].style.fontFamily = ''; 4160 } 4161 4162 var fColor = s[i].style.color; 4163 if (fColor != null && fColor != "") { 4164 tinyMCE.setAttrib(s[i], 'color', tinyMCE.convertRGBToHex(fColor)); 4165 s[i].style.color = ''; 4166 } 4167 } 4168 }; 4169 4170 TinyMCE_Engine.prototype.convertFontsToSpans = function(doc) { 4171 var sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(','); 4172 4173 /* var h = doc.body.innerHTML; 4174 h = h.replace(/<font/gi, '<span'); 4175 h = h.replace(/<\/font/gi, '</span'); 4176 tinyMCE.setInnerHTML(doc.body, h);*/ 4177 4178 var fsClasses = tinyMCE.getParam('font_size_classes'); 4179 if (fsClasses != '') 4180 fsClasses = fsClasses.replace(/\s+/, '').split(','); 4181 else 4182 fsClasses = null; 4183 4184 var s = tinyMCE.selectElements(doc, 'span,font'); 4185 for (var i=0; i<s.length; i++) { 4186 var fSize, fFace, fColor; 4187 4188 fSize = tinyMCE.getAttrib(s[i], 'size'); 4189 fFace = tinyMCE.getAttrib(s[i], 'face'); 4190 fColor = tinyMCE.getAttrib(s[i], 'color'); 4191 4192 if (fSize != "") { 4193 fSize = parseInt(fSize); 4194 4195 if (fSize > 0 && fSize < 8) { 4196 if (fsClasses != null) 4197 tinyMCE.setAttrib(s[i], 'class', fsClasses[fSize-1]); 4198 else 4199 s[i].style.fontSize = sizes[fSize-1]; 4200 } 4201 4202 s[i].removeAttribute('size'); 4203 } 4204 4205 if (fFace != "") { 4206 s[i].style.fontFamily = fFace; 4207 s[i].removeAttribute('face'); 4208 } 4209 4210 if (fColor != "") { 4211 s[i].style.color = fColor; 4212 s[i].removeAttribute('color'); 4213 } 4214 } 4215 }; 4216 4217 TinyMCE_Engine.prototype.cleanupAnchors = function(doc) { 4218 var i, cn, x, an = doc.getElementsByTagName("a"); 4219 4220 // Loops backwards due to bug #1467987 4221 for (i=an.length-1; i>=0; i--) { 4222 if (tinyMCE.getAttrib(an[i], "name") != "" && tinyMCE.getAttrib(an[i], "href") == "") { 4223 cn = an[i].childNodes; 4224 4225 for (x=cn.length-1; x>=0; x--) 4226 tinyMCE.insertAfter(cn[x], an[i]); 4227 } 4228 } 4229 }; 4230 4231 TinyMCE_Engine.prototype.getContent = function(editor_id) { 4232 if (typeof(editor_id) != "undefined") 4233 tinyMCE.getInstanceById(editor_id).select(); 4234 4235 if (tinyMCE.selectedInstance) 4236 return tinyMCE.selectedInstance.getHTML(); 4237 4238 return null; 4239 }; 4240 4241 TinyMCE_Engine.prototype._fixListElements = function(d) { 4242 var nl, x, a = ['ol', 'ul'], i, n, p, r = new RegExp('^(OL|UL)$'), np; 4243 4244 for (x=0; x<a.length; x++) { 4245 nl = d.getElementsByTagName(a[x]); 4246 4247 for (i=0; i<nl.length; i++) { 4248 n = nl[i]; 4249 p = n.parentNode; 4250 4251 if (r.test(p.nodeName)) { 4252 np = tinyMCE.prevNode(n, 'LI'); 4253 4254 if (!np) { 4255 np = d.createElement('li'); 4256 np.innerHTML = ' '; 4257 np.appendChild(n); 4258 p.insertBefore(np, p.firstChild); 4259 } else 4260 np.appendChild(n); 4261 } 4262 } 4263 } 4264 }; 4265 4266 TinyMCE_Engine.prototype._fixTables = function(d) { 4267 var nl, i, n, p, np, x, t; 4268 4269 nl = d.getElementsByTagName('table'); 4270 for (i=0; i<nl.length; i++) { 4271 n = nl[i]; 4272 4273 if ((p = tinyMCE.getParentElement(n, 'p,h1,h2,h3,h4,h5,h6')) != null) { 4274 np = p.cloneNode(false); 4275 np.removeAttribute('id'); 4276 4277 t = n; 4278 4279 while ((n = n.nextSibling)) 4280 np.appendChild(n); 4281 4282 tinyMCE.insertAfter(np, p); 4283 tinyMCE.insertAfter(t, p); 4284 } 4285 } 4286 }; 4287 4288 TinyMCE_Engine.prototype._cleanupHTML = function(inst, doc, config, elm, visual, on_save, on_submit, inn) { 4289 var h, d, t1, t2, t3, t4, t5, c, s, nb; 4290 4291 if (!tinyMCE.getParam('cleanup')) 4292 return elm.innerHTML; 4293 4294 on_save = typeof(on_save) == 'undefined' ? false : on_save; 4295 4296 c = inst.cleanup; 4297 s = inst.settings; 4298 d = c.settings.debug; 4299 4300 if (d) 4301 t1 = new Date().getTime(); 4302 4303 if (tinyMCE.getParam("convert_fonts_to_spans")) 4304 tinyMCE.convertFontsToSpans(doc); 4305 4306 if (tinyMCE.getParam("fix_list_elements")) 4307 tinyMCE._fixListElements(doc); 4308 4309 if (tinyMCE.getParam("fix_table_elements")) 4310 tinyMCE._fixTables(doc); 4311 4312 // Call custom cleanup code 4313 tinyMCE._customCleanup(inst, on_save ? "get_from_editor_dom" : "insert_to_editor_dom", doc.body); 4314 4315 if (d) 4316 t2 = new Date().getTime(); 4317 4318 c.settings.on_save = on_save; 4319 //for (var i=0; i<100; i++) 4320 4321 c.idCount = 0; 4322 c.serializationId++; 4323 c.serializedNodes = new Array(); 4324 c.sourceIndex = -1; 4325 4326 if (s.cleanup_serializer == "xml") 4327 h = c.serializeNodeAsXML(elm, inn); 4328 else 4329 h = c.serializeNodeAsHTML(elm, inn); 4330 4331 if (d) 4332 t3 = new Date().getTime(); 4333 4334 // Post processing 4335 nb = tinyMCE.getParam('entity_encoding') == 'numeric' ? ' ' : ' '; 4336 h = h.replace(/<\/?(body|head|html)[^>]*>/gi, ''); 4337 h = h.replace(new RegExp(' (rowspan="1"|colspan="1")', 'g'), ''); 4338 h = h.replace(/<p><hr \/><\/p>/g, '<hr />'); 4339 h = h.replace(/<p>( | )<\/p><hr \/><p>( | )<\/p>/g, '<hr />'); 4340 h = h.replace(/<td>\s*<br \/>\s*<\/td>/g, '<td>' + nb + '</td>'); 4341 h = h.replace(/<p>\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>'); 4342 h = h.replace(/<br \/>$/, ''); // Remove last BR for Gecko 4343 h = h.replace(/<br \/><\/p>/g, '</p>'); // Remove last BR in P tags for Gecko 4344 h = h.replace(/<p>\s*( | )\s*<br \/>\s*( | )\s*<\/p>/g, '<p>' + nb + '</p>'); 4345 h = h.replace(/<p>\s*( | )\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>'); 4346 h = h.replace(/<p>\s*<br \/>\s* \s*<\/p>/g, '<p>' + nb + '</p>'); 4347 h = h.replace(new RegExp('<a>(.*?)<\\/a>', 'g'), '$1'); 4348 h = h.replace(/<p([^>]*)>\s*<\/p>/g, '<p$1>' + nb + '</p>'); 4349 4350 // Clean body 4351 if (/^\s*(<br \/>|<p> <\/p>|<p> <\/p>|<p><\/p>)\s*$/.test(h)) 4352 h = ''; 4353 4354 // If preformatted 4355 if (s.preformatted) { 4356 h = h.replace(/^<pre>/, ''); 4357 h = h.replace(/<\/pre>$/, ''); 4358 h = '<pre>' + h + '</pre>'; 4359 } 4360 4361 // Gecko specific processing 4362 if (tinyMCE.isGecko) { 4363 h = h.replace(/<o:p _moz-userdefined="" \/>/g, ''); 4364 h = h.replace(/<td([^>]*)>\s*<br \/>\s*<\/td>/g, '<td$1>' + nb + '</td>'); 4365 } 4366 4367 if (s.force_br_newlines) 4368 h = h.replace(/<p>( | )<\/p>/g, '<br />'); 4369 4370 // Call custom cleanup code 4371 h = tinyMCE._customCleanup(inst, on_save ? "get_from_editor" : "insert_to_editor", h); 4372 4373 // Remove internal classes 4374 if (on_save) { 4375 h = h.replace(new RegExp(' ?(mceItem[a-zA-Z0-9]*|' + s.visual_table_class + ')', 'g'), ''); 4376 h = h.replace(new RegExp(' ?class=""', 'g'), ''); 4377 } 4378 4379 if (s.remove_linebreaks && !c.settings.indent) 4380 h = h.replace(/\n|\r/g, ' '); 4381 4382 if (d) 4383 t4 = new Date().getTime(); 4384 4385 if (on_save && c.settings.indent) 4386 h = c.formatHTML(h); 4387 4388 // If encoding (not recommended option) 4389 if (on_submit && (s.encoding == "xml" || s.encoding == "html")) 4390 h = c.xmlEncode(h); 4391 4392 if (d) 4393 t5 = new Date().getTime(); 4394 4395 if (c.settings.debug) 4396 tinyMCE.debug("Cleanup in ms: Pre=" + (t2-t1) + ", Serialize: " + (t3-t2) + ", Post: " + (t4-t3) + ", Format: " + (t5-t4) + ", Sum: " + (t5-t1) + "."); 4397 4398 return h; 4399 }; 4400 4401 function TinyMCE_Cleanup() { 4402 this.isIE = (navigator.appName == "Microsoft Internet Explorer"); 4403 this.rules = tinyMCE.clearArray(new Array()); 4404 4405 // Default config 4406 this.settings = { 4407 indent_elements : 'head,table,tbody,thead,tfoot,form,tr,ul,ol,blockquote,object', 4408 newline_before_elements : 'h1,h2,h3,h4,h5,h6,pre,address,div,ul,ol,li,meta,option,area,title,link,base,script,td', 4409 newline_after_elements : 'br,hr,p,pre,address,div,ul,ol,meta,option,area,link,base,script', 4410 newline_before_after_elements : 'html,head,body,table,thead,tbody,tfoot,tr,form,ul,ol,blockquote,p,object,param,hr,div', 4411 indent_char : '\t', 4412 indent_levels : 1, 4413 entity_encoding : 'raw', 4414 valid_elements : '*[*]', 4415 entities : '', 4416 url_converter : '', 4417 invalid_elements : '', 4418 verify_html : false 4419 }; 4420 4421 this.vElements = tinyMCE.clearArray(new Array()); 4422 this.vElementsRe = ''; 4423 this.closeElementsRe = /^(IMG|BR|HR|LINK|META|BASE|INPUT|AREA)$/; 4424 this.codeElementsRe = /^(SCRIPT|STYLE)$/; 4425 this.serializationId = 0; 4426 this.mceAttribs = { 4427 href : 'mce_href', 4428 src : 'mce_src', 4429 type : 'mce_type' 4430 }; 4431 } 4432 4433 TinyMCE_Cleanup.prototype = { 4434 init : function(s) { 4435 var n, a, i, ir, or, st; 4436 4437 for (n in s) 4438 this.settings[n] = s[n]; 4439 4440 // Setup code formating 4441 s = this.settings; 4442 4443 // Setup regexps 4444 this.inRe = this._arrayToRe(s.indent_elements.split(','), '', '^<(', ')[^>]*'); 4445 this.ouRe = this._arrayToRe(s.indent_elements.split(','), '', '^<\\/(', ')[^>]*'); 4446 this.nlBeforeRe = this._arrayToRe(s.newline_before_elements.split(','), 'gi', '<(', ')([^>]*)>'); 4447 this.nlAfterRe = this._arrayToRe(s.newline_after_elements.split(','), 'gi', '<(', ')([^>]*)>'); 4448 this.nlBeforeAfterRe = this._arrayToRe(s.newline_before_after_elements.split(','), 'gi', '<(\\/?)(', ')([^>]*)>'); 4449 this.serializedNodes = []; 4450 4451 if (s.invalid_elements != '') 4452 this.iveRe = this._arrayToRe(s.invalid_elements.toUpperCase().split(','), 'g', '^(', ')$'); 4453 else 4454 this.iveRe = null; 4455 4456 // Setup separator 4457 st = ''; 4458 for (i=0; i<s.indent_levels; i++) 4459 st += s.indent_char; 4460 4461 this.inStr = st; 4462 4463 // If verify_html if false force *[*] 4464 if (!s.verify_html) { 4465 s.valid_elements = '*[*]'; 4466 s.extended_valid_elements = ''; 4467 } 4468 4469 this.fillStr = s.entity_encoding == "named" ? " " : " "; 4470 this.idCount = 0; 4471 this.xmlEncodeRe = new RegExp('[\u007F-\uFFFF<>&"]', 'g'); 4472 this.xmlEncodeAposRe = new RegExp('[\u007F-\uFFFF<>&"\']', 'g'); 4473 }, 4474 4475 addRuleStr : function(s) { 4476 var r = this.parseRuleStr(s); 4477 var n; 4478 4479 for (n in r) { 4480 if (r[n]) 4481 this.rules[n] = r[n]; 4482 } 4483 4484 this.vElements = tinyMCE.clearArray(new Array()); 4485 4486 for (n in this.rules) { 4487 if (this.rules[n]) 4488 this.vElements[this.vElements.length] = this.rules[n].tag; 4489 } 4490 4491 this.vElementsRe = this._arrayToRe(this.vElements, ''); 4492 }, 4493 4494 isValid : function(n) { 4495 this._setupRules(); // Will initialize cleanup rules 4496 4497 // Empty is true since it removes formatting 4498 if (!n) 4499 return true; 4500 4501 // Clean the name up a bit 4502 n = n.replace(/[^a-z0-9]+/gi, '').toUpperCase(); 4503 4504 return !tinyMCE.getParam('cleanup') || this.vElementsRe.test(n); 4505 }, 4506 4507 addChildRemoveRuleStr : function(s) { 4508 var x, y, p, i, t, tn, ta, cl, r; 4509 4510 if (!s) 4511 return; 4512 4513 ta = s.split(','); 4514 for (x=0; x<ta.length; x++) { 4515 s = ta[x]; 4516 4517 // Split tag/children 4518 p = this.split(/\[|\]/, s); 4519 if (p == null || p.length < 1) 4520 t = s.toUpperCase(); 4521 else 4522 t = p[0].toUpperCase(); 4523 4524 // Handle all tag names 4525 tn = this.split('/', t); 4526 for (y=0; y<tn.length; y++) { 4527 r = "^("; 4528 4529 // Build regex 4530 cl = this.split(/\|/, p[1]); 4531 for (i=0; i<cl.length; i++) { 4532 if (cl[i] == '%istrict') 4533 r += tinyMCE.inlineStrict; 4534 else if (cl[i] == '%itrans') 4535 r += tinyMCE.inlineTransitional; 4536 else if (cl[i] == '%istrict_na') 4537 r += tinyMCE.inlineStrict.substring(2); 4538 else if (cl[i] == '%itrans_na') 4539 r += tinyMCE.inlineTransitional.substring(2); 4540 else if (cl[i] == '%btrans') 4541 r += tinyMCE.blockElms; 4542 else if (cl[i] == '%strict') 4543 r += tinyMCE.blockStrict; 4544 else 4545 r += (cl[i].charAt(0) != '#' ? cl[i].toUpperCase() : cl[i]); 4546 4547 r += (i != cl.length - 1 ? '|' : ''); 4548 } 4549 4550 r += ')$'; 4551 //tinyMCE.debug(t + "=" + r); 4552 if (this.childRules == null) 4553 this.childRules = tinyMCE.clearArray(new Array()); 4554 4555 this.childRules[tn[y]] = new RegExp(r); 4556 4557 if (p.length > 1) 4558 this.childRules[tn[y]].wrapTag = p[2]; 4559 } 4560 } 4561 }, 4562 4563 parseRuleStr : function(s) { 4564 var ta, p, r, a, i, x, px, t, tn, y, av, or = tinyMCE.clearArray(new Array()), dv; 4565 4566 if (s == null || s.length == 0) 4567 return or; 4568 4569 ta = s.split(','); 4570 for (x=0; x<ta.length; x++) { 4571 s = ta[x]; 4572 if (s.length == 0) 4573 continue; 4574 4575 // Split tag/attrs 4576 p = this.split(/\[|\]/, s); 4577 if (p == null || p.length < 1) 4578 t = s.toUpperCase(); 4579 else 4580 t = p[0].toUpperCase(); 4581 4582 // Handle all tag names 4583 tn = this.split('/', t); 4584 for (y=0; y<tn.length; y++) { 4585 r = {}; 4586 4587 r.tag = tn[y]; 4588 r.forceAttribs = null; 4589 r.defaultAttribs = null; 4590 r.validAttribValues = null; 4591 4592 // Handle prefixes 4593 px = r.tag.charAt(0); 4594 r.forceOpen = px == '+'; 4595 r.removeEmpty = px == '-'; 4596 r.fill = px == '#'; 4597 r.tag = r.tag.replace(/\+|-|#/g, ''); 4598 r.oTagName = tn[0].replace(/\+|-|#/g, '').toLowerCase(); 4599 r.isWild = new RegExp('\\*|\\?|\\+', 'g').test(r.tag); 4600 r.validRe = new RegExp(this._wildcardToRe('^' + r.tag + '$')); 4601 4602 // Setup valid attributes 4603 if (p.length > 1) { 4604 r.vAttribsRe = '^('; 4605 a = this.split(/\|/, p[1]); 4606 4607 for (i=0; i<a.length; i++) { 4608 t = a[i]; 4609 4610 if (t.charAt(0) == '!') { 4611 a[i] = t = t.substring(1); 4612 4613 if (!r.reqAttribsRe) 4614 r.reqAttribsRe = '\\s+(' + t; 4615 else 4616 r.reqAttribsRe += '|' + t; 4617 } 4618 4619 av = new RegExp('(=|:|<)(.*?)$').exec(t); 4620 t = t.replace(new RegExp('(=|:|<).*?$'), ''); 4621 if (av && av.length > 0) { 4622 if (av[0].charAt(0) == ':') { 4623 if (!r.forceAttribs) 4624 r.forceAttribs = tinyMCE.clearArray(new Array()); 4625 4626 r.forceAttribs[t.toLowerCase()] = av[0].substring(1); 4627 } else if (av[0].charAt(0) == '=') { 4628 if (!r.defaultAttribs) 4629 r.defaultAttribs = tinyMCE.clearArray(new Array()); 4630 4631 dv = av[0].substring(1); 4632 4633 r.defaultAttribs[t.toLowerCase()] = dv == "" ? "mce_empty" : dv; 4634 } else if (av[0].charAt(0) == '<') { 4635 if (!r.validAttribValues) 4636 r.validAttribValues = tinyMCE.clearArray(new Array()); 4637 4638 r.validAttribValues[t.toLowerCase()] = this._arrayToRe(this.split('?', av[0].substring(1)), 'i'); 4639 } 4640 } 4641 4642 r.vAttribsRe += '' + t.toLowerCase() + (i != a.length - 1 ? '|' : ''); 4643 4644 a[i] = t.toLowerCase(); 4645 } 4646 4647 if (r.reqAttribsRe) 4648 r.reqAttribsRe = new RegExp(r.reqAttribsRe + ')=\"', 'g'); 4649 4650 r.vAttribsRe += ')$'; 4651 r.vAttribsRe = this._wildcardToRe(r.vAttribsRe); 4652 r.vAttribsReIsWild = new RegExp('\\*|\\?|\\+', 'g').test(r.vAttribsRe); 4653 r.vAttribsRe = new RegExp(r.vAttribsRe); 4654 r.vAttribs = a.reverse(); 4655 4656 //tinyMCE.debug(r.tag, r.oTagName, r.vAttribsRe, r.vAttribsReWC); 4657 } else { 4658 r.vAttribsRe = ''; 4659 r.vAttribs = tinyMCE.clearArray(new Array()); 4660 r.vAttribsReIsWild = false; 4661 } 4662 4663 or[r.tag] = r; 4664 } 4665 } 4666 4667 return or; 4668 }, 4669 4670 serializeNodeAsXML : function(n) { 4671 var s, b; 4672 4673 if (!this.xmlDoc) { 4674 if (this.isIE) { 4675 try {this.xmlDoc = new ActiveXObject('MSXML2.DOMDocument');} catch (e) {} 4676 4677 if (!this.xmlDoc) 4678 try {this.xmlDoc = new ActiveXObject('Microsoft.XmlDom');} catch (e) {} 4679 } else 4680 this.xmlDoc = document.implementation.createDocument('', '', null); 4681 4682 if (!this.xmlDoc) 4683 alert("Error XML Parser could not be found."); 4684 } 4685 4686 if (this.xmlDoc.firstChild) 4687 this.xmlDoc.removeChild(this.xmlDoc.firstChild); 4688 4689 b = this.xmlDoc.createElement("html"); 4690 b = this.xmlDoc.appendChild(b); 4691 4692 this._convertToXML(n, b); 4693 4694 if (this.isIE) 4695 return this.xmlDoc.xml; 4696 else 4697 return new XMLSerializer().serializeToString(this.xmlDoc); 4698 }, 4699 4700 _convertToXML : function(n, xn) { 4701 var xd, el, i, l, cn, at, no, hc = false; 4702 4703 if (tinyMCE.isRealIE && this._isDuplicate(n)) 4704 return; 4705 4706 xd = this.xmlDoc; 4707 4708 switch (n.nodeType) { 4709 case 1: // Element 4710 hc = n.hasChildNodes(); 4711 4712 el = xd.createElement(n.nodeName.toLowerCase()); 4713 4714 at = n.attributes; 4715 for (i=at.length-1; i>-1; i--) { 4716 no = at[i]; 4717 4718 if (no.specified && no.nodeValue) 4719 el.setAttribute(no.nodeName.toLowerCase(), no.nodeValue); 4720 } 4721 4722 if (!hc && !this.closeElementsRe.test(n.nodeName)) 4723 el.appendChild(xd.createTextNode("")); 4724 4725 xn = xn.appendChild(el); 4726 break; 4727 4728 case 3: // Text 4729 xn.appendChild(xd.createTextNode(n.nodeValue)); 4730 return; 4731 4732 case 8: // Comment 4733 xn.appendChild(xd.createComment(n.nodeValue)); 4734 return; 4735 } 4736 4737 if (hc) { 4738 cn = n.childNodes; 4739 4740 for (i=0, l=cn.length; i<l; i++) 4741 this._convertToXML(cn[i], xn); 4742 } 4743 }, 4744 4745 serializeNodeAsHTML : function(n, inn) { 4746 var en, no, h = '', i, l, t, st, r, cn, va = false, f = false, at, hc, cr, nn; 4747 4748 this._setupRules(); // Will initialize cleanup rules 4749 4750 if (tinyMCE.isRealIE && this._isDuplicate(n)) 4751 return ''; 4752 4753 // Skip non valid child elements 4754 if (n.parentNode && this.childRules != null) { 4755 cr = this.childRules[n.parentNode.nodeName]; 4756 4757 if (typeof(cr) != "undefined" && !cr.test(n.nodeName)) { 4758 st = true; 4759 t = null; 4760 } 4761 } 4762 4763 switch (n.nodeType) { 4764 case 1: // Element 4765 hc = n.hasChildNodes(); 4766 4767 if (st) 4768 break; 4769 4770 // MSIE sometimes produces <//tag> 4771 if ((tinyMCE.isRealIE) && n.nodeName.indexOf('/') != -1) 4772 break; 4773 4774 nn = n.nodeName; 4775 4776 // Convert fonts to spans 4777 if (this.settings.convert_fonts_to_spans) { 4778 // On get content FONT -> SPAN 4779 if (this.settings.on_save && nn == 'FONT') 4780 nn = 'SPAN'; 4781 4782 // On insert content SPAN -> FONT 4783 if (!this.settings.on_save && nn == 'SPAN') 4784 nn = 'FONT'; 4785 } 4786 4787 if (this.vElementsRe.test(nn) && (!this.iveRe || !this.iveRe.test(nn)) && !inn) { 4788 va = true; 4789 4790 r = this.rules[nn]; 4791 if (!r) { 4792 at = this.rules; 4793 for (no in at) { 4794 if (at[no] && at[no].validRe.test(nn)) { 4795 r = at[no]; 4796 break; 4797 } 4798 } 4799 } 4800 4801 en = r.isWild ? nn.toLowerCase() : r.oTagName; 4802 f = r.fill; 4803 4804 if (r.removeEmpty && !hc) 4805 return ""; 4806 4807 t = '<' + en; 4808 4809 if (r.vAttribsReIsWild) { 4810 // Serialize wildcard attributes 4811 at = n.attributes; 4812 for (i=at.length-1; i>-1; i--) { 4813 no = at[i]; 4814 if (no.specified && r.vAttribsRe.test(no.nodeName)) 4815 t += this._serializeAttribute(n, r, no.nodeName); 4816 } 4817 } else { 4818 // Serialize specific attributes 4819 for (i=r.vAttribs.length-1; i>-1; i--) 4820 t += this._serializeAttribute(n, r, r.vAttribs[i]); 4821 } 4822 4823 // Serialize mce_ atts 4824 if (!this.settings.on_save) { 4825 at = this.mceAttribs; 4826 4827 for (no in at) { 4828 if (at[no]) 4829 t += this._serializeAttribute(n, r, at[no]); 4830 } 4831 } 4832 4833 // Check for required attribs 4834 if (r.reqAttribsRe && !t.match(r.reqAttribsRe)) 4835 t = null; 4836 4837 // Close these 4838 if (t != null && this.closeElementsRe.test(nn)) 4839 return t + ' />'; 4840 4841 if (t != null) 4842 h += t + '>'; 4843 4844 if (this.isIE && this.codeElementsRe.test(nn)) 4845 h += n.innerHTML; 4846 } 4847 break; 4848 4849 case 3: // Text 4850 if (st) 4851 break; 4852 4853 if (n.parentNode && this.codeElementsRe.test(n.parentNode.nodeName)) 4854 return this.isIE ? '' : n.nodeValue; 4855 4856 return this.xmlEncode(n.nodeValue); 4857 4858 case 8: // Comment 4859 if (st) 4860 break; 4861 4862 return "<!--" + this._trimComment(n.nodeValue) + "-->"; 4863 } 4864 4865 if (hc) { 4866 cn = n.childNodes; 4867 4868 for (i=0, l=cn.length; i<l; i++) 4869 h += this.serializeNodeAsHTML(cn[i]); 4870 } 4871 4872 // Fill empty nodes 4873 if (f && !hc) 4874 h += this.fillStr; 4875 4876 // End element 4877 if (t != null && va) 4878 h += '</' + en + '>'; 4879 4880 return h; 4881 }, 4882 4883 _serializeAttribute : function(n, r, an) { 4884 var av = '', t, os = this.settings.on_save; 4885 4886 if (os && (an.indexOf('mce_') == 0 || an.indexOf('_moz') == 0)) 4887 return ''; 4888 4889 if (os && this.mceAttribs[an]) 4890 av = this._getAttrib(n, this.mceAttribs[an]); 4891 4892 if (av.length == 0) 4893 av = this._getAttrib(n, an); 4894 4895 if (av.length == 0 && r.defaultAttribs && (t = r.defaultAttribs[an])) { 4896 av = t; 4897 4898 if (av == "mce_empty") 4899 return " " + an + '=""'; 4900 } 4901 4902 if (r.forceAttribs && (t = r.forceAttribs[an])) 4903 av = t; 4904 4905 if (os && av.length != 0 && /^(src|href|longdesc)$/.test(an)) 4906 av = this._urlConverter(this, n, av); 4907 4908 if (av.length != 0 && r.validAttribValues && r.validAttribValues[an] && !r.validAttribValues[an].test(av)) 4909 return ""; 4910 4911 if (av.length != 0 && av == "{$uid}") 4912 av = "uid_" + (this.idCount++); 4913 4914 if (av.length != 0) { 4915 if (an.indexOf('on') != 0) 4916 av = this.xmlEncode(av, 1); 4917 4918 return " " + an + "=" + '"' + av + '"'; 4919 } 4920 4921 return ""; 4922 }, 4923 4924 formatHTML : function(h) { 4925 var s = this.settings, p = '', i = 0, li = 0, o = '', l; 4926 4927 // Replace BR in pre elements to \n 4928 h = h.replace(/<pre([^>]*)>(.*?)<\/pre>/gi, function (a, b, c) { 4929 c = c.replace(/<br\s*\/>/gi, '\n'); 4930 return '<pre' + b + '>' + c + '</pre>'; 4931 }); 4932 4933 h = h.replace(/\r/g, ''); // Windows sux, isn't carriage return a thing of the past :) 4934 h = '\n' + h; 4935 h = h.replace(new RegExp('\\n\\s+', 'gi'), '\n'); // Remove previous formatting 4936 h = h.replace(this.nlBeforeRe, '\n<$1$2>'); 4937 h = h.replace(this.nlAfterRe, '<$1$2>\n'); 4938 h = h.replace(this.nlBeforeAfterRe, '\n<$1$2$3>\n'); 4939 h += '\n'; 4940 4941 //tinyMCE.debug(h); 4942 4943 while ((i = h.indexOf('\n', i + 1)) != -1) { 4944 if ((l = h.substring(li + 1, i)).length != 0) { 4945 if (this.ouRe.test(l) && p.length >= s.indent_levels) 4946 p = p.substring(s.indent_levels); 4947 4948 o += p + l + '\n'; 4949 4950 if (this.inRe.test(l)) 4951 p += this.inStr; 4952 } 4953 4954 li = i; 4955 } 4956 4957 //tinyMCE.debug(h); 4958 4959 return o; 4960 }, 4961 4962 xmlEncode : function(s, skip_apos) { 4963 var cl = this, re = !skip_apos ? this.xmlEncodeAposRe : this.xmlEncodeRe; 4964 4965 this._setupEntities(); // Will intialize lookup table 4966 4967 switch (this.settings.entity_encoding) { 4968 case "raw": 4969 return tinyMCE.xmlEncode(s, skip_apos); 4970 4971 case "named": 4972 return s.replace(re, function (c, b) { 4973 b = cl.entities[c.charCodeAt(0)]; 4974 4975 return b ? '&' + b + ';' : c; 4976 }); 4977 4978 case "numeric": 4979 return s.replace(re, function (c, b) { 4980 return b ? '&#' + c.charCodeAt(0) + ';' : c; 4981 }); 4982 } 4983 4984 return s; 4985 }, 4986 4987 split : function(re, s) { 4988 var c = s.split(re); 4989 var i, l, o = new Array(); 4990 4991 for (i=0, l=c.length; i<l; i++) { 4992 if (c[i] != '') 4993 o[i] = c[i]; 4994 } 4995 4996 return o; 4997 }, 4998 4999 _trimComment : function(s) { 5000 // Remove mce_src, mce_href 5001 s = s.replace(new RegExp('\\smce_src=\"[^\"]*\"', 'gi'), ""); 5002 s = s.replace(new RegExp('\\smce_href=\"[^\"]*\"', 'gi'), ""); 5003 5004 return s; 5005 }, 5006 5007 _getAttrib : function(e, n, d) { 5008 var v, ex, nn; 5009 5010 if (typeof(d) == "undefined") 5011 d = ""; 5012 5013 if (!e || e.nodeType != 1) 5014 return d; 5015 5016 try { 5017 v = e.getAttribute(n, 0); 5018 } catch (ex) { 5019 // IE 7 may cast exception on invalid attributes 5020 v = e.getAttribute(n, 2); 5021 } 5022 5023 if (n == "class" && !v) 5024 v = e.className; 5025 5026 if (this.isIE) { 5027 if (n == "http-equiv") 5028 v = e.httpEquiv; 5029 5030 nn = e.nodeName; 5031 5032 // Skip the default values that IE returns 5033 if (nn == "FORM" && n == "enctype" && v == "application/x-www-form-urlencoded") 5034 v = ""; 5035 5036 if (nn == "INPUT" && n == "size" && v == "20") 5037 v = ""; 5038 5039 if (nn == "INPUT" && n == "maxlength" && v == "2147483647") 5040 v = ""; 5041 } 5042 5043 if (n == 'style' && v) { 5044 if (!tinyMCE.isOpera) 5045 v = e.style.cssText; 5046 5047 v = tinyMCE.serializeStyle(tinyMCE.parseStyle(v)); 5048 } 5049 5050 if (this.settings.on_save && n.indexOf('on') != -1 && this.settings.on_save && v && v != "") 5051 v = tinyMCE.cleanupEventStr(v); 5052 5053 return (v && v != "") ? '' + v : d; 5054 }, 5055 5056 _urlConverter : function(c, n, v) { 5057 if (!c.settings.on_save) 5058 return tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, v); 5059 else if (tinyMCE.getParam('convert_urls')) { 5060 if (!this.urlConverter) 5061 this.urlConverter = eval(tinyMCE.settings.urlconverter_callback); 5062 5063 return this.urlConverter(v, n, true); 5064 } 5065 5066 return v; 5067 }, 5068 5069 _arrayToRe : function(a, op, be, af) { 5070 var i, r; 5071 5072 op = typeof(op) == "undefined" ? "gi" : op; 5073 be = typeof(be) == "undefined" ? "^(" : be; 5074 af = typeof(af) == "undefined" ? ")$" : af; 5075 5076 r = be; 5077 5078 for (i=0; i<a.length; i++) 5079 r += this._wildcardToRe(a[i]) + (i != a.length-1 ? "|" : ""); 5080 5081 r += af; 5082 5083 return new RegExp(r, op); 5084 }, 5085 5086 _wildcardToRe : function(s) { 5087 s = s.replace(/\?/g, '(\\S?)'); 5088 s = s.replace(/\+/g, '(\\S+)'); 5089 s = s.replace(/\*/g, '(\\S*)'); 5090 5091 return s; 5092 }, 5093 5094 _setupEntities : function() { 5095 var n, a, i, s = this.settings; 5096 5097 // Setup entities 5098 if (!this.entitiesDone) { 5099 if (s.entity_encoding == "named") { 5100 n = tinyMCE.clearArray(new Array()); 5101 a = this.split(',', s.entities); 5102 for (i=0; i<a.length; i+=2) 5103 n[a[i]] = a[i+1]; 5104 5105 this.entities = n; 5106 } 5107 5108 this.entitiesDone = true; 5109 } 5110 }, 5111 5112 _setupRules : function() { 5113 var s = this.settings; 5114 5115 // Setup default rule 5116 if (!this.rulesDone) { 5117 this.addRuleStr(s.valid_elements); 5118 this.addRuleStr(s.extended_valid_elements); 5119 this.addChildRemoveRuleStr(s.valid_child_elements); 5120 5121 this.rulesDone = true; 5122 } 5123 }, 5124 5125 _isDuplicate : function(n) { 5126 var i; 5127 5128 if (!this.settings.fix_content_duplication) 5129 return false; 5130 5131 if (tinyMCE.isRealIE && n.nodeType == 1) { 5132 // Mark elements 5133 if (n.mce_serialized == this.serializationId) 5134 return true; 5135 5136 n.setAttribute('mce_serialized', this.serializationId); 5137 } else { 5138 // Search lookup table for text nodes and comments 5139 for (i=0; i<this.serializedNodes.length; i++) { 5140 if (this.serializedNodes[i] == n) 5141 return true; 5142 } 5143 5144 this.serializedNodes[this.serializedNodes.length] = n; 5145 } 5146 5147 return false; 5148 } 5149 5150 }; 5151 5152 /* file:jscripts/tiny_mce/classes/TinyMCE_DOMUtils.class.js */ 5153 5154 TinyMCE_Engine.prototype.createTagHTML = function(tn, a, h) { 5155 var o = '', f = tinyMCE.xmlEncode; 5156 5157 o = '<' + tn; 5158 5159 if (a) { 5160 for (n in a) { 5161 if (typeof(a[n]) != 'function' && a[n] != null) 5162 o += ' ' + f(n) + '="' + f('' + a[n]) + '"'; 5163 } 5164 } 5165 5166 o += !h ? ' />' : '>' + h + '</' + tn + '>'; 5167 5168 return o; 5169 }; 5170 5171 TinyMCE_Engine.prototype.createTag = function(d, tn, a, h) { 5172 var o = d.createElement(tn); 5173 5174 if (a) { 5175 for (n in a) { 5176 if (typeof(a[n]) != 'function' && a[n] != null) 5177 tinyMCE.setAttrib(o, n, a[n]); 5178 } 5179 } 5180 5181 if (h) 5182 o.innerHTML = h; 5183 5184 return o; 5185 }; 5186 5187 TinyMCE_Engine.prototype.getElementByAttributeValue = function(n, e, a, v) { 5188 return (n = this.getElementsByAttributeValue(n, e, a, v)).length == 0 ? null : n[0]; 5189 }; 5190 5191 TinyMCE_Engine.prototype.getElementsByAttributeValue = function(n, e, a, v) { 5192 var i, nl = n.getElementsByTagName(e), o = new Array(); 5193 5194 for (i=0; i<nl.length; i++) { 5195 if (tinyMCE.getAttrib(nl[i], a).indexOf(v) != -1) 5196 o[o.length] = nl[i]; 5197 } 5198 5199 return o; 5200 }; 5201 5202 TinyMCE_Engine.prototype.isBlockElement = function(n) { 5203 return n != null && n.nodeType == 1 && this.blockRegExp.test(n.nodeName); 5204 }; 5205 5206 TinyMCE_Engine.prototype.getParentBlockElement = function(n, r) { 5207 return this.getParentNode(n, function(n) { 5208 return tinyMCE.isBlockElement(n); 5209 }, r); 5210 5211 return null; 5212 }; 5213 5214 TinyMCE_Engine.prototype.insertAfter = function(n, r){ 5215 if (r.nextSibling) 5216 r.parentNode.insertBefore(n, r.nextSibling); 5217 else 5218 r.parentNode.appendChild(n); 5219 }; 5220 5221 TinyMCE_Engine.prototype.setInnerHTML = function(e, h) { 5222 var i, nl, n; 5223 5224 // Convert all strong/em to b/i in Gecko 5225 if (tinyMCE.isGecko) { 5226 h = h.replace(/<embed([^>]*)>/gi, '<tmpembed$1>'); 5227 h = h.replace(/<em([^>]*)>/gi, '<i$1>'); 5228 h = h.replace(/<tmpembed([^>]*)>/gi, '<embed$1>'); 5229 h = h.replace(/<strong([^>]*)>/gi, '<b$1>'); 5230 h = h.replace(/<\/strong>/gi, '</b>'); 5231 h = h.replace(/<\/em>/gi, '</i>'); 5232 } 5233 5234 if (tinyMCE.isRealIE) { 5235 // Since MSIE handles invalid HTML better that valid XHTML we 5236 // need to make some things invalid. <hr /> gets converted to <hr>. 5237 h = h.replace(/\s\/>/g, '>'); 5238 5239 // Since MSIE auto generated emtpy P tags some times we must tell it to keep the real ones 5240 h = h.replace(/<p([^>]*)>\u00A0?<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs 5241 h = h.replace(/<p([^>]*)>\s* \s*<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs 5242 h = h.replace(/<p([^>]*)>\s+<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs 5243 5244 // Remove first comment 5245 e.innerHTML = tinyMCE.uniqueTag + h; 5246 e.firstChild.removeNode(true); 5247 5248 // Remove weird auto generated empty paragraphs unless it's supposed to be there 5249 nl = e.getElementsByTagName("p"); 5250 for (i=nl.length-1; i>=0; i--) { 5251 n = nl[i]; 5252 5253 if (n.nodeName == 'P' && !n.hasChildNodes() && !n.mce_keep) 5254 n.parentNode.removeChild(n); 5255 } 5256 } else { 5257 h = this.fixGeckoBaseHREFBug(1, e, h); 5258 e.innerHTML = h; 5259 this.fixGeckoBaseHREFBug(2, e, h); 5260 } 5261 }; 5262 5263 TinyMCE_Engine.prototype.getOuterHTML = function(e) { 5264 if (tinyMCE.isIE) 5265 return e.outerHTML; 5266 5267 var d = e.ownerDocument.createElement("body"); 5268 d.appendChild(e.cloneNode(true)); 5269 return d.innerHTML; 5270 }; 5271 5272 TinyMCE_Engine.prototype.setOuterHTML = function(e, h, d) { 5273 var d = typeof(d) == "undefined" ? e.ownerDocument : d, i, nl, t; 5274 5275 if (tinyMCE.isIE && e.nodeType == 1) 5276 e.outerHTML = h; 5277 else { 5278 t = d.createElement("body"); 5279 t.innerHTML = h; 5280 5281 for (i=0, nl=t.childNodes; i<nl.length; i++) 5282 e.parentNode.insertBefore(nl[i].cloneNode(true), e); 5283 5284 e.parentNode.removeChild(e); 5285 } 5286 }; 5287 5288 TinyMCE_Engine.prototype._getElementById = function(id, d) { 5289 var e, i, j, f; 5290 5291 if (typeof(d) == "undefined") 5292 d = document; 5293 5294 e = d.getElementById(id); 5295 if (!e) { 5296 f = d.forms; 5297 5298 for (i=0; i<f.length; i++) { 5299 for (j=0; j<f[i].elements.length; j++) { 5300 if (f[i].elements[j].name == id) { 5301 e = f[i].elements[j]; 5302 break; 5303 } 5304 } 5305 } 5306 } 5307 5308 return e; 5309 }; 5310 5311 TinyMCE_Engine.prototype.getNodeTree = function(n, na, t, nn) { 5312 return this.selectNodes(n, function(n) { 5313 return (!t || n.nodeType == t) && (!nn || n.nodeName == nn); 5314 }, na ? na : new Array()); 5315 }; 5316 5317 TinyMCE_Engine.prototype.getParentElement = function(n, na, f, r) { 5318 var re = na ? new RegExp('^(' + na.toUpperCase().replace(/,/g, '|') + ')$') : 0, v; 5319 5320 // Compatiblity with old scripts where f param was a attribute string 5321 if (f && typeof(f) == 'string') 5322 return this.getParentElement(n, na, function(no) {return tinyMCE.getAttrib(no, f) != '';}); 5323 5324 return this.getParentNode(n, function(n) { 5325 return ((n.nodeType == 1 && !re) || (re && re.test(n.nodeName))) && (!f || f(n)); 5326 }, r); 5327 }; 5328 5329 TinyMCE_Engine.prototype.getParentNode = function(n, f, r) { 5330 while (n) { 5331 if (n == r) 5332 return null; 5333 5334 if (f(n)) 5335 return n; 5336 5337 n = n.parentNode; 5338 } 5339 5340 return null; 5341 }; 5342 5343 TinyMCE_Engine.prototype.getAttrib = function(elm, name, dv) { 5344 var v; 5345 5346 if (typeof(dv) == "undefined") 5347 dv = ""; 5348 5349 // Not a element 5350 if (!elm || elm.nodeType != 1) 5351 return dv; 5352 5353 try { 5354 v = elm.getAttribute(name, 0); 5355 } catch (ex) { 5356 // IE 7 may cast exception on invalid attributes 5357 v = elm.getAttribute(name, 2); 5358 } 5359 5360 // Try className for class attrib 5361 if (name == "class" && !v) 5362 v = elm.className; 5363 5364 // Workaround for a issue with Firefox 1.5rc2+ 5365 if (tinyMCE.isGecko && name == "src" && elm.src != null && elm.src != "") 5366 v = elm.src; 5367 5368 // Workaround for a issue with Firefox 1.5rc2+ 5369 if (tinyMCE.isGecko && name == "href" && elm.href != null && elm.href != "") 5370 v = elm.href; 5371 5372 if (name == "http-equiv" && tinyMCE.isIE) 5373 v = elm.httpEquiv; 5374 5375 if (name == "style" && !tinyMCE.isOpera) 5376 v = elm.style.cssText; 5377 5378 return (v && v != "") ? v : dv; 5379 }; 5380 5381 TinyMCE_Engine.prototype.setAttrib = function(el, name, va, fix) { 5382 if (typeof(va) == "number" && va != null) 5383 va = "" + va; 5384 5385 if (fix) { 5386 if (va == null) 5387 va = ""; 5388 5389 va = va.replace(/[^0-9%]/g, ''); 5390 } 5391 5392 if (name == "style") 5393 el.style.cssText = va; 5394 5395 if (name == "class") 5396 el.className = va; 5397 5398 if (va != null && va != "" && va != -1) 5399 el.setAttribute(name, va); 5400 else 5401 el.removeAttribute(name); 5402 }; 5403 5404 TinyMCE_Engine.prototype.setStyleAttrib = function(e, n, v) { 5405 e.style[n] = v; 5406 5407 // Style attrib deleted in IE 5408 if (tinyMCE.isIE && v == null || v == '') { 5409 v = tinyMCE.serializeStyle(tinyMCE.parseStyle(e.style.cssText)); 5410 e.style.cssText = v; 5411 e.setAttribute("style", v); 5412 } 5413 }; 5414 5415 TinyMCE_Engine.prototype.switchClass = function(ei, c) { 5416 var e; 5417 5418 if (tinyMCE.switchClassCache[ei]) 5419 e = tinyMCE.switchClassCache[ei]; 5420 else 5421 e = tinyMCE.switchClassCache[ei] = document.getElementById(ei); 5422 5423 if (e) { 5424 // Keep tile mode 5425 if (tinyMCE.settings.button_tile_map && e.className && e.className.indexOf('mceTiledButton') == 0) 5426 c = 'mceTiledButton ' + c; 5427 5428 e.className = c; 5429 } 5430 }; 5431 5432 TinyMCE_Engine.prototype.getAbsPosition = function(n, cn) { 5433 var l = 0, t = 0; 5434 5435 while (n && n != cn) { 5436 l += n.offsetLeft; 5437 t += n.offsetTop; 5438 n = n.offsetParent; 5439 } 5440 5441 return {absLeft : l, absTop : t}; 5442 }; 5443 5444 TinyMCE_Engine.prototype.prevNode = function(e, n) { 5445 var a = n.split(','), i; 5446 5447 while ((e = e.previousSibling) != null) { 5448 for (i=0; i<a.length; i++) { 5449 if (e.nodeName == a[i]) 5450 return e; 5451 } 5452 } 5453 5454 return null; 5455 }; 5456 5457 TinyMCE_Engine.prototype.nextNode = function(e, n) { 5458 var a = n.split(','), i; 5459 5460 while ((e = e.nextSibling) != null) { 5461 for (i=0; i<a.length; i++) { 5462 if (e.nodeName == a[i]) 5463 return e; 5464 } 5465 } 5466 5467 return null; 5468 }; 5469 5470 TinyMCE_Engine.prototype.selectElements = function(n, na, f) { 5471 var i, a = [], nl, x; 5472 5473 for (x=0, na = na.split(','); x<na.length; x++) 5474 for (i=0, nl = n.getElementsByTagName(na[x]); i<nl.length; i++) 5475 (!f || f(nl[i])) && a.push(nl[i]); 5476 5477 return a; 5478 }; 5479 5480 TinyMCE_Engine.prototype.selectNodes = function(n, f, a) { 5481 var i; 5482 5483 if (!a) 5484 a = new Array(); 5485 5486 if (f(n)) 5487 a[a.length] = n; 5488 5489 if (n.hasChildNodes()) { 5490 for (i=0; i<n.childNodes.length; i++) 5491 tinyMCE.selectNodes(n.childNodes[i], f, a); 5492 } 5493 5494 return a; 5495 }; 5496 5497 TinyMCE_Engine.prototype.addCSSClass = function(e, c, b) { 5498 var o = this.removeCSSClass(e, c); 5499 return e.className = b ? c + (o != '' ? (' ' + o) : '') : (o != '' ? (o + ' ') : '') + c; 5500 }; 5501 5502 TinyMCE_Engine.prototype.removeCSSClass = function(e, c) { 5503 c = e.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' '); 5504 return e.className = c != ' ' ? c : ''; 5505 }; 5506 5507 TinyMCE_Engine.prototype.hasCSSClass = function(n, c) { 5508 return new RegExp('\\b' + c + '\\b', 'g').test(n.className); 5509 }; 5510 5511 TinyMCE_Engine.prototype.renameElement = function(e, n, d) { 5512 var ne, i, ar; 5513 5514 d = typeof(d) == "undefined" ? tinyMCE.selectedInstance.getDoc() : d; 5515 5516 if (e) { 5517 ne = d.createElement(n); 5518 5519 ar = e.attributes; 5520 for (i=ar.length-1; i>-1; i--) { 5521 if (ar[i].specified && ar[i].nodeValue) 5522 ne.setAttribute(ar[i].nodeName.toLowerCase(), ar[i].nodeValue); 5523 } 5524 5525 ar = e.childNodes; 5526 for (i=0; i<ar.length; i++) 5527 ne.appendChild(ar[i].cloneNode(true)); 5528 5529 e.parentNode.replaceChild(ne, e); 5530 } 5531 }; 5532 5533 TinyMCE_Engine.prototype.getViewPort = function(w) { 5534 var d = w.document, m = d.compatMode == 'CSS1Compat', b = d.body, de = d.documentElement; 5535 5536 return { 5537 left : w.pageXOffset || (m ? de.scrollLeft : b.scrollLeft), 5538 top : w.pageYOffset || (m ? de.scrollTop : b.scrollTop), 5539 width : w.innerWidth || (m ? de.clientWidth : b.clientWidth), 5540 height : w.innerHeight || (m ? de.clientHeight : b.clientHeight) 5541 }; 5542 }; 5543 5544 TinyMCE_Engine.prototype.getStyle = function(n, na, d) { 5545 if (!n) 5546 return false; 5547 5548 // Gecko 5549 if (tinyMCE.isGecko && n.ownerDocument.defaultView) { 5550 try { 5551 return n.ownerDocument.defaultView.getComputedStyle(n, null).getPropertyValue(na); 5552 } catch (n) { 5553 // Old safari might fail 5554 return null; 5555 } 5556 } 5557 5558 // Camelcase it, if needed 5559 na = na.replace(/-(\D)/g, function(a, b){ 5560 return b.toUpperCase(); 5561 }); 5562 5563 // IE & Opera 5564 if (n.currentStyle) 5565 return n.currentStyle[na]; 5566 5567 return false; 5568 }; 5569 5570 /* file:jscripts/tiny_mce/classes/TinyMCE_URL.class.js */ 5571 5572 TinyMCE_Engine.prototype.parseURL = function(url_str) { 5573 var urlParts = new Array(); 5574 5575 if (url_str) { 5576 var pos, lastPos; 5577 5578 // Parse protocol part 5579 pos = url_str.indexOf('://'); 5580 if (pos != -1) { 5581 urlParts['protocol'] = url_str.substring(0, pos); 5582 lastPos = pos + 3; 5583 } 5584 5585 // Find port or path start 5586 for (var i=lastPos; i<url_str.length; i++) { 5587 var chr = url_str.charAt(i); 5588 5589 if (chr == ':') 5590 break; 5591 5592 if (chr == '/') 5593 break; 5594 } 5595 pos = i; 5596 5597 // Get host 5598 urlParts['host'] = url_str.substring(lastPos, pos); 5599 5600 // Get port 5601 urlParts['port'] = ""; 5602 lastPos = pos; 5603 if (url_str.charAt(pos) == ':') { 5604 pos = url_str.indexOf('/', lastPos); 5605 urlParts['port'] = url_str.substring(lastPos+1, pos); 5606 } 5607 5608 // Get path 5609 lastPos = pos; 5610 pos = url_str.indexOf('?', lastPos); 5611 5612 if (pos == -1) 5613 pos = url_str.indexOf('#', lastPos); 5614 5615 if (pos == -1) 5616 pos = url_str.length; 5617 5618 urlParts['path'] = url_str.substring(lastPos, pos); 5619 5620 // Get query 5621 lastPos = pos; 5622 if (url_str.charAt(pos) == '?') { 5623 pos = url_str.indexOf('#'); 5624 pos = (pos == -1) ? url_str.length : pos; 5625 urlParts['query'] = url_str.substring(lastPos+1, pos); 5626 } 5627 5628 // Get anchor 5629 lastPos = pos; 5630 if (url_str.charAt(pos) == '#') { 5631 pos = url_str.length; 5632 urlParts['anchor'] = url_str.substring(lastPos+1, pos); 5633 } 5634 } 5635 5636 return urlParts; 5637 }; 5638 5639 TinyMCE_Engine.prototype.serializeURL = function(up) { 5640 var o = ""; 5641 5642 if (up['protocol']) 5643 o += up['protocol'] + "://"; 5644 5645 if (up['host']) 5646 o += up['host']; 5647 5648 if (up['port']) 5649 o += ":" + up['port']; 5650 5651 if (up['path']) 5652 o += up['path']; 5653 5654 if (up['query']) 5655 o += "?" + up['query']; 5656 5657 if (up['anchor']) 5658 o += "#" + up['anchor']; 5659 5660 return o; 5661 }; 5662 5663 TinyMCE_Engine.prototype.convertAbsoluteURLToRelativeURL = function(base_url, url_to_relative) { 5664 var baseURL = this.parseURL(base_url); 5665 var targetURL = this.parseURL(url_to_relative); 5666 var strTok1; 5667 var strTok2; 5668 var breakPoint = 0; 5669 var outPath = ""; 5670 var forceSlash = false; 5671 5672 if (targetURL.path == "") 5673 targetURL.path = "/"; 5674 else 5675 forceSlash = true; 5676 5677 // Crop away last path part 5678 base_url = baseURL.path.substring(0, baseURL.path.lastIndexOf('/')); 5679 strTok1 = base_url.split('/'); 5680 strTok2 = targetURL.path.split('/'); 5681 5682 if (strTok1.length >= strTok2.length) { 5683 for (var i=0; i<strTok1.length; i++) { 5684 if (i >= strTok2.length || strTok1[i] != strTok2[i]) { 5685 breakPoint = i + 1; 5686 break; 5687 } 5688 } 5689 } 5690 5691 if (strTok1.length < strTok2.length) { 5692 for (var i=0; i<strTok2.length; i++) { 5693 if (i >= strTok1.length || strTok1[i] != strTok2[i]) { 5694 breakPoint = i + 1; 5695 break; 5696 } 5697 } 5698 } 5699 5700 if (breakPoint == 1) 5701 return targetURL.path; 5702 5703 for (var i=0; i<(strTok1.length-(breakPoint-1)); i++) 5704 outPath += "../"; 5705 5706 for (var i=breakPoint-1; i<strTok2.length; i++) { 5707 if (i != (breakPoint-1)) 5708 outPath += "/" + strTok2[i]; 5709 else 5710 outPath += strTok2[i]; 5711 } 5712 5713 targetURL.protocol = null; 5714 targetURL.host = null; 5715 targetURL.port = null; 5716 targetURL.path = outPath == "" && forceSlash ? "/" : outPath; 5717 5718 // Remove document prefix from local anchors 5719 var fileName = baseURL.path; 5720 var pos; 5721 5722 if ((pos = fileName.lastIndexOf('/')) != -1) 5723 fileName = fileName.substring(pos + 1); 5724 5725 // Is local anchor 5726 if (fileName == targetURL.path && targetURL.anchor != "") 5727 targetURL.path = ""; 5728 5729 // If empty and not local anchor force filename or slash 5730 if (targetURL.path == "" && !targetURL.anchor) 5731 targetURL.path = fileName != "" ? fileName : "/"; 5732 5733 return this.serializeURL(targetURL); 5734 }; 5735 5736 TinyMCE_Engine.prototype.convertRelativeToAbsoluteURL = function(base_url, relative_url) { 5737 var baseURL = this.parseURL(base_url), baseURLParts, relURLParts; 5738 var relURL = this.parseURL(relative_url); 5739 5740 if (relative_url == "" || relative_url.indexOf('://') != -1 || /^(mailto:|javascript:|#|\/)/.test(relative_url)) 5741 return relative_url; 5742 5743 // Split parts 5744 baseURLParts = baseURL['path'].split('/'); 5745 relURLParts = relURL['path'].split('/'); 5746 5747 // Remove empty chunks 5748 var newBaseURLParts = new Array(); 5749 for (var i=baseURLParts.length-1; i>=0; i--) { 5750 if (baseURLParts[i].length == 0) 5751 continue; 5752 5753 newBaseURLParts[newBaseURLParts.length] = baseURLParts[i]; 5754 } 5755 baseURLParts = newBaseURLParts.reverse(); 5756 5757 // Merge relURLParts chunks 5758 var newRelURLParts = new Array(); 5759 var numBack = 0; 5760 for (var i=relURLParts.length-1; i>=0; i--) { 5761 if (relURLParts[i].length == 0 || relURLParts[i] == ".") 5762 continue; 5763 5764 if (relURLParts[i] == '..') { 5765 numBack++; 5766 continue; 5767 } 5768 5769 if (numBack > 0) { 5770 numBack--; 5771 continue; 5772 } 5773 5774 newRelURLParts[newRelURLParts.length] = relURLParts[i]; 5775 } 5776 5777 relURLParts = newRelURLParts.reverse(); 5778 5779 // Remove end from absolute path 5780 var len = baseURLParts.length-numBack; 5781 var absPath = (len <= 0 ? "" : "/") + baseURLParts.slice(0, len).join('/') + "/" + relURLParts.join('/'); 5782 var start = "", end = ""; 5783 5784 // Build output URL 5785 relURL.protocol = baseURL.protocol; 5786 relURL.host = baseURL.host; 5787 relURL.port = baseURL.port; 5788 5789 // Re-add trailing slash if it's removed 5790 if (relURL.path.charAt(relURL.path.length-1) == "/") 5791 absPath += "/"; 5792 5793 relURL.path = absPath; 5794 5795 return this.serializeURL(relURL); 5796 }; 5797 5798 TinyMCE_Engine.prototype.convertURL = function(url, node, on_save) { 5799 var prot = document.location.protocol; 5800 var host = document.location.hostname; 5801 var port = document.location.port; 5802 5803 // Pass through file protocol 5804 if (prot == "file:") 5805 return url; 5806 5807 // Something is wrong, remove weirdness 5808 url = tinyMCE.regexpReplace(url, '(http|https):///', '/'); 5809 5810 // Mailto link or anchor (Pass through) 5811 if (url.indexOf('mailto:') != -1 || url.indexOf('javascript:') != -1 || tinyMCE.regexpReplace(url,'[ \t\r\n\+]|%20','').charAt(0) == "#") 5812 return url; 5813 5814 // Fix relative/Mozilla 5815 if (!tinyMCE.isIE && !on_save && url.indexOf("://") == -1 && url.charAt(0) != '/') 5816 return tinyMCE.settings['base_href'] + url; 5817 5818 // Handle relative URLs 5819 if (on_save && tinyMCE.getParam('relative_urls')) { 5820 var curl = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], url); 5821 if (curl.charAt(0) == '/') 5822 curl = tinyMCE.settings['document_base_prefix'] + curl; 5823 5824 var urlParts = tinyMCE.parseURL(curl); 5825 var tmpUrlParts = tinyMCE.parseURL(tinyMCE.settings['document_base_url']); 5826 5827 // Force relative 5828 if (urlParts['host'] == tmpUrlParts['host'] && (urlParts['port'] == tmpUrlParts['port'])) 5829 return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings['document_base_url'], curl); 5830 } 5831 5832 // Handle absolute URLs 5833 if (!tinyMCE.getParam('relative_urls')) { 5834 var urlParts = tinyMCE.parseURL(url); 5835 var baseUrlParts = tinyMCE.parseURL(tinyMCE.settings['base_href']); 5836 5837 // Force absolute URLs from relative URLs 5838 url = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], url); 5839 5840 // If anchor and path is the same page 5841 if (urlParts['anchor'] && urlParts['path'] == baseUrlParts['path']) 5842 return "#" + urlParts['anchor']; 5843 } 5844 5845 // Remove current domain 5846 if (tinyMCE.getParam('remove_script_host')) { 5847 var start = "", portPart = ""; 5848 5849 if (port != "") 5850 portPart = ":" + port; 5851 5852 start = prot + "//" + host + portPart + "/"; 5853 5854 if (url.indexOf(start) == 0) 5855 url = url.substring(start.length-1); 5856 } 5857 5858 return url; 5859 }; 5860 5861 TinyMCE_Engine.prototype.convertAllRelativeURLs = function(body) { 5862 var i, elms, src, href, mhref, msrc; 5863 5864 // Convert all image URL:s to absolute URL 5865 elms = body.getElementsByTagName("img"); 5866 for (i=0; i<elms.length; i++) { 5867 src = tinyMCE.getAttrib(elms[i], 'src'); 5868 5869 msrc = tinyMCE.getAttrib(elms[i], 'mce_src'); 5870 if (msrc != "") 5871 src = msrc; 5872 5873 if (src != "") { 5874 src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src); 5875 elms[i].setAttribute("src", src); 5876 } 5877 } 5878 5879 // Convert all link URL:s to absolute URL 5880 elms = body.getElementsByTagName("a"); 5881 for (i=0; i<elms.length; i++) { 5882 href = tinyMCE.getAttrib(elms[i], 'href'); 5883 5884 mhref = tinyMCE.getAttrib(elms[i], 'mce_href'); 5885 if (mhref != "") 5886 href = mhref; 5887 5888 if (href && href != "") { 5889 href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], href); 5890 elms[i].setAttribute("href", href); 5891 } 5892 } 5893 }; 5894 5895 /* file:jscripts/tiny_mce/classes/TinyMCE_Array.class.js */ 5896 5897 TinyMCE_Engine.prototype.clearArray = function(a) { 5898 var n; 5899 5900 for (n in a) 5901 a[n] = null; 5902 5903 return a; 5904 }; 5905 5906 TinyMCE_Engine.prototype.explode = function(d, s) { 5907 var ar = s.split(d), oar = new Array(), i; 5908 5909 for (i = 0; i<ar.length; i++) { 5910 if (ar[i] != "") 5911 oar[oar.length] = ar[i]; 5912 } 5913 5914 return oar; 5915 }; 5916 5917 /* file:jscripts/tiny_mce/classes/TinyMCE_Event.class.js */ 5918 5919 TinyMCE_Engine.prototype._setEventsEnabled = function(node, state) { 5920 var evs, x, y, elms, i, event; 5921 var events = ['onfocus','onblur','onclick','ondblclick', 5922 'onmousedown','onmouseup','onmouseover','onmousemove', 5923 'onmouseout','onkeypress','onkeydown','onkeydown','onkeyup']; 5924 5925 evs = tinyMCE.settings['event_elements'].split(','); 5926 for (y=0; y<evs.length; y++){ 5927 elms = node.getElementsByTagName(evs[y]); 5928 for (i=0; i<elms.length; i++) { 5929 event = ""; 5930 5931 for (x=0; x<events.length; x++) { 5932 if ((event = tinyMCE.getAttrib(elms[i], events[x])) != '') { 5933 event = tinyMCE.cleanupEventStr("" + event); 5934 5935 if (!state) 5936 event = "return true;" + event; 5937 else 5938 event = event.replace(/^return true;/gi, ''); 5939 5940 elms[i].removeAttribute(events[x]); 5941 elms[i].setAttribute(events[x], event); 5942 } 5943 } 5944 } 5945 } 5946 }; 5947 5948 TinyMCE_Engine.prototype._eventPatch = function(editor_id) { 5949 var n, inst, win, e; 5950 5951 // Remove odd, error 5952 if (typeof(tinyMCE) == "undefined") 5953 return true; 5954 5955 try { 5956 // Try selected instance first 5957 if (tinyMCE.selectedInstance) { 5958 win = tinyMCE.selectedInstance.getWin(); 5959 5960 if (win && win.event) { 5961 e = win.event; 5962 5963 if (!e.target) 5964 e.target = e.srcElement; 5965 5966 TinyMCE_Engine.prototype.handleEvent(e); 5967 return; 5968 } 5969 } 5970 5971 // Search for it 5972 for (n in tinyMCE.instances) { 5973 inst = tinyMCE.instances[n]; 5974 5975 if (!tinyMCE.isInstance(inst)) 5976 continue; 5977 5978 inst.select(); 5979 win = inst.getWin(); 5980 5981 if (win && win.event) { 5982 e = win.event; 5983 5984 if (!e.target) 5985 e.target = e.srcElement; 5986 5987 TinyMCE_Engine.prototype.handleEvent(e); 5988 return; 5989 } 5990 } 5991 } catch (ex) { 5992 // Ignore error if iframe is pointing to external URL 5993 } 5994 }; 5995 5996 TinyMCE_Engine.prototype.findEvent = function(e) { 5997 var n, inst; 5998 5999 if (e) 6000 return e; 6001 6002 for (n in tinyMCE.instances) { 6003 inst = tinyMCE.instances[n]; 6004 6005 if (tinyMCE.isInstance(inst) && inst.getWin().event) 6006 return inst.getWin().event; 6007 } 6008 6009 return null; 6010 }; 6011 6012 TinyMCE_Engine.prototype.unloadHandler = function() { 6013 tinyMCE.triggerSave(true, true); 6014 }; 6015 6016 TinyMCE_Engine.prototype.addEventHandlers = function(inst) { 6017 this.setEventHandlers(inst, 1); 6018 }; 6019 6020 TinyMCE_Engine.prototype.setEventHandlers = function(inst, s) { 6021 var doc = inst.getDoc(), ie, ot, i, f = s ? tinyMCE.addEvent : tinyMCE.removeEvent; 6022 6023 ie = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'controlselect', 'dblclick']; 6024 ot = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'focus', 'blur', 'dragdrop']; 6025 6026 inst.switchSettings(); 6027 6028 if (tinyMCE.isIE) { 6029 for (i=0; i<ie.length; i++) 6030 f(doc, ie[i], TinyMCE_Engine.prototype._eventPatch); 6031 } else { 6032 for (i=0; i<ot.length; i++) 6033 f(doc, ot[i], tinyMCE.handleEvent); 6034 6035 // Force designmode 6036 try { 6037 doc.designMode = "On"; 6038 } catch (e) { 6039 // Ignore 6040 } 6041 } 6042 }; 6043 6044 TinyMCE_Engine.prototype.onMouseMove = function() { 6045 var inst, lh; 6046 6047 // Fix for IE7 bug where it's not restoring hover on anchors correctly 6048 if (tinyMCE.lastHover) { 6049 lh = tinyMCE.lastHover; 6050 6051 // Call out on menus and refresh class on normal buttons 6052 if (lh.className.indexOf('mceMenu') != -1) 6053 tinyMCE._menuButtonEvent('out', lh); 6054 else 6055 lh.className = lh.className; 6056 6057 tinyMCE.lastHover = null; 6058 } 6059 6060 if (!tinyMCE.hasMouseMoved) { 6061 inst = tinyMCE.selectedInstance; 6062 6063 // Workaround for bug #1437457 (Odd MSIE bug) 6064 if (inst.isFocused) { 6065 inst.undoBookmark = inst.selection.getBookmark(); 6066 tinyMCE.hasMouseMoved = true; 6067 } 6068 } 6069 6070 // tinyMCE.cancelEvent(inst.getWin().event); 6071 // return false; 6072 }; 6073 6074 TinyMCE_Engine.prototype.cancelEvent = function(e) { 6075 if (!e) 6076 return false; 6077 6078 if (tinyMCE.isIE) { 6079 e.returnValue = false; 6080 e.cancelBubble = true; 6081 } else { 6082 e.preventDefault(); 6083 e.stopPropagation && e.stopPropagation(); 6084 } 6085 6086 return false; 6087 }; 6088 6089 TinyMCE_Engine.prototype.addEvent = function(o, n, h) { 6090 // Add cleanup for all non unload events 6091 if (n != 'unload') { 6092 function clean() { 6093 var ex; 6094 6095 try { 6096 tinyMCE.removeEvent(o, n, h); 6097 tinyMCE.removeEvent(window, 'unload', clean); 6098 o = n = h = null; 6099 } catch (ex) { 6100 // IE may produce access denied exception on unload 6101 } 6102 } 6103 6104 // Add memory cleaner 6105 tinyMCE.addEvent(window, 'unload', clean); 6106 } 6107 6108 if (o.attachEvent) 6109 o.attachEvent("on" + n, h); 6110 else 6111 o.addEventListener(n, h, false); 6112 }; 6113 6114 TinyMCE_Engine.prototype.removeEvent = function(o, n, h) { 6115 if (o.detachEvent) 6116 o.detachEvent("on" + n, h); 6117 else 6118 o.removeEventListener(n, h, false); 6119 }; 6120 6121 TinyMCE_Engine.prototype.addSelectAccessibility = function(e, s, w) { 6122 // Add event handlers 6123 if (!s._isAccessible) { 6124 s.onkeydown = tinyMCE.accessibleEventHandler; 6125 s.onblur = tinyMCE.accessibleEventHandler; 6126 s._isAccessible = true; 6127 s._win = w; 6128 } 6129 6130 return false; 6131 }; 6132 6133 TinyMCE_Engine.prototype.accessibleEventHandler = function(e) { 6134 var win = this._win; 6135 e = tinyMCE.isIE ? win.event : e; 6136 var elm = tinyMCE.isIE ? e.srcElement : e.target; 6137 6138 // Unpiggyback onchange on blur 6139 if (e.type == "blur") { 6140 if (elm.oldonchange) { 6141 elm.onchange = elm.oldonchange; 6142 elm.oldonchange = null; 6143 } 6144 6145 return true; 6146 } 6147 6148 // Piggyback onchange 6149 if (elm.nodeName == "SELECT" && !elm.oldonchange) { 6150 elm.oldonchange = elm.onchange; 6151 elm.onchange = null; 6152 } 6153 6154 // Execute onchange and remove piggyback 6155 if (e.keyCode == 13 || e.keyCode == 32) { 6156 elm.onchange = elm.oldonchange; 6157 elm.onchange(); 6158 elm.oldonchange = null; 6159 6160 tinyMCE.cancelEvent(e); 6161 return false; 6162 } 6163 6164 return true; 6165 }; 6166 6167 TinyMCE_Engine.prototype._resetIframeHeight = function() { 6168 var ife; 6169 6170 if (tinyMCE.isRealIE) { 6171 ife = tinyMCE.selectedInstance.iframeElement; 6172 6173 /* if (ife._oldWidth) { 6174 ife.style.width = ife._oldWidth; 6175 ife.width = ife._oldWidth; 6176 }*/ 6177 6178 if (ife._oldHeight) { 6179 ife.style.height = ife._oldHeight; 6180 ife.height = ife._oldHeight; 6181 } 6182 } 6183 }; 6184 6185 /* file:jscripts/tiny_mce/classes/TinyMCE_Selection.class.js */ 6186 6187 function TinyMCE_Selection(inst) { 6188 this.instance = inst; 6189 }; 6190 6191 TinyMCE_Selection.prototype = { 6192 getSelectedHTML : function() { 6193 var inst = this.instance; 6194 var e, r = this.getRng(), h; 6195 6196 if (!r) 6197 return null; 6198 6199 e = document.createElement("body"); 6200 6201 if (r.cloneContents) 6202 e.appendChild(r.cloneContents()); 6203 else if (typeof(r.item) != 'undefined' || typeof(r.htmlText) != 'undefined') 6204 e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText; 6205 else 6206 e.innerHTML = r.toString(); // Failed, use text for now 6207 6208 h = tinyMCE._cleanupHTML(inst, inst.contentDocument, inst.settings, e, e, false, true, false); 6209 6210 // When editing always use fonts internaly 6211 //if (tinyMCE.getParam("convert_fonts_to_spans")) 6212 // tinyMCE.convertSpansToFonts(inst.getDoc()); 6213 6214 return h; 6215 }, 6216 6217 getSelectedText : function() { 6218 var inst = this.instance; 6219 var d, r, s, t; 6220 6221 if (tinyMCE.isIE) { 6222 d = inst.getDoc(); 6223 6224 if (d.selection.type == "Text") { 6225 r = d.selection.createRange(); 6226 t = r.text; 6227 } else 6228 t = ''; 6229 } else { 6230 s = this.getSel(); 6231 6232 if (s && s.toString) 6233 t = s.toString(); 6234 else 6235 t = ''; 6236 } 6237 6238 return t; 6239 }, 6240 6241 getBookmark : function(simple) { 6242 var inst = this.instance; 6243 var rng = this.getRng(); 6244 var doc = inst.getDoc(), b = inst.getBody(); 6245 var sp, le, s, e, nl, i, si, ei, w; 6246 var trng, sx, sy, xx = -999999999, vp = inst.getViewPort(); 6247 6248 sx = vp.left; 6249 sy = vp.top; 6250 6251 if (tinyMCE.isSafari || tinyMCE.isOpera || simple) 6252 return {rng : rng, scrollX : sx, scrollY : sy}; 6253 6254 if (tinyMCE.isIE) { 6255 if (rng.item) { 6256 e = rng.item(0); 6257 6258 nl = b.getElementsByTagName(e.nodeName); 6259 for (i=0; i<nl.length; i++) { 6260 if (e == nl[i]) { 6261 sp = i; 6262 break; 6263 } 6264 } 6265 6266 return { 6267 tag : e.nodeName, 6268 index : sp, 6269 scrollX : sx, 6270 scrollY : sy 6271 }; 6272 } else { 6273 trng = doc.body.createTextRange(); 6274 trng.moveToElementText(inst.getBody()); 6275 trng.collapse(true); 6276 bp = Math.abs(trng.move('character', xx)); 6277 6278 trng = rng.duplicate(); 6279 trng.collapse(true); 6280 sp = Math.abs(trng.move('character', xx)); 6281 6282 trng = rng.duplicate(); 6283 trng.collapse(false); 6284 le = Math.abs(trng.move('character', xx)) - sp; 6285 6286 return { 6287 start : sp - bp, 6288 length : le, 6289 scrollX : sx, 6290 scrollY : sy 6291 }; 6292 } 6293 } 6294 6295 if (tinyMCE.isGecko) { 6296 s = this.getSel(); 6297 e = this.getFocusElement(); 6298 6299 if (!s) 6300 return null; 6301 6302 if (e && e.nodeName == 'IMG') { 6303 /*nl = b.getElementsByTagName('IMG'); 6304 for (i=0; i<nl.length; i++) { 6305 if (e == nl[i]) { 6306 sp = i; 6307 break; 6308 } 6309 }*/ 6310 6311 return { 6312 start : -1, 6313 end : -1, 6314 index : sp, 6315 scrollX : sx, 6316 scrollY : sy 6317 }; 6318 } 6319 6320 // Caret or selection 6321 if (s.anchorNode == s.focusNode && s.anchorOffset == s.focusOffset) { 6322 e = this._getPosText(b, s.anchorNode, s.focusNode); 6323 6324 if (!e) 6325 return {scrollX : sx, scrollY : sy}; 6326 6327 return { 6328 start : e.start + s.anchorOffset, 6329 end : e.end + s.focusOffset, 6330 scrollX : sx, 6331 scrollY : sy 6332 }; 6333 } else { 6334 e = this._getPosText(b, rng.startContainer, rng.endContainer); 6335 6336 if (!e) 6337 return {scrollX : sx, scrollY : sy}; 6338 6339 return { 6340 start : e.start + rng.startOffset, 6341 end : e.end + rng.endOffset, 6342 scrollX : sx, 6343 scrollY : sy 6344 }; 6345 } 6346 } 6347 6348 return null; 6349 }, 6350 6351 moveToBookmark : function(bookmark) { 6352 var inst = this.instance; 6353 var rng, nl, i, ex, b = inst.getBody(), sd; 6354 var doc = inst.getDoc(); 6355 var win = inst.getWin(); 6356 var sel = this.getSel(); 6357 6358 if (!bookmark) 6359 return false; 6360 6361 if (tinyMCE.isSafari) { 6362 sel.setBaseAndExtent(bookmark.rng.startContainer, bookmark.rng.startOffset, bookmark.rng.endContainer, bookmark.rng.endOffset); 6363 return true; 6364 } 6365 6366 if (tinyMCE.isRealIE) { 6367 if (bookmark.rng) { 6368 try { 6369 bookmark.rng.select(); 6370 } catch (ex) { 6371 // Ignore 6372 } 6373 6374 return true; 6375 } 6376 6377 win.focus(); 6378 6379 if (bookmark.tag) { 6380 rng = b.createControlRange(); 6381 6382 nl = b.getElementsByTagName(bookmark.tag); 6383 6384 if (nl.length > bookmark.index) { 6385 try { 6386 rng.addElement(nl[bookmark.index]); 6387 } catch (ex) { 6388 // Might be thrown if the node no longer exists 6389 } 6390 } 6391 } else { 6392 // Try/catch needed since this operation breaks when TinyMCE is placed in hidden divs/tabs 6393 try { 6394 // Incorrect bookmark 6395 if (bookmark.start < 0) 6396 return true; 6397 6398 rng = inst.getSel().createRange(); 6399 rng.moveToElementText(inst.getBody()); 6400 rng.collapse(true); 6401 rng.moveStart('character', bookmark.start); 6402 rng.moveEnd('character', bookmark.length); 6403 } catch (ex) { 6404 return true; 6405 } 6406 } 6407 6408 rng.select(); 6409 6410 win.scrollTo(bookmark.scrollX, bookmark.scrollY); 6411 return true; 6412 } 6413 6414 if (tinyMCE.isGecko || tinyMCE.isOpera) { 6415 if (!sel) 6416 return false; 6417 6418 if (bookmark.rng) { 6419 sel.removeAllRanges(); 6420 sel.addRange(bookmark.rng); 6421 } 6422 6423 if (bookmark.start != -1 && bookmark.end != -1) { 6424 try { 6425 sd = this._getTextPos(b, bookmark.start, bookmark.end); 6426 rng = doc.createRange(); 6427 rng.setStart(sd.startNode, sd.startOffset); 6428 rng.setEnd(sd.endNode, sd.endOffset); 6429 sel.removeAllRanges(); 6430 sel.addRange(rng); 6431 win.focus(); 6432 } catch (ex) { 6433 // Ignore 6434 } 6435 } 6436 6437 /* 6438 if (typeof(bookmark.index) != 'undefined') { 6439 tinyMCE.selectElements(b, 'IMG', function (n) { 6440 if (bookmark.index-- == 0) { 6441 // Select image in Gecko here 6442 } 6443 6444 return false; 6445 }); 6446 } 6447 */ 6448 6449 win.scrollTo(bookmark.scrollX, bookmark.scrollY); 6450 return true; 6451 } 6452 6453 return false; 6454 }, 6455 6456 _getPosText : function(r, sn, en) { 6457 var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {}; 6458 6459 while ((n = w.nextNode()) != null) { 6460 if (n == sn) 6461 d.start = p; 6462 6463 if (n == en) { 6464 d.end = p; 6465 return d; 6466 } 6467 6468 p += n.nodeValue ? n.nodeValue.length : 0; 6469 } 6470 6471 return null; 6472 }, 6473 6474 _getTextPos : function(r, sp, ep) { 6475 var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {}; 6476 6477 while ((n = w.nextNode()) != null) { 6478 p += n.nodeValue ? n.nodeValue.length : 0; 6479 6480 if (p >= sp && !d.startNode) { 6481 d.startNode = n; 6482 d.startOffset = sp - (p - n.nodeValue.length); 6483 } 6484 6485 if (p >= ep) { 6486 d.endNode = n; 6487 d.endOffset = ep - (p - n.nodeValue.length); 6488 6489 return d; 6490 } 6491 } 6492 6493 return null; 6494 }, 6495 6496 selectNode : function(node, collapse, select_text_node, to_start) { 6497 var inst = this.instance, sel, rng, nodes; 6498 6499 if (!node) 6500 return; 6501 6502 if (typeof(collapse) == "undefined") 6503 collapse = true; 6504 6505 if (typeof(select_text_node) == "undefined") 6506 select_text_node = false; 6507 6508 if (typeof(to_start) == "undefined") 6509 to_start = true; 6510 6511 if (inst.settings.auto_resize) 6512 inst.resizeToContent(); 6513 6514 if (tinyMCE.isRealIE) { 6515 rng = inst.getDoc().body.createTextRange(); 6516 6517 try { 6518 rng.moveToElementText(node); 6519 6520 if (collapse) 6521 rng.collapse(to_start); 6522 6523 rng.select(); 6524 } catch (e) { 6525 // Throws illigal agrument in MSIE some times 6526 } 6527 } else { 6528 sel = this.getSel(); 6529 6530 if (!sel) 6531 return; 6532 6533 if (tinyMCE.isSafari) { 6534 sel.setBaseAndExtent(node, 0, node, node.innerText.length); 6535 6536 if (collapse) { 6537 if (to_start) 6538 sel.collapseToStart(); 6539 else 6540 sel.collapseToEnd(); 6541 } 6542 6543 this.scrollToNode(node); 6544 6545 return; 6546 } 6547 6548 rng = inst.getDoc().createRange(); 6549 6550 if (select_text_node) { 6551 // Find first textnode in tree 6552 nodes = tinyMCE.getNodeTree(node, new Array(), 3); 6553 if (nodes.length > 0) 6554 rng.selectNodeContents(nodes[0]); 6555 else 6556 rng.selectNodeContents(node); 6557 } else 6558 rng.selectNode(node); 6559 6560 if (collapse) { 6561 // Special treatment of textnode collapse 6562 if (!to_start && node.nodeType == 3) { 6563 rng.setStart(node, node.nodeValue.length); 6564 rng.setEnd(node, node.nodeValue.length); 6565 } else 6566 rng.collapse(to_start); 6567 } 6568 6569 sel.removeAllRanges(); 6570 sel.addRange(rng); 6571 } 6572 6573 this.scrollToNode(node); 6574 6575 // Set selected element 6576 tinyMCE.selectedElement = null; 6577 if (node.nodeType == 1) 6578 tinyMCE.selectedElement = node; 6579 }, 6580 6581 scrollToNode : function(node) { 6582 var inst = this.instance, w = inst.getWin(), vp = inst.getViewPort(), pos = tinyMCE.getAbsPosition(node), cvp, p, cwin; 6583 6584 // Only scroll if out of visible area 6585 if (pos.absLeft < vp.left || pos.absLeft > vp.left + vp.width || pos.absTop < vp.top || pos.absTop > vp.top + (vp.height-25)) 6586 w.scrollTo(pos.absLeft, pos.absTop - vp.height + 25); 6587 6588 // Scroll container window 6589 if (inst.settings.auto_resize) { 6590 cwin = inst.getContainerWin(); 6591 cvp = tinyMCE.getViewPort(cwin); 6592 p = this.getAbsPosition(node); 6593 6594 if (p.absLeft < cvp.left || p.absLeft > cvp.left + cvp.width || p.absTop < cvp.top || p.absTop > cvp.top + cvp.height) 6595 cwin.scrollTo(p.absLeft, p.absTop - cvp.height + 25); 6596 } 6597 }, 6598 6599 getAbsPosition : function(n) { 6600 var pos = tinyMCE.getAbsPosition(n), ipos = tinyMCE.getAbsPosition(this.instance.iframeElement); 6601 6602 return { 6603 absLeft : ipos.absLeft + pos.absLeft, 6604 absTop : ipos.absTop + pos.absTop 6605 }; 6606 }, 6607 6608 getSel : function() { 6609 var inst = this.instance; 6610 6611 if (tinyMCE.isRealIE) 6612 return inst.getDoc().selection; 6613 6614 return inst.contentWindow.getSelection(); 6615 }, 6616 6617 getRng : function() { 6618 var s = this.getSel(); 6619 6620 if (s == null) 6621 return null; 6622 6623 if (tinyMCE.isRealIE) 6624 return s.createRange(); 6625 6626 if (tinyMCE.isSafari && !s.getRangeAt) 6627 return '' + window.getSelection(); 6628 6629 if (s.rangeCount > 0) 6630 return s.getRangeAt(0); 6631 6632 return null; 6633 }, 6634 6635 isCollapsed : function() { 6636 var r = this.getRng(); 6637 6638 if (r.item) 6639 return false; 6640 6641 return r.boundingWidth == 0 || this.getSel().isCollapsed; 6642 }, 6643 6644 collapse : function(b) { 6645 var r = this.getRng(), s = this.getSel(); 6646 6647 if (r.select) { 6648 r.collapse(b); 6649 r.select(); 6650 } else { 6651 if (b) 6652 s.collapseToStart(); 6653 else 6654 s.collapseToEnd(); 6655 } 6656 }, 6657 6658 getFocusElement : function() { 6659 var inst = this.instance, doc, rng, sel, elm; 6660 6661 if (tinyMCE.isRealIE) { 6662 doc = inst.getDoc(); 6663 rng = doc.selection.createRange(); 6664 6665 // if (rng.collapse) 6666 // rng.collapse(true); 6667 6668 elm = rng.item ? rng.item(0) : rng.parentElement(); 6669 } else { 6670 if (!tinyMCE.isSafari && inst.isHidden()) 6671 return inst.getBody(); 6672 6673 sel = this.getSel(); 6674 rng = this.getRng(); 6675 6676 if (!sel || !rng) 6677 return null; 6678 6679 elm = rng.commonAncestorContainer; 6680 //elm = (sel && sel.anchorNode) ? sel.anchorNode : null; 6681 6682 // Handle selection a image or other control like element such as anchors 6683 if (!rng.collapsed) { 6684 // Is selection small 6685 if (rng.startContainer == rng.endContainer) { 6686 if (rng.startOffset - rng.endOffset < 2) { 6687 if (rng.startContainer.hasChildNodes()) 6688 elm = rng.startContainer.childNodes[rng.startOffset]; 6689 } 6690 } 6691 } 6692 6693 // Get the element parent of the node 6694 elm = tinyMCE.getParentElement(elm); 6695 6696 //if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") 6697 // elm = tinyMCE.selectedElement; 6698 } 6699 6700 return elm; 6701 } 6702 6703 }; 6704 6705 /* file:jscripts/tiny_mce/classes/TinyMCE_UndoRedo.class.js */ 6706 6707 function TinyMCE_UndoRedo(inst) { 6708 this.instance = inst; 6709 this.undoLevels = new Array(); 6710 this.undoIndex = 0; 6711 this.typingUndoIndex = -1; 6712 this.undoRedo = true; 6713 }; 6714 6715 TinyMCE_UndoRedo.prototype = { 6716 add : function(l) { 6717 var b, customUndoLevels, newHTML, inst = this.instance, i, ul, ur; 6718 6719 if (l) { 6720 this.undoLevels[this.undoLevels.length] = l; 6721 return true; 6722 } 6723 6724 if (this.typingUndoIndex != -1) { 6725 this.undoIndex = this.typingUndoIndex; 6726 6727 if (tinyMCE.typingUndoIndex != -1) 6728 tinyMCE.undoIndex = tinyMCE.typingUndoIndex; 6729 } 6730 6731 newHTML = tinyMCE.trim(inst.getBody().innerHTML); 6732 if (this.undoLevels[this.undoIndex] && newHTML != this.undoLevels[this.undoIndex].content) { 6733 //tinyMCE.debug(newHTML, this.undoLevels[this.undoIndex].content); 6734 6735 tinyMCE.dispatchCallback(inst, 'onchange_callback', 'onChange', inst); 6736 6737 // Time to compress 6738 customUndoLevels = tinyMCE.settings['custom_undo_redo_levels']; 6739 if (customUndoLevels != -1 && this.undoLevels.length > customUndoLevels) { 6740 for (i=0; i<this.undoLevels.length-1; i++) 6741 this.undoLevels[i] = this.undoLevels[i+1]; 6742 6743 this.undoLevels.length--; 6744 this.undoIndex--; 6745 6746 // Todo: Implement global undo/redo logic here 6747 } 6748 6749 b = inst.undoBookmark; 6750 6751 if (!b) 6752 b = inst.selection.getBookmark(); 6753 6754 this.undoIndex++; 6755 this.undoLevels[this.undoIndex] = { 6756 content : newHTML, 6757 bookmark : b 6758 }; 6759 6760 // Remove all above from global undo/redo 6761 ul = tinyMCE.undoLevels; 6762 for (i=tinyMCE.undoIndex + 1; i<ul.length; i++) { 6763 ur = ul[i].undoRedo; 6764 6765 if (ur.undoIndex == ur.undoLevels.length -1) 6766 ur.undoIndex--; 6767 6768 ur.undoLevels.length--; 6769 } 6770 6771 // Add global undo level 6772 tinyMCE.undoLevels[tinyMCE.undoIndex++] = inst; 6773 tinyMCE.undoLevels.length = tinyMCE.undoIndex; 6774 6775 this.undoLevels.length = this.undoIndex + 1; 6776 6777 return true; 6778 } 6779 6780 return false; 6781 }, 6782 6783 undo : function() { 6784 var inst = this.instance; 6785 6786 // Do undo 6787 if (this.undoIndex > 0) { 6788 this.undoIndex--; 6789 6790 tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content); 6791 inst.repaint(); 6792 6793 if (inst.settings.custom_undo_redo_restore_selection) 6794 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark); 6795 } 6796 }, 6797 6798 redo : function() { 6799 var inst = this.instance; 6800 6801 tinyMCE.execCommand("mceEndTyping"); 6802 6803 if (this.undoIndex < (this.undoLevels.length-1)) { 6804 this.undoIndex++; 6805 6806 tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content); 6807 inst.repaint(); 6808 6809 if (inst.settings.custom_undo_redo_restore_selection) 6810 inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark); 6811 } 6812 6813 tinyMCE.triggerNodeChange(); 6814 } 6815 6816 }; 6817 6818 /* file:jscripts/tiny_mce/classes/TinyMCE_ForceParagraphs.class.js */ 6819 6820 var TinyMCE_ForceParagraphs = { 6821 _insertPara : function(inst, e) { 6822 var doc = inst.getDoc(), sel = inst.getSel(), body = inst.getBody(), win = inst.contentWindow, rng = sel.getRangeAt(0); 6823 var rootElm = doc.documentElement, blockName = "P", startNode, endNode, startBlock, endBlock; 6824 var rngBefore, rngAfter, direct, startNode, startOffset, endNode, endOffset, b = tinyMCE.isOpera ? inst.selection.getBookmark() : null; 6825 var paraBefore, paraAfter, startChop, endChop, contents; 6826 6827 function isEmpty(para) { 6828 function isEmptyHTML(html) { 6829 return html.replace(new RegExp('[ \t\r\n]+', 'g'), '').toLowerCase() == ""; 6830 } 6831 6832 // Check for images 6833 if (para.getElementsByTagName("img").length > 0) 6834 return false; 6835 6836 // Check for tables 6837 if (para.getElementsByTagName("table").length > 0) 6838 return false; 6839 6840 // Check for HRs 6841 if (para.getElementsByTagName("hr").length > 0) 6842 return false; 6843 6844 // Check all textnodes 6845 var nodes = tinyMCE.getNodeTree(para, new Array(), 3); 6846 for (var i=0; i<nodes.length; i++) { 6847 if (!isEmptyHTML(nodes[i].nodeValue)) 6848 return false; 6849 } 6850 6851 // No images, no tables, no hrs, no text content then it's empty 6852 return true; 6853 } 6854 6855 // tinyMCE.debug(body.innerHTML); 6856 6857 // debug(e.target, sel.anchorNode.nodeName, sel.focusNode.nodeName, rng.startContainer, rng.endContainer, rng.commonAncestorContainer, sel.anchorOffset, sel.focusOffset, rng.toString()); 6858 6859 // Setup before range 6860 rngBefore = doc.createRange(); 6861 rngBefore.setStart(sel.anchorNode, sel.anchorOffset); 6862 rngBefore.collapse(true); 6863 6864 // Setup after range 6865 rngAfter = doc.createRange(); 6866 rngAfter.setStart(sel.focusNode, sel.focusOffset); 6867 rngAfter.collapse(true); 6868 6869 // Setup start/end points 6870 direct = rngBefore.compareBoundaryPoints(rngBefore.START_TO_END, rngAfter) < 0; 6871 startNode = direct ? sel.anchorNode : sel.focusNode; 6872 startOffset = direct ? sel.anchorOffset : sel.focusOffset; 6873 endNode = direct ? sel.focusNode : sel.anchorNode; 6874 endOffset = direct ? sel.focusOffset : sel.anchorOffset; 6875 6876 startNode = startNode.nodeName == "BODY" ? startNode.firstChild : startNode; 6877 endNode = endNode.nodeName == "BODY" ? endNode.firstChild : endNode; 6878 6879 // Get block elements 6880 startBlock = inst.getParentBlockElement(startNode); 6881 endBlock = inst.getParentBlockElement(endNode); 6882 6883 // If absolute force paragraph generation within 6884 if (startBlock && new RegExp('absolute|relative|static', 'gi').test(startBlock.style.position)) 6885 startBlock = null; 6886 6887 if (endBlock && new RegExp('absolute|relative|static', 'gi').test(endBlock.style.position)) 6888 endBlock = null; 6889 6890 // Use current block name 6891 if (startBlock != null) { 6892 blockName = startBlock.nodeName; 6893 6894 // Use P instead 6895 if (blockName == "TD" || blockName == "TABLE" || (blockName == "DIV" && new RegExp('left|right', 'gi').test(startBlock.style.cssFloat))) 6896 blockName = "P"; 6897 } 6898 6899 // Within a list use normal behaviour 6900 if (tinyMCE.getParentElement(startBlock, "OL,UL", null, body) != null) 6901 return false; 6902 6903 // Within a table create new paragraphs 6904 if ((startBlock != null && startBlock.nodeName == "TABLE") || (endBlock != null && endBlock.nodeName == "TABLE")) 6905 startBlock = endBlock = null; 6906 6907 // Setup new paragraphs 6908 paraBefore = (startBlock != null && startBlock.nodeName == blockName) ? startBlock.cloneNode(false) : doc.createElement(blockName); 6909 paraAfter = (endBlock != null && endBlock.nodeName == blockName) ? endBlock.cloneNode(false) : doc.createElement(blockName); 6910 6911 // Is header, then force paragraph under 6912 if (/^(H[1-6])$/.test(blockName)) 6913 paraAfter = doc.createElement("p"); 6914 6915 // Setup chop nodes 6916 startChop = startNode; 6917 endChop = endNode; 6918 6919 // Get startChop node 6920 node = startChop; 6921 do { 6922 if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node)) 6923 break; 6924 6925 startChop = node; 6926 } while ((node = node.previousSibling ? node.previousSibling : node.parentNode)); 6927 6928 // Get endChop node 6929 node = endChop; 6930 do { 6931 if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node)) 6932 break; 6933 6934 endChop = node; 6935 } while ((node = node.nextSibling ? node.nextSibling : node.parentNode)); 6936 6937 // Fix when only a image is within the TD 6938 if (startChop.nodeName == "TD") 6939 startChop = startChop.firstChild; 6940 6941 if (endChop.nodeName == "TD") 6942 endChop = endChop.lastChild; 6943 6944 // If not in a block element 6945 if (startBlock == null) { 6946 // Delete selection 6947 rng.deleteContents(); 6948 6949 if (!tinyMCE.isSafari) 6950 sel.removeAllRanges(); 6951 6952 if (startChop != rootElm && endChop != rootElm) { 6953 // Insert paragraph before 6954 rngBefore = rng.cloneRange(); 6955 6956 if (startChop == body) 6957 rngBefore.setStart(startChop, 0); 6958 else 6959 rngBefore.setStartBefore(startChop); 6960 6961 paraBefore.appendChild(rngBefore.cloneContents()); 6962 6963 // Insert paragraph after 6964 if (endChop.parentNode.nodeName == blockName) 6965 endChop = endChop.parentNode; 6966 6967 // If not after image 6968 //if (rng.startContainer.nodeName != "BODY" && rng.endContainer.nodeName != "BODY") 6969 rng.setEndAfter(endChop); 6970 6971 if (endChop.nodeName != "#text" && endChop.nodeName != "BODY") 6972 rngBefore.setEndAfter(endChop); 6973 6974 contents = rng.cloneContents(); 6975 if (contents.firstChild && (contents.firstChild.nodeName == blockName || contents.firstChild.nodeName == "BODY")) 6976 paraAfter.innerHTML = contents.firstChild.innerHTML; 6977 else 6978 paraAfter.appendChild(contents); 6979 6980 // Check if it's a empty paragraph 6981 if (isEmpty(paraBefore)) 6982 paraBefore.innerHTML = " "; 6983 6984 // Check if it's a empty paragraph 6985 if (isEmpty(paraAfter)) 6986 paraAfter.innerHTML = " "; 6987 6988 // Delete old contents 6989 rng.deleteContents(); 6990 rngAfter.deleteContents(); 6991 rngBefore.deleteContents(); 6992 6993 // Insert new paragraphs 6994 if (tinyMCE.isOpera) { 6995 paraBefore.normalize(); 6996 rngBefore.insertNode(paraBefore); 6997 paraAfter.normalize(); 6998 rngBefore.insertNode(paraAfter); 6999 } else { 7000 paraAfter.normalize(); 7001 rngBefore.insertNode(paraAfter); 7002 paraBefore.normalize(); 7003 rngBefore.insertNode(paraBefore); 7004 } 7005 7006 //tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML); 7007 } else { 7008 body.innerHTML = "<" + blockName + "> </" + blockName + "><" + blockName + "> </" + blockName + ">"; 7009 paraAfter = body.childNodes[1]; 7010 } 7011 7012 inst.selection.moveToBookmark(b); 7013 inst.selection.selectNode(paraAfter, true, true); 7014 7015 return true; 7016 } 7017 7018 // Place first part within new paragraph 7019 if (startChop.nodeName == blockName) 7020 rngBefore.setStart(startChop, 0); 7021 else 7022 rngBefore.setStartBefore(startChop); 7023 7024 rngBefore.setEnd(startNode, startOffset); 7025 paraBefore.appendChild(rngBefore.cloneContents()); 7026 7027 // Place secound part within new paragraph 7028 rngAfter.setEndAfter(endChop); 7029 rngAfter.setStart(endNode, endOffset); 7030 contents = rngAfter.cloneContents(); 7031 7032 if (contents.firstChild && contents.firstChild.nodeName == blockName) { 7033 /* var nodes = contents.firstChild.childNodes; 7034 for (var i=0; i<nodes.length; i++) { 7035 //tinyMCE.debug(nodes[i].nodeName); 7036 if (nodes[i].nodeName != "BODY") 7037 paraAfter.appendChild(nodes[i]); 7038 } 7039 */ 7040 paraAfter.innerHTML = contents.firstChild.innerHTML; 7041 } else 7042 paraAfter.appendChild(contents); 7043 7044 // Check if it's a empty paragraph 7045 if (isEmpty(paraBefore)) 7046 paraBefore.innerHTML = " "; 7047 7048 // Check if it's a empty paragraph 7049 if (isEmpty(paraAfter)) 7050 paraAfter.innerHTML = " "; 7051 7052 // Create a range around everything 7053 rng = doc.createRange(); 7054 7055 if (!startChop.previousSibling && startChop.parentNode.nodeName.toUpperCase() == blockName) { 7056 rng.setStartBefore(startChop.parentNode); 7057 } else { 7058 if (rngBefore.startContainer.nodeName.toUpperCase() == blockName && rngBefore.startOffset == 0) 7059 rng.setStartBefore(rngBefore.startContainer); 7060 else 7061 rng.setStart(rngBefore.startContainer, rngBefore.startOffset); 7062 } 7063 7064 if (!endChop.nextSibling && endChop.parentNode.nodeName.toUpperCase() == blockName) 7065 rng.setEndAfter(endChop.parentNode); 7066 else 7067 rng.setEnd(rngAfter.endContainer, rngAfter.endOffset); 7068 7069 // Delete all contents and insert new paragraphs 7070 rng.deleteContents(); 7071 7072 if (tinyMCE.isOpera) { 7073 rng.insertNode(paraBefore); 7074 rng.insertNode(paraAfter); 7075 } else { 7076 rng.insertNode(paraAfter); 7077 rng.insertNode(paraBefore); 7078 } 7079 7080 //tinyMCE.debug("2", paraBefore.innerHTML, paraAfter.innerHTML); 7081 7082 // Normalize 7083 paraAfter.normalize(); 7084 paraBefore.normalize(); 7085 7086 inst.selection.moveToBookmark(b); 7087 inst.selection.selectNode(paraAfter, true, true); 7088 7089 return true; 7090 }, 7091 7092 _handleBackSpace : function(inst) { 7093 var r = inst.getRng(), sn = r.startContainer, nv, s = false; 7094 7095 // Added body check for bug #1527787 7096 if (sn && sn.nextSibling && sn.nextSibling.nodeName == "BR" && sn.parentNode.nodeName != "BODY") { 7097 nv = sn.nodeValue; 7098 7099 // Handle if a backspace is pressed after a space character #bug 1466054 removed since fix for #1527787 7100 /*if (nv != null && nv.length >= r.startOffset && nv.charAt(r.startOffset - 1) == ' ') 7101 s = true;*/ 7102 7103 // Only remove BRs if we are at the end of line #bug 1464152 7104 if (nv != null && r.startOffset == nv.length) 7105 sn.nextSibling.parentNode.removeChild(sn.nextSibling); 7106 } 7107 7108 if (inst.settings.auto_resize) 7109 inst.resizeToContent(); 7110 7111 return s; 7112 } 7113 7114 }; 7115 7116 /* file:jscripts/tiny_mce/classes/TinyMCE_Layer.class.js */ 7117 7118 function TinyMCE_Layer(id, bm) { 7119 this.id = id; 7120 this.blockerElement = null; 7121 this.events = false; 7122 this.element = null; 7123 this.blockMode = typeof(bm) != 'undefined' ? bm : true; 7124 this.doc = document; 7125 }; 7126 7127 TinyMCE_Layer.prototype = { 7128 moveRelativeTo : function(re, p) { 7129 var rep = this.getAbsPosition(re); 7130 var w = parseInt(re.offsetWidth); 7131 var h = parseInt(re.offsetHeight); 7132 var e = this.getElement(); 7133 var ew = parseInt(e.offsetWidth); 7134 var eh = parseInt(e.offsetHeight); 7135 var x, y; 7136 7137 switch (p) { 7138 case "tl": 7139 x = rep.absLeft; 7140 y = rep.absTop; 7141 break; 7142 7143 case "tr": 7144 x = rep.absLeft + w; 7145 y = rep.absTop; 7146 break; 7147 7148 case "bl": 7149 x = rep.absLeft; 7150 y = rep.absTop + h; 7151 break; 7152 7153 case "br": 7154 x = rep.absLeft + w; 7155 y = rep.absTop + h; 7156 break; 7157 7158 case "cc": 7159 x = rep.absLeft + (w / 2) - (ew / 2); 7160 y = rep.absTop + (h / 2) - (eh / 2); 7161 break; 7162 } 7163 7164 this.moveTo(x, y); 7165 }, 7166 7167 moveBy : function(x, y) { 7168 var e = this.getElement(); 7169 this.moveTo(parseInt(e.style.left) + x, parseInt(e.style.top) + y); 7170 }, 7171 7172 moveTo : function(x, y) { 7173 var e = this.getElement(); 7174 7175 e.style.left = x + "px"; 7176 e.style.top = y + "px"; 7177 7178 this.updateBlocker(); 7179 }, 7180 7181 resizeBy : function(w, h) { 7182 var e = this.getElement(); 7183 this.resizeTo(parseInt(e.style.width) + w, parseInt(e.style.height) + h); 7184 }, 7185 7186 resizeTo : function(w, h) { 7187 var e = this.getElement(); 7188 7189 if (w != null) 7190 e.style.width = w + "px"; 7191 7192 if (h != null) 7193 e.style.height = h + "px"; 7194 7195 this.updateBlocker(); 7196 }, 7197 7198 show : function() { 7199 var el = this.getElement(); 7200 7201 if (el) { 7202 el.style.display = 'block'; 7203 this.updateBlocker(); 7204 } 7205 }, 7206 7207 hide : function() { 7208 var el = this.getElement(); 7209 7210 if (el) { 7211 el.style.display = 'none'; 7212 this.updateBlocker(); 7213 } 7214 }, 7215 7216 isVisible : function() { 7217 return this.getElement().style.display == 'block'; 7218 }, 7219 7220 getElement : function() { 7221 if (!this.element) 7222 this.element = this.doc.getElementById(this.id); 7223 7224 return this.element; 7225 }, 7226 7227 setBlockMode : function(s) { 7228 this.blockMode = s; 7229 }, 7230 7231 updateBlocker : function() { 7232 var e, b, x, y, w, h; 7233 7234 b = this.getBlocker(); 7235 if (b) { 7236 if (this.blockMode) { 7237 e = this.getElement(); 7238 x = this.parseInt(e.style.left); 7239 y = this.parseInt(e.style.top); 7240 w = this.parseInt(e.offsetWidth); 7241 h = this.parseInt(e.offsetHeight); 7242 7243 b.style.left = x + 'px'; 7244 b.style.top = y + 'px'; 7245 b.style.width = w + 'px'; 7246 b.style.height = h + 'px'; 7247 b.style.display = e.style.display; 7248 } else 7249 b.style.display = 'none'; 7250 } 7251 }, 7252 7253 getBlocker : function() { 7254 var d, b; 7255 7256 if (!this.blockerElement && this.blockMode) { 7257 d = this.doc; 7258 b = d.getElementById(this.id + "_blocker"); 7259 7260 if (!b) { 7261 b = d.createElement("iframe"); 7262 7263 b.setAttribute('id', this.id + "_blocker"); 7264 b.style.cssText = 'display: none; position: absolute; left: 0; top: 0'; 7265 b.src = 'javascript:false;'; 7266 b.frameBorder = '0'; 7267 b.scrolling = 'no'; 7268 7269 d.body.appendChild(b); 7270 } 7271 7272 this.blockerElement = b; 7273 } 7274 7275 return this.blockerElement; 7276 }, 7277 7278 getAbsPosition : function(n) { 7279 var p = {absLeft : 0, absTop : 0}; 7280 7281 while (n) { 7282 p.absLeft += n.offsetLeft; 7283 p.absTop += n.offsetTop; 7284 n = n.offsetParent; 7285 } 7286 7287 return p; 7288 }, 7289 7290 create : function(n, c, p, h) { 7291 var d = this.doc, e = d.createElement(n); 7292 7293 e.setAttribute('id', this.id); 7294 7295 if (c) 7296 e.className = c; 7297 7298 if (!p) 7299 p = d.body; 7300 7301 if (h) 7302 e.innerHTML = h; 7303 7304 p.appendChild(e); 7305 7306 return this.element = e; 7307 }, 7308 7309 exists : function() { 7310 return this.doc.getElementById(this.id) != null; 7311 }, 7312 7313 parseInt : function(s) { 7314 if (s == null || s == '') 7315 return 0; 7316 7317 return parseInt(s); 7318 }, 7319 7320 remove : function() { 7321 var e = this.getElement(), b = this.getBlocker(); 7322 7323 if (e) 7324 e.parentNode.removeChild(e); 7325 7326 if (b) 7327 b.parentNode.removeChild(b); 7328 } 7329 7330 }; 7331 7332 /* file:jscripts/tiny_mce/classes/TinyMCE_Menu.class.js */ 7333 7334 function TinyMCE_Menu() { 7335 var id; 7336 7337 if (typeof(tinyMCE.menuCounter) == "undefined") 7338 tinyMCE.menuCounter = 0; 7339 7340 id = "mc_menu_" + tinyMCE.menuCounter++; 7341 7342 TinyMCE_Layer.call(this, id, true); 7343 7344 this.id = id; 7345 this.items = new Array(); 7346 this.needsUpdate = true; 7347 }; 7348 7349 TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, { 7350 init : function(s) { 7351 var n; 7352 7353 // Default params 7354 this.settings = { 7355 separator_class : 'mceMenuSeparator', 7356 title_class : 'mceMenuTitle', 7357 disabled_class : 'mceMenuDisabled', 7358 menu_class : 'mceMenu', 7359 drop_menu : true 7360 }; 7361 7362 for (n in s) 7363 this.settings[n] = s[n]; 7364 7365 this.create('div', this.settings.menu_class); 7366 }, 7367 7368 clear : function() { 7369 this.items = new Array(); 7370 }, 7371 7372 addTitle : function(t) { 7373 this.add({type : 'title', text : t}); 7374 }, 7375 7376 addDisabled : function(t) { 7377 this.add({type : 'disabled', text : t}); 7378 }, 7379 7380 addSeparator : function() { 7381 this.add({type : 'separator'}); 7382 }, 7383 7384 addItem : function(t, js) { 7385 this.add({text : t, js : js}); 7386 }, 7387 7388 add : function(mi) { 7389 this.items[this.items.length] = mi; 7390 this.needsUpdate = true; 7391 }, 7392 7393 update : function() { 7394 var e = this.getElement(), h = '', i, t, m = this.items, s = this.settings; 7395 7396 if (this.settings.drop_menu) 7397 h += '<span class="mceMenuLine"></span>'; 7398 7399 h += '<table border="0" cellpadding="0" cellspacing="0">'; 7400 7401 for (i=0; i<m.length; i++) { 7402 t = tinyMCE.xmlEncode(m[i].text); 7403 c = m[i].class_name ? ' class="' + m[i].class_name + '"' : ''; 7404 7405 switch (m[i].type) { 7406 case 'separator': 7407 h += '<tr class="' + s.separator_class + '"><td>'; 7408 break; 7409 7410 case 'title': 7411 h += '<tr class="' + s.title_class + '"><td><span' + c +'>' + t + '</span>'; 7412 break; 7413 7414 case 'disabled': 7415 h += '<tr class="' + s.disabled_class + '"><td><span' + c +'>' + t + '</span>'; 7416 break; 7417 7418 default: 7419 h += '<tr><td><a href="' + tinyMCE.xmlEncode(m[i].js) + '" onmousedown="' + tinyMCE.xmlEncode(m[i].js) + ';return tinyMCE.cancelEvent(event);" onclick="return tinyMCE.cancelEvent(event);" onmouseup="return tinyMCE.cancelEvent(event);"><span' + c +'>' + t + '</span></a>'; 7420 } 7421 7422 h += '</td></tr>'; 7423 } 7424 7425 h += '</table>'; 7426 7427 e.innerHTML = h; 7428 7429 this.needsUpdate = false; 7430 this.updateBlocker(); 7431 }, 7432 7433 show : function() { 7434 var nl, i; 7435 7436 if (tinyMCE.lastMenu == this) 7437 return; 7438 7439 if (this.needsUpdate) 7440 this.update(); 7441 7442 if (tinyMCE.lastMenu && tinyMCE.lastMenu != this) 7443 tinyMCE.lastMenu.hide(); 7444 7445 TinyMCE_Layer.prototype.show.call(this); 7446 7447 if (!tinyMCE.isOpera) { 7448 // Accessibility stuff 7449 /* nl = this.getElement().getElementsByTagName("a"); 7450 if (nl.length > 0) 7451 nl[0].focus();*/ 7452 } 7453 7454 tinyMCE.lastMenu = this; 7455 } 7456 7457 }); 7458 7459 /* file:jscripts/tiny_mce/classes/TinyMCE_Compatibility.class.js */ 7460 7461 if (!Function.prototype.call) { 7462 Function.prototype.call = function() { 7463 var a = arguments, s = a[0], i, as = '', r, o; 7464 7465 for (i=1; i<a.length; i++) 7466 as += (i > 1 ? ',' : '') + 'a[' + i + ']'; 7467 7468 o = s._fu; 7469 s._fu = this; 7470 r = eval('s._fu(' + as + ')'); 7471 s._fu = o; 7472 7473 return r; 7474 }; 7475 }; 7476 7477 /* file:jscripts/tiny_mce/classes/TinyMCE_Debug.class.js */ 7478 7479 TinyMCE_Engine.prototype.debug = function() { 7480 var m = "", a, i, l = tinyMCE.log.length; 7481 7482 for (i=0, a = this.debug.arguments; i<a.length; i++) { 7483 m += a[i]; 7484 7485 if (i<a.length-1) 7486 m += ', '; 7487 } 7488 7489 if (l < 1000) 7490 tinyMCE.log[l] = "[debug] " + m; 7491 }; 7492
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |