-/**
- * $RCSfile: tiny_mce_src.js,v $
- * $Revision: 1.281 $
- * $Date: 2005/12/02 08:12:07 $
- *
- * @author Moxiecode
- * @copyright Copyright © 2004, Moxiecode Systems AB, All rights reserved.
- */
-
-function TinyMCE() {
+
+/* file:jscripts/tiny_mce/classes/TinyMCE_Engine.class.js */
+
+function TinyMCE_Engine() {
+ var ua;
+
this.majorVersion = "2";
- this.minorVersion = "0";
- this.releaseDate = "2005-12-01";
-
- this.instances = new Array();
- this.stickyClassesLookup = new Array();
- this.windowArgs = new Array();
- this.loadedFiles = new Array();
- this.configs = new Array();
+ this.minorVersion = "1.1.1";
+ this.releaseDate = "2007-05-14";
+
+ this.instances = [];
+ this.switchClassCache = [];
+ this.windowArgs = [];
+ this.loadedFiles = [];
+ this.pendingFiles = [];
+ this.loadingIndex = 0;
+ this.configs = [];
this.currentConfig = 0;
- this.eventHandlers = new Array();
+ this.eventHandlers = [];
+ this.log = [];
+ this.undoLevels = [];
+ this.undoIndex = 0;
+ this.typingUndoIndex = -1;
+ this.settings = [];
// Browser check
- var ua = navigator.userAgent;
+ ua = navigator.userAgent;
this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
this.isMSIE5 = this.isMSIE && (ua.indexOf('MSIE 5') != -1);
this.isMSIE5_0 = this.isMSIE && (ua.indexOf('MSIE 5.0') != -1);
- this.isGecko = ua.indexOf('Gecko') != -1;
+ this.isMSIE7 = this.isMSIE && (ua.indexOf('MSIE 7') != -1);
+ this.isGecko = ua.indexOf('Gecko') != -1; // Will also be true on Safari
this.isSafari = ua.indexOf('Safari') != -1;
- this.isOpera = ua.indexOf('Opera') != -1;
+ this.isOpera = window['opera'] && opera.buildNumber ? true : false;
this.isMac = ua.indexOf('Mac') != -1;
this.isNS7 = ua.indexOf('Netscape/7') != -1;
this.isNS71 = ua.indexOf('Netscape/7.1') != -1;
this.dialogCounter = 0;
+ this.plugins = [];
+ this.themes = [];
+ this.menus = [];
+ this.loadedPlugins = [];
+ this.buttonMap = [];
+ this.isLoaded = false;
// Fake MSIE on Opera and if Opera fakes IE, Gecko or Safari cancel those
if (this.isOpera) {
this.isSafari = false;
}
+ this.isIE = this.isMSIE;
+ this.isRealIE = this.isMSIE && !this.isOpera;
+
// TinyMCE editor id instance counter
this.idCounter = 0;
};
-TinyMCE.prototype.defParam = function(key, def_val) {
- this.settings[key] = tinyMCE.getParam(key, def_val);
-};
+TinyMCE_Engine.prototype = {
+ init : function(settings) {
+ var theme, nl, baseHREF = "", i, cssPath, entities, h, p, src, elements = [], head;
+
+ // 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.
+ if (this.isMSIE5_0)
+ return;
+
+ this.settings = settings;
+
+ // Check if valid browser has execcommand support
+ if (typeof(document.execCommand) == 'undefined')
+ return;
-TinyMCE.prototype.init = function(settings) {
- var theme;
+ // Get script base path
+ if (!tinyMCE.baseURL) {
+ // Search through head
+ head = document.getElementsByTagName('head')[0];
- this.settings = settings;
+ if (head) {
+ for (i=0, nl = head.getElementsByTagName('script'); i<nl.length; i++)
+ elements.push(nl[i]);
+ }
+
+ // Search through rest of document
+ for (i=0, nl = document.getElementsByTagName('script'); i<nl.length; i++)
+ elements.push(nl[i]);
- // Check if valid browser has execcommand support
- if (typeof(document.execCommand) == 'undefined')
- return;
+ // If base element found, add that infront of baseURL
+ nl = document.getElementsByTagName('base');
+ for (i=0; i<nl.length; i++) {
+ if (nl[i].href)
+ baseHREF = nl[i].href;
+ }
- // Get script base path
- if (!tinyMCE.baseURL) {
- var elements = document.getElementsByTagName('script');
+ for (i=0; i<elements.length; i++) {
+ 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)) {
+ src = elements[i].src;
- for (var i=0; i<elements.length; i++) {
- if (elements[i].src && (elements[i].src.indexOf("tiny_mce.js") != -1 || elements[i].src.indexOf("tiny_mce_src.js") != -1 || elements[i].src.indexOf("tiny_mce_gzip") != -1)) {
- var src = elements[i].src;
+ tinyMCE.srcMode = (src.indexOf('_src') != -1 || src.indexOf('_dev') != -1) ? '_src' : '';
+ tinyMCE.gzipMode = src.indexOf('_gzip') != -1;
+ src = src.substring(0, src.lastIndexOf('/'));
- tinyMCE.srcMode = (src.indexOf('_src') != -1) ? '_src' : '';
- src = src.substring(0, src.lastIndexOf('/'));
+ if (settings.exec_mode == "src" || settings.exec_mode == "normal")
+ tinyMCE.srcMode = settings.exec_mode == "src" ? '_src' : '';
- tinyMCE.baseURL = src;
- break;
+ // Force it absolute if page has a base href
+ if (baseHREF !== '' && src.indexOf('://') == -1)
+ tinyMCE.baseURL = baseHREF + src;
+ else
+ tinyMCE.baseURL = src;
+
+ break;
+ }
}
}
- }
- // Get document base path
- this.documentBasePath = document.location.href;
- if (this.documentBasePath.indexOf('?') != -1)
- this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.indexOf('?'));
- this.documentURL = this.documentBasePath;
- this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.lastIndexOf('/'));
-
- // If not HTTP absolute
- if (tinyMCE.baseURL.indexOf('://') == -1 && tinyMCE.baseURL.charAt(0) != '/') {
- // If site absolute
- tinyMCE.baseURL = this.documentBasePath + "/" + tinyMCE.baseURL;
- }
+ // Get document base path
+ this.documentBasePath = document.location.href;
+ if (this.documentBasePath.indexOf('?') != -1)
+ this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.indexOf('?'));
+ this.documentURL = this.documentBasePath;
+ this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.lastIndexOf('/'));
+
+ // If not HTTP absolute
+ if (tinyMCE.baseURL.indexOf('://') == -1 && tinyMCE.baseURL.charAt(0) != '/') {
+ // If site absolute
+ tinyMCE.baseURL = this.documentBasePath + "/" + tinyMCE.baseURL;
+ }
- // Set default values on settings
- this.defParam("mode", "none");
- this.defParam("theme", "advanced");
- this.defParam("plugins", "", true);
- this.defParam("language", "en");
- this.defParam("docs_language", this.settings['language']);
- this.defParam("elements", "");
- this.defParam("textarea_trigger", "mce_editable");
- this.defParam("editor_selector", "");
- this.defParam("editor_deselector", "mceNoEditor");
- this.defParam("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[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=0|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[style|dir|class|align],-h2[style|dir|class|align],-h3[style|dir|class|align],-h4[style|dir|class|align],-h5[style|dir|class|align],-h6[style|dir|class|align],hr[class|style],font[face|size|style|id|class|dir|color]");
- this.defParam("extended_valid_elements", "");
- this.defParam("invalid_elements", "");
- this.defParam("encoding", "");
- this.defParam("urlconverter_callback", tinyMCE.getParam("urlconvertor_callback", "TinyMCE.prototype.convertURL"));
- this.defParam("save_callback", "");
- this.defParam("debug", false);
- this.defParam("force_br_newlines", false);
- this.defParam("force_p_newlines", true);
- this.defParam("add_form_submit_trigger", true);
- this.defParam("relative_urls", true);
- this.defParam("remove_script_host", true);
- this.defParam("focus_alert", true);
- this.defParam("document_base_url", this.documentURL);
- this.defParam("visual", true);
- this.defParam("visual_table_class", "mceVisualAid");
- this.defParam("setupcontent_callback", "");
- this.defParam("fix_content_duplication", true);
- this.defParam("custom_undo_redo", true);
- this.defParam("custom_undo_redo_levels", -1);
- this.defParam("custom_undo_redo_keyboard_shortcuts", true);
- this.defParam("verify_css_classes", false);
- this.defParam("verify_html", true);
- this.defParam("apply_source_formatting", false);
- this.defParam("directionality", "ltr");
- this.defParam("cleanup_on_startup", false);
- this.defParam("inline_styles", false);
- this.defParam("convert_newlines_to_brs", false);
- this.defParam("auto_reset_designmode", true);
- this.defParam("entities", "160,nbsp,38,amp,34,quot,162,cent,8364,euro,163,pound,165,yen,169,copy,174,reg,8482,trade,8240,permil,181,micro,183,middot,8226,bull,8230,hellip,8242,prime,8243,Prime,167,sect,182,para,223,szlig,8249,lsaquo,8250,rsaquo,171,laquo,187,raquo,8216,lsquo,8217,rsquo,8220,ldquo,8221,rdquo,8218,sbquo,8222,bdquo,60,lt,62,gt,8804,le,8805,ge,8211,ndash,8212,mdash,175,macr,8254,oline,164,curren,166,brvbar,168,uml,161,iexcl,191,iquest,710,circ,732,tilde,176,deg,8722,minus,177,plusmn,247,divide,8260,frasl,215,times,185,sup1,178,sup2,179,sup3,188,frac14,189,frac12,190,frac34,402,fnof,8747,int,8721,sum,8734,infin,8730,radic,8764,sim,8773,cong,8776,asymp,8800,ne,8801,equiv,8712,isin,8713,notin,8715,ni,8719,prod,8743,and,8744,or,172,not,8745,cap,8746,cup,8706,part,8704,forall,8707,exist,8709,empty,8711,nabla,8727,lowast,8733,prop,8736,ang,180,acute,184,cedil,170,ordf,186,ordm,8224,dagger,8225,Dagger,192,Agrave,194,Acirc,195,Atilde,196,Auml,197,Aring,198,AElig,199,Ccedil,200,Egrave,202,Ecirc,203,Euml,204,Igrave,206,Icirc,207,Iuml,208,ETH,209,Ntilde,210,Ograve,212,Ocirc,213,Otilde,214,Ouml,216,Oslash,338,OElig,217,Ugrave,219,Ucirc,220,Uuml,376,Yuml,222,THORN,224,agrave,226,acirc,227,atilde,228,auml,229,aring,230,aelig,231,ccedil,232,egrave,234,ecirc,235,euml,236,igrave,238,icirc,239,iuml,240,eth,241,ntilde,242,ograve,244,ocirc,245,otilde,246,ouml,248,oslash,339,oelig,249,ugrave,251,ucirc,252,uuml,254,thorn,255,yuml,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,8501,alefsym,982,piv,8476,real,977,thetasym,978,upsih,8472,weierp,8465,image,8592,larr,8593,uarr,8594,rarr,8595,darr,8596,harr,8629,crarr,8656,lArr,8657,uArr,8658,rArr,8659,dArr,8660,hArr,8756,there4,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,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm,173,shy,233,eacute,237,iacute,243,oacute,250,uacute,193,Aacute,225,aacute,201,Eacute,205,Iacute,211,Oacute,218,Uacute,221,Yacute,253,yacute");
- this.defParam("entity_encoding", "named");
- this.defParam("cleanup_callback", "");
- this.defParam("add_unload_trigger", true);
- this.defParam("ask", false);
- this.defParam("nowrap", false);
- this.defParam("auto_resize", false);
- this.defParam("auto_focus", false);
- this.defParam("cleanup", true);
- this.defParam("remove_linebreaks", true);
- this.defParam("button_tile_map", false);
- this.defParam("submit_patch", true);
- this.defParam("browsers", "msie,safari,gecko,opera");
- this.defParam("dialog_type", "window");
- this.defParam("accessibility_warnings", true);
- this.defParam("merge_styles_invalid_parents", "");
- this.defParam("force_hex_style_colors", true);
- this.defParam("trim_span_elements", true);
- this.defParam("convert_fonts_to_spans", false);
- this.defParam("doctype", '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');
- this.defParam("font_size_classes", '');
- this.defParam("font_size_style_values", 'xx-small,x-small,small,medium,large,x-large,xx-large');
- this.defParam("event_elements", 'a,img');
- this.defParam("convert_urls", true);
- this.defParam("table_inline_editing", false);
- this.defParam("object_resizing", true);
-
- // Browser check IE
- if (this.isMSIE && this.settings['browsers'].indexOf('msie') == -1)
- return;
-
- // Browser check Gecko
- if (this.isGecko && this.settings['browsers'].indexOf('gecko') == -1)
- return;
-
- // Browser check Safari
- if (this.isSafari && this.settings['browsers'].indexOf('safari') == -1)
- return;
-
- // Browser check Opera
- if (this.isOpera && this.settings['browsers'].indexOf('opera') == -1)
- return;
-
- // If not super absolute make it so
- var baseHREF = tinyMCE.settings['document_base_url'];
- var h = document.location.href;
- var p = h.indexOf('://');
- if (p > 0 && document.location.protocol != "file:") {
- p = h.indexOf('/', p + 3);
- h = h.substring(0, p);
-
- if (baseHREF.indexOf('://') == -1)
- baseHREF = h + baseHREF;
-
- tinyMCE.settings['document_base_url'] = baseHREF;
- tinyMCE.settings['document_base_prefix'] = h;
- }
+ // Set default values on settings
+ this._def("mode", "none");
+ this._def("theme", "advanced");
+ this._def("plugins", "", true);
+ this._def("language", "en");
+ this._def("docs_language", this.settings.language);
+ this._def("elements", "");
+ this._def("textarea_trigger", "mce_editable");
+ this._def("editor_selector", "");
+ this._def("editor_deselector", "mceNoEditor");
+ 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]");
+ this._def("extended_valid_elements", "");
+ this._def("invalid_elements", "");
+ this._def("encoding", "");
+ this._def("urlconverter_callback", tinyMCE.getParam("urlconvertor_callback", "TinyMCE_Engine.prototype.convertURL"));
+ this._def("save_callback", "");
+ this._def("force_br_newlines", false);
+ this._def("force_p_newlines", true);
+ this._def("add_form_submit_trigger", true);
+ this._def("relative_urls", true);
+ this._def("remove_script_host", true);
+ this._def("focus_alert", true);
+ this._def("document_base_url", this.documentURL);
+ this._def("visual", true);
+ this._def("visual_table_class", "mceVisualAid");
+ this._def("setupcontent_callback", "");
+ this._def("fix_content_duplication", true);
+ this._def("custom_undo_redo", true);
+ this._def("custom_undo_redo_levels", -1);
+ this._def("custom_undo_redo_keyboard_shortcuts", true);
+ this._def("custom_undo_redo_restore_selection", true);
+ this._def("custom_undo_redo_global", false);
+ this._def("verify_html", true);
+ this._def("apply_source_formatting", false);
+ this._def("directionality", "ltr");
+ this._def("cleanup_on_startup", false);
+ this._def("inline_styles", false);
+ this._def("convert_newlines_to_brs", false);
+ this._def("auto_reset_designmode", true);
+ 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);
+ this._def("entity_encoding", "named");
+ this._def("cleanup_callback", "");
+ this._def("add_unload_trigger", true);
+ this._def("ask", false);
+ this._def("nowrap", false);
+ this._def("auto_resize", false);
+ this._def("auto_focus", false);
+ this._def("cleanup", true);
+ this._def("remove_linebreaks", true);
+ this._def("button_tile_map", false);
+ this._def("submit_patch", true);
+ this._def("browsers", "msie,safari,gecko,opera", true);
+ this._def("dialog_type", "window");
+ this._def("accessibility_warnings", true);
+ this._def("accessibility_focus", true);
+ this._def("merge_styles_invalid_parents", "");
+ this._def("force_hex_style_colors", true);
+ this._def("trim_span_elements", true);
+ this._def("convert_fonts_to_spans", false);
+ this._def("doctype", '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');
+ this._def("font_size_classes", '');
+ this._def("font_size_style_values", 'xx-small,x-small,small,medium,large,x-large,xx-large', true);
+ this._def("event_elements", 'a,img', true);
+ this._def("convert_urls", true);
+ this._def("table_inline_editing", false);
+ this._def("object_resizing", true);
+ this._def("custom_shortcuts", true);
+ this._def("convert_on_click", false);
+ this._def("content_css", '');
+ this._def("fix_list_elements", true);
+ this._def("fix_table_elements", false);
+ this._def("strict_loading_mode", document.contentType == 'application/xhtml+xml');
+ this._def("hidden_tab_class", '');
+ this._def("display_tab_class", '');
+ this._def("gecko_spellcheck", false);
+ this._def("hide_selects_on_submit", true);
+ this._def("forced_root_block", false);
+ this._def("remove_trailing_nbsp", false);
+
+ // Force strict loading mode to false on non Gecko browsers
+ if (this.isMSIE && !this.isOpera)
+ this.settings.strict_loading_mode = false;
+
+ // Browser check IE
+ if (this.isMSIE && this.settings.browsers.indexOf('msie') == -1)
+ return;
- // Trim away query part
- if (baseHREF.indexOf('?') != -1)
- baseHREF = baseHREF.substring(0, baseHREF.indexOf('?'));
+ // Browser check Gecko
+ if (this.isGecko && this.settings.browsers.indexOf('gecko') == -1)
+ return;
- this.settings['base_href'] = baseHREF.substring(0, baseHREF.lastIndexOf('/')) + "/";
+ // Browser check Safari
+ if (this.isSafari && this.settings.browsers.indexOf('safari') == -1)
+ return;
- theme = this.settings['theme'];
- this.blockRegExp = new RegExp("^(h[1-6]|p|div|address|pre|form|table|li|ol|ul|td|blockquote|center|dl|dir|fieldset|form|noscript|noframes|menu|isindex)$", "i");
- this.posKeyCodes = new Array(13,45,36,35,33,34,37,38,39,40);
- this.uniqueURL = 'http://tinymce.moxiecode.cp/mce_temp_url'; // Make unique URL non real URL
- this.uniqueTag = '<div id="mceTMPElement" style="display: none">TMP</div>';
+ // Browser check Opera
+ if (this.isOpera && this.settings.browsers.indexOf('opera') == -1)
+ return;
- // Theme url
- this.settings['theme_href'] = tinyMCE.baseURL + "/themes/" + theme;
+ // If not super absolute make it so
+ baseHREF = tinyMCE.settings.document_base_url;
+ h = document.location.href;
+ p = h.indexOf('://');
+ if (p > 0 && document.location.protocol != "file:") {
+ p = h.indexOf('/', p + 3);
+ h = h.substring(0, p);
- if (!tinyMCE.isMSIE)
- this.settings['force_br_newlines'] = false;
+ if (baseHREF.indexOf('://') == -1)
+ baseHREF = h + baseHREF;
- if (tinyMCE.getParam("content_css", false)) {
- var cssPath = tinyMCE.getParam("content_css", "");
+ tinyMCE.settings.document_base_url = baseHREF;
+ tinyMCE.settings.document_base_prefix = h;
+ }
- // Is relative
- if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
- this.settings['content_css'] = this.documentBasePath + "/" + cssPath;
- else
- this.settings['content_css'] = cssPath;
- } else
- this.settings['content_css'] = '';
+ // Trim away query part
+ if (baseHREF.indexOf('?') != -1)
+ baseHREF = baseHREF.substring(0, baseHREF.indexOf('?'));
- if (tinyMCE.getParam("popups_css", false)) {
- var cssPath = tinyMCE.getParam("popups_css", "");
+ this.settings.base_href = baseHREF.substring(0, baseHREF.lastIndexOf('/')) + "/";
- // Is relative
- if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
- this.settings['popups_css'] = this.documentBasePath + "/" + cssPath;
- else
- this.settings['popups_css'] = cssPath;
- } else
- this.settings['popups_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_popup.css";
+ theme = this.settings.theme;
+ 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';
+ 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';
+ this.blockElms = 'H[1-6]|P|DIV|ADDRESS|PRE|FORM|TABLE|LI|OL|UL|TD|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|FORM|NOSCRIPT|NOFRAMES|MENU|ISINDEX|SAMP';
+ this.blockRegExp = new RegExp("^(" + this.blockElms + ")$", "i");
+ this.posKeyCodes = [13,45,36,35,33,34,37,38,39,40];
+ this.uniqueURL = 'javascript:void(091039730);'; // Make unique URL non real URL
+ this.uniqueTag = '<div id="mceTMPElement" style="display: none">TMP</div>';
+ this.callbacks = ['onInit', 'getInfo', 'getEditorTemplate', 'setupContent', 'onChange', 'onPageLoad', 'handleNodeChange', 'initInstance', 'execCommand', 'getControlHTML', 'handleEvent', 'cleanup', 'removeInstance'];
- if (tinyMCE.getParam("editor_css", false)) {
- var cssPath = tinyMCE.getParam("editor_css", "");
+ // Theme url
+ this.settings.theme_href = tinyMCE.baseURL + "/themes/" + theme;
- // Is relative
- if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
- this.settings['editor_css'] = this.documentBasePath + "/" + cssPath;
- else
- this.settings['editor_css'] = cssPath;
- } else
- this.settings['editor_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css";
+ if (!tinyMCE.isIE || tinyMCE.isOpera)
+ this.settings.force_br_newlines = false;
- if (tinyMCE.settings['debug']) {
- var msg = "Debug: \n";
+ if (tinyMCE.getParam("popups_css", false)) {
+ cssPath = tinyMCE.getParam("popups_css", "");
- msg += "baseURL: " + this.baseURL + "\n";
- msg += "documentBasePath: " + this.documentBasePath + "\n";
- msg += "content_css: " + this.settings['content_css'] + "\n";
- msg += "popups_css: " + this.settings['popups_css'] + "\n";
- msg += "editor_css: " + this.settings['editor_css'] + "\n";
+ // Is relative
+ if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
+ this.settings.popups_css = this.documentBasePath + "/" + cssPath;
+ else
+ this.settings.popups_css = cssPath;
+ } else
+ this.settings.popups_css = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_popup.css";
- alert(msg);
- }
+ if (tinyMCE.getParam("editor_css", false)) {
+ cssPath = tinyMCE.getParam("editor_css", "");
+
+ // Is relative
+ if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')
+ this.settings.editor_css = this.documentBasePath + "/" + cssPath;
+ else
+ this.settings.editor_css = cssPath;
+ } else {
+ if (this.settings.editor_css !== '')
+ this.settings.editor_css = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css";
+ }
+
+ // Only do this once
+ if (this.configs.length == 0) {
+ if (typeof(TinyMCECompressed) == "undefined") {
+ tinyMCE.addEvent(window, "DOMContentLoaded", TinyMCE_Engine.prototype.onLoad);
+
+ if (tinyMCE.isRealIE) {
+ if (document.body)
+ tinyMCE.addEvent(document.body, "readystatechange", TinyMCE_Engine.prototype.onLoad);
+ else
+ tinyMCE.addEvent(document, "readystatechange", TinyMCE_Engine.prototype.onLoad);
+ }
+
+ tinyMCE.addEvent(window, "load", TinyMCE_Engine.prototype.onLoad);
+ tinyMCE._addUnloadEvents();
+ }
+ }
+
+ this.loadScript(tinyMCE.baseURL + '/themes/' + this.settings.theme + '/editor_template' + tinyMCE.srcMode + '.js');
+ this.loadScript(tinyMCE.baseURL + '/langs/' + this.settings.language + '.js');
+ this.loadCSS(this.settings.editor_css);
+
+ // Add plugins
+ p = tinyMCE.getParam('plugins', '', true, ',');
+ if (p.length > 0) {
+ for (i=0; i<p.length; i++) {
+ if (p[i].charAt(0) != '-')
+ this.loadScript(tinyMCE.baseURL + '/plugins/' + p[i] + '/editor_plugin' + tinyMCE.srcMode + '.js');
+ }
+ }
+
+ // Setup entities
+ if (tinyMCE.getParam('entity_encoding') == 'named') {
+ settings.cleanup_entities = [];
+ entities = tinyMCE.getParam('entities', '', true, ',');
+ for (i=0; i<entities.length; i+=2)
+ settings.cleanup_entities['c' + entities[i]] = entities[i+1];
+ }
- // Init HTML cleanup
- this._initCleanup();
+ // Save away this config
+ settings.index = this.configs.length;
+ this.configs[this.configs.length] = settings;
+
+ // Start loading first one in chain
+ this.loadNextScript();
+
+ // Force flicker free CSS backgrounds in IE
+ if (this.isIE && !this.isOpera) {
+ try {
+ document.execCommand('BackgroundImageCache', false, true);
+ } catch (e) {
+ // Ignore
+ }
+ }
- // Only do this once
- if (this.configs.length == 0) {
- // Is Safari enabled
- if (this.isSafari && this.getParam('safari_warning', true))
- alert("Safari support is very limited and should be considered experimental.\nSo there is no need to even submit bugreports on this early version.\nYou can disable this message by setting: safari_warning option to false");
+ // Setup XML encoding regexps
+ this.xmlEncodeRe = new RegExp('[<>&"]', 'g');
+ },
- tinyMCE.addEvent(window, "load", TinyMCE.prototype.onLoad);
+ _addUnloadEvents : function() {
+ var st = tinyMCE.settings.add_unload_trigger;
- if (tinyMCE.isMSIE) {
- if (tinyMCE.settings['add_unload_trigger']) {
- tinyMCE.addEvent(window, "unload", TinyMCE.prototype.unloadHandler);
- tinyMCE.addEvent(window.document, "beforeunload", TinyMCE.prototype.unloadHandler);
+ if (tinyMCE.isIE) {
+ if (st) {
+ tinyMCE.addEvent(window, "unload", TinyMCE_Engine.prototype.unloadHandler);
+ tinyMCE.addEvent(window.document, "beforeunload", TinyMCE_Engine.prototype.unloadHandler);
}
} else {
- if (tinyMCE.settings['add_unload_trigger'])
+ if (st)
tinyMCE.addEvent(window, "unload", function () {tinyMCE.triggerSave(true, true);});
}
- }
+ },
- this.loadScript(tinyMCE.baseURL + '/themes/' + this.settings['theme'] + '/editor_template' + tinyMCE.srcMode + '.js');
- this.loadScript(tinyMCE.baseURL + '/langs/' + this.settings['language'] + '.js');
- this.loadCSS(this.settings['editor_css']);
+ _def : function(key, def_val, t) {
+ var v = tinyMCE.getParam(key, def_val);
- // Add plugins
- var themePlugins = tinyMCE.getParam('plugins', '', true, ',');
- if (this.settings['plugins'] != '') {
- for (var i=0; i<themePlugins.length; i++)
- this.loadScript(tinyMCE.baseURL + '/plugins/' + themePlugins[i] + '/editor_plugin' + tinyMCE.srcMode + '.js');
- }
+ v = t ? v.replace(/\s+/g, "") : v;
- // Setup entities
- settings['cleanup_entities'] = new Array();
- var entities = tinyMCE.getParam('entities', '', true, ',');
- for (var i=0; i<entities.length; i+=2)
- settings['cleanup_entities']['c' + entities[i]] = entities[i+1];
+ this.settings[key] = v;
+ },
- // Save away this config
- settings['index'] = this.configs.length;
- this.configs[this.configs.length] = settings;
-};
+ hasPlugin : function(n) {
+ return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;
+ },
-TinyMCE.prototype.loadScript = function(url) {
- for (var i=0; i<this.loadedFiles.length; i++) {
- if (this.loadedFiles[i] == url)
- return;
- }
+ addPlugin : function(n, p) {
+ var op = this.plugins[n];
- document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></script>');
+ // Use the previous plugin object base URL used when loading external plugins
+ p.baseURL = op ? op.baseURL : tinyMCE.baseURL + "/plugins/" + n;
+ this.plugins[n] = p;
- this.loadedFiles[this.loadedFiles.length] = url;
-};
+ this.loadNextScript();
+ },
-TinyMCE.prototype.loadCSS = function(url) {
- for (var i=0; i<this.loadedFiles.length; i++) {
- if (this.loadedFiles[i] == url)
- return;
- }
+ setPluginBaseURL : function(n, u) {
+ var op = this.plugins[n];
- document.write('<link href="' + url + '" rel="stylesheet" type="text/css" />');
+ if (op)
+ op.baseURL = u;
+ else
+ this.plugins[n] = {baseURL : u};
+ },
- this.loadedFiles[this.loadedFiles.length] = url;
-};
+ loadPlugin : function(n, u) {
+ u = u.indexOf('.js') != -1 ? u.substring(0, u.lastIndexOf('/')) : u;
+ u = u.charAt(u.length-1) == '/' ? u.substring(0, u.length-1) : u;
+ this.plugins[n] = {baseURL : u};
+ this.loadScript(u + "/editor_plugin" + (tinyMCE.srcMode ? '_src' : '') + ".js");
+ },
-TinyMCE.prototype.importCSS = function(doc, css_file) {
- if (css_file == '')
- return;
+ hasTheme : function(n) {
+ return typeof(this.themes[n]) != "undefined" && this.themes[n] != null;
+ },
- if (typeof(doc.createStyleSheet) == "undefined") {
- var elm = doc.createElement("link");
+ addTheme : function(n, t) {
+ this.themes[n] = t;
- elm.rel = "stylesheet";
- elm.href = css_file;
+ this.loadNextScript();
+ },
- if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0)
- headArr[0].appendChild(elm);
- } else
- var styleSheet = doc.createStyleSheet(css_file);
-};
+ addMenu : function(n, m) {
+ this.menus[n] = m;
+ },
-TinyMCE.prototype.confirmAdd = function(e, settings) {
- var elm = tinyMCE.isMSIE ? event.srcElement : e.target;
- var elementId = elm.name ? elm.name : elm.id;
+ hasMenu : function(n) {
+ return typeof(this.plugins[n]) != "undefined" && this.plugins[n] != null;
+ },
- tinyMCE.settings = settings;
+ loadScript : function(url) {
+ var i;
- if (!elm.getAttribute('mce_noask') && confirm(tinyMCELang['lang_edit_confirm']))
- tinyMCE.addMCEControl(elm, elementId);
+ for (i=0; i<this.loadedFiles.length; i++) {
+ if (this.loadedFiles[i] == url)
+ return;
+ }
- elm.setAttribute('mce_noask', 'true');
-};
+ if (tinyMCE.settings.strict_loading_mode)
+ this.pendingFiles[this.pendingFiles.length] = url;
+ else
+ document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></script>');
-TinyMCE.prototype.updateContent = function(form_element_name) {
- // Find MCE instance linked to given form element and copy it's value
- var formElement = document.getElementById(form_element_name);
- for (var n in tinyMCE.instances) {
- var inst = tinyMCE.instances[n];
- if (!tinyMCE.isInstance(inst))
- continue;
+ this.loadedFiles[this.loadedFiles.length] = url;
+ },
- inst.switchSettings();
+ loadNextScript : function() {
+ var d = document, se;
- if (inst.formElement == formElement) {
- var doc = inst.getDoc();
-
- tinyMCE._setHTML(doc, inst.formElement.value);
+ if (!tinyMCE.settings.strict_loading_mode)
+ return;
- if (!tinyMCE.isMSIE)
- doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid);
- }
- }
-};
+ if (this.loadingIndex < this.pendingFiles.length) {
+ se = d.createElementNS('http://www.w3.org/1999/xhtml', 'script');
+ se.setAttribute('language', 'javascript');
+ se.setAttribute('type', 'text/javascript');
+ se.setAttribute('src', this.pendingFiles[this.loadingIndex++]);
+
+ d.getElementsByTagName("head")[0].appendChild(se);
+ } else
+ this.loadingIndex = -1; // Done with loading
+ },
+
+ loadCSS : function(url) {
+ var ar = url.replace(/\s+/, '').split(',');
+ var lflen = 0, csslen = 0, skip = false;
+ var x = 0, i = 0, nl, le;
+
+ for (x = 0,csslen = ar.length; x<csslen; x++) {
+ if (ar[x] != null && ar[x] != 'null' && ar[x].length > 0) {
+ /* Make sure it doesn't exist. */
+ for (i=0, lflen=this.loadedFiles.length; i<lflen; i++) {
+ if (this.loadedFiles[i] == ar[x]) {
+ skip = true;
+ break;
+ }
+ }
-TinyMCE.prototype.addMCEControl = function(replace_element, form_element_name, target_document) {
- var id = "mce_editor_" + tinyMCE.idCounter++;
- var inst = new TinyMCEControl(tinyMCE.settings);
+ if (!skip) {
+ if (tinyMCE.settings.strict_loading_mode) {
+ nl = document.getElementsByTagName("head");
- inst.editorId = id;
- this.instances[id] = inst;
+ le = document.createElement('link');
+ le.setAttribute('href', ar[x]);
+ le.setAttribute('rel', 'stylesheet');
+ le.setAttribute('type', 'text/css');
- inst.onAdd(replace_element, form_element_name, target_document);
-};
+ nl[0].appendChild(le);
+ } else
+ document.write('<link href="' + ar[x] + '" rel="stylesheet" type="text/css" />');
-TinyMCE.prototype.triggerSave = function(skip_cleanup, skip_callback) {
- // Cleanup and set all form fields
- for (var n in tinyMCE.instances) {
- var inst = tinyMCE.instances[n];
- if (!tinyMCE.isInstance(inst))
- continue;
+ this.loadedFiles[this.loadedFiles.length] = ar[x];
+ }
+ }
+ }
+ },
- inst.switchSettings();
+ importCSS : function(doc, css) {
+ var css_ary = css.replace(/\s+/, '').split(',');
+ var csslen, elm, headArr, x, css_file;
- tinyMCE.settings['preformatted'] = false;
+ for (x = 0, csslen = css_ary.length; x<csslen; x++) {
+ css_file = css_ary[x];
- // Default to false
- if (typeof(skip_cleanup) == "undefined")
- skip_cleanup = false;
+ if (css_file != null && css_file != 'null' && css_file.length > 0) {
+ // Is relative, make absolute
+ if (css_file.indexOf('://') == -1 && css_file.charAt(0) != '/')
+ css_file = this.documentBasePath + "/" + css_file;
- // Default to false
- if (typeof(skip_callback) == "undefined")
- skip_callback = false;
+ if (typeof(doc.createStyleSheet) == "undefined") {
+ elm = doc.createElement("link");
- tinyMCE._setHTML(inst.getDoc(), inst.getBody().innerHTML);
+ elm.rel = "stylesheet";
+ elm.href = css_file;
- // Remove visual aids when cleanup is disabled
- if (inst.settings['cleanup'] == false) {
- tinyMCE.handleVisualAid(inst.getBody(), true, false, inst);
- tinyMCE._setEventsEnabled(inst.getBody(), true);
+ if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0)
+ headArr[0].appendChild(elm);
+ } else
+ doc.createStyleSheet(css_file);
+ }
}
+ },
- tinyMCE._customCleanup(inst, "submit_content_dom", inst.contentWindow.document.body);
- var htm = skip_cleanup ? inst.getBody().innerHTML : tinyMCE._cleanupHTML(inst, inst.getDoc(), this.settings, inst.getBody(), this.visualAid, true);
- htm = tinyMCE._customCleanup(inst, "submit_content", htm);
+ confirmAdd : function(e, settings) {
+ var elm = tinyMCE.isIE ? event.srcElement : e.target;
+ var elementId = elm.name ? elm.name : elm.id;
- if (tinyMCE.settings["encoding"] == "xml" || tinyMCE.settings["encoding"] == "html")
- htm = tinyMCE.convertStringToXML(htm);
+ tinyMCE.settings = settings;
- if (!skip_callback && tinyMCE.settings['save_callback'] != "")
- var content = eval(tinyMCE.settings['save_callback'] + "(inst.formTargetElementId,htm,inst.getBody());");
+ if (tinyMCE.settings.convert_on_click || (!elm.getAttribute('mce_noask') && confirm(tinyMCELang.lang_edit_confirm)))
+ tinyMCE.addMCEControl(elm, elementId);
- // Use callback content if available
- if ((typeof(content) != "undefined") && content != null)
- htm = content;
+ elm.setAttribute('mce_noask', 'true');
+ },
- // Replace some weird entities (Bug: #1056343)
- htm = tinyMCE.regexpReplace(htm, "(", "(", "gi");
- htm = tinyMCE.regexpReplace(htm, ")", ")", "gi");
- htm = tinyMCE.regexpReplace(htm, ";", ";", "gi");
- htm = tinyMCE.regexpReplace(htm, """, """, "gi");
- htm = tinyMCE.regexpReplace(htm, "^", "^", "gi");
+ updateContent : function(form_element_name) {
+ var formElement, n, inst, doc;
- if (inst.formElement)
- inst.formElement.value = htm;
- }
-};
+ // Find MCE instance linked to given form element and copy it's value
+ formElement = document.getElementById(form_element_name);
+ for (n in tinyMCE.instances) {
+ inst = tinyMCE.instances[n];
-TinyMCE.prototype._setEventsEnabled = function(node, state) {
- var events = new Array('onfocus','onblur','onclick','ondblclick',
- 'onmousedown','onmouseup','onmouseover','onmousemove',
- 'onmouseout','onkeypress','onkeydown','onkeydown','onkeyup');
+ if (!tinyMCE.isInstance(inst))
+ continue;
- var evs = tinyMCE.settings['event_elements'].split(',');
- for (var y=0; y<evs.length; y++){
- var elms = node.getElementsByTagName(evs[y]);
- for (var i=0; i<elms.length; i++) {
- var event = "";
+ inst.switchSettings();
- for (var x=0; x<events.length; x++) {
- if ((event = tinyMCE.getAttrib(elms[i], events[x])) != '') {
- event = tinyMCE.cleanupEventStr("" + event);
+ if (inst.formElement == formElement) {
+ doc = inst.getDoc();
- if (!state)
- event = "return true;" + event;
- else
- event = event.replace(/^return true;/gi, '');
+ tinyMCE._setHTML(doc, inst.formElement.value);
- elms[i].removeAttribute(events[x]);
- elms[i].setAttribute(events[x], event);
- }
+ if (!tinyMCE.isIE)
+ doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid);
}
}
- }
-};
+ },
-TinyMCE.prototype.resetForm = function(form_index) {
- var formObj = document.forms[form_index];
+ addMCEControl : function(replace_element, form_element_name, target_document) {
+ var id = "mce_editor_" + tinyMCE.idCounter++;
+ var inst = new TinyMCE_Control(tinyMCE.settings);
- for (var n in tinyMCE.instances) {
- var inst = tinyMCE.instances[n];
- if (!tinyMCE.isInstance(inst))
- continue;
-
- inst.switchSettings();
+ inst.editorId = id;
+ this.instances[id] = inst;
- for (var i=0; i<formObj.elements.length; i++) {
- if (inst.formTargetElementId == formObj.elements[i].name)
- inst.getBody().innerHTML = inst.startContent;
- }
- }
-};
+ inst._onAdd(replace_element, form_element_name, target_document);
+ },
-TinyMCE.prototype.execInstanceCommand = function(editor_id, command, user_interface, value, focus) {
- var inst = tinyMCE.getInstanceById(editor_id);
- if (inst) {
- if (typeof(focus) == "undefined")
- focus = true;
+ removeInstance : function(ti) {
+ var t = [], n, i;
- if (focus)
- inst.contentWindow.focus();
+ // Remove from instances
+ for (n in tinyMCE.instances) {
+ i = tinyMCE.instances[n];
- // Reset design mode if lost
- inst.autoResetDesignMode();
+ if (tinyMCE.isInstance(i) && ti != i)
+ t[n] = i;
+ }
- this.selectedElement = inst.getFocusElement();
- this.selectedInstance = inst;
- tinyMCE.execCommand(command, user_interface, value);
+ tinyMCE.instances = t;
- // Cancel event so it doesn't call onbeforeonunlaod
- if (tinyMCE.isMSIE && window.event != null)
- tinyMCE.cancelEvent(window.event);
- }
-};
+ // Remove from global undo/redo
+ n = [];
+ t = tinyMCE.undoLevels;
-TinyMCE.prototype.execCommand = function(command, user_interface, value) {
- // Default input
- user_interface = user_interface ? user_interface : false;
- value = value ? value : null;
+ for (i=0; i<t.length; i++) {
+ if (t[i] != ti)
+ n.push(t[i]);
+ }
- if (tinyMCE.selectedInstance)
- tinyMCE.selectedInstance.switchSettings();
+ tinyMCE.undoLevels = n;
+ tinyMCE.undoIndex = n.length;
- switch (command) {
- case 'mceHelp':
- var template = new Array();
+ // Dispatch remove instance call
+ tinyMCE.dispatchCallback(ti, 'remove_instance_callback', 'removeInstance', ti);
- template['file'] = 'about.htm';
- template['width'] = 480;
- template['height'] = 380;
+ return ti;
+ },
- tinyMCE.openWindow(template, {
- tinymce_version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion,
- tinymce_releasedate : tinyMCE.releaseDate,
- inline : "yes"
- });
- return;
+ removeMCEControl : function(editor_id) {
+ var inst = tinyMCE.getInstanceById(editor_id), h, re, ot, tn;
- case 'mceFocus':
- var inst = tinyMCE.getInstanceById(value);
- if (inst)
- inst.contentWindow.focus();
- return;
+ if (inst) {
+ inst.switchSettings();
- case "mceAddControl":
- case "mceAddEditor":
- tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);
- return;
+ editor_id = inst.editorId;
+ h = tinyMCE.getContent(editor_id);
- case "mceAddFrameControl":
- tinyMCE.addMCEControl(tinyMCE._getElementById(value), value['element'], value['document']);
- return;
+ this.removeInstance(inst);
- case "mceRemoveControl":
- case "mceRemoveEditor":
- tinyMCE.removeMCEControl(value);
- return;
+ tinyMCE.selectedElement = null;
+ tinyMCE.selectedInstance = null;
- case "mceResetDesignMode":
- // Resets the designmode state of the editors in Gecko
- if (!tinyMCE.isMSIE) {
- for (var n in tinyMCE.instances) {
- if (!tinyMCE.isInstance(tinyMCE.instances[n]))
- continue;
+ // Remove element
+ re = document.getElementById(editor_id + "_parent");
+ ot = inst.oldTargetElement;
+ tn = ot.nodeName.toLowerCase();
- try {
- tinyMCE.instances[n].getDoc().designMode = "on";
- } catch (e) {
- // Ignore any errors
- }
- }
+ if (tn == "textarea" || tn == "input") {
+ re.parentNode.removeChild(re);
+ ot.style.display = "inline";
+ ot.value = h;
+ } else {
+ ot.innerHTML = h;
+ ot.style.display = 'block';
+ re.parentNode.insertBefore(ot, re);
+ re.parentNode.removeChild(re);
}
+ }
+ },
- return;
- }
+ triggerSave : function(skip_cleanup, skip_callback) {
+ var inst, n;
- if (this.selectedInstance) {
- this.selectedInstance.execCommand(command, user_interface, value);
- } else if (tinyMCE.settings['focus_alert'])
- alert(tinyMCELang['lang_focus_alert']);
-};
+ // Default to false
+ if (typeof(skip_cleanup) == "undefined")
+ skip_cleanup = false;
-TinyMCE.prototype.eventPatch = function(editor_id) {
- // Remove odd, error
- if (typeof(tinyMCE) == "undefined")
- return true;
+ // Default to false
+ if (typeof(skip_callback) == "undefined")
+ skip_callback = false;
- for (var i=0; i<document.frames.length; i++) {
- try {
- if (document.frames[i].event) {
- var event = document.frames[i].event;
+ // Cleanup and set all form fields
+ for (n in tinyMCE.instances) {
+ inst = tinyMCE.instances[n];
- if (!event.target)
- event.target = event.srcElement;
+ if (!tinyMCE.isInstance(inst))
+ continue;
- TinyMCE.prototype.handleEvent(event);
- return;
- }
- } catch (ex) {
- // Ignore error if iframe is pointing to external URL
+ inst.triggerSave(skip_cleanup, skip_callback);
}
- }
-};
+ },
-TinyMCE.prototype.unloadHandler = function() {
- tinyMCE.triggerSave(true, true);
-};
+ resetForm : function(form_index) {
+ var i, inst, n, formObj = document.forms[form_index];
-TinyMCE.prototype.addEventHandlers = function(editor_id) {
- if (tinyMCE.isMSIE) {
- var doc = document.frames[editor_id].document;
+ for (n in tinyMCE.instances) {
+ inst = tinyMCE.instances[n];
- // Event patch
- tinyMCE.addEvent(doc, "keypress", TinyMCE.prototype.eventPatch);
- tinyMCE.addEvent(doc, "keyup", TinyMCE.prototype.eventPatch);
- tinyMCE.addEvent(doc, "keydown", TinyMCE.prototype.eventPatch);
- tinyMCE.addEvent(doc, "mouseup", TinyMCE.prototype.eventPatch);
- tinyMCE.addEvent(doc, "click", TinyMCE.prototype.eventPatch);
- } else {
- var inst = tinyMCE.instances[editor_id];
- var doc = inst.getDoc();
+ if (!tinyMCE.isInstance(inst))
+ continue;
- inst.switchSettings();
+ inst.switchSettings();
- tinyMCE.addEvent(doc, "keypress", tinyMCE.handleEvent);
- tinyMCE.addEvent(doc, "keydown", tinyMCE.handleEvent);
- tinyMCE.addEvent(doc, "keyup", tinyMCE.handleEvent);
- tinyMCE.addEvent(doc, "click", tinyMCE.handleEvent);
- tinyMCE.addEvent(doc, "mouseup", tinyMCE.handleEvent);
- tinyMCE.addEvent(doc, "mousedown", tinyMCE.handleEvent);
- tinyMCE.addEvent(doc, "focus", tinyMCE.handleEvent);
- tinyMCE.addEvent(doc, "blur", tinyMCE.handleEvent);
+ for (i=0; i<formObj.elements.length; i++) {
+ if (inst.formTargetElementId == formObj.elements[i].name)
+ inst.getBody().innerHTML = inst.startContent;
+ }
+ }
+ },
- eval('try { doc.designMode = "On"; } catch(e) {}');
- }
-};
+ execInstanceCommand : function(editor_id, command, user_interface, value, focus) {
+ var inst = tinyMCE.getInstanceById(editor_id), r;
-TinyMCE.prototype._createIFrame = function(replace_element) {
- var iframe = document.createElement("iframe");
- var id = replace_element.getAttribute("id");
- var aw, ah;
+ if (inst) {
+ r = inst.selection.getRng();
- aw = "" + tinyMCE.settings['area_width'];
- ah = "" + tinyMCE.settings['area_height'];
+ if (typeof(focus) == "undefined")
+ focus = true;
- if (aw.indexOf('%') == -1) {
- aw = parseInt(aw);
- aw = aw < 0 ? 300 : aw;
- aw = aw + "px";
- }
+ // IE bug lost focus on images in absolute divs Bug #1534575
+ if (focus && (!r || !r.item))
+ inst.contentWindow.focus();
- if (ah.indexOf('%') == -1) {
- ah = parseInt(ah);
- ah = ah < 0 ? 240 : ah;
- ah = ah + "px";
- }
+ // Reset design mode if lost
+ inst.autoResetDesignMode();
- iframe.setAttribute("id", id);
- //iframe.setAttribute("className", "mceEditorArea");
- iframe.setAttribute("border", "0");
- iframe.setAttribute("frameBorder", "0");
- iframe.setAttribute("marginWidth", "0");
- iframe.setAttribute("marginHeight", "0");
- iframe.setAttribute("leftMargin", "0");
- iframe.setAttribute("topMargin", "0");
- iframe.setAttribute("width", aw);
- iframe.setAttribute("height", ah);
- iframe.setAttribute("allowtransparency", "true");
-
- if (tinyMCE.settings["auto_resize"])
- iframe.setAttribute("scrolling", "no");
-
- // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs
- if (tinyMCE.isMSIE && !tinyMCE.isOpera)
- iframe.setAttribute("src", this.settings['default_document']);
-
- iframe.style.width = aw;
- iframe.style.height = ah;
-
- // MSIE 5.0 issue
- if (tinyMCE.isMSIE && !tinyMCE.isOpera)
- replace_element.outerHTML = iframe.outerHTML;
- else
- replace_element.parentNode.replaceChild(iframe, replace_element);
-
- if (tinyMCE.isMSIE)
- return window.frames[id];
- else
- return iframe;
-};
+ this.selectedElement = inst.getFocusElement();
+ inst.select();
+ tinyMCE.execCommand(command, user_interface, value);
-TinyMCE.prototype.setupContent = function(editor_id) {
- var inst = tinyMCE.instances[editor_id];
- var doc = inst.getDoc();
- var head = doc.getElementsByTagName('head').item(0);
- var content = inst.startContent;
+ // Cancel event so it doesn't call onbeforeonunlaod
+ if (tinyMCE.isIE && window.event != null)
+ tinyMCE.cancelEvent(window.event);
+ }
+ },
- tinyMCE.operaOpacityCounter = 100 * tinyMCE.idCounter;
+ execCommand : function(command, user_interface, value) {
+ var inst = tinyMCE.selectedInstance, n, pe, te;
- inst.switchSettings();
+ // Default input
+ user_interface = user_interface ? user_interface : false;
+ value = value ? value : null;
- // Not loaded correctly hit it again, Mozilla bug #997860
- if (!tinyMCE.isMSIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") {
- // This part will remove the designMode status
- // Failes first time in Firefox 1.5b2 on Mac
- try {doc.location.href = tinyMCE.baseURL + "/blank.htm";} catch (ex) {}
- window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 1000);
- return;
- }
+ if (inst)
+ inst.switchSettings();
- if (!head) {
- window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10);
- return;
- }
+ switch (command) {
+ case "Undo":
+ if (this.getParam('custom_undo_redo_global')) {
+ if (this.undoIndex > 0) {
+ tinyMCE.nextUndoRedoAction = 'Undo';
+ inst = this.undoLevels[--this.undoIndex];
+ inst.select();
+
+ if (!tinyMCE.nextUndoRedoInstanceId)
+ inst.execCommand('Undo');
+ }
+ } else
+ inst.execCommand('Undo');
+ return true;
- // Import theme specific content CSS the user specific
- tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/themes/" + inst.settings['theme'] + "/css/editor_content.css");
- tinyMCE.importCSS(inst.getDoc(), inst.settings['content_css']);
- tinyMCE.executeCallback('init_instance_callback', '_initInstance', 0, inst);
+ case "Redo":
+ if (this.getParam('custom_undo_redo_global')) {
+ if (this.undoIndex <= this.undoLevels.length - 1) {
+ tinyMCE.nextUndoRedoAction = 'Redo';
+ inst = this.undoLevels[this.undoIndex++];
+ inst.select();
- // Setup span styles
- if (tinyMCE.getParam("convert_fonts_to_spans"))
- inst.getDoc().body.setAttribute('id', 'mceSpanFonts');
+ if (!tinyMCE.nextUndoRedoInstanceId)
+ inst.execCommand('Redo');
+ }
+ } else
+ inst.execCommand('Redo');
- if (tinyMCE.settings['nowrap'])
- doc.body.style.whiteSpace = "nowrap";
+ return true;
- doc.body.dir = this.settings['directionality'];
- doc.editorId = editor_id;
+ case 'mceFocus':
+ inst = tinyMCE.getInstanceById(value);
- // Add on document element in Mozilla
- if (!tinyMCE.isMSIE)
- doc.documentElement.editorId = editor_id;
+ if (inst)
+ inst.getWin().focus();
+ return;
- // Setup base element
- var base = doc.createElement("base");
- base.setAttribute('href', tinyMCE.settings['base_href']);
- head.appendChild(base);
+ case "mceAddControl":
+ case "mceAddEditor":
+ tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);
+ return;
- // Replace new line characters to BRs
- if (tinyMCE.settings['convert_newlines_to_brs']) {
- content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi");
- content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi");
- content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi");
- }
+ case "mceAddFrameControl":
+ tinyMCE.addMCEControl(tinyMCE._getElementById(value.element, value.document), value.element, value.document);
+ return;
- // Open closed anchors
-// content = content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
+ case "mceRemoveControl":
+ case "mceRemoveEditor":
+ tinyMCE.removeMCEControl(value);
+ return;
- // Call custom cleanup code
- content = tinyMCE.storeAwayURLs(content);
- content = tinyMCE._customCleanup(inst, "insert_to_editor", content);
+ case "mceToggleEditor":
+ inst = tinyMCE.getInstanceById(value);
- if (tinyMCE.isMSIE) {
- // Ugly!!!
- window.setInterval('try{tinyMCE.getCSSClasses(document.frames["' + editor_id + '"].document, "' + editor_id + '");}catch(e){}', 500);
+ if (inst) {
+ pe = document.getElementById(inst.editorId + '_parent');
+ te = inst.oldTargetElement;
- if (tinyMCE.settings["force_br_newlines"])
- document.frames[editor_id].document.styleSheets[0].addRule("p", "margin: 0px;");
+ if (typeof(inst.enabled) == 'undefined')
+ inst.enabled = true;
- var body = document.frames[editor_id].document.body;
+ inst.enabled = !inst.enabled;
- tinyMCE.addEvent(body, "beforepaste", TinyMCE.prototype.eventPatch);
- tinyMCE.addEvent(body, "beforecut", TinyMCE.prototype.eventPatch);
+ if (!inst.enabled) {
+ pe.style.display = 'none';
- body.editorId = editor_id;
- }
+ if (te.nodeName == 'TEXTAREA' || te.nodeName == 'INPUT')
+ te.value = inst.getHTML();
+ else
+ te.innerHTML = inst.getHTML();
- content = tinyMCE.cleanupHTMLCode(content);
+ te.style.display = inst.oldTargetDisplay;
+ tinyMCE.dispatchCallback(inst, 'hide_instance_callback', 'hideInstance', inst);
+ } else {
+ pe.style.display = 'block';
+ te.style.display = 'none';
- // Fix for bug #958637
- if (!tinyMCE.isMSIE) {
- var contentElement = inst.getDoc().createElement("body");
- var doc = inst.getDoc();
+ if (te.nodeName == 'TEXTAREA' || te.nodeName == 'INPUT')
+ inst.setHTML(te.value);
+ else
+ inst.setHTML(te.innerHTML);
- contentElement.innerHTML = content;
+ inst.useCSS = false;
+ tinyMCE.dispatchCallback(inst, 'show_instance_callback', 'showInstance', inst);
+ }
+ } else
+ tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);
- // Remove weridness!
- if (tinyMCE.isGecko && tinyMCE.settings['remove_lt_gt'])
- content = content.replace(new RegExp('<>', 'g'), "");
+ return;
- if (tinyMCE.settings['cleanup_on_startup'])
- tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement));
- else {
- // Convert all strong/em to b/i
- content = tinyMCE.regexpReplace(content, "<strong", "<b", "gi");
- content = tinyMCE.regexpReplace(content, "<em(/?)>", "<i$1>", "gi");
- content = tinyMCE.regexpReplace(content, "<em ", "<i ", "gi");
- content = tinyMCE.regexpReplace(content, "</strong>", "</b>", "gi");
- content = tinyMCE.regexpReplace(content, "</em>", "</i>", "gi");
- tinyMCE.setInnerHTML(inst.getBody(), content);
- }
-
- inst.convertAllRelativeURLs();
- } else {
- if (tinyMCE.settings['cleanup_on_startup']) {
- tinyMCE._setHTML(inst.getDoc(), content);
-
- // Produces permission denied error in MSIE 5.5
- eval('try {tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody()));} catch(e) {}');
- } else
- tinyMCE._setHTML(inst.getDoc(), content);
- }
+ case "mceResetDesignMode":
+ // Resets the designmode state of the editors in Gecko
+ if (tinyMCE.isGecko) {
+ for (n in tinyMCE.instances) {
+ if (!tinyMCE.isInstance(tinyMCE.instances[n]))
+ continue;
+
+ try {
+ tinyMCE.instances[n].getDoc().designMode = "off";
+ tinyMCE.instances[n].getDoc().designMode = "on";
+ tinyMCE.instances[n].useCSS = false;
+ } catch (e) {
+ // Ignore any errors
+ }
+ }
+ }
- // Fix for bug #957681
- //inst.getDoc().designMode = inst.getDoc().designMode;
+ return;
+ }
- // Setup element references
- var parentElm = document.getElementById(inst.editorId + '_parent');
- if (parentElm.lastChild.nodeName == "INPUT")
- inst.formElement = tinyMCE.isGecko ? parentElm.firstChild : parentElm.lastChild;
- else
- inst.formElement = tinyMCE.isGecko ? parentElm.previousSibling : parentElm.nextSibling;
+ if (inst) {
+ inst.execCommand(command, user_interface, value);
+ } else if (tinyMCE.settings.focus_alert)
+ alert(tinyMCELang.lang_focus_alert);
+ },
- tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings['visual'], inst);
- tinyMCE.executeCallback('setupcontent_callback', '_setupContent', 0, editor_id, inst.getBody(), inst.getDoc());
+ _createIFrame : function(replace_element, doc, win) {
+ var iframe, id = replace_element.getAttribute("id");
+ var aw, ah;
- // Re-add design mode on mozilla
- if (!tinyMCE.isMSIE)
- TinyMCE.prototype.addEventHandlers(editor_id);
+ if (typeof(doc) == "undefined")
+ doc = document;
- // Add blur handler
- if (tinyMCE.isMSIE)
- tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE.prototype.eventPatch);
+ if (typeof(win) == "undefined")
+ win = window;
- // Trigger node change, this call locks buttons for tables and so forth
- tinyMCE.selectedInstance = inst;
- tinyMCE.selectedElement = inst.contentWindow.document.body;
+ iframe = doc.createElement("iframe");
- if (!inst.isHidden())
- tinyMCE.triggerNodeChange(false, true);
+ aw = "" + tinyMCE.settings.area_width;
+ ah = "" + tinyMCE.settings.area_height;
- // Call custom DOM cleanup
- tinyMCE._customCleanup(inst, "insert_to_editor_dom", inst.getBody());
- tinyMCE._customCleanup(inst, "setup_content_dom", inst.getBody());
- tinyMCE._setEventsEnabled(inst.getBody(), false);
- tinyMCE.cleanupAnchors(inst.getDoc());
+ if (aw.indexOf('%') == -1) {
+ aw = parseInt(aw);
+ aw = (isNaN(aw) || aw < 0) ? 300 : aw;
+ aw = aw + "px";
+ }
- if (tinyMCE.getParam("convert_fonts_to_spans"))
- tinyMCE.convertSpansToFonts(inst.getDoc());
+ if (ah.indexOf('%') == -1) {
+ ah = parseInt(ah);
+ ah = (isNaN(ah) || ah < 0) ? 240 : ah;
+ ah = ah + "px";
+ }
- inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);
- inst.undoLevels[inst.undoLevels.length] = inst.startContent;
+ iframe.setAttribute("id", id);
+ iframe.setAttribute("name", id);
+ iframe.setAttribute("class", "mceEditorIframe");
+ iframe.setAttribute("border", "0");
+ iframe.setAttribute("frameBorder", "0");
+ iframe.setAttribute("marginWidth", "0");
+ iframe.setAttribute("marginHeight", "0");
+ iframe.setAttribute("leftMargin", "0");
+ iframe.setAttribute("topMargin", "0");
+ iframe.setAttribute("width", aw);
+ iframe.setAttribute("height", ah);
+ iframe.setAttribute("allowtransparency", "true");
+ iframe.className = 'mceEditorIframe';
+
+ if (tinyMCE.settings.auto_resize)
+ iframe.setAttribute("scrolling", "no");
+
+ // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs
+ if (tinyMCE.isRealIE)
+ iframe.setAttribute("src", this.settings.default_document);
+
+ iframe.style.width = aw;
+ iframe.style.height = ah;
+
+ // Ugly hack for Gecko problem in strict mode
+ if (tinyMCE.settings.strict_loading_mode)
+ iframe.style.marginBottom = '-5px';
+
+ // MSIE 5.0 issue
+ if (tinyMCE.isRealIE)
+ replace_element.outerHTML = iframe.outerHTML;
+ else
+ replace_element.parentNode.replaceChild(iframe, replace_element);
- tinyMCE.operaOpacityCounter = -1;
-};
+ if (tinyMCE.isRealIE)
+ return win.frames[id];
+ else
+ return iframe;
+ },
+
+ setupContent : function(editor_id) {
+ var inst = tinyMCE.instances[editor_id], i, doc = inst.getDoc(), head = doc.getElementsByTagName('head').item(0);
+ var content = inst.startContent, contentElement, body;
+
+ // HTML values get XML encoded in strict mode
+ if (tinyMCE.settings.strict_loading_mode) {
+ content = content.replace(/</g, '<');
+ content = content.replace(/>/g, '>');
+ content = content.replace(/"/g, '"');
+ content = content.replace(/&/g, '&');
+ }
-TinyMCE.prototype.cleanupHTMLCode = function(s) {
- s = s.replace(/<p \/>/gi, '<p> </p>');
- s = s.replace(/<p>\s*<\/p>/gi, '<p> </p>');
+ tinyMCE.selectedInstance = inst;
+ inst.switchSettings();
- // Open closed tags like <b/> to <b></b>
-// tinyMCE.debug("f:" + s);
- s = s.replace(/<(h[1-6]|p|div|address|pre|form|table|li|ol|ul|td|b|em|strong|i|strike|u|span|a|ul|ol|li|blockquote)([a-z]*)([^\\|>]*?)\/>/gi, '<$1$2$3></$1$2>');
-// tinyMCE.debug("e:" + s);
+ // Not loaded correctly hit it again, Mozilla bug #997860
+ if (!tinyMCE.isIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") {
+ // This part will remove the designMode status
+ // Failes first time in Firefox 1.5b2 on Mac
+ try {doc.location.href = tinyMCE.baseURL + "/blank.htm";} catch (ex) {}
+ window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 1000);
+ return;
+ }
- // Remove trailing space <b > to <b>
- s = s.replace(new RegExp('\\s+></', 'gi'), '></');
+ // Wait for it to load
+ if (!head || !doc.body) {
+ window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10);
+ return;
+ }
- // Close tags <img></img> to <img/>
- s = s.replace(/<(img|br|hr)(.*?)><\/(img|br|hr)>/gi, '<$1$2 />');
+ // Import theme specific content CSS the user specific
+ tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/themes/" + inst.settings.theme + "/css/editor_content.css");
+ tinyMCE.importCSS(inst.getDoc(), inst.settings.content_css);
+ tinyMCE.dispatchCallback(inst, 'init_instance_callback', 'initInstance', inst);
- // Weird MSIE bug, <p><hr /></p> breaks runtime?
- if (tinyMCE.isMSIE)
- s = s.replace(/<p><hr \/><\/p>/gi, "<hr>");
+ // Setup keyboard shortcuts
+ if (tinyMCE.getParam('custom_undo_redo_keyboard_shortcuts')) {
+ inst.addShortcut('ctrl', 'z', 'lang_undo_desc', 'Undo');
+ inst.addShortcut('ctrl', 'y', 'lang_redo_desc', 'Redo');
+ }
- // Convert relative anchors to absolute URLs ex: #something to file.htm#something
- s = s.replace(new RegExp('(href=\"?)(\\s*?#)', 'gi'), '$1' + tinyMCE.settings['document_base_url'] + "#");
+ // BlockFormat shortcuts keys
+ for (i=1; i<=6; i++)
+ inst.addShortcut('ctrl', '' + i, '', 'FormatBlock', false, '<h' + i + '>');
- return s;
-};
+ inst.addShortcut('ctrl', '7', '', 'FormatBlock', false, '<p>');
+ inst.addShortcut('ctrl', '8', '', 'FormatBlock', false, '<div>');
+ inst.addShortcut('ctrl', '9', '', 'FormatBlock', false, '<address>');
-TinyMCE.prototype.storeAwayURLs = function(s) {
- // Remove all mce_src, mce_href and replace them with new ones
- s = s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
- s = s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
- s = s.replace(new RegExp('src\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'src="$1" mce_src="$1"');
- s = s.replace(new RegExp('href\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'href="$1" mce_href="$1"');
+ // Add default shortcuts for gecko
+ if (tinyMCE.isGecko) {
+ inst.addShortcut('ctrl', 'b', 'lang_bold_desc', 'Bold');
+ inst.addShortcut('ctrl', 'i', 'lang_italic_desc', 'Italic');
+ inst.addShortcut('ctrl', 'u', 'lang_underline_desc', 'Underline');
+ }
- return s;
-};
+ // Setup span styles
+ if (tinyMCE.getParam("convert_fonts_to_spans"))
+ inst.getBody().setAttribute('id', 'mceSpanFonts');
-TinyMCE.prototype.cancelEvent = function(e) {
- if (tinyMCE.isMSIE) {
- e.returnValue = false;
- e.cancelBubble = true;
- } else
- e.preventDefault();
-};
+ if (tinyMCE.settings.nowrap)
+ doc.body.style.whiteSpace = "nowrap";
-TinyMCE.prototype.removeTinyMCEFormElements = function(form_obj) {
- // Check if form is valid
- if (typeof(form_obj) == "undefined" || form_obj == null)
- return;
+ doc.body.dir = this.settings.directionality;
+ doc.editorId = editor_id;
- // If not a form, find the form
- if (form_obj.nodeName != "FORM") {
- if (form_obj.form)
- form_obj = form_obj.form;
- else
- form_obj = tinyMCE.getParentElement(form_obj, "form");
- }
+ // Add on document element in Mozilla
+ if (!tinyMCE.isIE)
+ doc.documentElement.editorId = editor_id;
- // Still nothing
- if (form_obj == null)
- return;
+ inst.setBaseHREF(tinyMCE.settings.base_href);
- // Disable all UI form elements that TinyMCE created
- for (var i=0; i<form_obj.elements.length; i++) {
- var elementId = form_obj.elements[i].name ? form_obj.elements[i].name : form_obj.elements[i].id;
+ // Replace new line characters to BRs
+ if (tinyMCE.settings.convert_newlines_to_brs) {
+ content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi");
+ content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi");
+ content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi");
+ }
- if (elementId.indexOf('mce_editor_') == 0)
- form_obj.elements[i].disabled = true;
- }
-};
+ // Open closed anchors
+ // content = content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
-TinyMCE.prototype.accessibleEventHandler = function(e) {
- var win = this._win;
- e = tinyMCE.isMSIE ? win.event : e;
- var elm = tinyMCE.isMSIE ? e.srcElement : e.target;
+ // Call custom cleanup code
+ content = tinyMCE.storeAwayURLs(content);
+ content = tinyMCE._customCleanup(inst, "insert_to_editor", content);
- // Piggyback onchange
- if (elm.nodeName == "SELECT" && !elm.oldonchange) {
- elm.oldonchange = elm.onchange;
- elm.onchange = null;
- }
+ if (tinyMCE.isIE) {
+ // Ugly!!!
+ window.setInterval('try{tinyMCE.getCSSClasses(tinyMCE.instances["' + editor_id + '"].getDoc(), "' + editor_id + '");}catch(e){}', 500);
- // Execute onchange and remove piggyback
- if (e.keyCode == 13 || e.keyCode == 32) {
- elm.onchange = elm.oldonchange;
- elm.onchange();
- elm.oldonchange = null;
- tinyMCE.cancelEvent(e);
- }
-};
+ if (tinyMCE.settings.force_br_newlines)
+ doc.styleSheets[0].addRule("p", "margin: 0;");
-TinyMCE.prototype.addSelectAccessibility = function(e, select, win) {
- // Add event handlers
- if (!select._isAccessible) {
- select.onkeydown = tinyMCE.accessibleEventHandler;
- select._isAccessible = true;
- select._win = win;
- }
-};
+ body = inst.getBody();
+ body.editorId = editor_id;
+ }
-TinyMCE.prototype.handleEvent = function(e) {
- // Remove odd, error
- if (typeof(tinyMCE) == "undefined")
- return true;
+ content = tinyMCE.cleanupHTMLCode(content);
- //tinyMCE.debug(e.type + " " + e.target.nodeName + " " + (e.relatedTarget ? e.relatedTarget.nodeName : ""));
+ // Fix for bug #958637
+ if (!tinyMCE.isIE) {
+ contentElement = inst.getDoc().createElement("body");
+ doc = inst.getDoc();
- switch (e.type) {
- case "blur":
- if (tinyMCE.selectedInstance)
- tinyMCE.selectedInstance.execCommand('mceEndTyping');
+ contentElement.innerHTML = content;
- return;
+ if (tinyMCE.settings.cleanup_on_startup)
+ tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement));
+ else
+ tinyMCE.setInnerHTML(inst.getBody(), content);
- case "submit":
- tinyMCE.removeTinyMCEFormElements(tinyMCE.isMSIE ? window.event.srcElement : e.target);
- tinyMCE.triggerSave();
- tinyMCE.isNotDirty = true;
- return;
+ tinyMCE.convertAllRelativeURLs(inst.getBody());
+ } else {
+ if (tinyMCE.settings.cleanup_on_startup) {
+ tinyMCE._setHTML(inst.getDoc(), content);
- case "reset":
- var formObj = tinyMCE.isMSIE ? window.event.srcElement : e.target;
+ // Produces permission denied error in MSIE 5.5
+ try {
+ tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody()));
+ } catch(e) {
+ // Ignore
+ }
+ } else
+ tinyMCE._setHTML(inst.getDoc(), content);
+ }
- for (var i=0; i<document.forms.length; i++) {
- if (document.forms[i] == formObj)
- window.setTimeout('tinyMCE.resetForm(' + i + ');', 10);
- }
+ // Fix for bug #957681
+ //inst.getDoc().designMode = inst.getDoc().designMode;
- return;
+ tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings.visual, inst);
+ tinyMCE.dispatchCallback(inst, 'setupcontent_callback', 'setupContent', editor_id, inst.getBody(), inst.getDoc());
- case "keypress":
- if (e.target.editorId) {
- tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];
- } else {
- if (e.target.ownerDocument.editorId)
- tinyMCE.selectedInstance = tinyMCE.instances[e.target.ownerDocument.editorId];
+ // Re-add design mode on mozilla
+ if (!tinyMCE.isIE)
+ tinyMCE.addEventHandlers(inst);
+
+ // Add blur handler
+ if (tinyMCE.isIE) {
+ tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE_Engine.prototype._eventPatch);
+ tinyMCE.addEvent(inst.getBody(), "beforedeactivate", TinyMCE_Engine.prototype._eventPatch); // Bug #1439953
+
+ // Workaround for drag drop/copy paste base href bug
+ if (!tinyMCE.isOpera) {
+ tinyMCE.addEvent(doc.body, "mousemove", TinyMCE_Engine.prototype.onMouseMove);
+ tinyMCE.addEvent(doc.body, "beforepaste", TinyMCE_Engine.prototype._eventPatch);
+ tinyMCE.addEvent(doc.body, "drop", TinyMCE_Engine.prototype._eventPatch);
}
+ }
- if (tinyMCE.selectedInstance)
- tinyMCE.selectedInstance.switchSettings();
+ // Trigger node change, this call locks buttons for tables and so forth
+ inst.select();
+ tinyMCE.selectedElement = inst.contentWindow.document.body;
- // Insert space instead of
-/* if (tinyMCE.isGecko && e.charCode == 32) {
- if (tinyMCE.selectedInstance._insertSpace()) {
- // Cancel event
- e.preventDefault();
- return false;
- }
- }*/
+ // Call custom DOM cleanup
+ tinyMCE._customCleanup(inst, "insert_to_editor_dom", inst.getBody());
+ tinyMCE._customCleanup(inst, "setup_content_dom", inst.getBody());
+ tinyMCE._setEventsEnabled(inst.getBody(), false);
+ tinyMCE.cleanupAnchors(inst.getDoc());
- // Insert P element
- if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && e.keyCode == 13 && !e.shiftKey) {
- // Insert P element instead of BR
- if (tinyMCE.selectedInstance._insertPara(e)) {
- // Cancel event
- tinyMCE.execCommand("mceAddUndoLevel");
- tinyMCE.cancelEvent(e);
- return false;
- }
- }
+ if (tinyMCE.getParam("convert_fonts_to_spans"))
+ tinyMCE.convertSpansToFonts(inst.getDoc());
- // Handle backspace
- if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
- // Insert P element instead of BR
- if (tinyMCE.selectedInstance._handleBackSpace(e.type)) {
- // Cancel event
- tinyMCE.execCommand("mceAddUndoLevel");
- tinyMCE.cancelEvent(e);
- return false;
- }
- }
+ inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);
+ inst.undoRedo.add({ content : inst.startContent });
- // Mozilla custom key handling
- if (tinyMCE.isGecko && (e.ctrlKey && !e.altKey) && tinyMCE.settings['custom_undo_redo']) {
- if (tinyMCE.settings['custom_undo_redo_keyboard_shortcuts']) {
- if (e.charCode == 122) { // Ctrl+Z
- tinyMCE.selectedInstance.execCommand("Undo");
- tinyMCE.cancelEvent(e);
- return false;
- }
+ // Cleanup any mess left from storyAwayURLs
+ if (tinyMCE.isGecko) {
+ // Remove mce_src from textnodes and comments
+ tinyMCE.selectNodes(inst.getBody(), function(n) {
+ if (n.nodeType == 3 || n.nodeType == 8)
+ n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), "");
- if (e.charCode == 121) { // Ctrl+Y
- tinyMCE.selectedInstance.execCommand("Redo");
- tinyMCE.cancelEvent(e);
- return false;
- }
- }
+ return false;
+ });
+ }
- if (e.charCode == 98) { // Ctrl+B
- tinyMCE.selectedInstance.execCommand("Bold");
- tinyMCE.cancelEvent(e);
- return false;
- }
+ // Remove Gecko spellchecking
+ if (tinyMCE.isGecko)
+ inst.getBody().spellcheck = tinyMCE.getParam("gecko_spellcheck");
- if (e.charCode == 105) { // Ctrl+I
- tinyMCE.selectedInstance.execCommand("Italic");
- tinyMCE.cancelEvent(e);
- return false;
- }
+ // Cleanup any mess left from storyAwayURLs
+ tinyMCE._removeInternal(inst.getBody());
- if (e.charCode == 117) { // Ctrl+U
- tinyMCE.selectedInstance.execCommand("Underline");
- tinyMCE.cancelEvent(e);
- return false;
- }
+ inst.select();
+ tinyMCE.triggerNodeChange(false, true);
+ },
- if (e.charCode == 118) { // Ctrl+V
- tinyMCE.selectedInstance.execCommand("mceInsertContent", false, '<geckopastefix/>');
- }
- }
+ storeAwayURLs : function(s) {
+ // Remove all mce_src, mce_href and replace them with new ones
+ // s = s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
+ // s = s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
- // Return key pressed
- if (tinyMCE.isMSIE && tinyMCE.settings['force_br_newlines'] && e.keyCode == 13) {
- if (e.target.editorId)
- tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];
+ if (!s.match(/(mce_src|mce_href)/gi, s)) {
+ s = s.replace(new RegExp('src\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'src="$1" mce_src="$1"');
+ s = s.replace(new RegExp('href\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'href="$1" mce_href="$1"');
+ }
- if (tinyMCE.selectedInstance) {
- var sel = tinyMCE.selectedInstance.getDoc().selection;
- var rng = sel.createRange();
+ return s;
+ },
- if (tinyMCE.getParentElement(rng.parentElement(), "li") != null)
- return false;
+ _removeInternal : function(n) {
+ if (tinyMCE.isGecko) {
+ // Remove mce_src from textnodes and comments
+ tinyMCE.selectNodes(n, function(n) {
+ if (n.nodeType == 3 || n.nodeType == 8)
+ n.nodeValue = n.nodeValue.replace(new RegExp('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), "");
- // Cancel event
- e.returnValue = false;
- e.cancelBubble = true;
+ return false;
+ });
+ }
+ },
- // Insert BR element
- rng.pasteHTML("<br />");
- rng.collapse(false);
- rng.select();
+ removeTinyMCEFormElements : function(form_obj) {
+ var i, elementId;
- tinyMCE.execCommand("mceAddUndoLevel");
- tinyMCE.triggerNodeChange(false);
- return false;
- }
- }
+ // Skip form element removal
+ if (!tinyMCE.getParam('hide_selects_on_submit'))
+ return;
- // Backspace or delete
- if (e.keyCode == 8 || e.keyCode == 46) {
- tinyMCE.selectedElement = e.target;
- tinyMCE.linkElement = tinyMCE.getParentElement(e.target, "a");
- tinyMCE.imgElement = tinyMCE.getParentElement(e.target, "img");
- tinyMCE.triggerNodeChange(false);
- }
+ // Check if form is valid
+ if (typeof(form_obj) == "undefined" || form_obj == null)
+ return;
+
+ // If not a form, find the form
+ if (form_obj.nodeName != "FORM") {
+ if (form_obj.form)
+ form_obj = form_obj.form;
+ else
+ form_obj = tinyMCE.getParentElement(form_obj, "form");
+ }
+
+ // Still nothing
+ if (form_obj == null)
+ return;
+
+ // Disable all UI form elements that TinyMCE created
+ for (i=0; i<form_obj.elements.length; i++) {
+ elementId = form_obj.elements[i].name ? form_obj.elements[i].name : form_obj.elements[i].id;
+
+ if (elementId.indexOf('mce_editor_') == 0)
+ form_obj.elements[i].disabled = true;
+ }
+ },
+
+ handleEvent : function(e) {
+ var inst = tinyMCE.selectedInstance, i, elm, keys;
+ // Remove odd, error
+ if (typeof(tinyMCE) == "undefined")
+ return true;
+
+ //tinyMCE.debug(e.type + " " + e.target.nodeName + " " + (e.relatedTarget ? e.relatedTarget.nodeName : ""));
+
+ if (tinyMCE.executeCallback(tinyMCE.selectedInstance, 'handle_event_callback', 'handleEvent', e))
return false;
- break;
- case "keyup":
- case "keydown":
- if (e.target.editorId)
- tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];
- else
- return;
+ switch (e.type) {
+ case "beforedeactivate": // Was added due to bug #1439953
+ case "blur":
+ if (tinyMCE.selectedInstance)
+ tinyMCE.selectedInstance.execCommand('mceEndTyping');
- if (tinyMCE.selectedInstance)
- tinyMCE.selectedInstance.switchSettings();
+ tinyMCE.hideMenus();
- var inst = tinyMCE.selectedInstance;
+ return;
- // Handle backspace
- if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
- // Insert P element instead of BR
- if (tinyMCE.selectedInstance._handleBackSpace(e.type)) {
- // Cancel event
- tinyMCE.execCommand("mceAddUndoLevel");
- e.preventDefault();
- return false;
+ // Workaround for drag drop/copy paste base href bug
+ case "drop":
+ case "beforepaste":
+ if (tinyMCE.selectedInstance)
+ tinyMCE.selectedInstance.setBaseHREF(null);
+
+ // Fixes odd MSIE bug where drag/droping elements in a iframe with height 100% breaks
+ // This logic forces the width/height to be in pixels while the user is drag/dropping
+ if (tinyMCE.isRealIE) {
+ var ife = tinyMCE.selectedInstance.iframeElement;
+
+ /*if (ife.style.width.indexOf('%') != -1) {
+ ife._oldWidth = ife.width.height;
+ ife.style.width = ife.clientWidth;
+ }*/
+
+ if (ife.style.height.indexOf('%') != -1) {
+ ife._oldHeight = ife.style.height;
+ ife.style.height = ife.clientHeight;
+ }
}
- }
- tinyMCE.selectedElement = null;
- tinyMCE.selectedNode = null;
- var elm = tinyMCE.selectedInstance.getFocusElement();
- tinyMCE.linkElement = tinyMCE.getParentElement(elm, "a");
- tinyMCE.imgElement = tinyMCE.getParentElement(elm, "img");
- tinyMCE.selectedElement = elm;
-
- // Update visualaids on tabs
- if (tinyMCE.isGecko && e.type == "keyup" && e.keyCode == 9)
- tinyMCE.handleVisualAid(tinyMCE.selectedInstance.getBody(), true, tinyMCE.settings['visual'], tinyMCE.selectedInstance);
-
- // Fix empty elements on return/enter, check where enter occured
- if (tinyMCE.isMSIE && e.type == "keydown" && e.keyCode == 13)
- tinyMCE.enterKeyElement = tinyMCE.selectedInstance.getFocusElement();
-
- // Fix empty elements on return/enter
- if (tinyMCE.isMSIE && e.type == "keyup" && e.keyCode == 13) {
- var elm = tinyMCE.enterKeyElement;
- if (elm) {
- var re = new RegExp('^HR|IMG|BR$','g'); // Skip these
- var dre = new RegExp('^H[1-6]$','g'); // Add double on these
-
- if (!elm.hasChildNodes() && !re.test(elm.nodeName)) {
- if (dre.test(elm.nodeName))
- elm.innerHTML = " ";
- else
- elm.innerHTML = " ";
- }
+ window.setTimeout("tinyMCE.selectedInstance.setBaseHREF(tinyMCE.settings.base_href);tinyMCE._resetIframeHeight();", 1);
+ return;
+
+ case "submit":
+ tinyMCE.formSubmit(tinyMCE.isMSIE ? window.event.srcElement : e.target);
+ return;
+
+ case "reset":
+ var formObj = tinyMCE.isIE ? window.event.srcElement : e.target;
+
+ for (i=0; i<document.forms.length; i++) {
+ if (document.forms[i] == formObj)
+ window.setTimeout('tinyMCE.resetForm(' + i + ');', 10);
}
- }
- // Check if it's a position key
- var keys = tinyMCE.posKeyCodes;
- var posKey = false;
- for (var i=0; i<keys.length; i++) {
- if (keys[i] == e.keyCode) {
- posKey = true;
- break;
+ return;
+
+ case "keypress":
+ if (inst && inst.handleShortcut(e))
+ return false;
+
+ if (e.target.editorId) {
+ tinyMCE.instances[e.target.editorId].select();
+ } else {
+ if (e.target.ownerDocument.editorId)
+ tinyMCE.instances[e.target.ownerDocument.editorId].select();
}
- }
- // MSIE custom key handling
- if (tinyMCE.isMSIE && tinyMCE.settings['custom_undo_redo']) {
- var keys = new Array(8,46); // Backspace,Delete
- for (var i=0; i<keys.length; i++) {
- if (keys[i] == e.keyCode) {
- if (e.type == "keyup")
- tinyMCE.triggerNodeChange(false);
+ if (tinyMCE.selectedInstance)
+ tinyMCE.selectedInstance.switchSettings();
+
+ // Insert P element
+ if ((tinyMCE.isGecko || tinyMCE.isOpera || tinyMCE.isSafari) && tinyMCE.settings.force_p_newlines && e.keyCode == 13 && !e.shiftKey) {
+ // Insert P element instead of BR
+ if (TinyMCE_ForceParagraphs._insertPara(tinyMCE.selectedInstance, e)) {
+ // Cancel event
+ tinyMCE.execCommand("mceAddUndoLevel");
+ return tinyMCE.cancelEvent(e);
}
}
- if (tinyMCE.settings['custom_undo_redo_keyboard_shortcuts']) {
- if (e.keyCode == 90 && (e.ctrlKey && !e.altKey) && e.type == "keydown") { // Ctrl+Z
- tinyMCE.selectedInstance.execCommand("Undo");
- tinyMCE.triggerNodeChange(false);
+ // Handle backspace
+ if ((tinyMCE.isGecko && !tinyMCE.isSafari) && tinyMCE.settings.force_p_newlines && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
+ // Insert P element instead of BR
+ if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) {
+ // Cancel event
+ tinyMCE.execCommand("mceAddUndoLevel");
+ return tinyMCE.cancelEvent(e);
}
+ }
- if (e.keyCode == 89 && (e.ctrlKey && !e.altKey) && e.type == "keydown") { // Ctrl+Y
- tinyMCE.selectedInstance.execCommand("Redo");
- tinyMCE.triggerNodeChange(false);
- }
+ // Return key pressed
+ if (tinyMCE.isIE && tinyMCE.settings.force_br_newlines && e.keyCode == 13) {
+ if (e.target.editorId)
+ tinyMCE.instances[e.target.editorId].select();
+
+ if (tinyMCE.selectedInstance) {
+ var sel = tinyMCE.selectedInstance.getDoc().selection;
+ var rng = sel.createRange();
+
+ if (tinyMCE.getParentElement(rng.parentElement(), "li") != null)
+ return false;
- if ((e.keyCode == 90 || e.keyCode == 89) && (e.ctrlKey && !e.altKey)) {
// Cancel event
e.returnValue = false;
e.cancelBubble = true;
+
+ // Insert BR element
+ rng.pasteHTML("<br />");
+ rng.collapse(false);
+ rng.select();
+
+ tinyMCE.execCommand("mceAddUndoLevel");
+ tinyMCE.triggerNodeChange(false);
return false;
}
}
- }
- // If undo/redo key
- if ((e.keyCode == 90 || e.keyCode == 89) && (e.ctrlKey && !e.altKey))
- return true;
+ // Backspace or delete
+ if (e.keyCode == 8 || e.keyCode == 46) {
+ tinyMCE.selectedElement = e.target;
+ tinyMCE.linkElement = tinyMCE.getParentElement(e.target, "a");
+ tinyMCE.imgElement = tinyMCE.getParentElement(e.target, "img");
+ tinyMCE.triggerNodeChange(false);
+ }
- // If Ctrl key
- if (e.keyCode == 17)
- return true;
+ return false;
- // Handle Undo/Redo when typing content
+ case "keyup":
+ case "keydown":
+ tinyMCE.hideMenus();
+ tinyMCE.hasMouseMoved = false;
- // Start typing (non position key)
- if (!posKey && e.type == "keyup")
- tinyMCE.execCommand("mceStartTyping");
+ if (inst && inst.handleShortcut(e))
+ return false;
- // End typing (position key) or some Ctrl event
- if (e.type == "keyup" && (posKey || e.ctrlKey))
- tinyMCE.execCommand("mceEndTyping");
+ inst._fixRootBlocks();
- if (posKey && e.type == "keyup")
- tinyMCE.triggerNodeChange(false);
+ if (inst.settings.remove_trailing_nbsp)
+ inst._fixTrailingNbsp();
- if (tinyMCE.isMSIE && e.ctrlKey)
- window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
- break;
-
- case "mousedown":
- case "mouseup":
- case "click":
- case "focus":
- if (tinyMCE.selectedInstance)
- tinyMCE.selectedInstance.switchSettings();
-
- // Check instance event trigged on
- var targetBody = tinyMCE.getParentElement(e.target, "body");
- for (var instanceName in tinyMCE.instances) {
- if (!tinyMCE.isInstance(tinyMCE.instances[instanceName]))
- continue;
+ if (e.target.editorId)
+ tinyMCE.instances[e.target.editorId].select();
- var inst = tinyMCE.instances[instanceName];
+ if (tinyMCE.selectedInstance)
+ tinyMCE.selectedInstance.switchSettings();
- // Reset design mode if lost (on everything just in case)
- inst.autoResetDesignMode();
+ inst = tinyMCE.selectedInstance;
- if (inst.getBody() == targetBody) {
- tinyMCE.selectedInstance = inst;
- tinyMCE.selectedElement = e.target;
- tinyMCE.linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");
- tinyMCE.imgElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "img");
- break;
+ // Handle backspace
+ if (tinyMCE.isGecko && tinyMCE.settings.force_p_newlines && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
+ // Insert P element instead of BR
+ if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) {
+ // Cancel event
+ tinyMCE.execCommand("mceAddUndoLevel");
+ e.preventDefault();
+ return false;
+ }
}
- }
-
- if (tinyMCE.isSafari) {
- tinyMCE.selectedInstance.lastSafariSelection = tinyMCE.selectedInstance.getBookmark();
- tinyMCE.selectedInstance.lastSafariSelectedElement = tinyMCE.selectedElement;
- var lnk = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");
+ tinyMCE.selectedElement = null;
+ tinyMCE.selectedNode = null;
+ elm = tinyMCE.selectedInstance.getFocusElement();
+ tinyMCE.linkElement = tinyMCE.getParentElement(elm, "a");
+ tinyMCE.imgElement = tinyMCE.getParentElement(elm, "img");
+ tinyMCE.selectedElement = elm;
+
+ // Update visualaids on tabs
+ if (tinyMCE.isGecko && e.type == "keyup" && e.keyCode == 9)
+ tinyMCE.handleVisualAid(tinyMCE.selectedInstance.getBody(), true, tinyMCE.settings.visual, tinyMCE.selectedInstance);
+
+ // Fix empty elements on return/enter, check where enter occured
+ if (tinyMCE.isIE && e.type == "keydown" && e.keyCode == 13)
+ tinyMCE.enterKeyElement = tinyMCE.selectedInstance.getFocusElement();
+
+ // Fix empty elements on return/enter
+ if (tinyMCE.isIE && e.type == "keyup" && e.keyCode == 13) {
+ elm = tinyMCE.enterKeyElement;
+ if (elm) {
+ var re = new RegExp('^HR|IMG|BR$','g'); // Skip these
+ var dre = new RegExp('^H[1-6]$','g'); // Add double on these
+
+ if (!elm.hasChildNodes() && !re.test(elm.nodeName)) {
+ if (dre.test(elm.nodeName))
+ elm.innerHTML = " ";
+ else
+ elm.innerHTML = " ";
+ }
+ }
+ }
- // Patch the darned link
- if (lnk && e.type == "mousedown") {
- lnk.setAttribute("mce_real_href", lnk.getAttribute("href"));
- lnk.setAttribute("href", "javascript:void(0);");
+ // Check if it's a position key
+ keys = tinyMCE.posKeyCodes;
+ var posKey = false;
+ for (i=0; i<keys.length; i++) {
+ if (keys[i] == e.keyCode) {
+ posKey = true;
+ break;
+ }
}
- // Patch back
- if (lnk && e.type == "click") {
- window.setTimeout(function() {
- lnk.setAttribute("href", lnk.getAttribute("mce_real_href"));
- lnk.removeAttribute("mce_real_href");
- }, 10);
+ // MSIE custom key handling
+ if (tinyMCE.isIE && tinyMCE.settings.custom_undo_redo) {
+ keys = [8, 46]; // Backspace,Delete
+
+ for (i=0; i<keys.length; i++) {
+ if (keys[i] == e.keyCode) {
+ if (e.type == "keyup")
+ tinyMCE.triggerNodeChange(false);
+ }
+ }
}
- }
- // Reset selected node
- if (e.type != "focus")
- tinyMCE.selectedNode = null;
+ // If Ctrl key
+ if (e.keyCode == 17)
+ return true;
- tinyMCE.triggerNodeChange(false);
- tinyMCE.execCommand("mceEndTyping");
+ // Handle Undo/Redo when typing content
- if (e.type == "mouseup")
- tinyMCE.execCommand("mceAddUndoLevel");
+ if (tinyMCE.isGecko) {
+ // Start typing (not a position key or ctrl key, but ctrl+x and ctrl+p is ok)
+ if (!posKey && e.type == "keyup" && !e.ctrlKey || (e.ctrlKey && (e.keyCode == 86 || e.keyCode == 88)))
+ tinyMCE.execCommand("mceStartTyping");
+ } else {
+ // IE seems to be working better with this setting
+ if (!posKey && e.type == "keyup")
+ tinyMCE.execCommand("mceStartTyping");
+ }
- // Just in case
- if (!tinyMCE.selectedInstance && e.target.editorId)
- tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];
+ // Store undo bookmark
+ if (e.type == "keydown" && (posKey || e.ctrlKey) && inst)
+ inst.undoBookmark = inst.selection.getBookmark();
- return false;
- break;
- } // end switch
-}; // end function
+ // End typing (position key) or some Ctrl event
+ if (e.type == "keyup" && (posKey || e.ctrlKey))
+ tinyMCE.execCommand("mceEndTyping");
-TinyMCE.prototype.switchClass = function(element, class_name, lock_state) {
- var lockChanged = false;
+ if (posKey && e.type == "keyup")
+ tinyMCE.triggerNodeChange(false);
- if (typeof(lock_state) != "undefined" && element != null) {
- element.classLock = lock_state;
- lockChanged = true;
- }
+ if (tinyMCE.isIE && e.ctrlKey)
+ window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
+ break;
- if (element != null && (lockChanged || !element.classLock)) {
- element.oldClassName = element.className;
- element.className = class_name;
- }
-};
+ case "mousedown":
+ case "mouseup":
+ case "click":
+ case "dblclick":
+ case "focus":
+ tinyMCE.hideMenus();
-TinyMCE.prototype.restoreAndSwitchClass = function(element, class_name) {
- if (element != null && !element.classLock) {
- this.restoreClass(element);
- this.switchClass(element, class_name);
- }
-};
+ if (tinyMCE.selectedInstance) {
+ tinyMCE.selectedInstance.switchSettings();
+ tinyMCE.selectedInstance.isFocused = true;
+ }
+
+ // Check instance event trigged on
+ var targetBody = tinyMCE.getParentElement(e.target, "html");
+ for (var instanceName in tinyMCE.instances) {
+ if (!tinyMCE.isInstance(tinyMCE.instances[instanceName]))
+ continue;
-TinyMCE.prototype.switchClassSticky = function(element_name, class_name, lock_state) {
- var element, lockChanged = false;
+ inst = tinyMCE.instances[instanceName];
- // Performance issue
- if (!this.stickyClassesLookup[element_name])
- this.stickyClassesLookup[element_name] = document.getElementById(element_name);
+ // Reset design mode if lost (on everything just in case)
+ inst.autoResetDesignMode();
-// element = document.getElementById(element_name);
- element = this.stickyClassesLookup[element_name];
+ // Use HTML element since users might click outside of body element
+ if (inst.getBody().parentNode == targetBody) {
+ inst.select();
+ tinyMCE.selectedElement = e.target;
+ tinyMCE.linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");
+ tinyMCE.imgElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "img");
+ break;
+ }
+ }
- if (typeof(lock_state) != "undefined" && element != null) {
- element.classLock = lock_state;
- lockChanged = true;
- }
+ // Add first bookmark location
+ if (!tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark && (e.type == "mouseup" || e.type == "dblclick"))
+ tinyMCE.selectedInstance.undoRedo.undoLevels[0].bookmark = tinyMCE.selectedInstance.selection.getBookmark();
- if (element != null && (lockChanged || !element.classLock)) {
- element.className = class_name;
- element.oldClassName = class_name;
+ // Reset selected node
+ if (e.type != "focus")
+ tinyMCE.selectedNode = null;
- // Fix opacity in Opera
- if (tinyMCE.isOpera) {
- if (class_name == "mceButtonDisabled") {
- var suffix = "";
+ tinyMCE.triggerNodeChange(false);
+ tinyMCE.execCommand("mceEndTyping");
- if (!element.mceOldSrc)
- element.mceOldSrc = element.src;
+ if (e.type == "mouseup")
+ tinyMCE.execCommand("mceAddUndoLevel");
- if (this.operaOpacityCounter > -1)
- suffix = '?rnd=' + this.operaOpacityCounter++;
+ // Just in case
+ if (!tinyMCE.selectedInstance && e.target.editorId)
+ tinyMCE.instances[e.target.editorId].select();
- element.src = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/images/opacity.png" + suffix;
- element.style.backgroundImage = "url('" + element.mceOldSrc + "')";
- } else {
- if (element.mceOldSrc) {
- element.src = element.mceOldSrc;
- element.parentNode.style.backgroundImage = "";
- element.mceOldSrc = null;
- }
- }
+ return false;
}
- }
-};
+ },
-TinyMCE.prototype.restoreClass = function(element) {
- if (element != null && element.oldClassName && !element.classLock) {
- element.className = element.oldClassName;
- element.oldClassName = null;
- }
-};
+ getButtonHTML : function(id, lang, img, cmd, ui, val) {
+ var h = '', m, x, io = '';
-TinyMCE.prototype.setClassLock = function(element, lock_state) {
- if (element != null)
- element.classLock = lock_state;
-};
+ cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\'';
-TinyMCE.prototype.addEvent = function(obj, name, handler) {
- if (tinyMCE.isMSIE) {
- obj.attachEvent("on" + name, handler);
- } else
- obj.addEventListener(name, handler, false);
-};
+ if (typeof(ui) != "undefined" && ui != null)
+ cmd += ',' + ui;
-TinyMCE.prototype.submitPatch = function() {
- tinyMCE.removeTinyMCEFormElements(this);
- tinyMCE.triggerSave();
- this.mceOldSubmit();
- tinyMCE.isNotDirty = true;
-};
+ if (typeof(val) != "undefined" && val != null)
+ cmd += ",'" + val + "'";
-TinyMCE.prototype.onLoad = function() {
- for (var c=0; c<tinyMCE.configs.length; c++) {
- tinyMCE.settings = tinyMCE.configs[c];
+ cmd += ');';
- var selector = tinyMCE.getParam("editor_selector");
- var deselector = tinyMCE.getParam("editor_deselector");
- var elementRefAr = new Array();
+ // Patch for IE7 bug with hover out not restoring correctly
+ if (tinyMCE.isRealIE)
+ io = 'onmouseover="tinyMCE.lastHover = this;"';
- // Add submit triggers
- if (document.forms && tinyMCE.settings['add_form_submit_trigger'] && !tinyMCE.submitTriggers) {
- for (var i=0; i<document.forms.length; i++) {
- var form = document.forms[i];
+ // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled
+ if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = this.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) {
+ // Tiled button
+ x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20);
+ h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceTiledButton mceButtonNormal" target="_self">';
+ h += '<img src="{$themeurl}/images/spacer.gif" style="background-position: ' + x + 'px 0" alt="{$'+lang+'}" title="{$' + lang + '}" />';
+ h += '</a>';
+ } else {
+ // Normal button
+ h += '<a id="{$editor_id}_' + id + '" href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" ' + io + ' class="mceButtonNormal" target="_self">';
+ h += '<img src="' + img + '" alt="{$'+lang+'}" title="{$' + lang + '}" />';
+ h += '</a>';
+ }
- tinyMCE.addEvent(form, "submit", TinyMCE.prototype.handleEvent);
- tinyMCE.addEvent(form, "reset", TinyMCE.prototype.handleEvent);
- tinyMCE.submitTriggers = true; // Do it only once
+ return h;
+ },
- // Patch the form.submit function
- if (tinyMCE.settings['submit_patch']) {
- try {
- form.mceOldSubmit = form.submit;
- form.submit = TinyMCE.prototype.submitPatch;
- } catch (e) {
- // Do nothing
- }
- }
- }
- }
+ getMenuButtonHTML : function(id, lang, img, mcmd, cmd, ui, val) {
+ var h = '', m, x;
- // Add editor instances based on mode
- var mode = tinyMCE.settings['mode'];
- switch (mode) {
- case "exact":
- var elements = tinyMCE.getParam('elements', '', true, ',');
+ mcmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + mcmd + '\');';
+ cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'' + cmd + '\'';
- for (var i=0; i<elements.length; i++) {
- var element = tinyMCE._getElementById(elements[i]);
- var trigger = element ? element.getAttribute(tinyMCE.settings['textarea_trigger']) : "";
+ if (typeof(ui) != "undefined" && ui != null)
+ cmd += ',' + ui;
- if (tinyMCE.getAttrib(element, "class").indexOf(deselector) != -1)
- continue;
+ if (typeof(val) != "undefined" && val != null)
+ cmd += ",'" + val + "'";
- if (trigger == "false")
- continue;
+ cmd += ');';
- if (tinyMCE.settings['ask'] && element) {
- elementRefAr[elementRefAr.length] = element;
- continue;
- }
+ // Use tilemaps when enabled and found and never in MSIE since it loads the tile each time from cache if cahce is disabled
+ if (tinyMCE.getParam('button_tile_map') && (!tinyMCE.isIE || tinyMCE.isOpera) && (m = tinyMCE.buttonMap[id]) != null && (tinyMCE.getParam("language") == "en" || img.indexOf('$lang') == -1)) {
+ x = 0 - (m * 20) == 0 ? '0' : 0 - (m * 20);
- if (element)
- tinyMCE.addMCEControl(element, elements[i]);
- else if (tinyMCE.settings['debug'])
- alert("Error: Could not find element by id or name: " + elements[i]);
- }
- break;
+ if (tinyMCE.isRealIE)
+ h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">';
+ else
+ h += '<span id="{$editor_id}_' + id + '" class="mceMenuButton">';
- case "specific_textareas":
- case "textareas":
- var nodeList = document.getElementsByTagName("textarea");
+ h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceTiledButton mceMenuButtonNormal" target="_self">';
+ h += '<img src="{$themeurl}/images/spacer.gif" style="width: 20px; height: 20px; background-position: ' + x + 'px 0" title="{$' + lang + '}" /></a>';
+ h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />';
+ h += '</a></span>';
+ } else {
+ if (tinyMCE.isRealIE)
+ h += '<span id="{$editor_id}_' + id + '" dir="ltr" class="mceMenuButton" onmouseover="tinyMCE._menuButtonEvent(\'over\',this);tinyMCE.lastHover = this;" onmouseout="tinyMCE._menuButtonEvent(\'out\',this);">';
+ else
+ h += '<span id="{$editor_id}_' + id + '" dir="ltr" class="mceMenuButton">';
- for (var i=0; i<nodeList.length; i++) {
- var elm = nodeList.item(i);
- var trigger = elm.getAttribute(tinyMCE.settings['textarea_trigger']);
+ h += '<a href="javascript:' + cmd + '" onclick="' + cmd + 'return false;" onmousedown="return false;" class="mceMenuButtonNormal" target="_self">';
+ h += '<img src="' + img + '" title="{$' + lang + '}" /></a>';
+ h += '<a href="javascript:' + mcmd + '" onclick="' + mcmd + 'return false;" onmousedown="return false;"><img src="{$themeurl}/images/button_menu.gif" title="{$' + lang + '}" class="mceMenuButton" />';
+ h += '</a></span>';
+ }
- if (selector != '' && tinyMCE.getAttrib(elm, "class").indexOf(selector) == -1)
- continue;
+ return h;
+ },
- if (selector != '')
- trigger = selector != "" ? "true" : "";
+ _menuButtonEvent : function(e, o) {
+ if (o.className == 'mceMenuButtonFocus')
+ return;
- if (tinyMCE.getAttrib(elm, "class").indexOf(deselector) != -1)
- continue;
+ if (e == 'over')
+ o.className = o.className + ' mceMenuHover';
+ else
+ o.className = o.className.replace(/\s.*$/, '');
+ },
- if ((mode == "specific_textareas" && trigger == "true") || (mode == "textareas" && trigger != "false"))
- elementRefAr[elementRefAr.length] = elm;
- }
- break;
- }
+ addButtonMap : function(m) {
+ var i, a = m.replace(/\s+/, '').split(',');
- for (var i=0; i<elementRefAr.length; i++) {
- var element = elementRefAr[i];
- var elementId = element.name ? element.name : element.id;
+ for (i=0; i<a.length; i++)
+ this.buttonMap[a[i]] = i;
+ },
- if (tinyMCE.settings['ask']) {
- // Focus breaks in Mozilla
- if (tinyMCE.isGecko) {
- var settings = tinyMCE.settings;
+ formSubmit : function(f, p) {
+ var n, inst, found = false;
- tinyMCE.addEvent(element, "focus", function (e) {window.setTimeout(function() {TinyMCE.prototype.confirmAdd(e, settings);}, 10);});
- } else {
- var settings = tinyMCE.settings;
+ if (f.form)
+ f = f.form;
- tinyMCE.addEvent(element, "focus", function () { TinyMCE.prototype.confirmAdd(null, settings); });
+ // Is it a form that has a TinyMCE instance
+ for (n in tinyMCE.instances) {
+ inst = tinyMCE.instances[n];
+
+ if (!tinyMCE.isInstance(inst))
+ continue;
+
+ if (inst.formElement) {
+ if (f == inst.formElement.form) {
+ found = true;
+ inst.isNotDirty = true;
}
- } else
- tinyMCE.addMCEControl(element, elementId);
+ }
}
- // Handle auto focus
- if (tinyMCE.settings['auto_focus']) {
- window.setTimeout(function () {
- var inst = tinyMCE.getInstanceById(tinyMCE.settings['auto_focus']);
- inst.selectNode(inst.getBody(), true, true);
- inst.contentWindow.focus();
- }, 10);
+ // Is valid
+ if (found) {
+ tinyMCE.removeTinyMCEFormElements(f);
+ tinyMCE.triggerSave();
}
- tinyMCE.executeCallback('oninit', '_oninit', 0);
- }
-};
+ // Is it patched
+ if (f.mceOldSubmit && p)
+ f.mceOldSubmit();
+ },
-TinyMCE.prototype.removeMCEControl = function(editor_id) {
- var inst = tinyMCE.getInstanceById(editor_id);
+ submitPatch : function() {
+ tinyMCE.formSubmit(this, true);
+ },
- if (inst) {
- inst.switchSettings();
+ onLoad : function() {
+ var r, i, c, mode, trigger, elements, element, settings, elementId, elm;
+ var selector, deselector, elementRefAr, form;
- editor_id = inst.editorId;
- var html = tinyMCE.getContent(editor_id);
+ // Wait for everything to be loaded first
+ if (tinyMCE.settings.strict_loading_mode && this.loadingIndex != -1) {
+ window.setTimeout('tinyMCE.onLoad();', 1);
+ return;
+ }
- // Remove editor instance from instances array
- var tmpInstances = new Array();
- for (var instanceName in tinyMCE.instances) {
- var instance = tinyMCE.instances[instanceName];
- if (!tinyMCE.isInstance(instance))
- continue;
+ if (tinyMCE.isRealIE && window.event.type == "readystatechange" && document.readyState != "complete")
+ return true;
- if (instanceName != editor_id)
- tmpInstances[instanceName] = instance;
- }
- tinyMCE.instances = tmpInstances;
+ if (tinyMCE.isLoaded)
+ return true;
- tinyMCE.selectedElement = null;
- tinyMCE.selectedInstance = null;
-
- // Remove element
- var replaceElement = document.getElementById(editor_id + "_parent");
- var oldTargetElement = inst.oldTargetElement;
- var targetName = oldTargetElement.nodeName.toLowerCase();
-
- if (targetName == "textarea" || targetName == "input") {
- // Just show the old text area
- replaceElement.parentNode.removeChild(replaceElement);
- oldTargetElement.style.display = "inline";
- oldTargetElement.value = html;
- } else {
- oldTargetElement.innerHTML = html;
+ tinyMCE.isLoaded = true;
- replaceElement.parentNode.insertBefore(oldTargetElement, replaceElement);
- replaceElement.parentNode.removeChild(replaceElement);
+ // IE produces JS error if TinyMCE is placed in a frame
+ // It seems to have something to do with the selection not beeing
+ // correctly initialized in IE so this hack solves the problem
+ if (tinyMCE.isRealIE && document.body && window.location.href != window.top.location.href) {
+ r = document.body.createTextRange();
+ r.collapse(true);
+ r.select();
}
- }
-};
-TinyMCE.prototype._cleanupElementName = function(element_name, element) {
- var name = "";
+ tinyMCE.dispatchCallback(null, 'onpageload', 'onPageLoad');
- element_name = element_name.toLowerCase();
+ for (c=0; c<tinyMCE.configs.length; c++) {
+ tinyMCE.settings = tinyMCE.configs[c];
- // Never include body
- if (element_name == "body")
- return null;
+ selector = tinyMCE.getParam("editor_selector");
+ deselector = tinyMCE.getParam("editor_deselector");
+ elementRefAr = [];
- // If verification mode
- if (tinyMCE.cleanup_verify_html) {
- // Check if invalid element
- for (var i=0; i<tinyMCE.cleanup_invalidElements.length; i++) {
- if (tinyMCE.cleanup_invalidElements[i] == element_name)
- return null;
- }
+ // Add submit triggers
+ if (document.forms && tinyMCE.settings.add_form_submit_trigger && !tinyMCE.submitTriggers) {
+ for (i=0; i<document.forms.length; i++) {
+ form = document.forms[i];
- // Check if valid element
- var validElement = false;
- var elementAttribs = null;
- for (var i=0; i<tinyMCE.cleanup_validElements.length && !elementAttribs; i++) {
- for (var x=0, n=tinyMCE.cleanup_validElements[i][0].length; x<n; x++) {
- var elmMatch = tinyMCE.cleanup_validElements[i][0][x];
-
- if (elmMatch.charAt(0) == '+' || elmMatch.charAt(0) == '-')
- elmMatch = elmMatch.substring(1);
-
- // Handle wildcard/regexp
- if (elmMatch.match(new RegExp('\\*|\\?|\\+', 'g')) != null) {
- elmMatch = elmMatch.replace(new RegExp('\\?', 'g'), '(\\S?)');
- elmMatch = elmMatch.replace(new RegExp('\\+', 'g'), '(\\S+)');
- elmMatch = elmMatch.replace(new RegExp('\\*', 'g'), '(\\S*)');
- elmMatch = "^" + elmMatch + "$";
- if (element_name.match(new RegExp(elmMatch, 'g'))) {
- elementAttribs = tinyMCE.cleanup_validElements[i];
- validElement = true;
- break;
- }
- }
+ tinyMCE.addEvent(form, "submit", TinyMCE_Engine.prototype.handleEvent);
+ tinyMCE.addEvent(form, "reset", TinyMCE_Engine.prototype.handleEvent);
+ tinyMCE.submitTriggers = true; // Do it only once
- // Handle non regexp
- if (element_name == elmMatch) {
- elementAttribs = tinyMCE.cleanup_validElements[i];
- validElement = true;
- element_name = elementAttribs[0][0];
- break;
+ // Patch the form.submit function
+ if (tinyMCE.settings.submit_patch) {
+ try {
+ form.mceOldSubmit = form.submit;
+ form.submit = TinyMCE_Engine.prototype.submitPatch;
+ } catch (e) {
+ // Do nothing
+ }
+ }
}
}
- }
- if (!validElement)
- return null;
- }
+ // Add editor instances based on mode
+ mode = tinyMCE.settings.mode;
+ switch (mode) {
+ case "exact":
+ elements = tinyMCE.getParam('elements', '', true, ',');
- if (element_name.charAt(0) == '+' || element_name.charAt(0) == '-')
- name = element_name.substring(1);
+ for (i=0; i<elements.length; i++) {
+ element = tinyMCE._getElementById(elements[i]);
+ trigger = element ? element.getAttribute(tinyMCE.settings.textarea_trigger) : "";
- // Special Mozilla stuff
- if (!tinyMCE.isMSIE) {
- // Fix for bug #958498
- if (name == "strong" && !tinyMCE.cleanup_on_save)
- element_name = "b";
- else if (name == "em" && !tinyMCE.cleanup_on_save)
- element_name = "i";
- }
+ if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(element, "class")))
+ continue;
- var elmData = new Object();
+ if (trigger == "false")
+ continue;
- elmData.element_name = element_name;
- elmData.valid_attribs = elementAttribs;
+ if ((tinyMCE.settings.ask || tinyMCE.settings.convert_on_click) && element) {
+ elementRefAr[elementRefAr.length] = element;
+ continue;
+ }
- return elmData;
-};
+ if (element)
+ tinyMCE.addMCEControl(element, elements[i]);
+ }
+ break;
-/**
- * This function moves CSS styles to/from attributes.
- */
-TinyMCE.prototype._moveStyle = function(elm, style, attrib) {
- if (tinyMCE.cleanup_inline_styles) {
- var val = tinyMCE.getAttrib(elm, attrib);
+ case "specific_textareas":
+ case "textareas":
+ elements = document.getElementsByTagName("textarea");
- if (val != '') {
- val = '' + val;
+ for (i=0; i<elements.length; i++) {
+ elm = elements.item(i);
+ trigger = elm.getAttribute(tinyMCE.settings.textarea_trigger);
- switch (attrib) {
- case "background":
- val = "url('" + val + "')";
- break;
+ if (selector !== '' && !new RegExp('\\b' + selector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
+ continue;
- case "bordercolor":
- if (elm.style.borderStyle == '' || elm.style.borderStyle == 'none')
- elm.style.borderStyle = 'solid';
- break;
+ if (selector !== '')
+ trigger = selector !== '' ? "true" : "";
- case "border":
- case "width":
- case "height":
- if (attrib == "border" && elm.style.borderWidth > 0)
- return;
+ if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
+ continue;
- if (val.indexOf('%') == -1)
- val += 'px';
- break;
+ if ((mode == "specific_textareas" && trigger == "true") || (mode == "textareas" && trigger != "false"))
+ elementRefAr[elementRefAr.length] = elm;
+ }
+ break;
+ }
- case "vspace":
- case "hspace":
- elm.style.marginTop = val + "px";
- elm.style.marginBottom = val + "px";
- elm.removeAttribute(attrib);
- return;
+ for (i=0; i<elementRefAr.length; i++) {
+ element = elementRefAr[i];
+ elementId = element.name ? element.name : element.id;
- case "align":
- if (elm.nodeName == "IMG") {
- if (tinyMCE.isMSIE)
- elm.style.styleFloat = val;
- else
- elm.style.cssFloat = val;
- } else
- elm.style.textAlign = val;
+ if (tinyMCE.settings.ask || tinyMCE.settings.convert_on_click) {
+ // Focus breaks in Mozilla
+ if (tinyMCE.isGecko) {
+ settings = tinyMCE.settings;
- elm.removeAttribute(attrib);
- return;
+ tinyMCE.addEvent(element, "focus", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
+
+ if (element.nodeName != "TEXTAREA" && element.nodeName != "INPUT")
+ tinyMCE.addEvent(element, "click", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
+ // tinyMCE.addEvent(element, "mouseover", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
+ } else {
+ settings = tinyMCE.settings;
+
+ tinyMCE.addEvent(element, "focus", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
+ tinyMCE.addEvent(element, "click", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
+ // tinyMCE.addEvent(element, "mouseenter", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
+ }
+ } else
+ tinyMCE.addMCEControl(element, elementId);
}
- if (val != '') {
- eval('elm.style.' + style + ' = val;');
- elm.removeAttribute(attrib);
+ // Handle auto focus
+ if (tinyMCE.settings.auto_focus) {
+ window.setTimeout(function () {
+ var inst = tinyMCE.getInstanceById(tinyMCE.settings.auto_focus);
+ inst.selection.selectNode(inst.getBody(), true, true);
+ inst.contentWindow.focus();
+ }, 100);
}
+
+ tinyMCE.dispatchCallback(null, 'oninit', 'onInit');
}
- } else {
- if (style == '')
- return;
+ },
- var val = eval('elm.style.' + style) == '' ? tinyMCE.getAttrib(elm, attrib) : eval('elm.style.' + style);
- val = val == null ? '' : '' + val;
+ isInstance : function(o) {
+ return o != null && typeof(o) == "object" && o.isTinyMCE_Control;
+ },
- switch (attrib) {
- // Always move background to style
- case "background":
- if (val.indexOf('url') == -1 && val != '')
- val = "url('" + val + "');";
+ getParam : function(name, default_value, strip_whitespace, split_chr) {
+ var i, outArray, value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
- if (val != '') {
- elm.style.backgroundImage = val;
- elm.removeAttribute(attrib);
- }
- return;
+ // Fix bool values
+ if (value == "true" || value == "false")
+ return (value == "true");
- case "border":
- case "width":
- case "height":
- val = val.replace('px', '');
- break;
+ if (strip_whitespace)
+ value = tinyMCE.regexpReplace(value, "[ \t\r\n]", "");
- case "align":
- if (tinyMCE.getAttrib(elm, 'align') == '') {
- if (elm.nodeName == "IMG") {
- if (tinyMCE.isMSIE && elm.style.styleFloat != '') {
- val = elm.style.styleFloat;
- style = 'styleFloat';
- } else if (tinyMCE.isGecko && elm.style.cssFloat != '') {
- val = elm.style.cssFloat;
- style = 'cssFloat';
- }
- }
- }
- break;
- }
+ if (typeof(split_chr) != "undefined" && split_chr != null) {
+ value = value.split(split_chr);
+ outArray = [];
+
+ for (i=0; i<value.length; i++) {
+ if (value[i] && value[i] !== '')
+ outArray[outArray.length] = value[i];
+ }
- if (val != '') {
- elm.removeAttribute(attrib);
- elm.setAttribute(attrib, val);
- eval('elm.style.' + style + ' = "";');
+ value = outArray;
}
- }
-};
-TinyMCE.prototype._cleanupAttribute = function(valid_attributes, element_name, attribute_node, element_node) {
- var attribName = attribute_node.nodeName.toLowerCase();
- var attribValue = attribute_node.nodeValue;
- var attribMustBeValue = null;
- var verified = false;
+ return value;
+ },
- // Mozilla attibute, remove them
- if (attribName.indexOf('moz_') != -1)
- return null;
+ getLang : function(name, default_value, parse_entities, va) {
+ var v = (typeof(tinyMCELang[name]) == "undefined") ? default_value : tinyMCELang[name], n;
- if (!tinyMCE.cleanup_on_save && (attribName == "mce_href" || attribName == "mce_src"))
- return {name : attribName, value : attribValue};
-
- // Verify attrib
- if (tinyMCE.cleanup_verify_html && !verified) {
- for (var i=1; i<valid_attributes.length; i++) {
- var attribMatch = valid_attributes[i][0];
- var re = null;
-
- // Build regexp from wildcard
- if (attribMatch.match(new RegExp('\\*|\\?|\\+', 'g')) != null) {
- attribMatch = attribMatch.replace(new RegExp('\\?', 'g'), '(\\S?)');
- attribMatch = attribMatch.replace(new RegExp('\\+', 'g'), '(\\S+)');
- attribMatch = attribMatch.replace(new RegExp('\\*', 'g'), '(\\S*)');
- attribMatch = "^" + attribMatch + "$";
- re = new RegExp(attribMatch, 'g');
- }
+ if (parse_entities)
+ v = tinyMCE.entityDecode(v);
- if ((re && attribName.match(re) != null) || attribName == attribMatch) {
- verified = true;
- attribMustBeValue = valid_attributes[i][3];
- break;
- }
+ if (va) {
+ for (n in va)
+ v = this.replaceVar(v, n, va[n]);
}
- if (!verified)
- return false;
- } else
- verified = true;
-
- // Treat some attribs diffrent
- switch (attribName) {
- case "size":
- if (tinyMCE.isMSIE5 && element_name == "font")
- attribValue = element_node.size;
- break;
+ return v;
+ },
- case "width":
- case "height":
- case "border":
- // Old MSIE needs this
- if (tinyMCE.isMSIE5)
- attribValue = eval("element_node." + attribName);
- break;
+ entityDecode : function(s) {
+ var e = document.createElement("div");
- case "shape":
- attribValue = attribValue.toLowerCase();
- break;
+ e.innerHTML = s;
- case "cellspacing":
- if (tinyMCE.isMSIE5)
- attribValue = element_node.cellSpacing;
- break;
+ return !e.firstChild ? s : e.firstChild.nodeValue;
+ },
- case "cellpadding":
- if (tinyMCE.isMSIE5)
- attribValue = element_node.cellPadding;
- break;
+ addToLang : function(prefix, ar) {
+ var k;
- case "color":
- if (tinyMCE.isMSIE5 && element_name == "font")
- attribValue = element_node.color;
- break;
+ for (k in ar) {
+ if (typeof(ar[k]) == 'function')
+ continue;
- case "class":
- // Remove mceItem classes from anchors
- if (tinyMCE.cleanup_on_save && attribValue.indexOf('mceItemAnchor') != -1)
- attribValue = attribValue.replace(/mceItem[a-z0-9]+/gi, '');
+ tinyMCELang[(k.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix !== '' ? (prefix + "_") : '') + k] = ar[k];
+ }
- if (element_name == "table" || element_name == "td" || element_name == "th") {
- // Handle visual aid
- if (tinyMCE.cleanup_visual_table_class != "")
- attribValue = tinyMCE.getVisualAidClass(attribValue, !tinyMCE.cleanup_on_save);
- }
+ this.loadNextScript();
+ },
- if (!tinyMCE._verifyClass(element_node) || attribValue == "")
- return null;
+ triggerNodeChange : function(focus, setup_content) {
+ var elm, inst, editorId, undoIndex = -1, undoLevels = -1, doc, anySelection = false, st;
- break;
+ if (tinyMCE.selectedInstance) {
+ inst = tinyMCE.selectedInstance;
+ elm = (typeof(setup_content) != "undefined" && setup_content) ? tinyMCE.selectedElement : inst.getFocusElement();
- case "onfocus":
- case "onblur":
- case "onclick":
- case "ondblclick":
- case "onmousedown":
- case "onmouseup":
- case "onmouseover":
- case "onmousemove":
- case "onmouseout":
- case "onkeypress":
- case "onkeydown":
- case "onkeydown":
- case "onkeyup":
- attribValue = tinyMCE.cleanupEventStr("" + attribValue);
-
- if (attribValue.indexOf('return false;') == 0)
- attribValue = attribValue.substring(14);
+/* if (elm == inst.lastTriggerEl)
+ return;
- break;
+ inst.lastTriggerEl = elm;*/
- case "style":
- attribValue = tinyMCE.serializeStyle(tinyMCE.parseStyle(tinyMCE.getAttrib(element_node, "style")));
- break;
+ editorId = inst.editorId;
+ st = inst.selection.getSelectedText();
- // Convert the URLs of these
- case "href":
- case "src":
- case "longdesc":
- attribValue = tinyMCE.getAttrib(element_node, attribName);
+ if (tinyMCE.settings.auto_resize)
+ inst.resizeToContent();
- // Use mce_href instead
- var href = tinyMCE.getAttrib(element_node, "mce_href");
- if (attribName == "href" && href != "")
- attribValue = href;
+ if (setup_content && tinyMCE.isGecko && inst.isHidden())
+ elm = inst.getBody();
- // Use mce_src instead
- var src = tinyMCE.getAttrib(element_node, "mce_src");
- if (attribName == "src" && src != "")
- attribValue = src;
+ inst.switchSettings();
- // Always use absolute URLs within TinyMCE
- if (!tinyMCE.cleanup_on_save)
- attribValue = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], attribValue);
- else if (tinyMCE.getParam('convert_urls'))
- attribValue = eval(tinyMCE.cleanup_urlconverter_callback + "(attribValue, element_node, tinyMCE.cleanup_on_save);");
+ if (tinyMCE.selectedElement)
+ anySelection = (tinyMCE.selectedElement.nodeName.toLowerCase() == "img") || (st && st.length > 0);
- break;
+ if (tinyMCE.settings.custom_undo_redo) {
+ undoIndex = inst.undoRedo.undoIndex;
+ undoLevels = inst.undoRedo.undoLevels.length;
+ }
- case "colspan":
- case "rowspan":
- // Not needed
- if (attribValue == "1")
- return null;
- break;
+ tinyMCE.dispatchCallback(inst, 'handle_node_change_callback', 'handleNodeChange', editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content);
+ }
- // Skip these
- case "_moz-userdefined":
- case "editorid":
- case "mce_href":
- case "mce_src":
- return null;
- }
+ if (this.selectedInstance && (typeof(focus) == "undefined" || focus))
+ this.selectedInstance.contentWindow.focus();
+ },
- // Not the must be value
- if (attribMustBeValue != null) {
- var isCorrect = false;
- for (var i=0; i<attribMustBeValue.length; i++) {
- if (attribValue == attribMustBeValue[i]) {
- isCorrect = true;
- break;
- }
+ _customCleanup : function(inst, type, content) {
+ var pl, po, i, customCleanup;
+
+ // Call custom cleanup
+ customCleanup = tinyMCE.settings.cleanup_callback;
+ if (customCleanup != '')
+ content = tinyMCE.resolveDots(tinyMCE.settings.cleanup_callback, window)(type, content, inst);
+
+ // Trigger theme cleanup
+ po = tinyMCE.themes[tinyMCE.settings.theme];
+ if (po && po.cleanup)
+ content = po.cleanup(type, content, inst);
+
+ // Trigger plugin cleanups
+ pl = inst.plugins;
+ for (i=0; i<pl.length; i++) {
+ po = tinyMCE.plugins[pl[i]];
+
+ if (po && po.cleanup)
+ content = po.cleanup(type, content, inst);
}
- if (!isCorrect)
- return null;
- }
+ return content;
+ },
- var attrib = new Object();
+ setContent : function(h) {
+ if (tinyMCE.selectedInstance) {
+ tinyMCE.selectedInstance.execCommand('mceSetContent', false, h);
+ tinyMCE.selectedInstance.repaint();
+ }
+ },
- attrib.name = attribName;
- attrib.value = attribValue;
+ importThemeLanguagePack : function(name) {
+ if (typeof(name) == "undefined")
+ name = tinyMCE.settings.theme;
- return attrib;
-};
+ tinyMCE.loadScript(tinyMCE.baseURL + '/themes/' + name + '/langs/' + tinyMCE.settings.language + '.js');
+ },
-TinyMCE.prototype.clearArray = function(ar) {
- // Since stupid people tend to extend core objects like
- // Array with their own crap I needed to make functions that clean away
- // this junk so the arrays get clean and nice as they should be
- for (var key in ar)
- ar[key] = null;
-};
+ importPluginLanguagePack : function(name) {
+ var b = tinyMCE.baseURL + '/plugins/' + name;
-TinyMCE.prototype.isInstance = function(inst) {
- return inst != null && typeof(inst) == "object" && inst.isTinyMCEControl;
-};
+ if (this.plugins[name])
+ b = this.plugins[name].baseURL;
-TinyMCE.prototype.parseStyle = function(str) {
- var ar = new Array();
+ tinyMCE.loadScript(b + '/langs/' + tinyMCE.settings.language + '.js');
+ },
- if (str == null)
- return ar;
+ applyTemplate : function(h, ag) {
+ return h.replace(new RegExp('\\{\\$([a-z0-9_]+)\\}', 'gi'), function(m, s) {
+ if (s.indexOf('lang_') == 0 && tinyMCELang[s])
+ return tinyMCELang[s];
- var st = str.split(';');
+ if (ag && ag[s])
+ return ag[s];
- tinyMCE.clearArray(ar);
+ if (tinyMCE.settings[s])
+ return tinyMCE.settings[s];
- for (var i=0; i<st.length; i++) {
- if (st[i] == '')
- continue;
+ if (m == 'themeurl')
+ return tinyMCE.themeURL;
- var re = new RegExp('^\\s*([^:]*):\\s*(.*)\\s*$');
- var pa = st[i].replace(re, '$1||$2').split('||');
-//tinyMCE.debug(str, pa[0] + "=" + pa[1], st[i].replace(re, '$1||$2'));
- if (pa.length == 2)
- ar[pa[0].toLowerCase()] = pa[1];
- }
+ return m;
+ });
+ },
- return ar;
-};
+ replaceVar : function(h, r, v) {
+ return h.replace(new RegExp('{\\\$' + r + '}', 'g'), v);
+ },
-TinyMCE.prototype.compressStyle = function(ar, pr, sf, res) {
- var box = new Array();
+ openWindow : function(template, args) {
+ var html, width, height, x, y, resizable, scrollbars, url, name, win, modal, features;
- box[0] = ar[pr + '-top' + sf];
- box[1] = ar[pr + '-left' + sf];
- box[2] = ar[pr + '-right' + sf];
- box[3] = ar[pr + '-bottom' + sf];
+ args = !args ? {} : args;
- for (var i=0; i<box.length; i++) {
- if (box[i] == null)
- return;
+ args.mce_template_file = template.file;
+ args.mce_width = template.width;
+ args.mce_height = template.height;
+ tinyMCE.windowArgs = args;
- for (var a=0; a<box.length; a++) {
- if (box[a] != box[i])
- return;
- }
- }
+ html = template.html;
+ if (!(width = parseInt(template.width)))
+ width = 320;
- // They are all the same
- ar[res] = box[0];
- ar[pr + '-top' + sf] = null;
- ar[pr + '-left' + sf] = null;
- ar[pr + '-right' + sf] = null;
- ar[pr + '-bottom' + sf] = null;
-};
+ if (!(height = parseInt(template.height)))
+ height = 200;
-TinyMCE.prototype.serializeStyle = function(ar) {
- var str = "";
+ // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!!
+ if (tinyMCE.isIE)
+ height += 40;
+ else
+ height += 20;
+
+ x = parseInt(screen.width / 2.0) - (width / 2.0);
+ y = parseInt(screen.height / 2.0) - (height / 2.0);
- // Compress box
- tinyMCE.compressStyle(ar, "border", "", "border");
- tinyMCE.compressStyle(ar, "border", "-width", "border-width");
- tinyMCE.compressStyle(ar, "border", "-color", "border-color");
+ resizable = (args && args.resizable) ? args.resizable : "no";
+ scrollbars = (args && args.scrollbars) ? args.scrollbars : "no";
- for (var key in ar) {
- var val = ar[key];
- if (typeof(val) == 'function')
- continue;
+ if (template.file.charAt(0) != '/' && template.file.indexOf('://') == -1)
+ url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template.file;
+ else
+ url = template.file;
- if (val != null && val != '') {
- val = '' + val; // Force string
+ // Replace all args as variables in URL
+ for (name in args) {
+ if (typeof(args[name]) == 'function')
+ continue;
- // Fix style URL
- val = val.replace(new RegExp("url\\(\\'?([^\\']*)\\'?\\)", 'gi'), "url('$1')");
+ url = tinyMCE.replaceVar(url, name, escape(args[name]));
+ }
- // Convert URL
- if (val.indexOf('url(') != -1 && tinyMCE.getParam('convert_urls')) {
- var m = new RegExp("url\\('(.*?)'\\)").exec(val);
+ if (html) {
+ html = tinyMCE.replaceVar(html, "css", this.settings.popups_css);
+ html = tinyMCE.applyTemplate(html, args);
- if (m.length > 1)
- val = "url('" + eval(tinyMCE.getParam('urlconverter_callback') + "(m[1], null, true);") + "')";
+ 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);
+ if (win == null) {
+ alert(tinyMCELang.lang_popup_blocked);
+ return;
}
- // Force HEX colors
- if (tinyMCE.getParam("force_hex_style_colors"))
- val = tinyMCE.convertRGBToHex(val, true);
+ win.document.write(html);
+ win.document.close();
+ win.resizeTo(width, height);
+ win.focus();
+ } else {
+ if ((tinyMCE.isRealIE) && resizable != 'yes' && tinyMCE.settings.dialog_type == "modal") {
+ height += 10;
+
+ features = "resizable:" + resizable + ";scroll:" + scrollbars + ";status:yes;center:yes;help:no;dialogWidth:" + width + "px;dialogHeight:" + height + "px;";
+
+ window.showModalDialog(url, window, features);
+ } else {
+ modal = (resizable == "yes") ? "no" : "yes";
+
+ if (tinyMCE.isGecko && tinyMCE.isMac)
+ modal = "no";
+
+ if (template.close_previous != "no")
+ try {tinyMCE.lastWindow.close();} catch (ex) {}
+
+ 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);
+ if (win == null) {
+ alert(tinyMCELang.lang_popup_blocked);
+ return;
+ }
+
+ if (template.close_previous != "no")
+ tinyMCE.lastWindow = win;
+
+ try {
+ win.resizeTo(width, height);
+ } catch(e) {
+ // Ignore
+ }
+
+ // Make it bigger if statusbar is forced
+ if (tinyMCE.isGecko) {
+ if (win.document.defaultView.statusbar.visible)
+ win.resizeBy(0, tinyMCE.isMac ? 10 : 24);
+ }
- if (val != "url('')")
- str += key.toLowerCase() + ": " + val + "; ";
+ win.focus();
+ }
}
- }
+ },
- if (new RegExp('; $').test(str))
- str = str.substring(0, str.length - 2);
+ closeWindow : function(win) {
+ win.close();
+ },
- return str;
-};
+ getVisualAidClass : function(class_name, state) {
+ var i, classNames, ar, className, aidClass = tinyMCE.settings.visual_table_class;
+
+ if (typeof(state) == "undefined")
+ state = tinyMCE.settings.visual;
-TinyMCE.prototype.convertRGBToHex = function(s, k) {
- if (s.toLowerCase().indexOf('rgb') != -1) {
- var re = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
- var rgb = s.replace(re, "$1,$2,$3,$4,$5").split(',');
- if (rgb.length == 5) {
- r = parseInt(rgb[1]).toString(16);
- g = parseInt(rgb[2]).toString(16);
- b = parseInt(rgb[3]).toString(16);
+ // Split
+ classNames = [];
+ ar = class_name.split(' ');
+ for (i=0; i<ar.length; i++) {
+ if (ar[i] == aidClass)
+ ar[i] = "";
- r = r.length == 1 ? '0' + r : r;
- g = g.length == 1 ? '0' + g : g;
- b = b.length == 1 ? '0' + b : b;
+ if (ar[i] !== '')
+ classNames[classNames.length] = ar[i];
+ }
+
+ if (state)
+ classNames[classNames.length] = aidClass;
- s = "#" + r + g + b;
+ // Glue
+ className = "";
+ for (i=0; i<classNames.length; i++) {
+ if (i > 0)
+ className += " ";
- if (k)
- s = rgb[0] + s + rgb[4];
+ className += classNames[i];
}
- }
- return s;
-};
+ return className;
+ },
-TinyMCE.prototype.convertHexToRGB = function(s) {
- if (s.indexOf('#') != -1) {
- s = s.replace(new RegExp('[^0-9A-F]', 'gi'), '');
- return "rgb(" + parseInt(s.substring(0, 2), 16) + "," + parseInt(s.substring(2, 4), 16) + "," + parseInt(s.substring(4, 6), 16) + ")";
- }
+ handleVisualAid : function(el, deep, state, inst, skip_dispatch) {
+ var i, x, y, tableElement, anchorName, oldW, oldH, bo, cn;
- return s;
-};
+ if (!el)
+ return;
-TinyMCE.prototype._verifyClass = function(node) {
- // Sometimes the class gets set to null, weird Gecko bug?
- if (tinyMCE.isGecko) {
- var className = node.getAttribute('class');
- if (!className)
- return false;
- }
+ if (!skip_dispatch)
+ tinyMCE.dispatchCallback(inst, 'handle_visual_aid_callback', 'handleVisualAid', el, deep, state, inst);
+
+ tableElement = null;
+
+ switch (el.nodeName) {
+ case "TABLE":
+ oldW = el.style.width;
+ oldH = el.style.height;
+ bo = tinyMCE.getAttrib(el, "border");
+
+ bo = bo == '' || bo == "0" ? true : false;
- // Trim CSS class
- if (tinyMCE.isMSIE)
- var className = node.getAttribute('className');
+ tinyMCE.setAttrib(el, "class", tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el, "class"), state && bo));
+
+ el.style.width = oldW;
+ el.style.height = oldH;
+
+ for (y=0; y<el.rows.length; y++) {
+ for (x=0; x<el.rows[y].cells.length; x++) {
+ cn = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el.rows[y].cells[x], "class"), state && bo);
+ tinyMCE.setAttrib(el.rows[y].cells[x], "class", cn);
+ }
+ }
+
+ break;
+
+ case "A":
+ anchorName = tinyMCE.getAttrib(el, "name");
+
+ if (anchorName !== '' && state) {
+ el.title = anchorName;
+ tinyMCE.addCSSClass(el, 'mceItemAnchor');
+ } else if (anchorName !== '' && !state)
+ el.className = '';
- if (tinyMCE.cleanup_verify_css_classes && tinyMCE.cleanup_on_save) {
- var csses = tinyMCE.getCSSClasses();
- nonDefinedCSS = true;
- for (var c=0; c<csses.length; c++) {
- if (csses[c] == className) {
- nonDefinedCSS = false;
break;
- }
}
- if (nonDefinedCSS && className.indexOf('mce_') != 0) {
- node.removeAttribute('className');
- node.removeAttribute('class');
- return false;
+ if (deep && el.hasChildNodes()) {
+ for (i=0; i<el.childNodes.length; i++)
+ tinyMCE.handleVisualAid(el.childNodes[i], deep, state, inst, true);
}
- }
+ },
- return true;
-};
+ fixGeckoBaseHREFBug : function(m, e, h) {
+ var xsrc, xhref;
-TinyMCE.prototype.cleanupNode = function(node) {
- var output = "";
+ if (tinyMCE.isGecko) {
+ if (m == 1) {
+ h = h.replace(/\ssrc=/gi, " mce_tsrc=");
+ h = h.replace(/\shref=/gi, " mce_thref=");
- switch (node.nodeType) {
- case 1: // Element
- var elementData = tinyMCE._cleanupElementName(node.nodeName, node);
- var elementName = elementData ? elementData.element_name : null;
- var elementValidAttribs = elementData ? elementData.valid_attribs : null;
- var elementAttribs = "";
- var openTag = false, nonEmptyTag = false;
+ return h;
+ } else {
+ // Why bother if there is no src or href broken
+ if (!new RegExp('(src|href)=', 'g').test(h))
+ return h;
+
+ // Restore src and href that gets messed up by Gecko
+ tinyMCE.selectElements(e, 'A,IMG,SELECT,AREA,IFRAME,BASE,INPUT,SCRIPT,EMBED,OBJECT,LINK', function (n) {
+ xsrc = tinyMCE.getAttrib(n, "mce_tsrc");
+ xhref = tinyMCE.getAttrib(n, "mce_thref");
+
+ if (xsrc !== '') {
+ try {
+ n.src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, xsrc);
+ } catch (e) {
+ // Ignore, Firefox cast exception if local file wasn't found
+ }
- if (elementName != null && elementName.charAt(0) == '+') {
- elementName = elementName.substring(1);
- openTag = true;
- }
+ n.removeAttribute("mce_tsrc");
+ }
- if (elementName != null && elementName.charAt(0) == '-') {
- elementName = elementName.substring(1);
- nonEmptyTag = true;
- }
+ if (xhref !== '') {
+ try {
+ n.href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, xhref);
+ } catch (e) {
+ // Ignore, Firefox cast exception if local file wasn't found
+ }
- // Checking DOM tree for MSIE weirdness!!
- if (tinyMCE.isMSIE && tinyMCE.settings['fix_content_duplication']) {
- var lookup = tinyMCE.cleanup_elementLookupTable;
+ n.removeAttribute("mce_thref");
+ }
- for (var i=0; i<lookup.length; i++) {
- // Found element reference else were, hmm?
- if (lookup[i] == node)
- return output;
- }
+ return false;
+ });
+
+ // Restore text/comment nodes
+ tinyMCE.selectNodes(e, function(n) {
+ if (n.nodeType == 3 || n.nodeType == 8) {
+ n.nodeValue = n.nodeValue.replace(/\smce_tsrc=/gi, " src=");
+ n.nodeValue = n.nodeValue.replace(/\smce_thref=/gi, " href=");
+ }
- // Add element to lookup table
- lookup[lookup.length] = node;
+ return false;
+ });
}
+ }
- // Element not valid (only render children)
- if (!elementName) {
- if (node.hasChildNodes()) {
- for (var i=0; i<node.childNodes.length; i++)
- output += this.cleanupNode(node.childNodes[i]);
- }
+ return h;
+ },
- return output;
- }
+ _setHTML : function(doc, html_content) {
+ var i, html, paras, node;
- if (tinyMCE.cleanup_on_save) {
- if (node.nodeName == "A" && node.className == "mceItemAnchor") {
- if (node.hasChildNodes()) {
- for (var i=0; i<node.childNodes.length; i++)
- output += this.cleanupNode(node.childNodes[i]);
- }
+ // Force closed anchors open
+ //html_content = html_content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
- return '<a name="' + this.convertStringToXML(node.getAttribute("name")) + '"></a>' + output;
- }
- }
+ html_content = tinyMCE.cleanupHTMLCode(html_content);
- // Remove deprecated attributes
- var re = new RegExp("^(TABLE|TD|TR)$");
- if (re.test(node.nodeName)) {
- // Move attrib to style
- if ((node.nodeName != "TABLE" || tinyMCE.cleanup_inline_styles) && (width = tinyMCE.getAttrib(node, "width")) != '') {
- node.style.width = width.indexOf('%') != -1 ? width : width.replace(/[^0-9]/gi, '') + "px";
- node.removeAttribute("width");
- }
+ // Try innerHTML if it fails use pasteHTML in MSIE
+ try {
+ tinyMCE.setInnerHTML(doc.body, html_content);
+ } catch (e) {
+ if (this.isMSIE)
+ doc.body.createTextRange().pasteHTML(html_content);
+ }
- // Is table and not inline
- if ((node.nodeName == "TABLE" && !tinyMCE.cleanup_inline_styles) && node.style.width != '') {
- tinyMCE.setAttrib(node, "width", node.style.width.replace('px',''));
- node.style.width = '';
- }
+ // Content duplication bug fix
+ if (tinyMCE.isIE && tinyMCE.settings.fix_content_duplication) {
+ // Remove P elements in P elements
+ paras = doc.getElementsByTagName("P");
+ for (i=0; i<paras.length; i++) {
+ node = paras[i];
- // Move attrib to style
- if ((height = tinyMCE.getAttrib(node, "height")) != '') {
- height = "" + height; // Force string
- node.style.height = height.indexOf('%') != -1 ? height : height.replace(/[^0-9]/gi, '') + "px";
- node.removeAttribute("height");
+ while ((node = node.parentNode) != null) {
+ if (node.nodeName == "P")
+ node.outerHTML = node.innerHTML;
}
}
- // Handle inline/outline styles
- if (tinyMCE.cleanup_inline_styles) {
- var re = new RegExp("^(TABLE|TD|TR|IMG|HR)$");
- if (re.test(node.nodeName) && tinyMCE.getAttrib(node, "class").indexOf('mceItem') == -1) {
- tinyMCE._moveStyle(node, 'width', 'width');
- tinyMCE._moveStyle(node, 'height', 'height');
- tinyMCE._moveStyle(node, 'borderWidth', 'border');
- tinyMCE._moveStyle(node, '', 'vspace');
- tinyMCE._moveStyle(node, '', 'hspace');
- tinyMCE._moveStyle(node, 'textAlign', 'align');
- tinyMCE._moveStyle(node, 'backgroundColor', 'bgColor');
- tinyMCE._moveStyle(node, 'borderColor', 'borderColor');
- tinyMCE._moveStyle(node, 'backgroundImage', 'background');
-
- // Refresh element in old MSIE
- if (tinyMCE.isMSIE5)
- node.outerHTML = node.outerHTML;
- } else if (tinyMCE.isBlockElement(node))
- tinyMCE._moveStyle(node, 'textAlign', 'align');
-
- if (node.nodeName == "FONT")
- tinyMCE._moveStyle(node, 'color', 'color');
+ // Content duplication bug fix (Seems to be word crap)
+ html = doc.body.innerHTML;
+
+ // Always set the htmlText output
+ tinyMCE.setInnerHTML(doc.body, html);
+ }
+
+ tinyMCE.cleanupAnchors(doc);
+
+ if (tinyMCE.getParam("convert_fonts_to_spans"))
+ tinyMCE.convertSpansToFonts(doc);
+ },
+
+ getEditorId : function(form_element) {
+ var inst = this.getInstanceById(form_element);
+
+ if (!inst)
+ return null;
+
+ return inst.editorId;
+ },
+
+ getInstanceById : function(editor_id) {
+ var inst = this.instances[editor_id], n;
+
+ if (!inst) {
+ for (n in tinyMCE.instances) {
+ inst = tinyMCE.instances[n];
+
+ if (!tinyMCE.isInstance(inst))
+ continue;
+
+ if (inst.formTargetElementId == editor_id)
+ return inst;
}
+ } else
+ return inst;
+
+ return null;
+ },
- // Set attrib data
- if (elementValidAttribs) {
- for (var a=1; a<elementValidAttribs.length; a++) {
- var attribName, attribDefaultValue, attribForceValue, attribValue;
+ queryInstanceCommandValue : function(editor_id, command) {
+ var inst = tinyMCE.getInstanceById(editor_id);
- attribName = elementValidAttribs[a][0];
- attribDefaultValue = elementValidAttribs[a][1];
- attribForceValue = elementValidAttribs[a][2];
+ if (inst)
+ return inst.queryCommandValue(command);
- if (attribDefaultValue != null || attribForceValue != null) {
- var attribValue = node.getAttribute(attribName);
+ return false;
+ },
+
+ queryInstanceCommandState : function(editor_id, command) {
+ var inst = tinyMCE.getInstanceById(editor_id);
- if (node.getAttribute(attribName) == null || node.getAttribute(attribName) == "")
- attribValue = attribDefaultValue;
+ if (inst)
+ return inst.queryCommandState(command);
- attribValue = attribForceValue ? attribForceValue : attribValue;
+ return null;
+ },
- // Is to generate id
- if (attribValue == "{$uid}")
- attribValue = "uid_" + (tinyMCE.cleanup_idCount++);
+ setWindowArg : function(n, v) {
+ this.windowArgs[n] = v;
+ },
- // Add visual aid class
- if (attribName == "class")
- attribValue = tinyMCE.getVisualAidClass(attribValue, tinyMCE.cleanup_on_save);
+ getWindowArg : function(n, d) {
+ return (typeof(this.windowArgs[n]) == "undefined") ? d : this.windowArgs[n];
+ },
- node.setAttribute(attribName, attribValue);
- //alert(attribName + "=" + attribValue);
- }
+ getCSSClasses : function(editor_id, doc) {
+ var i, c, x, rule, styles, rules, csses, selectorText, inst = tinyMCE.getInstanceById(editor_id);
+ var cssClass, addClass, p;
+
+ if (!inst)
+ inst = tinyMCE.selectedInstance;
+
+ if (!inst)
+ return [];
+
+ if (!doc)
+ doc = inst.getDoc();
+
+ // Is cached, use that
+ if (inst && inst.cssClasses.length > 0)
+ return inst.cssClasses;
+
+ if (!doc)
+ return;
+
+ styles = doc.styleSheets;
+
+ if (styles && styles.length > 0) {
+ for (x=0; x<styles.length; x++) {
+ csses = null;
+
+ try {
+ csses = tinyMCE.isIE ? doc.styleSheets(x).rules : styles[x].cssRules;
+ } catch(e) {
+ // Just ignore any errors I know this is ugly!!
}
- }
+
+ if (!csses)
+ return [];
- if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && elementName == "style")
- return "<style>" + node.innerHTML + "</style>";
+ for (i=0; i<csses.length; i++) {
+ selectorText = csses[i].selectorText;
+
+ // Can be multiple rules per selector
+ if (selectorText) {
+ rules = selectorText.split(',');
+ for (c=0; c<rules.length; c++) {
+ rule = rules[c];
- // Remove empty tables
- if (elementName == "table" && !node.hasChildNodes())
- return "";
+ // Strip spaces between selectors
+ while (rule.indexOf(' ') == 0)
+ rule = rule.substring(1);
- // Handle element attributes
- if (node.attributes.length > 0) {
- var lastAttrib = "";
+ // Invalid rule
+ if (rule.indexOf(' ') != -1 || rule.indexOf(':') != -1 || rule.indexOf('mceItem') != -1)
+ continue;
- for (var i=0; i<node.attributes.length; i++) {
- if (node.attributes[i].specified) {
- // Is the attrib already processed (removed duplicate attributes in opera TD[align=left])
- if (tinyMCE.isOpera) {
- if (node.attributes[i].nodeName == lastAttrib)
+ if (rule.indexOf(tinyMCE.settings.visual_table_class) != -1 || rule.indexOf('mceEditable') != -1 || rule.indexOf('mceNonEditable') != -1)
continue;
- lastAttrib = node.attributes[i].nodeName;
- }
+ // Is class rule
+ if (rule.indexOf('.') != -1) {
+ cssClass = rule.substring(rule.indexOf('.') + 1);
+ addClass = true;
+
+ for (p=0; p<inst.cssClasses.length && addClass; p++) {
+ if (inst.cssClasses[p] == cssClass)
+ addClass = false;
+ }
- // tinyMCE.debug(node.nodeName, node.attributes[i].nodeName, node.attributes[i].nodeValue, node.innerHTML);
- var attrib = tinyMCE._cleanupAttribute(elementValidAttribs, elementName, node.attributes[i], node);
- if (attrib && attrib.value != "")
- elementAttribs += " " + attrib.name + "=" + '"' + this.convertStringToXML("" + attrib.value) + '"';
+ if (addClass)
+ inst.cssClasses[inst.cssClasses.length] = cssClass;
+ }
+ }
}
}
}
+ }
+
+ return inst.cssClasses;
+ },
+
+ regexpReplace : function(in_str, reg_exp, replace_str, opts) {
+ var re;
+
+ if (in_str == null)
+ return in_str;
+
+ if (typeof(opts) == "undefined")
+ opts = 'g';
+
+ re = new RegExp(reg_exp, opts);
+
+ return in_str.replace(re, replace_str);
+ },
+
+ trim : function(s) {
+ return s.replace(/^\s*|\s*$/g, "");
+ },
- // MSIE table summary fix (MSIE 5.5)
- if (tinyMCE.isMSIE && elementName == "table" && node.getAttribute("summary") != null && elementAttribs.indexOf('summary') == -1) {
- var summary = tinyMCE.getAttrib(node, 'summary');
- if (summary != '')
- elementAttribs += " summary=" + '"' + this.convertStringToXML(summary) + '"';
+ cleanupEventStr : function(s) {
+ s = "" + s;
+ s = s.replace('function anonymous()\n{\n', '');
+ s = s.replace('\n}', '');
+ s = s.replace(/^return true;/gi, ''); // Remove event blocker
+
+ return s;
+ },
+
+ getControlHTML : function(c) {
+ var i, l, n, o, v, rtl = tinyMCE.getLang('lang_dir') == 'rtl';
+
+ l = tinyMCE.plugins;
+ for (n in l) {
+ o = l[n];
+
+ if (o.getControlHTML && (v = o.getControlHTML(c)) !== '') {
+ if (rtl)
+ return '<span dir="rtl">' + tinyMCE.replaceVar(v, "pluginurl", o.baseURL) + '</span>';
+
+ return tinyMCE.replaceVar(v, "pluginurl", o.baseURL);
}
+ }
- // Handle missing attributes in MSIE 5.5
- if (tinyMCE.isMSIE5 && /^(td|img|a)$/.test(elementName)) {
- var ma = new Array("scope", "longdesc", "hreflang", "charset", "type");
+ o = tinyMCE.themes[tinyMCE.settings.theme];
+ if (o.getControlHTML && (v = o.getControlHTML(c)) !== '') {
+ if (rtl)
+ return '<span dir="rtl">' + v + '</span>';
- for (var u=0; u<ma.length; u++) {
- if (node.getAttribute(ma[u]) != null) {
- var s = tinyMCE.getAttrib(node, ma[u]);
+ return v;
+ }
- if (s != '')
- elementAttribs += " " + ma[u] + "=" + '"' + this.convertStringToXML(s) + '"';
- }
- }
+ return '';
+ },
+
+ evalFunc : function(f, idx, a, o) {
+ o = !o ? window : o;
+ f = typeof(f) == 'function' ? f : o[f];
+
+ return f.apply(o, Array.prototype.slice.call(a, idx));
+ },
+
+ dispatchCallback : function(i, p, n) {
+ return this.callFunc(i, p, n, 0, this.dispatchCallback.arguments);
+ },
+
+ executeCallback : function(i, p, n) {
+ return this.callFunc(i, p, n, 1, this.executeCallback.arguments);
+ },
+
+ execCommandCallback : function(i, p, n) {
+ return this.callFunc(i, p, n, 2, this.execCommandCallback.arguments);
+ },
+
+ callFunc : function(ins, p, n, m, a) {
+ var l, i, on, o, s, v;
+
+ s = m == 2;
+
+ l = tinyMCE.getParam(p, '');
+
+ if (l !== '' && (v = tinyMCE.evalFunc(l, 3, a)) == s && m > 0)
+ return true;
+
+ if (ins != null) {
+ for (i=0, l = ins.plugins; i<l.length; i++) {
+ o = tinyMCE.plugins[l[i]];
+
+ if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0)
+ return true;
+ }
+ }
+
+ l = tinyMCE.themes;
+ for (on in l) {
+ o = l[on];
+
+ if (o[n] && (v = tinyMCE.evalFunc(n, 3, a, o)) == s && m > 0)
+ return true;
+ }
+
+ return false;
+ },
+
+ resolveDots : function(s, o) {
+ var i;
+
+ if (typeof(s) == 'string') {
+ for (i=0, s=s.split('.'); i<s.length; i++)
+ o = o[s[i]];
+ } else
+ o = s;
+
+ return o;
+ },
+
+ xmlEncode : function(s) {
+ return s ? ('' + s).replace(this.xmlEncodeRe, function (c, b) {
+ switch (c) {
+ case '&':
+ return '&';
+
+ case '"':
+ return '"';
+
+ case '<':
+ return '<';
+
+ case '>':
+ return '>';
}
- // MSIE form element issue
- if (tinyMCE.isMSIE && elementName == "input") {
- if (node.type) {
- if (!elementAttribs.match(/ type=/g))
- elementAttribs += " type=" + '"' + node.type + '"';
+ return c;
+ }) : s;
+ },
+
+ add : function(c, m) {
+ var n;
+
+ for (n in m)
+ c.prototype[n] = m[n];
+ },
+
+ extend : function(p, np) {
+ var o = {}, n;
+
+ o.parent = p;
+
+ for (n in p)
+ o[n] = p[n];
+
+ for (n in np)
+ o[n] = np[n];
+
+ return o;
+ },
+
+ hideMenus : function() {
+ var e = tinyMCE.lastSelectedMenuBtn;
+
+ if (tinyMCE.lastMenu) {
+ tinyMCE.lastMenu.hide();
+ tinyMCE.lastMenu = null;
+ }
+
+ if (e) {
+ tinyMCE.switchClass(e, tinyMCE.lastMenuBtnClass);
+ tinyMCE.lastSelectedMenuBtn = null;
+ }
+ }
+
+ };
+
+// Global instances
+var TinyMCE = TinyMCE_Engine; // Compatiblity with gzip compressors
+var tinyMCE = new TinyMCE_Engine();
+var tinyMCELang = {};
+
+/* file:jscripts/tiny_mce/classes/TinyMCE_Control.class.js */
+
+function TinyMCE_Control(settings) {
+ var t, i, tos, fu, p, x, fn, fu, pn, s = settings;
+
+ this.undoRedoLevel = true;
+ this.isTinyMCE_Control = true;
+
+ // Default settings
+ this.enabled = true;
+ this.settings = s;
+ this.settings.theme = tinyMCE.getParam("theme", "default");
+ this.settings.width = tinyMCE.getParam("width", -1);
+ this.settings.height = tinyMCE.getParam("height", -1);
+ this.selection = new TinyMCE_Selection(this);
+ this.undoRedo = new TinyMCE_UndoRedo(this);
+ this.cleanup = new TinyMCE_Cleanup();
+ this.shortcuts = [];
+ this.hasMouseMoved = false;
+ this.foreColor = this.backColor = "#999999";
+ this.data = {};
+ this.cssClasses = [];
+
+ this.cleanup.init({
+ valid_elements : s.valid_elements,
+ extended_valid_elements : s.extended_valid_elements,
+ valid_child_elements : s.valid_child_elements,
+ entities : s.entities,
+ entity_encoding : s.entity_encoding,
+ debug : s.cleanup_debug,
+ indent : s.apply_source_formatting,
+ invalid_elements : s.invalid_elements,
+ verify_html : s.verify_html,
+ fix_content_duplication : s.fix_content_duplication,
+ convert_fonts_to_spans : s.convert_fonts_to_spans
+ });
+
+ // Wrap old theme
+ t = this.settings.theme;
+ if (!tinyMCE.hasTheme(t)) {
+ fn = tinyMCE.callbacks;
+ tos = {};
+
+ for (i=0; i<fn.length; i++) {
+ if ((fu = window['TinyMCE_' + t + "_" + fn[i]]))
+ tos[fn[i]] = fu;
+ }
+
+ tinyMCE.addTheme(t, tos);
+ }
+
+ // Wrap old plugins
+ this.plugins = [];
+ p = tinyMCE.getParam('plugins', '', true, ',');
+ if (p.length > 0) {
+ for (i=0; i<p.length; i++) {
+ pn = p[i];
+
+ if (pn.charAt(0) == '-')
+ pn = pn.substring(1);
+
+ if (!tinyMCE.hasPlugin(pn)) {
+ fn = tinyMCE.callbacks;
+ tos = {};
+
+ for (x=0; x<fn.length; x++) {
+ if ((fu = window['TinyMCE_' + pn + "_" + fn[x]]))
+ tos[fn[x]] = fu;
}
- if (node.value) {
- if (!elementAttribs.match(/ value=/g))
- elementAttribs += " value=" + '"' + node.value + '"';
- }
+ tinyMCE.addPlugin(pn, tos);
+ }
+
+ this.plugins[this.plugins.length] = pn;
+ }
+ }
+};
+
+TinyMCE_Control.prototype = {
+ selection : null,
+
+ settings : null,
+
+ cleanup : null,
+
+ getData : function(na) {
+ var o = this.data[na];
+
+ if (!o)
+ o = this.data[na] = {};
+
+ return o;
+ },
+
+ hasPlugin : function(n) {
+ var i;
+
+ for (i=0; i<this.plugins.length; i++) {
+ if (this.plugins[i] == n)
+ return true;
+ }
+
+ return false;
+ },
+
+ addPlugin : function(n, p) {
+ if (!this.hasPlugin(n)) {
+ tinyMCE.addPlugin(n, p);
+ this.plugins[this.plugins.length] = n;
+ }
+ },
+
+ repaint : function() {
+ var s, b, ex;
+
+ if (tinyMCE.isRealIE)
+ return;
+
+ try {
+ s = this.selection;
+ b = s.getBookmark(true);
+ this.getBody().style.display = 'none';
+ this.getDoc().execCommand('selectall', false, null);
+ this.getSel().collapseToStart();
+ this.getBody().style.display = 'block';
+ s.moveToBookmark(b);
+ } catch (ex) {
+ // Ignore
+ }
+ },
+
+ switchSettings : function() {
+ if (tinyMCE.configs.length > 1 && tinyMCE.currentConfig != this.settings.index) {
+ tinyMCE.settings = this.settings;
+ tinyMCE.currentConfig = this.settings.index;
+ }
+ },
+
+ select : function() {
+ var oldInst = tinyMCE.selectedInstance;
+
+ if (oldInst != this) {
+ if (oldInst)
+ oldInst.execCommand('mceEndTyping');
+
+ tinyMCE.dispatchCallback(this, 'select_instance_callback', 'selectInstance', this, oldInst);
+ tinyMCE.selectedInstance = this;
+ }
+ },
+
+ getBody : function() {
+ return this.contentBody ? this.contentBody : this.getDoc().body;
+ },
+
+ getDoc : function() {
+// return this.contentDocument ? this.contentDocument : this.contentWindow.document; // Removed due to IE 5.5 ?
+ return this.contentWindow.document;
+ },
+
+ getWin : function() {
+ return this.contentWindow;
+ },
+
+ getContainerWin : function() {
+ return this.containerWindow ? this.containerWindow : window;
+ },
+
+ getViewPort : function() {
+ return tinyMCE.getViewPort(this.getWin());
+ },
+
+ getParentNode : function(n, f) {
+ return tinyMCE.getParentNode(n, f, this.getBody());
+ },
+
+ getParentElement : function(n, na, f) {
+ return tinyMCE.getParentElement(n, na, f, this.getBody());
+ },
+
+ getParentBlockElement : function(n) {
+ return tinyMCE.getParentBlockElement(n, this.getBody());
+ },
+
+ resizeToContent : function() {
+ var d = this.getDoc(), b = d.body, de = d.documentElement;
+
+ this.iframeElement.style.height = (tinyMCE.isRealIE) ? b.scrollHeight : de.offsetHeight + 'px';
+ },
+
+ addShortcut : function(m, k, d, cmd, ui, va) {
+ var n = typeof(k) == "number", ie = tinyMCE.isIE, c, sc, i, scl = this.shortcuts;
+
+ if (!tinyMCE.getParam('custom_shortcuts'))
+ return false;
+
+ m = m.toLowerCase();
+ k = ie && !n ? k.toUpperCase() : k;
+ c = n ? null : k.charCodeAt(0);
+ d = d && d.indexOf('lang_') == 0 ? tinyMCE.getLang(d) : d;
+
+ sc = {
+ alt : m.indexOf('alt') != -1,
+ ctrl : m.indexOf('ctrl') != -1,
+ shift : m.indexOf('shift') != -1,
+ charCode : c,
+ keyCode : n ? k : (ie ? c : null),
+ desc : d,
+ cmd : cmd,
+ ui : ui,
+ val : va
+ };
+
+ for (i=0; i<scl.length; i++) {
+ if (sc.alt == scl[i].alt && sc.ctrl == scl[i].ctrl && sc.shift == scl[i].shift
+ && sc.charCode == scl[i].charCode && sc.keyCode == scl[i].keyCode) {
+ return false;
+ }
+ }
+
+ scl[scl.length] = sc;
+
+ return true;
+ },
+
+ handleShortcut : function(e) {
+ var i, s, o;
+
+ // Normal key press, then ignore it
+ if (!e.altKey && !e.ctrlKey)
+ return false;
+
+ s = this.shortcuts;
+
+ for (i=0; i<s.length; i++) {
+ o = s[i];
+
+ if (o.alt == e.altKey && o.ctrl == e.ctrlKey && (o.keyCode == e.keyCode || o.charCode == e.charCode)) {
+ if (o.cmd && (e.type == "keydown" || (e.type == "keypress" && !tinyMCE.isOpera)))
+ tinyMCE.execCommand(o.cmd, o.ui, o.val);
+
+ tinyMCE.cancelEvent(e);
+ return true;
+ }
+ }
+
+ return false;
+ },
+
+ autoResetDesignMode : function() {
+ // Add fix for tab/style.display none/block problems in Gecko
+ if (!tinyMCE.isIE && this.isHidden() && tinyMCE.getParam('auto_reset_designmode'))
+ eval('try { this.getDoc().designMode = "On"; this.useCSS = false; } catch(e) {}');
+ },
+
+ isHidden : function() {
+ var s;
+
+ if (tinyMCE.isIE)
+ return false;
+
+ s = this.getSel();
+
+ // Weird, wheres that cursor selection?
+ return (!s || !s.rangeCount || s.rangeCount == 0);
+ },
+
+ isDirty : function() {
+ // Is content modified and not in a submit procedure
+ return tinyMCE.trim(this.startContent) != tinyMCE.trim(this.getBody().innerHTML) && !this.isNotDirty;
+ },
+
+ _mergeElements : function(scmd, pa, ch, override) {
+ var st, stc, className, n;
+
+ if (scmd == "removeformat") {
+ pa.className = "";
+ pa.style.cssText = "";
+ ch.className = "";
+ ch.style.cssText = "";
+ return;
+ }
+
+ st = tinyMCE.parseStyle(tinyMCE.getAttrib(pa, "style"));
+ stc = tinyMCE.parseStyle(tinyMCE.getAttrib(ch, "style"));
+ className = tinyMCE.getAttrib(pa, "class");
+
+ // Removed class adding due to bug #1478272
+ className = tinyMCE.getAttrib(ch, "class");
+
+ if (override) {
+ for (n in st) {
+ if (typeof(st[n]) == 'function')
+ continue;
+
+ stc[n] = st[n];
+ }
+ } else {
+ for (n in stc) {
+ if (typeof(stc[n]) == 'function')
+ continue;
+
+ st[n] = stc[n];
+ }
+ }
+
+ tinyMCE.setAttrib(pa, "style", tinyMCE.serializeStyle(st));
+ tinyMCE.setAttrib(pa, "class", tinyMCE.trim(className));
+ ch.className = "";
+ ch.style.cssText = "";
+ ch.removeAttribute("class");
+ ch.removeAttribute("style");
+ },
+
+ _fixRootBlocks : function() {
+ var rb, b, ne, be, nx, bm;
+
+ rb = tinyMCE.getParam('forced_root_block');
+ if (!rb)
+ return;
+
+ b = this.getBody();
+ ne = b.firstChild;
+
+ while (ne) {
+ nx = ne.nextSibling;
+
+ // If text node or inline element wrap it in a block element
+ if (ne.nodeType == 3 || !tinyMCE.blockRegExp.test(ne.nodeName)) {
+ if (!bm)
+ bm = this.selection.getBookmark();
+
+ if (!be) {
+ be = this.getDoc().createElement(rb);
+ be.appendChild(ne.cloneNode(true));
+ b.replaceChild(be, ne);
+ } else {
+ be.appendChild(ne.cloneNode(true));
+ b.removeChild(ne);
+ }
+ } else
+ be = null;
+
+ ne = nx;
+ }
+
+ if (bm)
+ this.selection.moveToBookmark(bm);
+ },
+
+ _fixTrailingNbsp : function() {
+ var s = this.selection, e = s.getFocusElement(), bm, v;
+
+ if (e && tinyMCE.blockRegExp.test(e.nodeName) && e.firstChild) {
+ v = e.firstChild.nodeValue;
+
+ if (v && v.length > 1 && /(^\u00a0|\u00a0$)/.test(v)) {
+ e.firstChild.nodeValue = v.replace(/(^\u00a0|\u00a0$)/, '');
+ s.selectNode(e.firstChild, true, false, false); // Select and collapse
+ }
+ }
+ },
+
+ _setUseCSS : function(b) {
+ var d = this.getDoc();
+
+ try {d.execCommand("useCSS", false, !b);} catch (ex) {}
+ try {d.execCommand("styleWithCSS", false, b);} catch (ex) {}
+
+ if (!tinyMCE.getParam("table_inline_editing"))
+ try {d.execCommand('enableInlineTableEditing', false, "false");} catch (ex) {}
+
+ if (!tinyMCE.getParam("object_resizing"))
+ try {d.execCommand('enableObjectResizing', false, "false");} catch (ex) {}
+ },
+
+ execCommand : function(command, user_interface, value) {
+ var i, x, z, align, img, div, doc = this.getDoc(), win = this.getWin(), focusElm = this.getFocusElement();
+
+ // Is not a undo specific command
+ if (!new RegExp('mceStartTyping|mceEndTyping|mceBeginUndoLevel|mceEndUndoLevel|mceAddUndoLevel', 'gi').test(command))
+ this.undoBookmark = null;
+
+ // Mozilla issue
+ if (!tinyMCE.isIE && !this.useCSS) {
+ this._setUseCSS(false);
+ this.useCSS = true;
+ }
+
+ //debug("command: " + command + ", user_interface: " + user_interface + ", value: " + value);
+ this.contentDocument = doc; // <-- Strange, unless this is applied Mozilla 1.3 breaks
+
+ // Don't dispatch key commands
+ if (!/mceStartTyping|mceEndTyping/.test(command)) {
+ if (tinyMCE.execCommandCallback(this, 'execcommand_callback', 'execCommand', this.editorId, this.getBody(), command, user_interface, value))
+ return;
+ }
+
+ // Fix align on images
+ if (focusElm && focusElm.nodeName == "IMG") {
+ align = focusElm.getAttribute('align');
+ img = command == "JustifyCenter" ? focusElm.cloneNode(false) : focusElm;
+
+ switch (command) {
+ case "JustifyLeft":
+ if (align == 'left')
+ img.removeAttribute('align');
+ else
+ img.setAttribute('align', 'left');
+
+ // Remove the div
+ div = focusElm.parentNode;
+ if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
+ div.parentNode.replaceChild(img, div);
+
+ this.selection.selectNode(img);
+ this.repaint();
+ tinyMCE.triggerNodeChange();
+ return;
+
+ case "JustifyCenter":
+ img.removeAttribute('align');
+
+ // Is centered
+ div = tinyMCE.getParentElement(focusElm, "div");
+ if (div && div.style.textAlign == "center") {
+ // Remove div
+ if (div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
+ div.parentNode.replaceChild(img, div);
+ } else {
+ // Add div
+ div = this.getDoc().createElement("div");
+ div.style.textAlign = 'center';
+ div.appendChild(img);
+ focusElm.parentNode.replaceChild(div, focusElm);
+ }
+
+ this.selection.selectNode(img);
+ this.repaint();
+ tinyMCE.triggerNodeChange();
+ return;
+
+ case "JustifyRight":
+ if (align == 'right')
+ img.removeAttribute('align');
+ else
+ img.setAttribute('align', 'right');
+
+ // Remove the div
+ div = focusElm.parentNode;
+ if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
+ div.parentNode.replaceChild(img, div);
+
+ this.selection.selectNode(img);
+ this.repaint();
+ tinyMCE.triggerNodeChange();
+ return;
+ }
+ }
+
+ if (tinyMCE.settings.force_br_newlines) {
+ var alignValue = "";
+
+ if (doc.selection.type != "Control") {
+ switch (command) {
+ case "JustifyLeft":
+ alignValue = "left";
+ break;
+
+ case "JustifyCenter":
+ alignValue = "center";
+ break;
+
+ case "JustifyFull":
+ alignValue = "justify";
+ break;
+
+ case "JustifyRight":
+ alignValue = "right";
+ break;
+ }
+
+ if (alignValue !== '') {
+ var rng = doc.selection.createRange();
+
+ if ((divElm = tinyMCE.getParentElement(rng.parentElement(), "div")) != null)
+ divElm.setAttribute("align", alignValue);
+ else if (rng.pasteHTML && rng.htmlText.length > 0)
+ rng.pasteHTML('<div align="' + alignValue + '">' + rng.htmlText + "</div>");
+
+ tinyMCE.triggerNodeChange();
+ return;
+ }
+ }
+ }
+
+ switch (command) {
+ case "mceRepaint":
+ this.repaint();
+ return true;
+
+ case "unlink":
+ // Unlink if caret is inside link
+ if (tinyMCE.isGecko && this.getSel().isCollapsed) {
+ focusElm = tinyMCE.getParentElement(focusElm, 'A');
+
+ if (focusElm)
+ this.selection.selectNode(focusElm, false);
+ }
+
+ this.getDoc().execCommand(command, user_interface, value);
+
+ tinyMCE.isGecko && this.getSel().collapseToEnd();
+
+ tinyMCE.triggerNodeChange();
+
+ return true;
+
+ case "InsertUnorderedList":
+ case "InsertOrderedList":
+ this.getDoc().execCommand(command, user_interface, value);
+ tinyMCE.triggerNodeChange();
+ break;
+
+ case "Strikethrough":
+ this.getDoc().execCommand(command, user_interface, value);
+ tinyMCE.triggerNodeChange();
+ break;
+
+ case "mceSelectNode":
+ this.selection.selectNode(value);
+ tinyMCE.triggerNodeChange();
+ tinyMCE.selectedNode = value;
+ break;
+
+ case "FormatBlock":
+ if (value == null || value == '') {
+ var elm = tinyMCE.getParentElement(this.getFocusElement(), "p,div,h1,h2,h3,h4,h5,h6,pre,address,blockquote,dt,dl,dd,samp");
+
+ if (elm)
+ this.execCommand("mceRemoveNode", false, elm);
+ } else {
+ if (!this.cleanup.isValid(value))
+ return true;
+
+ if (tinyMCE.isGecko && new RegExp('<(div|blockquote|code|dt|dd|dl|samp)>', 'gi').test(value))
+ value = value.replace(/[^a-z]/gi, '');
+
+ if (tinyMCE.isIE && new RegExp('blockquote|code|samp', 'gi').test(value)) {
+ var b = this.selection.getBookmark();
+ this.getDoc().execCommand("FormatBlock", false, '<p>');
+ tinyMCE.renameElement(tinyMCE.getParentBlockElement(this.getFocusElement()), value);
+ this.selection.moveToBookmark(b);
+ } else
+ this.getDoc().execCommand("FormatBlock", false, value);
+ }
+
+ tinyMCE.triggerNodeChange();
+
+ break;
+
+ case "mceRemoveNode":
+ if (!value)
+ value = tinyMCE.getParentElement(this.getFocusElement());
+
+ if (tinyMCE.isIE) {
+ value.outerHTML = value.innerHTML;
+ } else {
+ var rng = value.ownerDocument.createRange();
+ rng.setStartBefore(value);
+ rng.setEndAfter(value);
+ rng.deleteContents();
+ rng.insertNode(rng.createContextualFragment(value.innerHTML));
+ }
+
+ tinyMCE.triggerNodeChange();
+
+ break;
+
+ case "mceSelectNodeDepth":
+ var parentNode = this.getFocusElement();
+ for (i=0; parentNode; i++) {
+ if (parentNode.nodeName.toLowerCase() == "body")
+ break;
+
+ if (parentNode.nodeName.toLowerCase() == "#text") {
+ i--;
+ parentNode = parentNode.parentNode;
+ continue;
+ }
+
+ if (i == value) {
+ this.selection.selectNode(parentNode, false);
+ tinyMCE.triggerNodeChange();
+ tinyMCE.selectedNode = parentNode;
+ return;
+ }
+
+ parentNode = parentNode.parentNode;
+ }
+
+ break;
+
+ case "mceSetStyleInfo":
+ case "SetStyleInfo":
+ var rng = this.getRng();
+ var sel = this.getSel();
+ var scmd = value.command;
+ var sname = value.name;
+ var svalue = value.value == null ? '' : value.value;
+ //var svalue = value['value'] == null ? '' : value['value'];
+ var wrapper = value.wrapper ? value.wrapper : "span";
+ var parentElm = null;
+ var invalidRe = new RegExp("^BODY|HTML$", "g");
+ var invalidParentsRe = tinyMCE.settings.merge_styles_invalid_parents !== '' ? new RegExp(tinyMCE.settings.merge_styles_invalid_parents, "gi") : null;
+
+ // Whole element selected check
+ if (tinyMCE.isIE) {
+ // Control range
+ if (rng.item)
+ parentElm = rng.item(0);
+ else {
+ var pelm = rng.parentElement();
+ var prng = doc.selection.createRange();
+ prng.moveToElementText(pelm);
+
+ if (rng.htmlText == prng.htmlText || rng.boundingWidth == 0) {
+ if (invalidParentsRe == null || !invalidParentsRe.test(pelm.nodeName))
+ parentElm = pelm;
+ }
+ }
+ } else {
+ var felm = this.getFocusElement();
+ if (sel.isCollapsed || (new RegExp('td|tr|tbody|table|img', 'gi').test(felm.nodeName) && sel.anchorNode == felm.parentNode))
+ parentElm = felm;
+ }
+
+ // Whole element selected
+ if (parentElm && !invalidRe.test(parentElm.nodeName)) {
+ if (scmd == "setstyle")
+ tinyMCE.setStyleAttrib(parentElm, sname, svalue);
+
+ if (scmd == "setattrib")
+ tinyMCE.setAttrib(parentElm, sname, svalue);
+
+ if (scmd == "removeformat") {
+ parentElm.style.cssText = '';
+ tinyMCE.setAttrib(parentElm, 'class', '');
+ }
+
+ // Remove style/attribs from all children
+ var ch = tinyMCE.getNodeTree(parentElm, [], 1);
+ for (z=0; z<ch.length; z++) {
+ if (ch[z] == parentElm)
+ continue;
+
+ if (scmd == "setstyle")
+ tinyMCE.setStyleAttrib(ch[z], sname, '');
+
+ if (scmd == "setattrib")
+ tinyMCE.setAttrib(ch[z], sname, '');
+
+ if (scmd == "removeformat") {
+ ch[z].style.cssText = '';
+ tinyMCE.setAttrib(ch[z], 'class', '');
+ }
+ }
+ } else {
+ this._setUseCSS(false); // Bug in FF when running in fullscreen
+ doc.execCommand("FontName", false, "#mce_temp_font#");
+ var elementArray = tinyMCE.getElementsByAttributeValue(this.getBody(), "font", "face", "#mce_temp_font#");
+
+ // Change them all
+ for (x=0; x<elementArray.length; x++) {
+ elm = elementArray[x];
+ if (elm) {
+ var spanElm = doc.createElement(wrapper);
+
+ if (scmd == "setstyle")
+ tinyMCE.setStyleAttrib(spanElm, sname, svalue);
+
+ if (scmd == "setattrib")
+ tinyMCE.setAttrib(spanElm, sname, svalue);
+
+ if (scmd == "removeformat") {
+ spanElm.style.cssText = '';
+ tinyMCE.setAttrib(spanElm, 'class', '');
+ }
+
+ if (elm.hasChildNodes()) {
+ for (i=0; i<elm.childNodes.length; i++)
+ spanElm.appendChild(elm.childNodes[i].cloneNode(true));
+ }
+
+ spanElm.setAttribute("mce_new", "true");
+ elm.parentNode.replaceChild(spanElm, elm);
+
+ // Remove style/attribs from all children
+ var ch = tinyMCE.getNodeTree(spanElm, [], 1);
+ for (z=0; z<ch.length; z++) {
+ if (ch[z] == spanElm)
+ continue;
+
+ if (scmd == "setstyle")
+ tinyMCE.setStyleAttrib(ch[z], sname, '');
+
+ if (scmd == "setattrib")
+ tinyMCE.setAttrib(ch[z], sname, '');
+
+ if (scmd == "removeformat") {
+ ch[z].style.cssText = '';
+ tinyMCE.setAttrib(ch[z], 'class', '');
+ }
+ }
+ }
+ }
+ }
+
+ // Cleaup wrappers
+ var nodes = doc.getElementsByTagName(wrapper);
+ for (i=nodes.length-1; i>=0; i--) {
+ var elm = nodes[i];
+ var isNew = tinyMCE.getAttrib(elm, "mce_new") == "true";
+
+ elm.removeAttribute("mce_new");
+
+ // Is only child a element
+ if (elm.childNodes && elm.childNodes.length == 1 && elm.childNodes[0].nodeType == 1) {
+ //tinyMCE.debug("merge1" + isNew);
+ this._mergeElements(scmd, elm, elm.childNodes[0], isNew);
+ continue;
+ }
+
+ // Is I the only child
+ if (elm.parentNode.childNodes.length == 1 && !invalidRe.test(elm.nodeName) && !invalidRe.test(elm.parentNode.nodeName)) {
+ //tinyMCE.debug("merge2" + isNew + "," + elm.nodeName + "," + elm.parentNode.nodeName);
+ if (invalidParentsRe == null || !invalidParentsRe.test(elm.parentNode.nodeName))
+ this._mergeElements(scmd, elm.parentNode, elm, false);
+ }
+ }
+
+ // Remove empty wrappers
+ var nodes = doc.getElementsByTagName(wrapper);
+ for (i=nodes.length-1; i>=0; i--) {
+ var elm = nodes[i], isEmpty = true;
+
+ // Check if it has any attribs
+ var tmp = doc.createElement("body");
+ tmp.appendChild(elm.cloneNode(false));
+
+ // Is empty span, remove it
+ tmp.innerHTML = tmp.innerHTML.replace(new RegExp('style=""|class=""', 'gi'), '');
+ //tinyMCE.debug(tmp.innerHTML);
+ if (new RegExp('<span>', 'gi').test(tmp.innerHTML)) {
+ for (x=0; x<elm.childNodes.length; x++) {
+ if (elm.parentNode != null)
+ elm.parentNode.insertBefore(elm.childNodes[x].cloneNode(true), elm);
+ }
+
+ elm.parentNode.removeChild(elm);
+ }
+ }
+
+ // Re add the visual aids
+ if (scmd == "removeformat")
+ tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
+
+ tinyMCE.triggerNodeChange();
+
+ break;
+
+ case "FontName":
+ if (value == null) {
+ var s = this.getSel();
+
+ // Find font and select it
+ if (tinyMCE.isGecko && s.isCollapsed) {
+ var f = tinyMCE.getParentElement(this.getFocusElement(), "font");
+
+ if (f != null)
+ this.selection.selectNode(f, false);
+ }
+
+ // Remove format
+ this.getDoc().execCommand("RemoveFormat", false, null);
+
+ // Collapse range if font was found
+ if (f != null && tinyMCE.isGecko) {
+ var r = this.getRng().cloneRange();
+ r.collapse(true);
+ s.removeAllRanges();
+ s.addRange(r);
+ }
+ } else
+ this.getDoc().execCommand('FontName', false, value);
+
+ if (tinyMCE.isGecko)
+ window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
+
+ return;
+
+ case "FontSize":
+ this.getDoc().execCommand('FontSize', false, value);
+
+ if (tinyMCE.isGecko)
+ window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
+
+ return;
+
+ case "forecolor":
+ value = value == null ? this.foreColor : value;
+ value = tinyMCE.trim(value);
+ value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value;
+
+ this.foreColor = value;
+ this.getDoc().execCommand('forecolor', false, value);
+ break;
+
+ case "HiliteColor":
+ value = value == null ? this.backColor : value;
+ value = tinyMCE.trim(value);
+ value = value.charAt(0) != '#' ? (isNaN('0x' + value) ? value : '#' + value) : value;
+ this.backColor = value;
+
+ if (tinyMCE.isGecko) {
+ this._setUseCSS(true);
+ this.getDoc().execCommand('hilitecolor', false, value);
+ this._setUseCSS(false);
+ } else
+ this.getDoc().execCommand('BackColor', false, value);
+ break;
+
+ case "Cut":
+ case "Copy":
+ case "Paste":
+ var cmdFailed = false;
+
+ // Try executing command
+ eval('try {this.getDoc().execCommand(command, user_interface, value);} catch (e) {cmdFailed = true;}');
+
+ if (tinyMCE.isOpera && cmdFailed)
+ alert('Currently not supported by your browser, use keyboard shortcuts instead.');
+
+ // Alert error in gecko if command failed
+ if (tinyMCE.isGecko && cmdFailed) {
+ // Confirm more info
+ if (confirm(tinyMCE.entityDecode(tinyMCE.getLang('lang_clipboard_msg'))))
+ window.open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', 'mceExternal');
+
+ return;
+ } else
+ tinyMCE.triggerNodeChange();
+ break;
+
+ case "mceSetContent":
+ if (!value)
+ value = "";
+
+ // Call custom cleanup code
+ value = tinyMCE.storeAwayURLs(value);
+ value = tinyMCE._customCleanup(this, "insert_to_editor", value);
+
+ if (this.getBody().nodeName == 'BODY')
+ tinyMCE._setHTML(doc, value);
+ else
+ this.getBody().innerHTML = value;
+
+ tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, doc, this.settings, this.getBody(), false, false, false, true));
+ tinyMCE.convertAllRelativeURLs(this.getBody());
+
+ // Cleanup any mess left from storyAwayURLs
+ tinyMCE._removeInternal(this.getBody());
+
+ // When editing always use fonts internaly
+ if (tinyMCE.getParam("convert_fonts_to_spans"))
+ tinyMCE.convertSpansToFonts(doc);
+
+ tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
+ tinyMCE._setEventsEnabled(this.getBody(), false);
+ this._addBogusBR();
+
+ return true;
+
+ case "mceCleanup":
+ var b = this.selection.getBookmark();
+ tinyMCE._setHTML(this.contentDocument, this.getBody().innerHTML);
+ tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, this.contentDocument, this.settings, this.getBody(), this.visualAid));
+ tinyMCE.convertAllRelativeURLs(doc.body);
+
+ // When editing always use fonts internaly
+ if (tinyMCE.getParam("convert_fonts_to_spans"))
+ tinyMCE.convertSpansToFonts(doc);
+
+ tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
+ tinyMCE._setEventsEnabled(this.getBody(), false);
+ this._addBogusBR();
+ this.repaint();
+ this.selection.moveToBookmark(b);
+ tinyMCE.triggerNodeChange();
+ break;
+
+ case "mceReplaceContent":
+ // Force empty string
+ if (!value)
+ value = '';
+
+ this.getWin().focus();
+
+ var selectedText = "";
+
+ if (tinyMCE.isIE) {
+ var rng = doc.selection.createRange();
+ selectedText = rng.text;
+ } else
+ selectedText = this.getSel().toString();
+
+ if (selectedText.length > 0) {
+ value = tinyMCE.replaceVar(value, "selection", selectedText);
+ tinyMCE.execCommand('mceInsertContent', false, value);
+ }
+
+ this._addBogusBR();
+ tinyMCE.triggerNodeChange();
+ break;
+
+ case "mceSetAttribute":
+ if (typeof(value) == 'object') {
+ var targetElms = (typeof(value.targets) == "undefined") ? "p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address" : value.targets;
+ var targetNode = tinyMCE.getParentElement(this.getFocusElement(), targetElms);
+
+ if (targetNode) {
+ targetNode.setAttribute(value.name, value.value);
+ tinyMCE.triggerNodeChange();
+ }
+ }
+ break;
+
+ case "mceSetCSSClass":
+ this.execCommand("mceSetStyleInfo", false, {command : "setattrib", name : "class", value : value});
+ break;
+
+ case "mceInsertRawHTML":
+ var key = 'tiny_mce_marker';
+
+ this.execCommand('mceBeginUndoLevel');
+
+ // Insert marker key
+ this.execCommand('mceInsertContent', false, key);
+
+ // Store away scroll pos
+ var scrollX = this.getBody().scrollLeft + this.getDoc().documentElement.scrollLeft;
+ var scrollY = this.getBody().scrollTop + this.getDoc().documentElement.scrollTop;
+
+ // Find marker and replace with RAW HTML
+ var html = this.getBody().innerHTML;
+ if ((pos = html.indexOf(key)) != -1)
+ tinyMCE.setInnerHTML(this.getBody(), html.substring(0, pos) + value + html.substring(pos + key.length));
+
+ // Restore scoll pos
+ this.contentWindow.scrollTo(scrollX, scrollY);
+
+ this.execCommand('mceEndUndoLevel');
+
+ break;
+
+ case "mceInsertContent":
+ // Force empty string
+ if (!value)
+ value = '';
+
+ var insertHTMLFailed = false;
+
+ // Removed since it produced problems in IE
+ // this.getWin().focus();
+
+ if (tinyMCE.isGecko || tinyMCE.isOpera) {
+ try {
+ // Is plain text or HTML, &, etc will be encoded wrong in FF
+ if (value.indexOf('<') == -1 && !value.match(/(&| |<|>)/g)) {
+ var r = this.getRng();
+ var n = this.getDoc().createTextNode(tinyMCE.entityDecode(value));
+ var s = this.getSel();
+ var r2 = r.cloneRange();
+
+ // Insert text at cursor position
+ s.removeAllRanges();
+ r.deleteContents();
+ r.insertNode(n);
+
+ // Move the cursor to the end of text
+ r2.selectNode(n);
+ r2.collapse(false);
+ s.removeAllRanges();
+ s.addRange(r2);
+ } else {
+ value = tinyMCE.fixGeckoBaseHREFBug(1, this.getDoc(), value);
+ this.getDoc().execCommand('inserthtml', false, value);
+ tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
+ }
+ } catch (ex) {
+ insertHTMLFailed = true;
+ }
+
+ if (!insertHTMLFailed) {
+ tinyMCE.triggerNodeChange();
+ return;
+ }
+ }
+
+ if (!tinyMCE.isIE) {
+ var isHTML = value.indexOf('<') != -1;
+ var sel = this.getSel();
+ var rng = this.getRng();
+
+ if (isHTML) {
+ if (tinyMCE.isSafari) {
+ var tmpRng = this.getDoc().createRange();
+
+ tmpRng.setStart(this.getBody(), 0);
+ tmpRng.setEnd(this.getBody(), 0);
+
+ value = tmpRng.createContextualFragment(value);
+ } else
+ value = rng.createContextualFragment(value);
+ } else {
+ // Setup text node
+ value = doc.createTextNode(tinyMCE.entityDecode(value));
+ }
+
+ // Insert plain text in Safari
+ if (tinyMCE.isSafari && !isHTML) {
+ this.execCommand('InsertText', false, value.nodeValue);
+ tinyMCE.triggerNodeChange();
+ return true;
+ } else if (tinyMCE.isSafari && isHTML) {
+ rng.deleteContents();
+ rng.insertNode(value);
+ tinyMCE.triggerNodeChange();
+ return true;
+ }
+
+ rng.deleteContents();
+
+ // If target node is text do special treatment, (Mozilla 1.3 fix)
+ if (rng.startContainer.nodeType == 3) {
+ var node = rng.startContainer.splitText(rng.startOffset);
+ node.parentNode.insertBefore(value, node);
+ } else
+ rng.insertNode(value);
+
+ if (!isHTML) {
+ // Removes weird selection trails
+ sel.selectAllChildren(doc.body);
+ sel.removeAllRanges();
+
+ // Move cursor to end of content
+ var rng = doc.createRange();
+
+ rng.selectNode(value);
+ rng.collapse(false);
+
+ sel.addRange(rng);
+ } else
+ rng.collapse(false);
+
+ tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
+ } else {
+ var rng = doc.selection.createRange(), tmpRng = null;
+ var c = value.indexOf('<!--') != -1;
+
+ // Fix comment bug, add tag before comments
+ if (c)
+ value = tinyMCE.uniqueTag + value;
+
+ // tmpRng = rng.duplicate(); // Store away range (Fixes Undo bookmark bug in IE)
+
+ if (rng.item)
+ rng.item(0).outerHTML = value;
+ else
+ rng.pasteHTML(value);
+
+ //if (tmpRng)
+ // tmpRng.select(); // Restore range (Fixes Undo bookmark bug in IE)
+
+ // Remove unique tag
+ if (c) {
+ var e = this.getDoc().getElementById('mceTMPElement');
+ e.parentNode.removeChild(e);
+ }
+ }
+
+ tinyMCE.execCommand("mceAddUndoLevel");
+ tinyMCE.triggerNodeChange();
+ break;
+
+ case "mceStartTyping":
+ if (tinyMCE.settings.custom_undo_redo && this.undoRedo.typingUndoIndex == -1) {
+ this.undoRedo.typingUndoIndex = this.undoRedo.undoIndex;
+ tinyMCE.typingUndoIndex = tinyMCE.undoIndex;
+ this.execCommand('mceAddUndoLevel');
+ }
+ break;
+
+ case "mceEndTyping":
+ if (tinyMCE.settings.custom_undo_redo && this.undoRedo.typingUndoIndex != -1) {
+ this.execCommand('mceAddUndoLevel');
+ this.undoRedo.typingUndoIndex = -1;
+ }
+
+ tinyMCE.typingUndoIndex = -1;
+ break;
+
+ case "mceBeginUndoLevel":
+ this.undoRedoLevel = false;
+ break;
+
+ case "mceEndUndoLevel":
+ this.undoRedoLevel = true;
+ this.execCommand('mceAddUndoLevel');
+ break;
+
+ case "mceAddUndoLevel":
+ if (tinyMCE.settings.custom_undo_redo && this.undoRedoLevel) {
+ if (this.undoRedo.add())
+ tinyMCE.triggerNodeChange(false);
+ }
+ break;
+
+ case "Undo":
+ if (tinyMCE.settings.custom_undo_redo) {
+ tinyMCE.execCommand("mceEndTyping");
+ this.undoRedo.undo();
+ tinyMCE.triggerNodeChange();
+ } else
+ this.getDoc().execCommand(command, user_interface, value);
+ break;
+
+ case "Redo":
+ if (tinyMCE.settings.custom_undo_redo) {
+ tinyMCE.execCommand("mceEndTyping");
+ this.undoRedo.redo();
+ tinyMCE.triggerNodeChange();
+ } else
+ this.getDoc().execCommand(command, user_interface, value);
+ break;
+
+ case "mceToggleVisualAid":
+ this.visualAid = !this.visualAid;
+ tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
+ tinyMCE.triggerNodeChange();
+ break;
+
+ case "Indent":
+ this.getDoc().execCommand(command, user_interface, value);
+ tinyMCE.triggerNodeChange();
+
+ if (tinyMCE.isIE) {
+ var n = tinyMCE.getParentElement(this.getFocusElement(), "blockquote");
+ do {
+ if (n && n.nodeName == "BLOCKQUOTE") {
+ n.removeAttribute("dir");
+ n.removeAttribute("style");
+ }
+ } while (n != null && (n = n.parentNode) != null);
+ }
+ break;
+
+ case "RemoveFormat":
+ case "removeformat":
+ var text = this.selection.getSelectedText();
+
+ if (tinyMCE.isOpera) {
+ this.getDoc().execCommand("RemoveFormat", false, null);
+ return;
+ }
+
+ if (tinyMCE.isIE) {
+ try {
+ var rng = doc.selection.createRange();
+ rng.execCommand("RemoveFormat", false, null);
+ } catch (e) {
+ // Do nothing
+ }
+
+ this.execCommand("mceSetStyleInfo", false, {command : "removeformat"});
+ } else {
+ this.getDoc().execCommand(command, user_interface, value);
+
+ this.execCommand("mceSetStyleInfo", false, {command : "removeformat"});
+ }
+
+ // Remove class
+ if (text.length == 0)
+ this.execCommand("mceSetCSSClass", false, "");
+
+ tinyMCE.triggerNodeChange();
+ break;
+
+ default:
+ this.getDoc().execCommand(command, user_interface, value);
+
+ if (tinyMCE.isGecko)
+ window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
+ else
+ tinyMCE.triggerNodeChange();
+ }
+
+ // Add undo level after modification
+ if (command != "mceAddUndoLevel" && command != "Undo" && command != "Redo" && command != "mceStartTyping" && command != "mceEndTyping")
+ tinyMCE.execCommand("mceAddUndoLevel");
+ },
+
+ queryCommandValue : function(c) {
+ try {
+ return this.getDoc().queryCommandValue(c);
+ } catch (e) {
+ return null;
+ }
+ },
+
+ queryCommandState : function(c) {
+ return this.getDoc().queryCommandState(c);
+ },
+
+ _addBogusBR : function() {
+ var b = this.getBody();
+
+ if (tinyMCE.isGecko && !b.hasChildNodes())
+ b.innerHTML = '<br _moz_editor_bogus_node="TRUE" />';
+ },
+
+ _onAdd : function(replace_element, form_element_name, target_document) {
+ var hc, th, tos, editorTemplate, targetDoc, deltaWidth, deltaHeight, html, rng, fragment;
+ var dynamicIFrame, tElm, doc, parentElm;
+
+ th = this.settings.theme;
+ tos = tinyMCE.themes[th];
+
+ targetDoc = target_document ? target_document : document;
+
+ this.targetDoc = targetDoc;
+
+ tinyMCE.themeURL = tinyMCE.baseURL + "/themes/" + this.settings.theme;
+ this.settings.themeurl = tinyMCE.themeURL;
+
+ if (!replace_element) {
+ alert("Error: Could not find the target element.");
+ return false;
+ }
+
+ if (tos.getEditorTemplate)
+ editorTemplate = tos.getEditorTemplate(this.settings, this.editorId);
+
+ deltaWidth = editorTemplate.delta_width ? editorTemplate.delta_width : 0;
+ deltaHeight = editorTemplate.delta_height ? editorTemplate.delta_height : 0;
+ html = '<span id="' + this.editorId + '_parent" class="mceEditorContainer">' + editorTemplate.html;
+
+ html = tinyMCE.replaceVar(html, "editor_id", this.editorId);
+
+ if (!this.settings.default_document)
+ this.settings.default_document = tinyMCE.baseURL + "/blank.htm";
+
+ this.settings.old_width = this.settings.width;
+ this.settings.old_height = this.settings.height;
+
+ // Set default width, height
+ if (this.settings.width == -1)
+ this.settings.width = replace_element.offsetWidth;
+
+ if (this.settings.height == -1)
+ this.settings.height = replace_element.offsetHeight;
+
+ // Try the style width
+ if (this.settings.width == 0)
+ this.settings.width = replace_element.style.width;
+
+ // Try the style height
+ if (this.settings.height == 0)
+ this.settings.height = replace_element.style.height;
+
+ // If no width/height then default to 320x240, better than nothing
+ if (this.settings.width == 0)
+ this.settings.width = 320;
+
+ if (this.settings.height == 0)
+ this.settings.height = 240;
+
+ this.settings.area_width = parseInt(this.settings.width);
+ this.settings.area_height = parseInt(this.settings.height);
+ this.settings.area_width += deltaWidth;
+ this.settings.area_height += deltaHeight;
+ this.settings.width_style = "" + this.settings.width;
+ this.settings.height_style = "" + this.settings.height;
+
+ // Special % handling
+ if (("" + this.settings.width).indexOf('%') != -1)
+ this.settings.area_width = "100%";
+ else
+ this.settings.width_style += 'px';
+
+ if (("" + this.settings.height).indexOf('%') != -1)
+ this.settings.area_height = "100%";
+ else
+ this.settings.height_style += 'px';
+
+ if (("" + replace_element.style.width).indexOf('%') != -1) {
+ this.settings.width = replace_element.style.width;
+ this.settings.area_width = "100%";
+ this.settings.width_style = "100%";
+ }
+
+ if (("" + replace_element.style.height).indexOf('%') != -1) {
+ this.settings.height = replace_element.style.height;
+ this.settings.area_height = "100%";
+ this.settings.height_style = "100%";
+ }
+
+ html = tinyMCE.applyTemplate(html);
+
+ this.settings.width = this.settings.old_width;
+ this.settings.height = this.settings.old_height;
+
+ this.visualAid = this.settings.visual;
+ this.formTargetElementId = form_element_name;
+
+ // Get replace_element contents
+ if (replace_element.nodeName == "TEXTAREA" || replace_element.nodeName == "INPUT")
+ this.startContent = replace_element.value;
+ else
+ this.startContent = replace_element.innerHTML;
+
+ // If not text area or input
+ if (replace_element.nodeName != "TEXTAREA" && replace_element.nodeName != "INPUT") {
+ this.oldTargetElement = replace_element;
+
+ // Debug mode
+ hc = '<input type="hidden" id="' + form_element_name + '" name="' + form_element_name + '" />';
+ this.oldTargetDisplay = tinyMCE.getStyle(this.oldTargetElement, 'display', 'inline');
+ this.oldTargetElement.style.display = "none";
+
+ html += '</span>';
+
+ if (tinyMCE.isGecko)
+ html = hc + html;
+ else
+ html += hc;
+
+ // Output HTML and set editable
+ if (tinyMCE.isGecko) {
+ rng = replace_element.ownerDocument.createRange();
+ rng.setStartBefore(replace_element);
+
+ fragment = rng.createContextualFragment(html);
+ tinyMCE.insertAfter(fragment, replace_element);
+ } else
+ replace_element.insertAdjacentHTML("beforeBegin", html);
+ } else {
+ html += '</span>';
+
+ // Just hide the textarea element
+ this.oldTargetElement = replace_element;
+
+ this.oldTargetDisplay = tinyMCE.getStyle(this.oldTargetElement, 'display', 'inline');
+ this.oldTargetElement.style.display = "none";
+
+ // Output HTML and set editable
+ if (tinyMCE.isGecko) {
+ rng = replace_element.ownerDocument.createRange();
+ rng.setStartBefore(replace_element);
+
+ fragment = rng.createContextualFragment(html);
+ tinyMCE.insertAfter(fragment, replace_element);
+ } else
+ replace_element.insertAdjacentHTML("beforeBegin", html);
+ }
+
+ // Setup iframe
+ dynamicIFrame = false;
+ tElm = targetDoc.getElementById(this.editorId);
+
+ if (!tinyMCE.isIE) {
+ // Node case is preserved in XML strict mode
+ if (tElm && (tElm.nodeName == "SPAN" || tElm.nodeName == "span")) {
+ tElm = tinyMCE._createIFrame(tElm, targetDoc);
+ dynamicIFrame = true;
}
- // Add nbsp to some elements
- if ((elementName == "p" || elementName == "td") && (node.innerHTML == "" || node.innerHTML == " "))
- return "<" + elementName + elementAttribs + ">" + this.convertStringToXML(String.fromCharCode(160)) + "</" + elementName + ">";
-
- // Is MSIE script element
- if (tinyMCE.isMSIE && elementName == "script")
- return "<" + elementName + elementAttribs + ">" + node.text + "</" + elementName + ">";
-
- // Clean up children
- if (node.hasChildNodes()) {
- // If not empty span
- if (!(elementName == "span" && elementAttribs == "" && tinyMCE.getParam("trim_span_elements"))) {
- // Force BR
- if (elementName == "p" && tinyMCE.cleanup_force_br_newlines)
- output += "<div" + elementAttribs + ">";
- else
- output += "<" + elementName + elementAttribs + ">";
- }
+ this.targetElement = tElm;
+ this.iframeElement = tElm;
+ this.contentDocument = tElm.contentDocument;
+ this.contentWindow = tElm.contentWindow;
+
+ //this.getDoc().designMode = "on";
+ } else {
+ if (tElm && tElm.nodeName == "SPAN")
+ tElm = tinyMCE._createIFrame(tElm, targetDoc, targetDoc.parentWindow);
+ else
+ tElm = targetDoc.frames[this.editorId];
- for (var i=0; i<node.childNodes.length; i++)
- output += this.cleanupNode(node.childNodes[i]);
+ this.targetElement = tElm;
+ this.iframeElement = targetDoc.getElementById(this.editorId);
- // If not empty span
- if (!(elementName == "span" && elementAttribs == "" && tinyMCE.getParam("trim_span_elements"))) {
- // Force BR
- if (elementName == "p" && tinyMCE.cleanup_force_br_newlines)
- output += "</div><br />";
- else
- output += "</" + elementName + ">";
- }
+ if (tinyMCE.isOpera) {
+ this.contentDocument = this.iframeElement.contentDocument;
+ this.contentWindow = this.iframeElement.contentWindow;
+ dynamicIFrame = true;
} else {
- if (!nonEmptyTag) {
- if (openTag)
- output += "<" + elementName + elementAttribs + "></" + elementName + ">";
- else
- output += "<" + elementName + elementAttribs + " />";
- }
+ this.contentDocument = tElm.window.document;
+ this.contentWindow = tElm.window;
}
- return output;
+ this.getDoc().designMode = "on";
+ }
- case 3: // Text
- // Do not convert script elements
- if (node.parentNode.nodeName == "SCRIPT" || node.parentNode.nodeName == "NOSCRIPT" || node.parentNode.nodeName == "STYLE")
- return node.nodeValue;
+ // Setup base HTML
+ doc = this.contentDocument;
+ if (dynamicIFrame) {
+ 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>';
+
+ try {
+ if (!this.isHidden())
+ this.getDoc().designMode = "on";
+
+ doc.open();
+ doc.write(html);
+ doc.close();
+ } catch (e) {
+ // Failed Mozilla 1.3
+ this.getDoc().location.href = tinyMCE.baseURL + "/blank.htm";
+ }
+ }
- return this.convertStringToXML(node.nodeValue);
+ // This timeout is needed in MSIE 5.5 for some odd reason
+ // it seems that the document.frames isn't initialized yet?
+ if (tinyMCE.isIE)
+ window.setTimeout("tinyMCE.addEventHandlers(tinyMCE.instances[\"" + this.editorId + "\"]);", 1);
- case 8: // Comment
- return "<!--" + node.nodeValue + "-->";
+ // Setup element references
+ parentElm = this.targetDoc.getElementById(this.editorId + '_parent');
+ this.formElement = tinyMCE.isGecko ? parentElm.previousSibling : parentElm.nextSibling;
- default: // Unknown
- return "[UNKNOWN NODETYPE " + node.nodeType + "]";
- }
-};
+ tinyMCE.setupContent(this.editorId, true);
-TinyMCE.prototype.convertStringToXML = function(html_data) {
- var output = "";
+ return true;
+ },
- for (var i=0; i<html_data.length; i++) {
- var chr = html_data.charCodeAt(i);
+ setBaseHREF : function(u) {
+ var h, b, d, nl;
- // Numeric entities
- if (tinyMCE.settings['entity_encoding'] == "numeric") {
- if (chr > 127)
- output += '&#' + chr + ";";
- else
- output += String.fromCharCode(chr);
+ d = this.getDoc();
+ nl = d.getElementsByTagName("base");
+ b = nl.length > 0 ? nl[0] : null;
- continue;
- }
+ if (!b) {
+ nl = d.getElementsByTagName("head");
+ h = nl.length > 0 ? nl[0] : null;
- // Raw entities
- if (tinyMCE.settings['entity_encoding'] == "raw") {
- output += String.fromCharCode(chr);
- continue;
+ b = d.createElement("base");
+ b.setAttribute('href', u);
+ h.appendChild(b);
+ } else {
+ if (u == '' || u == null)
+ b.parentNode.removeChild(b);
+ else
+ b.setAttribute('href', u);
}
+ },
- // Named entities
- if (typeof(tinyMCE.settings['cleanup_entities']["c" + chr]) != 'undefined' && tinyMCE.settings['cleanup_entities']["c" + chr] != '')
- output += '&' + tinyMCE.settings['cleanup_entities']["c" + chr] + ';';
- else
- output += '' + String.fromCharCode(chr);
- }
+ getHTML : function(r) {
+ var h, d = this.getDoc(), b = this.getBody();
- return output;
-};
+ if (r)
+ return b.innerHTML;
-TinyMCE.prototype._getCleanupElementName = function(chunk) {
- var pos;
+ h = tinyMCE._cleanupHTML(this, d, this.settings, b, false, true, false, true);
- if (chunk.charAt(0) == '+')
- chunk = chunk.substring(1);
+ if (tinyMCE.getParam("convert_fonts_to_spans"))
+ tinyMCE.convertSpansToFonts(d);
- if (chunk.charAt(0) == '-')
- chunk = chunk.substring(1);
+ return h;
+ },
- if ((pos = chunk.indexOf('/')) != -1)
- chunk = chunk.substring(0, pos);
+ setHTML : function(h) {
+ this.execCommand('mceSetContent', false, h);
+ this.repaint();
+ },
- if ((pos = chunk.indexOf('[')) != -1)
- chunk = chunk.substring(0, pos);
+ getFocusElement : function() {
+ return this.selection.getFocusElement();
+ },
- return chunk;
-};
+ getSel : function() {
+ return this.selection.getSel();
+ },
-TinyMCE.prototype._initCleanup = function() {
- // Parse valid elements and attributes
- var validElements = tinyMCE.settings["valid_elements"];
- validElements = validElements.split(',');
-
- // Handle extended valid elements
- var extendedValidElements = tinyMCE.settings["extended_valid_elements"];
- extendedValidElements = extendedValidElements.split(',');
- for (var i=0; i<extendedValidElements.length; i++) {
- var elementName = this._getCleanupElementName(extendedValidElements[i]);
- var skipAdd = false;
-
- // Check if it's defined before, if so override that one
- for (var x=0; x<validElements.length; x++) {
- if (this._getCleanupElementName(validElements[x]) == elementName) {
- validElements[x] = extendedValidElements[i];
- skipAdd = true;
- break;
- }
- }
+ getRng : function() {
+ return this.selection.getRng();
+ },
- if (!skipAdd)
- validElements[validElements.length] = extendedValidElements[i];
- }
+ triggerSave : function(skip_cleanup, skip_callback) {
+ var e, nl = [], i, s, content, htm;
- for (var i=0; i<validElements.length; i++) {
- var item = validElements[i];
+ if (!this.enabled)
+ return;
+
+ this.switchSettings();
+ s = tinyMCE.settings;
- item = item.replace('[','|');
- item = item.replace(']','');
+ // Force hidden tabs visible while serializing
+ if (tinyMCE.isRealIE) {
+ e = this.iframeElement;
- // Split and convert
- var attribs = item.split('|');
- for (var x=0; x<attribs.length; x++)
- attribs[x] = attribs[x].toLowerCase();
+ do {
+ if (e.style && e.style.display == 'none') {
+ e.style.display = 'block';
+ nl[nl.length] = {elm : e, type : 'style'};
+ }
- // Handle change elements
- attribs[0] = attribs[0].split('/');
+ if (e.style && s.hidden_tab_class.length > 0 && e.className.indexOf(s.hidden_tab_class) != -1) {
+ e.className = s.display_tab_class;
+ nl[nl.length] = {elm : e, type : 'class'};
+ }
+ } while ((e = e.parentNode) != null)
+ }
- // Handle default attribute values
- for (var x=1; x<attribs.length; x++) {
- var attribName = attribs[x];
- var attribDefault = null;
- var attribForce = null;
- var attribMustBe = null;
+ tinyMCE.settings.preformatted = false;
- // Default value
- if ((pos = attribName.indexOf('=')) != -1) {
- attribDefault = attribName.substring(pos+1);
- attribName = attribName.substring(0, pos);
- }
+ // Default to false
+ if (typeof(skip_cleanup) == "undefined")
+ skip_cleanup = false;
- // Force check
- if ((pos = attribName.indexOf(':')) != -1) {
- attribForce = attribName.substring(pos+1);
- attribName = attribName.substring(0, pos);
- }
+ // Default to false
+ if (typeof(skip_callback) == "undefined")
+ skip_callback = false;
- // Force check
- if ((pos = attribName.indexOf('<')) != -1) {
- attribMustBe = attribName.substring(pos+1).split('?');
- attribName = attribName.substring(0, pos);
- }
+ tinyMCE._setHTML(this.getDoc(), this.getBody().innerHTML);
- attribs[x] = new Array(attribName, attribDefault, attribForce, attribMustBe);
+ // Remove visual aids when cleanup is disabled
+ if (this.settings.cleanup == false) {
+ tinyMCE.handleVisualAid(this.getBody(), true, false, this);
+ tinyMCE._setEventsEnabled(this.getBody(), true);
}
- validElements[i] = attribs;
- }
+ tinyMCE._customCleanup(this, "submit_content_dom", this.contentWindow.document.body);
+ htm = skip_cleanup ? this.getBody().innerHTML : tinyMCE._cleanupHTML(this, this.getDoc(), this.settings, this.getBody(), tinyMCE.visualAid, true, true);
+ htm = tinyMCE._customCleanup(this, "submit_content", htm);
- var invalidElements = tinyMCE.settings['invalid_elements'].split(',');
- for (var i=0; i<invalidElements.length; i++)
- invalidElements[i] = invalidElements[i].toLowerCase();
+ if (!skip_callback && tinyMCE.settings.save_callback !== '')
+ content = tinyMCE.resolveDots(tinyMCE.settings.save_callback, window)(this.formTargetElementId,htm,this.getBody());
- // Set these for performance
- tinyMCE.settings['cleanup_validElements'] = validElements;
- tinyMCE.settings['cleanup_invalidElements'] = invalidElements;
-};
+ // Use callback content if available
+ if ((typeof(content) != "undefined") && content != null)
+ htm = content;
-TinyMCE.prototype._cleanupHTML = function(inst, doc, config, element, visual, on_save) {
- if (!tinyMCE.settings['cleanup']) {
- tinyMCE.handleVisualAid(inst.getBody(), true, false, inst);
+ // Replace some weird entities (Bug: #1056343)
+ htm = tinyMCE.regexpReplace(htm, "(", "(", "gi");
+ htm = tinyMCE.regexpReplace(htm, ")", ")", "gi");
+ htm = tinyMCE.regexpReplace(htm, ";", ";", "gi");
+ htm = tinyMCE.regexpReplace(htm, """, """, "gi");
+ htm = tinyMCE.regexpReplace(htm, "^", "^", "gi");
- var html = element.innerHTML;
+ if (this.formElement)
+ this.formElement.value = htm;
- // Remove mce_href/mce_src
- html = html.replace(new RegExp('(mce_href|mce_src)=".*?"', 'gi'), '');
- html = html.replace(/\s+>/gi, '>');
+ if (tinyMCE.isSafari && this.formElement)
+ this.formElement.innerText = htm;
- return html;
+ // Hide them again (tabs in MSIE)
+ for (i=0; i<nl.length; i++) {
+ if (nl[i].type == 'style')
+ nl[i].elm.style.display = 'none';
+ else
+ nl[i].elm.className = s.hidden_tab_class;
+ }
}
- if (on_save && tinyMCE.getParam("convert_fonts_to_spans"))
- tinyMCE.convertFontsToSpans(doc);
+ };
- // Call custom cleanup code
- tinyMCE._customCleanup(inst, on_save ? "get_from_editor_dom" : "insert_to_editor_dom", doc.body);
+/* file:jscripts/tiny_mce/classes/TinyMCE_Cleanup.class.js */
- // Move bgcolor to style
- var n = doc.getElementsByTagName("font");
- for (var i=0; i<n.length; i++) {
- var c = "";
- if ((c = tinyMCE.getAttrib(n[i], "bgcolor")) != "") {
- n[i].style.backgroundColor = c;
- tinyMCE.setAttrib(n[i], "bgcolor", "");
- }
- }
+tinyMCE.add(TinyMCE_Engine, {
+ cleanupHTMLCode : function(s) {
+ s = s.replace(new RegExp('<p \\/>', 'gi'), '<p> </p>');
+ s = s.replace(new RegExp('<p>\\s*<\\/p>', 'gi'), '<p> </p>');
- // Set these for performance
- tinyMCE.cleanup_validElements = tinyMCE.settings['cleanup_validElements'];
- tinyMCE.cleanup_invalidElements = tinyMCE.settings['cleanup_invalidElements'];
- tinyMCE.cleanup_verify_html = tinyMCE.settings['verify_html'];
- tinyMCE.cleanup_force_br_newlines = tinyMCE.settings['force_br_newlines'];
- tinyMCE.cleanup_urlconverter_callback = tinyMCE.settings['urlconverter_callback'];
- tinyMCE.cleanup_verify_css_classes = tinyMCE.settings['verify_css_classes'];
- tinyMCE.cleanup_visual_table_class = tinyMCE.settings['visual_table_class'];
- tinyMCE.cleanup_apply_source_formatting = tinyMCE.settings['apply_source_formatting'];
- tinyMCE.cleanup_inline_styles = tinyMCE.settings['inline_styles'];
- tinyMCE.cleanup_visual_aid = visual;
- tinyMCE.cleanup_on_save = on_save;
- tinyMCE.cleanup_idCount = 0;
- tinyMCE.cleanup_elementLookupTable = new Array();
-
- var startTime = new Date().getTime();
-
- // Cleanup madness that breaks the editor in MSIE
- if (tinyMCE.isMSIE) {
- // Remove null ids from HR elements, results in runtime error
- var nodes = element.getElementsByTagName("hr");
- for (var i=0; i<nodes.length; i++) {
- if (nodes[i].id == "null")
- nodes[i].removeAttribute("id");
- }
-
- tinyMCE.setInnerHTML(element, tinyMCE.regexpReplace(element.innerHTML, '<p>[ \n\r]*<hr.*>[ \n\r]*</p>', '<hr />', 'gi'));
- tinyMCE.setInnerHTML(element, tinyMCE.regexpReplace(element.innerHTML, '<!([^-(DOCTYPE)]* )|<!/[^-]*>', '', 'gi'));
- }
+ // Fix close BR elements
+ s = s.replace(new RegExp('<br>\\s*<\\/br>', 'gi'), '<br />');
- var html = this.cleanupNode(element);
+ // Open closed tags like <b/> to <b></b>
+ 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>');
- if (tinyMCE.settings['debug'])
- tinyMCE.debug("Cleanup process executed in: " + (new Date().getTime()-startTime) + " ms.");
+ // Remove trailing space <b > to <b>
+ s = s.replace(new RegExp('\\s+></', 'gi'), '></');
- // Remove pesky HR paragraphs and other crap
- html = tinyMCE.regexpReplace(html, '<p><hr /></p>', '<hr />');
- html = tinyMCE.regexpReplace(html, '<p> </p><hr /><p> </p>', '<hr />');
- html = tinyMCE.regexpReplace(html, '<td>\\s*<br />\\s*</td>', '<td> </td>');
- html = tinyMCE.regexpReplace(html, '<p>\\s*<br />\\s*</p>', '<p> </p>');
- html = tinyMCE.regexpReplace(html, '<p>\\s* \\s*<br />\\s* \\s*</p>', '<p> </p>');
- html = tinyMCE.regexpReplace(html, '<p>\\s* \\s*<br />\\s*</p>', '<p> </p>');
- html = tinyMCE.regexpReplace(html, '<p>\\s*<br />\\s* \\s*</p>', '<p> </p>');
+ // Close tags <img></img> to <img/>
+ s = s.replace(new RegExp('<(img|br|hr)([^>]*)><\\/(img|br|hr)>', 'gi'), '<$1$2 />');
- // Remove empty anchors
- html = html.replace(new RegExp('<a>(.*?)</a>', 'gi'), '$1');
+ // Weird MSIE bug, <p><hr /></p> breaks runtime?
+ if (tinyMCE.isIE)
+ s = s.replace(new RegExp('<p><hr \\/><\\/p>', 'gi'), "<hr>");
- // Remove some mozilla crap
- if (!tinyMCE.isMSIE)
- html = html.replace(new RegExp('<o:p _moz-userdefined="" />', 'g'), "");
+ // Weird tags will make IE error #bug: 1538495
+ if (tinyMCE.isIE)
+ s = s.replace(/<!(\s*)\/>/g, '');
- if (tinyMCE.settings['remove_linebreaks'])
- html = html.replace(new RegExp('\r|\n', 'g'), ' ');
+ // Convert relative anchors to absolute URLs ex: #something to file.htm#something
+ // Removed: Since local document anchors should never be forced absolute example edit.php?id=something
+ //if (tinyMCE.getParam('convert_urls'))
+ // s = s.replace(new RegExp('(href=\"{0,1})(\\s*#)', 'gi'), '$1' + tinyMCE.settings.document_base_url + "#");
- if (tinyMCE.getParam('apply_source_formatting')) {
- html = html.replace(new RegExp('<(p|div)([^>]*)>', 'g'), "\n<$1$2>\n");
- html = html.replace(new RegExp('<\/(p|div)([^>]*)>', 'g'), "\n</$1$2>\n");
- html = html.replace(new RegExp('<br />', 'g'), "<br />\n");
- }
+ return s;
+ },
- if (tinyMCE.settings['force_br_newlines']) {
- var re = new RegExp('<p> </p>', 'g');
- html = html.replace(re, "<br />");
- }
+ parseStyle : function(str) {
+ var ar = [], st, i, re, pa;
- if (tinyMCE.isGecko && tinyMCE.settings['remove_lt_gt']) {
- // Remove weridness!
- var re = new RegExp('<>', 'g');
- html = html.replace(re, "");
- }
+ if (str == null)
+ return ar;
- // Call custom cleanup code
- html = tinyMCE._customCleanup(inst, on_save ? "get_from_editor" : "insert_to_editor", html);
+ st = str.split(';');
- // Emtpy node, return empty
- var chk = tinyMCE.regexpReplace(html, "[ \t\r\n]", "").toLowerCase();
- if (chk == "<br/>" || chk == "<br>" || chk == "<p> </p>" || chk == "<p> </p>" || chk == "<p></p>")
- html = "";
+ tinyMCE.clearArray(ar);
- if (tinyMCE.settings["preformatted"])
- return "<pre>" + html + "</pre>";
+ for (i=0; i<st.length; i++) {
+ if (st[i] == '')
+ continue;
- return html;
-};
+ re = new RegExp('^\\s*([^:]*):\\s*(.*)\\s*$');
+ pa = st[i].replace(re, '$1||$2').split('||');
+ //tinyMCE.debug(str, pa[0] + "=" + pa[1], st[i].replace(re, '$1||$2'));
+ if (pa.length == 2)
+ ar[pa[0].toLowerCase()] = pa[1];
+ }
+
+ return ar;
+ },
+
+ compressStyle : function(ar, pr, sf, res) {
+ var box = [], i, a;
-TinyMCE.prototype.insertLink = function(href, target, title, onclick, style_class) {
- tinyMCE.execCommand('mceBeginUndoLevel');
+ box[0] = ar[pr + '-top' + sf];
+ box[1] = ar[pr + '-left' + sf];
+ box[2] = ar[pr + '-right' + sf];
+ box[3] = ar[pr + '-bottom' + sf];
- if (this.selectedInstance && this.selectedElement && this.selectedElement.nodeName.toLowerCase() == "img") {
- var doc = this.selectedInstance.getDoc();
- var linkElement = tinyMCE.getParentElement(this.selectedElement, "a");
- var newLink = false;
+ for (i=0; i<box.length; i++) {
+ if (box[i] == null)
+ return;
- if (!linkElement) {
- linkElement = doc.createElement("a");
- newLink = true;
+ for (a=0; a<box.length; a++) {
+ if (box[a] != box[i])
+ return;
+ }
}
- var mhref = href;
- var thref = eval(tinyMCE.settings['urlconverter_callback'] + "(href, linkElement);");
- mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
+ // They are all the same
+ ar[res] = box[0];
+ ar[pr + '-top' + sf] = null;
+ ar[pr + '-left' + sf] = null;
+ ar[pr + '-right' + sf] = null;
+ ar[pr + '-bottom' + sf] = null;
+ },
+
+ serializeStyle : function(ar) {
+ var str = "", key, val, m;
+
+ // Compress box
+ tinyMCE.compressStyle(ar, "border", "", "border");
+ tinyMCE.compressStyle(ar, "border", "-width", "border-width");
+ tinyMCE.compressStyle(ar, "border", "-color", "border-color");
+ tinyMCE.compressStyle(ar, "border", "-style", "border-style");
+ tinyMCE.compressStyle(ar, "padding", "", "padding");
+ tinyMCE.compressStyle(ar, "margin", "", "margin");
+
+ for (key in ar) {
+ val = ar[key];
+
+ if (typeof(val) == 'function')
+ continue;
- tinyMCE.setAttrib(linkElement, 'href', thref);
- tinyMCE.setAttrib(linkElement, 'mce_href', mhref);
- tinyMCE.setAttrib(linkElement, 'target', target);
- tinyMCE.setAttrib(linkElement, 'title', title);
- tinyMCE.setAttrib(linkElement, 'onclick', onclick);
- tinyMCE.setAttrib(linkElement, 'class', style_class);
+ if (key.indexOf('mso-') == 0)
+ continue;
- if (newLink) {
- linkElement.appendChild(this.selectedElement.cloneNode(true));
- this.selectedElement.parentNode.replaceChild(linkElement, this.selectedElement);
- }
+ if (val != null && val !== '') {
+ val = '' + val; // Force string
- return;
- }
+ // Fix style URL
+ val = val.replace(new RegExp("url\\(\\'?([^\\']*)\\'?\\)", 'gi'), "url('$1')");
- if (!this.linkElement && this.selectedInstance) {
- if (tinyMCE.isSafari) {
- tinyMCE.execCommand("mceInsertContent", false, '<a href="' + tinyMCE.uniqueURL + '">' + this.selectedInstance.getSelectedHTML() + '</a>');
- } else
- this.selectedInstance.contentDocument.execCommand("createlink", false, tinyMCE.uniqueURL);
+ // Convert URL
+ if (val.indexOf('url(') != -1 && tinyMCE.getParam('convert_urls')) {
+ m = new RegExp("url\\('(.*?)'\\)").exec(val);
- tinyMCE.linkElement = this.getElementByAttributeValue(this.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);
+ if (m.length > 1)
+ val = "url('" + eval(tinyMCE.getParam('urlconverter_callback') + "(m[1], null, true);") + "')";
+ }
- var elementArray = this.getElementsByAttributeValue(this.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);
+ // Force HEX colors
+ if (tinyMCE.getParam("force_hex_style_colors"))
+ val = tinyMCE.convertRGBToHex(val, true);
- for (var i=0; i<elementArray.length; i++) {
- var mhref = href;
- var thref = eval(tinyMCE.settings['urlconverter_callback'] + "(href, elementArray[i]);");
- mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
+ val = val.replace(/\"/g, '\'');
- tinyMCE.setAttrib(elementArray[i], 'href', thref);
- tinyMCE.setAttrib(elementArray[i], 'mce_href', mhref);
- tinyMCE.setAttrib(elementArray[i], 'target', target);
- tinyMCE.setAttrib(elementArray[i], 'title', title);
- tinyMCE.setAttrib(elementArray[i], 'onclick', onclick);
- tinyMCE.setAttrib(elementArray[i], 'class', style_class);
+ if (val != "url('')")
+ str += key.toLowerCase() + ": " + val + "; ";
+ }
}
- tinyMCE.linkElement = elementArray[0];
- }
-
- if (this.linkElement) {
- var mhref = href;
- href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, this.linkElement);");
- mhref = tinyMCE.getParam('convert_urls') ? href : mhref;
-
- tinyMCE.setAttrib(this.linkElement, 'href', href);
- tinyMCE.setAttrib(this.linkElement, 'mce_href', mhref);
- tinyMCE.setAttrib(this.linkElement, 'target', target);
- tinyMCE.setAttrib(this.linkElement, 'title', title);
- tinyMCE.setAttrib(this.linkElement, 'onclick', onclick);
- tinyMCE.setAttrib(this.linkElement, 'class', style_class);
- }
+ if (new RegExp('; $').test(str))
+ str = str.substring(0, str.length - 2);
- tinyMCE.execCommand('mceEndUndoLevel');
-};
+ return str;
+ },
-TinyMCE.prototype.insertImage = function(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout) {
- tinyMCE.execCommand('mceBeginUndoLevel');
+ convertRGBToHex : function(s, k) {
+ var re, rgb;
- if (src == "")
- return;
+ if (s.toLowerCase().indexOf('rgb') != -1) {
+ re = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
+ rgb = s.replace(re, "$1,$2,$3,$4,$5").split(',');
- if (!this.imgElement && tinyMCE.isSafari) {
- var html = "";
+ if (rgb.length == 5) {
+ r = parseInt(rgb[1]).toString(16);
+ g = parseInt(rgb[2]).toString(16);
+ b = parseInt(rgb[3]).toString(16);
- html += '<img src="' + src + '" alt="' + alt + '"';
- html += ' border="' + border + '" hspace="' + hspace + '"';
- html += ' vspace="' + vspace + '" width="' + width + '"';
- html += ' height="' + height + '" align="' + align + '" title="' + title + '" onmouseover="' + onmouseover + '" onmouseout="' + onmouseout + '" />';
+ r = r.length == 1 ? '0' + r : r;
+ g = g.length == 1 ? '0' + g : g;
+ b = b.length == 1 ? '0' + b : b;
- tinyMCE.execCommand("mceInsertContent", false, html);
- } else {
- if (!this.imgElement && this.selectedInstance) {
- if (tinyMCE.isSafari)
- tinyMCE.execCommand("mceInsertContent", false, '<img src="' + tinyMCE.uniqueURL + '" />');
- else
- this.selectedInstance.contentDocument.execCommand("insertimage", false, tinyMCE.uniqueURL);
+ s = "#" + r + g + b;
- tinyMCE.imgElement = this.getElementByAttributeValue(this.selectedInstance.contentDocument.body, "img", "src", tinyMCE.uniqueURL);
+ if (k)
+ s = rgb[0] + s + rgb[4];
+ }
}
- }
- if (this.imgElement) {
- var needsRepaint = false;
- var msrc = src;
+ return s;
+ },
- src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, tinyMCE.imgElement);");
+ convertHexToRGB : function(s) {
+ if (s.indexOf('#') != -1) {
+ s = s.replace(new RegExp('[^0-9A-F]', 'gi'), '');
+ return "rgb(" + parseInt(s.substring(0, 2), 16) + "," + parseInt(s.substring(2, 4), 16) + "," + parseInt(s.substring(4, 6), 16) + ")";
+ }
- if (tinyMCE.getParam('convert_urls'))
- msrc = src;
+ return s;
+ },
- if (onmouseover && onmouseover != "")
- onmouseover = "this.src='" + eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseover, tinyMCE.imgElement);") + "';";
+ convertSpansToFonts : function(doc) {
+ var s, i, size, fSize, x, fFace, fColor, sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
- if (onmouseout && onmouseout != "")
- onmouseout = "this.src='" + eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseout, tinyMCE.imgElement);") + "';";
+ s = tinyMCE.selectElements(doc, 'span,font');
+ for (i=0; i<s.length; i++) {
+ size = tinyMCE.trim(s[i].style.fontSize).toLowerCase();
+ fSize = 0;
- // Use alt as title if it's undefined
- if (typeof(title) == "undefined")
- title = alt;
+ for (x=0; x<sizes.length; x++) {
+ if (sizes[x] == size) {
+ fSize = x + 1;
+ break;
+ }
+ }
- if (width != this.imgElement.getAttribute("width") || height != this.imgElement.getAttribute("height") || align != this.imgElement.getAttribute("align"))
- needsRepaint = true;
+ if (fSize > 0) {
+ tinyMCE.setAttrib(s[i], 'size', fSize);
+ s[i].style.fontSize = '';
+ }
- tinyMCE.setAttrib(this.imgElement, 'src', src);
- tinyMCE.setAttrib(this.imgElement, 'mce_src', msrc);
- tinyMCE.setAttrib(this.imgElement, 'alt', alt);
- tinyMCE.setAttrib(this.imgElement, 'title', title);
- tinyMCE.setAttrib(this.imgElement, 'align', align);
- tinyMCE.setAttrib(this.imgElement, 'border', border, true);
- tinyMCE.setAttrib(this.imgElement, 'hspace', hspace, true);
- tinyMCE.setAttrib(this.imgElement, 'vspace', vspace, true);
- tinyMCE.setAttrib(this.imgElement, 'width', width, true);
- tinyMCE.setAttrib(this.imgElement, 'height', height, true);
- tinyMCE.setAttrib(this.imgElement, 'onmouseover', onmouseover);
- tinyMCE.setAttrib(this.imgElement, 'onmouseout', onmouseout);
+ fFace = s[i].style.fontFamily;
+ if (fFace != null && fFace !== '') {
+ tinyMCE.setAttrib(s[i], 'face', fFace);
+ s[i].style.fontFamily = '';
+ }
- // Fix for bug #989846 - Image resize bug
- if (width && width != "")
- this.imgElement.style.pixelWidth = width;
+ fColor = s[i].style.color;
+ if (fColor != null && fColor !== '') {
+ tinyMCE.setAttrib(s[i], 'color', tinyMCE.convertRGBToHex(fColor));
+ s[i].style.color = '';
+ }
+ }
+ },
- if (height && height != "")
- this.imgElement.style.pixelHeight = height;
+ convertFontsToSpans : function(doc) {
+ var fsClasses, s, i, fSize, fFace, fColor, sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
- if (needsRepaint)
- tinyMCE.selectedInstance.repaint();
- }
+ fsClasses = tinyMCE.getParam('font_size_classes');
+ if (fsClasses !== '')
+ fsClasses = fsClasses.replace(/\s+/, '').split(',');
+ else
+ fsClasses = null;
- tinyMCE.execCommand('mceEndUndoLevel');
-};
+ s = tinyMCE.selectElements(doc, 'span,font');
+ for (i=0; i<s.length; i++) {
+ fSize = tinyMCE.getAttrib(s[i], 'size');
+ fFace = tinyMCE.getAttrib(s[i], 'face');
+ fColor = tinyMCE.getAttrib(s[i], 'color');
-TinyMCE.prototype.getElementByAttributeValue = function(node, element_name, attrib, value) {
- var elements = this.getElementsByAttributeValue(node, element_name, attrib, value);
- if (elements.length == 0)
- return null;
+ if (fSize !== '') {
+ fSize = parseInt(fSize);
- return elements[0];
-};
+ if (fSize > 0 && fSize < 8) {
+ if (fsClasses != null)
+ tinyMCE.setAttrib(s[i], 'class', fsClasses[fSize-1]);
+ else
+ s[i].style.fontSize = sizes[fSize-1];
+ }
-TinyMCE.prototype.getElementsByAttributeValue = function(node, element_name, attrib, value) {
- var elements = new Array();
+ s[i].removeAttribute('size');
+ }
- if (node && node.nodeName.toLowerCase() == element_name) {
- if (node.getAttribute(attrib) && node.getAttribute(attrib).indexOf(value) != -1)
- elements[elements.length] = node;
- }
+ if (fFace !== '') {
+ s[i].style.fontFamily = fFace;
+ s[i].removeAttribute('face');
+ }
- if (node && node.hasChildNodes()) {
- for (var x=0, n=node.childNodes.length; x<n; x++) {
- var childElements = this.getElementsByAttributeValue(node.childNodes[x], element_name, attrib, value);
- for (var i=0, m=childElements.length; i<m; i++)
- elements[elements.length] = childElements[i];
+ if (fColor !== '') {
+ s[i].style.color = fColor;
+ s[i].removeAttribute('color');
+ }
}
- }
-
- return elements;
-};
+ },
-TinyMCE.prototype.isBlockElement = function(node) {
- return node != null && node.nodeType == 1 && this.blockRegExp.test(node.nodeName);
-};
-
-TinyMCE.prototype.getParentBlockElement = function(node) {
- // Search up the tree for block element
- while (node) {
- if (this.blockRegExp.test(node.nodeName))
- return node;
-
- node = node.parentNode;
- }
+ cleanupAnchors : function(doc) {
+ var i, cn, x, an = doc.getElementsByTagName("a");
- return null;
-};
+ // Loops backwards due to bug #1467987
+ for (i=an.length-1; i>=0; i--) {
+ if (tinyMCE.getAttrib(an[i], "name") !== '' && tinyMCE.getAttrib(an[i], "href") == '') {
+ cn = an[i].childNodes;
-TinyMCE.prototype.getNodeTree = function(node, node_array, type, node_name) {
- if (typeof(type) == "undefined" || node.nodeType == type && (typeof(node_name) == "undefined" || node.nodeName == node_name))
- node_array[node_array.length] = node;
+ for (x=cn.length-1; x>=0; x--)
+ tinyMCE.insertAfter(cn[x], an[i]);
+ }
+ }
+ },
- if (node.hasChildNodes()) {
- for (var i=0; i<node.childNodes.length; i++)
- tinyMCE.getNodeTree(node.childNodes[i], node_array, type, node_name);
- }
+ getContent : function(editor_id) {
+ if (typeof(editor_id) != "undefined")
+ tinyMCE.getInstanceById(editor_id).select();
- return node_array;
-};
+ if (tinyMCE.selectedInstance)
+ return tinyMCE.selectedInstance.getHTML();
-TinyMCE.prototype.getParentElement = function(node, names, attrib_name, attrib_value) {
- if (typeof(names) == "undefined") {
- if (node.nodeType == 1)
- return node;
+ return null;
+ },
- // Find parent node that is a element
- while ((node = node.parentNode) != null && node.nodeType != 1) ;
+ _fixListElements : function(d) {
+ var nl, x, a = ['ol', 'ul'], i, n, p, r = new RegExp('^(OL|UL)$'), np;
- return node;
- }
+ for (x=0; x<a.length; x++) {
+ nl = d.getElementsByTagName(a[x]);
- var namesAr = names.split(',');
+ for (i=0; i<nl.length; i++) {
+ n = nl[i];
+ p = n.parentNode;
- if (node == null)
- return null;
+ if (r.test(p.nodeName)) {
+ np = tinyMCE.prevNode(n, 'LI');
- do {
- for (var i=0; i<namesAr.length; i++) {
- if (node.nodeName.toLowerCase() == namesAr[i].toLowerCase() || names == "*") {
- if (typeof(attrib_name) == "undefined")
- return node;
- else if (node.getAttribute(attrib_name)) {
- if (typeof(attrib_value) == "undefined") {
- if (node.getAttribute(attrib_name) != "")
- return node;
- } else if (node.getAttribute(attrib_name) == attrib_value)
- return node;
+ if (!np) {
+ np = d.createElement('li');
+ np.innerHTML = ' ';
+ np.appendChild(n);
+ p.insertBefore(np, p.firstChild);
+ } else
+ np.appendChild(n);
}
}
}
- } while ((node = node.parentNode) != null);
+ },
- return null;
-};
+ _fixTables : function(d) {
+ var nl, i, n, p, np, x, t;
-TinyMCE.prototype.convertURL = function(url, node, on_save) {
- var prot = document.location.protocol;
- var host = document.location.hostname;
- var port = document.location.port;
+ nl = d.getElementsByTagName('table');
+ for (i=0; i<nl.length; i++) {
+ n = nl[i];
- // Pass through file protocol
- if (prot == "file:")
- return url;
+ if ((p = tinyMCE.getParentElement(n, 'p,h1,h2,h3,h4,h5,h6')) != null) {
+ np = p.cloneNode(false);
+ np.removeAttribute('id');
- // Something is wrong, remove weirdness
- url = tinyMCE.regexpReplace(url, '(http|https):///', '/');
+ t = n;
- // Mailto link or anchor (Pass through)
- if (url.indexOf('mailto:') != -1 || url.indexOf('javascript:') != -1 || tinyMCE.regexpReplace(url,'[ \t\r\n\+]|%20','').charAt(0) == "#")
- return url;
+ while ((n = n.nextSibling))
+ np.appendChild(n);
- // Fix relative/Mozilla
- if (!tinyMCE.isMSIE && !on_save && url.indexOf("://") == -1 && url.charAt(0) != '/')
- return tinyMCE.settings['base_href'] + url;
+ tinyMCE.insertAfter(np, p);
+ tinyMCE.insertAfter(t, p);
+ }
+ }
+ },
- // Handle relative URLs
- if (on_save && tinyMCE.getParam('relative_urls')) {
- var curl = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], url);
- if (curl.charAt(0) == '/')
- curl = tinyMCE.settings['document_base_prefix'] + curl;
+ _cleanupHTML : function(inst, doc, config, elm, visual, on_save, on_submit, inn) {
+ var h, d, t1, t2, t3, t4, t5, c, s, nb;
- var urlParts = tinyMCE.parseURL(curl);
- var tmpUrlParts = tinyMCE.parseURL(tinyMCE.settings['document_base_url']);
+ if (!tinyMCE.getParam('cleanup'))
+ return elm.innerHTML;
- // Force relative
- if (urlParts['host'] == tmpUrlParts['host'] && (urlParts['port'] == tmpUrlParts['port']))
- return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings['document_base_url'], curl);
- }
+ on_save = typeof(on_save) == 'undefined' ? false : on_save;
- // Handle absolute URLs
- if (!tinyMCE.getParam('relative_urls')) {
- var urlParts = tinyMCE.parseURL(url);
- var baseUrlParts = tinyMCE.parseURL(tinyMCE.settings['base_href']);
+ c = inst.cleanup;
+ s = inst.settings;
+ d = c.settings.debug;
- // Force absolute URLs from relative URLs
- url = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], url);
+ if (d)
+ t1 = new Date().getTime();
- // If anchor and path is the same page
- if (urlParts['anchor'] && urlParts['path'] == baseUrlParts['path'])
- return "#" + urlParts['anchor'];
- }
+ inst._fixRootBlocks();
- // Remove current domain
- if (tinyMCE.getParam('remove_script_host')) {
- var start = "", portPart = "";
+ if (tinyMCE.getParam("convert_fonts_to_spans"))
+ tinyMCE.convertFontsToSpans(doc);
- if (port != "")
- portPart = ":" + port;
+ if (tinyMCE.getParam("fix_list_elements"))
+ tinyMCE._fixListElements(doc);
- start = prot + "//" + host + portPart + "/";
+ if (tinyMCE.getParam("fix_table_elements"))
+ tinyMCE._fixTables(doc);
- if (url.indexOf(start) == 0)
- url = url.substring(start.length-1);
- }
+ // Call custom cleanup code
+ tinyMCE._customCleanup(inst, on_save ? "get_from_editor_dom" : "insert_to_editor_dom", doc.body);
- return url;
-};
+ if (d)
+ t2 = new Date().getTime();
+
+ c.settings.on_save = on_save;
-/**
- * Parses a URL in to its diffrent components.
- */
-TinyMCE.prototype.parseURL = function(url_str) {
- var urlParts = new Array();
+ c.idCount = 0;
+ c.serializationId = new Date().getTime().toString(32); // Unique ID needed for the content duplication bug
+ c.serializedNodes = [];
+ c.sourceIndex = -1;
- if (url_str) {
- var pos, lastPos;
+ if (s.cleanup_serializer == "xml")
+ h = c.serializeNodeAsXML(elm, inn);
+ else
+ h = c.serializeNodeAsHTML(elm, inn);
+
+ if (d)
+ t3 = new Date().getTime();
+
+ // Post processing
+ nb = tinyMCE.getParam('entity_encoding') == 'numeric' ? ' ' : ' ';
+ h = h.replace(/<\/?(body|head|html)[^>]*>/gi, '');
+ h = h.replace(new RegExp(' (rowspan="1"|colspan="1")', 'g'), '');
+ h = h.replace(/<p><hr \/><\/p>/g, '<hr />');
+ h = h.replace(/<p>( | )<\/p><hr \/><p>( | )<\/p>/g, '<hr />');
+ h = h.replace(/<td>\s*<br \/>\s*<\/td>/g, '<td>' + nb + '</td>');
+ h = h.replace(/<p>\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>');
+ h = h.replace(/<br \/>$/, ''); // Remove last BR for Gecko
+ h = h.replace(/<br \/><\/p>/g, '</p>'); // Remove last BR in P tags for Gecko
+ h = h.replace(/<p>\s*( | )\s*<br \/>\s*( | )\s*<\/p>/g, '<p>' + nb + '</p>');
+ h = h.replace(/<p>\s*( | )\s*<br \/>\s*<\/p>/g, '<p>' + nb + '</p>');
+ h = h.replace(/<p>\s*<br \/>\s* \s*<\/p>/g, '<p>' + nb + '</p>');
+ h = h.replace(new RegExp('<a>(.*?)<\\/a>', 'g'), '$1');
+ h = h.replace(/<p([^>]*)>\s*<\/p>/g, '<p$1>' + nb + '</p>');
+
+ // Clean body
+ if (/^\s*(<br \/>|<p> <\/p>|<p> <\/p>|<p><\/p>)\s*$/.test(h))
+ h = '';
+
+ // If preformatted
+ if (s.preformatted) {
+ h = h.replace(/^<pre>/, '');
+ h = h.replace(/<\/pre>$/, '');
+ h = '<pre>' + h + '</pre>';
+ }
- // Parse protocol part
- pos = url_str.indexOf('://');
- if (pos != -1) {
- urlParts['protocol'] = url_str.substring(0, pos);
- lastPos = pos + 3;
+ // Gecko specific processing
+ if (tinyMCE.isGecko) {
+ // Makes no sence but FF generates it!!
+ h = h.replace(/<br \/>\s*<\/li>/g, '</li>');
+ h = h.replace(/ \s*<\/(dd|dt)>/g, '</$1>');
+ h = h.replace(/<o:p _moz-userdefined="" \/>/g, '');
+ h = h.replace(/<td([^>]*)>\s*<br \/>\s*<\/td>/g, '<td$1>' + nb + '</td>');
}
- // Find port or path start
- for (var i=lastPos; i<url_str.length; i++) {
- var chr = url_str.charAt(i);
+ if (s.force_br_newlines)
+ h = h.replace(/<p>( | )<\/p>/g, '<br />');
- if (chr == ':')
- break;
+ // Call custom cleanup code
+ h = tinyMCE._customCleanup(inst, on_save ? "get_from_editor" : "insert_to_editor", h);
- if (chr == '/')
- break;
+ // Remove internal classes
+ if (on_save) {
+ h = h.replace(new RegExp(' ?(mceItem[a-zA-Z0-9]*|' + s.visual_table_class + ')', 'g'), '');
+ h = h.replace(new RegExp(' ?class=""', 'g'), '');
}
- pos = i;
- // Get host
- urlParts['host'] = url_str.substring(lastPos, pos);
+ if (s.remove_linebreaks && !c.settings.indent)
+ h = h.replace(/\n|\r/g, ' ');
+
+ if (d)
+ t4 = new Date().getTime();
+
+ if (on_save && c.settings.indent)
+ h = c.formatHTML(h);
+
+ // If encoding (not recommended option)
+ if (on_submit && (s.encoding == "xml" || s.encoding == "html"))
+ h = c.xmlEncode(h);
+
+ if (d)
+ t5 = new Date().getTime();
+
+ if (c.settings.debug)
+ tinyMCE.debug("Cleanup in ms: Pre=" + (t2-t1) + ", Serialize: " + (t3-t2) + ", Post: " + (t4-t3) + ", Format: " + (t5-t4) + ", Sum: " + (t5-t1) + ".");
+
+ return h;
+ }
+});
+
+function TinyMCE_Cleanup() {
+ this.isIE = (navigator.appName == "Microsoft Internet Explorer");
+ this.rules = tinyMCE.clearArray([]);
+
+ // Default config
+ this.settings = {
+ indent_elements : 'head,table,tbody,thead,tfoot,form,tr,ul,ol,blockquote,object',
+ newline_before_elements : 'h1,h2,h3,h4,h5,h6,pre,address,div,ul,ol,li,meta,option,area,title,link,base,script,td',
+ newline_after_elements : 'br,hr,p,pre,address,div,ul,ol,meta,option,area,link,base,script',
+ newline_before_after_elements : 'html,head,body,table,thead,tbody,tfoot,tr,form,ul,ol,blockquote,p,object,param,hr,div',
+ indent_char : '\t',
+ indent_levels : 1,
+ entity_encoding : 'raw',
+ valid_elements : '*[*]',
+ entities : '',
+ url_converter : '',
+ invalid_elements : '',
+ verify_html : false
+ };
+
+ this.vElements = tinyMCE.clearArray([]);
+ this.vElementsRe = '';
+ this.closeElementsRe = /^(IMG|BR|HR|LINK|META|BASE|INPUT|AREA)$/;
+ this.codeElementsRe = /^(SCRIPT|STYLE)$/;
+ this.serializationId = 0;
+ this.mceAttribs = {
+ href : 'mce_href',
+ src : 'mce_src',
+ type : 'mce_type'
+ };
+}
+
+TinyMCE_Cleanup.prototype = {
+ init : function(s) {
+ var n, a, i, ir, or, st;
+
+ for (n in s)
+ this.settings[n] = s[n];
+
+ // Setup code formating
+ s = this.settings;
+
+ // Setup regexps
+ this.inRe = this._arrayToRe(s.indent_elements.split(','), '', '^<(', ')[^>]*');
+ this.ouRe = this._arrayToRe(s.indent_elements.split(','), '', '^<\\/(', ')[^>]*');
+ this.nlBeforeRe = this._arrayToRe(s.newline_before_elements.split(','), 'gi', '<(', ')([^>]*)>');
+ this.nlAfterRe = this._arrayToRe(s.newline_after_elements.split(','), 'gi', '<(', ')([^>]*)>');
+ this.nlBeforeAfterRe = this._arrayToRe(s.newline_before_after_elements.split(','), 'gi', '<(\\/?)(', ')([^>]*)>');
+ this.serializedNodes = [];
+
+ if (s.invalid_elements !== '')
+ this.iveRe = this._arrayToRe(s.invalid_elements.toUpperCase().split(','), 'g', '^(', ')$');
+ else
+ this.iveRe = null;
- // Get port
- urlParts['port'] = "";
- lastPos = pos;
- if (url_str.charAt(pos) == ':') {
- pos = url_str.indexOf('/', lastPos);
- urlParts['port'] = url_str.substring(lastPos+1, pos);
- }
+ // Setup separator
+ st = '';
+ for (i=0; i<s.indent_levels; i++)
+ st += s.indent_char;
- // Get path
- lastPos = pos;
- pos = url_str.indexOf('?', lastPos);
+ this.inStr = st;
- if (pos == -1)
- pos = url_str.indexOf('#', lastPos);
+ // If verify_html if false force *[*]
+ if (!s.verify_html) {
+ s.valid_elements = '*[*]';
+ s.extended_valid_elements = '';
+ }
- if (pos == -1)
- pos = url_str.length;
+ this.fillStr = s.entity_encoding == "named" ? " " : " ";
+ this.idCount = 0;
+ this.xmlEncodeRe = new RegExp('[\u007F-\uFFFF<>&"]', 'g');
+ },
- urlParts['path'] = url_str.substring(lastPos, pos);
+ addRuleStr : function(s) {
+ var r = this.parseRuleStr(s), n;
- // Get query
- lastPos = pos;
- if (url_str.charAt(pos) == '?') {
- pos = url_str.indexOf('#');
- pos = (pos == -1) ? url_str.length : pos;
- urlParts['query'] = url_str.substring(lastPos+1, pos);
+ for (n in r) {
+ if (r[n])
+ this.rules[n] = r[n];
}
- // Get anchor
- lastPos = pos;
- if (url_str.charAt(pos) == '#') {
- pos = url_str.length;
- urlParts['anchor'] = url_str.substring(lastPos+1, pos);
+ this.vElements = tinyMCE.clearArray([]);
+
+ for (n in this.rules) {
+ if (this.rules[n])
+ this.vElements[this.vElements.length] = this.rules[n].tag;
}
- }
- return urlParts;
-};
+ this.vElementsRe = this._arrayToRe(this.vElements, '');
+ },
+
+ isValid : function(n) {
+ if (!this.rulesDone)
+ this._setupRules(); // Will initialize cleanup rules
+
+ // Empty is true since it removes formatting
+ if (!n)
+ return true;
-TinyMCE.prototype.serializeURL = function(up) {
- var url = "";
+ // Clean the name up a bit
+ n = n.replace(/[^a-z0-9]+/gi, '').toUpperCase();
- if (up['protocol'])
- url += up['protocol'] + "://";
+ return !tinyMCE.getParam('cleanup') || this.vElementsRe.test(n);
+ },
- if (up['host'])
- url += up['host'];
+ addChildRemoveRuleStr : function(s) {
+ var x, y, p, i, t, tn, ta, cl, r;
- if (up['port'])
- url += ":" + up['port'];
+ if (!s)
+ return;
- if (up['path'])
- url += up['path'];
+ ta = s.split(',');
+ for (x=0; x<ta.length; x++) {
+ s = ta[x];
- if (up['query'])
- url += "?" + up['query'];
+ // Split tag/children
+ p = this.split(/\[|\]/, s);
+ if (p == null || p.length < 1)
+ t = s.toUpperCase();
+ else
+ t = p[0].toUpperCase();
+
+ // Handle all tag names
+ tn = this.split('/', t);
+ for (y=0; y<tn.length; y++) {
+ r = "^(";
+
+ // Build regex
+ cl = this.split(/\|/, p[1]);
+ for (i=0; i<cl.length; i++) {
+ if (cl[i] == '%istrict')
+ r += tinyMCE.inlineStrict;
+ else if (cl[i] == '%itrans')
+ r += tinyMCE.inlineTransitional;
+ else if (cl[i] == '%istrict_na')
+ r += tinyMCE.inlineStrict.substring(2);
+ else if (cl[i] == '%itrans_na')
+ r += tinyMCE.inlineTransitional.substring(2);
+ else if (cl[i] == '%btrans')
+ r += tinyMCE.blockElms;
+ else if (cl[i] == '%strict')
+ r += tinyMCE.blockStrict;
+ else
+ r += (cl[i].charAt(0) != '#' ? cl[i].toUpperCase() : cl[i]);
- if (up['anchor'])
- url += "#" + up['anchor'];
+ r += (i != cl.length - 1 ? '|' : '');
+ }
- return url;
-};
+ r += ')$';
-/**
- * Converts an absolute path to relative path.
- */
-TinyMCE.prototype.convertAbsoluteURLToRelativeURL = function(base_url, url_to_relative) {
- var baseURL = this.parseURL(base_url);
- var targetURL = this.parseURL(url_to_relative);
- var strTok1;
- var strTok2;
- var breakPoint = 0;
- var outPath = "";
- var forceSlash = false;
-
- if (targetURL.path == "")
- targetURL.path = "/";
- else
- forceSlash = true;
-
- // Crop away last path part
- base_url = baseURL.path.substring(0, baseURL.path.lastIndexOf('/'));
- strTok1 = base_url.split('/');
- strTok2 = targetURL.path.split('/');
-
- if (strTok1.length >= strTok2.length) {
- for (var i=0; i<strTok1.length; i++) {
- if (i >= strTok2.length || strTok1[i] != strTok2[i]) {
- breakPoint = i + 1;
- break;
- }
- }
- }
+ if (this.childRules == null)
+ this.childRules = tinyMCE.clearArray([]);
- if (strTok1.length < strTok2.length) {
- for (var i=0; i<strTok2.length; i++) {
- if (i >= strTok1.length || strTok1[i] != strTok2[i]) {
- breakPoint = i + 1;
- break;
+ this.childRules[tn[y]] = new RegExp(r);
+
+ if (p.length > 1)
+ this.childRules[tn[y]].wrapTag = p[2];
}
}
- }
+ },
- if (breakPoint == 1)
- return targetURL.path;
+ parseRuleStr : function(s) {
+ var ta, p, r, a, i, x, px, t, tn, y, av, or = tinyMCE.clearArray([]), dv;
- for (var i=0; i<(strTok1.length-(breakPoint-1)); i++)
- outPath += "../";
+ if (s == null || s.length == 0)
+ return or;
- for (var i=breakPoint-1; i<strTok2.length; i++) {
- if (i != (breakPoint-1))
- outPath += "/" + strTok2[i];
- else
- outPath += strTok2[i];
- }
+ ta = s.split(',');
+ for (x=0; x<ta.length; x++) {
+ s = ta[x];
+ if (s.length == 0)
+ continue;
- targetURL.protocol = null;
- targetURL.host = null;
- targetURL.port = null;
- targetURL.path = outPath == "" && forceSlash ? "/" : outPath;
+ // Split tag/attrs
+ p = this.split(/\[|\]/, s);
+ if (p == null || p.length < 1)
+ t = s.toUpperCase();
+ else
+ t = p[0].toUpperCase();
+
+ // Handle all tag names
+ tn = this.split('/', t);
+ for (y=0; y<tn.length; y++) {
+ r = {};
+
+ r.tag = tn[y];
+ r.forceAttribs = null;
+ r.defaultAttribs = null;
+ r.validAttribValues = null;
+
+ // Handle prefixes
+ px = r.tag.charAt(0);
+ r.forceOpen = px == '+';
+ r.removeEmpty = px == '-';
+ r.fill = px == '#';
+ r.tag = r.tag.replace(/\+|-|#/g, '');
+ r.oTagName = tn[0].replace(/\+|-|#/g, '').toLowerCase();
+ r.isWild = new RegExp('\\*|\\?|\\+', 'g').test(r.tag);
+ r.validRe = new RegExp(this._wildcardToRe('^' + r.tag + '$'));
+
+ // Setup valid attributes
+ if (p.length > 1) {
+ r.vAttribsRe = '^(';
+ a = this.split(/\|/, p[1]);
+
+ for (i=0; i<a.length; i++) {
+ t = a[i];
+
+ if (t.charAt(0) == '!') {
+ a[i] = t = t.substring(1);
+
+ if (!r.reqAttribsRe)
+ r.reqAttribsRe = '\\s+(' + t;
+ else
+ r.reqAttribsRe += '|' + t;
+ }
- // Remove document prefix from local anchors
- var fileName = baseURL.path;
- var pos;
+ av = new RegExp('(=|:|<)(.*?)$').exec(t);
+ t = t.replace(new RegExp('(=|:|<).*?$'), '');
+ if (av && av.length > 0) {
+ if (av[0].charAt(0) == ':') {
+ if (!r.forceAttribs)
+ r.forceAttribs = tinyMCE.clearArray([]);
- if ((pos = fileName.lastIndexOf('/')) != -1)
- fileName = fileName.substring(pos + 1);
+ r.forceAttribs[t.toLowerCase()] = av[0].substring(1);
+ } else if (av[0].charAt(0) == '=') {
+ if (!r.defaultAttribs)
+ r.defaultAttribs = tinyMCE.clearArray([]);
- // Is local anchor
- if (fileName == targetURL.path && targetURL.anchor != "")
- targetURL.path = "";
+ dv = av[0].substring(1);
- return this.serializeURL(targetURL);
-};
+ r.defaultAttribs[t.toLowerCase()] = dv == '' ? "mce_empty" : dv;
+ } else if (av[0].charAt(0) == '<') {
+ if (!r.validAttribValues)
+ r.validAttribValues = tinyMCE.clearArray([]);
-TinyMCE.prototype.convertRelativeToAbsoluteURL = function(base_url, relative_url) {
- var baseURL = TinyMCE.prototype.parseURL(base_url);
- var relURL = TinyMCE.prototype.parseURL(relative_url);
+ r.validAttribValues[t.toLowerCase()] = this._arrayToRe(this.split('?', av[0].substring(1)), 'i');
+ }
+ }
- if (relative_url == "" || relative_url.charAt(0) == '/' || relative_url.indexOf('://') != -1 || relative_url.indexOf('mailto:') != -1 || relative_url.indexOf('javascript:') != -1)
- return relative_url;
+ r.vAttribsRe += '' + t.toLowerCase() + (i != a.length - 1 ? '|' : '');
- // Split parts
- baseURLParts = baseURL['path'].split('/');
- relURLParts = relURL['path'].split('/');
+ a[i] = t.toLowerCase();
+ }
- // Remove empty chunks
- var newBaseURLParts = new Array();
- for (var i=baseURLParts.length-1; i>=0; i--) {
- if (baseURLParts[i].length == 0)
- continue;
+ if (r.reqAttribsRe)
+ r.reqAttribsRe = new RegExp(r.reqAttribsRe + ')=\"', 'g');
- newBaseURLParts[newBaseURLParts.length] = baseURLParts[i];
- }
- baseURLParts = newBaseURLParts.reverse();
+ r.vAttribsRe += ')$';
+ r.vAttribsRe = this._wildcardToRe(r.vAttribsRe);
+ r.vAttribsReIsWild = new RegExp('\\*|\\?|\\+', 'g').test(r.vAttribsRe);
+ r.vAttribsRe = new RegExp(r.vAttribsRe);
+ r.vAttribs = a.reverse();
- // Merge relURLParts chunks
- var newRelURLParts = new Array();
- var numBack = 0;
- for (var i=relURLParts.length-1; i>=0; i--) {
- if (relURLParts[i].length == 0 || relURLParts[i] == ".")
- continue;
+ //tinyMCE.debug(r.tag, r.oTagName, r.vAttribsRe, r.vAttribsReWC);
+ } else {
+ r.vAttribsRe = '';
+ r.vAttribs = tinyMCE.clearArray([]);
+ r.vAttribsReIsWild = false;
+ }
- if (relURLParts[i] == '..') {
- numBack++;
- continue;
+ or[r.tag] = r;
+ }
}
- if (numBack > 0) {
- numBack--;
- continue;
+ return or;
+ },
+
+ serializeNodeAsXML : function(n) {
+ var s, b;
+
+ if (!this.xmlDoc) {
+ if (this.isIE) {
+ try {this.xmlDoc = new ActiveXObject('MSXML2.DOMDocument');} catch (e) {}
+
+ if (!this.xmlDoc)
+ try {this.xmlDoc = new ActiveXObject('Microsoft.XmlDom');} catch (e) {}
+ } else
+ this.xmlDoc = document.implementation.createDocument('', '', null);
+
+ if (!this.xmlDoc)
+ alert("Error XML Parser could not be found.");
}
- newRelURLParts[newRelURLParts.length] = relURLParts[i];
- }
+ if (this.xmlDoc.firstChild)
+ this.xmlDoc.removeChild(this.xmlDoc.firstChild);
- relURLParts = newRelURLParts.reverse();
+ b = this.xmlDoc.createElement("html");
+ b = this.xmlDoc.appendChild(b);
- // Remove end from absolute path
- var len = baseURLParts.length-numBack;
- var absPath = (len <= 0 ? "" : "/") + baseURLParts.slice(0, len).join('/') + "/" + relURLParts.join('/');
- var start = "", end = "";
+ this._convertToXML(n, b);
- // Build output URL
- relURL.protocol = baseURL.protocol;
- relURL.host = baseURL.host;
- relURL.port = baseURL.port;
+ if (this.isIE)
+ return this.xmlDoc.xml;
+ else
+ return new XMLSerializer().serializeToString(this.xmlDoc);
+ },
- // Re-add trailing slash if it's removed
- if (relURL.path.charAt(relURL.path.length-1) == "/")
- absPath += "/";
+ _convertToXML : function(n, xn) {
+ var xd, el, i, l, cn, at, no, hc = false;
- relURL.path = absPath;
+ if (tinyMCE.isRealIE && this._isDuplicate(n))
+ return;
- return TinyMCE.prototype.serializeURL(relURL);
-};
+ xd = this.xmlDoc;
-TinyMCE.prototype.getParam = function(name, default_value, strip_whitespace, split_chr) {
- var value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
+ switch (n.nodeType) {
+ case 1: // Element
+ hc = n.hasChildNodes();
- // Fix bool values
- if (value == "true" || value == "false")
- return (value == "true");
+ el = xd.createElement(n.nodeName.toLowerCase());
- if (strip_whitespace)
- value = tinyMCE.regexpReplace(value, "[ \t\r\n]", "");
+ at = n.attributes;
+ for (i=at.length-1; i>-1; i--) {
+ no = at[i];
- if (typeof(split_chr) != "undefined" && split_chr != null) {
- value = value.split(split_chr);
- var outArray = new Array();
+ if (no.specified && no.nodeValue)
+ el.setAttribute(no.nodeName.toLowerCase(), no.nodeValue);
+ }
- for (var i=0; i<value.length; i++) {
- if (value[i] && value[i] != "")
- outArray[outArray.length] = value[i];
- }
+ if (!hc && !this.closeElementsRe.test(n.nodeName))
+ el.appendChild(xd.createTextNode(""));
- value = outArray;
- }
+ xn = xn.appendChild(el);
+ break;
- return value;
-};
+ case 3: // Text
+ xn.appendChild(xd.createTextNode(n.nodeValue));
+ return;
-TinyMCE.prototype.getLang = function(name, default_value, parse_entities) {
- var value = (typeof(tinyMCELang[name]) == "undefined") ? default_value : tinyMCELang[name];
+ case 8: // Comment
+ xn.appendChild(xd.createComment(n.nodeValue));
+ return;
+ }
- if (parse_entities)
- value = tinyMCE.entityDecode(value);
+ if (hc) {
+ cn = n.childNodes;
- return value;
-};
+ for (i=0, l=cn.length; i<l; i++)
+ this._convertToXML(cn[i], xn);
+ }
+ },
-TinyMCE.prototype.entityDecode = function(s) {
- var e = document.createElement("div");
- e.innerHTML = s;
- return e.innerHTML;
-};
+ serializeNodeAsHTML : function(n, inn) {
+ var en, no, h = '', i, l, t, st, r, cn, va = false, f = false, at, hc, cr, nn;
-TinyMCE.prototype.addToLang = function(prefix, ar) {
- for (var key in ar) {
- if (typeof(ar[key]) == 'function')
- continue;
+ if (!this.rulesDone)
+ this._setupRules(); // Will initialize cleanup rules
- tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = ar[key];
- }
+ if (tinyMCE.isRealIE && this._isDuplicate(n))
+ return '';
-// for (var key in ar)
-// tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = "|" + ar[key] + "|";
-};
+ // Skip non valid child elements
+ if (n.parentNode && this.childRules != null) {
+ cr = this.childRules[n.parentNode.nodeName];
-TinyMCE.prototype.replaceVar = function(replace_haystack, replace_var, replace_str) {
- var re = new RegExp('{\\\$' + replace_var + '}', 'g');
- return replace_haystack.replace(re, replace_str);
-};
+ if (typeof(cr) != "undefined" && !cr.test(n.nodeName)) {
+ st = true;
+ t = null;
+ }
+ }
-TinyMCE.prototype.replaceVars = function(replace_haystack, replace_vars) {
- for (var key in replace_vars) {
- var value = replace_vars[key];
- if (typeof(value) == 'function')
- continue;
+ switch (n.nodeType) {
+ case 1: // Element
+ hc = n.hasChildNodes();
- replace_haystack = tinyMCE.replaceVar(replace_haystack, key, value);
- }
+ if (st)
+ break;
- return replace_haystack;
-};
+ nn = n.nodeName;
-TinyMCE.prototype.triggerNodeChange = function(focus, setup_content) {
- if (tinyMCE.settings['handleNodeChangeCallback']) {
- if (tinyMCE.selectedInstance) {
- var inst = tinyMCE.selectedInstance;
- var editorId = inst.editorId;
- var elm = (typeof(setup_content) != "undefined" && setup_content) ? tinyMCE.selectedElement : inst.getFocusElement();
- var undoIndex = -1;
- var undoLevels = -1;
- var anySelection = false;
- var selectedText = inst.getSelectedText();
+ if (tinyMCE.isRealIE) {
+ // MSIE sometimes produces <//tag>
+ if (n.nodeName.indexOf('/') != -1)
+ break;
- inst.switchSettings();
+ // MSIE has it's NS in a separate attrib
+ if (n.scopeName && n.scopeName != 'HTML')
+ nn = n.scopeName.toUpperCase() + ':' + nn.toUpperCase();
+ } else if (tinyMCE.isOpera && nn.indexOf(':') > 0)
+ nn = nn.toUpperCase();
+
+ // Convert fonts to spans
+ if (this.settings.convert_fonts_to_spans) {
+ // On get content FONT -> SPAN
+ if (this.settings.on_save && nn == 'FONT')
+ nn = 'SPAN';
+
+ // On insert content SPAN -> FONT
+ if (!this.settings.on_save && nn == 'SPAN')
+ nn = 'FONT';
+ }
- if (tinyMCE.settings["auto_resize"]) {
- var doc = inst.getDoc();
+ if (this.vElementsRe.test(nn) && (!this.iveRe || !this.iveRe.test(nn)) && !inn) {
+ va = true;
- inst.iframeElement.style.width = doc.body.offsetWidth + "px";
- inst.iframeElement.style.height = doc.body.offsetHeight + "px";
- }
+ r = this.rules[nn];
+ if (!r) {
+ at = this.rules;
+ for (no in at) {
+ if (at[no] && at[no].validRe.test(nn)) {
+ r = at[no];
+ break;
+ }
+ }
+ }
- if (tinyMCE.selectedElement)
- anySelection = (tinyMCE.selectedElement.nodeName.toLowerCase() == "img") || (selectedText && selectedText.length > 0);
+ en = r.isWild ? nn.toLowerCase() : r.oTagName;
+ f = r.fill;
- if (tinyMCE.settings['custom_undo_redo']) {
- undoIndex = inst.undoIndex;
- undoLevels = inst.undoLevels.length;
- }
+ if (r.removeEmpty && !hc)
+ return "";
- tinyMCE.executeCallback('handleNodeChangeCallback', '_handleNodeChange', 0, editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content);
- }
- }
+ t = '<' + en;
- if (this.selectedInstance && (typeof(focus) == "undefined" || focus))
- this.selectedInstance.contentWindow.focus();
-};
+ if (r.vAttribsReIsWild) {
+ // Serialize wildcard attributes
+ at = n.attributes;
+ for (i=at.length-1; i>-1; i--) {
+ no = at[i];
+ if (no.specified && r.vAttribsRe.test(no.nodeName))
+ t += this._serializeAttribute(n, r, no.nodeName);
+ }
+ } else {
+ // Serialize specific attributes
+ for (i=r.vAttribs.length-1; i>-1; i--)
+ t += this._serializeAttribute(n, r, r.vAttribs[i]);
+ }
-TinyMCE.prototype._customCleanup = function(inst, type, content) {
- // Call custom cleanup
- var customCleanup = tinyMCE.settings['cleanup_callback'];
- if (customCleanup != "" && eval("typeof(" + customCleanup + ")") != "undefined")
- content = eval(customCleanup + "(type, content, inst);");
-
- // Trigger plugin cleanups
- var plugins = tinyMCE.getParam('plugins', '', true, ',');
- for (var i=0; i<plugins.length; i++) {
- if (eval("typeof(TinyMCE_" + plugins[i] + "_cleanup)") != "undefined")
- content = eval("TinyMCE_" + plugins[i] + "_cleanup(type, content, inst);");
- }
+ // Serialize mce_ atts
+ if (!this.settings.on_save) {
+ at = this.mceAttribs;
- return content;
-};
+ for (no in at) {
+ if (at[no])
+ t += this._serializeAttribute(n, r, at[no]);
+ }
+ }
-TinyMCE.prototype.getContent = function(editor_id) {
- if (typeof(editor_id) != "undefined")
- tinyMCE.selectedInstance = tinyMCE.getInstanceById(editor_id);
+ // Check for required attribs
+ if (r.reqAttribsRe && !t.match(r.reqAttribsRe))
+ t = null;
- if (tinyMCE.selectedInstance) {
- var old = this.selectedInstance.getBody().innerHTML;
- var html = tinyMCE._cleanupHTML(this.selectedInstance, this.selectedInstance.getDoc(), tinyMCE.settings, this.selectedInstance.getBody(), false, true);
- tinyMCE.setInnerHTML(this.selectedInstance.getBody(), old);
- return html;
- }
+ // Close these
+ if (t != null && this.closeElementsRe.test(nn))
+ return t + ' />';
- return null;
-};
+ if (t != null)
+ h += t + '>';
-TinyMCE.prototype.setContent = function(html_content) {
- if (tinyMCE.selectedInstance) {
- tinyMCE.selectedInstance.execCommand('mceSetContent', false, html_content);
- tinyMCE.selectedInstance.repaint();
- }
-};
+ if (this.isIE && this.codeElementsRe.test(nn))
+ h += n.innerHTML;
+ }
+ break;
-TinyMCE.prototype.importThemeLanguagePack = function(name) {
- if (typeof(name) == "undefined")
- name = tinyMCE.settings['theme'];
+ case 3: // Text
+ if (st)
+ break;
- tinyMCE.loadScript(tinyMCE.baseURL + '/themes/' + name + '/langs/' + tinyMCE.settings['language'] + '.js');
-};
+ if (n.parentNode && this.codeElementsRe.test(n.parentNode.nodeName))
+ return this.isIE ? '' : n.nodeValue;
-TinyMCE.prototype.importPluginLanguagePack = function(name, valid_languages) {
- var lang = "en";
+ return this.xmlEncode(n.nodeValue);
- valid_languages = valid_languages.split(',');
- for (var i=0; i<valid_languages.length; i++) {
- if (tinyMCE.settings['language'] == valid_languages[i])
- lang = tinyMCE.settings['language'];
- }
+ case 8: // Comment
+ if (st)
+ break;
- tinyMCE.loadScript(tinyMCE.baseURL + '/plugins/' + name + '/langs/' + lang + '.js');
-};
+ return "<!--" + this._trimComment(n.nodeValue) + "-->";
+ }
-/**
- * Adds themeurl, settings and lang to HTML code.
- */
-TinyMCE.prototype.applyTemplate = function(html, args) {
- html = tinyMCE.replaceVar(html, "themeurl", tinyMCE.themeURL);
+ if (hc) {
+ cn = n.childNodes;
- if (typeof(args) != "undefined")
- html = tinyMCE.replaceVars(html, args);
+ for (i=0, l=cn.length; i<l; i++)
+ h += this.serializeNodeAsHTML(cn[i]);
+ }
- html = tinyMCE.replaceVars(html, tinyMCE.settings);
- html = tinyMCE.replaceVars(html, tinyMCELang);
+ // Fill empty nodes
+ if (f && !hc)
+ h += this.fillStr;
- return html;
-};
+ // End element
+ if (t != null && va)
+ h += '</' + en + '>';
-TinyMCE.prototype.openWindow = function(template, args) {
- var html, width, height, x, y, resizable, scrollbars, url;
+ return h;
+ },
- args['mce_template_file'] = template['file'];
- args['mce_width'] = template['width'];
- args['mce_height'] = template['height'];
- tinyMCE.windowArgs = args;
+ _serializeAttribute : function(n, r, an) {
+ var av = '', t, os = this.settings.on_save;
- html = template['html'];
- if (!(width = parseInt(template['width'])))
- width = 320;
+ if (os && (an.indexOf('mce_') == 0 || an.indexOf('_moz') == 0))
+ return '';
- if (!(height = parseInt(template['height'])))
- height = 200;
+ if (os && this.mceAttribs[an])
+ av = this._getAttrib(n, this.mceAttribs[an]);
- // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!!
- if (tinyMCE.isMSIE)
- height += 40;
- else
- height += 20;
+ if (av.length == 0)
+ av = this._getAttrib(n, an);
- x = parseInt(screen.width / 2.0) - (width / 2.0);
- y = parseInt(screen.height / 2.0) - (height / 2.0);
+ if (av.length == 0 && r.defaultAttribs && (t = r.defaultAttribs[an])) {
+ av = t;
- resizable = (args && args['resizable']) ? args['resizable'] : "no";
- scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no";
+ if (av == "mce_empty")
+ return " " + an + '=""';
+ }
- if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1)
- url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file'];
- else
- url = template['file'];
+ if (r.forceAttribs && (t = r.forceAttribs[an]))
+ av = t;
- // Replace all args as variables in URL
- for (var name in args) {
- if (typeof(args[name]) == 'function')
- continue;
+ if (os && av.length != 0 && /^(src|href|longdesc)$/.test(an))
+ av = this._urlConverter(this, n, av);
- url = tinyMCE.replaceVar(url, name, escape(args[name]));
- }
+ if (av.length != 0 && r.validAttribValues && r.validAttribValues[an] && !r.validAttribValues[an].test(av))
+ return "";
- if (html) {
- html = tinyMCE.replaceVar(html, "css", this.settings['popups_css']);
- html = tinyMCE.applyTemplate(html, args);
+ if (av.length != 0 && av == "{$uid}")
+ av = "uid_" + (this.idCount++);
- 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);
- if (win == null) {
- alert(tinyMCELang['lang_popup_blocked']);
- return;
+ if (av.length != 0) {
+ if (an.indexOf('on') != 0)
+ av = this.xmlEncode(av, 1);
+
+ return " " + an + "=" + '"' + av + '"';
}
- win.document.write(html);
- win.document.close();
- win.resizeTo(width, height);
- win.focus();
- } else {
- if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && resizable != 'yes' && tinyMCE.settings["dialog_type"] == "modal") {
- var features = "resizable:" + resizable
- + ";scroll:"
- + scrollbars + ";status:yes;center:yes;help:no;dialogWidth:"
- + width + "px;dialogHeight:" + height + "px;";
+ return "";
+ },
- window.showModalDialog(url, window, features);
- } else {
- var modal = (resizable == "yes") ? "no" : "yes";
+ formatHTML : function(h) {
+ var s = this.settings, p = '', i = 0, li = 0, o = '', l;
- if (tinyMCE.isGecko && tinyMCE.isMac)
- modal = "no";
+ // Replace BR in pre elements to \n
+ h = h.replace(/<pre([^>]*)>(.*?)<\/pre>/gi, function (a, b, c) {
+ c = c.replace(/<br\s*\/>/gi, '\n');
+ return '<pre' + b + '>' + c + '</pre>';
+ });
- if (template['close_previous'] != "no")
- try {tinyMCE.lastWindow.close();} catch (ex) {}
+ h = h.replace(/\r/g, ''); // Windows sux, isn't carriage return a thing of the past :)
+ h = '\n' + h;
+ h = h.replace(new RegExp('\\n\\s+', 'gi'), '\n'); // Remove previous formatting
+ h = h.replace(this.nlBeforeRe, '\n<$1$2>');
+ h = h.replace(this.nlAfterRe, '<$1$2>\n');
+ h = h.replace(this.nlBeforeAfterRe, '\n<$1$2$3>\n');
+ h += '\n';
- 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);
- if (win == null) {
- alert(tinyMCELang['lang_popup_blocked']);
- return;
+ //tinyMCE.debug(h);
+
+ while ((i = h.indexOf('\n', i + 1)) != -1) {
+ if ((l = h.substring(li + 1, i)).length != 0) {
+ if (this.ouRe.test(l) && p.length >= s.indent_levels)
+ p = p.substring(s.indent_levels);
+
+ o += p + l + '\n';
+
+ if (this.inRe.test(l))
+ p += this.inStr;
}
- if (template['close_previous'] != "no")
- tinyMCE.lastWindow = win;
+ li = i;
+ }
+
+ //tinyMCE.debug(h);
- eval('try { win.resizeTo(width, height); } catch(e) { }');
+ return o;
+ },
- // Make it bigger if statusbar is forced
- if (tinyMCE.isGecko) {
- if (win.document.defaultView.statusbar.visible)
- win.resizeBy(0, tinyMCE.isMac ? 10 : 24);
- }
+ xmlEncode : function(s) {
+ var cl = this, re = this.xmlEncodeRe;
- win.focus();
+ if (!this.entitiesDone)
+ this._setupEntities(); // Will intialize lookup table
+
+ switch (this.settings.entity_encoding) {
+ case "raw":
+ return tinyMCE.xmlEncode(s);
+
+ case "named":
+ return s.replace(re, function (c) {
+ var b = cl.entities[c.charCodeAt(0)];
+
+ return b ? '&' + b + ';' : c;
+ });
+
+ case "numeric":
+ return s.replace(re, function (c) {
+ return '&#' + c.charCodeAt(0) + ';';
+ });
+ }
+
+ return s;
+ },
+
+ split : function(re, s) {
+ var i, l, o = [], c = s.split(re);
+
+ for (i=0, l=c.length; i<l; i++) {
+ if (c[i] !== '')
+ o[i] = c[i];
}
- }
-};
-TinyMCE.prototype.closeWindow = function(win) {
- win.close();
-};
+ return o;
+ },
-TinyMCE.prototype.getVisualAidClass = function(class_name, state) {
- var aidClass = tinyMCE.settings['visual_table_class'];
+ _trimComment : function(s) {
+ // Remove mce_src, mce_href
+ s = s.replace(new RegExp('\\smce_src=\"[^\"]*\"', 'gi'), "");
+ s = s.replace(new RegExp('\\smce_href=\"[^\"]*\"', 'gi'), "");
- if (typeof(state) == "undefined")
- state = tinyMCE.settings['visual'];
+ return s;
+ },
- // Split
- var classNames = new Array();
- var ar = class_name.split(' ');
- for (var i=0; i<ar.length; i++) {
- if (ar[i] == aidClass)
- ar[i] = "";
+ _getAttrib : function(e, n, d) {
+ var v, ex, nn;
- if (ar[i] != "")
- classNames[classNames.length] = ar[i];
- }
+ if (typeof(d) == "undefined")
+ d = "";
- if (state)
- classNames[classNames.length] = aidClass;
+ if (!e || e.nodeType != 1)
+ return d;
- // Glue
- var className = "";
- for (var i=0; i<classNames.length; i++) {
- if (i > 0)
- className += " ";
+ try {
+ v = e.getAttribute(n, 0);
+ } catch (ex) {
+ // IE 7 may cast exception on invalid attributes
+ v = e.getAttribute(n, 2);
+ }
- className += classNames[i];
- }
+ if (n == "class" && !v)
+ v = e.className;
- return className;
-};
+ if (this.isIE) {
+ if (n == "http-equiv")
+ v = e.httpEquiv;
-TinyMCE.prototype.handleVisualAid = function(el, deep, state, inst) {
- if (!el)
- return;
+ nn = e.nodeName;
- var tableElement = null;
+ // Skip the default values that IE returns
+ if (nn == "FORM" && n == "enctype" && v == "application/x-www-form-urlencoded")
+ v = "";
- switch (el.nodeName) {
- case "TABLE":
- var oldW = el.style.width;
- var oldH = el.style.height;
- var bo = tinyMCE.getAttrib(el, "border");
+ if (nn == "INPUT" && n == "size" && v == "20")
+ v = "";
- bo = bo == "" || bo == "0" ? true : false;
+ if (nn == "INPUT" && n == "maxlength" && v == "2147483647")
+ v = "";
- tinyMCE.setAttrib(el, "class", tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el, "class"), state && bo));
+ // Images
+ if (n == "width" || n == "height")
+ v = e.getAttribute(n, 2);
+ }
- el.style.width = oldW;
- el.style.height = oldH;
+ if (n == 'style' && v) {
+ if (!tinyMCE.isOpera)
+ v = e.style.cssText;
- for (var y=0; y<el.rows.length; y++) {
- for (var x=0; x<el.rows[y].cells.length; x++) {
- var cn = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el.rows[y].cells[x], "class"), state && bo);
- tinyMCE.setAttrib(el.rows[y].cells[x], "class", cn);
- }
- }
+ v = tinyMCE.serializeStyle(tinyMCE.parseStyle(v));
+ }
- break;
+ if (this.settings.on_save && n.indexOf('on') != -1 && this.settings.on_save && v && v !== '')
+ v = tinyMCE.cleanupEventStr(v);
- case "A":
- var anchorName = tinyMCE.getAttrib(el, "name");
+ return (v && v !== '') ? '' + v : d;
+ },
- if (anchorName != '' && state) {
- el.title = anchorName;
- el.className = 'mceItemAnchor';
- } else if (anchorName != '' && !state)
- el.className = '';
+ _urlConverter : function(c, n, v) {
+ if (!c.settings.on_save)
+ return tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, v);
+ else if (tinyMCE.getParam('convert_urls')) {
+ if (!this.urlConverter)
+ this.urlConverter = eval(tinyMCE.settings.urlconverter_callback);
- break;
- }
+ return this.urlConverter(v, n, true);
+ }
- if (deep && el.hasChildNodes()) {
- for (var i=0; i<el.childNodes.length; i++)
- tinyMCE.handleVisualAid(el.childNodes[i], deep, state, inst);
- }
-};
+ return v;
+ },
-TinyMCE.prototype.getAttrib = function(elm, name, default_value) {
- if (typeof(default_value) == "undefined")
- default_value = "";
+ _arrayToRe : function(a, op, be, af) {
+ var i, r;
- // Not a element
- if (!elm || elm.nodeType != 1)
- return default_value;
+ op = typeof(op) == "undefined" ? "gi" : op;
+ be = typeof(be) == "undefined" ? "^(" : be;
+ af = typeof(af) == "undefined" ? ")$" : af;
- var v = elm.getAttribute(name);
+ r = be;
- // Try className for class attrib
- if (name == "class" && !v)
- v = elm.className;
+ for (i=0; i<a.length; i++)
+ r += this._wildcardToRe(a[i]) + (i != a.length-1 ? "|" : "");
- // Workaround for a issue with Firefox 1.5rc2+
- if (tinyMCE.isGecko && name == "src" && elm.src != null && elm.src != "")
- v = elm.src;
+ r += af;
- // Workaround for a issue with Firefox 1.5rc2+
- if (tinyMCE.isGecko && name == "href" && elm.href != null && elm.href != "")
- v = elm.href;
+ return new RegExp(r, op);
+ },
- if (name == "style" && !tinyMCE.isOpera)
- v = elm.style.cssText;
+ _wildcardToRe : function(s) {
+ s = s.replace(/\?/g, '(\\S?)');
+ s = s.replace(/\+/g, '(\\S+)');
+ s = s.replace(/\*/g, '(\\S*)');
- return (v && v != "") ? v : default_value;
-};
+ return s;
+ },
-TinyMCE.prototype.setAttrib = function(element, name, value, fix_value) {
- if (typeof(value) == "number" && value != null)
- value = "" + value;
+ _setupEntities : function() {
+ var n, a, i, s = this.settings;
- if (fix_value) {
- if (value == null)
- value = "";
+ // Setup entities
+ if (s.entity_encoding == "named") {
+ n = tinyMCE.clearArray([]);
+ a = this.split(',', s.entities);
+ for (i=0; i<a.length; i+=2)
+ n[a[i]] = a[i+1];
- var re = new RegExp('[^0-9%]', 'g');
- value = value.replace(re, '');
- }
+ this.entities = n;
+ }
- if (name == "style")
- element.style.cssText = value;
+ this.entitiesDone = true;
+ },
- if (name == "class")
- element.className = value;
+ _setupRules : function() {
+ var s = this.settings;
- if (value != null && value != "" && value != -1)
- element.setAttribute(name, value);
- else
- element.removeAttribute(name);
-};
+ // Setup default rule
+ this.addRuleStr(s.valid_elements);
+ this.addRuleStr(s.extended_valid_elements);
+ this.addChildRemoveRuleStr(s.valid_child_elements);
-TinyMCE.prototype.setStyleAttrib = function(elm, name, value) {
- eval('elm.style.' + name + '=value;');
+ this.rulesDone = true;
+ },
- // Style attrib deleted
- if (tinyMCE.isMSIE && value == null || value == '') {
- var str = tinyMCE.serializeStyle(tinyMCE.parseStyle(elm.style.cssText));
- elm.style.cssText = str;
- elm.setAttribute("style", str);
- }
-};
+ _isDuplicate : function(n) {
+ var i, l, sn;
-TinyMCE.prototype.convertSpansToFonts = function(doc) {
- var sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
+ if (!this.settings.fix_content_duplication)
+ return false;
- var h = doc.body.innerHTML;
- h = h.replace(/<span/gi, '<font');
- h = h.replace(/<\/span/gi, '</font');
- doc.body.innerHTML = h;
+ if (tinyMCE.isRealIE && n.nodeType == 1) {
+ // Mark elements
+ if (n.mce_serialized == this.serializationId)
+ return true;
- var s = doc.getElementsByTagName("font");
- for (var i=0; i<s.length; i++) {
- var size = tinyMCE.trim(s[i].style.fontSize).toLowerCase();
- var fSize = 0;
+ n.setAttribute('mce_serialized', this.serializationId);
+ } else {
+ sn = this.serializedNodes;
- for (var x=0; x<sizes.length; x++) {
- if (sizes[x] == size) {
- fSize = x + 1;
- break;
+ // Search lookup table for text nodes and comments
+ for (i=0, l = sn.length; i<l; i++) {
+ if (sn[i] == n)
+ return true;
}
- }
-
- if (fSize > 0) {
- tinyMCE.setAttrib(s[i], 'size', fSize);
- s[i].style.fontSize = '';
- }
- var fFace = s[i].style.fontFamily;
- if (fFace != null && fFace != "") {
- tinyMCE.setAttrib(s[i], 'face', fFace);
- s[i].style.fontFamily = '';
+ sn.push(n);
}
- var fColor = s[i].style.color;
- if (fColor != null && fColor != "") {
- tinyMCE.setAttrib(s[i], 'color', tinyMCE.convertRGBToHex(fColor));
- s[i].style.color = '';
- }
+ return false;
}
-};
-TinyMCE.prototype.convertFontsToSpans = function(doc) {
- var sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');
+ };
- var h = doc.body.innerHTML;
- h = h.replace(/<font/gi, '<span');
- h = h.replace(/<\/font/gi, '</span');
- doc.body.innerHTML = h;
+/* file:jscripts/tiny_mce/classes/TinyMCE_DOMUtils.class.js */
- var fsClasses = tinyMCE.getParam('font_size_classes');
- if (fsClasses != '')
- fsClasses = fsClasses.replace(/\s+/, '').split(',');
- else
- fsClasses = null;
+tinyMCE.add(TinyMCE_Engine, {
+ createTagHTML : function(tn, a, h) {
+ var o = '', f = tinyMCE.xmlEncode, n;
- var s = doc.getElementsByTagName("span");
- for (var i=0; i<s.length; i++) {
- var fSize, fFace, fColor;
+ o = '<' + tn;
- fSize = tinyMCE.getAttrib(s[i], 'size');
- fFace = tinyMCE.getAttrib(s[i], 'face');
- fColor = tinyMCE.getAttrib(s[i], 'color');
-
- if (fSize != "") {
- fSize = parseInt(fSize);
-
- if (fSize > 0 && fSize < 8) {
- if (fsClasses != null)
- tinyMCE.setAttrib(s[i], 'class', fsClasses[fSize-1]);
- else
- s[i].style.fontSize = sizes[fSize-1];
+ if (a) {
+ for (n in a) {
+ if (typeof(a[n]) != 'function' && a[n] != null)
+ o += ' ' + f(n) + '="' + f('' + a[n]) + '"';
}
-
- s[i].removeAttribute('size');
}
- if (fFace != "") {
- s[i].style.fontFamily = fFace;
- s[i].removeAttribute('face');
- }
+ o += !h ? ' />' : '>' + h + '</' + tn + '>';
+
+ return o;
+ },
- if (fColor != "") {
- s[i].style.color = fColor;
- s[i].removeAttribute('color');
+ createTag : function(d, tn, a, h) {
+ var o = d.createElement(tn), n;
+
+ if (a) {
+ for (n in a) {
+ if (typeof(a[n]) != 'function' && a[n] != null)
+ tinyMCE.setAttrib(o, n, a[n]);
+ }
}
- }
-};
-/*
-TinyMCE.prototype.applyClassesToFonts = function(doc, size) {
- var f = doc.getElementsByTagName("font");
- for (var i=0; i<f.length; i++) {
- var s = tinyMCE.getAttrib(f[i], "size");
+ if (h)
+ o.innerHTML = h;
- if (s != "")
- tinyMCE.setAttrib(f[i], 'class', "mceItemFont" + s);
- }
+ return o;
+ },
- if (typeof(size) != "undefined") {
- var css = "";
+ getElementByAttributeValue : function(n, e, a, v) {
+ return (n = this.getElementsByAttributeValue(n, e, a, v)).length == 0 ? null : n[0];
+ },
- for (var x=0; x<doc.styleSheets.length; x++) {
- for (var i=0; i<doc.styleSheets[x].rules.length; i++) {
- if (doc.styleSheets[x].rules[i].selectorText == '#mceSpanFonts .mceItemFont' + size) {
- css = doc.styleSheets[x].rules[i].style.cssText;
- break;
- }
- }
+ getElementsByAttributeValue : function(n, e, a, v) {
+ var i, nl = n.getElementsByTagName(e), o = [];
- if (css != "")
- break;
+ for (i=0; i<nl.length; i++) {
+ if (tinyMCE.getAttrib(nl[i], a).indexOf(v) != -1)
+ o[o.length] = nl[i];
}
- if (doc.styleSheets[0].rules[0].selectorText == "FONT")
- doc.styleSheets[0].removeRule(0);
+ return o;
+ },
- doc.styleSheets[0].addRule("FONT", css, 0);
- }
-};
-*/
-
-TinyMCE.prototype.setInnerHTML = function(e, h) {
- if (tinyMCE.isMSIE && !tinyMCE.isOpera) {
- e.innerHTML = tinyMCE.uniqueTag + h;
- e.firstChild.removeNode(true);
- } else {
- h = this.fixGeckoBaseHREFBug(1, e, h);
- e.innerHTML = h;
- this.fixGeckoBaseHREFBug(2, e, h);
- }
-};
+ isBlockElement : function(n) {
+ return n != null && n.nodeType == 1 && this.blockRegExp.test(n.nodeName);
+ },
-TinyMCE.prototype.fixGeckoBaseHREFBug = function(m, e, h) {
- if (tinyMCE.isGecko) {
- if (m == 1) {
- h = h.replace(/\ssrc=/gi, " xsrc=");
- h = h.replace(/\shref=/gi, " xhref=");
+ getParentBlockElement : function(n, r) {
+ return this.getParentNode(n, function(n) {
+ return tinyMCE.isBlockElement(n);
+ }, r);
- return h;
- } else {
- if (h.indexOf(' xsrc') != -1) {
- var n = e.getElementsByTagName("img");
- for (var i=0; i<n.length; i++) {
- var xsrc = tinyMCE.getAttrib(n[i], "xsrc");
-
- if (xsrc != "") {
- n[i].src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xsrc);
- n[i].removeAttribute("xsrc");
- }
- }
+ return null;
+ },
- // Select image form fields
- var n = e.getElementsByTagName("select");
- for (var i=0; i<n.length; i++) {
- var xsrc = tinyMCE.getAttrib(n[i], "xsrc");
+ insertAfter : function(n, r){
+ if (r.nextSibling)
+ r.parentNode.insertBefore(n, r.nextSibling);
+ else
+ r.parentNode.appendChild(n);
+ },
+
+ setInnerHTML : function(e, h) {
+ var i, nl, n;
+
+ // Convert all strong/em to b/i in Gecko
+ if (tinyMCE.isGecko) {
+ h = h.replace(/<embed([^>]*)>/gi, '<tmpembed$1>');
+ h = h.replace(/<em([^>]*)>/gi, '<i$1>');
+ h = h.replace(/<tmpembed([^>]*)>/gi, '<embed$1>');
+ h = h.replace(/<strong([^>]*)>/gi, '<b$1>');
+ h = h.replace(/<\/strong>/gi, '</b>');
+ h = h.replace(/<\/em>/gi, '</i>');
+ }
- if (xsrc != "") {
- n[i].src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xsrc);
- n[i].removeAttribute("xsrc");
- }
- }
+ if (tinyMCE.isRealIE) {
+ // Since MSIE handles invalid HTML better that valid XHTML we
+ // need to make some things invalid. <hr /> gets converted to <hr>.
+ h = h.replace(/\s\/>/g, '>');
- // iframes
- var n = e.getElementsByTagName("iframe");
- for (var i=0; i<n.length; i++) {
- var xsrc = tinyMCE.getAttrib(n[i], "xsrc");
+ // Since MSIE auto generated emtpy P tags some times we must tell it to keep the real ones
+ h = h.replace(/<p([^>]*)>\u00A0?<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs
+ h = h.replace(/<p([^>]*)>\s* \s*<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs
+ h = h.replace(/<p([^>]*)>\s+<\/p>/gi, '<p$1 mce_keep="true"> </p>'); // Keep empty paragraphs
- if (xsrc != "") {
- n[i].src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xsrc);
- n[i].removeAttribute("xsrc");
- }
- }
- }
+ // Remove first comment
+ e.innerHTML = tinyMCE.uniqueTag + h;
+ e.firstChild.removeNode(true);
- if (h.indexOf(' xhref') != -1) {
- var n = e.getElementsByTagName("a");
- for (var i=0; i<n.length; i++) {
- var xhref = tinyMCE.getAttrib(n[i], "xhref");
+ // Remove weird auto generated empty paragraphs unless it's supposed to be there
+ nl = e.getElementsByTagName("p");
+ for (i=nl.length-1; i>=0; i--) {
+ n = nl[i];
- if (xhref != "") {
- n[i].href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xhref);
- n[i].removeAttribute("xhref");
- }
- }
+ if (n.nodeName == 'P' && !n.hasChildNodes() && !n.mce_keep)
+ n.parentNode.removeChild(n);
}
+ } else {
+ h = this.fixGeckoBaseHREFBug(1, e, h);
+ e.innerHTML = h;
+ this.fixGeckoBaseHREFBug(2, e, h);
}
- }
+ },
- return h;
-};
+ getOuterHTML : function(e) {
+ var d;
-TinyMCE.prototype.getOuterHTML = function(e) {
- if (tinyMCE.isMSIE)
- return e.outerHTML;
+ if (tinyMCE.isIE)
+ return e.outerHTML;
- var d = e.ownerDocument.createElement("body");
- d.appendChild(e);
- return d.innerHTML;
-};
+ d = e.ownerDocument.createElement("body");
+ d.appendChild(e.cloneNode(true));
-TinyMCE.prototype.setOuterHTML = function(doc, e, h) {
- if (tinyMCE.isMSIE) {
- e.outerHTML = h;
- return;
- }
+ return d.innerHTML;
+ },
- var d = e.ownerDocument.createElement("body");
- d.innerHTML = h;
- e.parentNode.replaceChild(d.firstChild, e);
-};
+ setOuterHTML : function(e, h, d) {
+ var d = typeof(d) == "undefined" ? e.ownerDocument : d, i, nl, t;
-TinyMCE.prototype.insertAfter = function(nc, rc){
- if (rc.nextSibling)
- rc.parentNode.insertBefore(nc, rc.nextSibling);
- else
- rc.parentNode.appendChild(nc);
-};
+ if (tinyMCE.isIE && e.nodeType == 1)
+ e.outerHTML = h;
+ else {
+ t = d.createElement("body");
+ t.innerHTML = h;
-TinyMCE.prototype.cleanupAnchors = function(doc) {
- var an = doc.getElementsByTagName("a");
+ for (i=0, nl=t.childNodes; i<nl.length; i++)
+ e.parentNode.insertBefore(nl[i].cloneNode(true), e);
- for (var i=0; i<an.length; i++) {
- if (tinyMCE.getAttrib(an[i], "name") != "") {
- var cn = an[i].childNodes;
- for (var x=cn.length-1; x>=0; x--)
- tinyMCE.insertAfter(cn[x], an[i]);
+ e.parentNode.removeChild(e);
}
- }
-};
+ },
-TinyMCE.prototype._setHTML = function(doc, html_content) {
- // Force closed anchors open
- //html_content = html_content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
+ _getElementById : function(id, d) {
+ var e, i, j, f;
- html_content = tinyMCE.cleanupHTMLCode(html_content);
+ if (typeof(d) == "undefined")
+ d = document;
- // Try innerHTML if it fails use pasteHTML in MSIE
- try {
- tinyMCE.setInnerHTML(doc.body, html_content);
- } catch (e) {
- if (this.isMSIE)
- doc.body.createTextRange().pasteHTML(html_content);
- }
+ e = d.getElementById(id);
+ if (!e) {
+ f = d.forms;
- // Content duplication bug fix
- if (tinyMCE.isMSIE && tinyMCE.settings['fix_content_duplication']) {
- // Remove P elements in P elements
- var paras = doc.getElementsByTagName("P");
- for (var i=0; i<paras.length; i++) {
- var node = paras[i];
- while ((node = node.parentNode) != null) {
- if (node.nodeName == "P")
- node.outerHTML = node.innerHTML;
+ for (i=0; i<f.length; i++) {
+ for (j=0; j<f[i].elements.length; j++) {
+ if (f[i].elements[j].name == id) {
+ e = f[i].elements[j];
+ break;
+ }
+ }
}
}
- // Content duplication bug fix (Seems to be word crap)
- var html = doc.body.innerHTML;
+ return e;
+ },
- if (html.indexOf('="mso') != -1) {
- for (var i=0; i<doc.body.all.length; i++) {
- var el = doc.body.all[i];
- el.removeAttribute("className","",0);
- el.removeAttribute("style","",0);
- }
+ getNodeTree : function(n, na, t, nn) {
+ return this.selectNodes(n, function(n) {
+ return (!t || n.nodeType == t) && (!nn || n.nodeName == nn);
+ }, na ? na : []);
+ },
- html = doc.body.innerHTML;
- html = tinyMCE.regexpReplace(html, "<o:p><\/o:p>", "<br />");
- html = tinyMCE.regexpReplace(html, "<o:p> <\/o:p>", "");
- html = tinyMCE.regexpReplace(html, "<st1:.*?>", "");
- html = tinyMCE.regexpReplace(html, "<p><\/p>", "");
- html = tinyMCE.regexpReplace(html, "<p><\/p>\r\n<p><\/p>", "");
- html = tinyMCE.regexpReplace(html, "<p> <\/p>", "<br />");
- html = tinyMCE.regexpReplace(html, "<p>\s*(<p>\s*)?", "<p>");
- html = tinyMCE.regexpReplace(html, "<\/p>\s*(<\/p>\s*)?", "</p>");
- }
-
- // Always set the htmlText output
- tinyMCE.setInnerHTML(doc.body, html);
- }
+ getParentElement : function(n, na, f, r) {
+ var re = na ? new RegExp('^(' + na.toUpperCase().replace(/,/g, '|') + ')$') : 0, v;
- tinyMCE.cleanupAnchors(doc);
+ // Compatiblity with old scripts where f param was a attribute string
+ if (f && typeof(f) == 'string')
+ return this.getParentElement(n, na, function(no) {return tinyMCE.getAttrib(no, f) !== '';});
- if (tinyMCE.getParam("convert_fonts_to_spans"))
- tinyMCE.convertSpansToFonts(doc);
-};
+ return this.getParentNode(n, function(n) {
+ return ((n.nodeType == 1 && !re) || (re && re.test(n.nodeName))) && (!f || f(n));
+ }, r);
+ },
+
+ getParentNode : function(n, f, r) {
+ while (n) {
+ if (n == r)
+ return null;
-TinyMCE.prototype.getImageSrc = function(str) {
- var pos = -1;
+ if (f(n))
+ return n;
- if (!str)
- return "";
+ n = n.parentNode;
+ }
+
+ return null;
+ },
- if ((pos = str.indexOf('this.src=')) != -1) {
- var src = str.substring(pos + 10);
+ getAttrib : function(elm, name, dv) {
+ var v;
- src = src.substring(0, src.indexOf('\''));
+ if (typeof(dv) == "undefined")
+ dv = "";
- return src;
- }
+ // Not a element
+ if (!elm || elm.nodeType != 1)
+ return dv;
- return "";
-};
+ try {
+ v = elm.getAttribute(name, 0);
+ } catch (ex) {
+ // IE 7 may cast exception on invalid attributes
+ v = elm.getAttribute(name, 2);
+ }
-TinyMCE.prototype._getElementById = function(element_id) {
- var elm = document.getElementById(element_id);
- if (!elm) {
- // Check for element in forms
- for (var j=0; j<document.forms.length; j++) {
- for (var k=0; k<document.forms[j].elements.length; k++) {
- if (document.forms[j].elements[k].name == element_id) {
- elm = document.forms[j].elements[k];
+ // Try className for class attrib
+ if (name == "class" && !v)
+ v = elm.className;
+
+ // Workaround for a issue with Firefox 1.5rc2+
+ if (tinyMCE.isGecko) {
+ if (name == "src" && elm.src != null && elm.src !== '')
+ v = elm.src;
+
+ // Workaround for a issue with Firefox 1.5rc2+
+ if (name == "href" && elm.href != null && elm.href !== '')
+ v = elm.href;
+ } else if (tinyMCE.isIE) {
+ switch (name) {
+ case "http-equiv":
+ v = elm.httpEquiv;
+ break;
+
+ case "width":
+ case "height":
+ v = elm.getAttribute(name, 2);
break;
- }
}
}
- }
- return elm;
-};
+ if (name == "style" && !tinyMCE.isOpera)
+ v = elm.style.cssText;
-TinyMCE.prototype.getEditorId = function(form_element) {
- var inst = this.getInstanceById(form_element);
- if (!inst)
- return null;
+ return (v && v !== '') ? v : dv;
+ },
- return inst.editorId;
-};
+ setAttrib : function(el, name, va, fix) {
+ if (typeof(va) == "number" && va != null)
+ va = "" + va;
-TinyMCE.prototype.getInstanceById = function(editor_id) {
- var inst = this.instances[editor_id];
- if (!inst) {
- for (var n in tinyMCE.instances) {
- var instance = tinyMCE.instances[n];
- if (!tinyMCE.isInstance(instance))
- continue;
+ if (fix) {
+ if (va == null)
+ va = "";
- if (instance.formTargetElementId == editor_id) {
- inst = instance;
- break;
- }
+ va = va.replace(/[^0-9%]/g, '');
}
- }
-
- return inst;
-};
-
-TinyMCE.prototype.queryInstanceCommandValue = function(editor_id, command) {
- var inst = tinyMCE.getInstanceById(editor_id);
- if (inst)
- return inst.queryCommandValue(command);
-
- return false;
-};
-TinyMCE.prototype.queryInstanceCommandState = function(editor_id, command) {
- var inst = tinyMCE.getInstanceById(editor_id);
- if (inst)
- return inst.queryCommandState(command);
+ if (name == "style")
+ el.style.cssText = va;
- return null;
-};
+ if (name == "class")
+ el.className = va;
-TinyMCE.prototype.setWindowArg = function(name, value) {
- this.windowArgs[name] = value;
-};
+ if (va != null && va !== '' && va != -1)
+ el.setAttribute(name, va);
+ else
+ el.removeAttribute(name);
+ },
-TinyMCE.prototype.getWindowArg = function(name, default_value) {
- return (typeof(this.windowArgs[name]) == "undefined") ? default_value : this.windowArgs[name];
-};
+ setStyleAttrib : function(e, n, v) {
+ e.style[n] = v;
-TinyMCE.prototype.getCSSClasses = function(editor_id, doc) {
- var output = new Array();
+ // Style attrib deleted in IE
+ if (tinyMCE.isIE && v == null || v == '') {
+ v = tinyMCE.serializeStyle(tinyMCE.parseStyle(e.style.cssText));
+ e.style.cssText = v;
+ e.setAttribute("style", v);
+ }
+ },
- // Is cached, use that
- if (typeof(tinyMCE.cssClasses) != "undefined")
- return tinyMCE.cssClasses;
+ switchClass : function(ei, c) {
+ var e;
- if (typeof(editor_id) == "undefined" && typeof(doc) == "undefined") {
- var instance;
+ if (tinyMCE.switchClassCache[ei])
+ e = tinyMCE.switchClassCache[ei];
+ else
+ e = tinyMCE.switchClassCache[ei] = document.getElementById(ei);
- for (var instanceName in tinyMCE.instances) {
- instance = tinyMCE.instances[instanceName];
- if (!tinyMCE.isInstance(instance))
- continue;
+ if (e) {
+ // Keep tile mode
+ if (tinyMCE.settings.button_tile_map && e.className && e.className.indexOf('mceTiledButton') == 0)
+ c = 'mceTiledButton ' + c;
- break;
+ e.className = c;
}
+ },
- doc = instance.getDoc();
- }
-
- if (typeof(doc) == "undefined") {
- var instance = tinyMCE.getInstanceById(editor_id);
- doc = instance.getDoc();
- }
+ getAbsPosition : function(n, cn) {
+ var l = 0, t = 0;
- if (doc) {
- var styles = tinyMCE.isMSIE ? doc.styleSheets : doc.styleSheets;
+ while (n && n != cn) {
+ l += n.offsetLeft;
+ t += n.offsetTop;
+ n = n.offsetParent;
+ }
- if (styles && styles.length > 0) {
- for (var x=0; x<styles.length; x++) {
- var csses = null;
+ return {absLeft : l, absTop : t};
+ },
- // Just ignore any errors
- eval("try {var csses = tinyMCE.isMSIE ? doc.styleSheets(" + x + ").rules : doc.styleSheets[" + x + "].cssRules;} catch(e) {}");
- if (!csses)
- return new Array();
+ prevNode : function(e, n) {
+ var a = n.split(','), i;
- for (var i=0; i<csses.length; i++) {
- var selectorText = csses[i].selectorText;
+ while ((e = e.previousSibling) != null) {
+ for (i=0; i<a.length; i++) {
+ if (e.nodeName == a[i])
+ return e;
+ }
+ }
- // Can be multiple rules per selector
- if (selectorText) {
- var rules = selectorText.split(',');
- for (var c=0; c<rules.length; c++) {
- // Invalid rule
- if (rules[c].indexOf(' ') != -1 || rules[c].indexOf(':') != -1 || rules[c].indexOf('mceItem') != -1)
- continue;
+ return null;
+ },
- if (rules[c] == "." + tinyMCE.settings['visual_table_class'])
- continue;
+ nextNode : function(e, n) {
+ var a = n.split(','), i;
- // Is class rule
- if (rules[c].indexOf('.') != -1) {
- //alert(rules[c].substring(rules[c].indexOf('.')));
- output[output.length] = rules[c].substring(rules[c].indexOf('.')+1);
- }
- }
- }
- }
+ while ((e = e.nextSibling) != null) {
+ for (i=0; i<a.length; i++) {
+ if (e.nodeName == a[i])
+ return e;
}
}
- }
- // Cache em
- if (output.length > 0)
- tinyMCE.cssClasses = output;
+ return null;
+ },
- return output;
-};
+ selectElements : function(n, na, f) {
+ var i, a = [], nl, x;
-TinyMCE.prototype.regexpReplace = function(in_str, reg_exp, replace_str, opts) {
- if (in_str == null)
- return in_str;
+ for (x=0, na = na.split(','); x<na.length; x++)
+ for (i=0, nl = n.getElementsByTagName(na[x]); i<nl.length; i++)
+ (!f || f(nl[i])) && a.push(nl[i]);
- if (typeof(opts) == "undefined")
- opts = 'g';
+ return a;
+ },
- var re = new RegExp(reg_exp, opts);
- return in_str.replace(re, replace_str);
-};
+ selectNodes : function(n, f, a) {
+ var i;
-TinyMCE.prototype.trim = function(str) {
- return str.replace(/^\s*|\s*$/g, "");
-};
+ if (!a)
+ a = [];
-TinyMCE.prototype.cleanupEventStr = function(str) {
- str = "" + str;
- str = str.replace('function anonymous()\n{\n', '');
- str = str.replace('\n}', '');
- str = str.replace(/^return true;/gi, ''); // Remove event blocker
+ if (f(n))
+ a[a.length] = n;
- return str;
-};
+ if (n.hasChildNodes()) {
+ for (i=0; i<n.childNodes.length; i++)
+ tinyMCE.selectNodes(n.childNodes[i], f, a);
+ }
-TinyMCE.prototype.getAbsPosition = function(node) {
- var pos = new Object();
+ return a;
+ },
- pos.absLeft = pos.absTop = 0;
+ addCSSClass : function(e, c, b) {
+ var o = this.removeCSSClass(e, c);
+ return e.className = b ? c + (o !== '' ? (' ' + o) : '') : (o !== '' ? (o + ' ') : '') + c;
+ },
- var parentNode = node;
- while (parentNode) {
- pos.absLeft += parentNode.offsetLeft;
- pos.absTop += parentNode.offsetTop;
+ removeCSSClass : function(e, c) {
+ c = e.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' ');
+ return e.className = c != ' ' ? c : '';
+ },
- parentNode = parentNode.offsetParent;
- }
+ hasCSSClass : function(n, c) {
+ return new RegExp('\\b' + c + '\\b', 'g').test(n.className);
+ },
- return pos;
-};
+ renameElement : function(e, n, d) {
+ var ne, i, ar;
-TinyMCE.prototype.getControlHTML = function(control_name) {
- var themePlugins = tinyMCE.getParam('plugins', '', true, ',');
- var templateFunction;
+ d = typeof(d) == "undefined" ? tinyMCE.selectedInstance.getDoc() : d;
- // Is it defined in any plugins
- for (var i=themePlugins.length; i>=0; i--) {
- templateFunction = 'TinyMCE_' + themePlugins[i] + "_getControlHTML";
- if (eval("typeof(" + templateFunction + ")") != 'undefined') {
- var html = eval(templateFunction + "('" + control_name + "');");
- if (html != "")
- return tinyMCE.replaceVar(html, "pluginurl", tinyMCE.baseURL + "/plugins/" + themePlugins[i]);
- }
- }
+ if (e) {
+ ne = d.createElement(n);
- return eval('TinyMCE_' + tinyMCE.settings['theme'] + "_getControlHTML" + "('" + control_name + "');");
-};
+ ar = e.attributes;
+ for (i=ar.length-1; i>-1; i--) {
+ if (ar[i].specified && ar[i].nodeValue)
+ ne.setAttribute(ar[i].nodeName.toLowerCase(), ar[i].nodeValue);
+ }
-TinyMCE.prototype._themeExecCommand = function(editor_id, element, command, user_interface, value) {
- var themePlugins = tinyMCE.getParam('plugins', '', true, ',');
- var templateFunction;
+ ar = e.childNodes;
+ for (i=0; i<ar.length; i++)
+ ne.appendChild(ar[i].cloneNode(true));
- // Is it defined in any plugins
- for (var i=themePlugins.length; i>=0; i--) {
- templateFunction = 'TinyMCE_' + themePlugins[i] + "_execCommand";
- if (eval("typeof(" + templateFunction + ")") != 'undefined') {
- if (eval(templateFunction + "(editor_id, element, command, user_interface, value);"))
- return true;
+ e.parentNode.replaceChild(ne, e);
}
- }
+ },
- // Theme funtion
- templateFunction = 'TinyMCE_' + tinyMCE.settings['theme'] + "_execCommand";
- if (eval("typeof(" + templateFunction + ")") != 'undefined')
- return eval(templateFunction + "(editor_id, element, command, user_interface, value);");
-
- // Pass to normal
- return false;
-};
+ getViewPort : function(w) {
+ var d = w.document, m = d.compatMode == 'CSS1Compat', b = d.body, de = d.documentElement;
-TinyMCE.prototype._getThemeFunction = function(suffix, skip_plugins) {
- if (skip_plugins)
- return 'TinyMCE_' + tinyMCE.settings['theme'] + suffix;
+ return {
+ left : w.pageXOffset || (m ? de.scrollLeft : b.scrollLeft),
+ top : w.pageYOffset || (m ? de.scrollTop : b.scrollTop),
+ width : w.innerWidth || (m ? de.clientWidth : b.clientWidth),
+ height : w.innerHeight || (m ? de.clientHeight : b.clientHeight)
+ };
+ },
- var themePlugins = tinyMCE.getParam('plugins', '', true, ',');
- var templateFunction;
+ getStyle : function(n, na, d) {
+ if (!n)
+ return false;
- // Is it defined in any plugins
- for (var i=themePlugins.length; i>=0; i--) {
- templateFunction = 'TinyMCE_' + themePlugins[i] + suffix;
- if (eval("typeof(" + templateFunction + ")") != 'undefined')
- return templateFunction;
- }
+ // Gecko
+ if (tinyMCE.isGecko && n.ownerDocument.defaultView) {
+ try {
+ return n.ownerDocument.defaultView.getComputedStyle(n, null).getPropertyValue(na);
+ } catch (n) {
+ // Old safari might fail
+ return null;
+ }
+ }
- return 'TinyMCE_' + tinyMCE.settings['theme'] + suffix;
-};
+ // Camelcase it, if needed
+ na = na.replace(/-(\D)/g, function(a, b){
+ return b.toUpperCase();
+ });
+ // IE & Opera
+ if (n.currentStyle)
+ return n.currentStyle[na];
-TinyMCE.prototype.isFunc = function(func_name) {
- if (func_name == null || func_name == "")
return false;
+ }
- return eval("typeof(" + func_name + ")") != "undefined";
-};
+ });
-TinyMCE.prototype.exec = function(func_name, args) {
- var str = func_name + '(';
+/* file:jscripts/tiny_mce/classes/TinyMCE_URL.class.js */
- // Add all arguments
- for (var i=3; i<args.length; i++) {
- str += 'args[' + i + ']';
+tinyMCE.add(TinyMCE_Engine, {
+ parseURL : function(url_str) {
+ var urlParts = [], i, pos, lastPos, chr;
- if (i < args.length-1)
- str += ',';
- }
+ if (url_str) {
+ // Parse protocol part
+ pos = url_str.indexOf('://');
+ if (pos != -1) {
+ urlParts.protocol = url_str.substring(0, pos);
+ lastPos = pos + 3;
+ }
- str += ');';
+ // Find port or path start
+ for (i=lastPos; i<url_str.length; i++) {
+ chr = url_str.charAt(i);
- return eval(str);
-};
+ if (chr == ':')
+ break;
-TinyMCE.prototype.executeCallback = function(param, suffix, mode) {
- switch (mode) {
- // No chain
- case 0:
- var state = false;
-
- // Execute each plugin callback
- var plugins = tinyMCE.getParam('plugins', '', true, ',');
- for (var i=0; i<plugins.length; i++) {
- var func = "TinyMCE_" + plugins[i] + suffix;
- if (tinyMCE.isFunc(func)) {
- tinyMCE.exec(func, this.executeCallback.arguments);
- state = true;
- }
+ if (chr == '/')
+ break;
}
+ pos = i;
- // Execute theme callback
- var func = 'TinyMCE_' + tinyMCE.settings['theme'] + suffix;
- if (tinyMCE.isFunc(func)) {
- tinyMCE.exec(func, this.executeCallback.arguments);
- state = true;
- }
+ // Get host
+ urlParts.host = url_str.substring(lastPos, pos);
- // Execute settings callback
- var func = tinyMCE.getParam(param, '');
- if (tinyMCE.isFunc(func)) {
- tinyMCE.exec(func, this.executeCallback.arguments);
- state = true;
+ // Get port
+ urlParts.port = "";
+ lastPos = pos;
+ if (url_str.charAt(pos) == ':') {
+ pos = url_str.indexOf('/', lastPos);
+ urlParts.port = url_str.substring(lastPos+1, pos);
}
- return state;
+ // Get path
+ lastPos = pos;
+ pos = url_str.indexOf('?', lastPos);
- // Chain mode
- case 1:
- // Execute each plugin callback
- var plugins = tinyMCE.getParam('plugins', '', true, ',');
- for (var i=0; i<plugins.length; i++) {
- var func = "TinyMCE_" + plugins[i] + suffix;
- if (tinyMCE.isFunc(func)) {
- if (tinyMCE.exec(func, this.executeCallback.arguments))
- return true;
- }
- }
+ if (pos == -1)
+ pos = url_str.indexOf('#', lastPos);
- // Execute theme callback
- var func = 'TinyMCE_' + tinyMCE.settings['theme'] + suffix;
- if (tinyMCE.isFunc(func)) {
- if (tinyMCE.exec(func, this.executeCallback.arguments))
- return true;
+ if (pos == -1)
+ pos = url_str.length;
+
+ urlParts.path = url_str.substring(lastPos, pos);
+
+ // Get query
+ lastPos = pos;
+ if (url_str.charAt(pos) == '?') {
+ pos = url_str.indexOf('#');
+ pos = (pos == -1) ? url_str.length : pos;
+ urlParts.query = url_str.substring(lastPos+1, pos);
}
- // Execute settings callback
- var func = tinyMCE.getParam(param, '');
- if (tinyMCE.isFunc(func)) {
- if (tinyMCE.exec(func, this.executeCallback.arguments))
- return true;
+ // Get anchor
+ lastPos = pos;
+ if (url_str.charAt(pos) == '#') {
+ pos = url_str.length;
+ urlParts.anchor = url_str.substring(lastPos+1, pos);
}
+ }
- return false;
- }
-};
+ return urlParts;
+ },
-TinyMCE.prototype.debug = function() {
- var msg = "";
+ serializeURL : function(up) {
+ var o = "";
- var elm = document.getElementById("tinymce_debug");
- if (!elm) {
- var debugDiv = document.createElement("div");
- debugDiv.setAttribute("className", "debugger");
- debugDiv.className = "debugger";
- debugDiv.innerHTML = '\
- Debug output:\
- <textarea id="tinymce_debug" style="width: 100%; height: 300px" wrap="nowrap"></textarea>';
+ if (up.protocol)
+ o += up.protocol + "://";
- document.body.appendChild(debugDiv);
- elm = document.getElementById("tinymce_debug");
- }
+ if (up.host)
+ o += up.host;
- var args = this.debug.arguments;
- for (var i=0; i<args.length; i++) {
- msg += args[i];
- if (i<args.length-1)
- msg += ', ';
- }
+ if (up.port)
+ o += ":" + up.port;
- elm.value += msg + "\n";
-};
+ if (up.path)
+ o += up.path;
-// TinyMCEControl
-function TinyMCEControl(settings) {
- // Undo levels
- this.undoLevels = new Array();
- this.undoIndex = 0;
- this.typingUndoIndex = -1;
- this.undoRedo = true;
- this.isTinyMCEControl = true;
+ if (up.query)
+ o += "?" + up.query;
- // Default settings
- this.settings = settings;
- this.settings['theme'] = tinyMCE.getParam("theme", "default");
- this.settings['width'] = tinyMCE.getParam("width", -1);
- this.settings['height'] = tinyMCE.getParam("height", -1);
-};
+ if (up.anchor)
+ o += "#" + up.anchor;
-TinyMCEControl.prototype.repaint = function() {
- if (tinyMCE.isMSIE && !tinyMCE.isOpera)
- return;
-
- // Ugly mozilla hack to remove ghost resize handles
- try {
- this.getBody().style.display = 'none';
- this.getDoc().execCommand('selectall', false, null);
- this.getSel().collapseToStart();
- this.getBody().style.display = 'block';
- } catch (ex) {
- // Could I care less!!
- }
-};
+ return o;
+ },
-TinyMCEControl.prototype.switchSettings = function() {
- if (tinyMCE.configs.length > 1 && tinyMCE.currentConfig != this.settings['index']) {
- tinyMCE.settings = this.settings;
- tinyMCE.currentConfig = this.settings['index'];
- }
-};
+ convertAbsoluteURLToRelativeURL : function(base_url, url_to_relative) {
+ var baseURL = this.parseURL(base_url), targetURL = this.parseURL(url_to_relative);
+ var i, strTok1, strTok2, breakPoint = 0, outPath = "", forceSlash = false;
+ var fileName, pos;
-TinyMCEControl.prototype.convertAllRelativeURLs = function() {
- var body = this.getBody();
+ if (targetURL.path == '')
+ targetURL.path = "/";
+ else
+ forceSlash = true;
- // Convert all image URL:s to absolute URL
- var elms = body.getElementsByTagName("img");
- for (var i=0; i<elms.length; i++) {
- var src = tinyMCE.getAttrib(elms[i], 'src');
+ // Crop away last path part
+ base_url = baseURL.path.substring(0, baseURL.path.lastIndexOf('/'));
+ strTok1 = base_url.split('/');
+ strTok2 = targetURL.path.split('/');
- var msrc = tinyMCE.getAttrib(elms[i], 'mce_src');
- if (msrc != "")
- src = msrc;
+ if (strTok1.length >= strTok2.length) {
+ for (i=0; i<strTok1.length; i++) {
+ if (i >= strTok2.length || strTok1[i] != strTok2[i]) {
+ breakPoint = i + 1;
+ break;
+ }
+ }
+ }
- if (src != "") {
- src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);
- elms[i].setAttribute("src", src);
+ if (strTok1.length < strTok2.length) {
+ for (i=0; i<strTok2.length; i++) {
+ if (i >= strTok1.length || strTok1[i] != strTok2[i]) {
+ breakPoint = i + 1;
+ break;
+ }
+ }
}
- }
- // Convert all link URL:s to absolute URL
- var elms = body.getElementsByTagName("a");
- for (var i=0; i<elms.length; i++) {
- var href = tinyMCE.getAttrib(elms[i], 'href');
+ if (breakPoint == 1)
+ return targetURL.path;
- var mhref = tinyMCE.getAttrib(elms[i], 'mce_href');
- if (mhref != "")
- href = mhref;
+ for (i=0; i<(strTok1.length-(breakPoint-1)); i++)
+ outPath += "../";
- if (href && href != "") {
- href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], href);
- elms[i].setAttribute("href", href);
+ for (i=breakPoint-1; i<strTok2.length; i++) {
+ if (i != (breakPoint-1))
+ outPath += "/" + strTok2[i];
+ else
+ outPath += strTok2[i];
}
- }
-};
-TinyMCEControl.prototype.getSelectedHTML = function() {
- if (tinyMCE.isSafari) {
- // Not realy perfect!!
+ targetURL.protocol = null;
+ targetURL.host = null;
+ targetURL.port = null;
+ targetURL.path = outPath == '' && forceSlash ? "/" : outPath;
- return this.getRng().toString();
- }
+ // Remove document prefix from local anchors
+ fileName = baseURL.path;
- var elm = document.createElement("body");
+ if ((pos = fileName.lastIndexOf('/')) != -1)
+ fileName = fileName.substring(pos + 1);
- if (tinyMCE.isGecko)
- elm.appendChild(this.getRng().cloneContents());
- else
- elm.innerHTML = this.getRng().htmlText;
+ // Is local anchor
+ if (fileName == targetURL.path && targetURL.anchor !== '')
+ targetURL.path = "";
- return tinyMCE._cleanupHTML(this, this.contentDocument, this.settings, elm, this.visualAid);
-};
+ // If empty and not local anchor force filename or slash
+ if (targetURL.path == '' && !targetURL.anchor)
+ targetURL.path = fileName !== '' ? fileName : "/";
-TinyMCEControl.prototype.getBookmark = function() {
- var rng = this.getRng();
+ return this.serializeURL(targetURL);
+ },
- if (tinyMCE.isSafari)
- return rng;
+ convertRelativeToAbsoluteURL : function(base_url, relative_url) {
+ var baseURL = this.parseURL(base_url), baseURLParts, relURLParts, newRelURLParts, numBack, relURL = this.parseURL(relative_url), i;
+ var len, absPath, start, end, newBaseURLParts;
- if (tinyMCE.isMSIE)
- return rng;
+ if (relative_url == '' || relative_url.indexOf('://') != -1 || /^(mailto:|javascript:|#|\/)/.test(relative_url))
+ return relative_url;
- if (tinyMCE.isGecko)
- return rng.cloneRange();
+ // Split parts
+ baseURLParts = baseURL.path.split('/');
+ relURLParts = relURL.path.split('/');
- return null;
-};
+ // Remove empty chunks
+ newBaseURLParts = [];
+ for (i=baseURLParts.length-1; i>=0; i--) {
+ if (baseURLParts[i].length == 0)
+ continue;
-TinyMCEControl.prototype.moveToBookmark = function(bookmark) {
- if (tinyMCE.isSafari) {
- var sel = this.getSel().realSelection;
+ newBaseURLParts[newBaseURLParts.length] = baseURLParts[i];
+ }
+ baseURLParts = newBaseURLParts.reverse();
- sel.setBaseAndExtent(bookmark.startContainer, bookmark.startOffset, bookmark.endContainer, bookmark.endOffset);
+ // Merge relURLParts chunks
+ newRelURLParts = [];
+ numBack = 0;
+ for (i=relURLParts.length-1; i>=0; i--) {
+ if (relURLParts[i].length == 0 || relURLParts[i] == ".")
+ continue;
- return true;
- }
+ if (relURLParts[i] == '..') {
+ numBack++;
+ continue;
+ }
- if (tinyMCE.isMSIE)
- return bookmark.select();
+ if (numBack > 0) {
+ numBack--;
+ continue;
+ }
- if (tinyMCE.isGecko) {
- var rng = this.getDoc().createRange();
- var sel = this.getSel();
+ newRelURLParts[newRelURLParts.length] = relURLParts[i];
+ }
- rng.setStart(bookmark.startContainer, bookmark.startOffset);
- rng.setEnd(bookmark.endContainer, bookmark.endOffset);
+ relURLParts = newRelURLParts.reverse();
- sel.removeAllRanges();
- sel.addRange(rng);
+ // Remove end from absolute path
+ len = baseURLParts.length-numBack;
+ absPath = (len <= 0 ? "" : "/") + baseURLParts.slice(0, len).join('/') + "/" + relURLParts.join('/');
+ start = "";
+ end = "";
- return true;
- }
+ // Build output URL
+ relURL.protocol = baseURL.protocol;
+ relURL.host = baseURL.host;
+ relURL.port = baseURL.port;
- return false;
-};
+ // Re-add trailing slash if it's removed
+ if (relURL.path.charAt(relURL.path.length-1) == "/")
+ absPath += "/";
-TinyMCEControl.prototype.getSelectedText = function() {
- if (tinyMCE.isMSIE) {
- var doc = this.getDoc();
+ relURL.path = absPath;
- if (doc.selection.type == "Text") {
- var rng = doc.selection.createRange();
- selectedText = rng.text;
- } else
- selectedText = '';
- } else {
- var sel = this.getSel();
+ return this.serializeURL(relURL);
+ },
- if (sel && sel.toString)
- selectedText = sel.toString();
- else
- selectedText = '';
- }
+ convertURL : function(url, node, on_save) {
+ var dl = document.location, start, portPart, urlParts, baseUrlParts, tmpUrlParts, curl;
+ var prot = dl.protocol, host = dl.hostname, port = dl.port;
- return selectedText;
-};
+ // Pass through file protocol
+ if (prot == "file:")
+ return url;
-TinyMCEControl.prototype.selectNode = function(node, collapse, select_text_node, to_start) {
- if (!node)
- return;
+ // Something is wrong, remove weirdness
+ url = tinyMCE.regexpReplace(url, '(http|https):///', '/');
- if (typeof(collapse) == "undefined")
- collapse = true;
+ // Mailto link or anchor (Pass through)
+ if (url.indexOf('mailto:') != -1 || url.indexOf('javascript:') != -1 || /^[ \t\r\n\+]*[#\?]/.test(url))
+ return url;
- if (typeof(select_text_node) == "undefined")
- select_text_node = false;
+ // Fix relative/Mozilla
+ if (!tinyMCE.isIE && !on_save && url.indexOf("://") == -1 && url.charAt(0) != '/')
+ return tinyMCE.settings.base_href + url;
- if (typeof(to_start) == "undefined")
- to_start = true;
+ // Handle relative URLs
+ if (on_save && tinyMCE.getParam('relative_urls')) {
+ curl = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, url);
+ if (curl.charAt(0) == '/')
+ curl = tinyMCE.settings.document_base_prefix + curl;
- if (tinyMCE.isMSIE) {
- var rng = this.getBody().createTextRange();
+ urlParts = tinyMCE.parseURL(curl);
+ tmpUrlParts = tinyMCE.parseURL(tinyMCE.settings.document_base_url);
- try {
- rng.moveToElementText(node);
+ // Force relative
+ if (urlParts.host == tmpUrlParts.host && (urlParts.port == tmpUrlParts.port))
+ return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings.document_base_url, curl);
+ }
- if (collapse)
- rng.collapse(to_start);
+ // Handle absolute URLs
+ if (!tinyMCE.getParam('relative_urls')) {
+ urlParts = tinyMCE.parseURL(url);
+ baseUrlParts = tinyMCE.parseURL(tinyMCE.settings.base_href);
- rng.select();
- } catch (e) {
- // Throws illigal agrument in MSIE some times
- }
- } else {
- var sel = this.getSel();
+ // Force absolute URLs from relative URLs
+ url = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, url);
- if (!sel)
- return;
+ // If anchor and path is the same page
+ if (urlParts.anchor && urlParts.path == baseUrlParts.path)
+ return "#" + urlParts.anchor;
+ }
- if (tinyMCE.isSafari) {
- sel.realSelection.setBaseAndExtent(node, 0, node, node.innerText.length);
+ // Remove current domain
+ if (tinyMCE.getParam('remove_script_host')) {
+ start = "";
+ portPart = "";
- if (collapse) {
- if (to_start)
- sel.realSelection.collapseToStart();
- else
- sel.realSelection.collapseToEnd();
- }
+ if (port !== '')
+ portPart = ":" + port;
- this.scrollToNode(node);
+ start = prot + "//" + host + portPart + "/";
- return;
+ if (url.indexOf(start) == 0)
+ url = url.substring(start.length-1);
}
- var rng = this.getDoc().createRange();
+ return url;
+ },
- if (select_text_node) {
- // Find first textnode in tree
- var nodes = tinyMCE.getNodeTree(node, new Array(), 3);
- if (nodes.length > 0)
- rng.selectNodeContents(nodes[0]);
- else
- rng.selectNodeContents(node);
- } else
- rng.selectNode(node);
+ convertAllRelativeURLs : function(body) {
+ var i, elms, src, href, mhref, msrc;
- if (collapse) {
- // Special treatment of textnode collapse
- if (!to_start && node.nodeType == 3) {
- rng.setStart(node, node.nodeValue.length);
- rng.setEnd(node, node.nodeValue.length);
- } else
- rng.collapse(to_start);
+ // Convert all image URL:s to absolute URL
+ elms = body.getElementsByTagName("img");
+ for (i=0; i<elms.length; i++) {
+ src = tinyMCE.getAttrib(elms[i], 'src');
+
+ msrc = tinyMCE.getAttrib(elms[i], 'mce_src');
+ if (msrc !== '')
+ src = msrc;
+
+ if (src !== '') {
+ src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, src);
+ elms[i].setAttribute("src", src);
+ }
}
- sel.removeAllRanges();
- sel.addRange(rng);
- }
+ // Convert all link URL:s to absolute URL
+ elms = body.getElementsByTagName("a");
+ for (i=0; i<elms.length; i++) {
+ href = tinyMCE.getAttrib(elms[i], 'href');
- this.scrollToNode(node);
+ mhref = tinyMCE.getAttrib(elms[i], 'mce_href');
+ if (mhref !== '')
+ href = mhref;
- // Set selected element
- tinyMCE.selectedElement = null;
- if (node.nodeType == 1)
- tinyMCE.selectedElement = node;
-};
+ if (href && href !== '') {
+ href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings.base_href, href);
+ elms[i].setAttribute("href", href);
+ }
+ }
+ }
-TinyMCEControl.prototype.scrollToNode = function(node) {
- // Scroll to node position
- var pos = tinyMCE.getAbsPosition(node);
- var doc = this.getDoc();
- var scrollX = doc.body.scrollLeft + doc.documentElement.scrollLeft;
- var scrollY = doc.body.scrollTop + doc.documentElement.scrollTop;
- var height = tinyMCE.isMSIE ? document.getElementById(this.editorId).style.pixelHeight : this.targetElement.clientHeight;
-
- // Only scroll if out of visible area
- if (!tinyMCE.settings['auto_resize'] && !(pos.absTop > scrollY && pos.absTop < (scrollY - 25 + height)))
- this.contentWindow.scrollTo(pos.absLeft, pos.absTop - height + 25);
-};
+ });
-TinyMCEControl.prototype.getBody = function() {
- return this.getDoc().body;
-};
+/* file:jscripts/tiny_mce/classes/TinyMCE_Array.class.js */
-TinyMCEControl.prototype.getDoc = function() {
- return this.contentWindow.document;
-};
+tinyMCE.add(TinyMCE_Engine, {
+ clearArray : function(a) {
+ var n;
-TinyMCEControl.prototype.getWin = function() {
- return this.contentWindow;
-};
+ for (n in a)
+ a[n] = null;
-TinyMCEControl.prototype.getSel = function() {
- if (tinyMCE.isMSIE && !tinyMCE.isOpera)
- return this.getDoc().selection;
+ return a;
+ },
- var sel = this.contentWindow.getSelection();
+ explode : function(d, s) {
+ var ar = s.split(d), oar = [], i;
- // Fake getRangeAt
- if (tinyMCE.isSafari && !sel.getRangeAt) {
- var newSel = new Object();
- var doc = this.getDoc();
+ for (i = 0; i<ar.length; i++) {
+ if (ar[i] !== '')
+ oar[oar.length] = ar[i];
+ }
- function getRangeAt(idx) {
- var rng = new Object();
+ return oar;
+ }
+});
- rng.startContainer = this.focusNode;
- rng.endContainer = this.anchorNode;
- rng.commonAncestorContainer = this.focusNode;
- rng.createContextualFragment = function (html) {
- // Seems to be a tag
- if (html.charAt(0) == '<') {
- var elm = doc.createElement("div");
+/* file:jscripts/tiny_mce/classes/TinyMCE_Event.class.js */
- elm.innerHTML = html;
+tinyMCE.add(TinyMCE_Engine, {
+ _setEventsEnabled : function(node, state) {
+ var evs, x, y, elms, i, event;
+ var events = ['onfocus','onblur','onclick','ondblclick',
+ 'onmousedown','onmouseup','onmouseover','onmousemove',
+ 'onmouseout','onkeypress','onkeydown','onkeydown','onkeyup'];
- return elm.firstChild;
- }
+ evs = tinyMCE.settings.event_elements.split(',');
+ for (y=0; y<evs.length; y++){
+ elms = node.getElementsByTagName(evs[y]);
+ for (i=0; i<elms.length; i++) {
+ event = "";
- return doc.createTextNode("UNSUPPORTED, DUE TO LIMITATIONS IN SAFARI!");
- };
+ for (x=0; x<events.length; x++) {
+ if ((event = tinyMCE.getAttrib(elms[i], events[x])) !== '') {
+ event = tinyMCE.cleanupEventStr("" + event);
- rng.deleteContents = function () {
- doc.execCommand("Delete", false, "");
- };
+ if (!state)
+ event = "return true;" + event;
+ else
+ event = event.replace(/^return true;/gi, '');
- return rng;
+ elms[i].removeAttribute(events[x]);
+ elms[i].setAttribute(events[x], event);
+ }
+ }
+ }
}
+ },
- // Patch selection
+ _eventPatch : function(editor_id) {
+ var n, inst, win, e;
- newSel.focusNode = sel.baseNode;
- newSel.focusOffset = sel.baseOffset;
- newSel.anchorNode = sel.extentNode;
- newSel.anchorOffset = sel.extentOffset;
- newSel.getRangeAt = getRangeAt;
- newSel.text = "" + sel;
- newSel.realSelection = sel;
+ // Remove odd, error
+ if (typeof(tinyMCE) == "undefined")
+ return true;
- newSel.toString = function () {return this.text;};
+ try {
+ // Try selected instance first
+ if (tinyMCE.selectedInstance) {
+ win = tinyMCE.selectedInstance.getWin();
- return newSel;
- }
+ if (win && win.event) {
+ e = win.event;
- return sel;
-};
+ if (!e.target)
+ e.target = e.srcElement;
-TinyMCEControl.prototype.getRng = function() {
- var sel = this.getSel();
- if (sel == null)
- return null;
+ TinyMCE_Engine.prototype.handleEvent(e);
+ return;
+ }
+ }
- if (tinyMCE.isMSIE && !tinyMCE.isOpera)
- return sel.createRange();
+ // Search for it
+ for (n in tinyMCE.instances) {
+ inst = tinyMCE.instances[n];
- if (tinyMCE.isSafari) {
- var rng = this.getDoc().createRange();
- var sel = this.getSel().realSelection;
+ if (!tinyMCE.isInstance(inst))
+ continue;
- rng.setStart(sel.baseNode, sel.baseOffset);
- rng.setEnd(sel.extentNode, sel.extentOffset);
+ inst.select();
+ win = inst.getWin();
- return rng;
- }
+ if (win && win.event) {
+ e = win.event;
- return this.getSel().getRangeAt(0);
-};
+ if (!e.target)
+ e.target = e.srcElement;
-TinyMCEControl.prototype._insertPara = function(e) {
- function isEmpty(para) {
- function isEmptyHTML(html) {
- return html.replace(new RegExp('[ \t\r\n]+', 'g'), '').toLowerCase() == "";
+ TinyMCE_Engine.prototype.handleEvent(e);
+ return;
+ }
+ }
+ } catch (ex) {
+ // Ignore error if iframe is pointing to external URL
}
+ },
- // Check for images
- if (para.getElementsByTagName("img").length > 0)
- return false;
+ findEvent : function(e) {
+ var n, inst;
- // Check for tables
- if (para.getElementsByTagName("table").length > 0)
- return false;
+ if (e)
+ return e;
- // Check for HRs
- if (para.getElementsByTagName("hr").length > 0)
- return false;
+ for (n in tinyMCE.instances) {
+ inst = tinyMCE.instances[n];
- // Check all textnodes
- var nodes = tinyMCE.getNodeTree(para, new Array(), 3);
- for (var i=0; i<nodes.length; i++) {
- if (!isEmptyHTML(nodes[i].nodeValue))
- return false;
+ if (tinyMCE.isInstance(inst) && inst.getWin().event)
+ return inst.getWin().event;
}
- // No images, no tables, no hrs, no text content then it's empty
- return true;
- }
-
- var doc = this.getDoc();
- var sel = this.getSel();
- var win = this.contentWindow;
- var rng = sel.getRangeAt(0);
- var body = doc.body;
- var rootElm = doc.documentElement;
- var self = this;
- var blockName = "P";
+ return null;
+ },
-// tinyMCE.debug(body.innerHTML);
+ unloadHandler : function() {
+ tinyMCE.triggerSave(true, true);
+ },
-// debug(e.target, sel.anchorNode.nodeName, sel.focusNode.nodeName, rng.startContainer, rng.endContainer, rng.commonAncestorContainer, sel.anchorOffset, sel.focusOffset, rng.toString());
+ addEventHandlers : function(inst) {
+ this.setEventHandlers(inst, 1);
+ },
- // Setup before range
- var rngBefore = doc.createRange();
- rngBefore.setStart(sel.anchorNode, sel.anchorOffset);
- rngBefore.collapse(true);
+ setEventHandlers : function(inst, s) {
+ var doc = inst.getDoc(), ie, ot, i, f = s ? tinyMCE.addEvent : tinyMCE.removeEvent;
- // Setup after range
- var rngAfter = doc.createRange();
- rngAfter.setStart(sel.focusNode, sel.focusOffset);
- rngAfter.collapse(true);
+ ie = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'controlselect', 'dblclick'];
+ ot = ['keypress', 'keyup', 'keydown', 'click', 'mouseup', 'mousedown', 'focus', 'blur', 'dragdrop'];
- // Setup start/end points
- var direct = rngBefore.compareBoundaryPoints(rngBefore.START_TO_END, rngAfter) < 0;
- var startNode = direct ? sel.anchorNode : sel.focusNode;
- var startOffset = direct ? sel.anchorOffset : sel.focusOffset;
- var endNode = direct ? sel.focusNode : sel.anchorNode;
- var endOffset = direct ? sel.focusOffset : sel.anchorOffset;
+ inst.switchSettings();
- startNode = startNode.nodeName == "BODY" ? startNode.firstChild : startNode;
- endNode = endNode.nodeName == "BODY" ? endNode.firstChild : endNode;
+ if (tinyMCE.isIE) {
+ for (i=0; i<ie.length; i++)
+ f(doc, ie[i], TinyMCE_Engine.prototype._eventPatch);
+ } else {
+ for (i=0; i<ot.length; i++)
+ f(doc, ot[i], tinyMCE.handleEvent);
+
+ // Force designmode
+ try {
+ doc.designMode = "On";
+ } catch (e) {
+ // Ignore
+ }
+ }
+ },
- // tinyMCE.debug(startNode, endNode);
+ onMouseMove : function() {
+ var inst, lh;
- // Get block elements
- var startBlock = tinyMCE.getParentBlockElement(startNode);
- var endBlock = tinyMCE.getParentBlockElement(endNode);
+ // Fix for IE7 bug where it's not restoring hover on anchors correctly
+ if (tinyMCE.lastHover) {
+ lh = tinyMCE.lastHover;
- // Use current block name
- if (startBlock != null) {
- blockName = startBlock.nodeName;
+ // Call out on menus and refresh class on normal buttons
+ if (lh.className.indexOf('mceMenu') != -1)
+ tinyMCE._menuButtonEvent('out', lh);
+ else
+ lh.className = lh.className;
- // Use P instead
- if (blockName == "TD" || blockName == "TABLE" || (blockName == "DIV" && new RegExp('left|right', 'gi').test(startBlock.style.cssFloat)))
- blockName = "P";
- }
+ tinyMCE.lastHover = null;
+ }
- // Within a list use normal behaviour
- if (tinyMCE.getParentElement(startBlock, "OL,UL") != null)
- return false;
+ if (!tinyMCE.hasMouseMoved) {
+ inst = tinyMCE.selectedInstance;
- // Within a table create new paragraphs
- if ((startBlock != null && startBlock.nodeName == "TABLE") || (endBlock != null && endBlock.nodeName == "TABLE"))
- startBlock = endBlock = null;
+ // Workaround for bug #1437457 (Odd MSIE bug)
+ if (inst.isFocused) {
+ inst.undoBookmark = inst.selection.getBookmark();
+ tinyMCE.hasMouseMoved = true;
+ }
+ }
- // Setup new paragraphs
- var paraBefore = (startBlock != null && startBlock.nodeName == blockName) ? startBlock.cloneNode(false) : doc.createElement(blockName);
- var paraAfter = (endBlock != null && endBlock.nodeName == blockName) ? endBlock.cloneNode(false) : doc.createElement(blockName);
+ // tinyMCE.cancelEvent(inst.getWin().event);
+ // return false;
+ },
- // Is header, then force paragraph under
- if (/^(H[1-6])$/.test(blockName))
- paraAfter = doc.createElement("p");
+ cancelEvent : function(e) {
+ if (!e)
+ return false;
- // Setup chop nodes
- var startChop = startNode;
- var endChop = endNode;
+ if (tinyMCE.isIE) {
+ e.returnValue = false;
+ e.cancelBubble = true;
+ } else {
+ e.preventDefault();
+ e.stopPropagation && e.stopPropagation();
+ }
- // Get startChop node
- node = startChop;
- do {
- if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
- break;
+ return false;
+ },
- startChop = node;
- } while ((node = node.previousSibling ? node.previousSibling : node.parentNode));
+ addEvent : function(o, n, h) {
+ // Add cleanup for all non unload events
+ if (n != 'unload') {
+ function clean() {
+ var ex;
- // Get endChop node
- node = endChop;
- do {
- if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
- break;
+ try {
+ tinyMCE.removeEvent(o, n, h);
+ tinyMCE.removeEvent(window, 'unload', clean);
+ o = n = h = null;
+ } catch (ex) {
+ // IE may produce access denied exception on unload
+ }
+ }
- endChop = node;
- } while ((node = node.nextSibling ? node.nextSibling : node.parentNode));
+ // Add memory cleaner
+ tinyMCE.addEvent(window, 'unload', clean);
+ }
- // Fix when only a image is within the TD
- if (startChop.nodeName == "TD")
- startChop = startChop.firstChild;
+ if (o.attachEvent)
+ o.attachEvent("on" + n, h);
+ else
+ o.addEventListener(n, h, false);
+ },
- if (endChop.nodeName == "TD")
- endChop = endChop.lastChild;
+ removeEvent : function(o, n, h) {
+ if (o.detachEvent)
+ o.detachEvent("on" + n, h);
+ else
+ o.removeEventListener(n, h, false);
+ },
+
+ addSelectAccessibility : function(e, s, w) {
+ // Add event handlers
+ if (!s._isAccessible) {
+ s.onkeydown = tinyMCE.accessibleEventHandler;
+ s.onblur = tinyMCE.accessibleEventHandler;
+ s._isAccessible = true;
+ s._win = w;
+ }
- // If not in a block element
- if (startBlock == null) {
- // Delete selection
- rng.deleteContents();
- sel.removeAllRanges();
+ return false;
+ },
- if (startChop != rootElm && endChop != rootElm) {
- // Insert paragraph before
- rngBefore = rng.cloneRange();
+ accessibleEventHandler : function(e) {
+ var elm, win = this._win;
- if (startChop == body)
- rngBefore.setStart(startChop, 0);
- else
- rngBefore.setStartBefore(startChop);
+ e = tinyMCE.isIE ? win.event : e;
+ elm = tinyMCE.isIE ? e.srcElement : e.target;
- paraBefore.appendChild(rngBefore.cloneContents());
+ // Unpiggyback onchange on blur
+ if (e.type == "blur") {
+ if (elm.oldonchange) {
+ elm.onchange = elm.oldonchange;
+ elm.oldonchange = null;
+ }
- // Insert paragraph after
- if (endChop.parentNode.nodeName == blockName)
- endChop = endChop.parentNode;
+ return true;
+ }
- // If not after image
- //if (rng.startContainer.nodeName != "BODY" && rng.endContainer.nodeName != "BODY")
- rng.setEndAfter(endChop);
+ // Piggyback onchange
+ if (elm.nodeName == "SELECT" && !elm.oldonchange) {
+ elm.oldonchange = elm.onchange;
+ elm.onchange = null;
+ }
- if (endChop.nodeName != "#text" && endChop.nodeName != "BODY")
- rngBefore.setEndAfter(endChop);
+ // Execute onchange and remove piggyback
+ if (e.keyCode == 13 || e.keyCode == 32) {
+ elm.onchange = elm.oldonchange;
+ elm.onchange();
+ elm.oldonchange = null;
- var contents = rng.cloneContents();
- if (contents.firstChild && (contents.firstChild.nodeName == blockName || contents.firstChild.nodeName == "BODY"))
- paraAfter.innerHTML = contents.firstChild.innerHTML;
- else
- paraAfter.appendChild(contents);
+ tinyMCE.cancelEvent(e);
+ return false;
+ }
- // Check if it's a empty paragraph
- if (isEmpty(paraBefore))
- paraBefore.innerHTML = " ";
+ return true;
+ },
- // Check if it's a empty paragraph
- if (isEmpty(paraAfter))
- paraAfter.innerHTML = " ";
+ _resetIframeHeight : function() {
+ var ife;
- // Delete old contents
- rng.deleteContents();
- rngAfter.deleteContents();
- rngBefore.deleteContents();
+ if (tinyMCE.isRealIE) {
+ ife = tinyMCE.selectedInstance.iframeElement;
- // Insert new paragraphs
- paraAfter.normalize();
- rngBefore.insertNode(paraAfter);
- paraBefore.normalize();
- rngBefore.insertNode(paraBefore);
+ /* if (ife._oldWidth) {
+ ife.style.width = ife._oldWidth;
+ ife.width = ife._oldWidth;
+ }*/
- // tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML);
- } else {
- body.innerHTML = "<" + blockName + "> </" + blockName + "><" + blockName + "> </" + blockName + ">";
- paraAfter = body.childNodes[1];
+ if (ife._oldHeight) {
+ ife.style.height = ife._oldHeight;
+ ife.height = ife._oldHeight;
+ }
}
+ }
- this.selectNode(paraAfter, true, true);
+ });
- return true;
- }
+/* file:jscripts/tiny_mce/classes/TinyMCE_Selection.class.js */
- // Place first part within new paragraph
- if (startChop.nodeName == blockName)
- rngBefore.setStart(startChop, 0);
- else
- rngBefore.setStartBefore(startChop);
-
- rngBefore.setEnd(startNode, startOffset);
- paraBefore.appendChild(rngBefore.cloneContents());
-
- // Place secound part within new paragraph
- rngAfter.setEndAfter(endChop);
- rngAfter.setStart(endNode, endOffset);
- var contents = rngAfter.cloneContents();
-
- if (contents.firstChild && contents.firstChild.nodeName == blockName) {
-/* var nodes = contents.firstChild.childNodes;
- for (var i=0; i<nodes.length; i++) {
- //tinyMCE.debug(nodes[i].nodeName);
- if (nodes[i].nodeName != "BODY")
- paraAfter.appendChild(nodes[i]);
- }
-*/
- paraAfter.innerHTML = contents.firstChild.innerHTML;
- } else
- paraAfter.appendChild(contents);
-
- // Check if it's a empty paragraph
- if (isEmpty(paraBefore))
- paraBefore.innerHTML = " ";
-
- // Check if it's a empty paragraph
- if (isEmpty(paraAfter))
- paraAfter.innerHTML = " ";
-
- // Create a range around everything
- var rng = doc.createRange();
-
- if (!startChop.previousSibling && startChop.parentNode.nodeName.toUpperCase() == blockName) {
- rng.setStartBefore(startChop.parentNode);
- } else {
- if (rngBefore.startContainer.nodeName.toUpperCase() == blockName && rngBefore.startOffset == 0)
- rng.setStartBefore(rngBefore.startContainer);
- else
- rng.setStart(rngBefore.startContainer, rngBefore.startOffset);
- }
+function TinyMCE_Selection(inst) {
+ this.instance = inst;
+};
- if (!endChop.nextSibling && endChop.parentNode.nodeName.toUpperCase() == blockName)
- rng.setEndAfter(endChop.parentNode);
- else
- rng.setEnd(rngAfter.endContainer, rngAfter.endOffset);
+TinyMCE_Selection.prototype = {
+ getSelectedHTML : function() {
+ var inst = this.instance, e, r = this.getRng(), h;
- // Delete all contents and insert new paragraphs
- rng.deleteContents();
- rng.insertNode(paraAfter);
- rng.insertNode(paraBefore);
- //tinyMCE.debug("2", paraBefore.innerHTML, paraAfter.innerHTML);
+ if (!r)
+ return null;
- // Normalize
- paraAfter.normalize();
- paraBefore.normalize();
+ e = document.createElement("body");
- this.selectNode(paraAfter, true, true);
+ if (r.cloneContents)
+ e.appendChild(r.cloneContents());
+ else if (typeof(r.item) != 'undefined' || typeof(r.htmlText) != 'undefined')
+ e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText;
+ else
+ e.innerHTML = r.toString(); // Failed, use text for now
- return true;
-};
+ h = tinyMCE._cleanupHTML(inst, inst.contentDocument, inst.settings, e, e, false, true, false);
-TinyMCEControl.prototype._handleBackSpace = function(evt_type) {
- var doc = this.getDoc();
- var sel = this.getSel();
- if (sel == null)
- return false;
+ // When editing always use fonts internaly
+ //if (tinyMCE.getParam("convert_fonts_to_spans"))
+ // tinyMCE.convertSpansToFonts(inst.getDoc());
- var rng = sel.getRangeAt(0);
- var node = rng.startContainer;
- var elm = node.nodeType == 3 ? node.parentNode : node;
+ return h;
+ },
- if (node == null)
- return;
+ getSelectedText : function() {
+ var inst = this.instance, d, r, s, t;
- // Empty node, wrap contents in paragraph
- if (elm && elm.nodeName == "") {
- var para = doc.createElement("p");
+ if (tinyMCE.isIE) {
+ d = inst.getDoc();
- while (elm.firstChild)
- para.appendChild(elm.firstChild);
+ if (d.selection.type == "Text") {
+ r = d.selection.createRange();
+ t = r.text;
+ } else
+ t = '';
+ } else {
+ s = this.getSel();
- elm.parentNode.insertBefore(para, elm);
- elm.parentNode.removeChild(elm);
+ if (s && s.toString)
+ t = s.toString();
+ else
+ t = '';
+ }
- var rng = rng.cloneRange();
- rng.setStartBefore(node.nextSibling);
- rng.setEndAfter(node.nextSibling);
- rng.extractContents();
+ return t;
+ },
- this.selectNode(node.nextSibling, true, true);
- }
+ getBookmark : function(simple) {
+ var inst = this.instance, rng = this.getRng(), doc = inst.getDoc(), b = inst.getBody();
+ var trng, sx, sy, xx = -999999999, vp = inst.getViewPort();
+ var sp, le, s, e, nl, i, si, ei, w;
- // Remove empty paragraphs
- var para = tinyMCE.getParentBlockElement(node);
- if (para != null && para.nodeName.toLowerCase() == 'p' && evt_type == "keypress") {
- var htm = para.innerHTML;
- var block = tinyMCE.getParentBlockElement(node);
+ sx = vp.left;
+ sy = vp.top;
- // Empty node, we do the killing!!
- if (htm == "" || htm == " " || block.nodeName.toLowerCase() == "li") {
- var prevElm = para.previousSibling;
+ if (simple)
+ return {rng : rng, scrollX : sx, scrollY : sy};
- while (prevElm != null && prevElm.nodeType != 1)
- prevElm = prevElm.previousSibling;
+ if (tinyMCE.isRealIE) {
+ if (rng.item) {
+ e = rng.item(0);
- if (prevElm == null)
- return false;
+ nl = b.getElementsByTagName(e.nodeName);
+ for (i=0; i<nl.length; i++) {
+ if (e == nl[i]) {
+ sp = i;
+ break;
+ }
+ }
- // Get previous elements last text node
- var nodes = tinyMCE.getNodeTree(prevElm, new Array(), 3);
- var lastTextNode = nodes.length == 0 ? null : nodes[nodes.length-1];
+ return {
+ tag : e.nodeName,
+ index : sp,
+ scrollX : sx,
+ scrollY : sy
+ };
+ } else {
+ trng = doc.body.createTextRange();
+ trng.moveToElementText(inst.getBody());
+ trng.collapse(true);
+ bp = Math.abs(trng.move('character', xx));
+
+ trng = rng.duplicate();
+ trng.collapse(true);
+ sp = Math.abs(trng.move('character', xx));
+
+ trng = rng.duplicate();
+ trng.collapse(false);
+ le = Math.abs(trng.move('character', xx)) - sp;
+
+ return {
+ start : sp - bp,
+ length : le,
+ scrollX : sx,
+ scrollY : sy
+ };
+ }
+ } else {
+ s = this.getSel();
+ e = this.getFocusElement();
- // Select the last text node and move curstor to end
- if (lastTextNode != null)
- this.selectNode(lastTextNode, true, false, false);
+ if (!s)
+ return null;
- // Remove the empty paragrapsh
- para.parentNode.removeChild(para);
+ if (e && e.nodeName == 'IMG') {
+ /*nl = b.getElementsByTagName('IMG');
+ for (i=0; i<nl.length; i++) {
+ if (e == nl[i]) {
+ sp = i;
+ break;
+ }
+ }*/
+
+ return {
+ start : -1,
+ end : -1,
+ index : sp,
+ scrollX : sx,
+ scrollY : sy
+ };
+ }
- //debug("within p element" + para.innerHTML);
- //showHTML(this.getBody().innerHTML);
- return true;
- }
- }
+ // Caret or selection
+ if (s.anchorNode == s.focusNode && s.anchorOffset == s.focusOffset) {
+ e = this._getPosText(b, s.anchorNode, s.focusNode);
- // Remove BR elements
-/* while (node != null && (node = node.nextSibling) != null) {
- if (node.nodeName.toLowerCase() == 'br')
- node.parentNode.removeChild(node);
- else if (node.nodeType == 1) // Break at other element
- break;
- }*/
+ if (!e)
+ return {scrollX : sx, scrollY : sy};
- //showHTML(this.getBody().innerHTML);
+ return {
+ start : e.start + s.anchorOffset,
+ end : e.end + s.focusOffset,
+ scrollX : sx,
+ scrollY : sy
+ };
+ } else {
+ e = this._getPosText(b, rng.startContainer, rng.endContainer);
- return false;
-};
+ if (!e)
+ return {scrollX : sx, scrollY : sy};
-TinyMCEControl.prototype._insertSpace = function() {
- return true;
-};
+ return {
+ start : e.start + rng.startOffset,
+ end : e.end + rng.endOffset,
+ scrollX : sx,
+ scrollY : sy
+ };
+ }
+ }
-TinyMCEControl.prototype.autoResetDesignMode = function() {
- // Add fix for tab/style.display none/block problems in Gecko
- if (!tinyMCE.isMSIE && tinyMCE.settings['auto_reset_designmode'] && this.isHidden())
- eval('try { this.getDoc().designMode = "On"; } catch(e) {}');
-};
+ return null;
+ },
-TinyMCEControl.prototype.isHidden = function() {
- if (tinyMCE.isMSIE)
- return false;
+ moveToBookmark : function(bookmark) {
+ var inst = this.instance, rng, nl, i, ex, b = inst.getBody(), sd;
+ var doc = inst.getDoc(), win = inst.getWin(), sel = this.getSel();
- var sel = this.getSel();
+ if (!bookmark)
+ return false;
- // Weird, wheres that cursor selection?
- return (!sel || !sel.rangeCount || sel.rangeCount == 0);
-};
+ if (tinyMCE.isSafari && bookmark.rng) {
+ sel.setBaseAndExtent(bookmark.rng.startContainer, bookmark.rng.startOffset, bookmark.rng.endContainer, bookmark.rng.endOffset);
+ return true;
+ }
-TinyMCEControl.prototype.isDirty = function() {
- // Is content modified and not in a submit procedure
- return this.startContent != tinyMCE.trim(this.getBody().innerHTML) && !tinyMCE.isNotDirty;
-};
+ if (tinyMCE.isRealIE) {
+ if (bookmark.rng) {
+ try {
+ bookmark.rng.select();
+ } catch (ex) {
+ // Ignore
+ }
-TinyMCEControl.prototype._mergeElements = function(scmd, pa, ch, override) {
- if (scmd == "removeformat") {
- pa.className = "";
- pa.style.cssText = "";
- ch.className = "";
- ch.style.cssText = "";
- return;
- }
+ return true;
+ }
- var st = tinyMCE.parseStyle(tinyMCE.getAttrib(pa, "style"));
- var stc = tinyMCE.parseStyle(tinyMCE.getAttrib(ch, "style"));
- var className = tinyMCE.getAttrib(pa, "class");
+ win.focus();
- className += " " + tinyMCE.getAttrib(ch, "class");
+ if (bookmark.tag) {
+ rng = b.createControlRange();
- if (override) {
- for (var n in st) {
- if (typeof(st[n]) == 'function')
- continue;
+ nl = b.getElementsByTagName(bookmark.tag);
- stc[n] = st[n];
- }
- } else {
- for (var n in stc) {
- if (typeof(stc[n]) == 'function')
- continue;
+ if (nl.length > bookmark.index) {
+ try {
+ rng.addElement(nl[bookmark.index]);
+ } catch (ex) {
+ // Might be thrown if the node no longer exists
+ }
+ }
+ } else {
+ // Try/catch needed since this operation breaks when TinyMCE is placed in hidden divs/tabs
+ try {
+ // Incorrect bookmark
+ if (bookmark.start < 0)
+ return true;
- st[n] = stc[n];
- }
- }
+ rng = inst.getSel().createRange();
+ rng.moveToElementText(inst.getBody());
+ rng.collapse(true);
+ rng.moveStart('character', bookmark.start);
+ rng.moveEnd('character', bookmark.length);
+ } catch (ex) {
+ return true;
+ }
+ }
- tinyMCE.setAttrib(pa, "style", tinyMCE.serializeStyle(st));
- tinyMCE.setAttrib(pa, "class", tinyMCE.trim(className));
- ch.className = "";
- ch.style.cssText = "";
- ch.removeAttribute("class");
- ch.removeAttribute("style");
-};
+ rng.select();
+
+ win.scrollTo(bookmark.scrollX, bookmark.scrollY);
+ return true;
+ }
-TinyMCEControl.prototype.setUseCSS = function(b) {
- var doc = this.getDoc();
- try {doc.execCommand("useCSS", false, !b);} catch (ex) {}
- try {doc.execCommand("styleWithCSS", false, b);} catch (ex) {}
+ if (tinyMCE.isGecko || tinyMCE.isOpera) {
+ if (!sel)
+ return false;
- if (!tinyMCE.getParam("table_inline_editing"))
- try {doc.execCommand('enableInlineTableEditing', false, "false");} catch (ex) {}
+ if (bookmark.rng) {
+ sel.removeAllRanges();
+ sel.addRange(bookmark.rng);
+ }
- if (!tinyMCE.getParam("object_resizing"))
- try {doc.execCommand('enableObjectResizing', false, "false");} catch (ex) {}
-};
+ if (bookmark.start != -1 && bookmark.end != -1) {
+ try {
+ sd = this._getTextPos(b, bookmark.start, bookmark.end);
+ rng = doc.createRange();
+ rng.setStart(sd.startNode, sd.startOffset);
+ rng.setEnd(sd.endNode, sd.endOffset);
+ sel.removeAllRanges();
+ sel.addRange(rng);
-TinyMCEControl.prototype.execCommand = function(command, user_interface, value) {
- var doc = this.getDoc();
- var win = this.getWin();
- var focusElm = this.getFocusElement();
+ if (!tinyMCE.isOpera)
+ win.focus();
+ } catch (ex) {
+ // Ignore
+ }
+ }
- if (this.lastSafariSelection && !new RegExp('mceStartTyping|mceEndTyping|mceBeginUndoLevel|mceEndUndoLevel|mceAddUndoLevel', 'gi').test(command)) {
- this.moveToBookmark(this.lastSafariSelection);
- tinyMCE.selectedElement = this.lastSafariSelectedElement;
- }
+ /*
+ if (typeof(bookmark.index) != 'undefined') {
+ tinyMCE.selectElements(b, 'IMG', function (n) {
+ if (bookmark.index-- == 0) {
+ // Select image in Gecko here
+ }
- // Mozilla issue
- if (!tinyMCE.isMSIE && !this.useCSS) {
- this.setUseCSS(false);
- this.useCSS = true;
- }
+ return false;
+ });
+ }
+ */
- //debug("command: " + command + ", user_interface: " + user_interface + ", value: " + value);
- this.contentDocument = doc; // <-- Strange, unless this is applied Mozilla 1.3 breaks
+ win.scrollTo(bookmark.scrollX, bookmark.scrollY);
+ return true;
+ }
- // Call theme execcommand
- if (tinyMCE._themeExecCommand(this.editorId, this.getBody(), command, user_interface, value))
- return;
+ return false;
+ },
- // Fix align on images
- if (focusElm && focusElm.nodeName == "IMG") {
- var align = focusElm.getAttribute('align');
- var img = command == "JustifyCenter" ? focusElm.cloneNode(false) : focusElm;
+ _getPosText : function(r, sn, en) {
+ var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {};
- switch (command) {
- case "JustifyLeft":
- if (align == 'left')
- img.removeAttribute('align');
- else
- img.setAttribute('align', 'left');
+ while ((n = w.nextNode()) != null) {
+ if (n == sn)
+ d.start = p;
- // Remove the div
- var div = focusElm.parentNode;
- if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
- div.parentNode.replaceChild(img, div);
+ if (n == en) {
+ d.end = p;
+ return d;
+ }
- this.selectNode(img);
- this.repaint();
- tinyMCE.triggerNodeChange();
- return;
+ p += n.nodeValue ? n.nodeValue.length : 0;
+ }
- case "JustifyCenter":
- img.removeAttribute('align');
+ return null;
+ },
- // Is centered
- var div = tinyMCE.getParentElement(focusElm, "div");
- if (div && div.style.textAlign == "center") {
- // Remove div
- if (div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
- div.parentNode.replaceChild(img, div);
- } else {
- // Add div
- var div = this.getDoc().createElement("div");
- div.style.textAlign = 'center';
- div.appendChild(img);
- focusElm.parentNode.replaceChild(div, focusElm);
- }
+ _getTextPos : function(r, sp, ep) {
+ var w = document.createTreeWalker(r, NodeFilter.SHOW_TEXT, null, false), n, p = 0, d = {};
- this.selectNode(img);
- this.repaint();
- tinyMCE.triggerNodeChange();
- return;
+ while ((n = w.nextNode()) != null) {
+ p += n.nodeValue ? n.nodeValue.length : 0;
- case "JustifyRight":
- if (align == 'right')
- img.removeAttribute('align');
- else
- img.setAttribute('align', 'right');
+ if (p >= sp && !d.startNode) {
+ d.startNode = n;
+ d.startOffset = sp - (p - n.nodeValue.length);
+ }
- // Remove the div
- var div = focusElm.parentNode;
- if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)
- div.parentNode.replaceChild(img, div);
+ if (p >= ep) {
+ d.endNode = n;
+ d.endOffset = ep - (p - n.nodeValue.length);
- this.selectNode(img);
- this.repaint();
- tinyMCE.triggerNodeChange();
- return;
+ return d;
+ }
}
- }
-
- if (tinyMCE.settings['force_br_newlines']) {
- var alignValue = "";
- if (doc.selection.type != "Control") {
- switch (command) {
- case "JustifyLeft":
- alignValue = "left";
- break;
+ return null;
+ },
- case "JustifyCenter":
- alignValue = "center";
- break;
+ selectNode : function(node, collapse, select_text_node, to_start) {
+ var inst = this.instance, sel, rng, nodes;
- case "JustifyFull":
- alignValue = "justify";
- break;
+ if (!node)
+ return;
- case "JustifyRight":
- alignValue = "right";
- break;
- }
+ if (typeof(collapse) == "undefined")
+ collapse = true;
- if (alignValue != "") {
- var rng = doc.selection.createRange();
+ if (typeof(select_text_node) == "undefined")
+ select_text_node = false;
- if ((divElm = tinyMCE.getParentElement(rng.parentElement(), "div")) != null)
- divElm.setAttribute("align", alignValue);
- else if (rng.pasteHTML && rng.htmlText.length > 0)
- rng.pasteHTML('<div align="' + alignValue + '">' + rng.htmlText + "</div>");
+ if (typeof(to_start) == "undefined")
+ to_start = true;
- tinyMCE.triggerNodeChange();
- return;
- }
- }
- }
+ if (inst.settings.auto_resize)
+ inst.resizeToContent();
- switch (command) {
- case "mceRepaint":
- this.repaint();
- return true;
+ if (tinyMCE.isRealIE) {
+ rng = inst.getDoc().body.createTextRange();
- case "mceStoreSelection":
- this.selectionBookmark = this.getBookmark();
- return true;
+ try {
+ rng.moveToElementText(node);
- case "mceRestoreSelection":
- this.moveToBookmark(this.selectionBookmark);
- return true;
+ if (collapse)
+ rng.collapse(to_start);
- case "InsertUnorderedList":
- case "InsertOrderedList":
- var tag = (command == "InsertUnorderedList") ? "ul" : "ol";
+ rng.select();
+ } catch (e) {
+ // Throws illigal agrument in MSIE some times
+ }
+ } else {
+ sel = this.getSel();
- if (tinyMCE.isSafari)
- this.execCommand("mceInsertContent", false, "<" + tag + "><li> </li><" + tag + ">");
- else
- this.getDoc().execCommand(command, user_interface, value);
+ if (!sel)
+ return;
- tinyMCE.triggerNodeChange();
- break;
+ if (tinyMCE.isSafari) {
+ sel.setBaseAndExtent(node, 0, node, node.innerText.length);
- case "Strikethrough":
- if (tinyMCE.isSafari)
- this.execCommand("mceInsertContent", false, "<strike>" + this.getSelectedHTML() + "</strike>");
- else
- this.getDoc().execCommand(command, user_interface, value);
+ if (collapse) {
+ if (to_start)
+ sel.collapseToStart();
+ else
+ sel.collapseToEnd();
+ }
- tinyMCE.triggerNodeChange();
- break;
+ this.scrollToNode(node);
- case "mceSelectNode":
- this.selectNode(value);
- tinyMCE.triggerNodeChange();
- tinyMCE.selectedNode = value;
- break;
+ return;
+ }
- case "FormatBlock":
- if (value == null || value == "") {
- var elm = tinyMCE.getParentElement(this.getFocusElement(), "p,div,h1,h2,h3,h4,h5,h6,pre,address");
+ rng = inst.getDoc().createRange();
- if (elm)
- this.execCommand("mceRemoveNode", false, elm);
+ if (select_text_node) {
+ // Find first textnode in tree
+ nodes = tinyMCE.getNodeTree(node, [], 3);
+ if (nodes.length > 0)
+ rng.selectNodeContents(nodes[0]);
+ else
+ rng.selectNodeContents(node);
} else
- this.getDoc().execCommand("FormatBlock", false, value);
+ rng.selectNode(node);
- tinyMCE.triggerNodeChange();
+ if (collapse) {
+ // Special treatment of textnode collapse
+ if (!to_start && node.nodeType == 3) {
+ rng.setStart(node, node.nodeValue.length);
+ rng.setEnd(node, node.nodeValue.length);
+ } else
+ rng.collapse(to_start);
+ }
- break;
+ sel.removeAllRanges();
+ sel.addRange(rng);
+ }
- case "mceRemoveNode":
- if (!value)
- value = tinyMCE.getParentElement(this.getFocusElement());
+ this.scrollToNode(node);
- if (tinyMCE.isMSIE) {
- value.outerHTML = value.innerHTML;
- } else {
- var rng = value.ownerDocument.createRange();
- rng.setStartBefore(value);
- rng.setEndAfter(value);
- rng.deleteContents();
- rng.insertNode(rng.createContextualFragment(value.innerHTML));
- }
+ // Set selected element
+ tinyMCE.selectedElement = null;
+ if (node.nodeType == 1)
+ tinyMCE.selectedElement = node;
+ },
- tinyMCE.triggerNodeChange();
+ scrollToNode : function(node) {
+ var inst = this.instance, w = inst.getWin(), vp = inst.getViewPort(), pos = tinyMCE.getAbsPosition(node), cvp, p, cwin;
- break;
+ // Only scroll if out of visible area
+ if (pos.absLeft < vp.left || pos.absLeft > vp.left + vp.width || pos.absTop < vp.top || pos.absTop > vp.top + (vp.height-25))
+ w.scrollTo(pos.absLeft, pos.absTop - vp.height + 25);
- case "mceSelectNodeDepth":
- var parentNode = this.getFocusElement();
- for (var i=0; parentNode; i++) {
- if (parentNode.nodeName.toLowerCase() == "body")
- break;
+ // Scroll container window
+ if (inst.settings.auto_resize) {
+ cwin = inst.getContainerWin();
+ cvp = tinyMCE.getViewPort(cwin);
+ p = this.getAbsPosition(node);
- if (parentNode.nodeName.toLowerCase() == "#text") {
- i--;
- parentNode = parentNode.parentNode;
- continue;
- }
+ if (p.absLeft < cvp.left || p.absLeft > cvp.left + cvp.width || p.absTop < cvp.top || p.absTop > cvp.top + cvp.height)
+ cwin.scrollTo(p.absLeft, p.absTop - cvp.height + 25);
+ }
+ },
- if (i == value) {
- this.selectNode(parentNode, false);
- tinyMCE.triggerNodeChange();
- tinyMCE.selectedNode = parentNode;
- return;
- }
+ getAbsPosition : function(n) {
+ var pos = tinyMCE.getAbsPosition(n), ipos = tinyMCE.getAbsPosition(this.instance.iframeElement);
- parentNode = parentNode.parentNode;
- }
+ return {
+ absLeft : ipos.absLeft + pos.absLeft,
+ absTop : ipos.absTop + pos.absTop
+ };
+ },
- break;
+ getSel : function() {
+ var inst = this.instance;
- case "SetStyleInfo":
- var rng = this.getRng();
- var sel = this.getSel();
- var scmd = value['command'];
- var sname = value['name'];
- var svalue = value['value'] == null ? '' : value['value'];
- //var svalue = value['value'] == null ? '' : value['value'];
- var wrapper = value['wrapper'] ? value['wrapper'] : "span";
- var parentElm = null;
- var invalidRe = new RegExp("^BODY|HTML$", "g");
- var invalidParentsRe = tinyMCE.settings['merge_styles_invalid_parents'] != '' ? new RegExp(tinyMCE.settings['merge_styles_invalid_parents'], "gi") : null;
-
- // Whole element selected check
- if (tinyMCE.isMSIE) {
- // Control range
- if (rng.item)
- parentElm = rng.item(0);
- else {
- var pelm = rng.parentElement();
- var prng = doc.selection.createRange();
- prng.moveToElementText(pelm);
-
- if (rng.htmlText == prng.htmlText || rng.boundingWidth == 0) {
- if (invalidParentsRe == null || !invalidParentsRe.test(pelm.nodeName))
- parentElm = pelm;
- }
- }
- } else {
- var felm = this.getFocusElement();
- if (sel.isCollapsed || (/td|tr|tbody|table/ig.test(felm.nodeName) && sel.anchorNode == felm.parentNode))
- parentElm = felm;
- }
+ if (tinyMCE.isRealIE)
+ return inst.getDoc().selection;
- // Whole element selected
- if (parentElm && !invalidRe.test(parentElm.nodeName)) {
- if (scmd == "setstyle")
- tinyMCE.setStyleAttrib(parentElm, sname, svalue);
+ return inst.contentWindow.getSelection();
+ },
- if (scmd == "setattrib")
- tinyMCE.setAttrib(parentElm, sname, svalue);
+ getRng : function() {
+ var s = this.getSel();
- if (scmd == "removeformat") {
- parentElm.style.cssText = '';
- tinyMCE.setAttrib(parentElm, 'class', '');
- }
+ if (s == null)
+ return null;
- // Remove style/attribs from all children
- var ch = tinyMCE.getNodeTree(parentElm, new Array(), 1);
- for (var z=0; z<ch.length; z++) {
- if (ch[z] == parentElm)
- continue;
+ if (tinyMCE.isRealIE)
+ return s.createRange();
- if (scmd == "setstyle")
- tinyMCE.setStyleAttrib(ch[z], sname, '');
+ if (tinyMCE.isSafari && !s.getRangeAt)
+ return '' + window.getSelection();
- if (scmd == "setattrib")
- tinyMCE.setAttrib(ch[z], sname, '');
+ if (s.rangeCount > 0)
+ return s.getRangeAt(0);
- if (scmd == "removeformat") {
- ch[z].style.cssText = '';
- tinyMCE.setAttrib(ch[z], 'class', '');
- }
- }
- } else {
- doc.execCommand("fontname", false, "#mce_temp_font#");
- var elementArray = tinyMCE.getElementsByAttributeValue(this.getBody(), "font", "face", "#mce_temp_font#");
+ return null;
+ },
+
+ isCollapsed : function() {
+ var r = this.getRng();
+
+ if (r.item)
+ return false;
- // Change them all
- for (var x=0; x<elementArray.length; x++) {
- elm = elementArray[x];
- if (elm) {
- var spanElm = doc.createElement(wrapper);
+ return r.boundingWidth == 0 || this.getSel().isCollapsed;
+ },
- if (scmd == "setstyle")
- tinyMCE.setStyleAttrib(spanElm, sname, svalue);
+ collapse : function(b) {
+ var r = this.getRng(), s = this.getSel();
- if (scmd == "setattrib")
- tinyMCE.setAttrib(spanElm, sname, svalue);
+ if (r.select) {
+ r.collapse(b);
+ r.select();
+ } else {
+ if (b)
+ s.collapseToStart();
+ else
+ s.collapseToEnd();
+ }
+ },
- if (scmd == "removeformat") {
- spanElm.style.cssText = '';
- tinyMCE.setAttrib(spanElm, 'class', '');
- }
+ getFocusElement : function() {
+ var inst = this.instance, doc, rng, sel, elm;
- if (elm.hasChildNodes()) {
- for (var i=0; i<elm.childNodes.length; i++)
- spanElm.appendChild(elm.childNodes[i].cloneNode(true));
- }
+ if (tinyMCE.isRealIE) {
+ doc = inst.getDoc();
+ rng = doc.selection.createRange();
- spanElm.setAttribute("mce_new", "true");
- elm.parentNode.replaceChild(spanElm, elm);
+ // if (rng.collapse)
+ // rng.collapse(true);
- // Remove style/attribs from all children
- var ch = tinyMCE.getNodeTree(spanElm, new Array(), 1);
- for (var z=0; z<ch.length; z++) {
- if (ch[z] == spanElm)
- continue;
+ elm = rng.item ? rng.item(0) : rng.parentElement();
+ } else {
+ if (!tinyMCE.isSafari && inst.isHidden())
+ return inst.getBody();
- if (scmd == "setstyle")
- tinyMCE.setStyleAttrib(ch[z], sname, '');
+ sel = this.getSel();
+ rng = this.getRng();
- if (scmd == "setattrib")
- tinyMCE.setAttrib(ch[z], sname, '');
+ if (!sel || !rng)
+ return null;
- if (scmd == "removeformat") {
- ch[z].style.cssText = '';
- tinyMCE.setAttrib(ch[z], 'class', '');
- }
- }
+ elm = rng.commonAncestorContainer;
+ //elm = (sel && sel.anchorNode) ? sel.anchorNode : null;
+
+ // Handle selection a image or other control like element such as anchors
+ if (!rng.collapsed) {
+ // Is selection small
+ if (rng.startContainer == rng.endContainer) {
+ if (rng.startOffset - rng.endOffset < 2) {
+ if (rng.startContainer.hasChildNodes())
+ elm = rng.startContainer.childNodes[rng.startOffset];
}
}
}
- // Cleaup wrappers
- var nodes = doc.getElementsByTagName(wrapper);
- for (var i=nodes.length-1; i>=0; i--) {
- var elm = nodes[i];
- var isNew = tinyMCE.getAttrib(elm, "mce_new") == "true";
+ // Get the element parent of the node
+ elm = tinyMCE.getParentElement(elm);
- elm.removeAttribute("mce_new");
-
- // Is only child a element
- if (elm.childNodes && elm.childNodes.length == 1 && elm.childNodes[0].nodeType == 1) {
- //tinyMCE.debug("merge1" + isNew);
- this._mergeElements(scmd, elm, elm.childNodes[0], isNew);
- continue;
- }
+ //if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img")
+ // elm = tinyMCE.selectedElement;
+ }
- // Is I the only child
- if (elm.parentNode.childNodes.length == 1 && !invalidRe.test(elm.nodeName) && !invalidRe.test(elm.parentNode.nodeName)) {
- //tinyMCE.debug("merge2" + isNew + "," + elm.nodeName + "," + elm.parentNode.nodeName);
- if (invalidParentsRe == null || !invalidParentsRe.test(elm.parentNode.nodeName))
- this._mergeElements(scmd, elm.parentNode, elm, false);
- }
- }
+ return elm;
+ }
- // Remove empty wrappers
- var nodes = doc.getElementsByTagName(wrapper);
- for (var i=nodes.length-1; i>=0; i--) {
- var elm = nodes[i];
- var isEmpty = true;
-
- // Check if it has any attribs
- var tmp = doc.createElement("body");
- tmp.appendChild(elm.cloneNode(false));
-
- // Is empty span, remove it
- tmp.innerHTML = tmp.innerHTML.replace(new RegExp('style=""|class=""', 'gi'), '');
- //tinyMCE.debug(tmp.innerHTML);
- if (new RegExp('<span>', 'gi').test(tmp.innerHTML)) {
- for (var x=0; x<elm.childNodes.length; x++) {
- if (elm.parentNode != null)
- elm.parentNode.insertBefore(elm.childNodes[x].cloneNode(true), elm);
- }
+ };
- elm.parentNode.removeChild(elm);
- }
- }
+/* file:jscripts/tiny_mce/classes/TinyMCE_UndoRedo.class.js */
- // Re add the visual aids
- if (scmd == "removeformat")
- tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
+function TinyMCE_UndoRedo(inst) {
+ this.instance = inst;
+ this.undoLevels = [];
+ this.undoIndex = 0;
+ this.typingUndoIndex = -1;
+ this.undoRedo = true;
+};
- tinyMCE.triggerNodeChange();
+TinyMCE_UndoRedo.prototype = {
+ add : function(l) {
+ var b, customUndoLevels, newHTML, inst = this.instance, i, ul, ur;
- break;
+ if (l) {
+ this.undoLevels[this.undoLevels.length] = l;
+ return true;
+ }
- case "FontName":
- if (value == null) {
- var s = this.getSel();
+ if (this.typingUndoIndex != -1) {
+ this.undoIndex = this.typingUndoIndex;
- // Find font and select it
- if (tinyMCE.isGecko && s.isCollapsed) {
- var f = tinyMCE.getParentElement(this.getFocusElement(), "font");
+ if (tinyMCE.typingUndoIndex != -1)
+ tinyMCE.undoIndex = tinyMCE.typingUndoIndex;
+ }
- if (f != null)
- this.selectNode(f, false);
- }
+ newHTML = tinyMCE.trim(inst.getBody().innerHTML);
+ if (this.undoLevels[this.undoIndex] && newHTML != this.undoLevels[this.undoIndex].content) {
+ //tinyMCE.debug(newHTML, this.undoLevels[this.undoIndex].content);
- // Remove format
- this.getDoc().execCommand("RemoveFormat", false, null);
+ // Is dirty again
+ inst.isNotDirty = false;
- // Collapse range if font was found
- if (f != null && tinyMCE.isGecko) {
- var r = this.getRng().cloneRange();
- r.collapse(true);
- s.removeAllRanges();
- s.addRange(r);
- }
- } else
- this.getDoc().execCommand('FontName', false, value);
+ tinyMCE.dispatchCallback(inst, 'onchange_callback', 'onChange', inst);
- if (tinyMCE.isGecko)
- window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
+ // Time to compress
+ customUndoLevels = tinyMCE.settings.custom_undo_redo_levels;
+ if (customUndoLevels != -1 && this.undoLevels.length > customUndoLevels) {
+ for (i=0; i<this.undoLevels.length-1; i++)
+ this.undoLevels[i] = this.undoLevels[i+1];
- return;
+ this.undoLevels.length--;
+ this.undoIndex--;
- case "FontSize":
- this.getDoc().execCommand('FontSize', false, value);
+ // Todo: Implement global undo/redo logic here
+ }
- if (tinyMCE.isGecko)
- window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
+ b = inst.undoBookmark;
- return;
+ if (!b)
+ b = inst.selection.getBookmark();
- case "forecolor":
- this.getDoc().execCommand('forecolor', false, value);
- break;
+ this.undoIndex++;
+ this.undoLevels[this.undoIndex] = {
+ content : newHTML,
+ bookmark : b
+ };
- case "HiliteColor":
- if (tinyMCE.isGecko) {
- this.setUseCSS(true);
- this.getDoc().execCommand('hilitecolor', false, value);
- this.setUseCSS(false);
- } else
- this.getDoc().execCommand('BackColor', false, value);
- break;
+ // Remove all above from global undo/redo
+ ul = tinyMCE.undoLevels;
+ for (i=tinyMCE.undoIndex + 1; i<ul.length; i++) {
+ ur = ul[i].undoRedo;
- case "Cut":
- case "Copy":
- case "Paste":
- var cmdFailed = false;
+ if (ur.undoIndex == ur.undoLevels.length -1)
+ ur.undoIndex--;
- // Try executing command
- eval('try {this.getDoc().execCommand(command, user_interface, value);} catch (e) {cmdFailed = true;}');
+ ur.undoLevels.length--;
+ }
- if (tinyMCE.isOpera && cmdFailed)
- alert('Currently not supported by your browser, use keyboard shortcuts instead.');
+ // Add global undo level
+ tinyMCE.undoLevels[tinyMCE.undoIndex++] = inst;
+ tinyMCE.undoLevels.length = tinyMCE.undoIndex;
- // Alert error in gecko if command failed
- if (tinyMCE.isGecko && cmdFailed) {
- // Confirm more info
- if (confirm(tinyMCE.getLang('lang_clipboard_msg')))
- window.open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', 'mceExternal');
+ this.undoLevels.length = this.undoIndex + 1;
- return;
- } else
- tinyMCE.triggerNodeChange();
- break;
-
- case "mceSetContent":
- if (!value)
- value = "";
-
- // Call custom cleanup code
- value = tinyMCE.storeAwayURLs(value);
- //value = tinyMCE._customCleanup(this, "insert_to_editor", value);
- tinyMCE._setHTML(doc, value);
- tinyMCE.setInnerHTML(doc.body, tinyMCE._cleanupHTML(this, doc, tinyMCE.settings, doc.body));
- this.convertAllRelativeURLs();
- tinyMCE.handleVisualAid(doc.body, true, this.visualAid, this);
- tinyMCE._setEventsEnabled(doc.body, false);
return true;
+ }
- case "mceLink":
- var selectedText = "";
+ return false;
+ },
- if (tinyMCE.isMSIE) {
- var rng = doc.selection.createRange();
- selectedText = rng.text;
- } else
- selectedText = this.getSel().toString();
+ undo : function() {
+ var inst = this.instance;
- if (!tinyMCE.linkElement) {
- if ((tinyMCE.selectedElement.nodeName.toLowerCase() != "img") && (selectedText.length <= 0))
- return;
- }
+ // Do undo
+ if (this.undoIndex > 0) {
+ this.undoIndex--;
- var href = "", target = "", title = "", onclick = "", action = "insert", style_class = "";
+ tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);
+ inst.repaint();
- if (tinyMCE.selectedElement.nodeName.toLowerCase() == "a")
- tinyMCE.linkElement = tinyMCE.selectedElement;
+ if (inst.settings.custom_undo_redo_restore_selection)
+ inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);
+ }
+ },
- // Is anchor not a link
- if (tinyMCE.linkElement != null && tinyMCE.getAttrib(tinyMCE.linkElement, 'href') == "")
- tinyMCE.linkElement = null;
+ redo : function() {
+ var inst = this.instance;
- if (tinyMCE.linkElement) {
- href = tinyMCE.getAttrib(tinyMCE.linkElement, 'href');
- target = tinyMCE.getAttrib(tinyMCE.linkElement, 'target');
- title = tinyMCE.getAttrib(tinyMCE.linkElement, 'title');
- onclick = tinyMCE.getAttrib(tinyMCE.linkElement, 'onclick');
- style_class = tinyMCE.getAttrib(tinyMCE.linkElement, 'class');
+ tinyMCE.execCommand("mceEndTyping");
- // Try old onclick to if copy/pasted content
- if (onclick == "")
- onclick = tinyMCE.getAttrib(tinyMCE.linkElement, 'onclick');
+ if (this.undoIndex < (this.undoLevels.length-1)) {
+ this.undoIndex++;
- onclick = tinyMCE.cleanupEventStr(onclick);
+ tinyMCE.setInnerHTML(inst.getBody(), this.undoLevels[this.undoIndex].content);
+ inst.repaint();
- href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement, true);");
+ if (inst.settings.custom_undo_redo_restore_selection)
+ inst.selection.moveToBookmark(this.undoLevels[this.undoIndex].bookmark);
+ }
- // Use mce_href if defined
- mceRealHref = tinyMCE.getAttrib(tinyMCE.linkElement, 'mce_href');
- if (mceRealHref != "") {
- href = mceRealHref;
+ tinyMCE.triggerNodeChange();
+ }
- if (tinyMCE.getParam('convert_urls'))
- href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement, true);");
- }
+ };
- action = "update";
- }
+/* file:jscripts/tiny_mce/classes/TinyMCE_ForceParagraphs.class.js */
- if (this.settings['insertlink_callback']) {
- var returnVal = eval(this.settings['insertlink_callback'] + "(href, target, title, onclick, action, style_class);");
- if (returnVal && returnVal['href'])
- tinyMCE.insertLink(returnVal['href'], returnVal['target'], returnVal['title'], returnVal['onclick'], returnVal['style_class']);
- } else {
- tinyMCE.openWindow(this.insertLinkTemplate, {href : href, target : target, title : title, onclick : onclick, action : action, className : style_class, inline : "yes"});
+var TinyMCE_ForceParagraphs = {
+ _insertPara : function(inst, e) {
+ var doc = inst.getDoc(), sel = inst.getSel(), body = inst.getBody(), win = inst.contentWindow, rng = sel.getRangeAt(0);
+ var rootElm = doc.documentElement, blockName = "P", startNode, endNode, startBlock, endBlock;
+ var rngBefore, rngAfter, direct, startNode, startOffset, endNode, endOffset, b = tinyMCE.isOpera ? inst.selection.getBookmark() : null;
+ var paraBefore, paraAfter, startChop, endChop, contents, i;
+
+ function isEmpty(para) {
+ var nodes;
+
+ function isEmptyHTML(html) {
+ return html.replace(new RegExp('[ \t\r\n]+', 'g'), '').toLowerCase() == '';
}
- break;
- case "mceImage":
- var src = "", alt = "", border = "", hspace = "", vspace = "", width = "", height = "", align = "";
- var title = "", onmouseover = "", onmouseout = "", action = "insert";
- var img = tinyMCE.imgElement;
+ // Check for images
+ if (para.getElementsByTagName("img").length > 0)
+ return false;
+
+ // Check for tables
+ if (para.getElementsByTagName("table").length > 0)
+ return false;
+
+ // Check for HRs
+ if (para.getElementsByTagName("hr").length > 0)
+ return false;
- if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") {
- img = tinyMCE.selectedElement;
- tinyMCE.imgElement = img;
+ // Check all textnodes
+ nodes = tinyMCE.getNodeTree(para, [], 3);
+ for (i=0; i<nodes.length; i++) {
+ if (!isEmptyHTML(nodes[i].nodeValue))
+ return false;
}
- if (img) {
- // Is it a internal MCE visual aid image, then skip this one.
- if (tinyMCE.getAttrib(img, 'name').indexOf('mce_') == 0)
- return;
+ // No images, no tables, no hrs, no text content then it's empty
+ return true;
+ }
- src = tinyMCE.getAttrib(img, 'src');
- alt = tinyMCE.getAttrib(img, 'alt');
+ // tinyMCE.debug(body.innerHTML);
- // Try polling out the title
- if (alt == "")
- alt = tinyMCE.getAttrib(img, 'title');
+ // debug(e.target, sel.anchorNode.nodeName, sel.focusNode.nodeName, rng.startContainer, rng.endContainer, rng.commonAncestorContainer, sel.anchorOffset, sel.focusOffset, rng.toString());
- // Fix width/height attributes if the styles is specified
- if (tinyMCE.isGecko) {
- var w = img.style.width;
- if (w != null && w != "")
- img.setAttribute("width", w);
+ // Setup before range
+ rngBefore = doc.createRange();
+ rngBefore.setStart(sel.anchorNode, sel.anchorOffset);
+ rngBefore.collapse(true);
- var h = img.style.height;
- if (h != null && h != "")
- img.setAttribute("height", h);
- }
+ // Setup after range
+ rngAfter = doc.createRange();
+ rngAfter.setStart(sel.focusNode, sel.focusOffset);
+ rngAfter.collapse(true);
- border = tinyMCE.getAttrib(img, 'border');
- hspace = tinyMCE.getAttrib(img, 'hspace');
- vspace = tinyMCE.getAttrib(img, 'vspace');
- width = tinyMCE.getAttrib(img, 'width');
- height = tinyMCE.getAttrib(img, 'height');
- align = tinyMCE.getAttrib(img, 'align');
- onmouseover = tinyMCE.getAttrib(img, 'onmouseover');
- onmouseout = tinyMCE.getAttrib(img, 'onmouseout');
- title = tinyMCE.getAttrib(img, 'title');
-
- // Is realy specified?
- if (tinyMCE.isMSIE) {
- width = img.attributes['width'].specified ? width : "";
- height = img.attributes['height'].specified ? height : "";
- }
+ // Setup start/end points
+ direct = rngBefore.compareBoundaryPoints(rngBefore.START_TO_END, rngAfter) < 0;
+ startNode = direct ? sel.anchorNode : sel.focusNode;
+ startOffset = direct ? sel.anchorOffset : sel.focusOffset;
+ endNode = direct ? sel.focusNode : sel.anchorNode;
+ endOffset = direct ? sel.focusOffset : sel.anchorOffset;
- onmouseover = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseover));
- onmouseout = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseout));
+ startNode = startNode.nodeName == "BODY" ? startNode.firstChild : startNode;
+ endNode = endNode.nodeName == "BODY" ? endNode.firstChild : endNode;
- src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");
+ // Get block elements
+ startBlock = inst.getParentBlockElement(startNode);
+ endBlock = inst.getParentBlockElement(endNode);
- // Use mce_src if defined
- mceRealSrc = tinyMCE.getAttrib(img, 'mce_src');
- if (mceRealSrc != "") {
- src = mceRealSrc;
+ // If absolute force paragraph generation within
+ if (startBlock && (startBlock.nodeName == 'CAPTION' || /absolute|relative|static/gi.test(startBlock.style.position)))
+ startBlock = null;
- if (tinyMCE.getParam('convert_urls'))
- src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");
- }
+ if (endBlock && (endBlock.nodeName == 'CAPTION' || /absolute|relative|static/gi.test(endBlock.style.position)))
+ endBlock = null;
- if (onmouseover != "")
- onmouseover = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseover, img, true);");
+ // Use current block name
+ if (startBlock != null) {
+ blockName = startBlock.nodeName;
- if (onmouseout != "")
- onmouseout = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseout, img, true);");
+ // Use P instead
+ if (/(TD|TABLE|TH|CAPTION)/.test(blockName) || (blockName == "DIV" && /left|right/gi.test(startBlock.style.cssFloat)))
+ blockName = "P";
+ }
- action = "update";
- }
+ // Within a list use normal behaviour
+ if (tinyMCE.getParentElement(startBlock, "OL,UL", null, body) != null)
+ return false;
- if (this.settings['insertimage_callback']) {
- var returnVal = eval(this.settings['insertimage_callback'] + "(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout, action);");
- if (returnVal && returnVal['src'])
- tinyMCE.insertImage(returnVal['src'], returnVal['alt'], returnVal['border'], returnVal['hspace'], returnVal['vspace'], returnVal['width'], returnVal['height'], returnVal['align'], returnVal['title'], returnVal['onmouseover'], returnVal['onmouseout']);
- } else
- tinyMCE.openWindow(this.insertImageTemplate, {src : src, alt : alt, border : border, hspace : hspace, vspace : vspace, width : width, height : height, align : align, title : title, onmouseover : onmouseover, onmouseout : onmouseout, action : action, inline : "yes"});
- break;
-
- case "mceCleanup":
- tinyMCE._setHTML(this.contentDocument, this.getBody().innerHTML);
- tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, this.contentDocument, this.settings, this.getBody(), this.visualAid));
- this.convertAllRelativeURLs();
- tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
- tinyMCE._setEventsEnabled(this.getBody(), false);
- this.repaint();
- tinyMCE.triggerNodeChange();
- break;
-
- case "mceReplaceContent":
- this.getWin().focus();
-
- var selectedText = "";
-
- if (tinyMCE.isMSIE) {
- var rng = doc.selection.createRange();
- selectedText = rng.text;
- } else
- selectedText = this.getSel().toString();
+ // Within a table create new paragraphs
+ if ((startBlock != null && startBlock.nodeName == "TABLE") || (endBlock != null && endBlock.nodeName == "TABLE"))
+ startBlock = endBlock = null;
- if (selectedText.length > 0) {
- value = tinyMCE.replaceVar(value, "selection", selectedText);
- tinyMCE.execCommand('mceInsertContent', false, value);
- }
+ // Setup new paragraphs
+ paraBefore = (startBlock != null && startBlock.nodeName == blockName) ? startBlock.cloneNode(false) : doc.createElement(blockName);
+ paraAfter = (endBlock != null && endBlock.nodeName == blockName) ? endBlock.cloneNode(false) : doc.createElement(blockName);
- tinyMCE.triggerNodeChange();
- break;
+ // Is header, then force paragraph under
+ if (/^(H[1-6])$/.test(blockName))
+ paraAfter = doc.createElement("p");
- case "mceSetAttribute":
- if (typeof(value) == 'object') {
- var targetElms = (typeof(value['targets']) == "undefined") ? "p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address" : value['targets'];
- var targetNode = tinyMCE.getParentElement(this.getFocusElement(), targetElms);
+ // Setup chop nodes
+ startChop = startNode;
+ endChop = endNode;
- if (targetNode) {
- targetNode.setAttribute(value['name'], value['value']);
- tinyMCE.triggerNodeChange();
- }
- }
- break;
+ // Get startChop node
+ node = startChop;
+ do {
+ if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
+ break;
- case "mceSetCSSClass":
- this.execCommand("SetStyleInfo", false, {command : "setattrib", name : "class", value : value});
- break;
+ startChop = node;
+ } while ((node = node.previousSibling ? node.previousSibling : node.parentNode));
- case "mceInsertRawHTML":
- var key = 'tiny_mce_marker';
+ // Get endChop node
+ node = endChop;
+ do {
+ if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))
+ break;
- this.execCommand('mceBeginUndoLevel');
+ endChop = node;
+ } while ((node = node.nextSibling ? node.nextSibling : node.parentNode));
- // Insert marker key
- this.execCommand('mceInsertContent', false, key);
+ // Fix when only a image is within the TD
+ if (startChop.nodeName == "TD")
+ startChop = startChop.firstChild;
- // Store away scroll pos
- var scrollX = this.getDoc().body.scrollLeft + this.getDoc().documentElement.scrollLeft;
- var scrollY = this.getDoc().body.scrollTop + this.getDoc().documentElement.scrollTop;
+ if (endChop.nodeName == "TD")
+ endChop = endChop.lastChild;
- // Find marker and replace with RAW HTML
- var html = this.getBody().innerHTML;
- if ((pos = html.indexOf(key)) != -1)
- tinyMCE.setInnerHTML(this.getBody(), html.substring(0, pos) + value + html.substring(pos + key.length));
+ // If not in a block element
+ if (startBlock == null) {
+ // Delete selection
+ rng.deleteContents();
- // Restore scoll pos
- this.contentWindow.scrollTo(scrollX, scrollY);
+ if (!tinyMCE.isSafari)
+ sel.removeAllRanges();
- this.execCommand('mceEndUndoLevel');
+ if (startChop != rootElm && endChop != rootElm) {
+ // Insert paragraph before
+ rngBefore = rng.cloneRange();
- break;
+ if (startChop == body)
+ rngBefore.setStart(startChop, 0);
+ else
+ rngBefore.setStartBefore(startChop);
- case "mceInsertContent":
- var insertHTMLFailed = false;
- this.getWin().focus();
-/* WP
- if (tinyMCE.isGecko || tinyMCE.isOpera) {
- try {
- // Is plain text or HTML
- if (value.indexOf('<') == -1) {
- var r = this.getRng();
- var n = this.getDoc().createTextNode(tinyMCE.entityDecode(value));
- var s = this.getSel();
- var r2 = r.cloneRange();
-
- // Insert text at cursor position
- s.removeAllRanges();
- r.deleteContents();
- r.insertNode(n);
+ paraBefore.appendChild(rngBefore.cloneContents());
- // Move the cursor to the end of text
- r2.selectNode(n);
- r2.collapse(false);
- s.removeAllRanges();
- s.addRange(r2);
- } else {
- value = tinyMCE.fixGeckoBaseHREFBug(1, this.getDoc(), value);
- this.getDoc().execCommand('inserthtml', false, value);
- tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);
- }
- } catch (ex) {
- insertHTMLFailed = true;
- }
+ // Insert paragraph after
+ if (endChop.parentNode.nodeName == blockName)
+ endChop = endChop.parentNode;
- if (!insertHTMLFailed) {
- tinyMCE.triggerNodeChange();
- return;
- }
- }
-*/
- // Ugly hack in Opera due to non working "inserthtml"
- if (tinyMCE.isOpera && insertHTMLFailed) {
- this.getDoc().execCommand("insertimage", false, tinyMCE.uniqueURL);
- var ar = tinyMCE.getElementsByAttributeValue(this.getBody(), "img", "src", tinyMCE.uniqueURL);
- ar[0].outerHTML = value;
- return;
- }
+ // If not after image
+ //if (rng.startContainer.nodeName != "BODY" && rng.endContainer.nodeName != "BODY")
+ rng.setEndAfter(endChop);
- if (!tinyMCE.isMSIE) {
- var isHTML = value.indexOf('<') != -1;
- var sel = this.getSel();
- var rng = this.getRng();
+ if (endChop.nodeName != "#text" && endChop.nodeName != "BODY")
+ rngBefore.setEndAfter(endChop);
+
+ contents = rng.cloneContents();
+ if (contents.firstChild && (contents.firstChild.nodeName == blockName || contents.firstChild.nodeName == "BODY"))
+ paraAfter.innerHTML = contents.firstChild.innerHTML;
+ else
+ paraAfter.appendChild(contents);
- if (isHTML) {
- if (tinyMCE.isSafari) {
- var tmpRng = this.getDoc().createRange();
+ // Check if it's a empty paragraph
+ if (isEmpty(paraBefore))
+ paraBefore.innerHTML = " ";
- tmpRng.setStart(this.getBody(), 0);
- tmpRng.setEnd(this.getBody(), 0);
+ // Check if it's a empty paragraph
+ if (isEmpty(paraAfter))
+ paraAfter.innerHTML = " ";
- value = tmpRng.createContextualFragment(value);
- } else
- value = rng.createContextualFragment(value);
+ // Delete old contents
+ rng.deleteContents();
+ rngAfter.deleteContents();
+ rngBefore.deleteContents();
+
+ // Insert new paragraphs
+ if (tinyMCE.isOpera) {
+ paraBefore.normalize();
+ rngBefore.insertNode(paraBefore);
+ paraAfter.normalize();
+ rngBefore.insertNode(paraAfter);
} else {
- // Setup text node
- var el = document.createElement("div");
- el.innerHTML = value;
- value = el.firstChild.nodeValue;
- value = doc.createTextNode(value);
+ paraAfter.normalize();
+ rngBefore.insertNode(paraAfter);
+ paraBefore.normalize();
+ rngBefore.insertNode(paraBefore);
}
- // Insert plain text in Safari
- if (tinyMCE.isSafari && !isHTML) {
- this.execCommand('InsertText', false, value.nodeValue);
- tinyMCE.triggerNodeChange();
- return true;
- } else if (tinyMCE.isSafari && isHTML) {
- rng.deleteContents();
- rng.insertNode(value);
- tinyMCE.triggerNodeChange();
- return true;
- }
+ //tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML);
+ } else {
+ body.innerHTML = "<" + blockName + "> </" + blockName + "><" + blockName + "> </" + blockName + ">";
+ paraAfter = body.childNodes[1];
+ }
- rng.deleteContents();
+ inst.selection.moveToBookmark(b);
+ inst.selection.selectNode(paraAfter, true, true);
- // If target node is text do special treatment, (Mozilla 1.3 fix)
- if (rng.startContainer.nodeType == 3) {
- var node = rng.startContainer.splitText(rng.startOffset);
- node.parentNode.insertBefore(value, node);
- } else
- rng.insertNode(value);
+ return true;
+ }
- if (!isHTML) {
- // Removes weird selection trails
- sel.selectAllChildren(doc.body);
- sel.removeAllRanges();
+ // Place first part within new paragraph
+ if (startChop.nodeName == blockName)
+ rngBefore.setStart(startChop, 0);
+ else
+ rngBefore.setStartBefore(startChop);
+
+ rngBefore.setEnd(startNode, startOffset);
+ paraBefore.appendChild(rngBefore.cloneContents());
+
+ // Place secound part within new paragraph
+ rngAfter.setEndAfter(endChop);
+ rngAfter.setStart(endNode, endOffset);
+ contents = rngAfter.cloneContents();
+
+ if (contents.firstChild && contents.firstChild.nodeName == blockName) {
+ /* var nodes = contents.firstChild.childNodes;
+ for (i=0; i<nodes.length; i++) {
+ //tinyMCE.debug(nodes[i].nodeName);
+ if (nodes[i].nodeName != "BODY")
+ paraAfter.appendChild(nodes[i]);
+ }
+ */
+ paraAfter.innerHTML = contents.firstChild.innerHTML;
+ } else
+ paraAfter.appendChild(contents);
- // Move cursor to end of content
- var rng = doc.createRange();
+ // Check if it's a empty paragraph
+ if (isEmpty(paraBefore))
+ paraBefore.innerHTML = " ";
- rng.selectNode(value);
- rng.collapse(false);
+ // Check if it's a empty paragraph
+ if (isEmpty(paraAfter))
+ paraAfter.innerHTML = " ";
- sel.addRange(rng);
- } else
- rng.collapse(false);
- } else {
- var rng = doc.selection.createRange();
- var c = value.indexOf('<!--') != -1;
+ // Create a range around everything
+ rng = doc.createRange();
- // Fix comment bug, add tag before comments
- if (c)
- value = tinyMCE.uniqueTag + value;
+ if (!startChop.previousSibling && startChop.parentNode.nodeName.toUpperCase() == blockName) {
+ rng.setStartBefore(startChop.parentNode);
+ } else {
+ if (rngBefore.startContainer.nodeName.toUpperCase() == blockName && rngBefore.startOffset == 0)
+ rng.setStartBefore(rngBefore.startContainer);
+ else
+ rng.setStart(rngBefore.startContainer, rngBefore.startOffset);
+ }
- if (rng.item)
- rng.item(0).outerHTML = value;
- else
- rng.pasteHTML(value);
+ if (!endChop.nextSibling && endChop.parentNode.nodeName.toUpperCase() == blockName)
+ rng.setEndAfter(endChop.parentNode);
+ else
+ rng.setEnd(rngAfter.endContainer, rngAfter.endOffset);
- // Remove unique tag
- if (c) {
- var e = this.getDoc().getElementById('mceTMPElement');
- e.parentNode.removeChild(e);
- }
- }
+ // Delete all contents and insert new paragraphs
+ rng.deleteContents();
- tinyMCE.triggerNodeChange();
- break;
+ if (tinyMCE.isOpera) {
+ rng.insertNode(paraBefore);
+ rng.insertNode(paraAfter);
+ } else {
+ rng.insertNode(paraAfter);
+ rng.insertNode(paraBefore);
+ }
- case "mceStartTyping":
- if (tinyMCE.settings['custom_undo_redo'] && this.typingUndoIndex == -1) {
- this.typingUndoIndex = this.undoIndex;
- this.execCommand('mceAddUndoLevel');
- //tinyMCE.debug("mceStartTyping");
- }
- break;
+ //tinyMCE.debug("2", paraBefore.innerHTML, paraAfter.innerHTML);
- case "mceEndTyping":
- if (tinyMCE.settings['custom_undo_redo'] && this.typingUndoIndex != -1) {
- this.execCommand('mceAddUndoLevel');
- this.typingUndoIndex = -1;
- //tinyMCE.debug("mceEndTyping");
- }
- break;
+ // Normalize
+ paraAfter.normalize();
+ paraBefore.normalize();
- case "mceBeginUndoLevel":
- this.undoRedo = false;
- break;
+ inst.selection.moveToBookmark(b);
+ inst.selection.selectNode(paraAfter, true, true);
- case "mceEndUndoLevel":
- this.undoRedo = true;
- this.execCommand('mceAddUndoLevel');
- break;
+ return true;
+ },
- case "mceAddUndoLevel":
- if (tinyMCE.settings['custom_undo_redo'] && this.undoRedo) {
- // tinyMCE.debug("add level");
+ _handleBackSpace : function(inst) {
+ var r = inst.getRng(), sn = r.startContainer, nv, s = false;
- if (this.typingUndoIndex != -1) {
- this.undoIndex = this.typingUndoIndex;
- // tinyMCE.debug("Override: " + this.undoIndex);
- }
+ // Added body check for bug #1527787
+ if (sn && sn.nextSibling && sn.nextSibling.nodeName == "BR" && sn.parentNode.nodeName != "BODY") {
+ nv = sn.nodeValue;
- var newHTML = tinyMCE.trim(this.getBody().innerHTML);
- if (newHTML != this.undoLevels[this.undoIndex]) {
- tinyMCE.executeCallback('onchange_callback', '_onchange', 0, this);
+ // Handle if a backspace is pressed after a space character #bug 1466054 removed since fix for #1527787
+ /*if (nv != null && nv.length >= r.startOffset && nv.charAt(r.startOffset - 1) == ' ')
+ s = true;*/
- // Time to compress
- var customUndoLevels = tinyMCE.settings['custom_undo_redo_levels'];
- if (customUndoLevels != -1 && this.undoLevels.length > customUndoLevels) {
- for (var i=0; i<this.undoLevels.length-1; i++) {
- //tinyMCE.debug(this.undoLevels[i] + "=" + this.undoLevels[i+1]);
- this.undoLevels[i] = this.undoLevels[i+1];
- }
+ // Only remove BRs if we are at the end of line #bug 1464152
+ if (nv != null && r.startOffset == nv.length)
+ sn.nextSibling.parentNode.removeChild(sn.nextSibling);
+ }
- this.undoLevels.length--;
- this.undoIndex--;
- }
+ if (inst.settings.auto_resize)
+ inst.resizeToContent();
- this.undoIndex++;
- this.undoLevels[this.undoIndex] = newHTML;
- this.undoLevels.length = this.undoIndex + 1;
+ return s;
+ }
- // tinyMCE.debug("level added" + this.undoIndex);
- tinyMCE.triggerNodeChange(false);
+ };
- // tinyMCE.debug(this.undoIndex + "," + (this.undoLevels.length-1));
- }
- }
- break;
+/* file:jscripts/tiny_mce/classes/TinyMCE_Layer.class.js */
- case "Undo":
- if (tinyMCE.settings['custom_undo_redo']) {
- tinyMCE.execCommand("mceEndTyping");
+function TinyMCE_Layer(id, bm) {
+ this.id = id;
+ this.blockerElement = null;
+ this.events = false;
+ this.element = null;
+ this.blockMode = typeof(bm) != 'undefined' ? bm : true;
+ this.doc = document;
+};
- // Do undo
- if (this.undoIndex > 0) {
- this.undoIndex--;
- tinyMCE.setInnerHTML(this.getBody(), this.undoLevels[this.undoIndex]);
- this.repaint();
- }
+TinyMCE_Layer.prototype = {
+ moveRelativeTo : function(re, p) {
+ var rep = this.getAbsPosition(re), e = this.getElement(), x, y;
+ var w = parseInt(re.offsetWidth), h = parseInt(re.offsetHeight);
+ var ew = parseInt(e.offsetWidth), eh = parseInt(e.offsetHeight);
- // tinyMCE.debug("Undo - undo levels:" + this.undoLevels.length + ", undo index: " + this.undoIndex);
- tinyMCE.triggerNodeChange();
- } else
- this.getDoc().execCommand(command, user_interface, value);
- break;
+ switch (p) {
+ case "tl":
+ x = rep.absLeft;
+ y = rep.absTop;
+ break;
- case "Redo":
- if (tinyMCE.settings['custom_undo_redo']) {
- tinyMCE.execCommand("mceEndTyping");
+ case "tr":
+ x = rep.absLeft + w;
+ y = rep.absTop;
+ break;
- if (this.undoIndex < (this.undoLevels.length-1)) {
- this.undoIndex++;
- tinyMCE.setInnerHTML(this.getBody(), this.undoLevels[this.undoIndex]);
- this.repaint();
- // tinyMCE.debug("Redo - undo levels:" + this.undoLevels.length + ", undo index: " + this.undoIndex);
- }
+ case "bl":
+ x = rep.absLeft;
+ y = rep.absTop + h;
+ break;
- tinyMCE.triggerNodeChange();
- } else
- this.getDoc().execCommand(command, user_interface, value);
- break;
+ case "br":
+ x = rep.absLeft + w;
+ y = rep.absTop + h;
+ break;
- case "mceToggleVisualAid":
- this.visualAid = !this.visualAid;
- tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);
- tinyMCE.triggerNodeChange();
- break;
+ case "cc":
+ x = rep.absLeft + (w / 2) - (ew / 2);
+ y = rep.absTop + (h / 2) - (eh / 2);
+ break;
+ }
- case "Indent":
- this.getDoc().execCommand(command, user_interface, value);
- tinyMCE.triggerNodeChange();
- if (tinyMCE.isMSIE) {
- var n = tinyMCE.getParentElement(this.getFocusElement(), "blockquote");
- do {
- if (n && n.nodeName == "BLOCKQUOTE") {
- n.removeAttribute("dir");
- n.removeAttribute("style");
- }
- } while (n != null && (n = n.parentNode) != null);
- }
- break;
+ this.moveTo(x, y);
+ },
- case "removeformat":
- var text = this.getSelectedText();
+ moveBy : function(x, y) {
+ var e = this.getElement();
+ this.moveTo(parseInt(e.style.left) + x, parseInt(e.style.top) + y);
+ },
- if (tinyMCE.isOpera) {
- this.getDoc().execCommand("RemoveFormat", false, null);
- return;
- }
+ moveTo : function(x, y) {
+ var e = this.getElement();
- if (tinyMCE.isMSIE) {
- try {
- var rng = doc.selection.createRange();
- rng.execCommand("RemoveFormat", false, null);
- } catch (e) {
- // Do nothing
- }
+ e.style.left = x + "px";
+ e.style.top = y + "px";
- this.execCommand("SetStyleInfo", false, {command : "removeformat"});
- } else {
- this.getDoc().execCommand(command, user_interface, value);
+ this.updateBlocker();
+ },
- this.execCommand("SetStyleInfo", false, {command : "removeformat"});
- }
+ resizeBy : function(w, h) {
+ var e = this.getElement();
+ this.resizeTo(parseInt(e.style.width) + w, parseInt(e.style.height) + h);
+ },
- // Remove class
- if (text.length == 0)
- this.execCommand("mceSetCSSClass", false, "");
+ resizeTo : function(w, h) {
+ var e = this.getElement();
- tinyMCE.triggerNodeChange();
- break;
+ if (w != null)
+ e.style.width = w + "px";
- default:
- this.getDoc().execCommand(command, user_interface, value);
+ if (h != null)
+ e.style.height = h + "px";
- if (tinyMCE.isGecko)
- window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);
- else
- tinyMCE.triggerNodeChange();
- }
+ this.updateBlocker();
+ },
- // Add undo level after modification
- if (command != "mceAddUndoLevel" && command != "Undo" && command != "Redo" && command != "mceStartTyping" && command != "mceEndTyping")
- tinyMCE.execCommand("mceAddUndoLevel");
-};
+ show : function() {
+ var el = this.getElement();
-TinyMCEControl.prototype.queryCommandValue = function(command) {
- try {
- return this.getDoc().queryCommandValue(command);
- } catch (ex) {
- return null;
- }
-};
+ if (el) {
+ el.style.display = 'block';
+ this.updateBlocker();
+ }
+ },
-TinyMCEControl.prototype.queryCommandState = function(command) {
- return this.getDoc().queryCommandState(command);
-};
+ hide : function() {
+ var el = this.getElement();
-TinyMCEControl.prototype.onAdd = function(replace_element, form_element_name, target_document) {
- var targetDoc = target_document ? target_document : document;
+ if (el) {
+ el.style.display = 'none';
+ this.updateBlocker();
+ }
+ },
+
+ isVisible : function() {
+ return this.getElement().style.display == 'block';
+ },
+
+ getElement : function() {
+ if (!this.element)
+ this.element = this.doc.getElementById(this.id);
+
+ return this.element;
+ },
+
+ setBlockMode : function(s) {
+ this.blockMode = s;
+ },
+
+ updateBlocker : function() {
+ var e, b, x, y, w, h;
+
+ b = this.getBlocker();
+ if (b) {
+ if (this.blockMode) {
+ e = this.getElement();
+ x = this.parseInt(e.style.left);
+ y = this.parseInt(e.style.top);
+ w = this.parseInt(e.offsetWidth);
+ h = this.parseInt(e.offsetHeight);
+
+ b.style.left = x + 'px';
+ b.style.top = y + 'px';
+ b.style.width = w + 'px';
+ b.style.height = h + 'px';
+ b.style.display = e.style.display;
+ } else
+ b.style.display = 'none';
+ }
+ },
- this.targetDoc = targetDoc;
+ getBlocker : function() {
+ var d, b;
- tinyMCE.themeURL = tinyMCE.baseURL + "/themes/" + this.settings['theme'];
- this.settings['themeurl'] = tinyMCE.themeURL;
+ if (!this.blockerElement && this.blockMode) {
+ d = this.doc;
+ b = d.getElementById(this.id + "_blocker");
- if (!replace_element) {
- alert("Error: Could not find the target element.");
- return false;
- }
+ if (!b) {
+ b = d.createElement("iframe");
- var templateFunction = tinyMCE._getThemeFunction('_getInsertLinkTemplate');
- if (eval("typeof(" + templateFunction + ")") != 'undefined')
- this.insertLinkTemplate = eval(templateFunction + '(this.settings);');
+ b.setAttribute('id', this.id + "_blocker");
+ b.style.cssText = 'display: none; position: absolute; left: 0; top: 0';
+ b.src = 'javascript:false;';
+ b.frameBorder = '0';
+ b.scrolling = 'no';
+
+ d.body.appendChild(b);
+ }
- var templateFunction = tinyMCE._getThemeFunction('_getInsertImageTemplate');
- if (eval("typeof(" + templateFunction + ")") != 'undefined')
- this.insertImageTemplate = eval(templateFunction + '(this.settings);');
+ this.blockerElement = b;
+ }
- var templateFunction = tinyMCE._getThemeFunction('_getEditorTemplate');
- if (eval("typeof(" + templateFunction + ")") == 'undefined') {
- alert("Error: Could not find the template function: " + templateFunction);
- return false;
- }
+ return this.blockerElement;
+ },
- var editorTemplate = eval(templateFunction + '(this.settings, this.editorId);');
+ getAbsPosition : function(n) {
+ var p = {absLeft : 0, absTop : 0};
- var deltaWidth = editorTemplate['delta_width'] ? editorTemplate['delta_width'] : 0;
- var deltaHeight = editorTemplate['delta_height'] ? editorTemplate['delta_height'] : 0;
- var html = '<span id="' + this.editorId + '_parent">' + editorTemplate['html'];
+ while (n) {
+ p.absLeft += n.offsetLeft;
+ p.absTop += n.offsetTop;
+ n = n.offsetParent;
+ }
- var templateFunction = tinyMCE._getThemeFunction('_handleNodeChange', true);
- if (eval("typeof(" + templateFunction + ")") != 'undefined')
- this.settings['handleNodeChangeCallback'] = templateFunction;
+ return p;
+ },
- html = tinyMCE.replaceVar(html, "editor_id", this.editorId);
- this.settings['default_document'] = tinyMCE.baseURL + "/blank.htm";
+ create : function(n, c, p, h) {
+ var d = this.doc, e = d.createElement(n);
- this.settings['old_width'] = this.settings['width'];
- this.settings['old_height'] = this.settings['height'];
+ e.setAttribute('id', this.id);
- // Set default width, height
- if (this.settings['width'] == -1)
- this.settings['width'] = replace_element.offsetWidth;
+ if (c)
+ e.className = c;
- if (this.settings['height'] == -1)
- this.settings['height'] = replace_element.offsetHeight;
+ if (!p)
+ p = d.body;
- // Try the style width
- if (this.settings['width'] == 0)
- this.settings['width'] = replace_element.style.width;
+ if (h)
+ e.innerHTML = h;
- // Try the style height
- if (this.settings['height'] == 0)
- this.settings['height'] = replace_element.style.height;
+ p.appendChild(e);
- // If no width/height then default to 320x240, better than nothing
- if (this.settings['width'] == 0)
- this.settings['width'] = 320;
+ return this.element = e;
+ },
- if (this.settings['height'] == 0)
- this.settings['height'] = 240;
+ exists : function() {
+ return this.doc.getElementById(this.id) != null;
+ },
- this.settings['area_width'] = parseInt(this.settings['width']);
- this.settings['area_height'] = parseInt(this.settings['height']);
- this.settings['area_width'] += deltaWidth;
- this.settings['area_height'] += deltaHeight;
+ parseInt : function(s) {
+ if (s == null || s == '')
+ return 0;
- // Special % handling
- if (("" + this.settings['width']).indexOf('%') != -1)
- this.settings['area_width'] = "100%";
+ return parseInt(s);
+ },
- if (("" + this.settings['height']).indexOf('%') != -1)
- this.settings['area_height'] = "100%";
+ remove : function() {
+ var e = this.getElement(), b = this.getBlocker();
- if (("" + replace_element.style.width).indexOf('%') != -1) {
- this.settings['width'] = replace_element.style.width;
- this.settings['area_width'] = "100%";
- }
+ if (e)
+ e.parentNode.removeChild(e);
- if (("" + replace_element.style.height).indexOf('%') != -1) {
- this.settings['height'] = replace_element.style.height;
- this.settings['area_height'] = "100%";
+ if (b)
+ b.parentNode.removeChild(b);
}
- html = tinyMCE.applyTemplate(html);
+ };
- this.settings['width'] = this.settings['old_width'];
- this.settings['height'] = this.settings['old_height'];
+/* file:jscripts/tiny_mce/classes/TinyMCE_Menu.class.js */
- this.visualAid = this.settings['visual'];
- this.formTargetElementId = form_element_name;
+function TinyMCE_Menu() {
+ var id;
- // Get replace_element contents
- if (replace_element.nodeName == "TEXTAREA" || replace_element.nodeName == "INPUT")
- this.startContent = replace_element.value;
- else
- this.startContent = replace_element.innerHTML;
+ if (typeof(tinyMCE.menuCounter) == "undefined")
+ tinyMCE.menuCounter = 0;
- // If not text area
- if (replace_element.nodeName.toLowerCase() != "textarea") {
- this.oldTargetElement = replace_element.cloneNode(true);
+ id = "mc_menu_" + tinyMCE.menuCounter++;
- // Debug mode
- if (tinyMCE.settings['debug'])
- html += '<textarea wrap="off" id="' + form_element_name + '" name="' + form_element_name + '" cols="100" rows="15"></textarea>';
- else
- html += '<input type="hidden" type="text" id="' + form_element_name + '" name="' + form_element_name + '" />';
+ TinyMCE_Layer.call(this, id, true);
- html += '</span>';
+ this.id = id;
+ this.items = [];
+ this.needsUpdate = true;
+};
- // Output HTML and set editable
- if (!tinyMCE.isMSIE) {
- var rng = replace_element.ownerDocument.createRange();
- rng.setStartBefore(replace_element);
+TinyMCE_Menu.prototype = tinyMCE.extend(TinyMCE_Layer.prototype, {
+ init : function(s) {
+ var n;
- var fragment = rng.createContextualFragment(html);
- replace_element.parentNode.replaceChild(fragment, replace_element);
- } else
- replace_element.outerHTML = html;
- } else {
- html += '</span>';
+ // Default params
+ this.settings = {
+ separator_class : 'mceMenuSeparator',
+ title_class : 'mceMenuTitle',
+ disabled_class : 'mceMenuDisabled',
+ menu_class : 'mceMenu',
+ drop_menu : true
+ };
- // Just hide the textarea element
- this.oldTargetElement = replace_element;
+ for (n in s)
+ this.settings[n] = s[n];
- if (!tinyMCE.settings['debug'])
- this.oldTargetElement.style.display = "none";
+ this.create('div', this.settings.menu_class);
+ },
- // Output HTML and set editable
- if (!tinyMCE.isMSIE) {
- var rng = replace_element.ownerDocument.createRange();
- rng.setStartBefore(replace_element);
+ clear : function() {
+ this.items = [];
+ },
- var fragment = rng.createContextualFragment(html);
+ addTitle : function(t) {
+ this.add({type : 'title', text : t});
+ },
- if (tinyMCE.isGecko)
- tinyMCE.insertAfter(fragment, replace_element);
- else
- replace_element.parentNode.insertBefore(fragment, replace_element);
- } else
- replace_element.insertAdjacentHTML("beforeBegin", html);
- }
+ addDisabled : function(t) {
+ this.add({type : 'disabled', text : t});
+ },
- // Setup iframe
- var dynamicIFrame = false;
- var tElm = targetDoc.getElementById(this.editorId);
+ addSeparator : function() {
+ this.add({type : 'separator'});
+ },
- if (!tinyMCE.isMSIE) {
- if (tElm && tElm.nodeName.toLowerCase() == "span") {
- tElm = tinyMCE._createIFrame(tElm);
- dynamicIFrame = true;
- }
+ addItem : function(t, js) {
+ this.add({text : t, js : js});
+ },
- this.targetElement = tElm;
- this.iframeElement = tElm;
- this.contentDocument = tElm.contentDocument;
- this.contentWindow = tElm.contentWindow;
+ add : function(mi) {
+ this.items[this.items.length] = mi;
+ this.needsUpdate = true;
+ },
- //this.getDoc().designMode = "on";
- } else {
- if (tElm && tElm.nodeName.toLowerCase() == "span")
- tElm = tinyMCE._createIFrame(tElm);
- else
- tElm = targetDoc.frames[this.editorId];
+ update : function() {
+ var e = this.getElement(), h = '', i, t, m = this.items, s = this.settings;
- this.targetElement = tElm;
- this.iframeElement = targetDoc.getElementById(this.editorId);
+ if (this.settings.drop_menu)
+ h += '<span class="mceMenuLine"></span>';
- if (tinyMCE.isOpera) {
- this.contentDocument = this.iframeElement.contentDocument;
- this.contentWindow = this.iframeElement.contentWindow;
- dynamicIFrame = true;
- } else {
- this.contentDocument = tElm.window.document;
- this.contentWindow = tElm.window;
- }
+ h += '<table border="0" cellpadding="0" cellspacing="0">';
- this.getDoc().designMode = "on";
- }
+ for (i=0; i<m.length; i++) {
+ t = tinyMCE.xmlEncode(m[i].text);
+ c = m[i].class_name ? ' class="' + m[i].class_name + '"' : '';
- // Setup base HTML
- var doc = this.contentDocument;
- if (dynamicIFrame) {
- 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>';
+ switch (m[i].type) {
+ case 'separator':
+ h += '<tr class="' + s.separator_class + '"><td>';
+ break;
- try {
- if (!this.isHidden())
- this.getDoc().designMode = "on";
+ case 'title':
+ h += '<tr class="' + s.title_class + '"><td><span' + c +'>' + t + '</span>';
+ break;
- doc.open();
- doc.write(html);
- doc.close();
- } catch (e) {
- // Failed Mozilla 1.3
- this.getDoc().location.href = tinyMCE.baseURL + "/blank.htm";
+ case 'disabled':
+ h += '<tr class="' + s.disabled_class + '"><td><span' + c +'>' + t + '</span>';
+ break;
+
+ default:
+ 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>';
+ }
+
+ h += '</td></tr>';
}
- }
- // This timeout is needed in MSIE 5.5 for some odd reason
- // it seems that the document.frames isn't initialized yet?
- if (tinyMCE.isMSIE)
- window.setTimeout("TinyMCE.prototype.addEventHandlers('" + this.editorId + "');", 1);
+ h += '</table>';
- tinyMCE.setupContent(this.editorId, true);
+ e.innerHTML = h;
- return true;
-};
+ this.needsUpdate = false;
+ this.updateBlocker();
+ },
-TinyMCEControl.prototype.getFocusElement = function() {
- if (tinyMCE.isMSIE && !tinyMCE.isOpera) {
- var doc = this.getDoc();
- var rng = doc.selection.createRange();
+ show : function() {
+ var nl, i;
-// if (rng.collapse)
-// rng.collapse(true);
+ if (tinyMCE.lastMenu == this)
+ return;
- var elm = rng.item ? rng.item(0) : rng.parentElement();
- } else {
- if (this.isHidden())
- return this.getBody();
+ if (this.needsUpdate)
+ this.update();
- var sel = this.getSel();
- var rng = this.getRng();
+ if (tinyMCE.lastMenu && tinyMCE.lastMenu != this)
+ tinyMCE.lastMenu.hide();
- var elm = rng.commonAncestorContainer;
- //var elm = (sel && sel.anchorNode) ? sel.anchorNode : null;
+ TinyMCE_Layer.prototype.show.call(this);
- // Handle selection a image or other control like element such as anchors
- if (!rng.collapsed) {
- // Is selection small
- if (rng.startContainer == rng.endContainer) {
- if (rng.startOffset - rng.endOffset < 2) {
- if (rng.startContainer.hasChildNodes())
- elm = rng.startContainer.childNodes[rng.startOffset];
- }
- }
+ if (!tinyMCE.isOpera) {
+ // Accessibility stuff
+/* nl = this.getElement().getElementsByTagName("a");
+ if (nl.length > 0)
+ nl[0].focus();*/
}
- // Get the element parent of the node
- elm = tinyMCE.getParentElement(elm);
+ tinyMCE.lastMenu = this;
+ }
+
+ });
+
+/* file:jscripts/tiny_mce/classes/TinyMCE_Debug.class.js */
+
+tinyMCE.add(TinyMCE_Engine, {
+ debug : function() {
+ var m = "", a, i, l = tinyMCE.log.length;
+
+ for (i=0, a = this.debug.arguments; i<a.length; i++) {
+ m += a[i];
- //if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img")
- // elm = tinyMCE.selectedElement;
+ if (i<a.length-1)
+ m += ', ';
+ }
+
+ if (l < 1000)
+ tinyMCE.log[l] = "[debug] " + m;
}
- return elm;
-};
+ });
-// Global instances
-var tinyMCE = new TinyMCE();
-var tinyMCELang = new Array();