Google Personalized homepage like, how to save the last layout three
var Drag = {
Dragged:false,
Ao:null,
Tdiv:null,
Dragstart:function () {
Drag.ao = event.srcelement;
if ((Drag.ao.tagName = "TD") | | (Drag.ao.tagName = = "TR")) {
Drag.ao = Drag.ao.offsetParent;
Drag.ao.style.zIndex = 100;
}else{
Return
}
Drag.dragged = true;
Drag.tdiv = document.createelement ("div");
Drag.tdiv.innerHTML = Drag.ao.outerHTML;
Drag.ao.style.border = "1px dashed blue";
Drag.tdiv.style.display = "block";
Drag.tdiv.style.position = "absolute";
Drag.tdiv.style.filter = "alpha (opacity = 70)";
Drag.tdiv.style.cursor = "Move";
Drag.tdiv.style.border = "1px solid #000000";
Drag.tdiv.style.width = Drag.ao.offsetWidth;
Drag.tdiv.style.height = Drag.ao.offsetHeight;
Drag.tdiv.style.top = Drag.getinfo (Drag.ao). Top;
Drag.tdiv.style.left = Drag.getinfo (Drag.ao). Left;
Document.body.appendChild (DRAG.TDIV);
DRAG.LASTX = Event.clientx;
Drag.lasty = Event.clienty;
Drag.lastleft = Drag.tdiv.style.left;
Drag.lasttop = Drag.tdiv.style.top;
}//End Function DragStart ()
,
Draging:function () {//IMPORTANT: Determine the location of the mouse
if (! drag.dragged| | Drag.ao = = null) return;
var TX = Event.clientx;
var TY = Event.clienty;
Drag.tdiv.style.left = parseint (drag.lastleft) +tx-drag.lastx;
Drag.tdiv.style.top = parseint (drag.lasttop) +ty-drag.lasty;
for (var i = 0;i<parenttable.cells.length;i++) {
var Parentcell = Drag.getinfo (Parenttable.cells[i]);
if (TX >= parentcell.left &&
TX <= parentcell.right &&
TY >= parentcell.top &&
TY <= Parentcell.bottom) {
var subtables = parenttable.cells[i].getelementsbytagname ("table");
if (Subtables.length = = 0) {
if (TX >= parentcell.left &&
TX <= parentcell.right &&
TY >= parentcell.top &&
TY <= Parentcell.bottom) {
Parenttable.cells[i].appendchild (Drag.ao);
}
Break
}
for (var j = 0; j<subtables.length; j + +) {
var subtable = Drag.getinfo (Subtables[j]);
if (TX >= subtable.left &&
TX <= subtable.right &&
TY >= subtable.top &&
TY <= Subtable.bottom) {
Parenttable.cells[i].insertbefore (Drag.ao,subtables[j]);
Break
}else{
Parenttable.cells[i].appendchild (Drag.ao);
}
}
}
}
}//End Function Draging
,
Dragend:function () {
if (! drag.dragged) return;
Drag.dragged = false;
DRAG.MM = Drag.repos (150,15);
Drag.ao.style.borderWidth = "0px";
Drag.ao.style.borderTop = "1px solid #3366cc";
Drag.tdiv.style.borderWidth = "0px";
Drag.ao.style.zIndex = 1;
alert (Drag.ao.outerHTML);
Drag.savelayout ();
Displaysavelayout ();
}//End Function Dragend ()
,
Savelayout:function ()
{//Place the current layout in the Cookie, press the "Save page layout" and save it to the background
for (var i = 0;i<parenttable.cells.length;i++) {
var subtables = parenttable.cells[i].getelementsbytagname ("table");
for (var j = 0;j<subtables.length;j++) {
if (subtables[j].classname!= "dragtable") break;
I_cell Index of ParentTable
J_node Index of Parenttable.rows[0][i].childnodes
Setcookie (subtables[j].id+ "pos", i+ "::" +j+ "::" +subtables[j].id);
}
}
}//End Function Savelayout ()
,
Inittablepos:function ()
{
First get the value from the Cookie, if you don't get the data in DB.
var _tablepos = new Array ();
var _dragtablehtmlarray = new Array (); Store the HTML code in drag table
var _cookies = new Array ();
var _c = 0;
Get the contents of the picture to Javascript and then rearrange it.
for (var i = 0;i<parenttable.cells.length;i++) {
var subtables = parenttable.cells[i].getelementsbytagname ("table");
for (var j = 0;j<subtables.length;j++) {
if (subtables[j].classname!= "dragtable") break;
_cookies[_c] = GetCookie (subtables[j].id+ "pos");
_dragtablehtmlarray[subtables[j].id] = subtables[j].outerhtml;
_c++;
}
if (_cookies.tostring (). IndexOf ("::")!=-1)
{
parenttable.cells[i].innerhtml = ""; Clear Drag table on screen
}
}
_cookies.sort (); Sort after adding InnerHTML in order
if (_cookies.tostring (). IndexOf ("::")!=-1)
{
for (var _k = 0; _k <_cookies.length; _k++)
{
if (_cookies[_k]!= null)
{
_tablepos = _cookies[_k].split ("::");
alert (_tablepos);
if (typeof (_tablepos) = = "Object")
{
Alert (_dragtablehtmlarray[_tablepos[2]]);
Parenttable.cells[_tablepos[0]].innerhtml + = _dragtablehtmlarray[_tablepos[2]];
Parenttable.cells[_tablepos[0]].innertext + = _dragtablehtmlarray[_tablepos[2]];
}
}
}
}
_cookies.sort ();
alert (_cookies);
_dragtablehtmlarray = null;//Release Memoery
}//End Function Initdragtablepos ()
,
Getinfo:function (o) {//Get coordinates
var to = new Object ();
To.left = To.right = To.top = To.bottom = 0;
var twidth = o.offsetwidth;
var theight = o.offsetheight;
while (o!= document.body) {
To.left + = O.offsetleft;
To.top + = O.offsettop;
o = o.offsetparent;
}
To.right = To.left+twidth;
To.bottom = To.top+theight;
return to;
}//End Function GetInfo ()
,
Repos:function (Aa,ab) {
var f = Drag.tdiv.filters.alpha.opacity;
var tl = parseint (Drag.getinfo (Drag.tdiv). left);
var tt = parseint (Drag.getinfo (drag.tdiv). top);
var kl = (Tl-drag.getinfo (Drag.ao). left)/ab;
var kt = (Tt-drag.getinfo (drag.ao). top)/ab;
var KF = F/ab;
Return SetInterval (
function () {
if (ab<1) {
Clearinterval (DRAG.MM);
Drag.tdiv.removeNode (TRUE);
Drag.ao = null;
Return
}
ab--;
TL-= KL;
TT-= kt;
F-= KF;
Drag.tdiv.style.left = parseint (TL) + "px";
Drag.tdiv.style.top = parseint (TT) + "px";
Drag.tdiv.filters.alpha.opacity = f;
}//End Animation effect
, Aa/ab)
}//End Function Repos ()
,
Inint:function () {//initialization
Drag.inittablepos ();
for (var i = 0;i<parenttable.cells.length;i++) {
var subtables = parenttable.cells[i].getelementsbytagname ("table");
for (var j = 0;j<subtables.length;j++) {
if (subtables[j].classname!= "dragtable") break;
Subtables[j].rows[0].classname = "DRAGTR";
Subtables[j].rows[0].attachevent ("onmousedown", Drag.dragstart);
}
}
Document.onmousemove = drag.draging;
Document.onmouseup = Drag.dragend;
}//End Function Inint ()
}//end of Object Drag
Drag.inint ();