/static/scripts/tiny_mce/plugins/directionality/editor_plugin_src.js

http://n23.googlecode.com/ · JavaScript · 79 lines · 55 code · 16 blank · 8 comment · 9 complexity · 70a7c1cb13648399510653e5457374a7 MD5 · raw file

  1. /**
  2. * $Id: editor_plugin_src.js 520 2008-01-07 16:30:32Z spocke $
  3. *
  4. * @author Moxiecode
  5. * @copyright Copyright Š 2004-2008, Moxiecode Systems AB, All rights reserved.
  6. */
  7. (function() {
  8. tinymce.create('tinymce.plugins.Directionality', {
  9. init : function(ed, url) {
  10. var t = this;
  11. t.editor = ed;
  12. ed.addCommand('mceDirectionLTR', function() {
  13. var e = ed.dom.getParent(ed.selection.getNode(), ed.dom.isBlock);
  14. if (e) {
  15. if (ed.dom.getAttrib(e, "dir") != "ltr")
  16. ed.dom.setAttrib(e, "dir", "ltr");
  17. else
  18. ed.dom.setAttrib(e, "dir", "");
  19. }
  20. ed.nodeChanged();
  21. });
  22. ed.addCommand('mceDirectionRTL', function() {
  23. var e = ed.dom.getParent(ed.selection.getNode(), ed.dom.isBlock);
  24. if (e) {
  25. if (ed.dom.getAttrib(e, "dir") != "rtl")
  26. ed.dom.setAttrib(e, "dir", "rtl");
  27. else
  28. ed.dom.setAttrib(e, "dir", "");
  29. }
  30. ed.nodeChanged();
  31. });
  32. ed.addButton('ltr', {title : 'directionality.ltr_desc', cmd : 'mceDirectionLTR'});
  33. ed.addButton('rtl', {title : 'directionality.rtl_desc', cmd : 'mceDirectionRTL'});
  34. ed.onNodeChange.add(t._nodeChange, t);
  35. },
  36. getInfo : function() {
  37. return {
  38. longname : 'Directionality',
  39. author : 'Moxiecode Systems AB',
  40. authorurl : 'http://tinymce.moxiecode.com',
  41. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',
  42. version : tinymce.majorVersion + "." + tinymce.minorVersion
  43. };
  44. },
  45. // Private methods
  46. _nodeChange : function(ed, cm, n) {
  47. var dom = ed.dom, dir;
  48. n = dom.getParent(n, dom.isBlock);
  49. if (!n) {
  50. cm.setDisabled('ltr', 1);
  51. cm.setDisabled('rtl', 1);
  52. return;
  53. }
  54. dir = dom.getAttrib(n, 'dir');
  55. cm.setActive('ltr', dir == "ltr");
  56. cm.setDisabled('ltr', 0);
  57. cm.setActive('rtl', dir == "rtl");
  58. cm.setDisabled('rtl', 0);
  59. }
  60. });
  61. // Register plugin
  62. tinymce.PluginManager.add('directionality', tinymce.plugins.Directionality);
  63. })();