/*-- ------------------------------------------------------ oxsolution JAVASCRIPT functions http://www.oxsolution.com ------------------------------------------------------ --*/ (function(Viewer) { if (!Viewer) return; var Content = getFirstChild(Viewer,".content"); if (!Content) return; var aImg = Content.getElementsByTagName("img"), //À̹ÌÁö ¹è¿­ nImg = aImg.length; if (!nImg) return; foreach(Viewer.getElementsByTagName("span"), function(i,elm) { if (hasClass(elm,"inp_page")) { elm.innerHTML = ' / '+nImg; //Àüü ÆäÀÌÁö ¼ö return false; } }); var PageText = getById("pageText"), ZoomText = getById("zoomText"), ShowFit = getById("showFit"), ShowTwo = getById("showTwo"); if (!PageText || !ZoomText || !ShowFit || !ShowTwo) return; var aPaper = [], //À̹ÌÁö ¹è¿­°ú 1:1·Î ¸ÅĪ aWidth = [], aHeight = [], aY = []; foreach(aImg, function(i,elm) { aPaper[i] = elm.parentNode; aWidth[i] = parseInt(elm.getAttribute("width"),10); //À̹ÌÁö ű׿¡ width, height ¼Ó¼º Çʼö aHeight[i] = parseInt(elm.getAttribute("height"),10); }); var papers = getFirstChild(Content,".papers"), maxWidth = Math.max.apply(null,aWidth), //À̹ÌÁö Å©±â°¡ ¼­·Î ´Ù¸¦ °æ¿ì ÃÖ´ë°ªÀ» ÂüÁ¶ maxHeight = Math.max.apply(null,aHeight), getIntStyle = function(elm,key) { return parseInt(elm.style[key] || (window.getComputedStyle ? window.getComputedStyle(elm,null).getPropertyValue(key.replace(/([A-Z])/g,"-$1").toLowerCase()) : elm.currentStyle[key]) || 0, 10) || 0; }, spaceTop = getIntStyle(aPaper[0],"borderTopWidth") + getIntStyle(aPaper[0],"paddingTop"), //À̹ÌÁö °£°Ý spaceRight = getIntStyle(aPaper[0],"paddingRight") + getIntStyle(aPaper[0],"borderRightWidth"), spaceBottom = getIntStyle(aPaper[0],"borderBottomWidth") + getIntStyle(aPaper[0],"paddingBottom"), spaceLeft = getIntStyle(aPaper[0],"borderLeftWidth") + getIntStyle(aPaper[0],"paddingLeft"), spaceX = spaceRight + spaceLeft, spaceY = spaceTop + spaceBottom; //µ¿ÀÛ ÇÔ¼ö Á¤ÀÇ ----------------------------------------------------------- var goPage = function(go,relatively) { //ÆäÀÌÁö À̵¿ var v = parseInt(PageText.value,10) || 0; if (go != null) { if (relatively) { v += go; }else{ v = go; } } v = Math.min(Math.max(v,1),nImg); PageText.value = v; Content.scrollTop = parseInt(getOffsetPos(aPaper[v - 1]).y - getOffsetPos(Content).y + Content.scrollTop, 10); }; var getPage = function(baseY) { //ÇöÀç ÆäÀÌÁö ±¸Çϱâ if (aY.length) { if (ShowTwo.checked) { for (var i=2; i<=nImg; i+=2) { if (baseY < aY[i]) return i - 1; } }else{ for (var i=1; i<=nImg; i++) { if (baseY < aY[i]) return i; } } } return 1; }; var checkPage = function() { //ÇöÀç ÆäÀÌÁö Ç¥½Ã PageText.value = getPage(Content.scrollTop + parseInt(Content.clientHeight / 2, 10)); }; var setZoom = function(step) { //À̹ÌÁö Å©±â º¯°æ checkFit(false); removeClass(Content,"fit_view"); var v = parseInt(ZoomText.value,10) || 0; if (step != null) { v += step; v = parseInt(v / 10, 10) * 10; } v = Math.min(Math.max(v,10),200); ZoomText.value = v; var cTop = Content.scrollTop, cLeft = Content.scrollLeft, sX = 0, sY = 0, s; if (cTop) { var page = getPage(cTop), n = page, a = 0; if (ShowTwo.checked) { n = Math.ceil(n / 2); a = 1; } sY = spaceY * (n - 1); s = cTop - aY[page - 1]; if (s > 0) { if (s > spaceTop) { sY += spaceTop; s = spaceBottom - (aY[page + a] - cTop); if (s > 0) { sY += s; } }else{ sY += s; } } } if (cLeft) { if (cLeft > spaceLeft) { sX = spaceLeft; if (ShowTwo.checked) { s = spaceRight - (parseInt(papers.style.width,10) / 2 - cLeft); if (s > 0) { sX += s; } } }else{ sX = cLeft; } } var bf = parseInt(aImg[0].style.width,10); foreach(aImg, function(i,elm) { elm.style.width = parseInt(aWidth[i] * v / 100, 10)+"px"; elm.style.height = parseInt(aHeight[i] * v / 100, 10)+"px"; }); var w = parseInt(maxWidth * v / 100, 10) + spaceX; if (ShowTwo.checked) w *= 2; papers.style.width = w+"px"; if (bf) { var af = parseInt(aImg[0].style.width,10); if (af != bf) { var pct = af / bf * 100; Content.scrollTop = (cTop - sY) * pct / 100 + sY; Content.scrollLeft = (cLeft - sX) * pct / 100 + sX; } } }; var getZoom = function() { //ÇöÀç À̹ÌÁö ¹èÀ² ±¸Çϱâ var w = 0; if (ShowFit.checked) { w = Content.clientWidth || 0; //È­¸éÀÌ ·Îµù ÁßÀ̸é offsetWidth °ªÀÌ Á¤È®ÇÏÁö ¾ÊÀ» ¼ö ÀÖÀ½ if (ShowTwo.checked) w /= 2; w -= spaceX; } if (w < 1) w = aImg[0].offsetWidth; return w / aWidth[0] * 100; }; var checkZoom = function() { //ÇöÀç À̹ÌÁö ¹èÀ² Ç¥½Ã ZoomText.value = parseInt(getZoom(),10); }; var setFit = function(v) { //Æø ¸ÂÃã if (v == null) { v = ShowFit.checked; }else{ checkFit(v); } if (v) { addClass(Content,"fit_view"); checkZoom(); }else{ removeClass(Content,"fit_view"); setZoom(); } }; var checkFit = function(v) { if (v == null) { v = ShowFit.checked; }else{ ShowFit.checked = v; } (v ? addClass : removeClass)(ShowFit.parentNode,"on"); }; var setTwo = function(v) { //µÎ À徿 if (v == null) { v = ShowTwo.checked; }else{ checkTwo(v); } if (v) { removeClass(Content,"one_view"); addClass(Content,"two_view"); }else{ removeClass(Content,"two_view"); addClass(Content,"one_view"); } checkZoom(); }; var checkTwo = function(v) { if (v == null) { v = ShowTwo.checked; }else{ ShowTwo.checked = v; } (v ? addClass : removeClass)(ShowTwo.parentNode,"on"); }; var cacheY = function() { //À̹ÌÁö Æ÷Áö¼Ç ij½Ã var y = 0, i = 0, j = 1, zoom = getZoom(); if (ShowTwo.checked) { if (ShowFit.checked) { for (; i