// Copyright(c)2007 SWSPOT All rights reserved. // Title : Stylet Scrapping Tool // Version : 1.0 // Date : 2007-12-17 // Client : Stylet // Developer : Jae-Kyun, Park (NOSPAM_______duex5190@nate.com) // History : 1.0 - Functions are Implemented. // 1.1 - recurse frames bugs have been fixed. var StyletScrapTool = function() { this.initialize(); } StyletScrapTool.prototype = { /* --------------- properties --------------- */ isDebug : false, isLocked : false, checkFrames : true, urlHost : "http://www.stylet.com/STYLET/common/scraptool",//will be replaced by ASP.net Engine (ResolveUrl(".")) imgurlHost : "http://img.halfclub.com/images_Stylet",//will be replaced by ASP.net Engine (WEB.CONFIG IMGURL) fileScrap : "wndAddscrap.aspx", browserVersion : 0, browserIE : false, dwWidth : 420, dwHeight : 320, runMode : "modal", //modal , div /* --------------- local variable --------------- */ m_eventBuffer : new Array(), m_frameBuffer : new Array(), m_majorVersion : 1, m_minorVersion : 7, m_isframesetdoc : false, m_pagedoc : null, m_toppageurl : "", m_recurseCount : 0, m_postdiv : null, m_postdiv_html : null, m_loadingdiv : null, m_loadingdocument : null, m_iframeobj : null, /* --------------- methods --------------- */ //Print class name or short description toString : function() { return "Stylet Scrapping Tool by SWSPOT (v" + this.m_majorVersion + "." + this.m_minorVersion + ")"; }, //Initialize class initialize : function() { /* check browser version */ var agent = navigator.userAgent.toLowerCase(); var ver = agent.split(';'); if(agent.indexOf('msie') != -1) { this.browserVersion = parseFloat(ver[1].slice(6, ver[1].length)); this.browserIE = true; } /* default page url -> top document.URL */ this.m_toppageurl = document.URL; this.m_loadingdocument = document; if(document.getElementsByTagName("FRAMESET").length>0)this.m_isframesetdoc = true; /* If Document has frameset, find the largest frame from frameset objects */ if(this.m_isframesetdoc) { var obj = document.getElementsByTagName("FRAMESET")[0]; var framebuffer = new Array(); var rowvalue = obj.getAttribute("rows") var strs = ""; if(rowvalue.indexOf(",")>-1) { var arr = rowvalue.split(','); for(i=0;iscleft)scleft = document.body.scrollLeft; if(document.body.scrollTop>sctop)sctop = document.body.scrollTop; }catch(e){} var screenwidth = document.documentElement.clientWidth ; var screenheight = document.documentElement.clientHeight; if(screenwidth==0||screenheight==0) { screenwidth = document.body.clientWidth; screenheight = document.body.clientHeight; } //alert("screen width : " + screenwidth + " x " + screenheight); var left = parseInt((screenwidth - divwidth)/2) + scleft; var top = parseInt((screenheight - divheight)/2) + sctop; //iframe �� �߰��Ͽ��� selectbox ���� �ö󰡵��� �Ѵ�. var iframeobj = document.createElement("iframe"); iframeobj.style.position = "absolute"; iframeobj.style.zIndex = "9998"; iframeobj.style.left = left + "px"; iframeobj.style.top = top + "px"; iframeobj.style.width = divwidth + "px"; iframeobj.style.height = divheight + "px"; iframeobj.setAttribute("frameBorder","0"); iframeobj.setAttribute("border","0"); this.m_iframeobj = iframeobj; this.m_loadingdocument.body.appendChild(iframeobj); //alert("OK"); var divobj = document.createElement("div"); divobj.style.position = "absolute"; divobj.style.zIndex = "9999"; divobj.style.left = left + "px"; divobj.style.top = top + "px"; divobj.style.width = divwidth + "px"; divobj.style.height = divheight + "px"; //divobj.style.border = "1px solid #999999"; //divobj.style.backgroundColor = "#fffacd"; divobj.style.verticalAlign = "middle"; divobj.style.textAlign = "center"; //divobj.innerHTML = "
Stylet Scrapping Tool (v" + this.m_majorVersion + "." + this.m_minorVersion + ") Loaded

