d7096b7d75752655c7b79183772da93d48391abf.svn-base 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. // ================================================================
  2. // CHEditor 5
  3. // ================================================================
  4. var uploadScript = '',
  5. deleteScript = '',
  6. AppID = 'chximage',
  7. AppSRC = '',
  8. activeImage = null,
  9. destinationObject = null,
  10. readyToMove = false,
  11. moveTimer = -1,
  12. dragDropDiv,
  13. insertionMarker,
  14. offsetX_marker = -4,
  15. offsetY_marker = -3,
  16. geckoOffsetX_marker = 4,
  17. geckoOffsetY_marker = -2,
  18. divXPositions = [],
  19. divYPositions = [],
  20. divWidth = [],
  21. divHeight = [],
  22. tmpLeft = 0,
  23. tmpTop = 0,
  24. eventDiff_x = 0,
  25. eventDiff_y = 0,
  26. modifyImages = [],
  27. uploadMaxNumber = 12,
  28. imageCompleted = 0,
  29. imageCompletedList = [],
  30. uploadButton = '',
  31. uploadImagePath = '',
  32. showThumbnailSize = { width: 120, height: 90 },
  33. oEditor = null,
  34. button,
  35. imageResizeWidth = 0,
  36. makeThumbnail = true,
  37. makeThumbnailWidth = 120,
  38. makeThumbnailHeight = 90,
  39. sortOnName = false,
  40. browser = null;
  41. function createInsertionMaker() {
  42. var wrapper = document.getElementById('insertionMarker'),
  43. topIco = new Image(),
  44. middleIco = new Image(),
  45. bottomIco = new Image();
  46. topIco.src = uploadImagePath + '/marker_top.gif';
  47. topIco.style.width = '6px';
  48. topIco.style.height = '1px';
  49. wrapper.appendChild(topIco);
  50. middleIco.src = uploadImagePath + '/marker_middle.gif';
  51. middleIco.style.height = '96px';
  52. middleIco.style.width = '6px';
  53. wrapper.appendChild(middleIco);
  54. bottomIco.src = uploadImagePath + '/marker_bottom.gif';
  55. bottomIco.style.width = '6px';
  56. bottomIco.style.height = '1px';
  57. wrapper.appendChild(bottomIco);
  58. }
  59. function popupClose() {
  60. // ----------------------------------------------------------------------------------
  61. swfobject.removeSWF(AppID);
  62. oEditor.popupWinCancel();
  63. }
  64. function showContents() {
  65. var spacer = function (id) {
  66. var clear = document.createElement('span');
  67. clear.style.height = '0';
  68. clear.style.width = '0';
  69. clear.className = 'clear';
  70. clear.id = 'spacer' + id;
  71. return clear;
  72. }, spacerNo = 1, i, imgBox, theImg, lastSpacer;
  73. for (i = 0; i < uploadMaxNumber; i++) {
  74. if (i > 0 && ((i % 4) === 0)) {
  75. document.getElementById('imageListWrapper').appendChild(spacer(spacerNo++));
  76. }
  77. imgBox = document.createElement('div');
  78. imgBox.id = 'imgBox' + i;
  79. imgBox.className = 'imageBox';
  80. theImg = document.createElement('div');
  81. theImg.id = 'img_' + i;
  82. theImg.className = 'imageBox_theImage';
  83. imgBox.appendChild(theImg);
  84. document.getElementById('imageListWrapper').appendChild(imgBox);
  85. if (i === (uploadMaxNumber - 1)) {
  86. lastSpacer = spacer(spacerNo);
  87. lastSpacer.style.height = "7px";
  88. document.getElementById('imageListWrapper').appendChild(lastSpacer);
  89. }
  90. }
  91. if (browser.msie && browser.ver < 7) {
  92. document.getElementById('imageListWrapper').style.padding = '5px 2px 5px 2px';
  93. document.getElementById('imageInfoBox').style.height = '302px';
  94. document.getElementById('imageInfoBox').style.width = '124px';
  95. } else {
  96. document.getElementById('imageListWrapper').style.padding = '5px 7px 0 5px';
  97. document.getElementById('imageInfoBox').style.height = '298px';
  98. document.getElementById('imageInfoBox').style.width = '130px';
  99. }
  100. }
  101. function openFiles() {
  102. // ----------------------------------------------------------------------------------
  103. var elem = browser.msie ? document.getElementById(AppID) : document[AppID];
  104. elem.AddFiles();
  105. }
  106. function setImageCount() {
  107. imageCompleted++;
  108. document.getElementById('imageCount').innerHTML = imageCompleted;
  109. }
  110. function getImageCount() {
  111. return imageCompleted;
  112. }
  113. function allowedMaxImage() {
  114. return uploadMaxNumber - getImageCount();
  115. }
  116. function getUploadedCount() {
  117. return document.getElementById('imageListWrapper').getElementsByTagName('img').length;
  118. }
  119. function uploadedImageCount() {
  120. imageCompleted = getUploadedCount();
  121. document.getElementById('imageCount').innerHTML = imageCompleted;
  122. }
  123. function uploadError(msg) {
  124. alert(msg);
  125. }
  126. function imageDelete(filePath) {
  127. var chximage = document.getElementById(AppID);
  128. chximage.ImageDelete(encodeURI(filePath));
  129. }
  130. function getTopPos(inputObj) {
  131. // ----------------------------------------------------------------------------------
  132. var returnValue = inputObj.offsetTop;
  133. inputObj = inputObj.offsetParent;
  134. while (inputObj) {
  135. if (inputObj.tagName.toLowerCase() !== 'html') {
  136. returnValue += (inputObj.offsetTop - inputObj.scrollTop);
  137. if (browser.msie) {
  138. returnValue += inputObj.clientTop;
  139. }
  140. }
  141. inputObj = inputObj.offsetParent;
  142. }
  143. return returnValue;
  144. }
  145. function getLeftPos(inputObj) {
  146. // ----------------------------------------------------------------------------------
  147. var returnValue = inputObj.offsetLeft;
  148. inputObj = inputObj.offsetParent;
  149. while (inputObj) {
  150. if (inputObj.id !== 'imageListWrapper') {
  151. returnValue += inputObj.offsetLeft;
  152. if (browser.msie) {
  153. returnValue += inputObj.clientLeft;
  154. }
  155. }
  156. inputObj = inputObj.offsetParent;
  157. }
  158. return returnValue;
  159. }
  160. function getDivCoordinates() {
  161. // ----------------------------------------------------------------------------------
  162. var imgBox = document.getElementById('imageListWrapper').getElementsByTagName('DIV'),
  163. i = 0;
  164. for (; i < imgBox.length; i++) {
  165. if ((imgBox[i].className === 'imageBox' || imgBox[i].className === 'imageBoxHighlighted') && imgBox[i].id) {
  166. divXPositions[imgBox[i].id] = getLeftPos(imgBox[i]);
  167. divYPositions[imgBox[i].id] = getTopPos(imgBox[i]);
  168. divWidth[imgBox[i].id] = imgBox[i].offsetWidth;
  169. divHeight[imgBox[i].id] = imgBox[i].offsetHeight;
  170. }
  171. }
  172. }
  173. function reOrder() {
  174. // ----------------------------------------------------------------------------------
  175. var wrapper = document.getElementById('imageListWrapper'),
  176. imgBox = wrapper.getElementsByTagName('div'),
  177. imgNum = 0, i, spacer, breakline = [];
  178. for (i = 0; i < imgBox.length; i++) {
  179. if (imgBox[i].id.indexOf('imgBox') === -1) {
  180. continue;
  181. }
  182. imgBox[i].className = 'imageBox';
  183. imgBox[i].firstChild.className = 'imageBox_theImage';
  184. if (imgNum > 0 && (imgNum % 4) === 0) {
  185. breakline.push(imgBox[i].id);
  186. }
  187. imgNum++;
  188. }
  189. for (i = 0; i < breakline.length; i++) {
  190. spacer = document.getElementById('spacer' + (i + 1));
  191. if (i + 1 === breakline.length) {
  192. wrapper.appendChild(spacer);
  193. } else {
  194. wrapper.insertBefore(spacer, document.getElementById(breakline[i]));
  195. }
  196. }
  197. }
  198. function setImageInfo(id) {
  199. var elem;
  200. if (!id) {
  201. document.getElementById('selectedImageWidth').innerHTML = '0';
  202. document.getElementById('selectedImageHeight').innerHTML = '0';
  203. document.getElementById('selectedImageName').innerHTML = "없음";
  204. } else {
  205. elem = imageCompletedList[id];
  206. document.getElementById('selectedImageWidth').innerHTML = elem.width;
  207. document.getElementById('selectedImageHeight').innerHTML = elem.height;
  208. document.getElementById('selectedImageName').innerHTML = elem.origName;
  209. }
  210. }
  211. function showDelete() {
  212. // ----------------------------------------------------------------------------------
  213. var self = this, btn;
  214. if (readyToMove) {
  215. return;
  216. }
  217. getDivCoordinates();
  218. self.className = 'imageBox_theImage_over';
  219. btn = document.getElementById('removeImageButton');
  220. btn.style.left = (showThumbnailSize.width - parseInt(btn.style.width, 10) - 1) + 'px';
  221. btn.style.top = '-1px';
  222. self.appendChild(btn);
  223. btn.style.display = 'block';
  224. btn.onmouseover = function (ev) {
  225. ev = ev || window.event;
  226. ev.cancelBubble = true;
  227. this.style.display = 'block';
  228. setImageInfo(self.id);
  229. this.className = 'removeButton_over';
  230. self.className = 'imageBox_theImage_over';
  231. };
  232. btn.onmouseout = function () {
  233. this.className = 'removeButton';
  234. };
  235. btn.onmousedown = function () {
  236. var images = self.getElementsByTagName('img'), i, wrapper, moveobj, target;
  237. for (i = 0; i < images.length; i++) {
  238. self.removeChild(images[i]);
  239. }
  240. self.removeChild(self.firstChild);
  241. self.className = 'imageBox_theImage';
  242. if (self.parentNode.nextSibling && self.parentNode.nextSibling.id) {
  243. wrapper = document.getElementById('imageListWrapper');
  244. moveobj = self.parentNode.nextSibling;
  245. target = self.parentNode;
  246. while (moveobj !== null) {
  247. if (moveobj.firstChild && !moveobj.firstChild.firstChild) {
  248. break;
  249. }
  250. if (/^spacer/.test(moveobj.id)) {
  251. moveobj = moveobj.nextSibling;
  252. continue;
  253. }
  254. wrapper.insertBefore(moveobj, target);
  255. moveobj = target.nextSibling;
  256. }
  257. }
  258. reOrder();
  259. uploadedImageCount();
  260. setImageInfo(0);
  261. this.style.display = 'none';
  262. document.body.appendChild(this);
  263. self.onmouseout = self.onmouseover = null;
  264. };
  265. setImageInfo(self.id);
  266. }
  267. function hideDelete() {
  268. // ----------------------------------------------------------------------------------
  269. document.getElementById('removeImageButton').style.display = 'none';
  270. }
  271. function startUpload(count) {
  272. // ----------------------------------------------------------------------------------
  273. var el = document.getElementById('imageListWrapper').getElementsByTagName('div'), i, imgBox;
  274. for (i = 0; i < el.length; i++) {
  275. imgBox = el[i];
  276. if (imgBox.className !== 'imageBox_theImage') {
  277. continue;
  278. }
  279. if (count === 0) {
  280. break;
  281. }
  282. if (!imgBox.firstChild || imgBox.firstChild.tagName.toLowerCase() !== 'img') {
  283. imgBox.style.backgroundImage = "url('" + uploadImagePath + "/loader.gif')";
  284. count--;
  285. }
  286. }
  287. }
  288. function fileFilterError(file) {
  289. alert("선택하신 '" + file + "' 파일은 전송할 수 없습니다.\n" +
  290. "gif, png, jpg, 그림 파일만 전송할 수 있습니다.");
  291. }
  292. function imgComplete(img, imgSize, boxId) {
  293. var resizeW, resizeH, M, elem;
  294. img.setAttribute("border", '0');
  295. if (imgSize.width > showThumbnailSize.width || imgSize.height > showThumbnailSize.height) {
  296. if (imgSize.width > imgSize.height) {
  297. resizeW = (imgSize.width > showThumbnailSize.width) ? showThumbnailSize.width : imgSize.width;
  298. resizeH = Math.round((imgSize.height * resizeW) / imgSize.width);
  299. } else {
  300. resizeH = (imgSize.height > showThumbnailSize.height) ? showThumbnailSize.height : imgSize.height;
  301. resizeW = Math.round((imgSize.width * resizeH) / imgSize.height);
  302. }
  303. if (resizeH > showThumbnailSize.height) {
  304. resizeH = (imgSize.height > showThumbnailSize.height) ? showThumbnailSize.height : imgSize.height;
  305. resizeW = Math.round((imgSize.width * resizeH) / imgSize.height);
  306. }
  307. } else {
  308. resizeW = imgSize.width;
  309. resizeH = imgSize.height;
  310. }
  311. img.style.width = resizeW - 2 + 'px';
  312. img.style.height = resizeH - 2 + 'px';
  313. img.style.margin = "1px";
  314. if (resizeW < showThumbnailSize.width) {
  315. M = showThumbnailSize.width - resizeW;
  316. img.style.marginLeft = Math.round(M / 2) + 'px';
  317. }
  318. if (resizeH < showThumbnailSize.height) {
  319. M = showThumbnailSize.height - resizeH;
  320. img.style.marginTop = Math.round(M / 2) + 'px';
  321. }
  322. elem = document.getElementById(boxId);
  323. elem.style.backgroundImage = "url('" + uploadImagePath + "/dot.gif')";
  324. elem.onmouseover = showDelete;
  325. elem.onmouseout = function() {
  326. this.className = 'imageBox_theImage';
  327. setImageInfo(0);
  328. hideDelete();
  329. };
  330. setImageCount();
  331. }
  332. function uploadComplete(image) {
  333. // ----------------------------------------------------------------------------------
  334. var el = document.getElementById('imageListWrapper').getElementsByTagName('div'),
  335. imgBox = null, tmpImg, i, imgInfo,
  336. imgOnLoad = function () {
  337. imgInfo = { "width": image.width, "height": image.height, "fileSize": image.fileSize,
  338. "fileUrl": image.fileUrl, "fileName": image.fileName, "filePath": image.filePath, "origName": image.origName };
  339. imageCompletedList[imgBox.id] = imgInfo;
  340. imgComplete(this, imgInfo, imgBox.id);
  341. };
  342. image.filePath = decodeURI(image.filePath);
  343. image.origName = decodeURI(image.origName);
  344. for (i = 0; i < el.length; i++) {
  345. imgBox = el[i];
  346. if (imgBox.className !== 'imageBox_theImage') {
  347. continue;
  348. }
  349. if (!imgBox.firstChild || imgBox.firstChild.tagName.toLowerCase() !== 'img') {
  350. tmpImg = new Image();
  351. tmpImg.style.width = "0px";
  352. tmpImg.style.height = "0px";
  353. tmpImg.setAttribute("alt", image.origName);
  354. tmpImg.onload = imgOnLoad;
  355. tmpImg.src = image.fileUrl;
  356. imgBox.appendChild(tmpImg);
  357. break;
  358. }
  359. }
  360. }
  361. function showUploadWindow() {
  362. // ----------------------------------------------------------------------------------
  363. var uploadWindow = document.getElementById("uploadWindow"),
  364. uploadWindowWidth = 700,
  365. winWidth, el, i, j, imgBox, img;
  366. if (!(oEditor.undefined(window.innerWidth))) {
  367. winWidth = window.innerWidth;
  368. } else if (document.documentElement &&
  369. (!(oEditor.undefined(document.documentElement.clientWidth))) &&
  370. document.documentElement.clientWidth !== 0) {
  371. winWidth = document.documentElement.clientWidth;
  372. } else if (document.body && (!(oEditor.undefined(document.body.clientWidth)))) {
  373. winWidth = document.body.clientWidth;
  374. } else {
  375. alert('현재 브라우저를 지원하지 않습니다.');
  376. return;
  377. }
  378. uploadWindow.style.left = winWidth / 2 - (uploadWindowWidth / 2) + 'px';
  379. uploadWindow.style.display = "block";
  380. uploadWindow.style.width = uploadWindowWidth + 'px';
  381. if (modifyImages.length > 0) {
  382. el = document.getElementById('imageListWrapper').getElementsByTagName('div');
  383. for (i = 0; i < modifyImages.length; i++) {
  384. if (i > 7) {
  385. break;
  386. }
  387. for (j = 0; j < el.length; j++) {
  388. imgBox = el[j];
  389. if (imgBox.className !== 'imageBox_theImage') {
  390. continue;
  391. }
  392. if (imgBox.firstChild && (imgBox.firstChild.src === modifyImages[i])) {
  393. break;
  394. }
  395. if (imgBox.firstChild === null) {
  396. img = new Image();
  397. img.src = modifyImages[i];
  398. img.border = 0;
  399. img.alt = '';
  400. img.style.width = '120px';
  401. img.style.height = '90px';
  402. imgBox.appendChild(img);
  403. break;
  404. }
  405. }
  406. }
  407. }
  408. }
  409. function removeImages() {
  410. var images = [], i, j, theImage, img, remove;
  411. document.body.appendChild(document.getElementById('removeImageButton'));
  412. for (i = 0; i < uploadMaxNumber; i++) {
  413. theImage = document.getElementById('img_' + i);
  414. if (theImage.hasChildNodes() && theImage.firstChild.tagName.toLowerCase() === 'img') {
  415. images.push(theImage);
  416. }
  417. }
  418. for (i = 0; i < images.length; i++) {
  419. img = images[i];
  420. if (img.firstChild !== null) {
  421. oEditor.removeEvent(img, 'mouseover', showDelete);
  422. remove = img.getElementsByTagName('img');
  423. for (j = 0; j < remove.length; j++) {
  424. img.removeChild(remove[j]);
  425. }
  426. img.parentNode.className = 'imageBox';
  427. oEditor.removeEvent(img, 'mouseover', showDelete);
  428. }
  429. }
  430. uploadedImageCount();
  431. imageCompletedList = [];
  432. }
  433. function removeImage() {
  434. // ----------------------------------------------------------------------------------
  435. var i, theImage, found = false;
  436. for (i = 0; i < uploadMaxNumber; i++) {
  437. theImage = document.getElementById('img_' + i);
  438. if (theImage.hasChildNodes() && theImage.firstChild.tagName.toLowerCase() === 'img') {
  439. found = true;
  440. break;
  441. }
  442. }
  443. if (found) {
  444. if (!confirm('추가하신 사진이 있습니다. 사진 넣기를 취소하시겠습니까?')) {
  445. return false;
  446. }
  447. removeImages();
  448. }
  449. return true;
  450. }
  451. function closeWindow() {
  452. // ----------------------------------------------------------------------------------
  453. if (removeImage()) {
  454. popupClose();
  455. }
  456. }
  457. function cancelEvent() {
  458. // ----------------------------------------------------------------------------------
  459. return false;
  460. }
  461. function startMoveTimer() {
  462. // ----------------------------------------------------------------------------------
  463. var subElements, newDiv;
  464. if (moveTimer >= 0 && moveTimer < 10) {
  465. moveTimer++;
  466. setTimeout('startMoveTimer()', 8);
  467. }
  468. if (moveTimer === 5) {
  469. getDivCoordinates();
  470. subElements = dragDropDiv.getElementsByTagName('div');
  471. if (subElements.length > 0) {
  472. dragDropDiv.removeChild(subElements[0]);
  473. }
  474. dragDropDiv.style.display = 'block';
  475. newDiv = activeImage.cloneNode(true);
  476. newDiv.className = 'imageBox';
  477. newDiv.style.opacity = 0.5;
  478. newDiv.id = '';
  479. newDiv.style.padding = '2px';
  480. dragDropDiv.appendChild(newDiv);
  481. dragDropDiv.style.top = tmpTop + 'px';
  482. dragDropDiv.style.left = tmpLeft + 'px';
  483. }
  484. return false;
  485. }
  486. function getMouseButtn(e) {
  487. var code;
  488. e = e || window.event;
  489. code = e.button;
  490. if (code) {
  491. if (browser.msie && browser.version < 9) {
  492. code = code === 1 ? 0 : (code === 4 ? 1 : code);
  493. }
  494. }
  495. return code;
  496. }
  497. function selectImage(e) {
  498. // ----------------------------------------------------------------------------------
  499. var el = this.parentNode.firstChild.firstChild, obj;
  500. if (!el) {
  501. return;
  502. }
  503. e = e || window.event;
  504. if (getMouseButtn(e) === 2) {
  505. return;
  506. }
  507. obj = this.parentNode;
  508. hideDelete();
  509. obj.className = 'imageBoxHighlighted';
  510. activeImage = obj;
  511. readyToMove = true;
  512. moveTimer = 0;
  513. tmpLeft = e.clientX + Math.max(document.body.scrollLeft, document.documentElement.scrollLeft);
  514. tmpTop = e.clientY + Math.max(document.body.scrollTop, document.documentElement.scrollTop);
  515. startMoveTimer();
  516. return false;
  517. }
  518. function dragDropEnd() {
  519. // ----------------------------------------------------------------------------------
  520. var parentObj, chkObj, turn = false;
  521. readyToMove = false;
  522. moveTimer = -1;
  523. dragDropDiv.style.display = 'none';
  524. insertionMarker.style.display = 'none';
  525. if (!activeImage) {
  526. return;
  527. }
  528. if (destinationObject && destinationObject !== activeImage) {
  529. parentObj = destinationObject.parentNode;
  530. chkObj = destinationObject.previousSibling;
  531. turn = false;
  532. if (chkObj === null) {
  533. chkObj = document.getElementById('imageListWrapper').firstChild;
  534. turn = true;
  535. }
  536. if (chkObj.id.indexOf('spacer') !== -1) {
  537. chkObj = chkObj.previousSibling;
  538. }
  539. if (chkObj.firstChild.firstChild === null) {
  540. reOrder();
  541. return;
  542. }
  543. if (chkObj && chkObj.id !== null) {
  544. while (chkObj) {
  545. if (chkObj.firstChild.firstChild !== null) {
  546. break;
  547. }
  548. chkObj = chkObj.previousSibling;
  549. }
  550. destinationObject = turn ? chkObj : chkObj.nextSibling;
  551. }
  552. parentObj.insertBefore(activeImage, destinationObject);
  553. reOrder();
  554. activeImage = null;
  555. destinationObject = null;
  556. getDivCoordinates();
  557. return false;
  558. }
  559. activeImage.className = 'imageBox';
  560. return true;
  561. }
  562. function dragDropMove(e) {
  563. // ----------------------------------------------------------------------------------
  564. var elementFound = false, prop, offsetX, offsetY, leftPos, topPos, btnCode;
  565. if (moveTimer === -1 || !readyToMove) {
  566. return;
  567. }
  568. e = e || window.event;
  569. leftPos = e.clientX + document.documentElement.scrollLeft - eventDiff_x;
  570. topPos = e.clientY + document.documentElement.scrollTop - eventDiff_y;
  571. dragDropDiv.style.top = topPos + 'px';
  572. dragDropDiv.style.left = leftPos + 'px';
  573. leftPos = leftPos + eventDiff_x;
  574. topPos = topPos + eventDiff_y;
  575. if (getMouseButtn(e) !== 0) {
  576. dragDropEnd();
  577. }
  578. for (prop in divXPositions) {
  579. if (!divXPositions.hasOwnProperty(prop) || divXPositions[prop].className === 'clear') {
  580. continue;
  581. }
  582. if (divXPositions[prop] < leftPos &&
  583. (divXPositions[prop] + divWidth[prop] * 0.7) > leftPos &&
  584. divYPositions[prop] < topPos &&
  585. (divYPositions[prop] + divWidth[prop]) > topPos) {
  586. if (browser.msie) {
  587. offsetX = offsetX_marker;
  588. offsetY = offsetY_marker;
  589. } else {
  590. offsetX = geckoOffsetX_marker;
  591. offsetY = geckoOffsetY_marker;
  592. }
  593. insertionMarker.style.top = divYPositions[prop] + offsetY + 'px';
  594. insertionMarker.style.left = divXPositions[prop] + offsetX + 'px';
  595. insertionMarker.style.display = 'block';
  596. destinationObject = document.getElementById(prop);
  597. elementFound = true;
  598. break;
  599. }
  600. }
  601. if (!elementFound) {
  602. insertionMarker.style.display = 'none';
  603. destinationObject = null;
  604. }
  605. return false;
  606. }
  607. function saveImageOrder() {
  608. // ----------------------------------------------------------------------------------
  609. var rData = [],
  610. objects = document.getElementById('imageListWrapper').getElementsByTagName('div'),
  611. i;
  612. for (i = 0; i < objects.length; i++) {
  613. if (objects[i].className === 'imageBox' ||
  614. objects[i].className === 'imageBoxHighlighted') {
  615. rData.push(objects[i].id);
  616. }
  617. }
  618. return rData;
  619. }
  620. function initGallery() {
  621. // ----------------------------------------------------------------------------------
  622. var imgBox = document.getElementById('imageListWrapper').getElementsByTagName('div'),
  623. i;
  624. for (i = 0; i < imgBox.length; i++) {
  625. if (imgBox[i].className === 'imageBox_theImage') {
  626. imgBox[i].onmousedown = selectImage;
  627. }
  628. }
  629. document.body.onselectstart = cancelEvent;
  630. document.body.ondragstart = cancelEvent;
  631. document.body.onmouseup = dragDropEnd;
  632. document.body.onmousemove = dragDropMove;
  633. dragDropDiv = document.getElementById('dragDropContent');
  634. insertionMarker = document.getElementById('insertionMarker');
  635. getDivCoordinates();
  636. }
  637. function doSubmit() {
  638. // ----------------------------------------------------------------------------------
  639. var el = document.getElementById('imageListWrapper').getElementsByTagName('div'),
  640. imageArray = [],
  641. num = 0,
  642. elem = document.getElementById('id_alignment').elements,
  643. imgParagraph = false,
  644. useSpacer = false,
  645. imgAlign = 'top', i, imgBox, input;
  646. for (i = 0; i < elem.length; i++) {
  647. input = elem[i];
  648. switch (input.name) {
  649. case "alignment" :
  650. if (input.checked) {
  651. imgAlign = input.value;
  652. }
  653. break;
  654. case "para" :
  655. imgParagraph = input.checked;
  656. break;
  657. case "use_spacer" :
  658. useSpacer = input.checked;
  659. break;
  660. }
  661. }
  662. for (i = 0; i < el.length; i++) {
  663. imgBox = el[i];
  664. if (imgBox.className !== "imageBox_theImage") {
  665. continue;
  666. }
  667. if (imgBox.firstChild !== null) {
  668. imageArray[num] = imageCompletedList[imgBox.id];
  669. if (imgAlign === "break") {
  670. imageArray[num].alt = "break";
  671. } else {
  672. imageArray[num].alt = '';
  673. imageArray[num].align = imgAlign;
  674. }
  675. num++;
  676. }
  677. }
  678. if (imageArray.length > 0) {
  679. oEditor.doInsertImage(imageArray, imgParagraph, useSpacer);
  680. }
  681. oEditor.popupWinClose();
  682. }
  683. function initEvent() {
  684. var swfVersionStr = "11.1.0",
  685. xiSwfUrlStr = "http://get.adobe.com/kr/flashplayer/",
  686. flashvars = {
  687. UploadScript: uploadScript,
  688. DeleteScript: deleteScript,
  689. UploadButton: uploadButton,
  690. MakeThumbnail: makeThumbnail,
  691. ThumbnailWidth: makeThumbnailWidth,
  692. ThumbnailHeight: makeThumbnailHeight,
  693. ImageResizeWidth: imageResizeWidth,
  694. loadPolicyFile: true,
  695. SortOnName: sortOnName
  696. },
  697. params = {
  698. quality: "high",
  699. bgcolor: "#ffffff",
  700. allowscriptaccess: "Always",
  701. allowfullscreen: "false",
  702. //allowNetworking: "all",
  703. wmode: "transparent"
  704. },
  705. attributes = { id: AppID, name: AppID, align: "middle" };
  706. swfobject.embedSWF(AppSRC, "oFlashButton", "93", "22", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
  707. }
  708. function init(dialog) {
  709. var dlg = new Dialog(this),
  710. elem = document.getElementById('id_alignment').elements,
  711. i;
  712. oEditor = this;
  713. oEditor.dialog = dialog;
  714. browser = oEditor.getBrowser();
  715. uploadImagePath = oEditor.config.iconPath + 'imageUpload';
  716. uploadButton = '../icons/imageUpload/add.gif';
  717. AppSRC = oEditor.config.popupPath + 'flash/chximage.swf';
  718. uploadMaxNumber = oEditor.config.imgUploadNumber;
  719. uploadScript = oEditor.config.editorPath + 'imageUpload/upload.asp';
  720. deleteScript = oEditor.config.editorPath + 'imageUpload/delete.asp';
  721. imageResizeWidth = oEditor.config.imgMaxWidth;
  722. makeThumbnail = oEditor.config.makeThumbnail;
  723. sortOnName = oEditor.config.imgUploadSortName;
  724. makeThumbnailWidth = oEditor.config.thumbnailWidth;
  725. makeThumbnailHeight = oEditor.config.thumbnailHeight;
  726. document.getElementById("maxImageNum").appendChild(document.createTextNode(uploadMaxNumber));
  727. button = [
  728. { alt: "", img: 'submit.gif', cmd: doSubmit, hspace: 2 },
  729. { alt: "", img: 'cancel.gif', cmd: closeWindow, hspace: 2 }
  730. ];
  731. dlg.setDialogHeight(370);
  732. dlg.showButton(button);
  733. showContents();
  734. initGallery();
  735. showUploadWindow();
  736. initEvent();
  737. createInsertionMaker();
  738. for (i = 0; i < elem.length; i++) {
  739. if (elem[i].name === "alignment" && elem[i].value === oEditor.config.imgDefaultAlign) {
  740. elem[i].checked = "checked";
  741. break;
  742. }
  743. }
  744. }