PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/django/static/js/tiny_mce/plugins/compat2x/editor_plugin_src.js

https://github.com/narpaldhillon/flowgram.com
JavaScript | 613 lines | 441 code | 144 blank | 28 comment | 79 complexity | 931b031dc3a96d4801e72e4415f67b12 MD5 | raw file
  1. /**
  2. * $Id: editor_plugin_src.js 264 2007-04-26 20:53:09Z spocke $
  3. *
  4. * @author Moxiecode
  5. * @copyright Copyright � 2004-2007, Moxiecode Systems AB, All rights reserved.
  6. */
  7. (function() {
  8. var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, is = tinymce.is;
  9. tinymce.create('tinymce.plugins.Compat2x', {
  10. getInfo : function() {
  11. return {
  12. longname : 'Compat2x',
  13. author : 'Moxiecode Systems AB',
  14. authorurl : 'http://tinymce.moxiecode.com',
  15. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/compat2x',
  16. version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
  17. };
  18. }
  19. });
  20. (function() {
  21. // Extend tinyMCE/EditorManager
  22. tinymce.extend(tinyMCE, {
  23. addToLang : function(p, l) {
  24. each(l, function(v, k) {
  25. tinyMCE.i18n[(tinyMCE.settings.language || 'en') + '.' + (p ? p + '_' : '') + k] = v;
  26. });
  27. },
  28. getInstanceById : function(n) {
  29. return this.get(n);
  30. }
  31. });
  32. })();
  33. (function() {
  34. var EditorManager = tinymce.EditorManager;
  35. tinyMCE.instances = {};
  36. tinyMCE.plugins = {};
  37. tinymce.PluginManager.onAdd.add(function(pm, n, p) {
  38. tinyMCE.plugins[n] = p;
  39. });
  40. tinyMCE.majorVersion = tinymce.majorVersion;
  41. tinyMCE.minorVersion = tinymce.minorVersion;
  42. tinyMCE.releaseDate = tinymce.releaseDate;
  43. tinyMCE.baseURL = tinymce.baseURL;
  44. tinyMCE.isIE = tinyMCE.isMSIE = tinymce.isIE || tinymce.isOpera;
  45. tinyMCE.isMSIE5 = tinymce.isIE;
  46. tinyMCE.isMSIE5_0 = tinymce.isIE;
  47. tinyMCE.isMSIE7 = tinymce.isIE;
  48. tinyMCE.isGecko = tinymce.isGecko;
  49. tinyMCE.isSafari = tinymce.isWebKit;
  50. tinyMCE.isOpera = tinymce.isOpera;
  51. tinyMCE.isMac = false;
  52. tinyMCE.isNS7 = false;
  53. tinyMCE.isNS71 = false;
  54. tinyMCE.compat = true;
  55. // Extend tinyMCE class
  56. TinyMCE_Engine = tinyMCE;
  57. tinymce.extend(tinyMCE, {
  58. getParam : function(n, dv) {
  59. return this.activeEditor.getParam(n, dv);
  60. },
  61. addEvent : function(e, na, f, sc) {
  62. tinymce.dom.Event.add(e, na, f, sc || this);
  63. },
  64. getControlHTML : function(n) {
  65. return EditorManager.activeEditor.controlManager.createControl(n);
  66. },
  67. loadCSS : function(u) {
  68. tinymce.DOM.loadCSS(u);
  69. },
  70. importCSS : function(doc, u) {
  71. if (doc == document)
  72. this.loadCSS(u);
  73. else
  74. new tinymce.dom.DOMUtils(doc).loadCSS(u);
  75. },
  76. log : function() {
  77. //console.debug.apply(console, arguments);
  78. },
  79. getLang : function(n, dv) {
  80. var v = EditorManager.activeEditor.getLang(n.replace(/^lang_/g, ''), dv);
  81. // Is number
  82. if (/^[0-9\-.]+$/g.test(v))
  83. return parseInt(v);
  84. return v;
  85. },
  86. isInstance : function(o) {
  87. return o != null && typeof(o) == "object" && o.execCommand;
  88. },
  89. triggerNodeChange : function() {
  90. EditorManager.activeEditor.nodeChanged();
  91. },
  92. regexpReplace : function(in_str, reg_exp, replace_str, opts) {
  93. var re;
  94. if (in_str == null)
  95. return in_str;
  96. if (typeof(opts) == "undefined")
  97. opts = 'g';
  98. re = new RegExp(reg_exp, opts);
  99. return in_str.replace(re, replace_str);
  100. },
  101. trim : function(s) {
  102. return tinymce.trim(s);
  103. },
  104. xmlEncode : function(s) {
  105. return tinymce.DOM.encode(s);
  106. },
  107. explode : function(s, d) {
  108. var o = [];
  109. tinymce.each(s.split(d), function(v) {
  110. if (v != '')
  111. o.push(v);
  112. });
  113. return o;
  114. },
  115. switchClass : function(id, cls) {
  116. var b;
  117. if (/^mceButton/.test(cls)) {
  118. b = EditorManager.activeEditor.controlManager.get(id);
  119. if (!b)
  120. return;
  121. switch (cls) {
  122. case "mceButtonNormal":
  123. b.setDisabled(false);
  124. b.setActive(false);
  125. return;
  126. case "mceButtonDisabled":
  127. b.setDisabled(true);
  128. return;
  129. case "mceButtonSelected":
  130. b.setActive(true);
  131. b.setDisabled(false);
  132. return;
  133. }
  134. }
  135. },
  136. addCSSClass : function(e, n, b) {
  137. return tinymce.DOM.addClass(e, n, b);
  138. },
  139. hasCSSClass : function(e, n) {
  140. return tinymce.DOM.hasClass(e, n);
  141. },
  142. removeCSSClass : function(e, n) {
  143. return tinymce.DOM.removeClass(e, n);
  144. },
  145. getCSSClasses : function() {
  146. var cl = EditorManager.activeEditor.dom.getClasses(), o = [];
  147. each(cl, function(c) {
  148. o.push(c['class']);
  149. });
  150. return o;
  151. },
  152. setWindowArg : function(n, v) {
  153. EditorManager.activeEditor.windowManager.params[n] = v;
  154. },
  155. getWindowArg : function(n, dv) {
  156. var wm = EditorManager.activeEditor.windowManager, v;
  157. v = wm.getParam(n);
  158. if (v === '')
  159. return '';
  160. return v || wm.getFeature(n) || dv;
  161. },
  162. getParentNode : function(n, f) {
  163. return this._getDOM().getParent(n, f);
  164. },
  165. selectElements : function(n, na, f) {
  166. var i, a = [], nl, x;
  167. for (x=0, na = na.split(','); x<na.length; x++)
  168. for (i=0, nl = n.getElementsByTagName(na[x]); i<nl.length; i++)
  169. (!f || f(nl[i])) && a.push(nl[i]);
  170. return a;
  171. },
  172. getNodeTree : function(n, na, t, nn) {
  173. return this.selectNodes(n, function(n) {
  174. return (!t || n.nodeType == t) && (!nn || n.nodeName == nn);
  175. }, na ? na : []);
  176. },
  177. getAttrib : function(e, n, dv) {
  178. return this._getDOM().getAttrib(e, n, dv);
  179. },
  180. setAttrib : function(e, n, v) {
  181. return this._getDOM().setAttrib(e, n, v);
  182. },
  183. getElementsByAttributeValue : function(n, e, a, v) {
  184. var i, nl = n.getElementsByTagName(e), o = [];
  185. for (i=0; i<nl.length; i++) {
  186. if (tinyMCE.getAttrib(nl[i], a).indexOf(v) != -1)
  187. o[o.length] = nl[i];
  188. }
  189. return o;
  190. },
  191. selectNodes : function(n, f, a) {
  192. var i;
  193. if (!a)
  194. a = [];
  195. if (f(n))
  196. a[a.length] = n;
  197. if (n.hasChildNodes()) {
  198. for (i=0; i<n.childNodes.length; i++)
  199. tinyMCE.selectNodes(n.childNodes[i], f, a);
  200. }
  201. return a;
  202. },
  203. getContent : function() {
  204. return EditorManager.activeEditor.getContent();
  205. },
  206. getParentElement : function(n, na, f) {
  207. if (na)
  208. na = new RegExp('^(' + na.toUpperCase().replace(/,/g, '|') + ')$', 'g');
  209. return this._getDOM().getParent(n, function(n) {
  210. return n.nodeType == 1 && (!na || na.test(n.nodeName)) && (!f || f(n));
  211. }, this.activeEditor.getBody());
  212. },
  213. importPluginLanguagePack : function(n) {
  214. tinymce.PluginManager.requireLangPack(n);
  215. },
  216. getButtonHTML : function(cn, lang, img, c, u, v) {
  217. var ed = EditorManager.activeEditor;
  218. img = img.replace(/\{\$pluginurl\}/g, tinyMCE.pluginURL);
  219. img = img.replace(/\{\$themeurl\}/g, tinyMCE.themeURL);
  220. lang = lang.replace(/^lang_/g, '');
  221. return ed.controlManager.createButton(cn, {
  222. title : lang,
  223. command : c,
  224. ui : u,
  225. value : v,
  226. scope : this,
  227. 'class' : 'compat',
  228. image : img
  229. });
  230. },
  231. addSelectAccessibility : function(e, s, w) {
  232. // Add event handlers
  233. if (!s._isAccessible) {
  234. s.onkeydown = tinyMCE.accessibleEventHandler;
  235. s.onblur = tinyMCE.accessibleEventHandler;
  236. s._isAccessible = true;
  237. s._win = w;
  238. }
  239. return false;
  240. },
  241. accessibleEventHandler : function(e) {
  242. var elm, win = this._win;
  243. e = tinymce.isIE ? win.event : e;
  244. elm = tinymce.isIE ? e.srcElement : e.target;
  245. // Unpiggyback onchange on blur
  246. if (e.type == "blur") {
  247. if (elm.oldonchange) {
  248. elm.onchange = elm.oldonchange;
  249. elm.oldonchange = null;
  250. }
  251. return true;
  252. }
  253. // Piggyback onchange
  254. if (elm.nodeName == "SELECT" && !elm.oldonchange) {
  255. elm.oldonchange = elm.onchange;
  256. elm.onchange = null;
  257. }
  258. // Execute onchange and remove piggyback
  259. if (e.keyCode == 13 || e.keyCode == 32) {
  260. elm.onchange = elm.oldonchange;
  261. elm.onchange();
  262. elm.oldonchange = null;
  263. tinyMCE.cancelEvent(e);
  264. return false;
  265. }
  266. return true;
  267. },
  268. cancelEvent : function(e) {
  269. return tinymce.dom.Event.cancel(e);
  270. },
  271. handleVisualAid : function(e) {
  272. EditorManager.activeEditor.addVisual(e);
  273. },
  274. getAbsPosition : function(n, r) {
  275. return tinymce.DOM.getPos(n, r);
  276. },
  277. cleanupEventStr : function(s) {
  278. s = "" + s;
  279. s = s.replace('function anonymous()\n{\n', '');
  280. s = s.replace('\n}', '');
  281. s = s.replace(/^return true;/gi, ''); // Remove event blocker
  282. return s;
  283. },
  284. getVisualAidClass : function(s) {
  285. // TODO: Implement
  286. return s;
  287. },
  288. parseStyle : function(s) {
  289. return this._getDOM().parseStyle(s);
  290. },
  291. serializeStyle : function(s) {
  292. return this._getDOM().serializeStyle(s);
  293. },
  294. openWindow : function(tpl, args) {
  295. var ed = EditorManager.activeEditor, o = {}, n;
  296. // Convert name/value array to object
  297. for (n in tpl)
  298. o[n] = tpl[n];
  299. tpl = o;
  300. args = args || {};
  301. tpl.url = new tinymce.util.URI(tinymce.ThemeManager.themeURLs[ed.settings.theme]).toAbsolute(tpl.file);
  302. tpl.inline = tpl.inline || args.inline;
  303. ed.windowManager.open(tpl, args);
  304. },
  305. closeWindow : function(win) {
  306. EditorManager.activeEditor.windowManager.close(win);
  307. },
  308. getOuterHTML : function(e) {
  309. return tinymce.DOM.getOuterHTML(e);
  310. },
  311. setOuterHTML : function(e, h, d) {
  312. return tinymce.DOM.setOuterHTML(e, h, d);
  313. },
  314. hasPlugin : function(n) {
  315. return tinymce.PluginManager.get(n) != null;
  316. },
  317. _setEventsEnabled : function() {
  318. // Ignore it!!
  319. },
  320. addPlugin : function(pn, f) {
  321. var t = this;
  322. function PluginWrapper(ed) {
  323. tinyMCE.selectedInstance = ed;
  324. ed.onInit.add(function() {
  325. t.settings = ed.settings;
  326. t.settings['base_href'] = tinyMCE.documentBasePath;
  327. tinyMCE.settings = t.settings;
  328. tinyMCE.documentBasePath = ed.documentBasePath;
  329. //ed.formElement = DOM.get(ed.id);
  330. if (f.initInstance)
  331. f.initInstance(ed);
  332. ed.contentDocument = ed.getDoc();
  333. ed.contentWindow = ed.getWin();
  334. ed.undoRedo = ed.undoManager;
  335. ed.startContent = ed.getContent({format : 'raw'});
  336. tinyMCE.instances[ed.id] = ed;
  337. tinyMCE.loadedFiles = [];
  338. });
  339. ed.onActivate.add(function() {
  340. tinyMCE.settings = ed.settings;
  341. tinyMCE.selectedInstance = ed;
  342. });
  343. /* if (f.removeInstance) {
  344. ed.onDestroy.add(function() {
  345. return f.removeInstance(ed.id);
  346. });
  347. }*/
  348. if (f.handleNodeChange) {
  349. ed.onNodeChange.add(function(ed, cm, n) {
  350. f.handleNodeChange(ed.id, n, 0, 0, false, !ed.selection.isCollapsed());
  351. });
  352. }
  353. if (f.onChange) {
  354. ed.onChange.add(function(ed, n) {
  355. return f.onChange(ed);
  356. });
  357. }
  358. if (f.cleanup) {
  359. ed.onGetContent.add(function() {
  360. //f.cleanup(type, content, inst);
  361. });
  362. }
  363. this.getInfo = function() {
  364. return f.getInfo();
  365. };
  366. this.createControl = function(n) {
  367. tinyMCE.pluginURL = tinymce.baseURL + '/plugins/' + pn;
  368. tinyMCE.themeURL = tinymce.baseURL + '/themes/' + tinyMCE.activeEditor.settings.theme;
  369. if (f.getControlHTML)
  370. return f.getControlHTML(n);
  371. return null;
  372. };
  373. this.execCommand = function(cmd, ui, val) {
  374. if (f.execCommand)
  375. return f.execCommand(ed.id, ed.getBody(), cmd, ui, val);
  376. return false;
  377. };
  378. };
  379. tinymce.PluginManager.add(pn, PluginWrapper);
  380. },
  381. _getDOM : function() {
  382. return tinyMCE.activeEditor ? tinyMCE.activeEditor.dom : tinymce.DOM;
  383. },
  384. convertRelativeToAbsoluteURL : function(b, u) {
  385. return new tinymce.util.URI(b).toAbsolute(u);
  386. },
  387. convertAbsoluteURLToRelativeURL : function(b, u) {
  388. return new tinymce.util.URI(b).toRelative(u);
  389. }
  390. });
  391. // Extend Editor class
  392. tinymce.extend(tinymce.Editor.prototype, {
  393. getFocusElement : function() {
  394. return this.selection.getNode();
  395. },
  396. getData : function(n) {
  397. if (!this.data)
  398. this.data = [];
  399. if (!this.data[n])
  400. this.data[n] = [];
  401. return this.data[n];
  402. },
  403. hasPlugin : function(n) {
  404. return this.plugins[n] != null;
  405. },
  406. getContainerWin : function() {
  407. return window;
  408. },
  409. getHTML : function(raw) {
  410. return this.getContent({ format : raw ? 'raw' : 'html'});
  411. },
  412. setHTML : function(h) {
  413. this.setContent(h);
  414. },
  415. getSel : function() {
  416. return this.selection.getSel();
  417. },
  418. getRng : function() {
  419. return this.selection.getRng();
  420. },
  421. isHidden : function() {
  422. var s;
  423. if (!tinymce.isGecko)
  424. return false;
  425. s = this.getSel();
  426. // Weird, wheres that cursor selection?
  427. return (!s || !s.rangeCount || s.rangeCount == 0);
  428. },
  429. translate : function(s) {
  430. var c = this.settings.language, o;
  431. o = tinymce.EditorManager.i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) {
  432. return tinymce.EditorManager.i18n[c + '.' + b] || '{#' + b + '}';
  433. });
  434. o = o.replace(/{\$lang_([^}]+)\}/g, function(a, b) {
  435. return tinymce.EditorManager.i18n[c + '.' + b] || '{$lang_' + b + '}';
  436. });
  437. return o;
  438. },
  439. repaint : function() {
  440. this.execCommand('mceRepaint');
  441. }
  442. });
  443. // Extend selection
  444. tinymce.extend(tinymce.dom.Selection.prototype, {
  445. getSelectedText : function() {
  446. return this.getContent({format : 'text'});
  447. },
  448. getSelectedHTML : function() {
  449. return this.getContent({format : 'html'});
  450. },
  451. getFocusElement : function() {
  452. return this.getNode();
  453. },
  454. selectNode : function(node, collapse, select_text_node, to_start) {
  455. var t = this;
  456. t.select(node, select_text_node || 0);
  457. if (!is(collapse))
  458. collapse = true;
  459. if (collapse) {
  460. if (!is(to_start))
  461. to_start = true;
  462. t.collapse(to_start);
  463. }
  464. }
  465. });
  466. }).call(this);
  467. // Register plugin
  468. tinymce.PluginManager.add('compat2x', tinymce.plugins.Compat2x);
  469. })();