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

create_kindeditor.js 8.2 kB

10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //需求:表情栏可以隐藏显示,高度只要一点高
  2. function sd_create_editor(params){
  3. // var minHeight; //最小高度
  4. var paramsHeight = params.height; //设定的高度
  5. var id = arguments[1] ? arguments[1] : undefined;
  6. var type = arguments[2] ? arguments[2] : '';
  7. var paramsWidth = params.width == undefined ? "100%" : params.width;
  8. var editor = params.kindutil.create(params.textarea, {
  9. resizeType : 1,minWidth:"1px",width:"94%",
  10. height:"33px",// == undefined ? "30px":paramsHeight+"px",
  11. minHeight:"33px",// == undefined ? "30px":paramsHeight+"px",
  12. width:params.width,
  13. /*
  14. items:['emoticons','fontname',
  15. 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|',
  16. 'formatblock', 'fontsize', '|','indent', 'outdent',
  17. '|','imagedirectupload','more'],*/
  18. items : ['code','emoticons','fontname',
  19. 'forecolor', 'hilitecolor', 'bold', '|', 'justifyleft', 'justifycenter', 'insertorderedlist','insertunorderedlist', '|',
  20. 'formatblock', 'fontsize', '|','indent', 'outdent',
  21. '|','imagedirectupload','table', 'media', 'preview',"more"
  22. ],
  23. afterChange:function(){//按键事件
  24. var edit = this.edit;
  25. var body = edit.doc.body;
  26. edit.iframe.height(paramsHeight);
  27. this.resize(null, Math.max((params.kindutil.IE ? body.scrollHeight : (params.kindutil.GECKO ? body.offsetHeight+26:body.offsetHeight+7)) , paramsHeight));
  28. },
  29. afterBlur:function(){
  30. //params.toolbar_container.hide();
  31. sd_check_editor_form_field({content:this,contentmsg:params.contentmsg,textarea:params.textarea});
  32. if(this.isEmpty()) {
  33. this.edit.html("<span id='hint' style='color:#999999;font-size:12px;'>我要回复</span>");
  34. }
  35. //params.toolbar_container.hide();
  36. $('#reply_image_' + id).addClass('imageFuzzy');
  37. if(/^\s*<\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\s*\#\d*\;\s*\w*\-\w*\:\s*\w*\;\"\>[\u4e00-\u9fa5]*<\/\w*\>\s*$/.test(this.edit.html())){
  38. params.submit_btn.hide();
  39. params.toolbar_container.hide();
  40. this.resize("100%", null);
  41. }else if(this.edit.html().trim() != ""){
  42. params.submit_btn.show();
  43. params.toolbar_container.show();
  44. }
  45. //params.submit_btn.css("display","none");
  46. },
  47. afterFocus: function(){
  48. var edit = this.edit;
  49. var body = edit.doc.body;
  50. if(/^\s*<\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\s*\#\d*\;\s*\w*\-\w*\:\s*\w*\;\"\>[\u4e00-\u9fa5]*<\/\w*\>\s*$/.test(edit.html())){
  51. edit.html('');
  52. }
  53. params.submit_btn.show();
  54. params.contentmsg.hide();
  55. params.toolbar_container.show();
  56. // params.toolbar_container.show();
  57. $('#reply_image_' + id).removeClass('imageFuzzy');
  58. //edit.iframe.width(paramsWidth);
  59. this.resize(paramsWidth, null);
  60. //params.submit_btn.show();
  61. },
  62. afterCreate:function(){
  63. //params.submit_btn.hide();
  64. var toolbar = $("div[class='ke-toolbar']",params.div_form);
  65. toolbar.css('display','inline');
  66. toolbar.css('padding',0);
  67. $(".ke-outline>.ke-toolbar-icon",toolbar).append('表情');
  68. params.toolbar_container.append(toolbar);
  69. params.toolbar_container.hide();
  70. //init
  71. var edit = this.edit;
  72. var body = edit.doc.body;
  73. edit.iframe[0].scroll = 'no';
  74. body.style.overflowY = 'hidden';
  75. //reset height
  76. paramsHeight = paramsHeight == undefined ? params.kindutil.removeUnit(this.height) : paramsHeight;
  77. edit.iframe.height(paramsHeight);
  78. edit.html("<span id='hint' style='color:#999999;font-size:12px;'>我要回复</span>");
  79. this.resize(null,paramsHeight);// Math.max((params.kindutil.IE ? body.scrollHeight : body.offsetHeight)+ paramsHeight , paramsHeight)
  80. // params.toolbar_container.hide();
  81. if(typeof enableAt === 'function'){
  82. enableAt(this, id, type);
  83. }
  84. }
  85. }).loadPlugin('paste');
  86. return editor;
  87. }
  88. function sd_check_editor_form_field(params){
  89. var result=true;
  90. if(params.content!=undefined){
  91. if(params.content.isEmpty()){
  92. result=false;
  93. }
  94. if(params.content.html()!=params.textarea.html() || params.issubmit==true){
  95. params.textarea.html(params.content.html());
  96. params.content.sync();
  97. if(params.content.isEmpty() || /^\s*<\w*\s*\w*\=\"\w*\"\s*\w*\=\"\w*\:\s*\#\d*\;\s*\w*\-\w*\:\s*\w*\;\"\>[\u4e00-\u9fa5]*<\/\w*\>\s*$/.test(params.textarea.html())){
  98. params.contentmsg.html('内容不能为空');
  99. params.contentmsg.css({color:'#ff0000'});
  100. }else{
  101. params.contentmsg.html('填写正确');
  102. params.contentmsg.css({color:'#008000'});
  103. }
  104. params.contentmsg.show();
  105. }
  106. }
  107. return result;
  108. }
  109. function sd_create_form(params){
  110. params.form.submit(function(){
  111. var flag = false;
  112. if(params.form.attr('data-remote') != undefined ){
  113. flag = true
  114. }
  115. var is_checked = sd_check_editor_form_field({
  116. issubmit:true,
  117. content:params.editor,
  118. contentmsg:params.contentmsg,
  119. textarea:params.textarea
  120. });
  121. if(is_checked){
  122. if(flag){
  123. return true;
  124. }else{
  125. $(this)[0].submit();
  126. return false;
  127. }
  128. }
  129. return false;
  130. });
  131. }
  132. function sd_reset_editor_form(params){
  133. params.form[0].reset();
  134. params.textarea.empty();
  135. if(params.editor != undefined){
  136. params.editor.html(params.textarea.html());
  137. }
  138. params.contentmsg.hide();
  139. }
  140. //第二个参数是高度,可以传,可以不传
  141. function sd_create_editor_from_data(id){
  142. var height = arguments[1] ? arguments[1] : undefined;
  143. var width = arguments[2] ? arguments[2] : undefined;
  144. var type = arguments[3] ? arguments[3] : undefined;
  145. KindEditor.ready(function (K) {
  146. $("div[nhname='new_message_" + id + "']").each(function () {
  147. var params = {};
  148. params.kindutil = K;
  149. params.div_form = $(this);
  150. params.form = $("form", params.div_form);
  151. if (params.form == undefined || params.form.length == 0) {
  152. return;
  153. }
  154. params.textarea = $("textarea[nhname='new_message_textarea_" + id + "']", params.div_form);
  155. params.contentmsg = $("span[nhname='contentmsg_" + id + "']", params.div_form);
  156. params.toolbar_container = $("div[nhname='toolbar_container_" + id + "']", params.div_form);
  157. params.cancel_btn = $("#new_message_cancel_btn_" + id);
  158. params.submit_btn = $("#new_message_submit_btn_" + id);
  159. params.height = height;
  160. params.width = width;
  161. if (params.textarea.data('init') == undefined) {
  162. params.editor = sd_create_editor(params,id, type);
  163. sd_create_form(params);
  164. params.cancel_btn.click(function () {
  165. sd_reset_editor_form(params);
  166. });
  167. params.submit_btn.click(function () {
  168. params.form.submit();
  169. });
  170. params.textarea.data('init', 1);
  171. $(this).show();
  172. }
  173. });
  174. });
  175. div_form = $("div[nhname='new_message_" + id + "']");
  176. $(".ke-edit", div_form).css("height","33px");
  177. $(".ke-edit-iframe",div_form).css("height","33px");
  178. }

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...