A tumblelog CMS built on AJAX, PHP and MySQL.

editor_plugin_src.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
  3. *
  4. * @author Moxiecode
  5. * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
  6. */
  7. /* Import plugin specific language pack */
  8. tinyMCE.importPluginLanguagePack('directionality');
  9. var TinyMCE_DirectionalityPlugin = {
  10. getInfo : function() {
  11. return {
  12. longname : 'Directionality',
  13. author : 'Moxiecode Systems AB',
  14. authorurl : 'http://tinymce.moxiecode.com',
  15. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/directionality',
  16. version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
  17. };
  18. },
  19. getControlHTML : function(cn) {
  20. switch (cn) {
  21. case "ltr":
  22. return tinyMCE.getButtonHTML(cn, 'lang_directionality_ltr_desc', '{$pluginurl}/images/ltr.gif', 'mceDirectionLTR');
  23. case "rtl":
  24. return tinyMCE.getButtonHTML(cn, 'lang_directionality_rtl_desc', '{$pluginurl}/images/rtl.gif', 'mceDirectionRTL');
  25. }
  26. return "";
  27. },
  28. execCommand : function(editor_id, element, command, user_interface, value) {
  29. // Handle commands
  30. switch (command) {
  31. case "mceDirectionLTR":
  32. var inst = tinyMCE.getInstanceById(editor_id);
  33. var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address");
  34. if (elm)
  35. elm.setAttribute("dir", "ltr");
  36. tinyMCE.triggerNodeChange(false);
  37. return true;
  38. case "mceDirectionRTL":
  39. var inst = tinyMCE.getInstanceById(editor_id);
  40. var elm = tinyMCE.getParentElement(inst.getFocusElement(), "p,div,td,h1,h2,h3,h4,h5,h6,pre,address");
  41. if (elm)
  42. elm.setAttribute("dir", "rtl");
  43. tinyMCE.triggerNodeChange(false);
  44. return true;
  45. }
  46. // Pass to next handler in chain
  47. return false;
  48. },
  49. handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
  50. function getAttrib(elm, name) {
  51. return elm.getAttribute(name) ? elm.getAttribute(name) : "";
  52. }
  53. if (node == null)
  54. return;
  55. var elm = tinyMCE.getParentElement(node, "p,div,td,h1,h2,h3,h4,h5,h6,pre,address");
  56. if (!elm) {
  57. tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonDisabled');
  58. tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonDisabled');
  59. return true;
  60. }
  61. tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonNormal');
  62. tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonNormal');
  63. var dir = getAttrib(elm, "dir");
  64. if (dir == "ltr" || dir == "")
  65. tinyMCE.switchClass(editor_id + '_ltr', 'mceButtonSelected');
  66. else
  67. tinyMCE.switchClass(editor_id + '_rtl', 'mceButtonSelected');
  68. return true;
  69. }
  70. };
  71. tinyMCE.addPlugin("directionality", TinyMCE_DirectionalityPlugin);