//////////////////////////////////////////////////////////////////////////////////
// class clip object
function ClipObject(id)
{
var waRc= g_dc.GetWorkAreaRC();
this.m_expObj = g_dc.getElemFormID(id);
this.m_icnObj = this.CreateIcnObj(this.m_expObj);
if (this.m_icnObj==null || this.m_expObj==null){alert('error0');return;}
this.m_icnObj.style.position="absolute";
this.m_expObj.style.position="absolute";
this.m_origIsIcn = this.m_isIcn = (this.m_expObj.getAttribute("isIcn")==1);
this.m_defW = toInt(this.m_expObj.getAttribute("defW"))+SCROLL_WIDTH;
this.m_defH = toInt(this.m_expObj.getAttribute("defH"))+SCROLL_WIDTH;
this.m_BRZ = this.m_expObj.getAttribute("BRZ");
//alert("orig def height is: "+ toInt(this.m_expObj.getAttribute("defH"))+" with scroll its: "+this.m_defH);
this.m_origW = this.m_realW = toInt(this.m_expObj.getAttribute("realW"));
if (this.m_realW==0) //first time the clip is viewed
this.m_origW = this.m_realW = this.m_defW;
this.m_origH = this.m_realH = toInt(this.m_expObj.getAttribute("realH"));
if (this.m_realH==0) //first time the clip is viewed
this.m_origH = this.m_realH = this.m_defH;
this.m_maxW = Math.min(toInt(this.m_defW)+toInt(g_dc.m_clipResidueX), waRc.m_width);
this.m_maxH = Math.min(toInt(this.m_defH)+toInt(g_dc.m_clipResidueY), waRc.m_height);
this.m_deleted = false;
this.m_origX = this.m_posX = toInt(this.m_expObj.getAttribute("xPos"))+g_dc.GetWorkAreaRC().m_left;
this.m_origY = this.m_posY = toInt(this.m_expObj.getAttribute("yPos"))+g_dc.GetWorkAreaRC().m_top;
this.m_clpID = this.m_expObj.getAttribute("clipID");
this.url = this.m_expObj.getAttribute("srcUrl");
this.m_expObj.dragContainer = this.m_icnObj.dragContainer = this;
this.m_selected = false;
this.m_scrollVisibleX=false;
this.m_scrollVisibleY=false;
//this.m_clippingState = SC_SHOW_ALL;
//init inner clip bar item
var clipbar = g_dc.GetObjInnerByName(this.m_expObj, "clipTopBar")[0];
clipbar.onmousedown = g_eventRouter.onClipbarMouseDown;
clipbar.dragContainer = this;
this.m_icnObj.onmousedown = g_eventRouter.OnIconMouseDown;
this.m_icnObj.onmouseup = g_eventRouter.OnIconMouseUp;
this.m_recalcIconPos = true;
this.InitClipButton("clipButtonIconize", "onIconizeClick", this.m_expObj);
g_dc.InitRegularTT("clipButtonIconize",this.m_expObj,"Switch to icon", this.m_clpID+"iconize");
this.InitClipButton("clipButtonClose", "onDeleteClick", this.m_expObj);
g_dc.InitRegularTT("clipButtonClose",this.m_expObj,"Delete clip", this.m_clpID+"dll");
this.InitClipButton("IcnExpandBtn", "onExpandClick", this.m_icnObj);
g_dc.InitRegularTT("IcnExpandBtn",this.m_icnObj,"Expand clip", this.m_clpID+"expnd");
this.InitClipButton("IcnToSourceBtn", "onToSourceClick", this.m_icnObj);
g_dc.InitRegularTT("IcnToSourceBtn",this.m_icnObj,"Open source URL in new window", this.m_clpID+"os");
this.InitClipButton("clipButtonMax", "onMaximizeClick", this.m_expObj);
g_dc.InitRegularTT("clipButtonMax",this.m_expObj,"Maximize clip", this.m_clpID+"mxmz");
this.InitClipButton("IcnDeleteBtn", "onDeleteClick", this.m_icnObj);
g_dc.InitRegularTT("IcnDeleteBtn",this.m_icnObj,"delete clip", this.m_clpID+"dl");
this.SetSelected(false);
//var gtsLink = g_dc.GetObjInnerByName(this.m_expObj, "BarGoToSourceLink")[0];
//gtsLink.onmousedown = g_eventRouter.onGtsMouseDown;
var clpDsc = g_dc.GetObjInnerByName(this.m_expObj, "BarClipDesc")[0];
clpDsc.onmousedown = g_eventRouter.onDscMouseDown;
clpDsc.dragContainer = this;
this.CreateResizeHandles();
this.m_origTxt = this.Edit_getText();
}
ClipObject.prototype.c_defIcnW = 104; ClipObject.prototype.c_defIcnH = 61;
ClipObject.prototype.InitClipButton = function(nm, hndlr, prnt)
{
var btn = g_dc.GetObjInnerByName(prnt, nm)[0];
btn.onclick = eval("g_eventRouter."+hndlr);
btn.onmousedown = g_eventRouter.onBtnMouseDown;
btn.onmouseup = g_eventRouter.onBtnMouseUp;
btn.dragContainer = this;
}
ClipObject.prototype.CreateResizeHandles = function()
{
this.m_resizeHandle = g_dc.CreateResizeHandleObj();
this.m_expObj.appendChild(this.m_resizeHandle);
this.m_resizeHandle.dragContainer = this;
}
ClipObject.prototype.CreateIcnObj = function(expOb)
{
if (expOb==null){alert('error1');return;}
var div = document.createElement('div');
if (!(div) || div==null){alert('error3');return;}
g_dc.SetClass(div, "clipIconDiv");
if (!(expOb.getAttribute("desc"))){alert('error2');return;}
div.innerHTML = "
"+
""+
""+
""+
"
" +
"" +
HtmlEncode(expOb.getAttribute("desc"))
"
";
div.setAttribute('id',expOb.getAttribute("id")+"_icn");
g_dc.docBody.appendChild(div);
div.style.width = this.c_defIcnW+'px';
div.style.height = this.c_defIcnH+'px';
var bb= g_dc.GetObjInnerByName(div, "clipIconDivBottom")[0];
bb.style.fontFamily = "Verdana,Arial";
bb.style.fontSize = "11px";
bb.style.fontWeight = "400";
div.ondblclick = g_eventRouter.OnIcnDblClick;
/////////////////////////////////////////////////////////////
// Tooltip Implementation
div.TTShow = function()
{
try{
var prnt = this.dragContainer;
var rc = prnt.GetCurrRC(this.m_icnObj);
var expndRc = prnt.CalcExpndRC(rc);
prnt.MoveTo(expndRc.m_left, expndRc.m_top,prnt.m_expObj, false);
prnt.ShowAsTT(true);
}
catch(err)
{alert(err);}
}
div.TTHide = function()
{
var prnt = this.dragContainer;
prnt.ShowAsTT(false);
}
div.TTGetID = function()
{
return (this.dragContainer.m_clpID);
}
div.TTIsSame = function(other)
{
return (this.TTGetID() == other.TTGetID());
}
div.TTInBounds = function(x,y)
{
var prnt = this.dragContainer;
var frmWrapTD = prnt.m_expObj.getElementsByTagName('iframe')[0].parentNode.parentNode;
var rc = new Rect(g_dc.getDocY(frmWrapTD),
g_dc.getDocX(frmWrapTD),
toInt(frmWrapTD.offsetWidth),
toInt(frmWrapTD.offsetHeight));
return rc.isPtWithin(x,y);
}
return div;
}
ClipObject.prototype.Show = function()
{
if (!(this.m_expObj)) {alert('error5');return;}
if (!this.m_isIcn)
{
this.setFrameReff();
g_dc.showElem(this.m_expObj, true);
g_dc.showElem(this.m_icnObj, false);
//this.SetClipping(SC_SHOW_NAKED);
}
else
{
g_dc.showElem(this.m_expObj, false);
g_dc.showElem(this.m_icnObj, true);
}
}
ClipObject.prototype.maximizeZ = function()
{
try{
g_dc.maxZ(this.m_expObj);
g_dc.maxZ(this.m_icnObj);
}
catch(err){
alert(err.description);
}
}
//ClipObject.prototype.SetClipping = function(type)
//{
// if (this.m_clippingState == type)
// return;
// switch (type)
// {
// case SC_SHOW_ALL:
// this.m_expObj.style.clip="rect(auto auto auto auto)";
// break;
// case SC_SHOW_ORIGLINK:
// case SC_SHOW_NAKED:
// var frmRap = g_dc.GetObjInnerByName(this.m_expObj,"frameWrapper")[0];
// var frm = g_dc.GetObjInnerByName(this.m_expObj,"clipIframe")[0];
// left = frm.offsetLeft;
// tp = frm.offsetTop+frm.offsetParent.offsetTop;
// btm = frm.offsetTop+frm.offsetHeight;
// rht = frm.offsetLeft+frm.offsetWidth;
// param = "rect("+tp+"px, "+rht+"px, "+btm+"px, "+left+"px)";
// //alert(param);
// this.m_expObj.style.clip=param;
// break;
// }
// this.m_clippingState = type;
//}
ClipObject.prototype.SetSelected = function(bSel)
{
if (this.m_selected==bSel)
return;
this.m_selected=bSel;
if (this.m_isIcn)
{
var btnDiv = g_dc.GetObjInnerByName(this.m_icnObj, "clipIconDivTop")[0];
var bottomDiv = g_dc.GetObjInnerByName(this.m_icnObj, "clipIconDivBottom")[0];
btnDiv.style.visibility=bSel?"visible":"hidden";
bottomDiv.style.borderWidth = bSel?'3px':'1px';
this.maximizeZ();
}
}
ClipObject.prototype.CalcIcnRC = function(rc)
{
var incwidth = toInt(this.m_icnObj.style.width);
var incheight = toInt(this.m_icnObj.style.height);
var left = rc.m_left + Math.round((rc.m_width - incwidth)/2);
var top = rc.m_top + Math.round((rc.m_height - incheight)/2);
var rcret = new Rect(top, left, incwidth, incheight);
return rcret;
}
ClipObject.prototype.CalcExpndRC = function(rc)
{
var expdWidth = toInt(this.m_expObj.style.width);
var expdHeight = toInt(this.m_expObj.style.height);
var left = rc.m_left - Math.round((expdWidth - rc.m_width)/2);
var top = rc.m_top - Math.round((expdHeight - rc.m_height)/2);
top = Math.max(top,g_dc.getScrollY());
var rcret = new Rect(top, left, expdWidth, expdHeight);
return rcret;
}
ClipObject.prototype.ToIcon = function(bIcn)
{
rc = this.GetCurrRC();
this.m_isIcn = bIcn;
if (bIcn)
{
if (this.m_recalcIconPos)
{
var icnrc = this.CalcIcnRC(rc);
this.MoveTo(icnrc.m_left, icnrc.m_top);
}
g_dc.Select(this);
}
else
{
var expndRc = this.CalcExpndRC(rc);
this.MoveTo(expndRc.m_left, expndRc.m_top);
this.m_recalcIconPos = false;
g_dc.Select(null);
}
this.Show();
g_dc.setDirty(true);
}
ClipObject.prototype.Hide = function()
{
if (!(this.m_expObj)) {alert('error6');return;}
g_dc.showElem(this.m_expObj, false);
g_dc.showElem(this.m_icnObj, false);
}
ClipObject.prototype.currObj = function()
{
return (!this.m_isIcn)?this.m_expObj:this.m_icnObj;
}
//relative to document 0 and 0
ClipObject.prototype.MoveTo = function(x,y, obj, bRecord)
{
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error10');return;}
if (!this.m_isIcn)
this.m_recalcIconPos=true;
currRC = this.GetCurrRC(obj);
currRC.m_left = x;
currRC.m_top = y;
this.FixPos(currRC);
tgObj = (typeof(obj)!=dd_u)?obj:this.currObj();
tgObj.style.left = currRC.m_left+'px';
tgObj.style.top = currRC.m_top+'px';
if (typeof(bRecord)==dd_u || bRecord==true)
{
this.m_posX=currRC.m_left;
this.m_posY=currRC.m_top;
}
}
ClipObject.prototype.ShowAsTT = function(bShow)
{
if (bShow)
{
g_dc.showElem(this.m_expObj, true);
var bar = g_dc.GetObjInnerByName(this.m_expObj, "clipTopBar")[0];
var rhandle = g_dc.GetObjInnerByName(this.m_expObj, "resizeHandle")[0];
g_dc.showElem(bar, false);
g_dc.showElem(rhandle, false);
this.InitFrameSrc();
g_dc.maxZ(this.m_expObj);
}
else
{
var bar = g_dc.GetObjInnerByName(this.m_expObj, "clipTopBar")[0];
var rhandle = g_dc.GetObjInnerByName(this.m_expObj, "resizeHandle")[0];
g_dc.showElem(bar, true);
g_dc.showElem(rhandle, true);
g_dc.showElem(this.m_expObj,false);
}
}
//get position rect relative to current window
ClipObject.prototype.getClientPosition = function()
{
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error10');return;}
var left = g_dc.getDocX(this.currObj())-g_dc.getScrollX();
var top = g_dc.getDocY(this.currObj())-g_dc.getScrollY();
rc = new Rect(top, left, this.currObj().offsetWidth, this.currObj().offsetHeight);
return rc;
}
ClipObject.prototype.GetCurrRC = function(obj)
{
tgObj = (typeof(obj)!=dd_u)?obj:this.currObj();
return new Rect(toInt(tgObj.style.top),
toInt(tgObj.style.left),
toInt(tgObj.style.width),
toInt(tgObj.style.height));
}
ClipObject.prototype.isPosValid = function(t,l,w,h)
{
var wa = g_dc.GetWorkAreaRC();
var rc = new Rect(t,l,w,h);
return wa.isWithin(rc);
}
ClipObject.prototype.FixPos = function(rc, maxW, maxH, minW, minH)
{
return g_dc.FixPos(rc, "workingArea", maxW, maxH, minW, minH);
}
ClipObject.prototype.MoveBy = function(dx,dy)
{
var retarr = new Array();
retarr['xresidue']=0;
retarr['yresidue']=0;
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error11');return;}
var newLeft = (toInt(this.currObj().style.left)+dx);
var newTop = (toInt(this.currObj().style.top)+dy);
var pos = new Rect( newTop,
newLeft,
this.currObj().style.width,
this.currObj().style.height);
pos.SnapTopLeft(6, (dx<0), (dy<0));
this.FixPos(pos);
retarr['xresidue']=dx-(pos.m_left-toInt(this.currObj().style.left));
retarr['yresidue']=dy-(pos.m_top-toInt(this.currObj().style.top));
this.currObj().style.left = pos.m_left+'px';
this.currObj().style.top = pos.m_top+'px';
this.m_posX=pos.m_left;
this.m_posY=pos.m_top;
if (!this.m_isIcn)
this.m_recalcIconPos=true;
g_dc.setDirty(true);
return retarr;
}
ClipObject.prototype.ResizeToDiff = function(dw, dh)
{
try{
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error12');return;}
if (this.m_isIcn) return;
var rc = this.GetCurrRC();
var w = rc.m_width+dw;
var h = rc.m_height+dh;
this.resizeTo(w, h, true);
}
catch(err)
{
alert(err.description);
}
}
ClipObject.prototype.c_clipMinWidth = 130;
ClipObject.prototype.c_clipMinHeight = 120;
ClipObject.prototype.resizeTo = function(w,h, bWithRims)
{
try{
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error12');return;}
var rimx = g_dc.m_clipResidueX;
var rimy = g_dc.m_clipResidueY;
var mxw = this.m_maxW;
var mxh = this.m_maxH;
var minw = this.c_clipMinWidth+rimx;
var minh = this.c_clipMinHeight+rimy;
w = toInt(w)+(bWithRims?0:rimx);
h= toInt(h)+(bWithRims?0:rimy);
var rc = this.GetCurrRC();
rc.m_width = w;
rc.m_height = h;
if (!this.m_isIcn)
{
this.FixPos(rc,mxw, mxh, minw, minh);
}
this.currObj().style.width = (rc.m_width)+'px';
this.currObj().style.height = (rc.m_height)+'px';
this.currObj().style.left = (rc.m_left)+'px';
this.currObj().style.top = (rc.m_top)+'px';
if (this.m_isIcn)
{
return;
}
this.m_realW = (rc.m_width-rimx);
this.m_realH = (rc.m_height-rimy);
//alert(bWithRims +" "+this.m_realW+" "+this.m_realH+" "+rimx+" "+rimy+" "+rc.m_width +" " +rc.m_height);
//var rc = this.GetCurrRC();
this.m_resizeHandle.style.left = (rc.m_width-RES_HANDLE_WIDTH)+"px";
this.m_resizeHandle.style.top = (rc.m_height-RES_HANDLE_HEIGHT)+"px";
var gtsLink = g_dc.GetObjInnerByName(this.m_expObj, "clipSourceLine")[0];
gtsLink.style.width = (rc.m_width-rimx-g_dc.m_origTextLength-30)+'px';
var ghds = g_dc.GetObjInnerByName(this.m_expObj, "BarClipDesc")[0];
ghds.style.width = (rc.m_width-75)+'px';
var frms = this.m_expObj.getElementsByTagName('iframe');
var frmWrp =frms[0].parentNode;
frmWrp.style.width = this.m_realW+'px';
frmWrp.style.height = this.m_realH+'px';
//alert("defHeight is: "+this.m_defH+" realheigh is: "+this.m_realH);
var showScrollX = ((this.m_realW-this.m_defW)<-3);
var showScrollY = ((this.m_realH-this.m_defH)<-3);
if (showScrollX!=this.m_scrollVisibleX)
{
frmWrp.style.overflowX=showScrollX?'scroll':'hidden';
this.m_scrollVisibleX = showScrollX;
}
if (showScrollY!=this.m_scrollVisibleY)
{
frmWrp.style.overflowY=showScrollY?'scroll':'hidden';
this.m_scrollVisibleY = showScrollY;
}
g_dc.setDirty(true);
}
catch(err)
{
alert(err);
}
}
ClipObject.prototype.toRC = function(l,t,w,h)
{
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error12');return;}
this.resizeTo(w,h, true);
this.moveTo(l,t);
}
ClipObject.prototype.initSize = function()
{
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error12');return;}
var temp = this.m_isIcn;
this.m_isIcn=true;
this.resizeTo(this.c_defIcnW, this.c_defIcnH, true);
this.m_isIcn=false;
this.resizeTo(this.m_realW, this.m_realH,false);
this.m_isIcn = temp;
}
ClipObject.prototype.toDefSize = function()
{
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error12');return;}
if (this.m_isIcn)
{
this.resizeTo(this.c_defIcnW, this.c_defIcnH, true);
}
else
{
this.resizeTo(this.m_defW, this.m_defH,false);
}
}
ClipObject.prototype.InitFrameSrc = function()
{
var frms = this.m_expObj.getElementsByTagName('iframe');
if (!frms[0].src || (frms[0].src.indexOf("clip.php")<0))
{
frms[0].src = homeurl+'/clip.php?id='+this.m_clpID;
frms[0].style.width=toInt(this.m_expObj.getAttribute("defW"))+'px';
frms[0].style.height=toInt(this.m_expObj.getAttribute("defH"))+'px';
}
}
ClipObject.prototype.setFrameReff = function()
{
if (!(this.m_expObj) || !(this.m_icnObj)) {alert('error14');return;}
if (!this.m_isIcn)
{
this.InitFrameSrc();
}
}
ClipObject.prototype.Delete = function()
{
try {
//g_dc.m_aElements[this.m_expObj.id]= null;
this.m_expObj.parentNode.removeChild(this.m_expObj);
this.m_icnObj.parentNode.removeChild(this.m_icnObj);
this.m_deleted = true;
g_dc.setDirty(true);
//delete this;
}
catch (err){
alert(err.description)
}
}
ClipObject.prototype.GetXmlChanges = function()
{
var str = "";
return str;
}
var bDirty = false;
if (this.m_origW!=this.m_realW)
{
str+="width='"+ this.m_realW +"' ";
bDirty=true;
this.m_origW = this.m_realW;
}
if (this.m_origH!=this.m_realH)
{
str+="height='"+ this.m_realH +"' ";
bDirty=true;
this.m_origH = this.m_realH;
}
var wa = g_dc.GetWorkAreaRC();
if (this.m_origX!=this.m_posX)
{
str+="xPos='"+ (this.m_posX-wa.m_left) +"' ";
bDirty=true;
this.m_origX = this.m_posX;
}
if (this.m_origY!=this.m_posY)
{
str+="yPos='"+ (this.m_posY-wa.m_top) +"' ";
bDirty=true;
this.m_origY = this.m_posY;
}
if (this.m_origIsIcn!=this.m_isIcn)
{
str+="isIcn='"+ (this.m_isIcn?'1':'0') +"' ";
bDirty=true;
this.m_origIsIcn = this.m_isIcn;
}
curTxt = this.Edit_getText();
if (this.m_origTxt!=curTxt)
{
str+="txt='"+ encodeURIComponent(HtmlEncode(curTxt)) +"' ";
bDirty=true;
this.m_origTxt = curTxt;
}
if (!bDirty)
return "";
str+="/>";
return str;
}
ClipObject.prototype.DragElem = function(diffX,diffY)
{
return this.MoveBy(diffX, diffY);
}
///////////////////////////////////////////////////////////////
/// Edit Interface
ClipObject.prototype.Edit_getEditPosition = function()
{
var rc = this.GetCurrRC(this.m_icnObj);
rc.m_top+=20;
rc.m_height-=20;
return rc;
}
ClipObject.prototype.Edit_getText = function()
{
var bb= g_dc.GetObjInnerByName(this.m_icnObj, "clipIconDivBottom")[0];
return HtmlDecode(bb.innerHTML);
}
ClipObject.prototype.Edit_setText = function(txt)
{
var bb= g_dc.GetObjInnerByName(this.m_icnObj, "clipIconDivBottom")[0];
bb.innerHTML = HtmlEncode(txt);
}
ClipObject.prototype.Edit_getFontFamily = function()
{
var bb= g_dc.GetObjInnerByName(this.m_icnObj, "clipIconDivBottom")[0];
return bb.style.fontFamily;
}
ClipObject.prototype.Edit_getFontSize = function()
{
var bb= g_dc.GetObjInnerByName(this.m_icnObj, "clipIconDivBottom")[0];
return bb.style.fontSize;
}
ClipObject.prototype.Edit_getFontWeight = function()
{
var bb= g_dc.GetObjInnerByName(this.m_icnObj, "clipIconDivBottom")[0];
return bb.style.fontWeight;
}
ClipObject.prototype.Edit_getMaxChars = function()
{
return "100";
}
ClipObject.prototype.Edit_getTextAlign = function()
{
return "center";
}
ClipObject.prototype.Edit_getPadding = function()
{
return "2px 2px 2px 2px";
}
// end Edit interface
//////////////////////////////////////////////////////////////////////