Remark.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Created by Jacky.gao on 2016/10/25.
  3. */
  4. window.Remark=function (container) {
  5. this.remark="";
  6. this.defaultRemark="请输入备注内容";
  7. this.init(container);
  8. };
  9. Remark.prototype.init=function (container) {
  10. var toolbar=$("<div style='cursor:pointer;color:#777;font-size:12px'>备注</div>");
  11. container.append(toolbar);
  12. var icon=$("<i class='glyphicon glyphicon-circle-arrow-down'></i>");
  13. toolbar.append(icon);
  14. var contentContainer=$("<div class='collapse in'></div>");
  15. container.append(contentContainer);
  16. this.remarkLabel=$("<div style='color:#999;background: #fdfdfd;padding:5px;border:solid 1px #ddd;border-radius: 5px;font-size: 12px'>"+this.defaultRemark+"</div>");
  17. contentContainer.append(this.remarkLabel);
  18. this.remarkEditor=$("<textarea class='form-control' rows='4'>"+this.defaultRemark+"</textarea>");
  19. contentContainer.append(this.remarkEditor);
  20. this.remarkEditor.hide();
  21. var _this=this;
  22. this.remarkLabel.click(function () {
  23. _this.remarkEditor.show();
  24. _this.remarkEditor.focus();
  25. _this.remarkLabel.hide();
  26. });
  27. this.remarkEditor.change(function () {
  28. _this.remark=$(this).val();
  29. if(_this.remark===""){
  30. _this.remarkLabel.text(_this.defaultRemark);
  31. }else{
  32. _this.remarkLabel.html(_this.parseBreak(_this.remark));
  33. }
  34. if(window.setDirty){
  35. window.setDirty();
  36. }
  37. if(window._setDirty){
  38. window._setDirty();
  39. }
  40. });
  41. this.remarkEditor.blur(function () {
  42. _this.remarkEditor.hide();
  43. _this.remarkLabel.show();
  44. });
  45. toolbar.click(function () {
  46. contentContainer.collapse("toggle");
  47. });
  48. contentContainer.on('show.bs.collapse', function () {
  49. icon.removeClass("glyphicon-circle-arrow-right");
  50. icon.addClass("glyphicon-circle-arrow-down");
  51. });
  52. contentContainer.on('hide.bs.collapse', function () {
  53. icon.removeClass("glyphicon-circle-arrow-down");
  54. icon.addClass("glyphicon-circle-arrow-right");
  55. });
  56. contentContainer.collapse('hide');
  57. };
  58. Remark.prototype.setData=function (data) {
  59. if(!data || data===""){
  60. return;
  61. }
  62. this.remark=data;
  63. this.remarkEditor.val(data);
  64. this.remarkLabel.html(this.parseBreak(data));
  65. };
  66. Remark.prototype.toXml=function () {
  67. return "<remark><![CDATA["+this.remark+"]]></remark>";
  68. };
  69. Remark.prototype.parseBreak=function (data) {
  70. data=data.replace(new RegExp("<",'gm'),'&lt;');
  71. data=data.replace(new RegExp(">",'gm'),'&gt;');
  72. data=data.replace(new RegExp("\n",'gm'),'</br>');
  73. return data;
  74. };