Annotation of loncom/html/res/adm/pages/bookmarkmenu/bookmarklib.js, revision 1.8

1.1       tyszkabe    1: // bookmarklib.js
                      2: //
1.2       tyszkabe    3: // Functions combined with the HTML code in admbookmarks.pm
1.6       tyszkabe    4: // and code in bookmarkmenu_toolbar.html
1.1       tyszkabe    5: //
                      6: 
                      7: 
                      8: //-------------------------------------------------------------------------------
                      9: // Here are all of the bookmark methods:
                     10: //-------------------------------------------------------------------------------
                     11: 
                     12: //-------------------------------------------------------Adds a link to an object
                     13: function addLink(name, link, address, position) {
                     14:        this.lname = name;
                     15:        this.link = link;
                     16:        this.address = address;
                     17:        this.position = position;
                     18:        this.state = "link";
1.2       tyszkabe   19:        this.icon = "/res/adm/pages/bookmarkmenu/link.gif";
                     20:        this.pressed = "/res/adm/pages/bookmarkmenu/link_pressed.gif";
1.1       tyszkabe   21:        this.hover = hover;
                     22:        this.remove = remove
                     23:        this.exists = true;
                     24: }
                     25: 
                     26: //-----------------------------------------------------Adds a folder to an object
                     27: function addFolder(name, size, address) {
1.8     ! tyszkabe   28:        this.p = new Array();                            //BEN got rid of size in Array Agument
        !            29:                                                         // Currently SIZE doesn't matter
        !            30: 							// This probably works cross-platform
1.1       tyszkabe   31:        this.lname = name;
                     32:        this.address = address;
                     33:        this.state = "opened";
1.2       tyszkabe   34:        this.icon = "/res/adm/pages/bookmarkmenu/folder_opened.gif";
                     35:        this.pressed = "/res/adm/pages/bookmarkmenu/folder_opened_pressed.gif";
1.1       tyszkabe   36:        this.swapState = swapState;
1.8     ! tyszkabe   37:        this.clickFolder = clickFolder; 
1.1       tyszkabe   38:        this.clickLink = clickLink;
                     39:        this.hover = hover;
                     40:        this.remove = remove;
                     41:        this.bump = bump;
                     42:        this.insertLink = insertLink;
                     43:        this.insertFolder = insertFolder;
                     44:        this.exists = true;
                     45: }
                     46: 
                     47: //-----------------------------------------Swaps folder state from open to closed
                     48: function swapState() {
                     49:        if (this.state == "closed") {
                     50:            this.state = "opened";
1.3       tyszkabe   51:            this.icon = "/res/adm/pages/bookmarkmenu/folder_opened.gif";
                     52:            this.pressed = "/res/adm/pages/bookmarkmenu/folder_opened_pressed.gif";
1.1       tyszkabe   53:        } else {
                     54:            this.state = "closed";
1.3       tyszkabe   55:            this.icon = "/res/adm/pages/bookmarkmenu/folder_closed.gif";
                     56:            this.pressed = "/res/adm/pages/bookmarkmenu/folder_closed_pressed.gif";
1.1       tyszkabe   57:        }
1.4       tyszkabe   58:        redrawTree();
1.1       tyszkabe   59:     }
                     60: 
                     61: //------------------------------------------swaps the dragged icon into the image
                     62: function hover( object ) {
                     63:     if ( dragCache != "" ) {
                     64:         object.src = this.pressed;
1.8     ! tyszkabe   65:         if (lastDrug != -1) {
        !            66: 	   parent.frames[4].document.images[lastDrug].src = lastIcon;
        !            67: 	}
1.1       tyszkabe   68:         lastIcon = this.icon;
                     69:         lastDrug = object.name;
                     70:     }
                     71: }
                     72: 
                     73: //------------------------------------------------------The click on link  method
                     74: function clickLink( object, position ) {
                     75:     if (dragCache=="") {                            //---------'pick up' the icon
                     76:         dragCache=object.src;
                     77:         lastIcon=this.p[position].icon;
                     78:         lastDrug=object.name;
                     79:         addressCache=new addLink(this.p[position].lname,this.p[position].link,this.p[position].address,position);
                     80:         this.p[position].remove();
                     81:     } else {                                        //--------'put down' the icon
                     82:         dragCache="";
                     83:         if ( addressCache.state == "link" ) {       //------differently if a link
                     84:           this.insertLink( position );
                     85:         } else {                                    //--------------than a folder
                     86:           this.insertFolder( position );
                     87:         }
                     88:         redrawTree();
                     89:     }
                     90: }
                     91: 
                     92: //-----------------------------------------------------The click on Folder method
                     93: function clickFolder( object ) {
                     94:     if (dragCache=="") {                            //---------'pick up' the icon
                     95:         dragCache=object.src;
                     96:         lastIcon=this.icon;
                     97:         lastDrug=object.name;
1.8     ! tyszkabe   98:         addressCache=new addFolder("lame_folder",1,"doesnotmatter"); //used to be (this.lname,this.p.length+1,this.address)
        !            99:       shiftFolder(this,addressCache,0);               //this is  a whole new line
1.1       tyszkabe  100:         this.remove();
                    101:     } else {                                        //--------'put down' the icon
                    102:         dragCache = "";
                    103:            if ( addressCache.state == "link" ) {    //-----place link into folder
1.8     ! tyszkabe  104:               this.insertLink(0);
1.1       tyszkabe  105: //              this.p[ this.p.length ] = new addLink( addressCache.lname, addressCache.link, this.address, this.p.length );
                    106:            } else {                                 //---place folder into folder
1.8     ! tyszkabe  107:                 this.insertFolder(0);
1.1       tyszkabe  108: //              this.p[ this.p.length ] = new addFolder( addressCache.lname, addressCache.p.length, this.address+".p["+this.p.length+"]" );
                    109: //              this.p[ this.p.length ].p = addressCache.p;
                    110:            }
                    111:     redrawTree();
                    112:     }
                    113: }
                    114: 
                    115: //---------Folder method to place link in middle of other links (should simplify code)
                    116: function insertLink( position ) {
1.8     ! tyszkabe  117:         this.bump(position);
        !           118:         this.p[position]=new addLink(addressCache.lname,addressCache.link,this.address, position);
1.1       tyszkabe  119: }
                    120: 
                    121: 
                    122: //---------------------------Recursive folder Method to bump items up one to make room 
