PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/advlist/editor_plugin_src.js

#
JavaScript | 161 lines | 110 code | 32 blank | 19 comment | 34 complexity | 83863ad37beac288a1f5ebba9e829a74 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /**
  2. * editor_plugin_src.js
  3. *
  4. * Copyright 2009, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://tinymce.moxiecode.com/license
  8. * Contributing: http://tinymce.moxiecode.com/contributing
  9. */
  10. (function() {
  11. var each = tinymce.each;
  12. tinymce.create('tinymce.plugins.AdvListPlugin', {
  13. init : function(ed, url) {
  14. var t = this;
  15. t.editor = ed;
  16. function buildFormats(str) {
  17. var formats = [];
  18. each(str.split(/,/), function(type) {
  19. formats.push({
  20. title : 'advlist.' + (type == 'default' ? 'def' : type.replace(/-/g, '_')),
  21. styles : {
  22. listStyleType : type == 'default' ? '' : type
  23. }
  24. });
  25. });
  26. return formats;
  27. };
  28. // Setup number formats from config or default
  29. t.numlist = ed.getParam("advlist_number_styles") || buildFormats("default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman");
  30. t.bullist = ed.getParam("advlist_bullet_styles") || buildFormats("default,circle,disc,square");
  31. if (tinymce.isIE && /MSIE [2-7]/.test(navigator.userAgent))
  32. t.isIE7 = true;
  33. },
  34. createControl: function(name, cm) {
  35. var t = this, btn, format;
  36. if (name == 'numlist' || name == 'bullist') {
  37. // Default to first item if it's a default item
  38. if (t[name][0].title == 'advlist.def')
  39. format = t[name][0];
  40. function hasFormat(node, format) {
  41. var state = true;
  42. each(format.styles, function(value, name) {
  43. // Format doesn't match
  44. if (t.editor.dom.getStyle(node, name) != value) {
  45. state = false;
  46. return false;
  47. }
  48. });
  49. return state;
  50. };
  51. function applyListFormat() {
  52. var list, ed = t.editor, dom = ed.dom, sel = ed.selection;
  53. // Check for existing list element
  54. list = dom.getParent(sel.getNode(), 'ol,ul');
  55. // Switch/add list type if needed
  56. if (!list || list.nodeName == (name == 'bullist' ? 'OL' : 'UL') || hasFormat(list, format))
  57. ed.execCommand(name == 'bullist' ? 'InsertUnorderedList' : 'InsertOrderedList');
  58. // Append styles to new list element
  59. if (format) {
  60. list = dom.getParent(sel.getNode(), 'ol,ul');
  61. if (list) {
  62. dom.setStyles(list, format.styles);
  63. list.removeAttribute('data-mce-style');
  64. }
  65. }
  66. ed.focus();
  67. };
  68. btn = cm.createSplitButton(name, {
  69. title : 'advanced.' + name + '_desc',
  70. 'class' : 'mce_' + name,
  71. onclick : function() {
  72. applyListFormat();
  73. }
  74. });
  75. btn.onRenderMenu.add(function(btn, menu) {
  76. menu.onShowMenu.add(function() {
  77. var dom = t.editor.dom, list = dom.getParent(t.editor.selection.getNode(), 'ol,ul'), fmtList;
  78. if (list || format) {
  79. fmtList = t[name];
  80. // Unselect existing items
  81. each(menu.items, function(item) {
  82. var state = true;
  83. item.setSelected(0);
  84. if (list && !item.isDisabled()) {
  85. each(fmtList, function(fmt) {
  86. if (fmt.id == item.id) {
  87. if (!hasFormat(list, fmt)) {
  88. state = false;
  89. return false;
  90. }
  91. }
  92. });
  93. if (state)
  94. item.setSelected(1);
  95. }
  96. });
  97. // Select the current format
  98. if (!list)
  99. menu.items[format.id].setSelected(1);
  100. }
  101. });
  102. menu.add({id : t.editor.dom.uniqueId(), title : 'advlist.types', 'class' : 'mceMenuItemTitle', titleItem: true}).setDisabled(1);
  103. each(t[name], function(item) {
  104. // IE<8 doesn't support lower-greek, skip it
  105. if (t.isIE7 && item.styles.listStyleType == 'lower-greek')
  106. return;
  107. item.id = t.editor.dom.uniqueId();
  108. menu.add({id : item.id, title : item.title, onclick : function() {
  109. format = item;
  110. applyListFormat();
  111. }});
  112. });
  113. });
  114. return btn;
  115. }
  116. },
  117. getInfo : function() {
  118. return {
  119. longname : 'Advanced lists',
  120. author : 'Moxiecode Systems AB',
  121. authorurl : 'http://tinymce.moxiecode.com',
  122. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/advlist',
  123. version : tinymce.majorVersion + "." + tinymce.minorVersion
  124. };
  125. }
  126. });
  127. // Register plugin
  128. tinymce.PluginManager.add('advlist', tinymce.plugins.AdvListPlugin);
  129. })();