--- loncom/html/res/adm/pages/bookmarkmenu/bookmarklib.js 2000/10/10 20:30:57 1.7 +++ loncom/html/res/adm/pages/bookmarkmenu/bookmarklib.js 2000/10/13 11:57:29 1.8 @@ -25,14 +25,16 @@ function addLink(name, link, address, po //-----------------------------------------------------Adds a folder to an object function addFolder(name, size, address) { - this.p = new Array(size); + this.p = new Array(); //BEN got rid of size in Array Agument + // Currently SIZE doesn't matter + // This probably works cross-platform this.lname = name; this.address = address; this.state = "opened"; this.icon = "/res/adm/pages/bookmarkmenu/folder_opened.gif"; this.pressed = "/res/adm/pages/bookmarkmenu/folder_opened_pressed.gif"; this.swapState = swapState; - this.clickFolder = clickFolder; + this.clickFolder = clickFolder; this.clickLink = clickLink; this.hover = hover; this.remove = remove; @@ -60,7 +62,9 @@ function swapState() { function hover( object ) { if ( dragCache != "" ) { object.src = this.pressed; - parent.frames[4].document.images[lastDrug].src = lastIcon; + if (lastDrug != -1) { + parent.frames[4].document.images[lastDrug].src = lastIcon; + } lastIcon = this.icon; lastDrug = object.name; } @@ -91,16 +95,16 @@ function clickFolder( object ) { dragCache=object.src; lastIcon=this.icon; lastDrug=object.name; - addressCache=new addFolder("lame_folder",2,"doesnotmatter"); //used to be (this.lname,this.p.length+1,this.address) - shiftFolder(this,addressCache,1); //this is a whole new line + addressCache=new addFolder("lame_folder",1,"doesnotmatter"); //used to be (this.lname,this.p.length+1,this.address) + shiftFolder(this,addressCache,0); //this is a whole new line this.remove(); } else { //--------'put down' the icon dragCache = ""; if ( addressCache.state == "link" ) { //-----place link into folder - this.insertLink( 1 ); + this.insertLink(0); // this.p[ this.p.length ] = new addLink( addressCache.lname, addressCache.link, this.address, this.p.length ); } else { //---place folder into folder - this.insertFolder( 1 ); + this.insertFolder(0); // this.p[ this.p.length ] = new addFolder( addressCache.lname, addressCache.p.length, this.address+".p["+this.p.length+"]" ); // this.p[ this.p.length ].p = addressCache.p; } @@ -110,25 +114,14 @@ function clickFolder( object ) { //---------Folder method to place link in middle of other links (should simplify code) function insertLink( position ) { - this.bump( position ); - this.p[ position ] = new addLink( addressCache.lname, addressCache.link, this.address, position ); + this.bump(position); + this.p[position]=new addLink(addressCache.lname,addressCache.link,this.address, position); } //---------------------------Recursive folder Method to bump items up one to make room -// for new item. Currently, bump doesn't always work. -function bump( position ) { -// ORIGINAL RECURSIVE VERSION has short-comings but may work better because of 'not exists' -// -// if ( this.length >= position ) { -// this.bump( position + 1 ); -// } -// position; -// this.p[ position + 1 ] = this.p[position ]; -// -// NON RECURSIVE of the same thing (I'll probably stick with this). -// I can combine the creation and shifting if everything works out nicely -// Worry about what happens to the first link. +function bump(position) { + // long term: make recursive var i=this.p.length; // First, create a new spot at the top. if (this.p[i-1].state=="link") { this.p[i]=new addLink(this.p[i-1].lname,this.p[i-1].link,this.address,i); @@ -137,16 +130,14 @@ function bump( position ) { } this.p[i].exists=this.p[i-1].exists; // preserve existance i--; // Second, shift others up one - while ( i >= position + 1 ) { + while (i >= position+1 ) { if ( this.p[i-1].state == "link" ) { this.p[ i ] = new addLink( this.p[ i-1 ].lname, this.p[i-1].link, this.p[i-1].address, i); } else { this.p[ i ] = new addFolder( this.p[ i-1 ].lname, this.p[i-1].p.length, this.address+".p["+ i +"]" ); // move all of the inner folder stuff - shiftFolder( this.p[i-1], this, i); + shiftFolder(this.p[i-1],this,i); } -// this.p[i].address = this.p[i-1].address; -// this.p[i].exists = this.p[ i-1 ].exists; // preserve existance i--; } } @@ -168,11 +159,11 @@ function clickOnBookmark(url) { //---------------------------------shifts contents of folder up one position function shiftFolder(object1, object2, n) { object2.p[n] = new addFolder(object1.lname,object1.length,object2.address+".p["+n+"]"); - for (var i=1; i
'; + instr+='Address:

'; + instr+='
'; + instr+=''; + instr+=''; + instr+='
'; + instr+=''; + savedoc.write(instr); + savedoc.close(); +} + +//-------------------------------------------------------Add the just-named link +function addNewLink(title,address) { + dragCache="/res/adm/pages/bookmarkmenu/folder_opened.gif"; + lastIcon="/res/adm/pages/bookmarkmenu/folder_opened.gif"; + lastDrug="-1"; + addressCache=new addLink(title,address,"doesnotmatter",1); + add_link.close(); +} + +//----------------------------------------------------------------Add new Folder +function newFolder() { + var clienthref=opener.clientwindow.location.href; + var clienttitle=opener.opener.document.title; + add_link=window.open('','Link','width=360,height=165,scrollbars=0'); savedoc=add_link.document; - var instr='New Link'; - instr+='
'; - instr+='Name:
'; - instr+='URL:
'; - instr+=''; - instr+=''; + var instr='New Folder'; + instr+='
'; + instr+=''; + instr+='
'; + instr+='Folder Name:

'; + instr+='
'; + instr+=''; instr+=''; - instr+=''; + instr+='
'; instr+=''; savedoc.write(instr); savedoc.close(); } +//----------------------------------------------------Add the just-named folder +function addNewFolder(title) { + dragCache="/res/adm/pages/bookmarkmenu/folder_opened.gif"; + lastIcon="/res/adm/pages/bookmarkmenu/folder_opened.gif"; + lastDrug="-1"; + addressCache=new addFolder(title,1,"doesnotmatter"); + add_link.close(); +} + + + + + + + //----------------------------------------------------------------------------- // The following are construction functions. //----------------------------------------------------------------------------- //--------------------------------------------------generate the Tree HTML code function drawTree(depth, folder) { - for (var i=1; iDebug: Beginning save process...

"); // debug - saveVar="this.bookmarks=new addFolder('Stuff',"+bookmarkpal.bookmarks.p.length+",'bookmarks')
\n"; - saveTree("this.bookmarks",bookmarkpal.bookmarks.p); - parent.frames[4].document.write("

writing variable...

"+saveVar+"

...done

"); // debug - parent.frames[7].document.saveBookmarks.hidden_bookmarks=saveVar; +// parent.frames[4].document.clear(); // debug +// parent.frames[4].document.write("

Debug: Beginning save process...

"); // debug + saveVar="this.bookmarks=new addFolder(\"Stuff\","+bookmarkpal.bookmarks.p.length+",\"bookmarks\");\n"; + saveTree("bookmarks",bookmarkpal.bookmarks.p); +// parent.frames[4].document.write("

writing variable...

"+saveVar+"

...done

"); // debug + parent.frames[7].document.saveBookmarks.hiddenbookmarks.value=saveVar; return true; } //---------------------------------------------------------generate save string function saveTree(depth_string,folder) { - for (var i=1; i=0) { - saveTree(depth_string+".p["+i+"]",folder[i].p); + saveFolder(depth_string+".p["+n+"]",folder[i]); + if (folder[i].p.length>=0) { + saveTree(depth_string+".p["+n+"]",folder[i].p); } } + n++; } } } @@ -336,13 +382,13 @@ function saveTree(depth_string,folder) { //-------------------------Writes javascript code for generating individual folder function saveFolder(depth_string, folder) { - saveVar+=depth_string+"=new addfolder('"+folder.lname+"',"+folder.p.length+",'"+folder.address+"');
\n"; + saveVar+="this."+depth_string+"=new addFolder(\""+folder.lname+"\","+folder.p.length+",\""+depth_string+"\");\n"; } //-------------------------Writes javascript code for generating individual link -function saveLink(depth_string,link) { - saveVar+=depth_string+"=new addlink('"+link.lname+"','"+link.link+"','"+link.address+"',"+link.position+");
\n"; +function saveLink(depth_string,link,newpos) { + saveVar+="this."+depth_string+".p["+newpos+"]=new addLink(\""+link.lname+"\",\""+link.link+"\",\""+depth_string+"\","+newpos+");\n"; }