1.8     ! tyszkabe  123: function bump(position) {
        !           124: 					       //     long term: make recursive
1.1       tyszkabe  125:         var i=this.p.length;                   // First, create a new spot at the top.
                    126:         if (this.p[i-1].state=="link") {
                    127:            this.p[i]=new addLink(this.p[i-1].lname,this.p[i-1].link,this.address,i);
                    128:         } else {
                    129:           this.p[i]=new addFolder(this.p[i-1].lname,this.p[i-1].p.length,this.address+".p["+i+"]"); 
                    130:         }
                    131:         this.p[i].exists=this.p[i-1].exists;                    // preserve existance
                    132:         i--;                                           // Second, shift others up one
1.8     ! tyszkabe  133:         while (i >= position+1 ) {
1.1       tyszkabe  134:            if ( this.p[i-1].state == "link" ) {
                    135:               this.p[ i ] = new addLink( this.p[ i-1 ].lname, this.p[i-1].link, this.p[i-1].address, i);
                    136:            } else {
                    137:               this.p[ i ] = new addFolder( this.p[ i-1 ].lname, this.p[i-1].p.length, this.address+".p["+ i +"]" );
                    138:                                                 // move all of the inner folder stuff
1.8     ! tyszkabe  139:               shiftFolder(this.p[i-1],this,i);
1.1       tyszkabe  140:            }
                    141:            i--;
                    142:         }
                    143: }
                    144: 
                    145: //-----------------------------------------------------------Opens the page
                    146: function clickOnBookmark(url) {
1.3       tyszkabe  147:        open(url,opener.clientwindow.name); // <------THIS IS REAL VERSION
                    148: //       opener.open(url);                    // <------THIS IS FAKE VERSION
1.1       tyszkabe  149: }
                    150: 
                    151: 
                    152: 
                    153: 
                    154: //-------------------------------------------------------------------------
                    155: // Now we have standard (non-method) functions
                    156: //-------------------------------------------------------------------------
                    157: 
                    158: 
                    159: //---------------------------------shifts contents of folder up one position
                    160: function shiftFolder(object1, object2, n) {
                    161:       object2.p[n] = new addFolder(object1.lname,object1.length,object2.address+".p["+n+"]");
1.8     ! tyszkabe  162:       for (var i=0; i<object1.p.length; i++) {
1.1       tyszkabe  163:         if (object1.p[i].state=="link") {
                    164:           object2.p[n].p[i]=new addLink(object1.p[i].lname,object1.p[i].link,object2.p[n].address,i);
                    165:         } else {
1.8     ! tyszkabe  166:           object2.p[n].p[i]=new addFolder(object1.p[i].lname,object1.p.length,object2.address+".p["+n+"].p["+i+"]"); //BEN rid of [i]
1.1       tyszkabe  167:           shiftFolder(object1.p[i],object2.p[n],i);
                    168:         }
                    169:         object2.p[n].p[i].state=object1.p[i].state;
                    170:         object2.p[n].p[i].icon=object1.p[i].icon;
                    171:         object2.p[n].p[i].pressed=object1.p[i].pressed;
                    172:         object2.p[n].p[i].exists=object1.p[i].exists;      
                    173:       }
                    174:       object2.p[n].state=object1.state;
                    175:       object2.p[n].icon=object1.icon;
                    176:       object2.p[n].pressed=object1.pressed;
                    177:       object2.p[n].exists=object1.exists;      
                    178: }
                    179: 
                    180: 
                    181: //--------Method to place folder in middle of other links (this simplifies code)
                    182: function insertFolder(position) {
                    183:         this.bump(position);
1.8     ! tyszkabe  184:         shiftFolder(addressCache.p[0],this,position);
1.1       tyszkabe  185: }
                    186: 
                    187: 
                    188: //---------------------------delete link&folder from within other links&folders
                    189: function remove() {
                    190:         this.exists = false;
                    191: }
                    192: 
                    193: //---------------------Function that deletes link from dragging it to the trash
                    194: function clickTrash() {
                    195:         dragCache = "";
                    196:         redrawTree();
                    197: }
                    198: 
                    199: //-----------------------------------------------------------------------------
                    200: // These functions should be incorporated as methods
