You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

64 lines
1.4 KiB

  1. /**
  2. * plugin.js
  3. *
  4. * Released under LGPL License.
  5. * Copyright (c) 1999-2015 Ephox Corp. All rights reserved
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /*global tinymce:true */
  11. tinymce.PluginManager.add('directionality', function(editor) {
  12. function setDir(dir) {
  13. var dom = editor.dom, curDir, blocks = editor.selection.getSelectedBlocks();
  14. if (blocks.length) {
  15. curDir = dom.getAttrib(blocks[0], "dir");
  16. tinymce.each(blocks, function(block) {
  17. // Add dir to block if the parent block doesn't already have that dir
  18. if (!dom.getParent(block.parentNode, "*[dir='" + dir + "']", dom.getRoot())) {
  19. if (curDir != dir) {
  20. dom.setAttrib(block, "dir", dir);
  21. } else {
  22. dom.setAttrib(block, "dir", null);
  23. }
  24. }
  25. });
  26. editor.nodeChanged();
  27. }
  28. }
  29. function generateSelector(dir) {
  30. var selector = [];
  31. tinymce.each('h1 h2 h3 h4 h5 h6 div p'.split(' '), function(name) {
  32. selector.push(name + '[dir=' + dir + ']');
  33. });
  34. return selector.join(',');
  35. }
  36. editor.addCommand('mceDirectionLTR', function() {
  37. setDir("ltr");
  38. });
  39. editor.addCommand('mceDirectionRTL', function() {
  40. setDir("rtl");
  41. });
  42. editor.addButton('ltr', {
  43. title: 'Left to right',
  44. cmd: 'mceDirectionLTR',
  45. stateSelector: generateSelector('ltr')
  46. });
  47. editor.addButton('rtl', {
  48. title: 'Right to left',
  49. cmd: 'mceDirectionRTL',
  50. stateSelector: generateSelector('rtl')
  51. });
  52. });