plugin.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. CKEDITOR.plugins.add('tweetabletext', {
  2. icons: 'tweetabletext',
  3. beforeInit: function () {
  4. },
  5. init: function(editor) {
  6. editor.addCommand('tweetabletext', new CKEDITOR.dialogCommand('tweetabletextDialog'));
  7. editor.addCommand('untweetabletext', new CKEDITOR.unlinkCommand());
  8. editor.ui.addButton('TweetableText', {
  9. label: 'Insert TweetableText',
  10. command: 'tweetabletext',
  11. toolbar: 'insert'
  12. });
  13. if (editor.contextMenu) {
  14. editor.addMenuGroup('tweetabletextGroup');
  15. editor.addMenuItems({
  16. tweetabletextItem: {
  17. label: 'Edit TweetableText',
  18. icon: this.path + 'icons/tweetabletext.png',
  19. command: 'tweetabletext',
  20. group: 'tweetabletextGroup'
  21. },
  22. unTweetabletextItem: {
  23. label: 'Remove TweetableText',
  24. icon: this.path + 'icons/tweetabletext.png',
  25. command: 'untweetabletext',
  26. group: 'tweetabletextGroup'
  27. },
  28. });
  29. editor.contextMenu.addListener(function(element) {
  30. if (element.getAttribute('class') === 'tweetabletext') {
  31. return { tweetabletextItem: CKEDITOR.TRISTATE_OFF, unTweetabletextItem: CKEDITOR.TRISTATE_OFF,};
  32. }
  33. });
  34. }
  35. CKEDITOR.dialog.add('tweetabletextDialog', this.path + 'dialogs/tweetabletext.js');
  36. if (typeof editor.config.contentsCss === 'object') {
  37. editor.config.contentsCss.push(CKEDITOR.getUrl(this.path + 'css/tweetabletext.css'));
  38. }
  39. }
  40. });
  41. // This part was getting from http://ckeditor.com/addon/link.
  42. CKEDITOR.unlinkCommand = function() {};
  43. CKEDITOR.unlinkCommand.prototype = {
  44. exec: function(editor) {
  45. var style = new CKEDITOR.style({
  46. element: 'a',
  47. type: CKEDITOR.STYLE_INLINE,
  48. alwaysRemoveElement: 1
  49. });
  50. editor.removeStyle(style);
  51. },
  52. refresh: function(editor, path) {
  53. var element = path.lastElement && path.lastElement.getAscendant('a', true);
  54. if (element && element.getName() === 'a' && element.getAttribute('href') && element.getChildCount()) {
  55. this.setState(CKEDITOR.TRISTATE_OFF);
  56. }
  57. else {
  58. this.setState(CKEDITOR.TRISTATE_DISABLED);
  59. }
  60. },
  61. contextSensitive: 1,
  62. startDisabled: 1,
  63. requiredContent: 'a[href]'
  64. };