1.8     ! tyszkabe  201: // and the trash should be a folder. I'll work on that later.
1.1       tyszkabe  202: //-----------------------------------------------------------------------------
                    203: function hoverTrash() {
                    204: //        if ( dragCache != "" ) {
                    205: //           parent.frames[6].document.images[0].src = lastIcon;
                    206: //           lastIcon = "folder_trash.gif";
                    207: //        }       
                    208: }
                    209: //----------------------------------------------------------------------------
                    210: 
1.4       tyszkabe  211: //----------------------------------------------------------------Add new link
                    212: function newLink() {
1.6       tyszkabe  213:    var clienthref=opener.clientwindow.location.href;
                    214:    var clienttitle=opener.opener.document.title;
1.8     ! tyszkabe  215:    add_link=window.open('','Link','width=360,height=165,scrollbars=0');
        !           216:    savedoc=add_link.document;
        !           217:    var instr='<html><head><title>New Link</title></head><body bgcolor="#bbbbbb">';
        !           218:    instr+='<center><form method="post" name="newLink">';
        !           219:    instr+='<table width="340" height="150" bgcolor="#ffffff" align="center">';
        !           220:    instr+='<tr><td>';
        !           221:    instr+='Name:<br><input type="text" name="title" size="45" value="'+clienttitle+'"><br>';
        !           222:    instr+='Address:<br><input type="text" name="address" size="45" value="'+clienthref+'"><br>';
        !           223:    instr+='<center>';
        !           224:    instr+='<input type="button" value="Save and Position" onclick="javascript:opener.addNewLink(newLink.title.value,newLink.address.value);">';
        !           225:    instr+='<input type="button" value="Close (no save)" onclick="javascript:window.close();">';
        !           226:    instr+='</center></td></tr></table></form></center>';
        !           227:    instr+='</body></html>';
        !           228:    savedoc.write(instr);
        !           229:    savedoc.close();
        !           230: }
        !           231: 
        !           232: //-------------------------------------------------------Add the just-named link
        !           233: function addNewLink(title,address) {
        !           234:    dragCache="/res/adm/pages/bookmarkmenu/folder_opened.gif";
        !           235:    lastIcon="/res/adm/pages/bookmarkmenu/folder_opened.gif";
        !           236:    lastDrug="-1";
        !           237:    addressCache=new addLink(title,address,"doesnotmatter",1);
        !           238:    add_link.close();   
        !           239: }
        !           240: 
        !           241: //----------------------------------------------------------------Add new Folder
        !           242: function newFolder() {
        !           243:    var clienthref=opener.clientwindow.location.href;
        !           244:    var clienttitle=opener.opener.document.title;
        !           245:    add_link=window.open('','Link','width=360,height=165,scrollbars=0');
1.6       tyszkabe  246:    savedoc=add_link.document;
1.8     ! tyszkabe  247:    var instr='<html><head><title>New Folder</title></head><body bgcolor="#bbbbbb">';
        !           248:    instr+='<center><form method="post" name="newFolder">';
        !           249:    instr+='<table width="340" height="150" bgcolor="#ffffff" align="center">';
        !           250:    instr+='<tr><td>';
        !           251:    instr+='Folder Name:<br><input type="text" name="title" size="45" value=""><br>';
        !           252:    instr+='<center>';
        !           253:    instr+='<input type="button" value="Save and Position" onclick="javascript:opener.addNewFolder(newFolder.title.value);">';
1.7       tyszkabe  254:    instr+='<input type="button" value="Close (no save)" onclick="javascript:window.close();">';
1.8     ! tyszkabe  255:    instr+='</center></td></tr></table></form></center>';
1.6       tyszkabe  256:    instr+='</body></html>';
                    257:    savedoc.write(instr);
                    258:    savedoc.close();
1.4       tyszkabe  259: }
1.1       tyszkabe  260: 
1.8     ! tyszkabe  261: //----------------------------------------------------Add the just-named folder
        !           262: function addNewFolder(title) {
        !           263:    dragCache="/res/adm/pages/bookmarkmenu/folder_opened.gif";
        !           264:    lastIcon="/res/adm/pages/bookmarkmenu/folder_opened.gif";
        !           265:    lastDrug="-1";
        !           266:    addressCache=new addFolder(title,1,"doesnotmatter");
        !           267:    add_link.close();
        !           268: }
        !           269: 
        !           270: 
        !           271: 
        !           272: 
        !           273: 
        !           274: 
        !           275: 
