<script>
var blogTools = new BlogTools();
function BlogTools(){
this.dragObject = null;
this.mouseOffset = null;
this.init=function(id){
var item=document.getElementById(id);
item.onmousemove = blogTools.mouseMove;
item.onmouseup = blogTools.mouseUp;
item.style.cursor = "move";
item.style.zIndex = "1000";
item.onmousedown = function(ev){
this.style.zIndex="2000";
blogTools.dragObject = this;
blogTools.mouseOffset = blogTools.getMouseOffset(this, ev);
return false;
}
item.ondblclick = function(ev){
blogTools.setCookie(this.id+'top' , "" );
blogTools.setCookie(this.id+'left' , "" );
this.style.display='none';
}
var top = this.getCookie(item.id + "top");
var left = this.getCookie(item.id + "left");
if( (top!="") && (left!="")){
item.style.position = "absolute";
item.style.left = left + "px";
item.style.top = top + "px";
}
}
this.getPosition=function(e){
var left = 0;
var top = 0;
while (e.offsetParent){
left += e.offsetLeft;
top += e.offsetTop;
e = e.offsetParent;
}
left += e.offsetLeft;
top += e.offsetTop;
return {x:left, y:top};
}
this.getMouseOffset=function(target, ev){
ev = ev || window.event;
var docPos = blogTools.getPosition(target);
var mousePos = blogTools.mouseCoords(ev);
return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
}
this.mouseCoords=function(ev){
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
};
}
}
BlogTools.prototype.mouseMove=function(ev){
ev = ev || window.event;
var mousePos = blogTools.mouseCoords(ev);
if(blogTools.dragObject){
blogTools.dragObject.style.position = 'absolute';
blogTools.dragObject.style.top = mousePos.y - blogTools.mouseOffset.y + 'px';
blogTools.dragObject.style.left = mousePos.x - blogTools.mouseOffset.x + 'px';
return false;
}
}
BlogTools.prototype.mouseUp=function(ev){
if(blogTools.dragObject){
ev = ev || window.event;
var mousePos = blogTools.mouseCoords(ev);
blogTools.setCookie(blogTools.dragObject.id+'top' , mousePos.y - blogTools.mouseOffset.y, 365);
blogTools.setCookie(blogTools.dragObject.id+'left', mousePos.x - blogTools.mouseOffset.x, 365);
}
blogTools.dragObject.style.zIndex = "1000";
blogTools.dragObject = null;
}
BlogTools.prototype.getCookie=function(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
}
BlogTools.prototype.setCookie=function(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
</script>
No comments:
Post a Comment