plugin.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * plugin.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /*global tinymce:true */
  11. tinymce.PluginManager.add('nonbreaking', function(editor) {
  12. var setting = editor.getParam('nonbreaking_force_tab');
  13. editor.addCommand('mceNonBreaking', function() {
  14. editor.insertContent(
  15. (editor.plugins.visualchars && editor.plugins.visualchars.state) ?
  16. '<span class="mce-nbsp">&nbsp;</span>' : '&nbsp;'
  17. );
  18. editor.dom.setAttrib(editor.dom.select('span.mce-nbsp'), 'data-mce-bogus', '1');
  19. });
  20. editor.addButton('nonbreaking', {
  21. title: 'Insert nonbreaking space',
  22. cmd: 'mceNonBreaking'
  23. });
  24. editor.addMenuItem('nonbreaking', {
  25. text: 'Nonbreaking space',
  26. cmd: 'mceNonBreaking',
  27. context: 'insert'
  28. });
  29. if (setting) {
  30. var spaces = +setting > 1 ? +setting : 3; // defaults to 3 spaces if setting is true (or 1)
  31. editor.on('keydown', function(e) {
  32. if (e.keyCode == 9) {
  33. if (e.shiftKey) {
  34. return;
  35. }
  36. e.preventDefault();
  37. for (var i = 0; i < spaces; i++) {
  38. editor.execCommand('mceNonBreaking');
  39. }
  40. }
  41. });
  42. }
  43. });