Please Click the image that you want to scrap.
"; //loading design changed by Upleat var htmls = ""; htmls += "\"Close\" \"OK\" \"Cancel\""; divobj.innerHTML = htmls; this.m_loadingdiv = divobj; this.m_loadingdocument.body.appendChild(divobj); this.objectinCenter(divobj,divwidth,divheight); this.objectinCenter(iframeobj,divwidth,divheight); this.log("design loaded"); //setTimeout('sst.closeloading();',2500); }, designloader : function() { //sst.closeloading(); if(this.m_isframesetdoc) { alert("Stylet Scrapping Tool (v" + this.m_majorVersion + "." + this.m_minorVersion + ") is running.\n\nClick the image that you want to scrap."); return; } var divwidth = 267; var divheight = 109; //calculate center position var scleft = document.documentElement.scrollLeft; var sctop = document.documentElement.scrollTop; try { if(document.body.scrollLeft>scleft)scleft = document.body.scrollLeft; if(document.body.scrollTop>sctop)sctop = document.body.scrollTop; }catch(e){} var screenwidth = document.documentElement.clientWidth ; var screenheight = document.documentElement.clientHeight; if(screenwidth==0||screenheight==0) { screenwidth = document.body.clientWidth; screenheight = document.body.clientHeight; } //alert("screen width : " + screenwidth + " x " + screenheight); var left = parseInt((screenwidth - divwidth)/2) + scleft; var top = parseInt((screenheight - divheight)/2) + sctop; //iframe �� �߰��Ͽ��� selectbox ���� �ö󰡵��� �Ѵ�. var iframeobj = document.createElement("iframe"); iframeobj.style.position = "absolute"; iframeobj.style.zIndex = "9998"; iframeobj.style.left = left + "px"; iframeobj.style.top = top + "px"; iframeobj.style.width = divwidth + "px"; iframeobj.style.height = divheight + "px"; iframeobj.setAttribute("frameBorder","0"); iframeobj.setAttribute("border","0"); this.m_iframeobj = iframeobj; this.m_loadingdocument.body.appendChild(iframeobj); //alert("OK"); var divobj = document.createElement("div"); divobj.style.position = "absolute"; divobj.style.zIndex = "9999"; divobj.style.left = left + "px"; divobj.style.top = top + "px"; divobj.style.width = divwidth + "px"; divobj.style.height = divheight + "px"; //divobj.style.border = "1px solid #999999"; //divobj.style.backgroundColor = "#fffacd"; divobj.style.verticalAlign = "middle"; divobj.style.textAlign = "center"; //divobj.innerHTML = "
Stylet Scrapping Tool (v" + this.m_majorVersion + "." + this.m_minorVersion + ") Loaded

