5da19b15cad424bfbaa2f2c3b298536c3e19bd93.svn-base 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. // ================================================================
  2. // CHEditor 5
  3. // ----------------------------------------------------------------
  4. // Homepage: http://www.chcode.com
  5. // Copyright (c) 1997-2014 CHSOFT
  6. // ================================================================
  7. var AppWidth = "250";
  8. var AppHeight = "175";
  9. var AppID = "cheditorPreview";
  10. var oEditor = null;
  11. var button = [ { alt : "", img : 'submit.gif', cmd : doSubmit },
  12. { alt : "", img : 'cancel.gif', cmd : popupClose } ];
  13. var newImage = null;
  14. function CHEditorImagePreview () {
  15. // ----------------------------------------------------------------------------------
  16. // callBack function
  17. document.getElementById(AppID).CHEditorImagePreview("1", "1");
  18. }
  19. function CHXUploadRUN(src) {
  20. // ----------------------------------------------------------------------------------
  21. // Preview
  22. //
  23. chxupload_RUN("src", src,
  24. "width", AppWidth,
  25. "height", AppHeight,
  26. "align", "middle",
  27. "id", AppID,
  28. "classid", AppID,
  29. "quality", "high",
  30. "bgcolor", "#ebe9ed",
  31. "name", AppID,
  32. "wmode", "transparent",
  33. "allowScriptAccess","Always",
  34. "type", "application/x-shockwave-flash",
  35. "pluginspage", "http://www.adobe.com/go/getflashplayer");
  36. }
  37. function getFilename (file) {
  38. while (file.indexOf("/") != -1) {
  39. file = file.slice(file.indexOf("/") + 1);
  40. }
  41. return file;
  42. }
  43. function popupClose()
  44. {
  45. oEditor.popupWinCancel();
  46. }
  47. function chkImgFormat (url)
  48. {
  49. var imageName = getFilename(url);
  50. var allowSubmit = false;
  51. var extArray = [".gif", ".jpg", ".jpeg", ".png"];
  52. extArray.join(" ");
  53. if (imageName === "") {
  54. return false;
  55. }
  56. var ext = imageName.slice(imageName.lastIndexOf(".")).toLowerCase();
  57. var i;
  58. for (i = 0; i < extArray.length; i++) {
  59. if (extArray[i] == ext) {
  60. allowSubmit = true;
  61. break;
  62. }
  63. }
  64. if (!allowSubmit) {
  65. alert("사진은 GIF, JPG, PNG 형식만 넣을 수 있습니다.");
  66. return false;
  67. }
  68. return imageName;
  69. }
  70. function previewImage (source) {
  71. if (navigator.appName.indexOf("microsoft") != -1) {
  72. window[AppID].CHEditorImagePreview(source, 0, 0);
  73. }
  74. else {
  75. document[AppID].CHEditorImagePreview(source, 0, 0);
  76. }
  77. }
  78. function checkImageComplete (img) {
  79. if (img.complete != true) {
  80. setTimeout("checkImageComplete(document.getElementById('"+img.id+"'))", 250);
  81. }
  82. else {
  83. document.getElementById('imageSize').innerHTML = '';
  84. newImage = new Image();
  85. newImage.style.width = img.width + 'px';
  86. newImage.style.height = img.height + 'px';
  87. newImage.setAttribute("src", img.src);
  88. newImage.setAttribute("alt", getFilename(img.src));
  89. }
  90. }
  91. function doPreview () {
  92. var imgurl = document.getElementById('fm_imageUrl').value;
  93. var fileName = chkImgFormat(imgurl);
  94. if (!fileName) {
  95. return;
  96. }
  97. var img = new Image();
  98. img.src = imgurl;
  99. img.id = fileName;
  100. document.getElementById('tmpImage').appendChild(img);
  101. checkImageComplete(img);
  102. previewImage(img.src);
  103. }
  104. function getElementById(id) {
  105. var el = null;
  106. try {
  107. el = document.getElementById(id);
  108. }
  109. catch (ignore) {}
  110. return el;
  111. }
  112. function removeObjectInIE(id) {
  113. var obj = getElementById(id);
  114. if (obj) {
  115. var i;
  116. for (i in obj) {
  117. if (typeof obj[i] == "function") {
  118. obj[i] = null;
  119. }
  120. }
  121. obj.parentNode.removeChild(obj);
  122. }
  123. }
  124. function removeSWF(id) {
  125. var obj = getElementById(id);
  126. if (obj && obj.nodeName == "OBJECT") {
  127. if (oEditor.getBrowser().msie) {
  128. obj.style.display = "none";
  129. (function(){
  130. if (obj.readyState == 4) {
  131. removeObjectInIE(id);
  132. }
  133. })();
  134. }
  135. else {
  136. obj.parentNode.removeChild(obj);
  137. }
  138. }
  139. }
  140. function doSubmit ()
  141. {
  142. if (newImage == null) {
  143. alert("미리 보기 버튼을 클릭하여 이미지를 확인해 주십시오.");
  144. return;
  145. }
  146. if (navigator.userAgent.toLowerCase().indexOf("msie") != -1) {
  147. document.getElementById(AppID).style.display = 'none';
  148. }
  149. var fm_align = document.getElementById('fm_align').alignment;
  150. var align = 'center';
  151. var i;
  152. for (i=0; i<fm_align.length; i++) {
  153. if (fm_align[i].checked) {
  154. align = fm_align[i].value;
  155. break;
  156. }
  157. }
  158. newImage.setAttribute("align", align);
  159. var p = document.createElement("p");
  160. var id = oEditor.makeRandomString();
  161. p.id = id;
  162. p.setAttribute('align', align);
  163. p.appendChild(newImage);
  164. oEditor.insertHtmlPopup(p.cloneNode(true));
  165. p = oEditor._$(id);
  166. var br = document.createElement('br');
  167. oEditor.doc.body.insertBefore(br, p);
  168. oEditor.doc.body.insertBefore(p, br);
  169. removeSWF(AppID);
  170. oEditor.popupWinClose();
  171. }
  172. function outputImageSize (w, h) {
  173. var txt = document.createTextNode(w + ' X ' + h);
  174. document.getElementById('imageSize').innerHTML = '';
  175. document.getElementById('imageSize').appendChild(txt);
  176. }
  177. function showImageSize (w, h) {
  178. outputImageSize(w, h);
  179. }
  180. function setWrapper () {
  181. var wrapper = document.getElementById('tmpImage');
  182. wrapper.style.width = '0px';
  183. wrapper.style.height = '0px';
  184. wrapper.style.overflow = 'hidden';
  185. if (navigator.userAgent.toLowerCase().indexOf('opera') != -1) {
  186. wrapper.style.visibility = 'hidden';
  187. }
  188. else {
  189. wrapper.style.display = 'none';
  190. }
  191. }
  192. function showPreviewButton() {
  193. var img = new Image();
  194. img.src = oEditor.config.iconPath + 'button/preview.gif';
  195. img.style.verticalAlign = 'middle';
  196. img.className = 'button';
  197. img.alt = "";
  198. img.onclick = doPreview;
  199. document.getElementById("inputOutline").appendChild(img);
  200. }
  201. function init(dialog) {
  202. oEditor = this;
  203. oEditor.dialog = dialog;
  204. var dlg = new Dialog(oEditor);
  205. dlg.showButton(button);
  206. CHXUploadRUN(oEditor.config.popupPath + 'flash/ImagePreview');
  207. setWrapper();
  208. showPreviewButton();
  209. dlg.setDialogHeight();
  210. }