--- loncom/html/res/adm/pages/bookmarkmenu/bookmarklib.js 2000/11/07 17:25:32 1.11
+++ loncom/html/res/adm/pages/bookmarkmenu/bookmarklib.js 2001/04/19 03:28:43 1.16
@@ -1,287 +1,486 @@
// bookmarklib.js
//
-// Functions combined with the HTML code in admbookmarks.pm
-// and code in bookmarkmenu_toolbar.html
+// This is a rewritten version of bookmarklib.js
//
+// Functions to be combined with the HTML code found in
+// admbookmarks.pm. The combination will provide a complete
+// functionality for the bookmarkmenu in accordance to defined
+// requirements.
+//
+// For further information and documentation regarding this program,
+// please refer to bookmarkmenu_OOD.txt, the design documentation for
+// bookmarkmenu.
+//
+//
+//
+// The perl module admbookmarks.pm interacts with this library by
+// generating a page that includes bookmarklib.js and a JavaScript
+// function initializeTree() that builds the the tree using successive
+// newLink() and newFolder() calls and one cache=new newCache() call.
+// The entire newLink()/newFolder() succession is the string that is
+// stored in the userspace on Lon-Capa as bookmarks.
+//
+//
+// Created on: 12-28-2000 by Benjamin Tyszka
+// Edited: 12-29-2000 by Benjamin Tyszka
+// mm-dd-yyyy by Xxxxxxxx Xxxxxx
+
+
+clienttitle="barf"; //debug
+clienthref="Egads!"; //debug
+
+//---------------------------------------------------------------------
+// Tree object
+//---------------------------------------------------------------------
+// Basis for user's bookmarks and folders - All properties and methods
+// pertaining to a user in general are found here. Refer to
+// bookmarkmenu_OOD.txt for further documenation.
+function newTree() {
+ this.redraw = redraw;
+ this.treeSave = treeSave;
+ this.bookmarks = new newFolder("bookmarks",true);
+ this.cache = new newCache();
+}
+
+//------------------------------------------refresh folder/link display
+function redraw() {
+ image_num = -1; // reset to before (-1 not 0) the first image
+ with(frames[4].document) {
+ open(); //--------for 'compliant' browsers
+ clear(); //----------for Mozilla (Netscape6)
+ write("\n" );
+ write("
\n" );
+ write("\n" );
+ }
+// bendebugger=window.open('','HTML_DUMP','scrollbars'); //debug
+// bendebugger.document.clear(); //debug
+// bendebugger.document.write('TEXT DOCUMENT: NONE OF THE TAGS SHOULD WORK\n'); //debug
+ var objPath="top.tree.bookmarks";
+ depth=0;
+ for(var i=0;i\n\n");
+ top.frames[4].document.close();
+// bendebugger.document.close(); //debug
+// return false; //debug
+}
+
+//-----------------generate 'save-string' and submit to admbookmarks.pm
+function treeSave() {
+ saveStrng="";
+ var objPath="window.tree.bookmarks";
+ var n=0;
+ for(var i=0;i\n"+saveStrng); //debug
+// bendebugger.document.close();
+// END OF DEBUG STUFF
+// NOW SUBMIT THE STRING TO PERL MODULE -CHECK ADDRESS CHECK ADDRESS
+ top.frames[7].document.saveBookmarks.hiddenbookmarks.value=saveStrng;
+ top.frames[7].document.saveBookmarks.submit;
+}
-//-------------------------------------------------------------------------------
-// Here are all of the bookmark methods:
-//-------------------------------------------------------------------------------
-
-//-------------------------------------------------------Adds a link to an object
-function addLink(name, link, address, position) {
- this.lname = name;
- this.link = link;
- this.address = address;
- this.position = position;
- this.state = "link";
- this.icon = "/res/adm/pages/bookmarkmenu/link.gif";
- this.pressed = "/res/adm/pages/bookmarkmenu/link_pressed.gif";
- this.hover = hover;
- this.remove = remove
- this.exists = true;
-}
-
-//-----------------------------------------------------Adds a folder to an object
-function addFolder(name, size, address) {
- 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.clickLink = clickLink;
- this.hover = hover;
- this.remove = remove;
- this.bump = bump;
- this.insertLink = insertLink;
- this.insertFolder = insertFolder;
- this.exists = true;
+//---------------------------------------------------------------------
+// Folder object
+//---------------------------------------------------------------------
+// Pertains to a userdefined folder. Refer to
+// bookmarkmenu_OOD.txt for further documentation.
+function newFolder(name,opened) {
+ // Folder Properties
+ this.state = "folder";
+ this.name = name;
+ this.opened = opened;
+ if (this.opened) {
+ this.icon = "/res/adm/pages/bookmarkmenu/folder_open.gif";
+ } else {
+ this.icon = "/res/adm/pages/bookmarkmenu/folder_close.gif";
+ }
+ this.exists = true;
+ this.highlited = false;
+ this.p = new Array(); // ---- ordered folder contents
+ // Folder Methods
+ this.addLink = addLink;
+ this.addFolder = addFolder;
+ this.insertLink = insertLink;
+ this.swapState = swapState;
+ this.moveTo = moveTo;
+ this.bump = bump;
+ this.folderEdit = folderEdit;
+ this.folderDraw = folderDraw;
+ this.folderWriteSave = folderWriteSave;
+ this.folderHover = folderHover;
+ this.folderClick = folderClick;
+ this.linkClick = linkClick;//--Folder method, because of 'bump'
+}
+
+//------------------------------Add link to last position within folder
+function addLink(name,url) {
+// if (this.length!=0) {
+ var location=this.p.length;
+// alert("THE ADD link:"+name+", location:"+location);
+// }
+ this.p[location]=new newLink(name,url);
+// var location=this.length+1;
+// tree.treeRedraw(); //commented so that we can make tree. one more below
+}
+
+//----------------------Add empty folder to last position within folder
+function addFolder(name,opened) {
+// if (this.length!=0) {
+ var location=this.p.length;
+// alert("THE ADD FOLDER:"+name+", location:"+location);
+// }
+ this.p[location]=new newFolder(name,opened);
+// var location=this.length+1;
+// tree.treeRedraw();
+}
+
+//----------------------------------------Places folder within a folder
+function insertLink(location,name,url) {
+ this.bump(location);
+ this.p[location]=new newLink(name,url);
+ tree.redraw();
}
-//-----------------------------------------Swaps folder state from open to closed
+//----------------------------------Swap folder between open and closed
function swapState() {
- if (this.state == "closed") {
- this.state = "opened";
- this.icon = "/res/adm/pages/bookmarkmenu/folder_opened.gif";
- this.pressed = "/res/adm/pages/bookmarkmenu/folder_opened_pressed.gif";
- } else {
- this.state = "closed";
- this.icon = "/res/adm/pages/bookmarkmenu/folder_closed.gif";
- this.pressed = "/res/adm/pages/bookmarkmenu/folder_closed_pressed.gif";
- }
- redrawTree();
- }
-
-//------------------------------------------swaps the dragged icon into the image
-function hover( object ) {
- if ( dragCache != "" ) {
- object.src = this.pressed;
- if (lastDrug != -1) {
- parent.frames[4].document.images[lastDrug].src = lastIcon;
- }
- lastIcon = this.icon;
- lastDrug = object.name;
- }
-}
-
-//------------------------------------------------------The click on link method
-function clickLink( object, position ) {
- if (dragCache=="") { //---------'pick up' the icon
- dragCache=object.src;
- lastIcon=this.p[position].icon;
- lastDrug=object.name;
- addressCache=new addLink(this.p[position].lname,this.p[position].link,this.p[position].address,position);
- this.p[position].remove();
- } else { //--------'put down' the icon
- dragCache="";
- if (addressCache.state=="link") { //------differently if a link
- this.insertLink(position);
- } else { //--------------than a folder
- this.insertFolder(position);
- }
- redrawTree();
- }
-}
-
-//-----------------------------------------------------The click on Folder method
-function clickFolder( object ) {
- if (dragCache=="") { //---------'pick up' the icon
- dragCache=object.src;
- lastIcon=this.icon;
- lastDrug=object.name;
- 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(0);
- } else { //---place folder into folder
- this.insertFolder(0);
- }
- redrawTree();
- }
-}
-
-//---------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);
-}
-
-
-//---------------------------Recursive folder Method to bump items up one to make room
-function bump(position) {
- // long term: make recursive
- var i=this.p.length; // First, create a new spot at the top.
- 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+"]");
- }
- 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--;
- }
- }
+ this.opened=(!this.opened);
+ if (this.opened) {
+ this.icon = "/res/adm/pages/bookmarkmenu/folder_open.gif";
+ } else {
+ this.icon = "/res/adm/pages/bookmarkmenu/folder_close.gif";
+ }
+ top.tree.redraw();
}
-//-----------------------------------------------------------Opens the page
-function clickOnBookmark(url) {
- open(url,opener.clientwindow.name); // <------THIS IS REAL VERSION
-// opener.open(url); // <------THIS IS FAKE VERSION
+//-------------------recursive, Moves folder and contents to new object
+// Don't forget to 'bump' before calling moveTo!
+function moveTo(object1) {
+ //alert('moveto11: from '+this.name+' to: '+object1.name+' o1 exists?'+object1.exists);
+ object1=new newFolder(this.name,this.opened);
+ //alert('moveto22: from '+this.name+' to: '+object1.name+' o1 exists?'+object1.exists);
+ //object1.exists=this.exists;
+ for (var i=0;i=location;i--) {
+ if (this.p[i].exists) { //saves time by not moving non-existing items
+ if (this.p[i].state=="folder") {
+ this.p[i+1]=this.p[i].moveTo(this.p[i+1]);
+ } else {
+ var name=this.p[i].name;
+ var url =this.p[i].url;
+ this.p[i+1]=new newLink(name,url);
+ this.p[i+1].exists=this.p[i].exists;
+ }
+// this.p[i].exists=false; // may not be neccessary if I'm careful
+ } else {
+ if (i!=this.p.length-1) {
+ this.p[i+1].exists=false;
+ }
+ }
+ }
+}
+function folderEdit() {
+}
-//-------------------------------------------------------------------------
-// Now we have standard (non-method) functions
-//-------------------------------------------------------------------------
-
-
-//---------------------------------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=0; i" );
+ write("" );
+ write("" );
+ write("");
+ write("" );
+ write("" );
+ write( this.name+" | " );
}
- object2.p[n].state=object1.state;
- object2.p[n].icon=object1.icon;
- object2.p[n].pressed=object1.pressed;
- object2.p[n].exists=object1.exists;
+// with (bendebugger.document) {
+// write("|-tr-||-td-||-a href=JavaScript:"+objPath+".swapState();-|\n" );
+// write("|-img src=/res/adm/pages/bookmarkmenu/folder_pointer_opened.gif border=0-||-/a-|\n" );
+// write("|-a href='JavaScript:"+objPath+".folderClick();'\n" );
+// write("onmouseover="+objPath+".folderHover("+image_num+");-|\n" );
+// write("|-img src=/res/adm/pages/bookmarkmenu/pix.gif height=25 width="+20*(depth)+" border=0-||-/a-|\n");
+// write("|-a href='javaScript:"+objPath+".folderClick();'" );
+// write("onmouseover='"+objPath+".folderHover("+image_num+");'-|\n" );
+// write("|-img src="+this.icon+" border=0-||-/a-|\n" );
+// write( this.name );
+// write("|-/td-||-/tr-|\n" );
+// } //whole thing is a debug
+ for(var i=0;i" );
+ write("" );
+ write("" );
+ write("");
+ write("" );
+ write("" );
+ write( this.name+" | " );
+ }
+// with (bendebugger.document) {
+// write("|-tr-||-td-||-a href=JavaScript:"+objPath+".swapState();-|\n" );
+// write("|-img src=/res/adm/pages/bookmarkmenu/folder_pointer_closed.gif border=0-||-/a-|\n" );
+// write("|-a href='JavaScript:"+objPath+".folderClick();'" );
+// write(" onmouseover="+objPath+".folderHover("+image_num+");-|\n" );
+// write("|-img src=/res/adm/pages/bookmarkmenu/pix.gif height=25 width="+20*(depth)+" border=0-||-/a-|\n");
+// write("|-a href=JavaScript:"+objPath+".folderClick();-|\n" );
+// write("|-img src="+this.icon+" border=0-||-/a-|\n" );
+// write( this.name );
+// write("|-/td-||-/tr-|\n" );
+// }
+ }
}
-
-//--------Method to place folder in middle of other links (this simplifies code)
-function insertFolder(position) {
- this.bump(position);
- shiftFolder(addressCache.p[0],this,position); //ben debug was addressCache.p[0]
+//-------------generate folder save string and recurse through contents
+function folderWriteSave(objPath,pos) {
+ saveStrng += objPath+".addFolder('"+this.name+"',"+this.opened+");\n";
+ var n=0; //-----alt. counter doesn't count non-exists links/marks
+// alert(saveStrng+" with a length: "+this.p.length); //DEBUG
+ for(var i=0;i';
- instr+='