Please Click the image that you want to scrap.
"; //loading design changed by Upleat var htmls = ""; htmls += "\"Close\"\"OK\""; divobj.innerHTML = htmls; this.m_loadingdiv = divobj; this.m_loadingdocument.body.appendChild(divobj); this.objectinCenter(divobj,divwidth,divheight); this.objectinCenter(iframeobj,divwidth,divheight); this.log("design loaded"); //setTimeout('sst.closeloading();',2500); }, objectinCenter : function(obj,divwidth,divheight) { /* logging browser info */ var logmsg = ""; var baseobject = null; var screenwidth = 0; var screenheight = 0; var scleft = 0; var sctop = 0; if(document.documentElement) { this.log("document.documentElement supported.\n"); baseobject = document.documentElement; }else if(document.body) { this.log("document.body supported.\n"); baseobject = document.body; } this.log("screenwidth : " + baseobject.clientWidth); this.log("screenheight : " + baseobject.clientHeight); this.log("scrollleft : " + baseobject.scrollLeft); this.log("scrolltop : " + baseobject.scrollTop); this.log("scrollwidth : " + baseobject.scrollWidth); this.log("scrollheight : " + baseobject.scrollHeight); this.log("offsetWidth : " + baseobject.offsetWidth); this.log("offsetHeight : " + baseobject.offsetHeight); this.log("clientWidth : " + baseobject.clientWidth); this.log("clientHeight : " + baseobject.clientHeight); screenwidth = baseobject.offsetWidth; screenheight = baseobject.offsetHeight; if(baseobject.clientWidth>0) { screenwidth = baseobject.clientWidth; screenheight = baseobject.clientHeight; } scleft = baseobject.scrollLeft; sctop = baseobject.scrollTop; /* logging end */ var left = parseInt((screenwidth - divwidth)/2) + scleft; var top = parseInt((screenheight - divheight)/2) + sctop; obj.style.left = left + "px"; obj.style.top = top + "px"; //alert("screen width : " + screenwidth + " / screen height : " + screenheight + "\n\nlayer position : " + left + " / " + top + " -> scrollleft : " + scleft + " / scrolltop : " + sctop); //this.AddEventHandler(document,"keydown",function(event){sst.hookKeydown(event);}); }, closeloading : function() { try { this.m_loadingdocument.body.removeChild(this.m_loadingdiv); this.m_loadingdocument.body.removeChild(this.m_iframeobj); }catch(e){} //this.RemoveEventHandler(document,"keydown",function(event){sst.hookKeydown(event);}); }, hookKeydown : function(event) { alert("keycode : " + event.keyCode); }, //Start up the scrapping tool StartUp : function() { // scriptElement = this.m_pagedoc.getElementsByTagName('HEAD')[0].appendChild( this.m_pagedoc.createElement('script') ); // scriptElement.type = 'text/javascript'; // scriptElement.src = this.urlHost + '/bookmarklet_drag.js'; if(this.isDebug) { trace(this.toString()); this.CreateDebugWindow(); } if(!this.browserIE) { this.dwWidth = this.dwWidth - 10; this.dwHeight = this.dwHeight - 10; } else if(this.browserIE&&this.browserVersion<7) { this.dwWidth = this.dwWidth + 10; this.dwHeight = this.dwHeight + 65; this.log("size modified automatically -> " + this.dwWidth + " x " + this.dwHeight); } }, //Lock the page sets LockPage : function() { try { this.log("LockPage() - " + this.isLocked); if(this.isLocked)return; this.m_eventBuffer.length = 0; this.m_frameBuffer.length = 0; this.isLocked = true; this.RecurseDocument(this.m_pagedoc,true); } catch (e) { this.log("LockPage Error : " + e.description); this.traceDump(e); } }, //Release the pages sets UnlockPage : function() { try { this.log("UnlockPage() - " + this.isLocked); if(!this.isLocked)return; this.m_frameBuffer.length = 0; this.m_recurseCount = 0; this.RecurseDocument(this.m_pagedoc,false); this.m_eventBuffer.length = 0; this.isLocked = false; } catch (e) { this.log("UnlockPage Error : " + e.description); this.traceDump(e); } }, //Recurse document //_param doc ___ document [object] //_param runType ___ lock(true) / unlock(false) [Boolean] RecurseDocument : function(doc,runType) { this.m_recurseCount++; this.log("\n* RecurseDocument(" + this.m_recurseCount + ") : @doc : " + doc.location.href + " / @runType : " + runType); this.log("body width : " + doc.body.clientWidth + " x " + doc.body.clientHeight); if(this.m_recurseCount>50) { this.log("There has been too many recursive document. Exited forcely."); return; } var imgobj = doc.getElementsByTagName("img"); this.log("Images Count : " + imgobj.length); //trace(imgobj.length); for(i=0;i0) { for(i=0;i> Clicked Image Information.\n\nURL : " + imgurl + "\n\nDocument URL : " + docobj.location.href); } this.log("runMode : " + this.runMode); if(this.runMode=="modal") { var urlparam = "imgurl=" + encodeURIComponent(param_imgurl) + "&docurl=" + encodeURIComponent(param_docurl); this.log("window open prepare [browserIE] -> " + this.browserIE); if(this.browserIE) { // this.log("window open -> modal"); // // var retval = this.wndOpenmodal(this.urlHost + "/" + this.fileScrap + "?" + urlparam,this.dwWidth,this.dwHeight); // //alert("return value : " + retval); // // // //this.UnlockPage(); // // this.confirmloader(); this.log("window open -> new win"); urlparam += "&newwin=Y"; this.popupWindowInCenter(this.urlHost + "/" + this.fileScrap + "?" + urlparam,"wndScraptool","width=" + (this.dwWidth-10) + ",height=" + (this.dwHeight-40)); //FireFox �� ���� ��ȣȯIE�� ��� Modal �� �׼��� ������ �����Ƿ� ��â�� Open �ѵ� �ٷ� confirmloader �� ȭ�鿡 ����ǵ��� �Ѵ�. this.confirmloader(); }else { this.log("window open -> new win"); urlparam += "&newwin=Y"; this.popupWindowInCenter(this.urlHost + "/" + this.fileScrap + "?" + urlparam,"wndScraptool","width=" + this.dwWidth + ",height=" + this.dwHeight); //FireFox �� ���� ��ȣȯIE�� ��� Modal �� �׼��� ������ �����Ƿ� ��â�� Open �ѵ� �ٷ� confirmloader �� ȭ�鿡 ����ǵ��� �Ѵ�. this.confirmloader(); } }else if(this.runMode=="div") { if(this.m_postdiv==null) { this.log("postdiv container is null"); this.m_postdiv = this.m_pagedoc.createElement("div"); this.m_postdiv.innerHTML = this.m_postdiv_html; this.log("postdiv container generated"); } } this.log("image pannel show"); }, //Create debug window CreateDebugWindow : function() { var wndDebug = this.m_pagedoc.createElement("div"); var txtDebug = this.m_pagedoc.createElement("textarea"); txtDebug.style.width = this.dwWidth + "px"; txtDebug.style.height = this.dwHeight + "px"; txtDebug.style.fontSize = "11px"; txtDebug.style.backgroundColor = "black"; txtDebug.style.color = "white"; txtDebug.id = "xtxt_debug_viewer"; wndDebug.id = "wnd_debug_viewer"; wndDebug.style.position = "absolute"; wndDebug.style.zIndex = "9999"; wndDebug.style.top = "100px"; wndDebug.style.left = "100px"; wndDebug.style.border = "1px solid #000000"; wndDebug.style.backgroundColor = "navy"; wndDebug.style.color = "white"; wndDebug.style.fontWeight = "bolder"; var bodyobj = this.m_pagedoc.body; var mentdiv = this.m_pagedoc.createElement("div"); mentdiv.innerHTML = "DEBUG WINDOW"; //lock unlock test buttons mentdiv.innerHTML += "   "; mentdiv.id = "wnd_debug_viewer_bar"; mentdiv.style.padding = "5px"; wndDebug.appendChild(mentdiv); //test //var testdiv = this.m_pagedoc.createElement("div"); //testdiv.innerHTML = ""; //wndDebug.appendChild(testdiv); wndDebug.appendChild(txtDebug); bodyobj.appendChild(wndDebug); this.log("debug window initialized (browser version : " + this.browserVersion + ")"); setTimeout(this.DragableObject,1000); }, //make debug window dragable (asynchronous) DragableObject : function() { try { nfx.drag( 'wnd_debug_viewer' ); } catch (e) { //trace("error : " + e.description); } }, //Check that array contains some element. arrayContains : function(arrobj,compareObj) { var retval = false; var x = 0; for(x=0;x " + e.description); } } }, //open modal function wndOpenmodal : function(url,width,height) { //showModelessDialog //showModalDialog //var retval_hWnd = window.showModalDialog(url,'dlgWnd', 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px; center:yes; help:no; status:no; scroll:yes; resizable:yes'); var retval_hWnd = window.open(url,'dlgWnd', 'width=' + width + 'px,height=' + (height-40) + 'px, center:yes, help:no, status:no, scroll:yes, resizable:yes'); retval_hWnd.focus(); //alert("retval_hWnd : " + retval_hWnd); if(typeof retval_hWnd=="undefined"||retval_hWnd==null||typeof retval_hWnd==null) { retval_hWnd = ""; } this.log("modal window return value : " + retval_hWnd); return retval_hWnd; }, //�̺�Ʈ�� �߰��մϴ�.(Attach) //obj : �̺�Ʈ�� �߰��� DOM Object //eventName : �̺�Ʈ�� (on �� �����ϰ� ��:load) //functionNotify : �̺�Ʈ �ݹ��Լ� AddEventHandler : function(obj, eventName, functionNotify) { if (obj.attachEvent) { obj.attachEvent('on' + eventName, functionNotify); } else if (obj.addEventListener) { obj.addEventListener(eventName, functionNotify, true); } else { obj['on' + eventName] = functionNotify; } }, //�̺�Ʈ�� �����մϴ�.(Detach) //obj : �̺�Ʈ�� �߰��� DOM Object //eventName : �̺�Ʈ�� (on �� �����ϰ� ��:load) //functionNotify : �̺�Ʈ �ݹ��Լ� RemoveEventHandler : function(obj, eventName, functionNotify) { if (obj.detachEvent) { obj.detachEvent('on' + eventName, functionNotify); } else if (obj.removeEventListener) { obj.removeEventListener(eventName, functionNotify, true); } else { obj['on' + eventName] = null; } }, //ȭ�� �߰����� Window Open //targetUrl : ������ Page URL //windowName : ������ Window Handle Name //properties : window.open properties (��: width=400,height=300) popupWindowInCenter : function (targetUrl, windowName, properties) { var arr = properties.replace(/=/ig,',').split(','); var childWidth, childHeight; for(var i=0; i