1.1       tyszkabe  276: //-----------------------------------------------------------------------------
                    277: // The following are construction functions.
                    278: //-----------------------------------------------------------------------------
                    279: 
                    280: //--------------------------------------------------generate the Tree HTML code
                    281: function drawTree(depth, folder) {
1.8     ! tyszkabe  282:    for (var i=0; i<folder.length; i++) {
1.1       tyszkabe  283:       if (folder[i].exists) {
                    284:          if (folder[i].state=="link") {
                    285:             drawLink(depth,folder[i]);
                    286:          } else {
                    287:             drawFolder(depth,folder[i]);
                    288:             if (folder[i].state=="opened" && folder[i].p.length>=0) {
                    289:                drawTree(depth+1,folder[i].p);
                    290:             }
                    291:          }
                    292:       }
                    293:    }
                    294: }
                    295: 
                    296: //----------------------------------------Writes HTML code for individual folder
                    297: function drawFolder(depth, folder) {
                    298:        parent.frames[4].document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign=left nowrap>");
1.2       tyszkabe  299:        parent.frames[4].document.write("<a href=\"javascript:top.bookmarkpal."+folder.address+".swapState();\" ><IMG src='/res/adm/pages/bookmarkmenu/folder_pointer_"+folder.state+".gif' width=15 height=25 border=noborder ></a>");
1.1       tyszkabe  300:        image_num++;
                    301:        if ( depth != 1 ) {
                    302:            image_num++;
1.2       tyszkabe  303:            parent.frames[4].document.write("<A href=\"javascript:top.bookmarkpal."+folder.address+".clickFolder(document.images["+image_num+"]);\" onmouseover=\"top.bookmarkpal."+folder.address+".hover(document.images["+image_num+"])\" ><IMG src='/res/adm/pages/bookmarkmenu/folder_spacer.gif' width="+ 20*( depth - 1 ) +" height=25 border=noborder></A>");
1.1       tyszkabe  304:        }
                    305:        parent.frames[4].document.write("<A href=\"javascript:top.bookmarkpal."+folder.address+".clickFolder(document.images["+image_num+"]);\" onmouseover=\"top.bookmarkpal."+folder.address+".hover(document.images["+image_num+"])\" ><IMG src='"+folder.icon+"' width=25 height=25 border=noborder name="+image_num+"></A>");
                    306:        image_num++;
                    307:        parent.frames[4].document.write("<TD valign=middle align=left nowrap><FONT face='Arial, Helvetica'> "+folder.lname+"</FONT></TABLE>");
                    308: }
                    309: 
                    310: //--------------------------------------Writes HTML code for individual link
                    311: function drawLink(depth, folder) {
                    312:        parent.frames[4].document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign = middle nowrap>");
                    313:        image_num++;
1.2       tyszkabe  314:        parent.frames[4].document.write("<A href=\"javascript:top.bookmarkpal."+folder.address+".clickLink(document.images["+image_num+"], "+folder.position+");\" onmouseover=\"top.bookmarkpal."+folder.address+".p["+ folder.position +"].hover(document.images["+image_num+"])\" ><IMG src='/res/adm/pages/bookmarkmenu/folder_spacer.gif' width="+ 20 * depth +" height=25 border=noborder></A>");
1.1       tyszkabe  315: 
                    316:        parent.frames[4].document.write("<A href=\"javascript:top.bookmarkpal."+folder.address+".clickLink(document.images["+image_num+"], "+folder.position+");\" onmouseover=\"top.bookmarkpal."+folder.address+".p["+ folder.position +"].hover(document.images["+image_num+"])\" ><IMG src='"+folder.icon+"' width=25 height=25 border=noborder name="+image_num+" ></A>");
                    317:        image_num++;
                    318:        parent.frames[4].document.write("<TD valign=middle align=left nowrap><FONT size=-1 face='Arial, Helvetica'><A href=\"javascript:top.clickOnBookmark\( '"+folder.link+"\' );\">"+folder.lname+"</a></FONT></TABLE>");
                    319: }
                    320: 
                    321: //--------------------Calls Build and draws functions. This function also takes
                    322: //                                                         care of housekeeping
                    323: function initializeTree() {
1.5       tyszkabe  324: //       bookmarkpal = new buildUserTree();
1.1       tyszkabe  325:        redrawTree();
                    326: }
                    327: 
                    328: //--------------------------------Redraws screen without initiallizing anything
                    329: function redrawTree() {
1.5       tyszkabe  330: //       parent.frames[4].document.clear();  //--Remove this line later. clear has depreciated from Javascript
                    331:        parent.frames[4].document.open();
                    332:        image_num=0;
1.1       tyszkabe  333:        parent.frames[4].document.write("<BODY>");
1.5       tyszkabe  334: //       parent.frames[4].document.write("<p>So far so good</p>");  //--debug
                    335:        drawTree(1,bookmarkpal.bookmarks.p);     //----giving error: bookmarkpal not defined
                    336: //       parent.frames[4].document.write("<p>Still doing good, after DrawTree</p>");
1.1       tyszkabe  337:        parent.frames[4].document.write("</BODY>");
                    338: }
                    339: 
