How to use Tiny method in storybook-root

Best JavaScript code snippet using storybook-root

tiny_mce.js

Source:tiny_mce.js Github

copy

Full Screen

1/**2 * $RCSfile: tiny_mce_src.js,v $3 * $Revision: 1.281 $4 * $Date: 2005/12/02 08:12:07 $5 *6 * @author Moxiecode7 * @copyright Copyright © 2004, Moxiecode Systems AB, All rights reserved.8 */9function TinyMCE() {10 this.majorVersion = "2";11 this.minorVersion = "0";12 this.releaseDate = "2005-12-01";13 this.instances = new Array();14 this.stickyClassesLookup = new Array();15 this.windowArgs = new Array();16 this.loadedFiles = new Array();17 this.configs = new Array();18 this.currentConfig = 0;19 this.eventHandlers = new Array();20 // Browser check21 var ua = navigator.userAgent;22 this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");23 this.isMSIE5 = this.isMSIE && (ua.indexOf('MSIE 5') != -1);24 this.isMSIE5_0 = this.isMSIE && (ua.indexOf('MSIE 5.0') != -1);25 this.isGecko = ua.indexOf('Gecko') != -1;26 this.isSafari = ua.indexOf('Safari') != -1;27 this.isOpera = ua.indexOf('Opera') != -1;28 this.isMac = ua.indexOf('Mac') != -1;29 this.isNS7 = ua.indexOf('Netscape/7') != -1;30 this.isNS71 = ua.indexOf('Netscape/7.1') != -1;31 this.dialogCounter = 0;32 // Fake MSIE on Opera and if Opera fakes IE, Gecko or Safari cancel those33 if (this.isOpera) {34 this.isMSIE = true;35 this.isGecko = false;36 this.isSafari = false;37 }38 // TinyMCE editor id instance counter39 this.idCounter = 0;40};41TinyMCE.prototype.defParam = function(key, def_val) {42 this.settings[key] = tinyMCE.getParam(key, def_val);43};44TinyMCE.prototype.init = function(settings) {45 var theme;46 this.settings = settings;47 // Check if valid browser has execcommand support48 if (typeof(document.execCommand) == 'undefined')49 return;50 // Get script base path51 if (!tinyMCE.baseURL) {52 var elements = document.getElementsByTagName('script');53 for (var i=0; i<elements.length; i++) {54 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)) {55 var src = elements[i].src;56 tinyMCE.srcMode = (src.indexOf('_src') != -1) ? '_src' : '';57 src = src.substring(0, src.lastIndexOf('/'));58 tinyMCE.baseURL = src;59 break;60 }61 }62 }63 // Get document base path64 this.documentBasePath = document.location.href;65 if (this.documentBasePath.indexOf('?') != -1)66 this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.indexOf('?'));67 this.documentURL = this.documentBasePath;68 this.documentBasePath = this.documentBasePath.substring(0, this.documentBasePath.lastIndexOf('/'));69 // If not HTTP absolute70 if (tinyMCE.baseURL.indexOf('://') == -1 && tinyMCE.baseURL.charAt(0) != '/') {71 // If site absolute72 tinyMCE.baseURL = this.documentBasePath + "/" + tinyMCE.baseURL;73 }74 // Set default values on settings75 this.defParam("mode", "none");76 this.defParam("theme", "advanced");77 this.defParam("plugins", "", true);78 this.defParam("language", "en");79 this.defParam("docs_language", this.settings['language']);80 this.defParam("elements", "");81 this.defParam("textarea_trigger", "mce_editable");82 this.defParam("editor_selector", "");83 this.defParam("editor_deselector", "mceNoEditor");84 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]");85 this.defParam("extended_valid_elements", "");86 this.defParam("invalid_elements", "");87 this.defParam("encoding", "");88 this.defParam("urlconverter_callback", tinyMCE.getParam("urlconvertor_callback", "TinyMCE.prototype.convertURL"));89 this.defParam("save_callback", "");90 this.defParam("debug", false);91 this.defParam("force_br_newlines", false);92 this.defParam("force_p_newlines", true);93 this.defParam("add_form_submit_trigger", true);94 this.defParam("relative_urls", true);95 this.defParam("remove_script_host", true);96 this.defParam("focus_alert", true);97 this.defParam("document_base_url", this.documentURL);98 this.defParam("visual", true);99 this.defParam("visual_table_class", "mceVisualAid");100 this.defParam("setupcontent_callback", "");101 this.defParam("fix_content_duplication", true);102 this.defParam("custom_undo_redo", true);103 this.defParam("custom_undo_redo_levels", -1);104 this.defParam("custom_undo_redo_keyboard_shortcuts", true);105 this.defParam("verify_css_classes", false);106 this.defParam("verify_html", true);107 this.defParam("apply_source_formatting", false);108 this.defParam("directionality", "ltr");109 this.defParam("cleanup_on_startup", false);110 this.defParam("inline_styles", false);111 this.defParam("convert_newlines_to_brs", false);112 this.defParam("auto_reset_designmode", true);113 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");114 this.defParam("entity_encoding", "named");115 this.defParam("cleanup_callback", "");116 this.defParam("add_unload_trigger", true);117 this.defParam("ask", false);118 this.defParam("nowrap", false);119 this.defParam("auto_resize", false);120 this.defParam("auto_focus", false);121 this.defParam("cleanup", true);122 this.defParam("remove_linebreaks", true);123 this.defParam("button_tile_map", false);124 this.defParam("submit_patch", true);125 this.defParam("browsers", "msie,safari,gecko,opera");126 this.defParam("dialog_type", "window");127 this.defParam("accessibility_warnings", true);128 this.defParam("merge_styles_invalid_parents", "");129 this.defParam("force_hex_style_colors", true);130 this.defParam("trim_span_elements", true);131 this.defParam("convert_fonts_to_spans", false);132 this.defParam("doctype", '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');133 this.defParam("font_size_classes", '');134 this.defParam("font_size_style_values", 'xx-small,x-small,small,medium,large,x-large,xx-large');135 this.defParam("event_elements", 'a,img');136 this.defParam("convert_urls", true);137 this.defParam("table_inline_editing", false);138 this.defParam("object_resizing", true);139 // Browser check IE140 if (this.isMSIE && this.settings['browsers'].indexOf('msie') == -1)141 return;142 // Browser check Gecko143 if (this.isGecko && this.settings['browsers'].indexOf('gecko') == -1)144 return;145 // Browser check Safari146 if (this.isSafari && this.settings['browsers'].indexOf('safari') == -1)147 return;148 // Browser check Opera149 if (this.isOpera && this.settings['browsers'].indexOf('opera') == -1)150 return;151 // If not super absolute make it so152 var baseHREF = tinyMCE.settings['document_base_url'];153 var h = document.location.href;154 var p = h.indexOf('://');155 if (p > 0 && document.location.protocol != "file:") {156 p = h.indexOf('/', p + 3);157 h = h.substring(0, p);158 if (baseHREF.indexOf('://') == -1)159 baseHREF = h + baseHREF;160 tinyMCE.settings['document_base_url'] = baseHREF;161 tinyMCE.settings['document_base_prefix'] = h;162 }163 // Trim away query part164 if (baseHREF.indexOf('?') != -1)165 baseHREF = baseHREF.substring(0, baseHREF.indexOf('?'));166 this.settings['base_href'] = baseHREF.substring(0, baseHREF.lastIndexOf('/')) + "/";167 theme = this.settings['theme'];168 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");169 this.posKeyCodes = new Array(13,45,36,35,33,34,37,38,39,40);170 this.uniqueURL = 'http://tinymce.moxiecode.cp/mce_temp_url'; // Make unique URL non real URL171 this.uniqueTag = '<div id="mceTMPElement" style="display: none">TMP</div>';172 // Theme url173 this.settings['theme_href'] = tinyMCE.baseURL + "/themes/" + theme;174 if (!tinyMCE.isMSIE)175 this.settings['force_br_newlines'] = false;176 if (tinyMCE.getParam("content_css", false)) {177 var cssPath = tinyMCE.getParam("content_css", "");178 // Is relative179 if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')180 this.settings['content_css'] = this.documentBasePath + "/" + cssPath;181 else182 this.settings['content_css'] = cssPath;183 } else184 this.settings['content_css'] = '';185 if (tinyMCE.getParam("popups_css", false)) {186 var cssPath = tinyMCE.getParam("popups_css", "");187 // Is relative188 if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')189 this.settings['popups_css'] = this.documentBasePath + "/" + cssPath;190 else191 this.settings['popups_css'] = cssPath;192 } else193 this.settings['popups_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_popup.css";194 if (tinyMCE.getParam("editor_css", false)) {195 var cssPath = tinyMCE.getParam("editor_css", "");196 // Is relative197 if (cssPath.indexOf('://') == -1 && cssPath.charAt(0) != '/')198 this.settings['editor_css'] = this.documentBasePath + "/" + cssPath;199 else200 this.settings['editor_css'] = cssPath;201 } else202 this.settings['editor_css'] = tinyMCE.baseURL + "/themes/" + theme + "/css/editor_ui.css";203 if (tinyMCE.settings['debug']) {204 var msg = "Debug: \n";205 msg += "baseURL: " + this.baseURL + "\n";206 msg += "documentBasePath: " + this.documentBasePath + "\n";207 msg += "content_css: " + this.settings['content_css'] + "\n";208 msg += "popups_css: " + this.settings['popups_css'] + "\n";209 msg += "editor_css: " + this.settings['editor_css'] + "\n";210 alert(msg);211 }212 // Init HTML cleanup213 this._initCleanup();214 // Only do this once215 if (this.configs.length == 0) {216 // Is Safari enabled217 if (this.isSafari && this.getParam('safari_warning', true))218 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");219 tinyMCE.addEvent(window, "load", TinyMCE.prototype.onLoad);220 if (tinyMCE.isMSIE) {221 if (tinyMCE.settings['add_unload_trigger']) {222 tinyMCE.addEvent(window, "unload", TinyMCE.prototype.unloadHandler);223 tinyMCE.addEvent(window.document, "beforeunload", TinyMCE.prototype.unloadHandler);224 }225 } else {226 if (tinyMCE.settings['add_unload_trigger'])227 tinyMCE.addEvent(window, "unload", function () {tinyMCE.triggerSave(true, true);});228 }229 }230 this.loadScript(tinyMCE.baseURL + '/themes/' + this.settings['theme'] + '/editor_template' + tinyMCE.srcMode + '.js');231 this.loadScript(tinyMCE.baseURL + '/langs/' + this.settings['language'] + '.js');232 this.loadCSS(this.settings['editor_css']);233 // Add plugins234 var themePlugins = tinyMCE.getParam('plugins', '', true, ',');235 if (this.settings['plugins'] != '') {236 for (var i=0; i<themePlugins.length; i++)237 this.loadScript(tinyMCE.baseURL + '/plugins/' + themePlugins[i] + '/editor_plugin' + tinyMCE.srcMode + '.js');238 }239 // Setup entities240 settings['cleanup_entities'] = new Array();241 var entities = tinyMCE.getParam('entities', '', true, ',');242 for (var i=0; i<entities.length; i+=2)243 settings['cleanup_entities']['c' + entities[i]] = entities[i+1];244 // Save away this config245 settings['index'] = this.configs.length;246 this.configs[this.configs.length] = settings;247};248TinyMCE.prototype.loadScript = function(url) {249 for (var i=0; i<this.loadedFiles.length; i++) {250 if (this.loadedFiles[i] == url)251 return;252 }253 document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></script>');254 this.loadedFiles[this.loadedFiles.length] = url;255};256TinyMCE.prototype.loadCSS = function(url) {257 for (var i=0; i<this.loadedFiles.length; i++) {258 if (this.loadedFiles[i] == url)259 return;260 }261 document.write('<link href="' + url + '" rel="stylesheet" type="text/css" />');262 this.loadedFiles[this.loadedFiles.length] = url;263};264TinyMCE.prototype.importCSS = function(doc, css_file) {265 if (css_file == '')266 return;267 if (typeof(doc.createStyleSheet) == "undefined") {268 var elm = doc.createElement("link");269 elm.rel = "stylesheet";270 elm.href = css_file;271 if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0)272 headArr[0].appendChild(elm);273 } else274 var styleSheet = doc.createStyleSheet(css_file);275};276TinyMCE.prototype.confirmAdd = function(e, settings) {277 var elm = tinyMCE.isMSIE ? event.srcElement : e.target;278 var elementId = elm.name ? elm.name : elm.id;279 tinyMCE.settings = settings;280 if (!elm.getAttribute('mce_noask') && confirm(tinyMCELang['lang_edit_confirm']))281 tinyMCE.addMCEControl(elm, elementId);282 elm.setAttribute('mce_noask', 'true');283};284TinyMCE.prototype.updateContent = function(form_element_name) {285 // Find MCE instance linked to given form element and copy it's value286 var formElement = document.getElementById(form_element_name);287 for (var n in tinyMCE.instances) {288 var inst = tinyMCE.instances[n];289 if (!tinyMCE.isInstance(inst))290 continue;291 inst.switchSettings();292 if (inst.formElement == formElement) {293 var doc = inst.getDoc();294 295 tinyMCE._setHTML(doc, inst.formElement.value);296 if (!tinyMCE.isMSIE)297 doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid);298 }299 }300};301TinyMCE.prototype.addMCEControl = function(replace_element, form_element_name, target_document) {302 var id = "mce_editor_" + tinyMCE.idCounter++;303 var inst = new TinyMCEControl(tinyMCE.settings);304 inst.editorId = id;305 this.instances[id] = inst;306 inst.onAdd(replace_element, form_element_name, target_document);307};308TinyMCE.prototype.triggerSave = function(skip_cleanup, skip_callback) {309 // Cleanup and set all form fields310 for (var n in tinyMCE.instances) {311 var inst = tinyMCE.instances[n];312 if (!tinyMCE.isInstance(inst))313 continue;314 inst.switchSettings();315 tinyMCE.settings['preformatted'] = false;316 // Default to false317 if (typeof(skip_cleanup) == "undefined")318 skip_cleanup = false;319 // Default to false320 if (typeof(skip_callback) == "undefined")321 skip_callback = false;322 tinyMCE._setHTML(inst.getDoc(), inst.getBody().innerHTML);323 // Remove visual aids when cleanup is disabled324 if (inst.settings['cleanup'] == false) {325 tinyMCE.handleVisualAid(inst.getBody(), true, false, inst);326 tinyMCE._setEventsEnabled(inst.getBody(), true);327 }328 tinyMCE._customCleanup(inst, "submit_content_dom", inst.contentWindow.document.body);329 var htm = skip_cleanup ? inst.getBody().innerHTML : tinyMCE._cleanupHTML(inst, inst.getDoc(), this.settings, inst.getBody(), this.visualAid, true);330 htm = tinyMCE._customCleanup(inst, "submit_content", htm);331 if (tinyMCE.settings["encoding"] == "xml" || tinyMCE.settings["encoding"] == "html")332 htm = tinyMCE.convertStringToXML(htm);333 if (!skip_callback && tinyMCE.settings['save_callback'] != "")334 var content = eval(tinyMCE.settings['save_callback'] + "(inst.formTargetElementId,htm,inst.getBody());");335 // Use callback content if available336 if ((typeof(content) != "undefined") && content != null)337 htm = content;338 // Replace some weird entities (Bug: #1056343)339 htm = tinyMCE.regexpReplace(htm, "&#40;", "(", "gi");340 htm = tinyMCE.regexpReplace(htm, "&#41;", ")", "gi");341 htm = tinyMCE.regexpReplace(htm, "&#59;", ";", "gi");342 htm = tinyMCE.regexpReplace(htm, "&#34;", "&quot;", "gi");343 htm = tinyMCE.regexpReplace(htm, "&#94;", "^", "gi");344 if (inst.formElement)345 inst.formElement.value = htm;346 }347};348TinyMCE.prototype._setEventsEnabled = function(node, state) {349 var events = new Array('onfocus','onblur','onclick','ondblclick',350 'onmousedown','onmouseup','onmouseover','onmousemove',351 'onmouseout','onkeypress','onkeydown','onkeydown','onkeyup');352 var evs = tinyMCE.settings['event_elements'].split(',');353 for (var y=0; y<evs.length; y++){354 var elms = node.getElementsByTagName(evs[y]);355 for (var i=0; i<elms.length; i++) {356 var event = "";357 for (var x=0; x<events.length; x++) {358 if ((event = tinyMCE.getAttrib(elms[i], events[x])) != '') {359 event = tinyMCE.cleanupEventStr("" + event);360 if (!state)361 event = "return true;" + event;362 else363 event = event.replace(/^return true;/gi, '');364 elms[i].removeAttribute(events[x]);365 elms[i].setAttribute(events[x], event);366 }367 }368 }369 }370};371TinyMCE.prototype.resetForm = function(form_index) {372 var formObj = document.forms[form_index];373 for (var n in tinyMCE.instances) {374 var inst = tinyMCE.instances[n];375 if (!tinyMCE.isInstance(inst))376 continue;377 inst.switchSettings();378 for (var i=0; i<formObj.elements.length; i++) {379 if (inst.formTargetElementId == formObj.elements[i].name)380 inst.getBody().innerHTML = inst.startContent;381 }382 }383};384TinyMCE.prototype.execInstanceCommand = function(editor_id, command, user_interface, value, focus) {385 var inst = tinyMCE.getInstanceById(editor_id);386 if (inst) {387 if (typeof(focus) == "undefined")388 focus = true;389 if (focus)390 inst.contentWindow.focus();391 // Reset design mode if lost392 inst.autoResetDesignMode();393 this.selectedElement = inst.getFocusElement();394 this.selectedInstance = inst;395 tinyMCE.execCommand(command, user_interface, value);396 // Cancel event so it doesn't call onbeforeonunlaod397 if (tinyMCE.isMSIE && window.event != null)398 tinyMCE.cancelEvent(window.event);399 }400};401TinyMCE.prototype.execCommand = function(command, user_interface, value) {402 // Default input403 user_interface = user_interface ? user_interface : false;404 value = value ? value : null;405 if (tinyMCE.selectedInstance)406 tinyMCE.selectedInstance.switchSettings();407 switch (command) {408 case 'mceHelp':409 var template = new Array();410 template['file'] = 'about.htm';411 template['width'] = 480;412 template['height'] = 380;413 tinyMCE.openWindow(template, {414 tinymce_version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion,415 tinymce_releasedate : tinyMCE.releaseDate,416 inline : "yes"417 });418 return;419 case 'mceFocus':420 var inst = tinyMCE.getInstanceById(value);421 if (inst)422 inst.contentWindow.focus();423 return;424 case "mceAddControl":425 case "mceAddEditor":426 tinyMCE.addMCEControl(tinyMCE._getElementById(value), value);427 return;428 case "mceAddFrameControl":429 tinyMCE.addMCEControl(tinyMCE._getElementById(value), value['element'], value['document']);430 return;431 case "mceRemoveControl":432 case "mceRemoveEditor":433 tinyMCE.removeMCEControl(value);434 return;435 case "mceResetDesignMode":436 // Resets the designmode state of the editors in Gecko437 if (!tinyMCE.isMSIE) {438 for (var n in tinyMCE.instances) {439 if (!tinyMCE.isInstance(tinyMCE.instances[n]))440 continue;441 try {442 tinyMCE.instances[n].getDoc().designMode = "on";443 } catch (e) {444 // Ignore any errors445 }446 }447 }448 return;449 }450 if (this.selectedInstance) {451 this.selectedInstance.execCommand(command, user_interface, value);452 } else if (tinyMCE.settings['focus_alert'])453 alert(tinyMCELang['lang_focus_alert']);454};455TinyMCE.prototype.eventPatch = function(editor_id) {456 // Remove odd, error457 if (typeof(tinyMCE) == "undefined")458 return true;459 for (var i=0; i<document.frames.length; i++) {460 try {461 if (document.frames[i].event) {462 var event = document.frames[i].event;463 if (!event.target)464 event.target = event.srcElement;465 TinyMCE.prototype.handleEvent(event);466 return;467 }468 } catch (ex) {469 // Ignore error if iframe is pointing to external URL470 }471 }472};473TinyMCE.prototype.unloadHandler = function() {474 tinyMCE.triggerSave(true, true);475};476TinyMCE.prototype.addEventHandlers = function(editor_id) {477 if (tinyMCE.isMSIE) {478 var doc = document.frames[editor_id].document;479 // Event patch480 tinyMCE.addEvent(doc, "keypress", TinyMCE.prototype.eventPatch);481 tinyMCE.addEvent(doc, "keyup", TinyMCE.prototype.eventPatch);482 tinyMCE.addEvent(doc, "keydown", TinyMCE.prototype.eventPatch);483 tinyMCE.addEvent(doc, "mouseup", TinyMCE.prototype.eventPatch);484 tinyMCE.addEvent(doc, "click", TinyMCE.prototype.eventPatch);485 } else {486 var inst = tinyMCE.instances[editor_id];487 var doc = inst.getDoc();488 inst.switchSettings();489 tinyMCE.addEvent(doc, "keypress", tinyMCE.handleEvent);490 tinyMCE.addEvent(doc, "keydown", tinyMCE.handleEvent);491 tinyMCE.addEvent(doc, "keyup", tinyMCE.handleEvent);492 tinyMCE.addEvent(doc, "click", tinyMCE.handleEvent);493 tinyMCE.addEvent(doc, "mouseup", tinyMCE.handleEvent);494 tinyMCE.addEvent(doc, "mousedown", tinyMCE.handleEvent);495 tinyMCE.addEvent(doc, "focus", tinyMCE.handleEvent);496 tinyMCE.addEvent(doc, "blur", tinyMCE.handleEvent);497 eval('try { doc.designMode = "On"; } catch(e) {}');498 }499};500TinyMCE.prototype._createIFrame = function(replace_element) {501 var iframe = document.createElement("iframe");502 var id = replace_element.getAttribute("id");503 var aw, ah;504 aw = "" + tinyMCE.settings['area_width'];505 ah = "" + tinyMCE.settings['area_height'];506 if (aw.indexOf('%') == -1) {507 aw = parseInt(aw);508 aw = aw < 0 ? 300 : aw;509 aw = aw + "px";510 }511 if (ah.indexOf('%') == -1) {512 ah = parseInt(ah);513 ah = ah < 0 ? 240 : ah;514 ah = ah + "px";515 }516 iframe.setAttribute("id", id);517 //iframe.setAttribute("className", "mceEditorArea");518 iframe.setAttribute("border", "0");519 iframe.setAttribute("frameBorder", "0");520 iframe.setAttribute("marginWidth", "0");521 iframe.setAttribute("marginHeight", "0");522 iframe.setAttribute("leftMargin", "0");523 iframe.setAttribute("topMargin", "0");524 iframe.setAttribute("width", aw);525 iframe.setAttribute("height", ah);526 iframe.setAttribute("allowtransparency", "true");527 if (tinyMCE.settings["auto_resize"])528 iframe.setAttribute("scrolling", "no");529 // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs530 if (tinyMCE.isMSIE && !tinyMCE.isOpera)531 iframe.setAttribute("src", this.settings['default_document']);532 iframe.style.width = aw;533 iframe.style.height = ah;534 // MSIE 5.0 issue535 if (tinyMCE.isMSIE && !tinyMCE.isOpera)536 replace_element.outerHTML = iframe.outerHTML;537 else538 replace_element.parentNode.replaceChild(iframe, replace_element);539 if (tinyMCE.isMSIE)540 return window.frames[id];541 else542 return iframe;543};544TinyMCE.prototype.setupContent = function(editor_id) {545 var inst = tinyMCE.instances[editor_id];546 var doc = inst.getDoc();547 var head = doc.getElementsByTagName('head').item(0);548 var content = inst.startContent;549 tinyMCE.operaOpacityCounter = 100 * tinyMCE.idCounter;550 inst.switchSettings();551 // Not loaded correctly hit it again, Mozilla bug #997860552 if (!tinyMCE.isMSIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") {553 // This part will remove the designMode status554 // Failes first time in Firefox 1.5b2 on Mac555 try {doc.location.href = tinyMCE.baseURL + "/blank.htm";} catch (ex) {}556 window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 1000);557 return;558 }559 if (!head) {560 window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10);561 return;562 }563 // Import theme specific content CSS the user specific564 tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/themes/" + inst.settings['theme'] + "/css/editor_content.css");565 tinyMCE.importCSS(inst.getDoc(), inst.settings['content_css']);566 tinyMCE.executeCallback('init_instance_callback', '_initInstance', 0, inst);567 // Setup span styles568 if (tinyMCE.getParam("convert_fonts_to_spans"))569 inst.getDoc().body.setAttribute('id', 'mceSpanFonts');570 if (tinyMCE.settings['nowrap'])571 doc.body.style.whiteSpace = "nowrap";572 doc.body.dir = this.settings['directionality'];573 doc.editorId = editor_id;574 // Add on document element in Mozilla575 if (!tinyMCE.isMSIE)576 doc.documentElement.editorId = editor_id;577 // Setup base element578 var base = doc.createElement("base");579 base.setAttribute('href', tinyMCE.settings['base_href']);580 head.appendChild(base);581 // Replace new line characters to BRs582 if (tinyMCE.settings['convert_newlines_to_brs']) {583 content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi");584 content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi");585 content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi");586 }587 // Open closed anchors588// content = content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');589 // Call custom cleanup code590 content = tinyMCE.storeAwayURLs(content);591 content = tinyMCE._customCleanup(inst, "insert_to_editor", content);592 if (tinyMCE.isMSIE) {593 // Ugly!!!594 window.setInterval('try{tinyMCE.getCSSClasses(document.frames["' + editor_id + '"].document, "' + editor_id + '");}catch(e){}', 500);595 if (tinyMCE.settings["force_br_newlines"])596 document.frames[editor_id].document.styleSheets[0].addRule("p", "margin: 0px;");597 var body = document.frames[editor_id].document.body;598 tinyMCE.addEvent(body, "beforepaste", TinyMCE.prototype.eventPatch);599 tinyMCE.addEvent(body, "beforecut", TinyMCE.prototype.eventPatch);600 body.editorId = editor_id;601 }602 content = tinyMCE.cleanupHTMLCode(content);603 // Fix for bug #958637604 if (!tinyMCE.isMSIE) {605 var contentElement = inst.getDoc().createElement("body");606 var doc = inst.getDoc();607 contentElement.innerHTML = content;608 // Remove weridness!609 if (tinyMCE.isGecko && tinyMCE.settings['remove_lt_gt'])610 content = content.replace(new RegExp('&lt;&gt;', 'g'), "");611 if (tinyMCE.settings['cleanup_on_startup'])612 tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement));613 else {614 // Convert all strong/em to b/i615 content = tinyMCE.regexpReplace(content, "<strong", "<b", "gi");616 content = tinyMCE.regexpReplace(content, "<em(/?)>", "<i$1>", "gi");617 content = tinyMCE.regexpReplace(content, "<em ", "<i ", "gi");618 content = tinyMCE.regexpReplace(content, "</strong>", "</b>", "gi");619 content = tinyMCE.regexpReplace(content, "</em>", "</i>", "gi");620 tinyMCE.setInnerHTML(inst.getBody(), content);621 }622 inst.convertAllRelativeURLs();623 } else {624 if (tinyMCE.settings['cleanup_on_startup']) {625 tinyMCE._setHTML(inst.getDoc(), content);626 // Produces permission denied error in MSIE 5.5627 eval('try {tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody()));} catch(e) {}');628 } else629 tinyMCE._setHTML(inst.getDoc(), content);630 }631 // Fix for bug #957681632 //inst.getDoc().designMode = inst.getDoc().designMode;633 // Setup element references634 var parentElm = document.getElementById(inst.editorId + '_parent');635 if (parentElm.lastChild.nodeName == "INPUT")636 inst.formElement = tinyMCE.isGecko ? parentElm.firstChild : parentElm.lastChild;637 else638 inst.formElement = tinyMCE.isGecko ? parentElm.previousSibling : parentElm.nextSibling;639 tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings['visual'], inst);640 tinyMCE.executeCallback('setupcontent_callback', '_setupContent', 0, editor_id, inst.getBody(), inst.getDoc());641 // Re-add design mode on mozilla642 if (!tinyMCE.isMSIE)643 TinyMCE.prototype.addEventHandlers(editor_id);644 // Add blur handler645 if (tinyMCE.isMSIE)646 tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE.prototype.eventPatch);647 // Trigger node change, this call locks buttons for tables and so forth648 tinyMCE.selectedInstance = inst;649 tinyMCE.selectedElement = inst.contentWindow.document.body;650 if (!inst.isHidden())651 tinyMCE.triggerNodeChange(false, true);652 // Call custom DOM cleanup653 tinyMCE._customCleanup(inst, "insert_to_editor_dom", inst.getBody());654 tinyMCE._customCleanup(inst, "setup_content_dom", inst.getBody());655 tinyMCE._setEventsEnabled(inst.getBody(), false);656 tinyMCE.cleanupAnchors(inst.getDoc());657 if (tinyMCE.getParam("convert_fonts_to_spans"))658 tinyMCE.convertSpansToFonts(inst.getDoc());659 inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);660 inst.undoLevels[inst.undoLevels.length] = inst.startContent;661 tinyMCE.operaOpacityCounter = -1;662};663TinyMCE.prototype.cleanupHTMLCode = function(s) {664 s = s.replace(/<p \/>/gi, '<p>&nbsp;</p>');665 s = s.replace(/<p>\s*<\/p>/gi, '<p>&nbsp;</p>');666 // Open closed tags like <b/> to <b></b>667// tinyMCE.debug("f:" + s);668 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>');669// tinyMCE.debug("e:" + s);670 // Remove trailing space <b > to <b>671 s = s.replace(new RegExp('\\s+></', 'gi'), '></');672 // Close tags <img></img> to <img/>673 s = s.replace(/<(img|br|hr)(.*?)><\/(img|br|hr)>/gi, '<$1$2 />');674 // Weird MSIE bug, <p><hr /></p> breaks runtime?675 if (tinyMCE.isMSIE)676 s = s.replace(/<p><hr \/><\/p>/gi, "<hr>");677 // Convert relative anchors to absolute URLs ex: #something to file.htm#something678 s = s.replace(new RegExp('(href=\"?)(\\s*?#)', 'gi'), '$1' + tinyMCE.settings['document_base_url'] + "#");679 return s;680};681TinyMCE.prototype.storeAwayURLs = function(s) {682 // Remove all mce_src, mce_href and replace them with new ones683 s = s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');684 s = s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');685 s = s.replace(new RegExp('src\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'src="$1" mce_src="$1"');686 s = s.replace(new RegExp('href\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'href="$1" mce_href="$1"');687 return s;688};689TinyMCE.prototype.cancelEvent = function(e) {690 if (tinyMCE.isMSIE) {691 e.returnValue = false;692 e.cancelBubble = true;693 } else694 e.preventDefault();695};696TinyMCE.prototype.removeTinyMCEFormElements = function(form_obj) {697 // Check if form is valid698 if (typeof(form_obj) == "undefined" || form_obj == null)699 return;700 // If not a form, find the form701 if (form_obj.nodeName != "FORM") {702 if (form_obj.form)703 form_obj = form_obj.form;704 else705 form_obj = tinyMCE.getParentElement(form_obj, "form");706 }707 // Still nothing708 if (form_obj == null)709 return;710 // Disable all UI form elements that TinyMCE created711 for (var i=0; i<form_obj.elements.length; i++) {712 var elementId = form_obj.elements[i].name ? form_obj.elements[i].name : form_obj.elements[i].id;713 if (elementId.indexOf('mce_editor_') == 0)714 form_obj.elements[i].disabled = true;715 }716};717TinyMCE.prototype.accessibleEventHandler = function(e) {718 var win = this._win;719 e = tinyMCE.isMSIE ? win.event : e;720 var elm = tinyMCE.isMSIE ? e.srcElement : e.target;721 // Piggyback onchange722 if (elm.nodeName == "SELECT" && !elm.oldonchange) {723 elm.oldonchange = elm.onchange;724 elm.onchange = null;725 }726 // Execute onchange and remove piggyback727 if (e.keyCode == 13 || e.keyCode == 32) {728 elm.onchange = elm.oldonchange;729 elm.onchange();730 elm.oldonchange = null;731 tinyMCE.cancelEvent(e);732 }733};734TinyMCE.prototype.addSelectAccessibility = function(e, select, win) {735 // Add event handlers 736 if (!select._isAccessible) {737 select.onkeydown = tinyMCE.accessibleEventHandler;738 select._isAccessible = true;739 select._win = win;740 }741};742TinyMCE.prototype.handleEvent = function(e) {743 // Remove odd, error744 if (typeof(tinyMCE) == "undefined")745 return true;746 //tinyMCE.debug(e.type + " " + e.target.nodeName + " " + (e.relatedTarget ? e.relatedTarget.nodeName : ""));747 switch (e.type) {748 case "blur":749 if (tinyMCE.selectedInstance)750 tinyMCE.selectedInstance.execCommand('mceEndTyping');751 return;752 case "submit":753 tinyMCE.removeTinyMCEFormElements(tinyMCE.isMSIE ? window.event.srcElement : e.target);754 tinyMCE.triggerSave();755 tinyMCE.isNotDirty = true;756 return;757 case "reset":758 var formObj = tinyMCE.isMSIE ? window.event.srcElement : e.target;759 for (var i=0; i<document.forms.length; i++) {760 if (document.forms[i] == formObj)761 window.setTimeout('tinyMCE.resetForm(' + i + ');', 10);762 }763 return;764 case "keypress":765 if (e.target.editorId) {766 tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];767 } else {768 if (e.target.ownerDocument.editorId)769 tinyMCE.selectedInstance = tinyMCE.instances[e.target.ownerDocument.editorId];770 }771 if (tinyMCE.selectedInstance)772 tinyMCE.selectedInstance.switchSettings();773 // Insert space instead of &nbsp;774/* if (tinyMCE.isGecko && e.charCode == 32) {775 if (tinyMCE.selectedInstance._insertSpace()) {776 // Cancel event777 e.preventDefault();778 return false;779 }780 }*/781 // Insert P element782 if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && e.keyCode == 13 && !e.shiftKey) {783 // Insert P element instead of BR784 if (tinyMCE.selectedInstance._insertPara(e)) {785 // Cancel event786 tinyMCE.execCommand("mceAddUndoLevel");787 tinyMCE.cancelEvent(e);788 return false;789 }790 }791 // Handle backspace792 if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {793 // Insert P element instead of BR794 if (tinyMCE.selectedInstance._handleBackSpace(e.type)) {795 // Cancel event796 tinyMCE.execCommand("mceAddUndoLevel");797 tinyMCE.cancelEvent(e);798 return false;799 }800 }801 // Mozilla custom key handling802 if (tinyMCE.isGecko && (e.ctrlKey && !e.altKey) && tinyMCE.settings['custom_undo_redo']) {803 if (tinyMCE.settings['custom_undo_redo_keyboard_shortcuts']) {804 if (e.charCode == 122) { // Ctrl+Z805 tinyMCE.selectedInstance.execCommand("Undo");806 tinyMCE.cancelEvent(e);807 return false;808 }809 if (e.charCode == 121) { // Ctrl+Y810 tinyMCE.selectedInstance.execCommand("Redo");811 tinyMCE.cancelEvent(e);812 return false;813 }814 }815 if (e.charCode == 98) { // Ctrl+B816 tinyMCE.selectedInstance.execCommand("Bold");817 tinyMCE.cancelEvent(e);818 return false;819 }820 if (e.charCode == 105) { // Ctrl+I821 tinyMCE.selectedInstance.execCommand("Italic");822 tinyMCE.cancelEvent(e);823 return false;824 }825 if (e.charCode == 117) { // Ctrl+U826 tinyMCE.selectedInstance.execCommand("Underline");827 tinyMCE.cancelEvent(e);828 return false;829 }830 if (e.charCode == 118) { // Ctrl+V831 tinyMCE.selectedInstance.execCommand("mceInsertContent", false, '<geckopastefix/>');832 }833 }834 // Return key pressed835 if (tinyMCE.isMSIE && tinyMCE.settings['force_br_newlines'] && e.keyCode == 13) {836 if (e.target.editorId)837 tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];838 if (tinyMCE.selectedInstance) {839 var sel = tinyMCE.selectedInstance.getDoc().selection;840 var rng = sel.createRange();841 if (tinyMCE.getParentElement(rng.parentElement(), "li") != null)842 return false;843 // Cancel event844 e.returnValue = false;845 e.cancelBubble = true;846 // Insert BR element847 rng.pasteHTML("<br />");848 rng.collapse(false);849 rng.select();850 tinyMCE.execCommand("mceAddUndoLevel");851 tinyMCE.triggerNodeChange(false);852 return false;853 }854 }855 // Backspace or delete856 if (e.keyCode == 8 || e.keyCode == 46) {857 tinyMCE.selectedElement = e.target;858 tinyMCE.linkElement = tinyMCE.getParentElement(e.target, "a");859 tinyMCE.imgElement = tinyMCE.getParentElement(e.target, "img");860 tinyMCE.triggerNodeChange(false);861 }862 return false;863 break;864 case "keyup":865 case "keydown":866 if (e.target.editorId)867 tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];868 else869 return;870 if (tinyMCE.selectedInstance)871 tinyMCE.selectedInstance.switchSettings();872 var inst = tinyMCE.selectedInstance;873 // Handle backspace874 if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {875 // Insert P element instead of BR876 if (tinyMCE.selectedInstance._handleBackSpace(e.type)) {877 // Cancel event878 tinyMCE.execCommand("mceAddUndoLevel");879 e.preventDefault();880 return false;881 }882 }883 tinyMCE.selectedElement = null;884 tinyMCE.selectedNode = null;885 var elm = tinyMCE.selectedInstance.getFocusElement();886 tinyMCE.linkElement = tinyMCE.getParentElement(elm, "a");887 tinyMCE.imgElement = tinyMCE.getParentElement(elm, "img");888 tinyMCE.selectedElement = elm;889 // Update visualaids on tabs890 if (tinyMCE.isGecko && e.type == "keyup" && e.keyCode == 9)891 tinyMCE.handleVisualAid(tinyMCE.selectedInstance.getBody(), true, tinyMCE.settings['visual'], tinyMCE.selectedInstance);892 // Fix empty elements on return/enter, check where enter occured893 if (tinyMCE.isMSIE && e.type == "keydown" && e.keyCode == 13)894 tinyMCE.enterKeyElement = tinyMCE.selectedInstance.getFocusElement();895 // Fix empty elements on return/enter896 if (tinyMCE.isMSIE && e.type == "keyup" && e.keyCode == 13) {897 var elm = tinyMCE.enterKeyElement;898 if (elm) {899 var re = new RegExp('^HR|IMG|BR$','g'); // Skip these900 var dre = new RegExp('^H[1-6]$','g'); // Add double on these901 if (!elm.hasChildNodes() && !re.test(elm.nodeName)) {902 if (dre.test(elm.nodeName))903 elm.innerHTML = "&nbsp;&nbsp;";904 else905 elm.innerHTML = "&nbsp;";906 }907 }908 }909 // Check if it's a position key910 var keys = tinyMCE.posKeyCodes;911 var posKey = false;912 for (var i=0; i<keys.length; i++) {913 if (keys[i] == e.keyCode) {914 posKey = true;915 break;916 }917 }918 // MSIE custom key handling919 if (tinyMCE.isMSIE && tinyMCE.settings['custom_undo_redo']) {920 var keys = new Array(8,46); // Backspace,Delete921 for (var i=0; i<keys.length; i++) {922 if (keys[i] == e.keyCode) {923 if (e.type == "keyup")924 tinyMCE.triggerNodeChange(false);925 }926 }927 if (tinyMCE.settings['custom_undo_redo_keyboard_shortcuts']) {928 if (e.keyCode == 90 && (e.ctrlKey && !e.altKey) && e.type == "keydown") { // Ctrl+Z929 tinyMCE.selectedInstance.execCommand("Undo");930 tinyMCE.triggerNodeChange(false);931 }932 if (e.keyCode == 89 && (e.ctrlKey && !e.altKey) && e.type == "keydown") { // Ctrl+Y933 tinyMCE.selectedInstance.execCommand("Redo");934 tinyMCE.triggerNodeChange(false);935 }936 if ((e.keyCode == 90 || e.keyCode == 89) && (e.ctrlKey && !e.altKey)) {937 // Cancel event938 e.returnValue = false;939 e.cancelBubble = true;940 return false;941 }942 }943 }944 // If undo/redo key945 if ((e.keyCode == 90 || e.keyCode == 89) && (e.ctrlKey && !e.altKey))946 return true;947 // If Ctrl key948 if (e.keyCode == 17)949 return true;950 // Handle Undo/Redo when typing content951 // Start typing (non position key)952 if (!posKey && e.type == "keyup")953 tinyMCE.execCommand("mceStartTyping");954 // End typing (position key) or some Ctrl event955 if (e.type == "keyup" && (posKey || e.ctrlKey))956 tinyMCE.execCommand("mceEndTyping");957 if (posKey && e.type == "keyup")958 tinyMCE.triggerNodeChange(false);959 if (tinyMCE.isMSIE && e.ctrlKey)960 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);961 break;962 case "mousedown":963 case "mouseup":964 case "click":965 case "focus":966 if (tinyMCE.selectedInstance)967 tinyMCE.selectedInstance.switchSettings();968 // Check instance event trigged on969 var targetBody = tinyMCE.getParentElement(e.target, "body");970 for (var instanceName in tinyMCE.instances) {971 if (!tinyMCE.isInstance(tinyMCE.instances[instanceName]))972 continue;973 var inst = tinyMCE.instances[instanceName];974 // Reset design mode if lost (on everything just in case)975 inst.autoResetDesignMode();976 if (inst.getBody() == targetBody) {977 tinyMCE.selectedInstance = inst;978 tinyMCE.selectedElement = e.target;979 tinyMCE.linkElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");980 tinyMCE.imgElement = tinyMCE.getParentElement(tinyMCE.selectedElement, "img");981 break;982 }983 }984 if (tinyMCE.isSafari) {985 tinyMCE.selectedInstance.lastSafariSelection = tinyMCE.selectedInstance.getBookmark();986 tinyMCE.selectedInstance.lastSafariSelectedElement = tinyMCE.selectedElement;987 var lnk = tinyMCE.getParentElement(tinyMCE.selectedElement, "a");988 // Patch the darned link989 if (lnk && e.type == "mousedown") {990 lnk.setAttribute("mce_real_href", lnk.getAttribute("href"));991 lnk.setAttribute("href", "javascript:void(0);");992 }993 // Patch back994 if (lnk && e.type == "click") {995 window.setTimeout(function() {996 lnk.setAttribute("href", lnk.getAttribute("mce_real_href"));997 lnk.removeAttribute("mce_real_href");998 }, 10);999 }1000 }1001 // Reset selected node1002 if (e.type != "focus")1003 tinyMCE.selectedNode = null;1004 tinyMCE.triggerNodeChange(false);1005 tinyMCE.execCommand("mceEndTyping");1006 if (e.type == "mouseup")1007 tinyMCE.execCommand("mceAddUndoLevel");1008 // Just in case1009 if (!tinyMCE.selectedInstance && e.target.editorId)1010 tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];1011 return false;1012 break;1013 } // end switch1014}; // end function1015TinyMCE.prototype.switchClass = function(element, class_name, lock_state) {1016 var lockChanged = false;1017 if (typeof(lock_state) != "undefined" && element != null) {1018 element.classLock = lock_state;1019 lockChanged = true;1020 }1021 if (element != null && (lockChanged || !element.classLock)) {1022 element.oldClassName = element.className;1023 element.className = class_name;1024 }1025};1026TinyMCE.prototype.restoreAndSwitchClass = function(element, class_name) {1027 if (element != null && !element.classLock) {1028 this.restoreClass(element);1029 this.switchClass(element, class_name);1030 }1031};1032TinyMCE.prototype.switchClassSticky = function(element_name, class_name, lock_state) {1033 var element, lockChanged = false;1034 // Performance issue1035 if (!this.stickyClassesLookup[element_name])1036 this.stickyClassesLookup[element_name] = document.getElementById(element_name);1037// element = document.getElementById(element_name);1038 element = this.stickyClassesLookup[element_name];1039 if (typeof(lock_state) != "undefined" && element != null) {1040 element.classLock = lock_state;1041 lockChanged = true;1042 }1043 if (element != null && (lockChanged || !element.classLock)) {1044 element.className = class_name;1045 element.oldClassName = class_name;1046 // Fix opacity in Opera1047 if (tinyMCE.isOpera) {1048 if (class_name == "mceButtonDisabled") {1049 var suffix = "";1050 if (!element.mceOldSrc)1051 element.mceOldSrc = element.src;1052 if (this.operaOpacityCounter > -1)1053 suffix = '?rnd=' + this.operaOpacityCounter++;1054 element.src = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/images/opacity.png" + suffix;1055 element.style.backgroundImage = "url('" + element.mceOldSrc + "')";1056 } else {1057 if (element.mceOldSrc) {1058 element.src = element.mceOldSrc;1059 element.parentNode.style.backgroundImage = "";1060 element.mceOldSrc = null;1061 }1062 }1063 }1064 }1065};1066TinyMCE.prototype.restoreClass = function(element) {1067 if (element != null && element.oldClassName && !element.classLock) {1068 element.className = element.oldClassName;1069 element.oldClassName = null;1070 }1071};1072TinyMCE.prototype.setClassLock = function(element, lock_state) {1073 if (element != null)1074 element.classLock = lock_state;1075};1076TinyMCE.prototype.addEvent = function(obj, name, handler) {1077 if (tinyMCE.isMSIE) {1078 obj.attachEvent("on" + name, handler);1079 } else1080 obj.addEventListener(name, handler, false);1081};1082TinyMCE.prototype.submitPatch = function() {1083 tinyMCE.removeTinyMCEFormElements(this);1084 tinyMCE.triggerSave();1085 this.mceOldSubmit();1086 tinyMCE.isNotDirty = true;1087};1088TinyMCE.prototype.onLoad = function() {1089 for (var c=0; c<tinyMCE.configs.length; c++) {1090 tinyMCE.settings = tinyMCE.configs[c];1091 var selector = tinyMCE.getParam("editor_selector");1092 var deselector = tinyMCE.getParam("editor_deselector");1093 var elementRefAr = new Array();1094 // Add submit triggers1095 if (document.forms && tinyMCE.settings['add_form_submit_trigger'] && !tinyMCE.submitTriggers) {1096 for (var i=0; i<document.forms.length; i++) {1097 var form = document.forms[i];1098 tinyMCE.addEvent(form, "submit", TinyMCE.prototype.handleEvent);1099 tinyMCE.addEvent(form, "reset", TinyMCE.prototype.handleEvent);1100 tinyMCE.submitTriggers = true; // Do it only once1101 // Patch the form.submit function1102 if (tinyMCE.settings['submit_patch']) {1103 try {1104 form.mceOldSubmit = form.submit;1105 form.submit = TinyMCE.prototype.submitPatch;1106 } catch (e) {1107 // Do nothing1108 }1109 }1110 }1111 }1112 // Add editor instances based on mode1113 var mode = tinyMCE.settings['mode'];1114 switch (mode) {1115 case "exact":1116 var elements = tinyMCE.getParam('elements', '', true, ',');1117 for (var i=0; i<elements.length; i++) {1118 var element = tinyMCE._getElementById(elements[i]);1119 var trigger = element ? element.getAttribute(tinyMCE.settings['textarea_trigger']) : "";1120 if (tinyMCE.getAttrib(element, "class").indexOf(deselector) != -1)1121 continue;1122 if (trigger == "false")1123 continue;1124 if (tinyMCE.settings['ask'] && element) {1125 elementRefAr[elementRefAr.length] = element;1126 continue;1127 }1128 if (element)1129 tinyMCE.addMCEControl(element, elements[i]);1130 else if (tinyMCE.settings['debug'])1131 alert("Error: Could not find element by id or name: " + elements[i]);1132 }1133 break;1134 case "specific_textareas":1135 case "textareas":1136 var nodeList = document.getElementsByTagName("textarea");1137 for (var i=0; i<nodeList.length; i++) {1138 var elm = nodeList.item(i);1139 var trigger = elm.getAttribute(tinyMCE.settings['textarea_trigger']);1140 if (selector != '' && tinyMCE.getAttrib(elm, "class").indexOf(selector) == -1)1141 continue;1142 if (selector != '')1143 trigger = selector != "" ? "true" : "";1144 if (tinyMCE.getAttrib(elm, "class").indexOf(deselector) != -1)1145 continue;1146 if ((mode == "specific_textareas" && trigger == "true") || (mode == "textareas" && trigger != "false"))1147 elementRefAr[elementRefAr.length] = elm;1148 }1149 break;1150 }1151 for (var i=0; i<elementRefAr.length; i++) {1152 var element = elementRefAr[i];1153 var elementId = element.name ? element.name : element.id;1154 if (tinyMCE.settings['ask']) {1155 // Focus breaks in Mozilla1156 if (tinyMCE.isGecko) {1157 var settings = tinyMCE.settings;1158 tinyMCE.addEvent(element, "focus", function (e) {window.setTimeout(function() {TinyMCE.prototype.confirmAdd(e, settings);}, 10);});1159 } else {1160 var settings = tinyMCE.settings;1161 tinyMCE.addEvent(element, "focus", function () { TinyMCE.prototype.confirmAdd(null, settings); });1162 }1163 } else1164 tinyMCE.addMCEControl(element, elementId);1165 }1166 // Handle auto focus1167 if (tinyMCE.settings['auto_focus']) {1168 window.setTimeout(function () {1169 var inst = tinyMCE.getInstanceById(tinyMCE.settings['auto_focus']);1170 inst.selectNode(inst.getBody(), true, true);1171 inst.contentWindow.focus();1172 }, 10);1173 }1174 tinyMCE.executeCallback('oninit', '_oninit', 0);1175 }1176};1177TinyMCE.prototype.removeMCEControl = function(editor_id) {1178 var inst = tinyMCE.getInstanceById(editor_id);1179 if (inst) {1180 inst.switchSettings();1181 editor_id = inst.editorId;1182 var html = tinyMCE.getContent(editor_id);1183 // Remove editor instance from instances array1184 var tmpInstances = new Array();1185 for (var instanceName in tinyMCE.instances) {1186 var instance = tinyMCE.instances[instanceName];1187 if (!tinyMCE.isInstance(instance))1188 continue;1189 if (instanceName != editor_id)1190 tmpInstances[instanceName] = instance;1191 }1192 tinyMCE.instances = tmpInstances;1193 tinyMCE.selectedElement = null;1194 tinyMCE.selectedInstance = null;1195 // Remove element1196 var replaceElement = document.getElementById(editor_id + "_parent");1197 var oldTargetElement = inst.oldTargetElement;1198 var targetName = oldTargetElement.nodeName.toLowerCase();1199 if (targetName == "textarea" || targetName == "input") {1200 // Just show the old text area1201 replaceElement.parentNode.removeChild(replaceElement);1202 oldTargetElement.style.display = "inline";1203 oldTargetElement.value = html;1204 } else {1205 oldTargetElement.innerHTML = html;1206 replaceElement.parentNode.insertBefore(oldTargetElement, replaceElement);1207 replaceElement.parentNode.removeChild(replaceElement);1208 }1209 }1210};1211TinyMCE.prototype._cleanupElementName = function(element_name, element) {1212 var name = "";1213 element_name = element_name.toLowerCase();1214 // Never include body1215 if (element_name == "body")1216 return null;1217 // If verification mode1218 if (tinyMCE.cleanup_verify_html) {1219 // Check if invalid element1220 for (var i=0; i<tinyMCE.cleanup_invalidElements.length; i++) {1221 if (tinyMCE.cleanup_invalidElements[i] == element_name)1222 return null;1223 }1224 // Check if valid element1225 var validElement = false;1226 var elementAttribs = null;1227 for (var i=0; i<tinyMCE.cleanup_validElements.length && !elementAttribs; i++) {1228 for (var x=0, n=tinyMCE.cleanup_validElements[i][0].length; x<n; x++) {1229 var elmMatch = tinyMCE.cleanup_validElements[i][0][x];1230 if (elmMatch.charAt(0) == '+' || elmMatch.charAt(0) == '-')1231 elmMatch = elmMatch.substring(1);1232 // Handle wildcard/regexp1233 if (elmMatch.match(new RegExp('\\*|\\?|\\+', 'g')) != null) {1234 elmMatch = elmMatch.replace(new RegExp('\\?', 'g'), '(\\S?)');1235 elmMatch = elmMatch.replace(new RegExp('\\+', 'g'), '(\\S+)');1236 elmMatch = elmMatch.replace(new RegExp('\\*', 'g'), '(\\S*)');1237 elmMatch = "^" + elmMatch + "$";1238 if (element_name.match(new RegExp(elmMatch, 'g'))) {1239 elementAttribs = tinyMCE.cleanup_validElements[i];1240 validElement = true;1241 break;1242 }1243 }1244 // Handle non regexp1245 if (element_name == elmMatch) {1246 elementAttribs = tinyMCE.cleanup_validElements[i];1247 validElement = true;1248 element_name = elementAttribs[0][0];1249 break;1250 }1251 }1252 }1253 if (!validElement)1254 return null;1255 }1256 if (element_name.charAt(0) == '+' || element_name.charAt(0) == '-')1257 name = element_name.substring(1);1258 // Special Mozilla stuff1259 if (!tinyMCE.isMSIE) {1260 // Fix for bug #9584981261 if (name == "strong" && !tinyMCE.cleanup_on_save)1262 element_name = "b";1263 else if (name == "em" && !tinyMCE.cleanup_on_save)1264 element_name = "i";1265 }1266 var elmData = new Object();1267 elmData.element_name = element_name;1268 elmData.valid_attribs = elementAttribs;1269 return elmData;1270};1271/**1272 * This function moves CSS styles to/from attributes.1273 */1274TinyMCE.prototype._moveStyle = function(elm, style, attrib) {1275 if (tinyMCE.cleanup_inline_styles) {1276 var val = tinyMCE.getAttrib(elm, attrib);1277 if (val != '') {1278 val = '' + val;1279 switch (attrib) {1280 case "background":1281 val = "url('" + val + "')";1282 break;1283 case "bordercolor":1284 if (elm.style.borderStyle == '' || elm.style.borderStyle == 'none')1285 elm.style.borderStyle = 'solid';1286 break;1287 case "border":1288 case "width":1289 case "height":1290 if (attrib == "border" && elm.style.borderWidth > 0)1291 return;1292 if (val.indexOf('%') == -1)1293 val += 'px';1294 break;1295 case "vspace":1296 case "hspace":1297 elm.style.marginTop = val + "px";1298 elm.style.marginBottom = val + "px";1299 elm.removeAttribute(attrib);1300 return;1301 case "align":1302 if (elm.nodeName == "IMG") {1303 if (tinyMCE.isMSIE)1304 elm.style.styleFloat = val;1305 else1306 elm.style.cssFloat = val;1307 } else1308 elm.style.textAlign = val;1309 elm.removeAttribute(attrib);1310 return;1311 }1312 if (val != '') {1313 eval('elm.style.' + style + ' = val;');1314 elm.removeAttribute(attrib);1315 }1316 }1317 } else {1318 if (style == '')1319 return;1320 var val = eval('elm.style.' + style) == '' ? tinyMCE.getAttrib(elm, attrib) : eval('elm.style.' + style);1321 val = val == null ? '' : '' + val;1322 switch (attrib) {1323 // Always move background to style1324 case "background":1325 if (val.indexOf('url') == -1 && val != '')1326 val = "url('" + val + "');";1327 if (val != '') {1328 elm.style.backgroundImage = val;1329 elm.removeAttribute(attrib);1330 }1331 return;1332 case "border":1333 case "width":1334 case "height":1335 val = val.replace('px', '');1336 break;1337 case "align":1338 if (tinyMCE.getAttrib(elm, 'align') == '') {1339 if (elm.nodeName == "IMG") {1340 if (tinyMCE.isMSIE && elm.style.styleFloat != '') {1341 val = elm.style.styleFloat;1342 style = 'styleFloat';1343 } else if (tinyMCE.isGecko && elm.style.cssFloat != '') {1344 val = elm.style.cssFloat;1345 style = 'cssFloat';1346 }1347 }1348 }1349 break;1350 }1351 if (val != '') {1352 elm.removeAttribute(attrib);1353 elm.setAttribute(attrib, val);1354 eval('elm.style.' + style + ' = "";');1355 }1356 }1357};1358TinyMCE.prototype._cleanupAttribute = function(valid_attributes, element_name, attribute_node, element_node) {1359 var attribName = attribute_node.nodeName.toLowerCase();1360 var attribValue = attribute_node.nodeValue;1361 var attribMustBeValue = null;1362 var verified = false;1363 // Mozilla attibute, remove them1364 if (attribName.indexOf('moz_') != -1)1365 return null;1366 if (!tinyMCE.cleanup_on_save && (attribName == "mce_href" || attribName == "mce_src"))1367 return {name : attribName, value : attribValue};1368 // Verify attrib1369 if (tinyMCE.cleanup_verify_html && !verified) {1370 for (var i=1; i<valid_attributes.length; i++) {1371 var attribMatch = valid_attributes[i][0];1372 var re = null;1373 // Build regexp from wildcard1374 if (attribMatch.match(new RegExp('\\*|\\?|\\+', 'g')) != null) {1375 attribMatch = attribMatch.replace(new RegExp('\\?', 'g'), '(\\S?)');1376 attribMatch = attribMatch.replace(new RegExp('\\+', 'g'), '(\\S+)');1377 attribMatch = attribMatch.replace(new RegExp('\\*', 'g'), '(\\S*)');1378 attribMatch = "^" + attribMatch + "$";1379 re = new RegExp(attribMatch, 'g');1380 }1381 if ((re && attribName.match(re) != null) || attribName == attribMatch) {1382 verified = true;1383 attribMustBeValue = valid_attributes[i][3];1384 break;1385 }1386 }1387 if (!verified)1388 return false;1389 } else1390 verified = true;1391 // Treat some attribs diffrent1392 switch (attribName) {1393 case "size":1394 if (tinyMCE.isMSIE5 && element_name == "font")1395 attribValue = element_node.size;1396 break;1397 case "width":1398 case "height":1399 case "border":1400 // Old MSIE needs this1401 if (tinyMCE.isMSIE5)1402 attribValue = eval("element_node." + attribName);1403 break;1404 case "shape":1405 attribValue = attribValue.toLowerCase();1406 break;1407 case "cellspacing":1408 if (tinyMCE.isMSIE5)1409 attribValue = element_node.cellSpacing;1410 break;1411 case "cellpadding":1412 if (tinyMCE.isMSIE5)1413 attribValue = element_node.cellPadding;1414 break;1415 case "color":1416 if (tinyMCE.isMSIE5 && element_name == "font")1417 attribValue = element_node.color;1418 break;1419 case "class":1420 // Remove mceItem classes from anchors1421 if (tinyMCE.cleanup_on_save && attribValue.indexOf('mceItemAnchor') != -1)1422 attribValue = attribValue.replace(/mceItem[a-z0-9]+/gi, '');1423 if (element_name == "table" || element_name == "td" || element_name == "th") {1424 // Handle visual aid1425 if (tinyMCE.cleanup_visual_table_class != "")1426 attribValue = tinyMCE.getVisualAidClass(attribValue, !tinyMCE.cleanup_on_save);1427 }1428 if (!tinyMCE._verifyClass(element_node) || attribValue == "")1429 return null;1430 break;1431 case "onfocus":1432 case "onblur":1433 case "onclick":1434 case "ondblclick":1435 case "onmousedown":1436 case "onmouseup":1437 case "onmouseover":1438 case "onmousemove":1439 case "onmouseout":1440 case "onkeypress":1441 case "onkeydown":1442 case "onkeydown":1443 case "onkeyup":1444 attribValue = tinyMCE.cleanupEventStr("" + attribValue);1445 if (attribValue.indexOf('return false;') == 0)1446 attribValue = attribValue.substring(14);1447 break;1448 case "style":1449 attribValue = tinyMCE.serializeStyle(tinyMCE.parseStyle(tinyMCE.getAttrib(element_node, "style")));1450 break;1451 // Convert the URLs of these1452 case "href":1453 case "src":1454 case "longdesc":1455 attribValue = tinyMCE.getAttrib(element_node, attribName);1456 // Use mce_href instead1457 var href = tinyMCE.getAttrib(element_node, "mce_href");1458 if (attribName == "href" && href != "")1459 attribValue = href;1460 // Use mce_src instead1461 var src = tinyMCE.getAttrib(element_node, "mce_src");1462 if (attribName == "src" && src != "")1463 attribValue = src;1464 // Always use absolute URLs within TinyMCE1465 if (!tinyMCE.cleanup_on_save)1466 attribValue = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], attribValue);1467 else if (tinyMCE.getParam('convert_urls'))1468 attribValue = eval(tinyMCE.cleanup_urlconverter_callback + "(attribValue, element_node, tinyMCE.cleanup_on_save);");1469 break;1470 case "colspan":1471 case "rowspan":1472 // Not needed1473 if (attribValue == "1")1474 return null;1475 break;1476 // Skip these1477 case "_moz-userdefined":1478 case "editorid":1479 case "mce_href":1480 case "mce_src":1481 return null;1482 }1483 // Not the must be value1484 if (attribMustBeValue != null) {1485 var isCorrect = false;1486 for (var i=0; i<attribMustBeValue.length; i++) {1487 if (attribValue == attribMustBeValue[i]) {1488 isCorrect = true;1489 break;1490 }1491 }1492 if (!isCorrect)1493 return null;1494 }1495 var attrib = new Object();1496 attrib.name = attribName;1497 attrib.value = attribValue;1498 return attrib;1499};1500TinyMCE.prototype.clearArray = function(ar) {1501 // Since stupid people tend to extend core objects like1502 // Array with their own crap I needed to make functions that clean away1503 // this junk so the arrays get clean and nice as they should be1504 for (var key in ar)1505 ar[key] = null;1506};1507TinyMCE.prototype.isInstance = function(inst) {1508 return inst != null && typeof(inst) == "object" && inst.isTinyMCEControl;1509};1510TinyMCE.prototype.parseStyle = function(str) {1511 var ar = new Array();1512 if (str == null)1513 return ar;1514 var st = str.split(';');1515 tinyMCE.clearArray(ar);1516 for (var i=0; i<st.length; i++) {1517 if (st[i] == '')1518 continue;1519 var re = new RegExp('^\\s*([^:]*):\\s*(.*)\\s*$');1520 var pa = st[i].replace(re, '$1||$2').split('||');1521//tinyMCE.debug(str, pa[0] + "=" + pa[1], st[i].replace(re, '$1||$2'));1522 if (pa.length == 2)1523 ar[pa[0].toLowerCase()] = pa[1];1524 }1525 return ar;1526};1527TinyMCE.prototype.compressStyle = function(ar, pr, sf, res) {1528 var box = new Array();1529 box[0] = ar[pr + '-top' + sf];1530 box[1] = ar[pr + '-left' + sf];1531 box[2] = ar[pr + '-right' + sf];1532 box[3] = ar[pr + '-bottom' + sf];1533 for (var i=0; i<box.length; i++) {1534 if (box[i] == null)1535 return;1536 for (var a=0; a<box.length; a++) {1537 if (box[a] != box[i])1538 return;1539 }1540 }1541 // They are all the same1542 ar[res] = box[0];1543 ar[pr + '-top' + sf] = null;1544 ar[pr + '-left' + sf] = null;1545 ar[pr + '-right' + sf] = null;1546 ar[pr + '-bottom' + sf] = null;1547};1548TinyMCE.prototype.serializeStyle = function(ar) {1549 var str = "";1550 // Compress box1551 tinyMCE.compressStyle(ar, "border", "", "border");1552 tinyMCE.compressStyle(ar, "border", "-width", "border-width");1553 tinyMCE.compressStyle(ar, "border", "-color", "border-color");1554 for (var key in ar) {1555 var val = ar[key];1556 if (typeof(val) == 'function')1557 continue;1558 if (val != null && val != '') {1559 val = '' + val; // Force string1560 // Fix style URL1561 val = val.replace(new RegExp("url\\(\\'?([^\\']*)\\'?\\)", 'gi'), "url('$1')");1562 // Convert URL1563 if (val.indexOf('url(') != -1 && tinyMCE.getParam('convert_urls')) {1564 var m = new RegExp("url\\('(.*?)'\\)").exec(val);1565 if (m.length > 1)1566 val = "url('" + eval(tinyMCE.getParam('urlconverter_callback') + "(m[1], null, true);") + "')";1567 }1568 // Force HEX colors1569 if (tinyMCE.getParam("force_hex_style_colors"))1570 val = tinyMCE.convertRGBToHex(val, true);1571 if (val != "url('')")1572 str += key.toLowerCase() + ": " + val + "; ";1573 }1574 }1575 if (new RegExp('; $').test(str))1576 str = str.substring(0, str.length - 2);1577 return str;1578};1579TinyMCE.prototype.convertRGBToHex = function(s, k) {1580 if (s.toLowerCase().indexOf('rgb') != -1) {1581 var re = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");1582 var rgb = s.replace(re, "$1,$2,$3,$4,$5").split(',');1583 if (rgb.length == 5) {1584 r = parseInt(rgb[1]).toString(16);1585 g = parseInt(rgb[2]).toString(16);1586 b = parseInt(rgb[3]).toString(16);1587 r = r.length == 1 ? '0' + r : r;1588 g = g.length == 1 ? '0' + g : g;1589 b = b.length == 1 ? '0' + b : b;1590 s = "#" + r + g + b;1591 if (k)1592 s = rgb[0] + s + rgb[4];1593 }1594 }1595 return s;1596};1597TinyMCE.prototype.convertHexToRGB = function(s) {1598 if (s.indexOf('#') != -1) {1599 s = s.replace(new RegExp('[^0-9A-F]', 'gi'), '');1600 return "rgb(" + parseInt(s.substring(0, 2), 16) + "," + parseInt(s.substring(2, 4), 16) + "," + parseInt(s.substring(4, 6), 16) + ")";1601 }1602 return s;1603};1604TinyMCE.prototype._verifyClass = function(node) {1605 // Sometimes the class gets set to null, weird Gecko bug?1606 if (tinyMCE.isGecko) {1607 var className = node.getAttribute('class');1608 if (!className)1609 return false;1610 }1611 // Trim CSS class1612 if (tinyMCE.isMSIE)1613 var className = node.getAttribute('className');1614 if (tinyMCE.cleanup_verify_css_classes && tinyMCE.cleanup_on_save) {1615 var csses = tinyMCE.getCSSClasses();1616 nonDefinedCSS = true;1617 for (var c=0; c<csses.length; c++) {1618 if (csses[c] == className) {1619 nonDefinedCSS = false;1620 break;1621 }1622 }1623 if (nonDefinedCSS && className.indexOf('mce_') != 0) {1624 node.removeAttribute('className');1625 node.removeAttribute('class');1626 return false;1627 }1628 }1629 return true;1630};1631TinyMCE.prototype.cleanupNode = function(node) {1632 var output = "";1633 switch (node.nodeType) {1634 case 1: // Element1635 var elementData = tinyMCE._cleanupElementName(node.nodeName, node);1636 var elementName = elementData ? elementData.element_name : null;1637 var elementValidAttribs = elementData ? elementData.valid_attribs : null;1638 var elementAttribs = "";1639 var openTag = false, nonEmptyTag = false;1640 if (elementName != null && elementName.charAt(0) == '+') {1641 elementName = elementName.substring(1);1642 openTag = true;1643 }1644 if (elementName != null && elementName.charAt(0) == '-') {1645 elementName = elementName.substring(1);1646 nonEmptyTag = true;1647 }1648 // Checking DOM tree for MSIE weirdness!!1649 if (tinyMCE.isMSIE && tinyMCE.settings['fix_content_duplication']) {1650 var lookup = tinyMCE.cleanup_elementLookupTable;1651 for (var i=0; i<lookup.length; i++) {1652 // Found element reference else were, hmm?1653 if (lookup[i] == node)1654 return output;1655 }1656 // Add element to lookup table1657 lookup[lookup.length] = node;1658 }1659 // Element not valid (only render children)1660 if (!elementName) {1661 if (node.hasChildNodes()) {1662 for (var i=0; i<node.childNodes.length; i++)1663 output += this.cleanupNode(node.childNodes[i]);1664 }1665 return output;1666 }1667 if (tinyMCE.cleanup_on_save) {1668 if (node.nodeName == "A" && node.className == "mceItemAnchor") {1669 if (node.hasChildNodes()) {1670 for (var i=0; i<node.childNodes.length; i++)1671 output += this.cleanupNode(node.childNodes[i]);1672 }1673 return '<a name="' + this.convertStringToXML(node.getAttribute("name")) + '"></a>' + output;1674 }1675 }1676 // Remove deprecated attributes1677 var re = new RegExp("^(TABLE|TD|TR)$");1678 if (re.test(node.nodeName)) {1679 // Move attrib to style1680 if ((node.nodeName != "TABLE" || tinyMCE.cleanup_inline_styles) && (width = tinyMCE.getAttrib(node, "width")) != '') {1681 node.style.width = width.indexOf('%') != -1 ? width : width.replace(/[^0-9]/gi, '') + "px";1682 node.removeAttribute("width");1683 }1684 // Is table and not inline1685 if ((node.nodeName == "TABLE" && !tinyMCE.cleanup_inline_styles) && node.style.width != '') {1686 tinyMCE.setAttrib(node, "width", node.style.width.replace('px',''));1687 node.style.width = '';1688 }1689 // Move attrib to style1690 if ((height = tinyMCE.getAttrib(node, "height")) != '') {1691 height = "" + height; // Force string1692 node.style.height = height.indexOf('%') != -1 ? height : height.replace(/[^0-9]/gi, '') + "px";1693 node.removeAttribute("height");1694 }1695 }1696 // Handle inline/outline styles1697 if (tinyMCE.cleanup_inline_styles) {1698 var re = new RegExp("^(TABLE|TD|TR|IMG|HR)$");1699 if (re.test(node.nodeName) && tinyMCE.getAttrib(node, "class").indexOf('mceItem') == -1) {1700 tinyMCE._moveStyle(node, 'width', 'width');1701 tinyMCE._moveStyle(node, 'height', 'height');1702 tinyMCE._moveStyle(node, 'borderWidth', 'border');1703 tinyMCE._moveStyle(node, '', 'vspace');1704 tinyMCE._moveStyle(node, '', 'hspace');1705 tinyMCE._moveStyle(node, 'textAlign', 'align');1706 tinyMCE._moveStyle(node, 'backgroundColor', 'bgColor');1707 tinyMCE._moveStyle(node, 'borderColor', 'borderColor');1708 tinyMCE._moveStyle(node, 'backgroundImage', 'background');1709 // Refresh element in old MSIE1710 if (tinyMCE.isMSIE5)1711 node.outerHTML = node.outerHTML;1712 } else if (tinyMCE.isBlockElement(node))1713 tinyMCE._moveStyle(node, 'textAlign', 'align');1714 if (node.nodeName == "FONT")1715 tinyMCE._moveStyle(node, 'color', 'color');1716 }1717 // Set attrib data1718 if (elementValidAttribs) {1719 for (var a=1; a<elementValidAttribs.length; a++) {1720 var attribName, attribDefaultValue, attribForceValue, attribValue;1721 attribName = elementValidAttribs[a][0];1722 attribDefaultValue = elementValidAttribs[a][1];1723 attribForceValue = elementValidAttribs[a][2];1724 if (attribDefaultValue != null || attribForceValue != null) {1725 var attribValue = node.getAttribute(attribName);1726 if (node.getAttribute(attribName) == null || node.getAttribute(attribName) == "")1727 attribValue = attribDefaultValue;1728 attribValue = attribForceValue ? attribForceValue : attribValue;1729 // Is to generate id1730 if (attribValue == "{$uid}")1731 attribValue = "uid_" + (tinyMCE.cleanup_idCount++);1732 // Add visual aid class1733 if (attribName == "class")1734 attribValue = tinyMCE.getVisualAidClass(attribValue, tinyMCE.cleanup_on_save);1735 node.setAttribute(attribName, attribValue);1736 //alert(attribName + "=" + attribValue);1737 }1738 }1739 }1740 if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && elementName == "style")1741 return "<style>" + node.innerHTML + "</style>";1742 // Remove empty tables1743 if (elementName == "table" && !node.hasChildNodes())1744 return "";1745 // Handle element attributes1746 if (node.attributes.length > 0) {1747 var lastAttrib = "";1748 for (var i=0; i<node.attributes.length; i++) {1749 if (node.attributes[i].specified) {1750 // Is the attrib already processed (removed duplicate attributes in opera TD[align=left])1751 if (tinyMCE.isOpera) {1752 if (node.attributes[i].nodeName == lastAttrib)1753 continue;1754 lastAttrib = node.attributes[i].nodeName;1755 }1756 // tinyMCE.debug(node.nodeName, node.attributes[i].nodeName, node.attributes[i].nodeValue, node.innerHTML);1757 var attrib = tinyMCE._cleanupAttribute(elementValidAttribs, elementName, node.attributes[i], node);1758 if (attrib && attrib.value != "")1759 elementAttribs += " " + attrib.name + "=" + '"' + this.convertStringToXML("" + attrib.value) + '"';1760 }1761 }1762 }1763 // MSIE table summary fix (MSIE 5.5)1764 if (tinyMCE.isMSIE && elementName == "table" && node.getAttribute("summary") != null && elementAttribs.indexOf('summary') == -1) {1765 var summary = tinyMCE.getAttrib(node, 'summary');1766 if (summary != '')1767 elementAttribs += " summary=" + '"' + this.convertStringToXML(summary) + '"';1768 }1769 // Handle missing attributes in MSIE 5.51770 if (tinyMCE.isMSIE5 && /^(td|img|a)$/.test(elementName)) {1771 var ma = new Array("scope", "longdesc", "hreflang", "charset", "type");1772 for (var u=0; u<ma.length; u++) {1773 if (node.getAttribute(ma[u]) != null) {1774 var s = tinyMCE.getAttrib(node, ma[u]);1775 if (s != '')1776 elementAttribs += " " + ma[u] + "=" + '"' + this.convertStringToXML(s) + '"';1777 }1778 }1779 }1780 // MSIE form element issue1781 if (tinyMCE.isMSIE && elementName == "input") {1782 if (node.type) {1783 if (!elementAttribs.match(/ type=/g))1784 elementAttribs += " type=" + '"' + node.type + '"';1785 }1786 if (node.value) {1787 if (!elementAttribs.match(/ value=/g))1788 elementAttribs += " value=" + '"' + node.value + '"';1789 }1790 }1791 // Add nbsp to some elements1792 if ((elementName == "p" || elementName == "td") && (node.innerHTML == "" || node.innerHTML == "&nbsp;"))1793 return "<" + elementName + elementAttribs + ">" + this.convertStringToXML(String.fromCharCode(160)) + "</" + elementName + ">";1794 // Is MSIE script element1795 if (tinyMCE.isMSIE && elementName == "script")1796 return "<" + elementName + elementAttribs + ">" + node.text + "</" + elementName + ">";1797 // Clean up children1798 if (node.hasChildNodes()) {1799 // If not empty span1800 if (!(elementName == "span" && elementAttribs == "" && tinyMCE.getParam("trim_span_elements"))) {1801 // Force BR1802 if (elementName == "p" && tinyMCE.cleanup_force_br_newlines)1803 output += "<div" + elementAttribs + ">";1804 else1805 output += "<" + elementName + elementAttribs + ">";1806 }1807 for (var i=0; i<node.childNodes.length; i++)1808 output += this.cleanupNode(node.childNodes[i]);1809 // If not empty span1810 if (!(elementName == "span" && elementAttribs == "" && tinyMCE.getParam("trim_span_elements"))) {1811 // Force BR1812 if (elementName == "p" && tinyMCE.cleanup_force_br_newlines)1813 output += "</div><br />";1814 else1815 output += "</" + elementName + ">";1816 }1817 } else {1818 if (!nonEmptyTag) {1819 if (openTag)1820 output += "<" + elementName + elementAttribs + "></" + elementName + ">";1821 else1822 output += "<" + elementName + elementAttribs + " />";1823 }1824 }1825 return output;1826 case 3: // Text1827 // Do not convert script elements1828 if (node.parentNode.nodeName == "SCRIPT" || node.parentNode.nodeName == "NOSCRIPT" || node.parentNode.nodeName == "STYLE")1829 return node.nodeValue;1830 return this.convertStringToXML(node.nodeValue);1831 case 8: // Comment1832 return "<!--" + node.nodeValue + "-->";1833 default: // Unknown1834 return "[UNKNOWN NODETYPE " + node.nodeType + "]";1835 }1836};1837TinyMCE.prototype.convertStringToXML = function(html_data) {1838 var output = "";1839 for (var i=0; i<html_data.length; i++) {1840 var chr = html_data.charCodeAt(i);1841 // Numeric entities1842 if (tinyMCE.settings['entity_encoding'] == "numeric") {1843 if (chr > 127)1844 output += '&#' + chr + ";";1845 else1846 output += String.fromCharCode(chr);1847 continue;1848 }1849 // Raw entities1850 if (tinyMCE.settings['entity_encoding'] == "raw") {1851 output += String.fromCharCode(chr);1852 continue;1853 }1854 // Named entities1855 if (typeof(tinyMCE.settings['cleanup_entities']["c" + chr]) != 'undefined' && tinyMCE.settings['cleanup_entities']["c" + chr] != '')1856 output += '&' + tinyMCE.settings['cleanup_entities']["c" + chr] + ';';1857 else1858 output += '' + String.fromCharCode(chr);1859 }1860 return output;1861};1862TinyMCE.prototype._getCleanupElementName = function(chunk) {1863 var pos;1864 if (chunk.charAt(0) == '+')1865 chunk = chunk.substring(1);1866 if (chunk.charAt(0) == '-')1867 chunk = chunk.substring(1);1868 if ((pos = chunk.indexOf('/')) != -1)1869 chunk = chunk.substring(0, pos);1870 if ((pos = chunk.indexOf('[')) != -1)1871 chunk = chunk.substring(0, pos);1872 return chunk;1873};1874TinyMCE.prototype._initCleanup = function() {1875 // Parse valid elements and attributes1876 var validElements = tinyMCE.settings["valid_elements"];1877 validElements = validElements.split(',');1878 // Handle extended valid elements1879 var extendedValidElements = tinyMCE.settings["extended_valid_elements"];1880 extendedValidElements = extendedValidElements.split(',');1881 for (var i=0; i<extendedValidElements.length; i++) {1882 var elementName = this._getCleanupElementName(extendedValidElements[i]);1883 var skipAdd = false;1884 // Check if it's defined before, if so override that one1885 for (var x=0; x<validElements.length; x++) {1886 if (this._getCleanupElementName(validElements[x]) == elementName) {1887 validElements[x] = extendedValidElements[i];1888 skipAdd = true;1889 break;1890 }1891 }1892 if (!skipAdd)1893 validElements[validElements.length] = extendedValidElements[i];1894 }1895 for (var i=0; i<validElements.length; i++) {1896 var item = validElements[i];1897 item = item.replace('[','|');1898 item = item.replace(']','');1899 // Split and convert1900 var attribs = item.split('|');1901 for (var x=0; x<attribs.length; x++)1902 attribs[x] = attribs[x].toLowerCase();1903 // Handle change elements1904 attribs[0] = attribs[0].split('/');1905 // Handle default attribute values1906 for (var x=1; x<attribs.length; x++) {1907 var attribName = attribs[x];1908 var attribDefault = null;1909 var attribForce = null;1910 var attribMustBe = null;1911 // Default value1912 if ((pos = attribName.indexOf('=')) != -1) {1913 attribDefault = attribName.substring(pos+1);1914 attribName = attribName.substring(0, pos);1915 }1916 // Force check1917 if ((pos = attribName.indexOf(':')) != -1) {1918 attribForce = attribName.substring(pos+1);1919 attribName = attribName.substring(0, pos);1920 }1921 // Force check1922 if ((pos = attribName.indexOf('<')) != -1) {1923 attribMustBe = attribName.substring(pos+1).split('?');1924 attribName = attribName.substring(0, pos);1925 }1926 attribs[x] = new Array(attribName, attribDefault, attribForce, attribMustBe);1927 }1928 validElements[i] = attribs;1929 }1930 var invalidElements = tinyMCE.settings['invalid_elements'].split(',');1931 for (var i=0; i<invalidElements.length; i++)1932 invalidElements[i] = invalidElements[i].toLowerCase();1933 // Set these for performance1934 tinyMCE.settings['cleanup_validElements'] = validElements;1935 tinyMCE.settings['cleanup_invalidElements'] = invalidElements;1936};1937TinyMCE.prototype._cleanupHTML = function(inst, doc, config, element, visual, on_save) {1938 if (!tinyMCE.settings['cleanup']) {1939 tinyMCE.handleVisualAid(inst.getBody(), true, false, inst);1940 var html = element.innerHTML;1941 // Remove mce_href/mce_src1942 html = html.replace(new RegExp('(mce_href|mce_src)=".*?"', 'gi'), '');1943 html = html.replace(/\s+>/gi, '>');1944 return html;1945 }1946 if (on_save && tinyMCE.getParam("convert_fonts_to_spans"))1947 tinyMCE.convertFontsToSpans(doc);1948 // Call custom cleanup code1949 tinyMCE._customCleanup(inst, on_save ? "get_from_editor_dom" : "insert_to_editor_dom", doc.body);1950 // Move bgcolor to style1951 var n = doc.getElementsByTagName("font");1952 for (var i=0; i<n.length; i++) {1953 var c = "";1954 if ((c = tinyMCE.getAttrib(n[i], "bgcolor")) != "") {1955 n[i].style.backgroundColor = c;1956 tinyMCE.setAttrib(n[i], "bgcolor", "");1957 }1958 }1959 // Set these for performance1960 tinyMCE.cleanup_validElements = tinyMCE.settings['cleanup_validElements'];1961 tinyMCE.cleanup_invalidElements = tinyMCE.settings['cleanup_invalidElements'];1962 tinyMCE.cleanup_verify_html = tinyMCE.settings['verify_html'];1963 tinyMCE.cleanup_force_br_newlines = tinyMCE.settings['force_br_newlines'];1964 tinyMCE.cleanup_urlconverter_callback = tinyMCE.settings['urlconverter_callback'];1965 tinyMCE.cleanup_verify_css_classes = tinyMCE.settings['verify_css_classes'];1966 tinyMCE.cleanup_visual_table_class = tinyMCE.settings['visual_table_class'];1967 tinyMCE.cleanup_apply_source_formatting = tinyMCE.settings['apply_source_formatting'];1968 tinyMCE.cleanup_inline_styles = tinyMCE.settings['inline_styles'];1969 tinyMCE.cleanup_visual_aid = visual;1970 tinyMCE.cleanup_on_save = on_save;1971 tinyMCE.cleanup_idCount = 0;1972 tinyMCE.cleanup_elementLookupTable = new Array();1973 var startTime = new Date().getTime();1974 // Cleanup madness that breaks the editor in MSIE1975 if (tinyMCE.isMSIE) {1976 // Remove null ids from HR elements, results in runtime error1977 var nodes = element.getElementsByTagName("hr");1978 for (var i=0; i<nodes.length; i++) {1979 if (nodes[i].id == "null")1980 nodes[i].removeAttribute("id");1981 }1982 tinyMCE.setInnerHTML(element, tinyMCE.regexpReplace(element.innerHTML, '<p>[ \n\r]*<hr.*>[ \n\r]*</p>', '<hr />', 'gi'));1983 tinyMCE.setInnerHTML(element, tinyMCE.regexpReplace(element.innerHTML, '<!([^-(DOCTYPE)]* )|<!/[^-]*>', '', 'gi'));1984 }1985 var html = this.cleanupNode(element);1986 if (tinyMCE.settings['debug'])1987 tinyMCE.debug("Cleanup process executed in: " + (new Date().getTime()-startTime) + " ms.");1988 // Remove pesky HR paragraphs and other crap1989 html = tinyMCE.regexpReplace(html, '<p><hr /></p>', '<hr />');1990 html = tinyMCE.regexpReplace(html, '<p>&nbsp;</p><hr /><p>&nbsp;</p>', '<hr />');1991 html = tinyMCE.regexpReplace(html, '<td>\\s*<br />\\s*</td>', '<td>&nbsp;</td>');1992 html = tinyMCE.regexpReplace(html, '<p>\\s*<br />\\s*</p>', '<p>&nbsp;</p>');1993 html = tinyMCE.regexpReplace(html, '<p>\\s*&nbsp;\\s*<br />\\s*&nbsp;\\s*</p>', '<p>&nbsp;</p>');1994 html = tinyMCE.regexpReplace(html, '<p>\\s*&nbsp;\\s*<br />\\s*</p>', '<p>&nbsp;</p>');1995 html = tinyMCE.regexpReplace(html, '<p>\\s*<br />\\s*&nbsp;\\s*</p>', '<p>&nbsp;</p>');1996 // Remove empty anchors1997 html = html.replace(new RegExp('<a>(.*?)</a>', 'gi'), '$1');1998 // Remove some mozilla crap1999 if (!tinyMCE.isMSIE)2000 html = html.replace(new RegExp('<o:p _moz-userdefined="" />', 'g'), "");2001 if (tinyMCE.settings['remove_linebreaks'])2002 html = html.replace(new RegExp('\r|\n', 'g'), ' ');2003 if (tinyMCE.getParam('apply_source_formatting')) {2004 html = html.replace(new RegExp('<(p|div)([^>]*)>', 'g'), "\n<$1$2>\n");2005 html = html.replace(new RegExp('<\/(p|div)([^>]*)>', 'g'), "\n</$1$2>\n");2006 html = html.replace(new RegExp('<br />', 'g'), "<br />\n");2007 }2008 if (tinyMCE.settings['force_br_newlines']) {2009 var re = new RegExp('<p>&nbsp;</p>', 'g');2010 html = html.replace(re, "<br />");2011 }2012 if (tinyMCE.isGecko && tinyMCE.settings['remove_lt_gt']) {2013 // Remove weridness!2014 var re = new RegExp('&lt;&gt;', 'g');2015 html = html.replace(re, "");2016 }2017 // Call custom cleanup code2018 html = tinyMCE._customCleanup(inst, on_save ? "get_from_editor" : "insert_to_editor", html);2019 // Emtpy node, return empty2020 var chk = tinyMCE.regexpReplace(html, "[ \t\r\n]", "").toLowerCase();2021 if (chk == "<br/>" || chk == "<br>" || chk == "<p>&nbsp;</p>" || chk == "<p>&#160;</p>" || chk == "<p></p>")2022 html = "";2023 if (tinyMCE.settings["preformatted"])2024 return "<pre>" + html + "</pre>";2025 return html;2026};2027TinyMCE.prototype.insertLink = function(href, target, title, onclick, style_class) {2028 tinyMCE.execCommand('mceBeginUndoLevel');2029 if (this.selectedInstance && this.selectedElement && this.selectedElement.nodeName.toLowerCase() == "img") {2030 var doc = this.selectedInstance.getDoc();2031 var linkElement = tinyMCE.getParentElement(this.selectedElement, "a");2032 var newLink = false;2033 if (!linkElement) {2034 linkElement = doc.createElement("a");2035 newLink = true;2036 }2037 var mhref = href;2038 var thref = eval(tinyMCE.settings['urlconverter_callback'] + "(href, linkElement);");2039 mhref = tinyMCE.getParam('convert_urls') ? href : mhref;2040 tinyMCE.setAttrib(linkElement, 'href', thref);2041 tinyMCE.setAttrib(linkElement, 'mce_href', mhref);2042 tinyMCE.setAttrib(linkElement, 'target', target);2043 tinyMCE.setAttrib(linkElement, 'title', title);2044 tinyMCE.setAttrib(linkElement, 'onclick', onclick);2045 tinyMCE.setAttrib(linkElement, 'class', style_class);2046 if (newLink) {2047 linkElement.appendChild(this.selectedElement.cloneNode(true));2048 this.selectedElement.parentNode.replaceChild(linkElement, this.selectedElement);2049 }2050 return;2051 }2052 if (!this.linkElement && this.selectedInstance) {2053 if (tinyMCE.isSafari) {2054 tinyMCE.execCommand("mceInsertContent", false, '<a href="' + tinyMCE.uniqueURL + '">' + this.selectedInstance.getSelectedHTML() + '</a>');2055 } else2056 this.selectedInstance.contentDocument.execCommand("createlink", false, tinyMCE.uniqueURL);2057 tinyMCE.linkElement = this.getElementByAttributeValue(this.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);2058 var elementArray = this.getElementsByAttributeValue(this.selectedInstance.contentDocument.body, "a", "href", tinyMCE.uniqueURL);2059 for (var i=0; i<elementArray.length; i++) {2060 var mhref = href;2061 var thref = eval(tinyMCE.settings['urlconverter_callback'] + "(href, elementArray[i]);");2062 mhref = tinyMCE.getParam('convert_urls') ? href : mhref;2063 tinyMCE.setAttrib(elementArray[i], 'href', thref);2064 tinyMCE.setAttrib(elementArray[i], 'mce_href', mhref);2065 tinyMCE.setAttrib(elementArray[i], 'target', target);2066 tinyMCE.setAttrib(elementArray[i], 'title', title);2067 tinyMCE.setAttrib(elementArray[i], 'onclick', onclick);2068 tinyMCE.setAttrib(elementArray[i], 'class', style_class);2069 }2070 tinyMCE.linkElement = elementArray[0];2071 }2072 if (this.linkElement) {2073 var mhref = href;2074 href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, this.linkElement);");2075 mhref = tinyMCE.getParam('convert_urls') ? href : mhref;2076 tinyMCE.setAttrib(this.linkElement, 'href', href);2077 tinyMCE.setAttrib(this.linkElement, 'mce_href', mhref);2078 tinyMCE.setAttrib(this.linkElement, 'target', target);2079 tinyMCE.setAttrib(this.linkElement, 'title', title);2080 tinyMCE.setAttrib(this.linkElement, 'onclick', onclick);2081 tinyMCE.setAttrib(this.linkElement, 'class', style_class);2082 }2083 tinyMCE.execCommand('mceEndUndoLevel');2084};2085TinyMCE.prototype.insertImage = function(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout) {2086 tinyMCE.execCommand('mceBeginUndoLevel');2087 if (src == "")2088 return;2089 if (!this.imgElement && tinyMCE.isSafari) {2090 var html = "";2091 html += '<img src="' + src + '" alt="' + alt + '"';2092 html += ' border="' + border + '" hspace="' + hspace + '"';2093 html += ' vspace="' + vspace + '" width="' + width + '"';2094 html += ' height="' + height + '" align="' + align + '" title="' + title + '" onmouseover="' + onmouseover + '" onmouseout="' + onmouseout + '" />';2095 tinyMCE.execCommand("mceInsertContent", false, html);2096 } else {2097 if (!this.imgElement && this.selectedInstance) {2098 if (tinyMCE.isSafari)2099 tinyMCE.execCommand("mceInsertContent", false, '<img src="' + tinyMCE.uniqueURL + '" />');2100 else2101 this.selectedInstance.contentDocument.execCommand("insertimage", false, tinyMCE.uniqueURL);2102 tinyMCE.imgElement = this.getElementByAttributeValue(this.selectedInstance.contentDocument.body, "img", "src", tinyMCE.uniqueURL);2103 }2104 }2105 if (this.imgElement) {2106 var needsRepaint = false;2107 var msrc = src;2108 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, tinyMCE.imgElement);");2109 if (tinyMCE.getParam('convert_urls'))2110 msrc = src;2111 if (onmouseover && onmouseover != "")2112 onmouseover = "this.src='" + eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseover, tinyMCE.imgElement);") + "';";2113 if (onmouseout && onmouseout != "")2114 onmouseout = "this.src='" + eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseout, tinyMCE.imgElement);") + "';";2115 // Use alt as title if it's undefined2116 if (typeof(title) == "undefined")2117 title = alt;2118 if (width != this.imgElement.getAttribute("width") || height != this.imgElement.getAttribute("height") || align != this.imgElement.getAttribute("align"))2119 needsRepaint = true;2120 tinyMCE.setAttrib(this.imgElement, 'src', src);2121 tinyMCE.setAttrib(this.imgElement, 'mce_src', msrc);2122 tinyMCE.setAttrib(this.imgElement, 'alt', alt);2123 tinyMCE.setAttrib(this.imgElement, 'title', title);2124 tinyMCE.setAttrib(this.imgElement, 'align', align);2125 tinyMCE.setAttrib(this.imgElement, 'border', border, true);2126 tinyMCE.setAttrib(this.imgElement, 'hspace', hspace, true);2127 tinyMCE.setAttrib(this.imgElement, 'vspace', vspace, true);2128 tinyMCE.setAttrib(this.imgElement, 'width', width, true);2129 tinyMCE.setAttrib(this.imgElement, 'height', height, true);2130 tinyMCE.setAttrib(this.imgElement, 'onmouseover', onmouseover);2131 tinyMCE.setAttrib(this.imgElement, 'onmouseout', onmouseout);2132 // Fix for bug #989846 - Image resize bug2133 if (width && width != "")2134 this.imgElement.style.pixelWidth = width;2135 if (height && height != "")2136 this.imgElement.style.pixelHeight = height;2137 if (needsRepaint)2138 tinyMCE.selectedInstance.repaint();2139 }2140 tinyMCE.execCommand('mceEndUndoLevel');2141};2142TinyMCE.prototype.getElementByAttributeValue = function(node, element_name, attrib, value) {2143 var elements = this.getElementsByAttributeValue(node, element_name, attrib, value);2144 if (elements.length == 0)2145 return null;2146 return elements[0];2147};2148TinyMCE.prototype.getElementsByAttributeValue = function(node, element_name, attrib, value) {2149 var elements = new Array();2150 if (node && node.nodeName.toLowerCase() == element_name) {2151 if (node.getAttribute(attrib) && node.getAttribute(attrib).indexOf(value) != -1)2152 elements[elements.length] = node;2153 }2154 if (node && node.hasChildNodes()) {2155 for (var x=0, n=node.childNodes.length; x<n; x++) {2156 var childElements = this.getElementsByAttributeValue(node.childNodes[x], element_name, attrib, value);2157 for (var i=0, m=childElements.length; i<m; i++)2158 elements[elements.length] = childElements[i];2159 }2160 }2161 return elements;2162};2163TinyMCE.prototype.isBlockElement = function(node) {2164 return node != null && node.nodeType == 1 && this.blockRegExp.test(node.nodeName);2165};2166TinyMCE.prototype.getParentBlockElement = function(node) {2167 // Search up the tree for block element2168 while (node) {2169 if (this.blockRegExp.test(node.nodeName))2170 return node;2171 node = node.parentNode;2172 }2173 return null;2174};2175TinyMCE.prototype.getNodeTree = function(node, node_array, type, node_name) {2176 if (typeof(type) == "undefined" || node.nodeType == type && (typeof(node_name) == "undefined" || node.nodeName == node_name))2177 node_array[node_array.length] = node;2178 if (node.hasChildNodes()) {2179 for (var i=0; i<node.childNodes.length; i++)2180 tinyMCE.getNodeTree(node.childNodes[i], node_array, type, node_name);2181 }2182 return node_array;2183};2184TinyMCE.prototype.getParentElement = function(node, names, attrib_name, attrib_value) {2185 if (typeof(names) == "undefined") {2186 if (node.nodeType == 1)2187 return node;2188 // Find parent node that is a element2189 while ((node = node.parentNode) != null && node.nodeType != 1) ;2190 return node;2191 }2192 var namesAr = names.split(',');2193 if (node == null)2194 return null;2195 do {2196 for (var i=0; i<namesAr.length; i++) {2197 if (node.nodeName.toLowerCase() == namesAr[i].toLowerCase() || names == "*") {2198 if (typeof(attrib_name) == "undefined")2199 return node;2200 else if (node.getAttribute(attrib_name)) {2201 if (typeof(attrib_value) == "undefined") {2202 if (node.getAttribute(attrib_name) != "")2203 return node;2204 } else if (node.getAttribute(attrib_name) == attrib_value)2205 return node;2206 }2207 }2208 }2209 } while ((node = node.parentNode) != null);2210 return null;2211};2212TinyMCE.prototype.convertURL = function(url, node, on_save) {2213 var prot = document.location.protocol;2214 var host = document.location.hostname;2215 var port = document.location.port;2216 // Pass through file protocol2217 if (prot == "file:")2218 return url;2219 // Something is wrong, remove weirdness2220 url = tinyMCE.regexpReplace(url, '(http|https):///', '/');2221 // Mailto link or anchor (Pass through)2222 if (url.indexOf('mailto:') != -1 || url.indexOf('javascript:') != -1 || tinyMCE.regexpReplace(url,'[ \t\r\n\+]|%20','').charAt(0) == "#")2223 return url;2224 // Fix relative/Mozilla2225 if (!tinyMCE.isMSIE && !on_save && url.indexOf("://") == -1 && url.charAt(0) != '/')2226 return tinyMCE.settings['base_href'] + url;2227 // Handle relative URLs2228 if (on_save && tinyMCE.getParam('relative_urls')) {2229 var curl = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], url);2230 if (curl.charAt(0) == '/')2231 curl = tinyMCE.settings['document_base_prefix'] + curl;2232 var urlParts = tinyMCE.parseURL(curl);2233 var tmpUrlParts = tinyMCE.parseURL(tinyMCE.settings['document_base_url']);2234 // Force relative2235 if (urlParts['host'] == tmpUrlParts['host'] && (urlParts['port'] == tmpUrlParts['port']))2236 return tinyMCE.convertAbsoluteURLToRelativeURL(tinyMCE.settings['document_base_url'], curl);2237 }2238 // Handle absolute URLs2239 if (!tinyMCE.getParam('relative_urls')) {2240 var urlParts = tinyMCE.parseURL(url);2241 var baseUrlParts = tinyMCE.parseURL(tinyMCE.settings['base_href']);2242 // Force absolute URLs from relative URLs2243 url = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], url);2244 // If anchor and path is the same page2245 if (urlParts['anchor'] && urlParts['path'] == baseUrlParts['path'])2246 return "#" + urlParts['anchor'];2247 }2248 // Remove current domain2249 if (tinyMCE.getParam('remove_script_host')) {2250 var start = "", portPart = "";2251 if (port != "")2252 portPart = ":" + port;2253 start = prot + "//" + host + portPart + "/";2254 if (url.indexOf(start) == 0)2255 url = url.substring(start.length-1);2256 }2257 return url;2258};2259/**2260 * Parses a URL in to its diffrent components.2261 */2262TinyMCE.prototype.parseURL = function(url_str) {2263 var urlParts = new Array();2264 if (url_str) {2265 var pos, lastPos;2266 // Parse protocol part2267 pos = url_str.indexOf('://');2268 if (pos != -1) {2269 urlParts['protocol'] = url_str.substring(0, pos);2270 lastPos = pos + 3;2271 }2272 // Find port or path start2273 for (var i=lastPos; i<url_str.length; i++) {2274 var chr = url_str.charAt(i);2275 if (chr == ':')2276 break;2277 if (chr == '/')2278 break;2279 }2280 pos = i;2281 // Get host2282 urlParts['host'] = url_str.substring(lastPos, pos);2283 // Get port2284 urlParts['port'] = "";2285 lastPos = pos;2286 if (url_str.charAt(pos) == ':') {2287 pos = url_str.indexOf('/', lastPos);2288 urlParts['port'] = url_str.substring(lastPos+1, pos);2289 }2290 // Get path2291 lastPos = pos;2292 pos = url_str.indexOf('?', lastPos);2293 if (pos == -1)2294 pos = url_str.indexOf('#', lastPos);2295 if (pos == -1)2296 pos = url_str.length;2297 urlParts['path'] = url_str.substring(lastPos, pos);2298 // Get query2299 lastPos = pos;2300 if (url_str.charAt(pos) == '?') {2301 pos = url_str.indexOf('#');2302 pos = (pos == -1) ? url_str.length : pos;2303 urlParts['query'] = url_str.substring(lastPos+1, pos);2304 }2305 // Get anchor2306 lastPos = pos;2307 if (url_str.charAt(pos) == '#') {2308 pos = url_str.length;2309 urlParts['anchor'] = url_str.substring(lastPos+1, pos);2310 }2311 }2312 return urlParts;2313};2314TinyMCE.prototype.serializeURL = function(up) {2315 var url = "";2316 if (up['protocol'])2317 url += up['protocol'] + "://";2318 if (up['host'])2319 url += up['host'];2320 if (up['port'])2321 url += ":" + up['port'];2322 if (up['path'])2323 url += up['path'];2324 if (up['query'])2325 url += "?" + up['query'];2326 if (up['anchor'])2327 url += "#" + up['anchor'];2328 return url;2329};2330/**2331 * Converts an absolute path to relative path.2332 */2333TinyMCE.prototype.convertAbsoluteURLToRelativeURL = function(base_url, url_to_relative) {2334 var baseURL = this.parseURL(base_url);2335 var targetURL = this.parseURL(url_to_relative);2336 var strTok1;2337 var strTok2;2338 var breakPoint = 0;2339 var outPath = "";2340 var forceSlash = false;2341 if (targetURL.path == "")2342 targetURL.path = "/";2343 else2344 forceSlash = true;2345 // Crop away last path part2346 base_url = baseURL.path.substring(0, baseURL.path.lastIndexOf('/'));2347 strTok1 = base_url.split('/');2348 strTok2 = targetURL.path.split('/');2349 if (strTok1.length >= strTok2.length) {2350 for (var i=0; i<strTok1.length; i++) {2351 if (i >= strTok2.length || strTok1[i] != strTok2[i]) {2352 breakPoint = i + 1;2353 break;2354 }2355 }2356 }2357 if (strTok1.length < strTok2.length) {2358 for (var i=0; i<strTok2.length; i++) {2359 if (i >= strTok1.length || strTok1[i] != strTok2[i]) {2360 breakPoint = i + 1;2361 break;2362 }2363 }2364 }2365 if (breakPoint == 1)2366 return targetURL.path;2367 for (var i=0; i<(strTok1.length-(breakPoint-1)); i++)2368 outPath += "../";2369 for (var i=breakPoint-1; i<strTok2.length; i++) {2370 if (i != (breakPoint-1))2371 outPath += "/" + strTok2[i];2372 else2373 outPath += strTok2[i];2374 }2375 targetURL.protocol = null;2376 targetURL.host = null;2377 targetURL.port = null;2378 targetURL.path = outPath == "" && forceSlash ? "/" : outPath;2379 // Remove document prefix from local anchors2380 var fileName = baseURL.path;2381 var pos;2382 if ((pos = fileName.lastIndexOf('/')) != -1)2383 fileName = fileName.substring(pos + 1);2384 // Is local anchor2385 if (fileName == targetURL.path && targetURL.anchor != "")2386 targetURL.path = "";2387 return this.serializeURL(targetURL);2388};2389TinyMCE.prototype.convertRelativeToAbsoluteURL = function(base_url, relative_url) {2390 var baseURL = TinyMCE.prototype.parseURL(base_url);2391 var relURL = TinyMCE.prototype.parseURL(relative_url);2392 if (relative_url == "" || relative_url.charAt(0) == '/' || relative_url.indexOf('://') != -1 || relative_url.indexOf('mailto:') != -1 || relative_url.indexOf('javascript:') != -1)2393 return relative_url;2394 // Split parts2395 baseURLParts = baseURL['path'].split('/');2396 relURLParts = relURL['path'].split('/');2397 // Remove empty chunks2398 var newBaseURLParts = new Array();2399 for (var i=baseURLParts.length-1; i>=0; i--) {2400 if (baseURLParts[i].length == 0)2401 continue;2402 newBaseURLParts[newBaseURLParts.length] = baseURLParts[i];2403 }2404 baseURLParts = newBaseURLParts.reverse();2405 // Merge relURLParts chunks2406 var newRelURLParts = new Array();2407 var numBack = 0;2408 for (var i=relURLParts.length-1; i>=0; i--) {2409 if (relURLParts[i].length == 0 || relURLParts[i] == ".")2410 continue;2411 if (relURLParts[i] == '..') {2412 numBack++;2413 continue;2414 }2415 if (numBack > 0) {2416 numBack--;2417 continue;2418 }2419 newRelURLParts[newRelURLParts.length] = relURLParts[i];2420 }2421 relURLParts = newRelURLParts.reverse();2422 // Remove end from absolute path2423 var len = baseURLParts.length-numBack;2424 var absPath = (len <= 0 ? "" : "/") + baseURLParts.slice(0, len).join('/') + "/" + relURLParts.join('/');2425 var start = "", end = "";2426 // Build output URL2427 relURL.protocol = baseURL.protocol;2428 relURL.host = baseURL.host;2429 relURL.port = baseURL.port;2430 // Re-add trailing slash if it's removed2431 if (relURL.path.charAt(relURL.path.length-1) == "/")2432 absPath += "/";2433 relURL.path = absPath;2434 return TinyMCE.prototype.serializeURL(relURL);2435};2436TinyMCE.prototype.getParam = function(name, default_value, strip_whitespace, split_chr) {2437 var value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];2438 // Fix bool values2439 if (value == "true" || value == "false")2440 return (value == "true");2441 if (strip_whitespace)2442 value = tinyMCE.regexpReplace(value, "[ \t\r\n]", "");2443 if (typeof(split_chr) != "undefined" && split_chr != null) {2444 value = value.split(split_chr);2445 var outArray = new Array();2446 for (var i=0; i<value.length; i++) {2447 if (value[i] && value[i] != "")2448 outArray[outArray.length] = value[i];2449 }2450 value = outArray;2451 }2452 return value;2453};2454TinyMCE.prototype.getLang = function(name, default_value, parse_entities) {2455 var value = (typeof(tinyMCELang[name]) == "undefined") ? default_value : tinyMCELang[name];2456 if (parse_entities)2457 value = tinyMCE.entityDecode(value);2458 return value;2459};2460TinyMCE.prototype.entityDecode = function(s) {2461 var e = document.createElement("div");2462 e.innerHTML = s;2463 return e.innerHTML;2464};2465TinyMCE.prototype.addToLang = function(prefix, ar) {2466 for (var key in ar) {2467 if (typeof(ar[key]) == 'function')2468 continue;2469 tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = ar[key];2470 }2471// for (var key in ar)2472// tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = "|" + ar[key] + "|";2473};2474TinyMCE.prototype.replaceVar = function(replace_haystack, replace_var, replace_str) {2475 var re = new RegExp('{\\\$' + replace_var + '}', 'g');2476 return replace_haystack.replace(re, replace_str);2477};2478TinyMCE.prototype.replaceVars = function(replace_haystack, replace_vars) {2479 for (var key in replace_vars) {2480 var value = replace_vars[key];2481 if (typeof(value) == 'function')2482 continue;2483 replace_haystack = tinyMCE.replaceVar(replace_haystack, key, value);2484 }2485 return replace_haystack;2486};2487TinyMCE.prototype.triggerNodeChange = function(focus, setup_content) {2488 if (tinyMCE.settings['handleNodeChangeCallback']) {2489 if (tinyMCE.selectedInstance) {2490 var inst = tinyMCE.selectedInstance;2491 var editorId = inst.editorId;2492 var elm = (typeof(setup_content) != "undefined" && setup_content) ? tinyMCE.selectedElement : inst.getFocusElement();2493 var undoIndex = -1;2494 var undoLevels = -1;2495 var anySelection = false;2496 var selectedText = inst.getSelectedText();2497 inst.switchSettings();2498 if (tinyMCE.settings["auto_resize"]) {2499 var doc = inst.getDoc();2500 inst.iframeElement.style.width = doc.body.offsetWidth + "px";2501 inst.iframeElement.style.height = doc.body.offsetHeight + "px";2502 }2503 if (tinyMCE.selectedElement)2504 anySelection = (tinyMCE.selectedElement.nodeName.toLowerCase() == "img") || (selectedText && selectedText.length > 0);2505 if (tinyMCE.settings['custom_undo_redo']) {2506 undoIndex = inst.undoIndex;2507 undoLevels = inst.undoLevels.length;2508 }2509 tinyMCE.executeCallback('handleNodeChangeCallback', '_handleNodeChange', 0, editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content);2510 }2511 }2512 if (this.selectedInstance && (typeof(focus) == "undefined" || focus))2513 this.selectedInstance.contentWindow.focus();2514};2515TinyMCE.prototype._customCleanup = function(inst, type, content) {2516 // Call custom cleanup2517 var customCleanup = tinyMCE.settings['cleanup_callback'];2518 if (customCleanup != "" && eval("typeof(" + customCleanup + ")") != "undefined")2519 content = eval(customCleanup + "(type, content, inst);");2520 // Trigger plugin cleanups2521 var plugins = tinyMCE.getParam('plugins', '', true, ',');2522 for (var i=0; i<plugins.length; i++) {2523 if (eval("typeof(TinyMCE_" + plugins[i] + "_cleanup)") != "undefined")2524 content = eval("TinyMCE_" + plugins[i] + "_cleanup(type, content, inst);");2525 }2526 return content;2527};2528TinyMCE.prototype.getContent = function(editor_id) {2529 if (typeof(editor_id) != "undefined")2530 tinyMCE.selectedInstance = tinyMCE.getInstanceById(editor_id);2531 if (tinyMCE.selectedInstance) {2532 var old = this.selectedInstance.getBody().innerHTML;2533 var html = tinyMCE._cleanupHTML(this.selectedInstance, this.selectedInstance.getDoc(), tinyMCE.settings, this.selectedInstance.getBody(), false, true);2534 tinyMCE.setInnerHTML(this.selectedInstance.getBody(), old);2535 return html;2536 }2537 return null;2538};2539TinyMCE.prototype.setContent = function(html_content) {2540 if (tinyMCE.selectedInstance) {2541 tinyMCE.selectedInstance.execCommand('mceSetContent', false, html_content);2542 tinyMCE.selectedInstance.repaint();2543 }2544};2545TinyMCE.prototype.importThemeLanguagePack = function(name) {2546 if (typeof(name) == "undefined")2547 name = tinyMCE.settings['theme'];2548 tinyMCE.loadScript(tinyMCE.baseURL + '/themes/' + name + '/langs/' + tinyMCE.settings['language'] + '.js');2549};2550TinyMCE.prototype.importPluginLanguagePack = function(name, valid_languages) {2551 var lang = "en";2552 valid_languages = valid_languages.split(',');2553 for (var i=0; i<valid_languages.length; i++) {2554 if (tinyMCE.settings['language'] == valid_languages[i])2555 lang = tinyMCE.settings['language'];2556 }2557 tinyMCE.loadScript(tinyMCE.baseURL + '/plugins/' + name + '/langs/' + lang + '.js');2558};2559/**2560 * Adds themeurl, settings and lang to HTML code.2561 */2562TinyMCE.prototype.applyTemplate = function(html, args) {2563 html = tinyMCE.replaceVar(html, "themeurl", tinyMCE.themeURL);2564 if (typeof(args) != "undefined")2565 html = tinyMCE.replaceVars(html, args);2566 html = tinyMCE.replaceVars(html, tinyMCE.settings);2567 html = tinyMCE.replaceVars(html, tinyMCELang);2568 return html;2569};2570TinyMCE.prototype.openWindow = function(template, args) {2571 var html, width, height, x, y, resizable, scrollbars, url;2572 args['mce_template_file'] = template['file'];2573 args['mce_width'] = template['width'];2574 args['mce_height'] = template['height'];2575 tinyMCE.windowArgs = args;2576 html = template['html'];2577 if (!(width = parseInt(template['width'])))2578 width = 320;2579 if (!(height = parseInt(template['height'])))2580 height = 200;2581 // Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!!2582 if (tinyMCE.isMSIE)2583 height += 40;2584 else2585 height += 20;2586 x = parseInt(screen.width / 2.0) - (width / 2.0);2587 y = parseInt(screen.height / 2.0) - (height / 2.0);2588 resizable = (args && args['resizable']) ? args['resizable'] : "no";2589 scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no";2590 if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1)2591 url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file'];2592 else2593 url = template['file'];2594 // Replace all args as variables in URL2595 for (var name in args) {2596 if (typeof(args[name]) == 'function')2597 continue;2598 url = tinyMCE.replaceVar(url, name, escape(args[name]));2599 }2600 if (html) {2601 html = tinyMCE.replaceVar(html, "css", this.settings['popups_css']);2602 html = tinyMCE.applyTemplate(html, args);2603 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);2604 if (win == null) {2605 alert(tinyMCELang['lang_popup_blocked']);2606 return;2607 }2608 win.document.write(html);2609 win.document.close();2610 win.resizeTo(width, height);2611 win.focus();2612 } else {2613 if ((tinyMCE.isMSIE && !tinyMCE.isOpera) && resizable != 'yes' && tinyMCE.settings["dialog_type"] == "modal") {2614 var features = "resizable:" + resizable 2615 + ";scroll:"2616 + scrollbars + ";status:yes;center:yes;help:no;dialogWidth:"2617 + width + "px;dialogHeight:" + height + "px;";2618 window.showModalDialog(url, window, features);2619 } else {2620 var modal = (resizable == "yes") ? "no" : "yes";2621 if (tinyMCE.isGecko && tinyMCE.isMac)2622 modal = "no";2623 if (template['close_previous'] != "no")2624 try {tinyMCE.lastWindow.close();} catch (ex) {}2625 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);2626 if (win == null) {2627 alert(tinyMCELang['lang_popup_blocked']);2628 return;2629 }2630 if (template['close_previous'] != "no")2631 tinyMCE.lastWindow = win;2632 eval('try { win.resizeTo(width, height); } catch(e) { }');2633 // Make it bigger if statusbar is forced2634 if (tinyMCE.isGecko) {2635 if (win.document.defaultView.statusbar.visible)2636 win.resizeBy(0, tinyMCE.isMac ? 10 : 24);2637 }2638 win.focus();2639 }2640 }2641};2642TinyMCE.prototype.closeWindow = function(win) {2643 win.close();2644};2645TinyMCE.prototype.getVisualAidClass = function(class_name, state) {2646 var aidClass = tinyMCE.settings['visual_table_class'];2647 if (typeof(state) == "undefined")2648 state = tinyMCE.settings['visual'];2649 // Split2650 var classNames = new Array();2651 var ar = class_name.split(' ');2652 for (var i=0; i<ar.length; i++) {2653 if (ar[i] == aidClass)2654 ar[i] = "";2655 if (ar[i] != "")2656 classNames[classNames.length] = ar[i];2657 }2658 if (state)2659 classNames[classNames.length] = aidClass;2660 // Glue2661 var className = "";2662 for (var i=0; i<classNames.length; i++) {2663 if (i > 0)2664 className += " ";2665 className += classNames[i];2666 }2667 return className;2668};2669TinyMCE.prototype.handleVisualAid = function(el, deep, state, inst) {2670 if (!el)2671 return;2672 var tableElement = null;2673 switch (el.nodeName) {2674 case "TABLE":2675 var oldW = el.style.width;2676 var oldH = el.style.height;2677 var bo = tinyMCE.getAttrib(el, "border");2678 bo = bo == "" || bo == "0" ? true : false;2679 tinyMCE.setAttrib(el, "class", tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el, "class"), state && bo));2680 el.style.width = oldW;2681 el.style.height = oldH;2682 for (var y=0; y<el.rows.length; y++) {2683 for (var x=0; x<el.rows[y].cells.length; x++) {2684 var cn = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(el.rows[y].cells[x], "class"), state && bo);2685 tinyMCE.setAttrib(el.rows[y].cells[x], "class", cn);2686 }2687 }2688 break;2689 case "A":2690 var anchorName = tinyMCE.getAttrib(el, "name");2691 if (anchorName != '' && state) {2692 el.title = anchorName;2693 el.className = 'mceItemAnchor';2694 } else if (anchorName != '' && !state)2695 el.className = '';2696 break;2697 }2698 if (deep && el.hasChildNodes()) {2699 for (var i=0; i<el.childNodes.length; i++)2700 tinyMCE.handleVisualAid(el.childNodes[i], deep, state, inst);2701 }2702};2703TinyMCE.prototype.getAttrib = function(elm, name, default_value) {2704 if (typeof(default_value) == "undefined")2705 default_value = "";2706 // Not a element2707 if (!elm || elm.nodeType != 1)2708 return default_value;2709 var v = elm.getAttribute(name);2710 // Try className for class attrib2711 if (name == "class" && !v)2712 v = elm.className;2713 // Workaround for a issue with Firefox 1.5rc2+2714 if (tinyMCE.isGecko && name == "src" && elm.src != null && elm.src != "")2715 v = elm.src;2716 // Workaround for a issue with Firefox 1.5rc2+2717 if (tinyMCE.isGecko && name == "href" && elm.href != null && elm.href != "")2718 v = elm.href;2719 if (name == "style" && !tinyMCE.isOpera)2720 v = elm.style.cssText;2721 return (v && v != "") ? v : default_value;2722};2723TinyMCE.prototype.setAttrib = function(element, name, value, fix_value) {2724 if (typeof(value) == "number" && value != null)2725 value = "" + value;2726 if (fix_value) {2727 if (value == null)2728 value = "";2729 var re = new RegExp('[^0-9%]', 'g');2730 value = value.replace(re, '');2731 }2732 if (name == "style")2733 element.style.cssText = value;2734 if (name == "class")2735 element.className = value;2736 if (value != null && value != "" && value != -1)2737 element.setAttribute(name, value);2738 else2739 element.removeAttribute(name);2740};2741TinyMCE.prototype.setStyleAttrib = function(elm, name, value) {2742 eval('elm.style.' + name + '=value;');2743 // Style attrib deleted2744 if (tinyMCE.isMSIE && value == null || value == '') {2745 var str = tinyMCE.serializeStyle(tinyMCE.parseStyle(elm.style.cssText));2746 elm.style.cssText = str;2747 elm.setAttribute("style", str);2748 }2749};2750TinyMCE.prototype.convertSpansToFonts = function(doc) {2751 var sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');2752 var h = doc.body.innerHTML;2753 h = h.replace(/<span/gi, '<font');2754 h = h.replace(/<\/span/gi, '</font');2755 doc.body.innerHTML = h;2756 var s = doc.getElementsByTagName("font");2757 for (var i=0; i<s.length; i++) {2758 var size = tinyMCE.trim(s[i].style.fontSize).toLowerCase();2759 var fSize = 0;2760 for (var x=0; x<sizes.length; x++) {2761 if (sizes[x] == size) {2762 fSize = x + 1;2763 break;2764 }2765 }2766 if (fSize > 0) {2767 tinyMCE.setAttrib(s[i], 'size', fSize);2768 s[i].style.fontSize = '';2769 }2770 var fFace = s[i].style.fontFamily;2771 if (fFace != null && fFace != "") {2772 tinyMCE.setAttrib(s[i], 'face', fFace);2773 s[i].style.fontFamily = '';2774 }2775 var fColor = s[i].style.color;2776 if (fColor != null && fColor != "") {2777 tinyMCE.setAttrib(s[i], 'color', tinyMCE.convertRGBToHex(fColor));2778 s[i].style.color = '';2779 }2780 }2781};2782TinyMCE.prototype.convertFontsToSpans = function(doc) {2783 var sizes = tinyMCE.getParam('font_size_style_values').replace(/\s+/, '').split(',');2784 var h = doc.body.innerHTML;2785 h = h.replace(/<font/gi, '<span');2786 h = h.replace(/<\/font/gi, '</span');2787 doc.body.innerHTML = h;2788 var fsClasses = tinyMCE.getParam('font_size_classes');2789 if (fsClasses != '')2790 fsClasses = fsClasses.replace(/\s+/, '').split(',');2791 else2792 fsClasses = null;2793 var s = doc.getElementsByTagName("span");2794 for (var i=0; i<s.length; i++) {2795 var fSize, fFace, fColor;2796 fSize = tinyMCE.getAttrib(s[i], 'size');2797 fFace = tinyMCE.getAttrib(s[i], 'face');2798 fColor = tinyMCE.getAttrib(s[i], 'color');2799 if (fSize != "") {2800 fSize = parseInt(fSize);2801 if (fSize > 0 && fSize < 8) {2802 if (fsClasses != null)2803 tinyMCE.setAttrib(s[i], 'class', fsClasses[fSize-1]);2804 else2805 s[i].style.fontSize = sizes[fSize-1];2806 }2807 s[i].removeAttribute('size');2808 }2809 if (fFace != "") {2810 s[i].style.fontFamily = fFace;2811 s[i].removeAttribute('face');2812 }2813 if (fColor != "") {2814 s[i].style.color = fColor;2815 s[i].removeAttribute('color');2816 }2817 }2818};2819/*2820TinyMCE.prototype.applyClassesToFonts = function(doc, size) {2821 var f = doc.getElementsByTagName("font");2822 for (var i=0; i<f.length; i++) {2823 var s = tinyMCE.getAttrib(f[i], "size");2824 if (s != "")2825 tinyMCE.setAttrib(f[i], 'class', "mceItemFont" + s);2826 }2827 if (typeof(size) != "undefined") {2828 var css = "";2829 for (var x=0; x<doc.styleSheets.length; x++) {2830 for (var i=0; i<doc.styleSheets[x].rules.length; i++) {2831 if (doc.styleSheets[x].rules[i].selectorText == '#mceSpanFonts .mceItemFont' + size) {2832 css = doc.styleSheets[x].rules[i].style.cssText;2833 break;2834 }2835 }2836 if (css != "")2837 break;2838 }2839 if (doc.styleSheets[0].rules[0].selectorText == "FONT")2840 doc.styleSheets[0].removeRule(0);2841 doc.styleSheets[0].addRule("FONT", css, 0);2842 }2843};2844*/2845TinyMCE.prototype.setInnerHTML = function(e, h) {2846 if (tinyMCE.isMSIE && !tinyMCE.isOpera) {2847 e.innerHTML = tinyMCE.uniqueTag + h;2848 e.firstChild.removeNode(true);2849 } else {2850 h = this.fixGeckoBaseHREFBug(1, e, h);2851 e.innerHTML = h;2852 this.fixGeckoBaseHREFBug(2, e, h);2853 }2854};2855TinyMCE.prototype.fixGeckoBaseHREFBug = function(m, e, h) {2856 if (tinyMCE.isGecko) {2857 if (m == 1) {2858 h = h.replace(/\ssrc=/gi, " xsrc=");2859 h = h.replace(/\shref=/gi, " xhref=");2860 return h;2861 } else {2862 if (h.indexOf(' xsrc') != -1) {2863 var n = e.getElementsByTagName("img");2864 for (var i=0; i<n.length; i++) {2865 var xsrc = tinyMCE.getAttrib(n[i], "xsrc");2866 if (xsrc != "") {2867 n[i].src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xsrc);2868 n[i].removeAttribute("xsrc");2869 }2870 }2871 // Select image form fields2872 var n = e.getElementsByTagName("select");2873 for (var i=0; i<n.length; i++) {2874 var xsrc = tinyMCE.getAttrib(n[i], "xsrc");2875 if (xsrc != "") {2876 n[i].src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xsrc);2877 n[i].removeAttribute("xsrc");2878 }2879 }2880 // iframes2881 var n = e.getElementsByTagName("iframe");2882 for (var i=0; i<n.length; i++) {2883 var xsrc = tinyMCE.getAttrib(n[i], "xsrc");2884 if (xsrc != "") {2885 n[i].src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xsrc);2886 n[i].removeAttribute("xsrc");2887 }2888 }2889 }2890 if (h.indexOf(' xhref') != -1) {2891 var n = e.getElementsByTagName("a");2892 for (var i=0; i<n.length; i++) {2893 var xhref = tinyMCE.getAttrib(n[i], "xhref");2894 if (xhref != "") {2895 n[i].href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], xhref);2896 n[i].removeAttribute("xhref");2897 }2898 }2899 }2900 }2901 }2902 return h;2903};2904TinyMCE.prototype.getOuterHTML = function(e) {2905 if (tinyMCE.isMSIE)2906 return e.outerHTML;2907 var d = e.ownerDocument.createElement("body");2908 d.appendChild(e);2909 return d.innerHTML;2910};2911TinyMCE.prototype.setOuterHTML = function(doc, e, h) {2912 if (tinyMCE.isMSIE) {2913 e.outerHTML = h;2914 return;2915 }2916 var d = e.ownerDocument.createElement("body");2917 d.innerHTML = h;2918 e.parentNode.replaceChild(d.firstChild, e);2919};2920TinyMCE.prototype.insertAfter = function(nc, rc){2921 if (rc.nextSibling)2922 rc.parentNode.insertBefore(nc, rc.nextSibling);2923 else2924 rc.parentNode.appendChild(nc);2925};2926TinyMCE.prototype.cleanupAnchors = function(doc) {2927 var an = doc.getElementsByTagName("a");2928 for (var i=0; i<an.length; i++) {2929 if (tinyMCE.getAttrib(an[i], "name") != "") {2930 var cn = an[i].childNodes;2931 for (var x=cn.length-1; x>=0; x--)2932 tinyMCE.insertAfter(cn[x], an[i]);2933 }2934 }2935};2936TinyMCE.prototype._setHTML = function(doc, html_content) {2937 // Force closed anchors open2938 //html_content = html_content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');2939 html_content = tinyMCE.cleanupHTMLCode(html_content);2940 // Try innerHTML if it fails use pasteHTML in MSIE2941 try {2942 tinyMCE.setInnerHTML(doc.body, html_content);2943 } catch (e) {2944 if (this.isMSIE)2945 doc.body.createTextRange().pasteHTML(html_content);2946 }2947 // Content duplication bug fix2948 if (tinyMCE.isMSIE && tinyMCE.settings['fix_content_duplication']) {2949 // Remove P elements in P elements2950 var paras = doc.getElementsByTagName("P");2951 for (var i=0; i<paras.length; i++) {2952 var node = paras[i];2953 while ((node = node.parentNode) != null) {2954 if (node.nodeName == "P")2955 node.outerHTML = node.innerHTML;2956 }2957 }2958 // Content duplication bug fix (Seems to be word crap)2959 var html = doc.body.innerHTML;2960 if (html.indexOf('="mso') != -1) {2961 for (var i=0; i<doc.body.all.length; i++) {2962 var el = doc.body.all[i];2963 el.removeAttribute("className","",0);2964 el.removeAttribute("style","",0);2965 }2966 html = doc.body.innerHTML;2967 html = tinyMCE.regexpReplace(html, "<o:p><\/o:p>", "<br />");2968 html = tinyMCE.regexpReplace(html, "<o:p>&nbsp;<\/o:p>", "");2969 html = tinyMCE.regexpReplace(html, "<st1:.*?>", "");2970 html = tinyMCE.regexpReplace(html, "<p><\/p>", "");2971 html = tinyMCE.regexpReplace(html, "<p><\/p>\r\n<p><\/p>", "");2972 html = tinyMCE.regexpReplace(html, "<p>&nbsp;<\/p>", "<br />");2973 html = tinyMCE.regexpReplace(html, "<p>\s*(<p>\s*)?", "<p>");2974 html = tinyMCE.regexpReplace(html, "<\/p>\s*(<\/p>\s*)?", "</p>");2975 }2976 // Always set the htmlText output2977 tinyMCE.setInnerHTML(doc.body, html);2978 }2979 tinyMCE.cleanupAnchors(doc);2980 if (tinyMCE.getParam("convert_fonts_to_spans"))2981 tinyMCE.convertSpansToFonts(doc);2982};2983TinyMCE.prototype.getImageSrc = function(str) {2984 var pos = -1;2985 if (!str)2986 return "";2987 if ((pos = str.indexOf('this.src=')) != -1) {2988 var src = str.substring(pos + 10);2989 src = src.substring(0, src.indexOf('\''));2990 return src;2991 }2992 return "";2993};2994TinyMCE.prototype._getElementById = function(element_id) {2995 var elm = document.getElementById(element_id);2996 if (!elm) {2997 // Check for element in forms2998 for (var j=0; j<document.forms.length; j++) {2999 for (var k=0; k<document.forms[j].elements.length; k++) {3000 if (document.forms[j].elements[k].name == element_id) {3001 elm = document.forms[j].elements[k];3002 break;3003 }3004 }3005 }3006 }3007 return elm;3008};3009TinyMCE.prototype.getEditorId = function(form_element) {3010 var inst = this.getInstanceById(form_element);3011 if (!inst)3012 return null;3013 return inst.editorId;3014};3015TinyMCE.prototype.getInstanceById = function(editor_id) {3016 var inst = this.instances[editor_id];3017 if (!inst) {3018 for (var n in tinyMCE.instances) {3019 var instance = tinyMCE.instances[n];3020 if (!tinyMCE.isInstance(instance))3021 continue;3022 if (instance.formTargetElementId == editor_id) {3023 inst = instance;3024 break;3025 }3026 }3027 }3028 return inst;3029};3030TinyMCE.prototype.queryInstanceCommandValue = function(editor_id, command) {3031 var inst = tinyMCE.getInstanceById(editor_id);3032 if (inst)3033 return inst.queryCommandValue(command);3034 return false;3035};3036TinyMCE.prototype.queryInstanceCommandState = function(editor_id, command) {3037 var inst = tinyMCE.getInstanceById(editor_id);3038 if (inst)3039 return inst.queryCommandState(command);3040 return null;3041};3042TinyMCE.prototype.setWindowArg = function(name, value) {3043 this.windowArgs[name] = value;3044};3045TinyMCE.prototype.getWindowArg = function(name, default_value) {3046 return (typeof(this.windowArgs[name]) == "undefined") ? default_value : this.windowArgs[name];3047};3048TinyMCE.prototype.getCSSClasses = function(editor_id, doc) {3049 var output = new Array();3050 // Is cached, use that3051 if (typeof(tinyMCE.cssClasses) != "undefined")3052 return tinyMCE.cssClasses;3053 if (typeof(editor_id) == "undefined" && typeof(doc) == "undefined") {3054 var instance;3055 for (var instanceName in tinyMCE.instances) {3056 instance = tinyMCE.instances[instanceName];3057 if (!tinyMCE.isInstance(instance))3058 continue;3059 break;3060 }3061 doc = instance.getDoc();3062 }3063 if (typeof(doc) == "undefined") {3064 var instance = tinyMCE.getInstanceById(editor_id);3065 doc = instance.getDoc();3066 }3067 if (doc) {3068 var styles = tinyMCE.isMSIE ? doc.styleSheets : doc.styleSheets;3069 if (styles && styles.length > 0) {3070 for (var x=0; x<styles.length; x++) {3071 var csses = null;3072 // Just ignore any errors3073 eval("try {var csses = tinyMCE.isMSIE ? doc.styleSheets(" + x + ").rules : doc.styleSheets[" + x + "].cssRules;} catch(e) {}");3074 if (!csses)3075 return new Array();3076 for (var i=0; i<csses.length; i++) {3077 var selectorText = csses[i].selectorText;3078 // Can be multiple rules per selector3079 if (selectorText) {3080 var rules = selectorText.split(',');3081 for (var c=0; c<rules.length; c++) {3082 // Invalid rule3083 if (rules[c].indexOf(' ') != -1 || rules[c].indexOf(':') != -1 || rules[c].indexOf('mceItem') != -1)3084 continue;3085 if (rules[c] == "." + tinyMCE.settings['visual_table_class'])3086 continue;3087 // Is class rule3088 if (rules[c].indexOf('.') != -1) {3089 //alert(rules[c].substring(rules[c].indexOf('.')));3090 output[output.length] = rules[c].substring(rules[c].indexOf('.')+1);3091 }3092 }3093 }3094 }3095 }3096 }3097 }3098 // Cache em3099 if (output.length > 0)3100 tinyMCE.cssClasses = output;3101 return output;3102};3103TinyMCE.prototype.regexpReplace = function(in_str, reg_exp, replace_str, opts) {3104 if (in_str == null)3105 return in_str;3106 if (typeof(opts) == "undefined")3107 opts = 'g';3108 var re = new RegExp(reg_exp, opts);3109 return in_str.replace(re, replace_str);3110};3111TinyMCE.prototype.trim = function(str) {3112 return str.replace(/^\s*|\s*$/g, "");3113};3114TinyMCE.prototype.cleanupEventStr = function(str) {3115 str = "" + str;3116 str = str.replace('function anonymous()\n{\n', '');3117 str = str.replace('\n}', '');3118 str = str.replace(/^return true;/gi, ''); // Remove event blocker3119 return str;3120};3121TinyMCE.prototype.getAbsPosition = function(node) {3122 var pos = new Object();3123 pos.absLeft = pos.absTop = 0;3124 var parentNode = node;3125 while (parentNode) {3126 pos.absLeft += parentNode.offsetLeft;3127 pos.absTop += parentNode.offsetTop;3128 parentNode = parentNode.offsetParent;3129 }3130 return pos;3131};3132TinyMCE.prototype.getControlHTML = function(control_name) {3133 var themePlugins = tinyMCE.getParam('plugins', '', true, ',');3134 var templateFunction;3135 // Is it defined in any plugins3136 for (var i=themePlugins.length; i>=0; i--) {3137 templateFunction = 'TinyMCE_' + themePlugins[i] + "_getControlHTML";3138 if (eval("typeof(" + templateFunction + ")") != 'undefined') {3139 var html = eval(templateFunction + "('" + control_name + "');");3140 if (html != "")3141 return tinyMCE.replaceVar(html, "pluginurl", tinyMCE.baseURL + "/plugins/" + themePlugins[i]);3142 }3143 }3144 return eval('TinyMCE_' + tinyMCE.settings['theme'] + "_getControlHTML" + "('" + control_name + "');");3145};3146TinyMCE.prototype._themeExecCommand = function(editor_id, element, command, user_interface, value) {3147 var themePlugins = tinyMCE.getParam('plugins', '', true, ',');3148 var templateFunction;3149 // Is it defined in any plugins3150 for (var i=themePlugins.length; i>=0; i--) {3151 templateFunction = 'TinyMCE_' + themePlugins[i] + "_execCommand";3152 if (eval("typeof(" + templateFunction + ")") != 'undefined') {3153 if (eval(templateFunction + "(editor_id, element, command, user_interface, value);"))3154 return true;3155 }3156 }3157 // Theme funtion3158 templateFunction = 'TinyMCE_' + tinyMCE.settings['theme'] + "_execCommand";3159 if (eval("typeof(" + templateFunction + ")") != 'undefined')3160 return eval(templateFunction + "(editor_id, element, command, user_interface, value);");3161 // Pass to normal3162 return false;3163};3164TinyMCE.prototype._getThemeFunction = function(suffix, skip_plugins) {3165 if (skip_plugins)3166 return 'TinyMCE_' + tinyMCE.settings['theme'] + suffix;3167 var themePlugins = tinyMCE.getParam('plugins', '', true, ',');3168 var templateFunction;3169 // Is it defined in any plugins3170 for (var i=themePlugins.length; i>=0; i--) {3171 templateFunction = 'TinyMCE_' + themePlugins[i] + suffix;3172 if (eval("typeof(" + templateFunction + ")") != 'undefined')3173 return templateFunction;3174 }3175 return 'TinyMCE_' + tinyMCE.settings['theme'] + suffix;3176};3177TinyMCE.prototype.isFunc = function(func_name) {3178 if (func_name == null || func_name == "")3179 return false;3180 return eval("typeof(" + func_name + ")") != "undefined";3181};3182TinyMCE.prototype.exec = function(func_name, args) {3183 var str = func_name + '(';3184 // Add all arguments3185 for (var i=3; i<args.length; i++) {3186 str += 'args[' + i + ']';3187 if (i < args.length-1)3188 str += ',';3189 }3190 str += ');';3191 return eval(str);3192};3193TinyMCE.prototype.executeCallback = function(param, suffix, mode) {3194 switch (mode) {3195 // No chain3196 case 0:3197 var state = false;3198 // Execute each plugin callback3199 var plugins = tinyMCE.getParam('plugins', '', true, ',');3200 for (var i=0; i<plugins.length; i++) {3201 var func = "TinyMCE_" + plugins[i] + suffix;3202 if (tinyMCE.isFunc(func)) {3203 tinyMCE.exec(func, this.executeCallback.arguments);3204 state = true;3205 }3206 }3207 // Execute theme callback3208 var func = 'TinyMCE_' + tinyMCE.settings['theme'] + suffix;3209 if (tinyMCE.isFunc(func)) {3210 tinyMCE.exec(func, this.executeCallback.arguments);3211 state = true;3212 }3213 // Execute settings callback3214 var func = tinyMCE.getParam(param, '');3215 if (tinyMCE.isFunc(func)) {3216 tinyMCE.exec(func, this.executeCallback.arguments);3217 state = true;3218 }3219 return state;3220 // Chain mode3221 case 1:3222 // Execute each plugin callback3223 var plugins = tinyMCE.getParam('plugins', '', true, ',');3224 for (var i=0; i<plugins.length; i++) {3225 var func = "TinyMCE_" + plugins[i] + suffix;3226 if (tinyMCE.isFunc(func)) {3227 if (tinyMCE.exec(func, this.executeCallback.arguments))3228 return true;3229 }3230 }3231 // Execute theme callback3232 var func = 'TinyMCE_' + tinyMCE.settings['theme'] + suffix;3233 if (tinyMCE.isFunc(func)) {3234 if (tinyMCE.exec(func, this.executeCallback.arguments))3235 return true;3236 }3237 // Execute settings callback3238 var func = tinyMCE.getParam(param, '');3239 if (tinyMCE.isFunc(func)) {3240 if (tinyMCE.exec(func, this.executeCallback.arguments))3241 return true;3242 }3243 return false;3244 }3245};3246TinyMCE.prototype.debug = function() {3247 var msg = "";3248 var elm = document.getElementById("tinymce_debug");3249 if (!elm) {3250 var debugDiv = document.createElement("div");3251 debugDiv.setAttribute("className", "debugger");3252 debugDiv.className = "debugger";3253 debugDiv.innerHTML = '\3254 Debug output:\3255 <textarea id="tinymce_debug" style="width: 100%; height: 300px" wrap="nowrap"></textarea>';3256 document.body.appendChild(debugDiv);3257 elm = document.getElementById("tinymce_debug");3258 }3259 var args = this.debug.arguments;3260 for (var i=0; i<args.length; i++) {3261 msg += args[i];3262 if (i<args.length-1)3263 msg += ', ';3264 }3265 elm.value += msg + "\n";3266};3267// TinyMCEControl3268function TinyMCEControl(settings) {3269 // Undo levels3270 this.undoLevels = new Array();3271 this.undoIndex = 0;3272 this.typingUndoIndex = -1;3273 this.undoRedo = true;3274 this.isTinyMCEControl = true;3275 // Default settings3276 this.settings = settings;3277 this.settings['theme'] = tinyMCE.getParam("theme", "default");3278 this.settings['width'] = tinyMCE.getParam("width", -1);3279 this.settings['height'] = tinyMCE.getParam("height", -1);3280};3281TinyMCEControl.prototype.repaint = function() {3282 if (tinyMCE.isMSIE && !tinyMCE.isOpera)3283 return;3284 // Ugly mozilla hack to remove ghost resize handles3285 try {3286 this.getBody().style.display = 'none';3287 this.getDoc().execCommand('selectall', false, null);3288 this.getSel().collapseToStart();3289 this.getBody().style.display = 'block';3290 } catch (ex) {3291 // Could I care less!!3292 }3293};3294TinyMCEControl.prototype.switchSettings = function() {3295 if (tinyMCE.configs.length > 1 && tinyMCE.currentConfig != this.settings['index']) {3296 tinyMCE.settings = this.settings;3297 tinyMCE.currentConfig = this.settings['index'];3298 }3299};3300TinyMCEControl.prototype.convertAllRelativeURLs = function() {3301 var body = this.getBody();3302 // Convert all image URL:s to absolute URL3303 var elms = body.getElementsByTagName("img");3304 for (var i=0; i<elms.length; i++) {3305 var src = tinyMCE.getAttrib(elms[i], 'src');3306 var msrc = tinyMCE.getAttrib(elms[i], 'mce_src');3307 if (msrc != "")3308 src = msrc;3309 if (src != "") {3310 src = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], src);3311 elms[i].setAttribute("src", src);3312 }3313 }3314 // Convert all link URL:s to absolute URL3315 var elms = body.getElementsByTagName("a");3316 for (var i=0; i<elms.length; i++) {3317 var href = tinyMCE.getAttrib(elms[i], 'href');3318 var mhref = tinyMCE.getAttrib(elms[i], 'mce_href');3319 if (mhref != "")3320 href = mhref;3321 if (href && href != "") {3322 href = tinyMCE.convertRelativeToAbsoluteURL(tinyMCE.settings['base_href'], href);3323 elms[i].setAttribute("href", href);3324 }3325 }3326};3327TinyMCEControl.prototype.getSelectedHTML = function() {3328 if (tinyMCE.isSafari) {3329 // Not realy perfect!!3330 return this.getRng().toString();3331 }3332 var elm = document.createElement("body");3333 if (tinyMCE.isGecko)3334 elm.appendChild(this.getRng().cloneContents());3335 else3336 elm.innerHTML = this.getRng().htmlText;3337 return tinyMCE._cleanupHTML(this, this.contentDocument, this.settings, elm, this.visualAid);3338};3339TinyMCEControl.prototype.getBookmark = function() {3340 var rng = this.getRng();3341 if (tinyMCE.isSafari)3342 return rng;3343 if (tinyMCE.isMSIE)3344 return rng;3345 if (tinyMCE.isGecko)3346 return rng.cloneRange();3347 return null;3348};3349TinyMCEControl.prototype.moveToBookmark = function(bookmark) {3350 if (tinyMCE.isSafari) {3351 var sel = this.getSel().realSelection;3352 sel.setBaseAndExtent(bookmark.startContainer, bookmark.startOffset, bookmark.endContainer, bookmark.endOffset);3353 return true;3354 }3355 if (tinyMCE.isMSIE)3356 return bookmark.select();3357 if (tinyMCE.isGecko) {3358 var rng = this.getDoc().createRange();3359 var sel = this.getSel();3360 rng.setStart(bookmark.startContainer, bookmark.startOffset);3361 rng.setEnd(bookmark.endContainer, bookmark.endOffset);3362 sel.removeAllRanges();3363 sel.addRange(rng);3364 return true;3365 }3366 return false;3367};3368TinyMCEControl.prototype.getSelectedText = function() {3369 if (tinyMCE.isMSIE) {3370 var doc = this.getDoc();3371 if (doc.selection.type == "Text") {3372 var rng = doc.selection.createRange();3373 selectedText = rng.text;3374 } else3375 selectedText = '';3376 } else {3377 var sel = this.getSel();3378 if (sel && sel.toString)3379 selectedText = sel.toString();3380 else3381 selectedText = '';3382 }3383 return selectedText;3384};3385TinyMCEControl.prototype.selectNode = function(node, collapse, select_text_node, to_start) {3386 if (!node)3387 return;3388 if (typeof(collapse) == "undefined")3389 collapse = true;3390 if (typeof(select_text_node) == "undefined")3391 select_text_node = false;3392 if (typeof(to_start) == "undefined")3393 to_start = true;3394 if (tinyMCE.isMSIE) {3395 var rng = this.getBody().createTextRange();3396 try {3397 rng.moveToElementText(node);3398 if (collapse)3399 rng.collapse(to_start);3400 rng.select();3401 } catch (e) {3402 // Throws illigal agrument in MSIE some times3403 }3404 } else {3405 var sel = this.getSel();3406 if (!sel)3407 return;3408 if (tinyMCE.isSafari) {3409 sel.realSelection.setBaseAndExtent(node, 0, node, node.innerText.length);3410 if (collapse) {3411 if (to_start)3412 sel.realSelection.collapseToStart();3413 else3414 sel.realSelection.collapseToEnd();3415 }3416 this.scrollToNode(node);3417 return;3418 }3419 var rng = this.getDoc().createRange();3420 if (select_text_node) {3421 // Find first textnode in tree3422 var nodes = tinyMCE.getNodeTree(node, new Array(), 3);3423 if (nodes.length > 0)3424 rng.selectNodeContents(nodes[0]);3425 else3426 rng.selectNodeContents(node);3427 } else3428 rng.selectNode(node);3429 if (collapse) {3430 // Special treatment of textnode collapse3431 if (!to_start && node.nodeType == 3) {3432 rng.setStart(node, node.nodeValue.length);3433 rng.setEnd(node, node.nodeValue.length);3434 } else3435 rng.collapse(to_start);3436 }3437 sel.removeAllRanges();3438 sel.addRange(rng);3439 }3440 this.scrollToNode(node);3441 // Set selected element3442 tinyMCE.selectedElement = null;3443 if (node.nodeType == 1)3444 tinyMCE.selectedElement = node;3445};3446TinyMCEControl.prototype.scrollToNode = function(node) {3447 // Scroll to node position3448 var pos = tinyMCE.getAbsPosition(node);3449 var doc = this.getDoc();3450 var scrollX = doc.body.scrollLeft + doc.documentElement.scrollLeft;3451 var scrollY = doc.body.scrollTop + doc.documentElement.scrollTop;3452 var height = tinyMCE.isMSIE ? document.getElementById(this.editorId).style.pixelHeight : this.targetElement.clientHeight;3453 // Only scroll if out of visible area3454 if (!tinyMCE.settings['auto_resize'] && !(pos.absTop > scrollY && pos.absTop < (scrollY - 25 + height)))3455 this.contentWindow.scrollTo(pos.absLeft, pos.absTop - height + 25); 3456};3457TinyMCEControl.prototype.getBody = function() {3458 return this.getDoc().body;3459};3460TinyMCEControl.prototype.getDoc = function() {3461 return this.contentWindow.document;3462};3463TinyMCEControl.prototype.getWin = function() {3464 return this.contentWindow;3465};3466TinyMCEControl.prototype.getSel = function() {3467 if (tinyMCE.isMSIE && !tinyMCE.isOpera)3468 return this.getDoc().selection;3469 var sel = this.contentWindow.getSelection();3470 // Fake getRangeAt3471 if (tinyMCE.isSafari && !sel.getRangeAt) {3472 var newSel = new Object();3473 var doc = this.getDoc();3474 function getRangeAt(idx) {3475 var rng = new Object();3476 rng.startContainer = this.focusNode;3477 rng.endContainer = this.anchorNode;3478 rng.commonAncestorContainer = this.focusNode;3479 rng.createContextualFragment = function (html) {3480 // Seems to be a tag3481 if (html.charAt(0) == '<') {3482 var elm = doc.createElement("div");3483 elm.innerHTML = html;3484 return elm.firstChild;3485 }3486 return doc.createTextNode("UNSUPPORTED, DUE TO LIMITATIONS IN SAFARI!");3487 };3488 rng.deleteContents = function () {3489 doc.execCommand("Delete", false, "");3490 };3491 return rng;3492 }3493 // Patch selection3494 newSel.focusNode = sel.baseNode;3495 newSel.focusOffset = sel.baseOffset;3496 newSel.anchorNode = sel.extentNode;3497 newSel.anchorOffset = sel.extentOffset;3498 newSel.getRangeAt = getRangeAt;3499 newSel.text = "" + sel;3500 newSel.realSelection = sel;3501 newSel.toString = function () {return this.text;};3502 return newSel;3503 }3504 return sel;3505};3506TinyMCEControl.prototype.getRng = function() {3507 var sel = this.getSel();3508 if (sel == null)3509 return null;3510 if (tinyMCE.isMSIE && !tinyMCE.isOpera)3511 return sel.createRange();3512 if (tinyMCE.isSafari) {3513 var rng = this.getDoc().createRange();3514 var sel = this.getSel().realSelection;3515 rng.setStart(sel.baseNode, sel.baseOffset);3516 rng.setEnd(sel.extentNode, sel.extentOffset);3517 return rng;3518 }3519 return this.getSel().getRangeAt(0);3520};3521TinyMCEControl.prototype._insertPara = function(e) {3522 function isEmpty(para) {3523 function isEmptyHTML(html) {3524 return html.replace(new RegExp('[ \t\r\n]+', 'g'), '').toLowerCase() == "";3525 }3526 // Check for images3527 if (para.getElementsByTagName("img").length > 0)3528 return false;3529 // Check for tables3530 if (para.getElementsByTagName("table").length > 0)3531 return false;3532 // Check for HRs3533 if (para.getElementsByTagName("hr").length > 0)3534 return false;3535 // Check all textnodes3536 var nodes = tinyMCE.getNodeTree(para, new Array(), 3);3537 for (var i=0; i<nodes.length; i++) {3538 if (!isEmptyHTML(nodes[i].nodeValue))3539 return false;3540 }3541 // No images, no tables, no hrs, no text content then it's empty3542 return true;3543 }3544 var doc = this.getDoc();3545 var sel = this.getSel();3546 var win = this.contentWindow;3547 var rng = sel.getRangeAt(0);3548 var body = doc.body;3549 var rootElm = doc.documentElement;3550 var self = this;3551 var blockName = "P";3552// tinyMCE.debug(body.innerHTML);3553// debug(e.target, sel.anchorNode.nodeName, sel.focusNode.nodeName, rng.startContainer, rng.endContainer, rng.commonAncestorContainer, sel.anchorOffset, sel.focusOffset, rng.toString());3554 // Setup before range3555 var rngBefore = doc.createRange();3556 rngBefore.setStart(sel.anchorNode, sel.anchorOffset);3557 rngBefore.collapse(true);3558 // Setup after range3559 var rngAfter = doc.createRange();3560 rngAfter.setStart(sel.focusNode, sel.focusOffset);3561 rngAfter.collapse(true);3562 // Setup start/end points3563 var direct = rngBefore.compareBoundaryPoints(rngBefore.START_TO_END, rngAfter) < 0;3564 var startNode = direct ? sel.anchorNode : sel.focusNode;3565 var startOffset = direct ? sel.anchorOffset : sel.focusOffset;3566 var endNode = direct ? sel.focusNode : sel.anchorNode;3567 var endOffset = direct ? sel.focusOffset : sel.anchorOffset;3568 startNode = startNode.nodeName == "BODY" ? startNode.firstChild : startNode;3569 endNode = endNode.nodeName == "BODY" ? endNode.firstChild : endNode;3570 // tinyMCE.debug(startNode, endNode);3571 // Get block elements3572 var startBlock = tinyMCE.getParentBlockElement(startNode);3573 var endBlock = tinyMCE.getParentBlockElement(endNode);3574 // Use current block name3575 if (startBlock != null) {3576 blockName = startBlock.nodeName;3577 // Use P instead3578 if (blockName == "TD" || blockName == "TABLE" || (blockName == "DIV" && new RegExp('left|right', 'gi').test(startBlock.style.cssFloat)))3579 blockName = "P";3580 }3581 // Within a list use normal behaviour3582 if (tinyMCE.getParentElement(startBlock, "OL,UL") != null)3583 return false;3584 // Within a table create new paragraphs3585 if ((startBlock != null && startBlock.nodeName == "TABLE") || (endBlock != null && endBlock.nodeName == "TABLE"))3586 startBlock = endBlock = null;3587 // Setup new paragraphs3588 var paraBefore = (startBlock != null && startBlock.nodeName == blockName) ? startBlock.cloneNode(false) : doc.createElement(blockName);3589 var paraAfter = (endBlock != null && endBlock.nodeName == blockName) ? endBlock.cloneNode(false) : doc.createElement(blockName);3590 // Is header, then force paragraph under3591 if (/^(H[1-6])$/.test(blockName))3592 paraAfter = doc.createElement("p");3593 // Setup chop nodes3594 var startChop = startNode;3595 var endChop = endNode;3596 // Get startChop node3597 node = startChop;3598 do {3599 if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))3600 break;3601 startChop = node;3602 } while ((node = node.previousSibling ? node.previousSibling : node.parentNode));3603 // Get endChop node3604 node = endChop;3605 do {3606 if (node == body || node.nodeType == 9 || tinyMCE.isBlockElement(node))3607 break;3608 endChop = node;3609 } while ((node = node.nextSibling ? node.nextSibling : node.parentNode));3610 // Fix when only a image is within the TD3611 if (startChop.nodeName == "TD")3612 startChop = startChop.firstChild;3613 if (endChop.nodeName == "TD")3614 endChop = endChop.lastChild;3615 // If not in a block element3616 if (startBlock == null) {3617 // Delete selection3618 rng.deleteContents();3619 sel.removeAllRanges();3620 if (startChop != rootElm && endChop != rootElm) {3621 // Insert paragraph before3622 rngBefore = rng.cloneRange();3623 if (startChop == body)3624 rngBefore.setStart(startChop, 0);3625 else3626 rngBefore.setStartBefore(startChop);3627 paraBefore.appendChild(rngBefore.cloneContents());3628 // Insert paragraph after3629 if (endChop.parentNode.nodeName == blockName)3630 endChop = endChop.parentNode;3631 // If not after image3632 //if (rng.startContainer.nodeName != "BODY" && rng.endContainer.nodeName != "BODY")3633 rng.setEndAfter(endChop);3634 if (endChop.nodeName != "#text" && endChop.nodeName != "BODY")3635 rngBefore.setEndAfter(endChop);3636 var contents = rng.cloneContents();3637 if (contents.firstChild && (contents.firstChild.nodeName == blockName || contents.firstChild.nodeName == "BODY"))3638 paraAfter.innerHTML = contents.firstChild.innerHTML;3639 else3640 paraAfter.appendChild(contents);3641 // Check if it's a empty paragraph3642 if (isEmpty(paraBefore))3643 paraBefore.innerHTML = "&nbsp;";3644 // Check if it's a empty paragraph3645 if (isEmpty(paraAfter))3646 paraAfter.innerHTML = "&nbsp;";3647 // Delete old contents3648 rng.deleteContents();3649 rngAfter.deleteContents();3650 rngBefore.deleteContents();3651 // Insert new paragraphs3652 paraAfter.normalize();3653 rngBefore.insertNode(paraAfter);3654 paraBefore.normalize();3655 rngBefore.insertNode(paraBefore);3656 // tinyMCE.debug("1: ", paraBefore.innerHTML, paraAfter.innerHTML);3657 } else {3658 body.innerHTML = "<" + blockName + ">&nbsp;</" + blockName + "><" + blockName + ">&nbsp;</" + blockName + ">";3659 paraAfter = body.childNodes[1];3660 }3661 this.selectNode(paraAfter, true, true);3662 return true;3663 }3664 // Place first part within new paragraph3665 if (startChop.nodeName == blockName)3666 rngBefore.setStart(startChop, 0);3667 else3668 rngBefore.setStartBefore(startChop);3669 rngBefore.setEnd(startNode, startOffset);3670 paraBefore.appendChild(rngBefore.cloneContents());3671 // Place secound part within new paragraph3672 rngAfter.setEndAfter(endChop);3673 rngAfter.setStart(endNode, endOffset);3674 var contents = rngAfter.cloneContents();3675 if (contents.firstChild && contents.firstChild.nodeName == blockName) {3676/* var nodes = contents.firstChild.childNodes;3677 for (var i=0; i<nodes.length; i++) {3678 //tinyMCE.debug(nodes[i].nodeName);3679 if (nodes[i].nodeName != "BODY")3680 paraAfter.appendChild(nodes[i]);3681 }3682*/3683 paraAfter.innerHTML = contents.firstChild.innerHTML;3684 } else3685 paraAfter.appendChild(contents);3686 // Check if it's a empty paragraph3687 if (isEmpty(paraBefore))3688 paraBefore.innerHTML = "&nbsp;";3689 // Check if it's a empty paragraph3690 if (isEmpty(paraAfter))3691 paraAfter.innerHTML = "&nbsp;";3692 // Create a range around everything3693 var rng = doc.createRange();3694 if (!startChop.previousSibling && startChop.parentNode.nodeName.toUpperCase() == blockName) {3695 rng.setStartBefore(startChop.parentNode);3696 } else {3697 if (rngBefore.startContainer.nodeName.toUpperCase() == blockName && rngBefore.startOffset == 0)3698 rng.setStartBefore(rngBefore.startContainer);3699 else3700 rng.setStart(rngBefore.startContainer, rngBefore.startOffset);3701 }3702 if (!endChop.nextSibling && endChop.parentNode.nodeName.toUpperCase() == blockName)3703 rng.setEndAfter(endChop.parentNode);3704 else3705 rng.setEnd(rngAfter.endContainer, rngAfter.endOffset);3706 // Delete all contents and insert new paragraphs3707 rng.deleteContents();3708 rng.insertNode(paraAfter);3709 rng.insertNode(paraBefore);3710 //tinyMCE.debug("2", paraBefore.innerHTML, paraAfter.innerHTML);3711 // Normalize3712 paraAfter.normalize();3713 paraBefore.normalize();3714 this.selectNode(paraAfter, true, true);3715 return true;3716};3717TinyMCEControl.prototype._handleBackSpace = function(evt_type) {3718 var doc = this.getDoc();3719 var sel = this.getSel();3720 if (sel == null)3721 return false;3722 var rng = sel.getRangeAt(0);3723 var node = rng.startContainer;3724 var elm = node.nodeType == 3 ? node.parentNode : node;3725 if (node == null)3726 return;3727 // Empty node, wrap contents in paragraph3728 if (elm && elm.nodeName == "") {3729 var para = doc.createElement("p");3730 while (elm.firstChild)3731 para.appendChild(elm.firstChild);3732 elm.parentNode.insertBefore(para, elm);3733 elm.parentNode.removeChild(elm);3734 var rng = rng.cloneRange();3735 rng.setStartBefore(node.nextSibling);3736 rng.setEndAfter(node.nextSibling);3737 rng.extractContents();3738 this.selectNode(node.nextSibling, true, true);3739 }3740 // Remove empty paragraphs3741 var para = tinyMCE.getParentBlockElement(node);3742 if (para != null && para.nodeName.toLowerCase() == 'p' && evt_type == "keypress") {3743 var htm = para.innerHTML;3744 var block = tinyMCE.getParentBlockElement(node);3745 // Empty node, we do the killing!!3746 if (htm == "" || htm == "&nbsp;" || block.nodeName.toLowerCase() == "li") {3747 var prevElm = para.previousSibling;3748 while (prevElm != null && prevElm.nodeType != 1)3749 prevElm = prevElm.previousSibling;3750 if (prevElm == null)3751 return false;3752 // Get previous elements last text node3753 var nodes = tinyMCE.getNodeTree(prevElm, new Array(), 3);3754 var lastTextNode = nodes.length == 0 ? null : nodes[nodes.length-1];3755 // Select the last text node and move curstor to end3756 if (lastTextNode != null)3757 this.selectNode(lastTextNode, true, false, false);3758 // Remove the empty paragrapsh3759 para.parentNode.removeChild(para);3760 //debug("within p element" + para.innerHTML);3761 //showHTML(this.getBody().innerHTML);3762 return true;3763 }3764 }3765 // Remove BR elements3766/* while (node != null && (node = node.nextSibling) != null) {3767 if (node.nodeName.toLowerCase() == 'br')3768 node.parentNode.removeChild(node);3769 else if (node.nodeType == 1) // Break at other element3770 break;3771 }*/3772 //showHTML(this.getBody().innerHTML);3773 return false;3774};3775TinyMCEControl.prototype._insertSpace = function() {3776 return true;3777};3778TinyMCEControl.prototype.autoResetDesignMode = function() {3779 // Add fix for tab/style.display none/block problems in Gecko3780 if (!tinyMCE.isMSIE && tinyMCE.settings['auto_reset_designmode'] && this.isHidden())3781 eval('try { this.getDoc().designMode = "On"; } catch(e) {}');3782};3783TinyMCEControl.prototype.isHidden = function() {3784 if (tinyMCE.isMSIE)3785 return false;3786 var sel = this.getSel();3787 // Weird, wheres that cursor selection?3788 return (!sel || !sel.rangeCount || sel.rangeCount == 0);3789};3790TinyMCEControl.prototype.isDirty = function() {3791 // Is content modified and not in a submit procedure3792 return this.startContent != tinyMCE.trim(this.getBody().innerHTML) && !tinyMCE.isNotDirty;3793};3794TinyMCEControl.prototype._mergeElements = function(scmd, pa, ch, override) {3795 if (scmd == "removeformat") {3796 pa.className = "";3797 pa.style.cssText = "";3798 ch.className = "";3799 ch.style.cssText = "";3800 return;3801 }3802 var st = tinyMCE.parseStyle(tinyMCE.getAttrib(pa, "style"));3803 var stc = tinyMCE.parseStyle(tinyMCE.getAttrib(ch, "style"));3804 var className = tinyMCE.getAttrib(pa, "class");3805 className += " " + tinyMCE.getAttrib(ch, "class");3806 if (override) {3807 for (var n in st) {3808 if (typeof(st[n]) == 'function')3809 continue;3810 stc[n] = st[n];3811 }3812 } else {3813 for (var n in stc) {3814 if (typeof(stc[n]) == 'function')3815 continue;3816 st[n] = stc[n];3817 }3818 }3819 tinyMCE.setAttrib(pa, "style", tinyMCE.serializeStyle(st));3820 tinyMCE.setAttrib(pa, "class", tinyMCE.trim(className));3821 ch.className = "";3822 ch.style.cssText = "";3823 ch.removeAttribute("class");3824 ch.removeAttribute("style");3825};3826TinyMCEControl.prototype.setUseCSS = function(b) {3827 var doc = this.getDoc();3828 try {doc.execCommand("useCSS", false, !b);} catch (ex) {}3829 try {doc.execCommand("styleWithCSS", false, b);} catch (ex) {}3830 if (!tinyMCE.getParam("table_inline_editing"))3831 try {doc.execCommand('enableInlineTableEditing', false, "false");} catch (ex) {}3832 if (!tinyMCE.getParam("object_resizing"))3833 try {doc.execCommand('enableObjectResizing', false, "false");} catch (ex) {}3834};3835TinyMCEControl.prototype.execCommand = function(command, user_interface, value) {3836 var doc = this.getDoc();3837 var win = this.getWin();3838 var focusElm = this.getFocusElement();3839 if (this.lastSafariSelection && !new RegExp('mceStartTyping|mceEndTyping|mceBeginUndoLevel|mceEndUndoLevel|mceAddUndoLevel', 'gi').test(command)) {3840 this.moveToBookmark(this.lastSafariSelection);3841 tinyMCE.selectedElement = this.lastSafariSelectedElement;3842 }3843 // Mozilla issue3844 if (!tinyMCE.isMSIE && !this.useCSS) {3845 this.setUseCSS(false);3846 this.useCSS = true;3847 }3848 //debug("command: " + command + ", user_interface: " + user_interface + ", value: " + value);3849 this.contentDocument = doc; // <-- Strange, unless this is applied Mozilla 1.3 breaks3850 // Call theme execcommand3851 if (tinyMCE._themeExecCommand(this.editorId, this.getBody(), command, user_interface, value))3852 return;3853 // Fix align on images3854 if (focusElm && focusElm.nodeName == "IMG") {3855 var align = focusElm.getAttribute('align');3856 var img = command == "JustifyCenter" ? focusElm.cloneNode(false) : focusElm;3857 switch (command) {3858 case "JustifyLeft":3859 if (align == 'left')3860 img.removeAttribute('align');3861 else3862 img.setAttribute('align', 'left');3863 // Remove the div3864 var div = focusElm.parentNode;3865 if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)3866 div.parentNode.replaceChild(img, div);3867 this.selectNode(img);3868 this.repaint();3869 tinyMCE.triggerNodeChange();3870 return;3871 case "JustifyCenter":3872 img.removeAttribute('align');3873 // Is centered3874 var div = tinyMCE.getParentElement(focusElm, "div");3875 if (div && div.style.textAlign == "center") {3876 // Remove div3877 if (div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)3878 div.parentNode.replaceChild(img, div);3879 } else {3880 // Add div3881 var div = this.getDoc().createElement("div");3882 div.style.textAlign = 'center';3883 div.appendChild(img);3884 focusElm.parentNode.replaceChild(div, focusElm);3885 }3886 this.selectNode(img);3887 this.repaint();3888 tinyMCE.triggerNodeChange();3889 return;3890 case "JustifyRight":3891 if (align == 'right')3892 img.removeAttribute('align');3893 else3894 img.setAttribute('align', 'right');3895 // Remove the div3896 var div = focusElm.parentNode;3897 if (div && div.nodeName == "DIV" && div.childNodes.length == 1 && div.parentNode)3898 div.parentNode.replaceChild(img, div);3899 this.selectNode(img);3900 this.repaint();3901 tinyMCE.triggerNodeChange();3902 return;3903 }3904 }3905 if (tinyMCE.settings['force_br_newlines']) {3906 var alignValue = "";3907 if (doc.selection.type != "Control") {3908 switch (command) {3909 case "JustifyLeft":3910 alignValue = "left";3911 break;3912 case "JustifyCenter":3913 alignValue = "center";3914 break;3915 case "JustifyFull":3916 alignValue = "justify";3917 break;3918 case "JustifyRight":3919 alignValue = "right";3920 break;3921 }3922 if (alignValue != "") {3923 var rng = doc.selection.createRange();3924 if ((divElm = tinyMCE.getParentElement(rng.parentElement(), "div")) != null)3925 divElm.setAttribute("align", alignValue);3926 else if (rng.pasteHTML && rng.htmlText.length > 0)3927 rng.pasteHTML('<div align="' + alignValue + '">' + rng.htmlText + "</div>");3928 tinyMCE.triggerNodeChange();3929 return;3930 }3931 }3932 }3933 switch (command) {3934 case "mceRepaint":3935 this.repaint();3936 return true;3937 case "mceStoreSelection":3938 this.selectionBookmark = this.getBookmark();3939 return true;3940 case "mceRestoreSelection":3941 this.moveToBookmark(this.selectionBookmark);3942 return true;3943 case "InsertUnorderedList":3944 case "InsertOrderedList":3945 var tag = (command == "InsertUnorderedList") ? "ul" : "ol";3946 if (tinyMCE.isSafari)3947 this.execCommand("mceInsertContent", false, "<" + tag + "><li>&nbsp;</li><" + tag + ">");3948 else3949 this.getDoc().execCommand(command, user_interface, value);3950 tinyMCE.triggerNodeChange();3951 break;3952 case "Strikethrough":3953 if (tinyMCE.isSafari)3954 this.execCommand("mceInsertContent", false, "<strike>" + this.getSelectedHTML() + "</strike>");3955 else3956 this.getDoc().execCommand(command, user_interface, value);3957 tinyMCE.triggerNodeChange();3958 break;3959 case "mceSelectNode":3960 this.selectNode(value);3961 tinyMCE.triggerNodeChange();3962 tinyMCE.selectedNode = value;3963 break;3964 case "FormatBlock":3965 if (value == null || value == "") {3966 var elm = tinyMCE.getParentElement(this.getFocusElement(), "p,div,h1,h2,h3,h4,h5,h6,pre,address");3967 if (elm)3968 this.execCommand("mceRemoveNode", false, elm);3969 } else3970 this.getDoc().execCommand("FormatBlock", false, value);3971 tinyMCE.triggerNodeChange();3972 break;3973 case "mceRemoveNode":3974 if (!value)3975 value = tinyMCE.getParentElement(this.getFocusElement());3976 if (tinyMCE.isMSIE) {3977 value.outerHTML = value.innerHTML;3978 } else {3979 var rng = value.ownerDocument.createRange();3980 rng.setStartBefore(value);3981 rng.setEndAfter(value);3982 rng.deleteContents();3983 rng.insertNode(rng.createContextualFragment(value.innerHTML));3984 }3985 tinyMCE.triggerNodeChange();3986 break;3987 case "mceSelectNodeDepth":3988 var parentNode = this.getFocusElement();3989 for (var i=0; parentNode; i++) {3990 if (parentNode.nodeName.toLowerCase() == "body")3991 break;3992 if (parentNode.nodeName.toLowerCase() == "#text") {3993 i--;3994 parentNode = parentNode.parentNode;3995 continue;3996 }3997 if (i == value) {3998 this.selectNode(parentNode, false);3999 tinyMCE.triggerNodeChange();4000 tinyMCE.selectedNode = parentNode;4001 return;4002 }4003 parentNode = parentNode.parentNode;4004 }4005 break;4006 case "SetStyleInfo":4007 var rng = this.getRng();4008 var sel = this.getSel();4009 var scmd = value['command'];4010 var sname = value['name'];4011 var svalue = value['value'] == null ? '' : value['value'];4012 //var svalue = value['value'] == null ? '' : value['value'];4013 var wrapper = value['wrapper'] ? value['wrapper'] : "span";4014 var parentElm = null;4015 var invalidRe = new RegExp("^BODY|HTML$", "g");4016 var invalidParentsRe = tinyMCE.settings['merge_styles_invalid_parents'] != '' ? new RegExp(tinyMCE.settings['merge_styles_invalid_parents'], "gi") : null;4017 // Whole element selected check4018 if (tinyMCE.isMSIE) {4019 // Control range4020 if (rng.item)4021 parentElm = rng.item(0);4022 else {4023 var pelm = rng.parentElement();4024 var prng = doc.selection.createRange();4025 prng.moveToElementText(pelm);4026 if (rng.htmlText == prng.htmlText || rng.boundingWidth == 0) {4027 if (invalidParentsRe == null || !invalidParentsRe.test(pelm.nodeName))4028 parentElm = pelm;4029 }4030 }4031 } else {4032 var felm = this.getFocusElement();4033 if (sel.isCollapsed || (/td|tr|tbody|table/ig.test(felm.nodeName) && sel.anchorNode == felm.parentNode))4034 parentElm = felm;4035 }4036 // Whole element selected4037 if (parentElm && !invalidRe.test(parentElm.nodeName)) {4038 if (scmd == "setstyle")4039 tinyMCE.setStyleAttrib(parentElm, sname, svalue);4040 if (scmd == "setattrib")4041 tinyMCE.setAttrib(parentElm, sname, svalue);4042 if (scmd == "removeformat") {4043 parentElm.style.cssText = '';4044 tinyMCE.setAttrib(parentElm, 'class', '');4045 }4046 // Remove style/attribs from all children4047 var ch = tinyMCE.getNodeTree(parentElm, new Array(), 1);4048 for (var z=0; z<ch.length; z++) {4049 if (ch[z] == parentElm)4050 continue;4051 if (scmd == "setstyle")4052 tinyMCE.setStyleAttrib(ch[z], sname, '');4053 if (scmd == "setattrib")4054 tinyMCE.setAttrib(ch[z], sname, '');4055 if (scmd == "removeformat") {4056 ch[z].style.cssText = '';4057 tinyMCE.setAttrib(ch[z], 'class', '');4058 }4059 }4060 } else {4061 doc.execCommand("fontname", false, "#mce_temp_font#");4062 var elementArray = tinyMCE.getElementsByAttributeValue(this.getBody(), "font", "face", "#mce_temp_font#");4063 // Change them all4064 for (var x=0; x<elementArray.length; x++) {4065 elm = elementArray[x];4066 if (elm) {4067 var spanElm = doc.createElement(wrapper);4068 if (scmd == "setstyle")4069 tinyMCE.setStyleAttrib(spanElm, sname, svalue);4070 if (scmd == "setattrib")4071 tinyMCE.setAttrib(spanElm, sname, svalue);4072 if (scmd == "removeformat") {4073 spanElm.style.cssText = '';4074 tinyMCE.setAttrib(spanElm, 'class', '');4075 }4076 if (elm.hasChildNodes()) {4077 for (var i=0; i<elm.childNodes.length; i++)4078 spanElm.appendChild(elm.childNodes[i].cloneNode(true));4079 }4080 spanElm.setAttribute("mce_new", "true");4081 elm.parentNode.replaceChild(spanElm, elm);4082 // Remove style/attribs from all children4083 var ch = tinyMCE.getNodeTree(spanElm, new Array(), 1);4084 for (var z=0; z<ch.length; z++) {4085 if (ch[z] == spanElm)4086 continue;4087 if (scmd == "setstyle")4088 tinyMCE.setStyleAttrib(ch[z], sname, '');4089 if (scmd == "setattrib")4090 tinyMCE.setAttrib(ch[z], sname, '');4091 if (scmd == "removeformat") {4092 ch[z].style.cssText = '';4093 tinyMCE.setAttrib(ch[z], 'class', '');4094 }4095 }4096 }4097 }4098 }4099 // Cleaup wrappers4100 var nodes = doc.getElementsByTagName(wrapper);4101 for (var i=nodes.length-1; i>=0; i--) {4102 var elm = nodes[i];4103 var isNew = tinyMCE.getAttrib(elm, "mce_new") == "true";4104 elm.removeAttribute("mce_new");4105 // Is only child a element4106 if (elm.childNodes && elm.childNodes.length == 1 && elm.childNodes[0].nodeType == 1) {4107 //tinyMCE.debug("merge1" + isNew);4108 this._mergeElements(scmd, elm, elm.childNodes[0], isNew);4109 continue;4110 }4111 // Is I the only child4112 if (elm.parentNode.childNodes.length == 1 && !invalidRe.test(elm.nodeName) && !invalidRe.test(elm.parentNode.nodeName)) {4113 //tinyMCE.debug("merge2" + isNew + "," + elm.nodeName + "," + elm.parentNode.nodeName);4114 if (invalidParentsRe == null || !invalidParentsRe.test(elm.parentNode.nodeName))4115 this._mergeElements(scmd, elm.parentNode, elm, false);4116 }4117 }4118 // Remove empty wrappers4119 var nodes = doc.getElementsByTagName(wrapper);4120 for (var i=nodes.length-1; i>=0; i--) {4121 var elm = nodes[i];4122 var isEmpty = true;4123 // Check if it has any attribs4124 var tmp = doc.createElement("body");4125 tmp.appendChild(elm.cloneNode(false));4126 // Is empty span, remove it4127 tmp.innerHTML = tmp.innerHTML.replace(new RegExp('style=""|class=""', 'gi'), '');4128 //tinyMCE.debug(tmp.innerHTML);4129 if (new RegExp('<span>', 'gi').test(tmp.innerHTML)) {4130 for (var x=0; x<elm.childNodes.length; x++) {4131 if (elm.parentNode != null)4132 elm.parentNode.insertBefore(elm.childNodes[x].cloneNode(true), elm);4133 }4134 elm.parentNode.removeChild(elm);4135 }4136 }4137 // Re add the visual aids4138 if (scmd == "removeformat")4139 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);4140 tinyMCE.triggerNodeChange();4141 break;4142 case "FontName":4143 if (value == null) {4144 var s = this.getSel();4145 // Find font and select it4146 if (tinyMCE.isGecko && s.isCollapsed) {4147 var f = tinyMCE.getParentElement(this.getFocusElement(), "font");4148 if (f != null)4149 this.selectNode(f, false);4150 }4151 // Remove format4152 this.getDoc().execCommand("RemoveFormat", false, null);4153 // Collapse range if font was found4154 if (f != null && tinyMCE.isGecko) {4155 var r = this.getRng().cloneRange();4156 r.collapse(true);4157 s.removeAllRanges();4158 s.addRange(r);4159 }4160 } else4161 this.getDoc().execCommand('FontName', false, value);4162 if (tinyMCE.isGecko)4163 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);4164 return;4165 case "FontSize":4166 this.getDoc().execCommand('FontSize', false, value);4167 if (tinyMCE.isGecko)4168 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);4169 return;4170 case "forecolor":4171 this.getDoc().execCommand('forecolor', false, value);4172 break;4173 case "HiliteColor":4174 if (tinyMCE.isGecko) {4175 this.setUseCSS(true);4176 this.getDoc().execCommand('hilitecolor', false, value);4177 this.setUseCSS(false);4178 } else4179 this.getDoc().execCommand('BackColor', false, value);4180 break;4181 case "Cut":4182 case "Copy":4183 case "Paste":4184 var cmdFailed = false;4185 // Try executing command4186 eval('try {this.getDoc().execCommand(command, user_interface, value);} catch (e) {cmdFailed = true;}');4187 if (tinyMCE.isOpera && cmdFailed)4188 alert('Currently not supported by your browser, use keyboard shortcuts instead.');4189 // Alert error in gecko if command failed4190 if (tinyMCE.isGecko && cmdFailed) {4191 // Confirm more info4192 if (confirm(tinyMCE.getLang('lang_clipboard_msg')))4193 window.open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', 'mceExternal');4194 return;4195 } else4196 tinyMCE.triggerNodeChange();4197 break;4198 case "mceSetContent":4199 if (!value)4200 value = "";4201 // Call custom cleanup code4202 value = tinyMCE.storeAwayURLs(value);4203 //value = tinyMCE._customCleanup(this, "insert_to_editor", value);4204 tinyMCE._setHTML(doc, value);4205 tinyMCE.setInnerHTML(doc.body, tinyMCE._cleanupHTML(this, doc, tinyMCE.settings, doc.body));4206 this.convertAllRelativeURLs();4207 tinyMCE.handleVisualAid(doc.body, true, this.visualAid, this);4208 tinyMCE._setEventsEnabled(doc.body, false);4209 return true;4210 case "mceLink":4211 var selectedText = "";4212 if (tinyMCE.isMSIE) {4213 var rng = doc.selection.createRange();4214 selectedText = rng.text;4215 } else4216 selectedText = this.getSel().toString();4217 if (!tinyMCE.linkElement) {4218 if ((tinyMCE.selectedElement.nodeName.toLowerCase() != "img") && (selectedText.length <= 0))4219 return;4220 }4221 var href = "", target = "", title = "", onclick = "", action = "insert", style_class = "";4222 if (tinyMCE.selectedElement.nodeName.toLowerCase() == "a")4223 tinyMCE.linkElement = tinyMCE.selectedElement;4224 // Is anchor not a link4225 if (tinyMCE.linkElement != null && tinyMCE.getAttrib(tinyMCE.linkElement, 'href') == "")4226 tinyMCE.linkElement = null;4227 if (tinyMCE.linkElement) {4228 href = tinyMCE.getAttrib(tinyMCE.linkElement, 'href');4229 target = tinyMCE.getAttrib(tinyMCE.linkElement, 'target');4230 title = tinyMCE.getAttrib(tinyMCE.linkElement, 'title');4231 onclick = tinyMCE.getAttrib(tinyMCE.linkElement, 'onclick');4232 style_class = tinyMCE.getAttrib(tinyMCE.linkElement, 'class');4233 // Try old onclick to if copy/pasted content4234 if (onclick == "")4235 onclick = tinyMCE.getAttrib(tinyMCE.linkElement, 'onclick');4236 onclick = tinyMCE.cleanupEventStr(onclick);4237 href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement, true);");4238 // Use mce_href if defined4239 mceRealHref = tinyMCE.getAttrib(tinyMCE.linkElement, 'mce_href');4240 if (mceRealHref != "") {4241 href = mceRealHref;4242 if (tinyMCE.getParam('convert_urls'))4243 href = eval(tinyMCE.settings['urlconverter_callback'] + "(href, tinyMCE.linkElement, true);");4244 }4245 action = "update";4246 }4247 if (this.settings['insertlink_callback']) {4248 var returnVal = eval(this.settings['insertlink_callback'] + "(href, target, title, onclick, action, style_class);");4249 if (returnVal && returnVal['href'])4250 tinyMCE.insertLink(returnVal['href'], returnVal['target'], returnVal['title'], returnVal['onclick'], returnVal['style_class']);4251 } else {4252 tinyMCE.openWindow(this.insertLinkTemplate, {href : href, target : target, title : title, onclick : onclick, action : action, className : style_class, inline : "yes"});4253 }4254 break;4255 case "mceImage":4256 var src = "", alt = "", border = "", hspace = "", vspace = "", width = "", height = "", align = "";4257 var title = "", onmouseover = "", onmouseout = "", action = "insert";4258 var img = tinyMCE.imgElement;4259 if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img") {4260 img = tinyMCE.selectedElement;4261 tinyMCE.imgElement = img;4262 }4263 if (img) {4264 // Is it a internal MCE visual aid image, then skip this one.4265 if (tinyMCE.getAttrib(img, 'name').indexOf('mce_') == 0)4266 return;4267 src = tinyMCE.getAttrib(img, 'src');4268 alt = tinyMCE.getAttrib(img, 'alt');4269 // Try polling out the title4270 if (alt == "")4271 alt = tinyMCE.getAttrib(img, 'title');4272 // Fix width/height attributes if the styles is specified4273 if (tinyMCE.isGecko) {4274 var w = img.style.width;4275 if (w != null && w != "")4276 img.setAttribute("width", w);4277 var h = img.style.height;4278 if (h != null && h != "")4279 img.setAttribute("height", h);4280 }4281 border = tinyMCE.getAttrib(img, 'border');4282 hspace = tinyMCE.getAttrib(img, 'hspace');4283 vspace = tinyMCE.getAttrib(img, 'vspace');4284 width = tinyMCE.getAttrib(img, 'width');4285 height = tinyMCE.getAttrib(img, 'height');4286 align = tinyMCE.getAttrib(img, 'align');4287 onmouseover = tinyMCE.getAttrib(img, 'onmouseover');4288 onmouseout = tinyMCE.getAttrib(img, 'onmouseout');4289 title = tinyMCE.getAttrib(img, 'title');4290 // Is realy specified?4291 if (tinyMCE.isMSIE) {4292 width = img.attributes['width'].specified ? width : "";4293 height = img.attributes['height'].specified ? height : "";4294 }4295 onmouseover = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseover));4296 onmouseout = tinyMCE.getImageSrc(tinyMCE.cleanupEventStr(onmouseout));4297 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");4298 // Use mce_src if defined4299 mceRealSrc = tinyMCE.getAttrib(img, 'mce_src');4300 if (mceRealSrc != "") {4301 src = mceRealSrc;4302 if (tinyMCE.getParam('convert_urls'))4303 src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, img, true);");4304 }4305 if (onmouseover != "")4306 onmouseover = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseover, img, true);");4307 if (onmouseout != "")4308 onmouseout = eval(tinyMCE.settings['urlconverter_callback'] + "(onmouseout, img, true);");4309 action = "update";4310 }4311 if (this.settings['insertimage_callback']) {4312 var returnVal = eval(this.settings['insertimage_callback'] + "(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout, action);");4313 if (returnVal && returnVal['src'])4314 tinyMCE.insertImage(returnVal['src'], returnVal['alt'], returnVal['border'], returnVal['hspace'], returnVal['vspace'], returnVal['width'], returnVal['height'], returnVal['align'], returnVal['title'], returnVal['onmouseover'], returnVal['onmouseout']);4315 } else4316 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"});4317 break;4318 case "mceCleanup":4319 tinyMCE._setHTML(this.contentDocument, this.getBody().innerHTML);4320 tinyMCE.setInnerHTML(this.getBody(), tinyMCE._cleanupHTML(this, this.contentDocument, this.settings, this.getBody(), this.visualAid));4321 this.convertAllRelativeURLs();4322 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);4323 tinyMCE._setEventsEnabled(this.getBody(), false);4324 this.repaint();4325 tinyMCE.triggerNodeChange();4326 break;4327 case "mceReplaceContent":4328 this.getWin().focus();4329 var selectedText = "";4330 if (tinyMCE.isMSIE) {4331 var rng = doc.selection.createRange();4332 selectedText = rng.text;4333 } else4334 selectedText = this.getSel().toString();4335 if (selectedText.length > 0) {4336 value = tinyMCE.replaceVar(value, "selection", selectedText);4337 tinyMCE.execCommand('mceInsertContent', false, value);4338 }4339 tinyMCE.triggerNodeChange();4340 break;4341 case "mceSetAttribute":4342 if (typeof(value) == 'object') {4343 var targetElms = (typeof(value['targets']) == "undefined") ? "p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address" : value['targets'];4344 var targetNode = tinyMCE.getParentElement(this.getFocusElement(), targetElms);4345 if (targetNode) {4346 targetNode.setAttribute(value['name'], value['value']);4347 tinyMCE.triggerNodeChange();4348 }4349 }4350 break;4351 case "mceSetCSSClass":4352 this.execCommand("SetStyleInfo", false, {command : "setattrib", name : "class", value : value});4353 break;4354 case "mceInsertRawHTML":4355 var key = 'tiny_mce_marker';4356 this.execCommand('mceBeginUndoLevel');4357 // Insert marker key4358 this.execCommand('mceInsertContent', false, key);4359 // Store away scroll pos4360 var scrollX = this.getDoc().body.scrollLeft + this.getDoc().documentElement.scrollLeft;4361 var scrollY = this.getDoc().body.scrollTop + this.getDoc().documentElement.scrollTop;4362 // Find marker and replace with RAW HTML4363 var html = this.getBody().innerHTML;4364 if ((pos = html.indexOf(key)) != -1)4365 tinyMCE.setInnerHTML(this.getBody(), html.substring(0, pos) + value + html.substring(pos + key.length));4366 // Restore scoll pos4367 this.contentWindow.scrollTo(scrollX, scrollY);4368 this.execCommand('mceEndUndoLevel');4369 break;4370 case "mceInsertContent":4371 var insertHTMLFailed = false;4372 this.getWin().focus();4373/* WP4374 if (tinyMCE.isGecko || tinyMCE.isOpera) {4375 try {4376 // Is plain text or HTML4377 if (value.indexOf('<') == -1) {4378 var r = this.getRng();4379 var n = this.getDoc().createTextNode(tinyMCE.entityDecode(value));4380 var s = this.getSel();4381 var r2 = r.cloneRange();4382 // Insert text at cursor position4383 s.removeAllRanges();4384 r.deleteContents();4385 r.insertNode(n);4386 // Move the cursor to the end of text4387 r2.selectNode(n);4388 r2.collapse(false);4389 s.removeAllRanges();4390 s.addRange(r2);4391 } else {4392 value = tinyMCE.fixGeckoBaseHREFBug(1, this.getDoc(), value);4393 this.getDoc().execCommand('inserthtml', false, value);4394 tinyMCE.fixGeckoBaseHREFBug(2, this.getDoc(), value);4395 }4396 } catch (ex) {4397 insertHTMLFailed = true;4398 }4399 if (!insertHTMLFailed) {4400 tinyMCE.triggerNodeChange();4401 return;4402 }4403 }4404*/4405 // Ugly hack in Opera due to non working "inserthtml"4406 if (tinyMCE.isOpera && insertHTMLFailed) {4407 this.getDoc().execCommand("insertimage", false, tinyMCE.uniqueURL);4408 var ar = tinyMCE.getElementsByAttributeValue(this.getBody(), "img", "src", tinyMCE.uniqueURL);4409 ar[0].outerHTML = value;4410 return;4411 }4412 if (!tinyMCE.isMSIE) {4413 var isHTML = value.indexOf('<') != -1;4414 var sel = this.getSel();4415 var rng = this.getRng();4416 if (isHTML) {4417 if (tinyMCE.isSafari) {4418 var tmpRng = this.getDoc().createRange();4419 tmpRng.setStart(this.getBody(), 0);4420 tmpRng.setEnd(this.getBody(), 0);4421 value = tmpRng.createContextualFragment(value);4422 } else4423 value = rng.createContextualFragment(value);4424 } else {4425 // Setup text node4426 var el = document.createElement("div");4427 el.innerHTML = value;4428 value = el.firstChild.nodeValue;4429 value = doc.createTextNode(value);4430 }4431 // Insert plain text in Safari4432 if (tinyMCE.isSafari && !isHTML) {4433 this.execCommand('InsertText', false, value.nodeValue);4434 tinyMCE.triggerNodeChange();4435 return true;4436 } else if (tinyMCE.isSafari && isHTML) {4437 rng.deleteContents();4438 rng.insertNode(value);4439 tinyMCE.triggerNodeChange();4440 return true;4441 }4442 rng.deleteContents();4443 // If target node is text do special treatment, (Mozilla 1.3 fix)4444 if (rng.startContainer.nodeType == 3) {4445 var node = rng.startContainer.splitText(rng.startOffset);4446 node.parentNode.insertBefore(value, node); 4447 } else4448 rng.insertNode(value);4449 if (!isHTML) {4450 // Removes weird selection trails4451 sel.selectAllChildren(doc.body);4452 sel.removeAllRanges();4453 // Move cursor to end of content4454 var rng = doc.createRange();4455 rng.selectNode(value);4456 rng.collapse(false);4457 sel.addRange(rng);4458 } else4459 rng.collapse(false);4460 } else {4461 var rng = doc.selection.createRange();4462 var c = value.indexOf('<!--') != -1;4463 // Fix comment bug, add tag before comments4464 if (c)4465 value = tinyMCE.uniqueTag + value;4466 if (rng.item)4467 rng.item(0).outerHTML = value;4468 else4469 rng.pasteHTML(value);4470 // Remove unique tag4471 if (c) {4472 var e = this.getDoc().getElementById('mceTMPElement');4473 e.parentNode.removeChild(e);4474 }4475 }4476 tinyMCE.triggerNodeChange();4477 break;4478 case "mceStartTyping":4479 if (tinyMCE.settings['custom_undo_redo'] && this.typingUndoIndex == -1) {4480 this.typingUndoIndex = this.undoIndex;4481 this.execCommand('mceAddUndoLevel');4482 //tinyMCE.debug("mceStartTyping");4483 }4484 break;4485 case "mceEndTyping":4486 if (tinyMCE.settings['custom_undo_redo'] && this.typingUndoIndex != -1) {4487 this.execCommand('mceAddUndoLevel');4488 this.typingUndoIndex = -1;4489 //tinyMCE.debug("mceEndTyping");4490 }4491 break;4492 case "mceBeginUndoLevel":4493 this.undoRedo = false;4494 break;4495 case "mceEndUndoLevel":4496 this.undoRedo = true;4497 this.execCommand('mceAddUndoLevel');4498 break;4499 case "mceAddUndoLevel":4500 if (tinyMCE.settings['custom_undo_redo'] && this.undoRedo) {4501 // tinyMCE.debug("add level");4502 if (this.typingUndoIndex != -1) {4503 this.undoIndex = this.typingUndoIndex;4504 // tinyMCE.debug("Override: " + this.undoIndex);4505 }4506 var newHTML = tinyMCE.trim(this.getBody().innerHTML);4507 if (newHTML != this.undoLevels[this.undoIndex]) {4508 tinyMCE.executeCallback('onchange_callback', '_onchange', 0, this);4509 // Time to compress4510 var customUndoLevels = tinyMCE.settings['custom_undo_redo_levels'];4511 if (customUndoLevels != -1 && this.undoLevels.length > customUndoLevels) {4512 for (var i=0; i<this.undoLevels.length-1; i++) {4513 //tinyMCE.debug(this.undoLevels[i] + "=" + this.undoLevels[i+1]);4514 this.undoLevels[i] = this.undoLevels[i+1];4515 }4516 this.undoLevels.length--;4517 this.undoIndex--;4518 }4519 this.undoIndex++;4520 this.undoLevels[this.undoIndex] = newHTML;4521 this.undoLevels.length = this.undoIndex + 1;4522 // tinyMCE.debug("level added" + this.undoIndex);4523 tinyMCE.triggerNodeChange(false);4524 // tinyMCE.debug(this.undoIndex + "," + (this.undoLevels.length-1));4525 }4526 }4527 break;4528 case "Undo":4529 if (tinyMCE.settings['custom_undo_redo']) {4530 tinyMCE.execCommand("mceEndTyping");4531 // Do undo4532 if (this.undoIndex > 0) {4533 this.undoIndex--;4534 tinyMCE.setInnerHTML(this.getBody(), this.undoLevels[this.undoIndex]);4535 this.repaint();4536 }4537 // tinyMCE.debug("Undo - undo levels:" + this.undoLevels.length + ", undo index: " + this.undoIndex);4538 tinyMCE.triggerNodeChange();4539 } else4540 this.getDoc().execCommand(command, user_interface, value);4541 break;4542 case "Redo":4543 if (tinyMCE.settings['custom_undo_redo']) {4544 tinyMCE.execCommand("mceEndTyping");4545 if (this.undoIndex < (this.undoLevels.length-1)) {4546 this.undoIndex++;4547 tinyMCE.setInnerHTML(this.getBody(), this.undoLevels[this.undoIndex]);4548 this.repaint();4549 // tinyMCE.debug("Redo - undo levels:" + this.undoLevels.length + ", undo index: " + this.undoIndex);4550 }4551 tinyMCE.triggerNodeChange();4552 } else4553 this.getDoc().execCommand(command, user_interface, value);4554 break;4555 case "mceToggleVisualAid":4556 this.visualAid = !this.visualAid;4557 tinyMCE.handleVisualAid(this.getBody(), true, this.visualAid, this);4558 tinyMCE.triggerNodeChange();4559 break;4560 case "Indent":4561 this.getDoc().execCommand(command, user_interface, value);4562 tinyMCE.triggerNodeChange();4563 if (tinyMCE.isMSIE) {4564 var n = tinyMCE.getParentElement(this.getFocusElement(), "blockquote");4565 do {4566 if (n && n.nodeName == "BLOCKQUOTE") {4567 n.removeAttribute("dir");4568 n.removeAttribute("style");4569 }4570 } while (n != null && (n = n.parentNode) != null);4571 }4572 break;4573 case "removeformat":4574 var text = this.getSelectedText();4575 if (tinyMCE.isOpera) {4576 this.getDoc().execCommand("RemoveFormat", false, null);4577 return;4578 }4579 if (tinyMCE.isMSIE) {4580 try {4581 var rng = doc.selection.createRange();4582 rng.execCommand("RemoveFormat", false, null);4583 } catch (e) {4584 // Do nothing4585 }4586 this.execCommand("SetStyleInfo", false, {command : "removeformat"});4587 } else {4588 this.getDoc().execCommand(command, user_interface, value);4589 this.execCommand("SetStyleInfo", false, {command : "removeformat"});4590 }4591 // Remove class4592 if (text.length == 0)4593 this.execCommand("mceSetCSSClass", false, "");4594 tinyMCE.triggerNodeChange();4595 break;4596 default:4597 this.getDoc().execCommand(command, user_interface, value);4598 if (tinyMCE.isGecko)4599 window.setTimeout('tinyMCE.triggerNodeChange(false);', 1);4600 else4601 tinyMCE.triggerNodeChange();4602 }4603 // Add undo level after modification4604 if (command != "mceAddUndoLevel" && command != "Undo" && command != "Redo" && command != "mceStartTyping" && command != "mceEndTyping")4605 tinyMCE.execCommand("mceAddUndoLevel");4606};4607TinyMCEControl.prototype.queryCommandValue = function(command) {4608 try {4609 return this.getDoc().queryCommandValue(command);4610 } catch (ex) {4611 return null;4612 }4613};4614TinyMCEControl.prototype.queryCommandState = function(command) {4615 return this.getDoc().queryCommandState(command);4616};4617TinyMCEControl.prototype.onAdd = function(replace_element, form_element_name, target_document) {4618 var targetDoc = target_document ? target_document : document;4619 this.targetDoc = targetDoc;4620 tinyMCE.themeURL = tinyMCE.baseURL + "/themes/" + this.settings['theme'];4621 this.settings['themeurl'] = tinyMCE.themeURL;4622 if (!replace_element) {4623 alert("Error: Could not find the target element.");4624 return false;4625 }4626 var templateFunction = tinyMCE._getThemeFunction('_getInsertLinkTemplate');4627 if (eval("typeof(" + templateFunction + ")") != 'undefined')4628 this.insertLinkTemplate = eval(templateFunction + '(this.settings);');4629 var templateFunction = tinyMCE._getThemeFunction('_getInsertImageTemplate');4630 if (eval("typeof(" + templateFunction + ")") != 'undefined')4631 this.insertImageTemplate = eval(templateFunction + '(this.settings);');4632 var templateFunction = tinyMCE._getThemeFunction('_getEditorTemplate');4633 if (eval("typeof(" + templateFunction + ")") == 'undefined') {4634 alert("Error: Could not find the template function: " + templateFunction);4635 return false;4636 }4637 var editorTemplate = eval(templateFunction + '(this.settings, this.editorId);');4638 var deltaWidth = editorTemplate['delta_width'] ? editorTemplate['delta_width'] : 0;4639 var deltaHeight = editorTemplate['delta_height'] ? editorTemplate['delta_height'] : 0;4640 var html = '<span id="' + this.editorId + '_parent">' + editorTemplate['html'];4641 var templateFunction = tinyMCE._getThemeFunction('_handleNodeChange', true);4642 if (eval("typeof(" + templateFunction + ")") != 'undefined')4643 this.settings['handleNodeChangeCallback'] = templateFunction;4644 html = tinyMCE.replaceVar(html, "editor_id", this.editorId);4645 this.settings['default_document'] = tinyMCE.baseURL + "/blank.htm";4646 this.settings['old_width'] = this.settings['width'];4647 this.settings['old_height'] = this.settings['height'];4648 // Set default width, height4649 if (this.settings['width'] == -1)4650 this.settings['width'] = replace_element.offsetWidth;4651 if (this.settings['height'] == -1)4652 this.settings['height'] = replace_element.offsetHeight;4653 // Try the style width4654 if (this.settings['width'] == 0)4655 this.settings['width'] = replace_element.style.width;4656 // Try the style height4657 if (this.settings['height'] == 0)4658 this.settings['height'] = replace_element.style.height; 4659 // If no width/height then default to 320x240, better than nothing4660 if (this.settings['width'] == 0)4661 this.settings['width'] = 320;4662 if (this.settings['height'] == 0)4663 this.settings['height'] = 240;4664 this.settings['area_width'] = parseInt(this.settings['width']);4665 this.settings['area_height'] = parseInt(this.settings['height']);4666 this.settings['area_width'] += deltaWidth;4667 this.settings['area_height'] += deltaHeight;4668 // Special % handling4669 if (("" + this.settings['width']).indexOf('%') != -1)4670 this.settings['area_width'] = "100%";4671 if (("" + this.settings['height']).indexOf('%') != -1)4672 this.settings['area_height'] = "100%";4673 if (("" + replace_element.style.width).indexOf('%') != -1) {4674 this.settings['width'] = replace_element.style.width;4675 this.settings['area_width'] = "100%";4676 }4677 if (("" + replace_element.style.height).indexOf('%') != -1) {4678 this.settings['height'] = replace_element.style.height;4679 this.settings['area_height'] = "100%";4680 }4681 html = tinyMCE.applyTemplate(html);4682 this.settings['width'] = this.settings['old_width'];4683 this.settings['height'] = this.settings['old_height'];4684 this.visualAid = this.settings['visual'];4685 this.formTargetElementId = form_element_name;4686 // Get replace_element contents4687 if (replace_element.nodeName == "TEXTAREA" || replace_element.nodeName == "INPUT")4688 this.startContent = replace_element.value;4689 else4690 this.startContent = replace_element.innerHTML;4691 // If not text area4692 if (replace_element.nodeName.toLowerCase() != "textarea") {4693 this.oldTargetElement = replace_element.cloneNode(true);4694 // Debug mode4695 if (tinyMCE.settings['debug'])4696 html += '<textarea wrap="off" id="' + form_element_name + '" name="' + form_element_name + '" cols="100" rows="15"></textarea>';4697 else4698 html += '<input type="hidden" type="text" id="' + form_element_name + '" name="' + form_element_name + '" />';4699 html += '</span>';4700 // Output HTML and set editable4701 if (!tinyMCE.isMSIE) {4702 var rng = replace_element.ownerDocument.createRange();4703 rng.setStartBefore(replace_element);4704 var fragment = rng.createContextualFragment(html);4705 replace_element.parentNode.replaceChild(fragment, replace_element);4706 } else4707 replace_element.outerHTML = html;4708 } else {4709 html += '</span>';4710 // Just hide the textarea element4711 this.oldTargetElement = replace_element;4712 if (!tinyMCE.settings['debug'])4713 this.oldTargetElement.style.display = "none";4714 // Output HTML and set editable4715 if (!tinyMCE.isMSIE) {4716 var rng = replace_element.ownerDocument.createRange();4717 rng.setStartBefore(replace_element);4718 var fragment = rng.createContextualFragment(html);4719 if (tinyMCE.isGecko)4720 tinyMCE.insertAfter(fragment, replace_element);4721 else4722 replace_element.parentNode.insertBefore(fragment, replace_element);4723 } else4724 replace_element.insertAdjacentHTML("beforeBegin", html);4725 }4726 // Setup iframe4727 var dynamicIFrame = false;4728 var tElm = targetDoc.getElementById(this.editorId);4729 if (!tinyMCE.isMSIE) {4730 if (tElm && tElm.nodeName.toLowerCase() == "span") {4731 tElm = tinyMCE._createIFrame(tElm);4732 dynamicIFrame = true;4733 }4734 this.targetElement = tElm;4735 this.iframeElement = tElm;4736 this.contentDocument = tElm.contentDocument;4737 this.contentWindow = tElm.contentWindow;4738 //this.getDoc().designMode = "on";4739 } else {4740 if (tElm && tElm.nodeName.toLowerCase() == "span")4741 tElm = tinyMCE._createIFrame(tElm);4742 else4743 tElm = targetDoc.frames[this.editorId];4744 this.targetElement = tElm;4745 this.iframeElement = targetDoc.getElementById(this.editorId);4746 if (tinyMCE.isOpera) {4747 this.contentDocument = this.iframeElement.contentDocument;4748 this.contentWindow = this.iframeElement.contentWindow;4749 dynamicIFrame = true;4750 } else {4751 this.contentDocument = tElm.window.document;4752 this.contentWindow = tElm.window;4753 }4754 this.getDoc().designMode = "on";4755 }4756 // Setup base HTML4757 var doc = this.contentDocument;4758 if (dynamicIFrame) {4759 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>';4760 try {4761 if (!this.isHidden())4762 this.getDoc().designMode = "on";4763 doc.open();4764 doc.write(html);4765 doc.close();4766 } catch (e) {4767 // Failed Mozilla 1.34768 this.getDoc().location.href = tinyMCE.baseURL + "/blank.htm";4769 }4770 }4771 // This timeout is needed in MSIE 5.5 for some odd reason4772 // it seems that the document.frames isn't initialized yet?4773 if (tinyMCE.isMSIE)4774 window.setTimeout("TinyMCE.prototype.addEventHandlers('" + this.editorId + "');", 1);4775 tinyMCE.setupContent(this.editorId, true);4776 return true;4777};4778TinyMCEControl.prototype.getFocusElement = function() {4779 if (tinyMCE.isMSIE && !tinyMCE.isOpera) {4780 var doc = this.getDoc();4781 var rng = doc.selection.createRange();4782// if (rng.collapse)4783// rng.collapse(true);4784 var elm = rng.item ? rng.item(0) : rng.parentElement();4785 } else {4786 if (this.isHidden())4787 return this.getBody();4788 var sel = this.getSel();4789 var rng = this.getRng();4790 var elm = rng.commonAncestorContainer;4791 //var elm = (sel && sel.anchorNode) ? sel.anchorNode : null;4792 // Handle selection a image or other control like element such as anchors4793 if (!rng.collapsed) {4794 // Is selection small4795 if (rng.startContainer == rng.endContainer) {4796 if (rng.startOffset - rng.endOffset < 2) {4797 if (rng.startContainer.hasChildNodes())4798 elm = rng.startContainer.childNodes[rng.startOffset];4799 }4800 }4801 }4802 // Get the element parent of the node4803 elm = tinyMCE.getParentElement(elm);4804 //if (tinyMCE.selectedElement != null && tinyMCE.selectedElement.nodeName.toLowerCase() == "img")4805 // elm = tinyMCE.selectedElement;4806 }4807 return elm;4808};4809// Global instances4810var tinyMCE = new TinyMCE();...

Full Screen

Full Screen

tiny_mce_popup.js

Source:tiny_mce_popup.js Github

copy

Full Screen

1/**2 * $RCSfile: tiny_mce_popup.js,v $3 * $Revision: 1.18 $4 * $Date: 2005/10/29 19:13:20 $5 *6 * @author Moxiecode7 * @copyright Copyright © 2004, Moxiecode Systems AB, All rights reserved.8 */9var tinyMCE = null, tinyMCELang = null;10function TinyMCEPopup() {11};12TinyMCEPopup.prototype.init = function() {13 var win = window.opener ? window.opener : window.dialogArguments;14 if (!win)15 win = top;16 window.opener = win;17 this.windowOpener = win;18 this.onLoadEval = "";19 // Setup parent references20 tinyMCE = win.tinyMCE;21 tinyMCELang = win.tinyMCELang;22 if (!tinyMCE) {23 alert("tinyMCE object reference not found from popup.");24 return;25 }26 this.isWindow = tinyMCE.getWindowArg('mce_inside_iframe', false) == false;27 this.storeSelection = tinyMCE.isMSIE && !this.isWindow && tinyMCE.getWindowArg('mce_store_selection', true);28 if (this.isWindow)29 window.focus();30 // Store selection31 if (this.storeSelection)32 tinyMCE.selectedInstance.execCommand('mceStoreSelection');33 // Setup dir34 if (tinyMCELang['lang_dir'])35 document.dir = tinyMCELang['lang_dir'];36 // Setup title37 var re = new RegExp('{|\\\$|}', 'g');38 var title = document.title.replace(re, "");39 if (typeof tinyMCELang[title] != "undefined") {40 var divElm = document.createElement("div");41 divElm.innerHTML = tinyMCELang[title];42 document.title = divElm.innerHTML;43 if (tinyMCE.setWindowTitle != null)44 tinyMCE.setWindowTitle(window, divElm.innerHTML);45 }46 // Output Popup CSS class47 document.write('<link href="' + tinyMCE.getParam("popups_css") + '" rel="stylesheet" type="text/css">');48 tinyMCE.addEvent(window, "load", this.onLoad);49};50TinyMCEPopup.prototype.onLoad = function() {51 var body = document.body;52 body.onkeydown = function (e) {53 e = e ? e : window.event;54 if ( e.keyCode == 27 && !e.shiftKey && !e.controlKey && !e.altKey ) {55 tinyMCEPopup.close();56 }57 }58 if (tinyMCE.getWindowArg('mce_replacevariables', true))59 body.innerHTML = tinyMCE.applyTemplate(body.innerHTML, tinyMCE.windowArgs);60 var dir = tinyMCE.selectedInstance.settings['directionality'];61 if (dir == "rtl") {62 var elms = document.forms[0].elements;63 for (var i=0; i<elms.length; i++) {64 if ((elms[i].type == "text" || elms[i].type == "textarea") && elms[i].getAttribute("dir") != "ltr")65 elms[i].dir = dir;66 }67 }68 if (body.style.display == 'none')69 body.style.display = 'block';70 // Execute real onload (Opera fix)71 if (tinyMCEPopup.onLoadEval != "") {72 eval(tinyMCEPopup.onLoadEval);73 }74};75TinyMCEPopup.prototype.executeOnLoad = function(str) {76 if (tinyMCE.isOpera)77 this.onLoadEval = str;78 else79 eval(str);80};81TinyMCEPopup.prototype.resizeToInnerSize = function() {82 // Netscape 7.1 workaround83 if (this.isWindow && tinyMCE.isNS71) {84 window.resizeBy(0, 10);85 return;86 }87 if (this.isWindow) {88 var doc = document;89 var body = doc.body;90 var oldMargin, wrapper, iframe, nodes, dx, dy;91 if (body.style.display == 'none')92 body.style.display = 'block';93 // Remove margin94 oldMargin = body.style.margin;95 body.style.margin = '0px';96 // Create wrapper97 wrapper = doc.createElement("div");98 wrapper.id = 'mcBodyWrapper';99 wrapper.style.display = 'none';100 wrapper.style.margin = '0px';101 // Wrap body elements102 nodes = doc.body.childNodes;103 for (var i=nodes.length-1; i>=0; i--) {104 if (wrapper.hasChildNodes())105 wrapper.insertBefore(nodes[i].cloneNode(true), wrapper.firstChild);106 else107 wrapper.appendChild(nodes[i].cloneNode(true));108 nodes[i].parentNode.removeChild(nodes[i]);109 }110 // Add wrapper111 doc.body.appendChild(wrapper);112 // Create iframe113 iframe = document.createElement("iframe");114 iframe.id = "mcWinIframe";115 iframe.src = document.location.href.toLowerCase().indexOf('https') == -1 ? "about:blank" : tinyMCE.settings['default_document'];116 iframe.width = "100%";117 iframe.height = "100%";118 iframe.style.margin = '0px';119 // Add iframe120 doc.body.appendChild(iframe);121 // Measure iframe122 iframe = document.getElementById('mcWinIframe');123 dx = tinyMCE.getWindowArg('mce_width') - iframe.clientWidth;124 dy = tinyMCE.getWindowArg('mce_height') - iframe.clientHeight;125 // Resize window126 // tinyMCE.debug(tinyMCE.getWindowArg('mce_width') + "," + tinyMCE.getWindowArg('mce_height') + " - " + dx + "," + dy);127 window.resizeBy(dx, dy);128 // Hide iframe and show wrapper129 body.style.margin = oldMargin;130 iframe.style.display = 'none';131 wrapper.style.display = 'block';132 }133};134TinyMCEPopup.prototype.resizeToContent = function() {135 var isMSIE = (navigator.appName == "Microsoft Internet Explorer");136 var isOpera = (navigator.userAgent.indexOf("Opera") != -1);137 if (isOpera)138 return;139 if (isMSIE) {140 try { window.resizeTo(10, 10); } catch (e) {}141 var elm = document.body;142 var width = elm.offsetWidth;143 var height = elm.offsetHeight;144 var dx = (elm.scrollWidth - width) + 4;145 var dy = elm.scrollHeight - height;146 try { window.resizeBy(dx, dy); } catch (e) {}147 } else {148 window.scrollBy(1000, 1000);149 if (window.scrollX > 0 || window.scrollY > 0) {150 window.resizeBy(window.innerWidth * 2, window.innerHeight * 2);151 window.sizeToContent();152 window.scrollTo(0, 0);153 var x = parseInt(screen.width / 2.0) - (window.outerWidth / 2.0);154 var y = parseInt(screen.height / 2.0) - (window.outerHeight / 2.0);155 window.moveTo(x, y);156 }157 }158};159TinyMCEPopup.prototype.getWindowArg = function(name, default_value) {160 return tinyMCE.getWindowArg(name, default_value);161};162TinyMCEPopup.prototype.execCommand = function(command, user_interface, value) {163 var inst = tinyMCE.selectedInstance;164 // Restore selection165 if (this.storeSelection) {166 inst.getWin().focus();167 inst.execCommand('mceRestoreSelection');168 }169 inst.execCommand(command, user_interface, value);170 // Store selection171 if (this.storeSelection)172 inst.execCommand('mceStoreSelection');173};174TinyMCEPopup.prototype.close = function() {175 tinyMCE.closeWindow(window);176};177TinyMCEPopup.prototype.pickColor = function(e, element_id) {178 tinyMCE.selectedInstance.execCommand('mceColorPicker', true, {179 element_id : element_id,180 document : document,181 window : window,182 store_selection : false183 });184};185TinyMCEPopup.prototype.openBrowser = function(element_id, type, option) {186 var cb = tinyMCE.getParam(option, tinyMCE.getParam("file_browser_callback"));187 var url = document.getElementById(element_id).value;188 tinyMCE.setWindowArg("window", window);189 tinyMCE.setWindowArg("document", document);190 // Call to external callback191 if (eval('typeof(tinyMCEPopup.windowOpener.' + cb + ')') == "undefined")192 alert("Callback function: " + cb + " could not be found.");193 else194 eval("tinyMCEPopup.windowOpener." + cb + "(element_id, url, type, window);");195};196// Setup global instance197var tinyMCEPopup = new TinyMCEPopup();...

Full Screen

Full Screen

en.js

Source:en.js Github

copy

Full Screen

1// UK lang variables2if (navigator.userAgent.indexOf('Mac OS') != -1) {3// Mac OS browsers use Ctrl to hit accesskeys4 var metaKey = 'Ctrl';5}6else {7 var metaKey = 'Alt';8}9tinyMCELang['lang_bold_desc'] = 'Bold (' + metaKey + '+b)';10tinyMCELang['lang_italic_desc'] = 'Italic (' + metaKey + '+i)';11tinyMCELang['lang_underline_desc'] = 'Underline';12tinyMCELang['lang_striketrough_desc'] = 'Striketrough (' + metaKey + '-d)';13tinyMCELang['lang_justifyleft_desc'] = 'Align left (' + metaKey + '-f)';14tinyMCELang['lang_justifycenter_desc'] = 'Align center (' + metaKey + '-c)';15tinyMCELang['lang_justifyright_desc'] = 'Align right (' + metaKey + '-r)';16tinyMCELang['lang_justifyfull_desc'] = 'Align full';17tinyMCELang['lang_bullist_desc'] = 'Unordered list (' + metaKey + '-l)';18tinyMCELang['lang_numlist_desc'] = 'Ordered list (' + metaKey + '-o)';19tinyMCELang['lang_outdent_desc'] = 'Outdent (' + metaKey + '-w)';20tinyMCELang['lang_indent_desc'] = 'Indent/Blockquote (' + metaKey + '-q)';21tinyMCELang['lang_undo_desc'] = 'Undo (' + metaKey + '-u)';22tinyMCELang['lang_redo_desc'] = 'Redo (' + metaKey + '-y)';23tinyMCELang['lang_link_desc'] = 'Insert/edit link (' + metaKey + '-a)';24tinyMCELang['lang_unlink_desc'] = 'Unlink (' + metaKey + '-s)';25tinyMCELang['lang_image_desc'] = 'Insert/edit image (' + metaKey + '-m)';26tinyMCELang['lang_cleanup_desc'] = 'Cleanup messy code';27tinyMCELang['lang_focus_alert'] = 'A editor instance must be focused before using this command.';28tinyMCELang['lang_edit_confirm'] = 'Do you want to use the WYSIWYG mode for this textarea?';29tinyMCELang['lang_insert_link_title'] = 'Insert/edit link';30tinyMCELang['lang_insert'] = 'Insert';31tinyMCELang['lang_update'] = 'Update';32tinyMCELang['lang_cancel'] = 'Cancel';33tinyMCELang['lang_insert_link_url'] = 'Link URL';34tinyMCELang['lang_insert_link_target'] = 'Target';35tinyMCELang['lang_insert_link_target_same'] = 'Open link in the same window';36tinyMCELang['lang_insert_link_target_blank'] = 'Open link in a new window';37tinyMCELang['lang_insert_image_title'] = 'Insert/edit image';38tinyMCELang['lang_insert_image_src'] = 'Image URL';39tinyMCELang['lang_insert_image_alt'] = 'Image description';40tinyMCELang['lang_help_desc'] = 'Help';41tinyMCELang['lang_bold_img'] = "bold.gif";42tinyMCELang['lang_italic_img'] = "italic.gif";43tinyMCELang['lang_underline_img'] = "underline.gif";44tinyMCELang['lang_clipboard_msg'] = 'Copy/Cut/Paste is not available in Mozilla and Firefox.\nDo you want more information about this issue?';...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Tiny } from 'storybook-root'2import { Tiny } from 'storybook-root'3import { Tiny } from 'storybook-root'4import { Tiny } from 'storybook-root'5import { Tiny } from 'storybook-root'6import { Tiny } from 'storybook-root'7import { Tiny } from 'storybook-root'8import { Tiny } from 'storybook-root'9import { Tiny } from 'storybook-root'10import { Tiny } from 'storybook-root'11import { Tiny } from 'storybook-root'12import { Tiny } from 'storybook-root'13import { Tiny } from 'storybook-root'14import { Tiny } from 'storybook-root'15import { Tiny } from 'storybook-root'16import { Tiny } from 'storybook-root'17import { Tiny } from 'storybook-root'18import { Tiny } from 'storybook-root'19import { Tiny } from 'storybook-root'20import { Tiny } from 'storybook-root'21import { Tiny } from 'storybook-root'22import { Tiny } from 'storybook-root'

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Tiny } from 'storybook-root';2Tiny('Hello World!');3import { Tiny } from 'storybook-root';4Tiny('Hello World 2!');5import { Tiny } from 'storybook-root';6Tiny('Hello World 3!');7import { Tiny } from 'storybook-root';8Tiny('Hello World 4!');9import { Tiny } from 'storybook-root';10Tiny('Hello World 5!');11import { Tiny } from 'storybook-root';12Tiny('Hello World 6!');13import { Tiny } from 'storybook-root';14Tiny('Hello World 7!');15import { Tiny } from 'storybook-root';16Tiny('Hello World 8!');17import { Tiny } from 'storybook-root';18Tiny('Hello World 9!');19import { Tiny } from 'storybook-root';20Tiny('Hello World 10!');21import { Tiny } from 'storybook-root';22Tiny('Hello World 11!');23import { Tiny } from 'storybook-root';24Tiny('Hello World 12!');25import { Tiny } from 'storybook-root';26Tiny('Hello World 13!');27import { Tiny } from 'storybook-root';28Tiny('Hello World 14!');29import { Tiny } from 'storybook-root';30Tiny('

Full Screen

Using AI Code Generation

copy

Full Screen

1import Tiny from 'storybook-root/tiny';2const tiny = new Tiny();3tiny.tiny();4const tiny = new Tiny();5tiny.tiny();6const tiny = new Tiny();7tiny.tiny();8const tiny = new Tiny();9tiny.tiny();10const tiny = new Tiny();11tiny.tiny();12const tiny = new Tiny();13tiny.tiny();14const tiny = new Tiny();15tiny.tiny();16const tiny = new Tiny();17tiny.tiny();

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2storybookRoot('Tiny');3const storybookRoot = require('storybook-root');4storybookRoot('Huge');5const storybookRoot = require('storybook-root');6storybookRoot('Tiny');7const storybookRoot = require('storybook-root');8storybookRoot('Huge');9const storybookRoot = module.require('storybook-root');10const path = require('path');11const fs = require('fs');12const storybookRoot = (size) => {13 const storybookRoot = module.require('storybook-root');14 const storybookRootPath = storybookRoot(size);15 const storybookRootPathWithNodeModules = path.join(storybookRootPath, 'node_modules');16 const storybookRootPathWithNodeModulesExists = fs.existsSync(storybookRootPathWithNodeModules);17 if (!storybookRootPathWithNodeModulesExists) {18 fs.mkdirSync(storybookRootPathWithNodeModules);19 }20 return storybookRootPath;21};22module.exports = storybookRoot;23{24 "dependencies": {25 }26}

Full Screen

Using AI Code Generation

copy

Full Screen

1Tiny('storybook-root', {2});3storiesOf('Test', module)4 .add('Test', () => {5 return '<test></test>';6 });

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Tiny } from 'storybook-root'2Tiny({3 component: () => {4 },5 options: {6 },7})8import { Tiny } from 'storybook-root'9Tiny({10 component: () => {11 },12 options: {13 },14})15import { Tiny } from 'storybook-root'16Tiny({17 component: () => {18 },19 options: {20 },21})22import { Tiny } from 'storybook-root'23Tiny({24 component: () => {25 },26 options: {27 },28})29import { Tiny } from 'storybook-root'30Tiny({31 component: () => {32 },33 options: {34 },35})36import { Tiny } from 'storybook-root'37Tiny({38 component: () => {39 },40 options: {41 },42})43import { configure } from '@storybook/react'44import { setupRoot } from 'storybook-root'45setupRoot({46})47configure(require.context('../src', true, /\.stories\.js$/), module)48import { configure } from '@storybook/react'

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Tiny } = require('@storybook/addon-storyshots-puppeteer');2Tiny.initPage();3Tiny.renderStory('Button', 'with text');4Tiny.takeSnapshots();5Tiny.cleanup();6Tiny.getStorybook().then(storybook => {7 console.log(JSON.stringify(storybook, null, 2));8});9Tiny.getStorybookUI().then(storybookUI => {10 console.log(storybookUI);11});12Tiny.getStorybookUI({ port: 9001, host: 'localhost' }).then(storybookUI => {13 console.log(storybookUI);14});15Tiny.getStorybookUI({ port: 9001, host: 'localhost', ssl: true }).then(16 storybookUI => {17 console.log(storybookUI);18 }19);20Tiny.getStorybookUI({ port: 9001, host: 'localhost', ssl: true, staticDir: 'dist' }).then(21 storybookUI => {22 console.log(storybookUI);23 }24);25Tiny.getStorybookUI({ port: 9001, host: 'localhost', ssl: true, staticDir: 'dist', sslCert: 'cert.pem', sslKey: 'key.pem' }).then(

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful