gaga.summernote.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Summernote Java Script written by gagamel.
  3. *
  4. * Copyright (c) 2010 gagamel
  5. * Dual licensed under GPL (GPL-LICENSE.txt) licenses.
  6. *
  7. * $Date: 2020-10-29 $
  8. *
  9. * 사용 예)
  10. * // HTML 태그는 textarea로 구성
  11. * // id는 gagaSn.summernote 함수 호출 시에 넘겨줘야 한다.
  12. * <textarea class="textareaR4" name="clauseContent" id="clauseContent"></textarea>
  13. *
  14. * // Import할 자바스크립트 파일
  15. * <script type="text/javascript" src="/ux/plugins/summernote/summernote.js?v=2020102902"></script>
  16. * <script type="text/javascript" src="/ux/plugins/gaga/gaga.summernote.js?v=2020102902"></script>
  17. *
  18. * <script type="text/javascript">
  19. * // Get a summernote options
  20. * var snOptions = gagaSn.getToolbarOptions();
  21. *
  22. * $(document).ready(function() {
  23. * // Create a summernote
  24. * gagaSn.createSummernote(snOptions, '#clauseContent');
  25. * });
  26. * </script>
  27. */
  28. var gagaSn = {
  29. /**
  30. * Get a Toolbar options
  31. * @param type - 유형(default, media: 사진/동영상 업로드)
  32. */
  33. getToolbarOptions : function(type) {
  34. if (typeof(type) == 'undefined' || type == 'default') {
  35. return [
  36. ['style', ['style']],
  37. //['Font Style', ['fontname']], <!-- 210309 삭제 -->
  38. ['fontsize', ['fontsize']],
  39. ['height', ['height']],
  40. ['style', ['bold', 'italic', 'underline','clear']],
  41. ['font', ['strikethrough', 'superscript', 'subscript']],
  42. ['color', ['color']],
  43. ['para', ['ul', 'ol', 'paragraph']],
  44. ['Insert', ['table']],
  45. ['Insert', ['link']],
  46. ['misc', [ 'print']], // 프린트
  47. ['code', ['fullscreen', 'codeview', 'help']]
  48. ];
  49. } else if (type == 'media') {
  50. return [
  51. ['style', ['style']],
  52. //['Font Style', ['fontname']], <!-- 210309 삭제 -->
  53. ['fontsize', ['fontsize']],
  54. ['height', ['height']],
  55. ['style', ['bold', 'italic', 'underline','clear']],
  56. ['font', ['strikethrough', 'superscript', 'subscript']],
  57. ['color', ['color']],
  58. ['para', ['ul', 'ol', 'paragraph']],
  59. ['Insert', ['table']],
  60. ['Insert', ['link', 'picture', 'video']],
  61. ['misc', [ 'print']], // 프린트
  62. ['code', ['fullscreen', 'codeview', 'help']]
  63. ];
  64. }
  65. },
  66. /**
  67. * Create a summernote
  68. * @param toolbarOptions - 툴바옵션
  69. * @param editorId - 에디터 ID
  70. * @param editorHeight - 에디터 height
  71. */
  72. createSummernote : function(toolbarOptions, editorId, editorHeight) {
  73. if (typeof(editorHeight) == 'undefined') editorHeight = 300;
  74. $(editorId).summernote({
  75. disableDragAndDrop: true, //drag&drop 사용안함
  76. placeholder: '내용을 입력하세요',
  77. height: editorHeight, //에디터 기본 높이
  78. lang : 'ko-KR', //기본 언어 인코딩
  79. //fontNames: ['Malgun Gothic', 'HY견고딕', 'Helvetica', 'Verdana', 'Arial', 'Arial Black'], //폰트 스타일 <!-- 210309 삭제 -->
  80. //fontNamesIgnoreCheck: ['Malgun Gothic'], //기본폰트 스타일 <!-- 210309 삭제 -->
  81. fontNames: ['Noto Sans kr'], //폰트 스타일 <!-- 210309 수정 -->
  82. fontNamesIgnoreCheck: ['Noto Sans kr'], //기본폰트 스타일 <!-- 210309 수정 -->
  83. focus: false, //로드시 에디터창에 포커싱
  84. fontSizes: ['8','9','10','11','12','13','14','15','16','17','18','19','20','24','30','36'],
  85. toolbar: toolbarOptions,
  86. callbacks: {
  87. onImageUpload: function(files) { // 이미지 업로드
  88. for (var i = 0; i < files.length; i++) {
  89. gagaSn.uploadImage(files[i], this);
  90. }
  91. },
  92. onPaste: function(e) {
  93. var clipboardData = e.originalEvent.clipboardData;
  94. if (clipboardData && clipboardData.items && clipboardData.items.length) {
  95. var item = clipboardData.items[0];
  96. if (item.kind === 'file' && item.type.indexOf('image/') !== -1) {
  97. e.preventDefault();
  98. }
  99. }
  100. }
  101. }
  102. });
  103. },
  104. /**
  105. * Set value to summernote
  106. */
  107. setContents : function(editorId, content) {
  108. var content = content.replaceAll("&lt;", "<").replaceAll("&gt;",">").replaceAll("&quot;","\"");
  109. try {
  110. $(editorId).summernote('code', content);
  111. } catch(e) {
  112. // Do nothing
  113. }
  114. },
  115. uploadImage : function(file, editorId) {
  116. var formData = new FormData();
  117. formData.append("file", file);
  118. formData.append("policy", "image");
  119. $.ajax({
  120. data : formData,
  121. type : 'POST',
  122. url : '/common/file/upload?subDir=/editor',
  123. cache : false,
  124. contentType : false,
  125. enctype : 'multipart/form-data',
  126. processData : false,
  127. success : function(data) {
  128. console.log("================== EDITOR FILE UPLOAD ===================");
  129. console.log(data);
  130. console.log("================== // EDITOR FILE UPLOAD ===================");
  131. $(editorId).summernote('insertImage', data.viewUrl + "/editor/" + data.newFileName);
  132. }
  133. });
  134. }
  135. }