1.2       tyszkabe  340: //-----------------------------------------------------------------------------
                    341: // Saves bookmarks by building and then 'put'ing the string that generates the
                    342: // bookmarks
                    343: //-----------------------------------------------------------------------------
                    344: 
1.8     ! tyszkabe  345: //--------------recovers old bookmarks this is a debug function remove it later
        !           346: function recover() {
        !           347:    parent.frames[7].document.saveBookmarks.hiddenbookmarks.value='recover';
        !           348:    parent.frames[7].document.saveBookmarks.submit();
        !           349: }
        !           350: 
        !           351: 
1.2       tyszkabe  352: //----------------------------------------------------------starts save process
                    353: function save() {
1.8     ! tyszkabe  354: //   parent.frames[4].document.clear();                                    // debug
        !           355: //   parent.frames[4].document.write("<P>Debug: Beginning save process...</P>");   // debug
        !           356:    saveVar="this.bookmarks=new addFolder(\"Stuff\","+bookmarkpal.bookmarks.p.length+",\"bookmarks\");\n";
        !           357:    saveTree("bookmarks",bookmarkpal.bookmarks.p);
        !           358: //   parent.frames[4].document.write("<p>writing variable...</p>"+saveVar+"<p>...done</p>");      // debug
        !           359:    parent.frames[7].document.saveBookmarks.hiddenbookmarks.value=saveVar;
1.3       tyszkabe  360:    return true;
1.2       tyszkabe  361: }
                    362: 
                    363: 
