--- 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/11/07 17:25:32 1.11 @@ -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-browser 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; } @@ -76,10 +80,10 @@ function clickLink( object, position ) { this.p[position].remove(); } else { //--------'put down' the icon dragCache=""; - if ( addressCache.state == "link" ) { //------differently if a link - this.insertLink( position ); + if (addressCache.state=="link") { //------differently if a link + this.insertLink(position); } else { //--------------than a folder - this.insertFolder( position ); + this.insertFolder(position); } redrawTree(); } @@ -91,18 +95,15 @@ 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(this.lname,this.p.length,this.address); //ben debug see sheet + 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.p[ this.p.length ] = new addLink( addressCache.lname, addressCache.link, this.address, this.p.length ); + this.insertLink(0); } else { //---place folder into folder - this.insertFolder( 1 ); -// 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; + this.insertFolder(0); } redrawTree(); } @@ -110,45 +111,35 @@ 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); - } else { - this.p[i]=new addFolder(this.p[i-1].lname,this.p[i-1].p.length,this.address+".p["+i+"]"); - } - this.p[i].exists=this.p[i-1].exists; // preserve existance - i--; // Second, shift others up one - 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); + if (i>0) { // Does folder have any elements? + 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); } 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); + this.p[i]=new addFolder(this.p[i-1].lname,this.p[i-1].p.length,this.address+".p["+i+"]"); } -// this.p[i].address = this.p[i-1].address; -// this.p[i].exists = this.p[ i-1 ].exists; // preserve existance - i--; - } + this.p[i].exists=this.p[i-1].exists; // preserve existance + i--; // Second, shift others up one + 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); + } + this.p[i].exists=this.p[i-1].exists; // ben debug this just added + i--; + } + } } //-----------------------------------------------------------Opens the page @@ -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 at end of bookmarks +function addNewLink(title,address) { + nextPosition=bookmarkpal.bookmarks.p.length; + bookmarkpal.bookmarks.p[nextPosition]=new addLink(title,address,"bookmarks",nextPosition); + add_link.close(); + redrawTree(); +} + +//-----------------------Add the just-named link and then position within bookmarks +function addNewLink_b(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() { + 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 at the end of the bookmarks list +function addNewFolder(title) { + nextPosition=bookmarkpal.bookmarks.p.length; + nextAddress="bookmarks.p["+nextPosition+"]"; + bookmarkpal.bookmarks.p[nextPosition]=new addFolder(title,1,nextAddress); + add_link.close(); + redrawTree(); +} + +//---------------------------------Add the just-named folder and then position it +function addNewFolder_b(title) { + dragCache="/res/adm/pages/bookmarkmenu/folder_opened.gif"; + lastIcon="/res/adm/pages/bookmarkmenu/folder_opened.gif"; + lastDrug="-1"; + addressCache=new addFolder("doesnotmatter",1,"doesnotmatter"); + addressCache.p[0]=new addFolder(title,1,"doesnotmatter"); + addressCache.p[0].exists=true; //this and line above are debug + add_link.close(); +} + + + + + + + //----------------------------------------------------------------------------- // The following are construction functions. //----------------------------------------------------------------------------- //--------------------------------------------------generate the Tree HTML code function drawTree(depth, folder) { - for (var i=1; i"); -// parent.frames[4].document.write("

So far so good

"); //--debug drawTree(1,bookmarkpal.bookmarks.p); //----giving error: bookmarkpal not defined -// parent.frames[4].document.write("

Still doing good, after DrawTree

"); parent.frames[4].document.write(""); } @@ -305,30 +357,40 @@ function redrawTree() { // bookmarks //----------------------------------------------------------------------------- +//--------------recovers old bookmarks this is a debug function remove it later +function recover() { + parent.frames[7].document.saveBookmarks.hiddenbookmarks.value='recover'; + parent.frames[7].document.saveBookmarks.submit(); +} + + //----------------------------------------------------------starts save process function save() { - 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("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"; + saveVar=" "; + 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,14 +398,11 @@ 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"; } - - -