/war/src/main/webapp/js/admin/editorTinyMCE.js

http://github.com/b3log/b3log-solo · JavaScript · 126 lines · 75 code · 8 blank · 43 comment · 7 complexity · e030a805be08c5b46d2dfb93216b7222 MD5 · raw file

  1. /*
  2. * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @fileoverview tinyMCE editor
  18. *
  19. * @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
  20. * @version 1.0.0.5, Jun 19, 2012
  21. */
  22. admin.editors.tinyMCE = {
  23. /*
  24. * @description ??????
  25. * @param conf ????????
  26. * @param conf.kind ?????
  27. * @param conf.id ??????? id
  28. * @param conf.fun ??????????????
  29. */
  30. init: function (conf) {
  31. var language = Label.localeString.substring(0, 2);
  32. if (language === "zh") {
  33. language = "zh-cn";
  34. }
  35. if (conf.kind && conf.kind === "simple") {
  36. try {
  37. tinyMCE.init({
  38. // General options
  39. language: language,
  40. mode : "exact",
  41. elements : conf.id,
  42. theme : "advanced",
  43. // Theme options
  44. theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,|,bullist,numlist",
  45. theme_advanced_buttons2 : "",
  46. theme_advanced_buttons3 : "",
  47. theme_advanced_toolbar_location : "top",
  48. theme_advanced_toolbar_align : "left",
  49. valid_children : "+body[style]"
  50. });
  51. } catch (e) {
  52. $("#tipMsg").text("TinyMCE load fail");
  53. }
  54. } else {
  55. try {
  56. tinyMCE.init({
  57. // General options
  58. language: language,
  59. mode : "exact",
  60. elements : conf.id,
  61. theme : "advanced",
  62. plugins : "autosave,style,advhr,advimage,advlink,preview,inlinepopups,media,paste,syntaxhl,wordcount",
  63. // Theme options
  64. theme_advanced_buttons1 : "formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,forecolor,|,advhr,blockquote,syntaxhl,",
  65. theme_advanced_buttons2 : "undo,redo,|,bullist,numlist,outdent,indent,|,justifyleft,justifycenter,justifyright,justifyfull,|,pastetext,pasteword,|,link,unlink,image,iespell,media,|,cleanup,code,preview,",
  66. theme_advanced_buttons3 : "",
  67. theme_advanced_toolbar_location : "top",
  68. theme_advanced_toolbar_align : "left",
  69. theme_advanced_resizing : true,
  70. theme_advanced_statusbar_location : "bottom",
  71. extended_valid_elements: "link[type|rel|href|charset],pre[name|class],iframe[src|width|height|name|align],+a[*]",
  72. valid_children : "+body[style]",
  73. relative_urls: false,
  74. remove_script_host: false,
  75. oninit : function () {
  76. // TODO: chrome bug
  77. window.onhashchange = admin.setCurByHash;
  78. if (typeof(conf.fun) === "function") {
  79. conf.fun();
  80. }
  81. }
  82. });
  83. } catch (e) {
  84. $("#tipMsg").text("TinyMCE load fail");
  85. }
  86. }
  87. },
  88. /*
  89. * @description ??????
  90. * @param {string} id ???id
  91. * @returns {string} ????
  92. */
  93. getContent: function (id) {
  94. var content = "";
  95. try {
  96. content = tinyMCE.get(id).getContent();
  97. } catch (e) {
  98. content = $("#" + id).val();
  99. }
  100. return content;
  101. },
  102. /*
  103. * @description ??????
  104. * @param {string} id ??? id
  105. * @param {string} content ??????
  106. */
  107. setContent: function (id, content) {
  108. try {
  109. if (tinyMCE.get(id)) {
  110. tinyMCE.get(id).setContent(content);
  111. } else {
  112. $("#" + id).val(content);
  113. }
  114. } catch (e) {
  115. $("#" + id).val(content);
  116. }
  117. }
  118. };