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.

init_activity_KindEditor.js 7.0 kB

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

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