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