1.3       tyszkabe  364: //---------------------------------------------------------generate save string
1.2       tyszkabe  365: function saveTree(depth_string,folder) {
1.8     ! tyszkabe  366:    var n=0;                                    // n renumbers links because 
        !           367:    for (var i=0; i<folder.length; i++) {       // of deleted links
1.2       tyszkabe  368:       if (folder[i].exists) {
                    369:          if (folder[i].state=="link") {
1.8     ! tyszkabe  370:             saveLink(depth_string,folder[i], n);
1.2       tyszkabe  371:          } else {
1.8     ! tyszkabe  372:             saveFolder(depth_string+".p["+n+"]",folder[i]);
        !           373:             if (folder[i].p.length>=0) {
        !           374:                saveTree(depth_string+".p["+n+"]",folder[i].p);
1.2       tyszkabe  375:             }
                    376:          }
1.8     ! tyszkabe  377: 	 n++;
1.2       tyszkabe  378:       }
                    379:    }
1.1       tyszkabe  380: }
1.2       tyszkabe  381: 
                    382: 
                    383: //-------------------------Writes javascript code for generating individual folder
                    384: function saveFolder(depth_string, folder) {
1.8     ! tyszkabe  385:        saveVar+="this."+depth_string+"=new addFolder(\""+folder.lname+"\","+folder.p.length+",\""+depth_string+"\");\n";
1.2       tyszkabe  386: }
                    387: 
                    388: 
                    389: //-------------------------Writes javascript code for generating individual link
1.8     ! tyszkabe  390: function saveLink(depth_string,link,newpos) {
        !           391:        saveVar+="this."+depth_string+".p["+newpos+"]=new addLink(\""+link.lname+"\",\""+link.link+"\",\""+depth_string+"\","+newpos+");\n";
1.5       tyszkabe  392: }
                    393: 
                    394: 
                    395: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>