5 * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.
9 var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is;
11 tinymce.create('tinymce.plugins.Compat2x', {
12 getInfo : function() {
14 longname : 'Compat2x',
15 author : 'Moxiecode Systems AB',
16 authorurl : 'http://tinymce.moxiecode.com',
17 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/compat2x',
18 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
24 // Extend tinyMCE/EditorManager
25 tinymce.extend(tinyMCE, {
26 addToLang : function(p, l) {
27 each(l, function(v, k) {
28 tinyMCE.i18n[(tinyMCE.settings.language || 'en') + '.' + (p ? p + '_' : '') + k] = v;
32 getInstanceById : function(n) {
39 var EditorManager = tinymce.EditorManager;
41 tinyMCE.instances = {};
43 tinymce.PluginManager.onAdd.add(function(pm, n, p) {
44 tinyMCE.plugins[n] = p;
47 tinyMCE.majorVersion = tinymce.majorVersion;
48 tinyMCE.minorVersion = tinymce.minorVersion;
49 tinyMCE.releaseDate = tinymce.releaseDate;
50 tinyMCE.baseURL = tinymce.baseURL;
51 tinyMCE.isIE = tinyMCE.isMSIE = tinymce.isIE || tinymce.isOpera;
52 tinyMCE.isMSIE5 = tinymce.isIE;
53 tinyMCE.isMSIE5_0 = tinymce.isIE;
54 tinyMCE.isMSIE7 = tinymce.isIE;
55 tinyMCE.isGecko = tinymce.isGecko;
56 tinyMCE.isSafari = tinymce.isWebKit;
57 tinyMCE.isOpera = tinymce.isOpera;
58 tinyMCE.isMac = false;
59 tinyMCE.isNS7 = false;
60 tinyMCE.isNS71 = false;
61 tinyMCE.compat = true;
63 // Extend tinyMCE class
64 TinyMCE_Engine = tinyMCE;
65 tinymce.extend(tinyMCE, {
66 getParam : function(n, dv) {
67 return this.activeEditor.getParam(n, dv);
70 addEvent : function(e, na, f, sc) {
71 tinymce.dom.Event.add(e, na, f, sc || this);
74 getControlHTML : function(n) {
75 return EditorManager.activeEditor.controlManager.createControl(n);
78 loadCSS : function(u) {
79 tinymce.DOM.loadCSS(u);
82 importCSS : function(doc, u) {
86 new tinymce.dom.DOMUtils(doc).loadCSS(u);
90 console.debug.apply(console, arguments);
93 getLang : function(n, dv) {
94 var v = EditorManager.activeEditor.getLang(n.replace(/^lang_/g, ''), dv);
97 if (/^[0-9\-.]+$/g.test(v))
103 isInstance : function(o) {
104 return o != null && typeof(o) == "object" && o.execCommand;
107 triggerNodeChange : function() {
108 EditorManager.activeEditor.nodeChanged();
111 regexpReplace : function(in_str, reg_exp, replace_str, opts) {
117 if (typeof(opts) == "undefined")
120 re = new RegExp(reg_exp, opts);
122 return in_str.replace(re, replace_str);
126 return tinymce.trim(s);
129 xmlEncode : function(s) {
130 return tinymce.DOM.encode(s);
133 explode : function(s, d) {
136 tinymce.each(s.split(d), function(v) {
144 switchClass : function(id, cls) {
147 if (/^mceButton/.test(cls)) {
148 b = EditorManager.activeEditor.controlManager.get(id);
154 case "mceButtonNormal":
155 b.setDisabled(false);
159 case "mceButtonDisabled":
163 case "mceButtonSelected":
165 b.setDisabled(false);
171 addCSSClass : function(e, n, b) {
172 return tinymce.DOM.addClass(e, n, b);
175 hasCSSClass : function(e, n) {
176 return tinymce.DOM.hasClass(e, n);
179 removeCSSClass : function(e, n) {
180 return tinymce.DOM.removeClass(e, n);
183 getCSSClasses : function() {
184 var cl = EditorManager.activeEditor.dom.getClasses(), o = [];
186 each(cl, function(c) {
193 setWindowArg : function(n, v) {
194 EditorManager.activeEditor.windowManager.params[n] = v;
197 getWindowArg : function(n, dv) {
198 var wm = EditorManager.activeEditor.windowManager, v;
204 return v || wm.getFeature(n) || dv;
207 getParentNode : function(n, f) {
208 return this._getDOM().getParent(n, f);
211 selectElements : function(n, na, f) {
212 var i, a = [], nl, x;
214 for (x=0, na = na.split(','); x<na.length; x++)
215 for (i=0, nl = n.getElementsByTagName(na[x]); i<nl.length; i++)
216 (!f || f(nl[i])) && a.push(nl[i]);
221 getNodeTree : function(n, na, t, nn) {
222 return this.selectNodes(n, function(n) {
223 return (!t || n.nodeType == t) && (!nn || n.nodeName == nn);
227 getAttrib : function(e, n, dv) {
228 return this._getDOM().getAttrib(e, n, dv);
231 setAttrib : function(e, n, v) {
232 return this._getDOM().setAttrib(e, n, v);
235 getElementsByAttributeValue : function(n, e, a, v) {
236 var i, nl = n.getElementsByTagName(e), o = [];
238 for (i=0; i<nl.length; i++) {
239 if (tinyMCE.getAttrib(nl[i], a).indexOf(v) != -1)
246 selectNodes : function(n, f, a) {
255 if (n.hasChildNodes()) {
256 for (i=0; i<n.childNodes.length; i++)
257 tinyMCE.selectNodes(n.childNodes[i], f, a);
263 getContent : function() {
264 return EditorManager.activeEditor.getContent();
267 getParentElement : function(n, na, f) {
269 na = new RegExp('^(' + na.toUpperCase().replace(/,/g, '|') + ')$', 'g');
271 return this._getDOM().getParent(n, function(n) {
272 return n.nodeType == 1 && (!na || na.test(n.nodeName)) && (!f || f(n));
273 }, this.activeEditor.getBody());
276 importPluginLanguagePack : function(n) {
277 tinymce.PluginManager.requireLangPack(n);
280 getButtonHTML : function(cn, lang, img, c, u, v) {
281 var ed = EditorManager.activeEditor;
283 img = img.replace(/\{\$pluginurl\}/g, tinyMCE.pluginURL);
284 img = img.replace(/\{\$themeurl\}/g, tinyMCE.themeURL);
285 lang = lang.replace(/^lang_/g, '');
287 return ed.controlManager.createButton(cn, {
298 addSelectAccessibility : function(e, s, w) {
299 // Add event handlers
300 if (!s._isAccessible) {
301 s.onkeydown = tinyMCE.accessibleEventHandler;
302 s.onblur = tinyMCE.accessibleEventHandler;
303 s._isAccessible = true;
310 accessibleEventHandler : function(e) {
311 var elm, win = this._win;
313 e = tinymce.isIE ? win.event : e;
314 elm = tinymce.isIE ? e.srcElement : e.target;
316 // Unpiggyback onchange on blur
317 if (e.type == "blur") {
318 if (elm.oldonchange) {
319 elm.onchange = elm.oldonchange;
320 elm.oldonchange = null;
326 // Piggyback onchange
327 if (elm.nodeName == "SELECT" && !elm.oldonchange) {
328 elm.oldonchange = elm.onchange;
332 // Execute onchange and remove piggyback
333 if (e.keyCode == 13 || e.keyCode == 32) {
334 elm.onchange = elm.oldonchange;
336 elm.oldonchange = null;
338 tinyMCE.cancelEvent(e);
345 cancelEvent : function(e) {
346 return tinymce.dom.Event.cancel(e);
349 handleVisualAid : function(e) {
350 EditorManager.activeEditor.addVisual(e);
353 getAbsPosition : function(n, r) {
354 return tinymce.DOM.getPos(n, r);
357 cleanupEventStr : function(s) {
359 s = s.replace('function anonymous()\n{\n', '');
360 s = s.replace('\n}', '');
361 s = s.replace(/^return true;/gi, ''); // Remove event blocker
366 getVisualAidClass : function(s) {
371 parseStyle : function(s) {
372 return this._getDOM().parseStyle(s);
375 serializeStyle : function(s) {
376 return this._getDOM().serializeStyle(s);
379 openWindow : function(tpl, args) {
380 var ed = EditorManager.activeEditor, o = {}, n;
382 // Convert name/value array to object
389 tpl.url = new tinymce.util.URI(tinymce.ThemeManager.themeURLs[ed.settings.theme]).toAbsolute(tpl.file);
390 tpl.inline = tpl.inline || args.inline;
392 ed.windowManager.open(tpl, args);
395 closeWindow : function(win) {
396 EditorManager.activeEditor.windowManager.close(win);
399 getOuterHTML : function(e) {
400 return tinymce.DOM.getOuterHTML(e);
403 setOuterHTML : function(e, h, d) {
404 return tinymce.DOM.setOuterHTML(e, h, d);
407 hasPlugin : function(n) {
408 return tinymce.PluginManager.get(n) != null;
411 _setEventsEnabled : function() {
415 addPlugin : function(pn, f) {
418 function PluginWrapper(ed) {
419 tinyMCE.selectedInstance = ed;
421 ed.onInit.add(function() {
422 t.settings = ed.settings;
423 t.settings['base_href'] = tinyMCE.documentBasePath;
424 tinyMCE.settings = t.settings;
425 tinyMCE.documentBasePath = ed.documentBasePath;
426 //ed.formElement = DOM.get(ed.id);
431 ed.contentDocument = ed.getDoc();
432 ed.contentWindow = ed.getWin();
433 ed.undoRedo = ed.undoManager;
434 ed.startContent = ed.getContent({format : 'raw'});
436 tinyMCE.instances[ed.id] = ed;
437 tinyMCE.loadedFiles = [];
440 ed.onActivate.add(function() {
441 tinyMCE.settings = ed.settings;
442 tinyMCE.selectedInstance = ed;
445 /* if (f.removeInstance) {
446 ed.onDestroy.add(function() {
447 return f.removeInstance(ed.id);
451 if (f.handleNodeChange) {
452 ed.onNodeChange.add(function(ed, cm, n) {
453 f.handleNodeChange(ed.id, n, 0, 0, false, !ed.selection.isCollapsed());
458 ed.onChange.add(function(ed, n) {
459 return f.onChange(ed);
464 ed.onGetContent.add(function() {
465 //f.cleanup(type, content, inst);
469 this.getInfo = function() {
473 this.createControl = function(n) {
474 tinyMCE.pluginURL = tinymce.baseURL + '/plugins/' + pn;
475 tinyMCE.themeURL = tinymce.baseURL + '/themes/' + tinyMCE.activeEditor.settings.theme;
477 if (f.getControlHTML)
478 return f.getControlHTML(n);
483 this.execCommand = function(cmd, ui, val) {
485 return f.execCommand(ed.id, ed.getBody(), cmd, ui, val);
491 tinymce.PluginManager.add(pn, PluginWrapper);
494 _getDOM : function() {
495 return tinyMCE.activeEditor ? tinyMCE.activeEditor.dom : tinymce.DOM;
498 convertRelativeToAbsoluteURL : function(b, u) {
499 return new tinymce.util.URI(b).toAbsolute(u);
502 convertAbsoluteURLToRelativeURL : function(b, u) {
503 return new tinymce.util.URI(b).toRelative(u);
507 // Extend Editor class
508 tinymce.extend(tinymce.Editor.prototype, {
509 getFocusElement : function() {
510 return this.selection.getNode();
513 getData : function(n) {
523 hasPlugin : function(n) {
524 return this.plugins[n] != null;
527 getContainerWin : function() {
531 getHTML : function(raw) {
532 return this.getContent({ format : raw ? 'raw' : 'html'});
535 setHTML : function(h) {
539 getSel : function() {
540 return this.selection.getSel();
543 getRng : function() {
544 return this.selection.getRng();
547 isHidden : function() {
550 if (!tinymce.isGecko)
555 // Weird, wheres that cursor selection?
556 return (!s || !s.rangeCount || s.rangeCount == 0);
559 translate : function(s) {
560 var c = this.settings.language, o;
565 o = tinymce.EditorManager.i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) {
566 return tinymce.EditorManager.i18n[c + '.' + b] || '{#' + b + '}';
569 o = o.replace(/{\$lang_([^}]+)\}/g, function(a, b) {
570 return tinymce.EditorManager.i18n[c + '.' + b] || '{$lang_' + b + '}';
576 repaint : function() {
577 this.execCommand('mceRepaint');
582 tinymce.extend(tinymce.dom.Selection.prototype, {
583 getSelectedText : function() {
584 return this.getContent({format : 'text'});
587 getSelectedHTML : function() {
588 return this.getContent({format : 'html'});
591 getFocusElement : function() {
592 return this.getNode();
595 selectNode : function(node, collapse, select_text_node, to_start) {
598 t.select(node, select_text_node || 0);
607 t.collapse(to_start);
614 tinymce.PluginManager.add('compat2x', tinymce.plugins.Compat2x);