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

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.9     ! 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-browser
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="";
1.9     ! tyszkabe   83:         if (addressCache.state=="link") {       //------differently if a link
        !            84:           this.insertLink(position);
1.1       tyszkabe   85:         } else {                                    //--------------than a folder
1.9     ! tyszkabe   86:           this.insertFolder(position);
1.1       tyszkabe   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.9     ! tyszkabe   98:         addressCache=new addFolder(this.lname,this.p.length,this.address); //ben debug see sheet
        !            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:            } else {                                 //---place folder into folder
1.8       tyszkabe  106:                 this.insertFolder(0);
1.1       tyszkabe  107:            }
                    108:     redrawTree();
                    109:     }
                    110: }
                    111: 
                    112: //---------Folder method to place link in middle of other links (should simplify code)
                    113: function insertLink( position ) {
1.8       tyszkabe  114:         this.bump(position);
                    115:         this.p[position]=new addLink(addressCache.lname,addressCache.link,this.address, position);
1.1       tyszkabe  116: }
                    117: 
                    118: 
                    119: //---------------------------Recursive folder Method to bump items up one to make room 
1.8       tyszkabe  120: function bump(position) {
                    121: 					       //     long term: make recursive
1.1       tyszkabe  122:         var i=this.p.length;                   // First, create a new spot at the top.
1.9     ! tyszkabe  123: 	if (i>0) {                        // Does folder have any elements?
        !           124:            if (this.p[i-1].state=="link") {
        !           125:               this.p[i]=new addLink(this.p[i-1].lname,this.p[i-1].link,this.address,i);
1.1       tyszkabe  126:            } else {
1.9     ! tyszkabe  127:               this.p[i]=new addFolder(this.p[i-1].lname,this.p[i-1].p.length,this.address+".p["+i+"]"); 
1.1       tyszkabe  128:            }
1.9     ! tyszkabe  129:            this.p[i].exists=this.p[i-1].exists;                    // preserve existance
        !           130:            i--;                                           // Second, shift others up one
        !           131:            while (i >= position+1 ) {
        !           132:               if ( this.p[i-1].state == "link" ) {
        !           133:                  this.p[ i ] = new addLink( this.p[ i-1 ].lname, this.p[i-1].link, this.p[i-1].address, i);
        !           134:               } else {
        !           135:                  this.p[ i ] = new addFolder( this.p[ i-1 ].lname, this.p[i-1].p.length, this.address+".p["+ i +"]" );
        !           136:                                                    // move all of the inner folder stuff
        !           137:                  shiftFolder(this.p[i-1],this,i);
        !           138:               }
        !           139: 	      this.p[i].exists=this.p[i-1].exists;         // ben debug this just added
        !           140:               i--;
        !           141:            }
        !           142: 	}
1.1       tyszkabe  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.9     ! tyszkabe  184:         shiftFolder(addressCache.p[0],this,position);         //ben debug was addressCache.p[0]
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:    add_link=window.open('','Link','width=360,height=165,scrollbars=0');
1.6       tyszkabe  244:    savedoc=add_link.document;
1.8       tyszkabe  245:    var instr='<html><head><title>New Folder</title></head><body bgcolor="#bbbbbb">';
                    246:    instr+='<center><form method="post" name="newFolder">';
                    247:    instr+='<table width="340" height="150" bgcolor="#ffffff" align="center">';
                    248:    instr+='<tr><td>';
                    249:    instr+='Folder Name:<br><input type="text" name="title" size="45" value=""><br>';
                    250:    instr+='<center>';
                    251:    instr+='<input type="button" value="Save and Position" onclick="javascript:opener.addNewFolder(newFolder.title.value);">';
1.7       tyszkabe  252:    instr+='<input type="button" value="Close (no save)" onclick="javascript:window.close();">';
1.8       tyszkabe  253:    instr+='</center></td></tr></table></form></center>';
1.6       tyszkabe  254:    instr+='</body></html>';
                    255:    savedoc.write(instr);
                    256:    savedoc.close();
1.4       tyszkabe  257: }
1.1       tyszkabe  258: 
1.8       tyszkabe  259: //----------------------------------------------------Add the just-named folder
                    260: function addNewFolder(title) {
                    261:    dragCache="/res/adm/pages/bookmarkmenu/folder_opened.gif";
                    262:    lastIcon="/res/adm/pages/bookmarkmenu/folder_opened.gif";
                    263:    lastDrug="-1";
1.9     ! tyszkabe  264:    addressCache=new addFolder("doesnotmatter",1,"doesnotmatter");
        !           265:    addressCache.p[0]=new addFolder(title,1,"doesnotmatter");
        !           266:    addressCache.p[0].exists=true;           //this and line above are debug
1.8       tyszkabe  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.open();
                    331:        image_num=0;
1.1       tyszkabe  332:        parent.frames[4].document.write("<BODY>");
1.5       tyszkabe  333: //       parent.frames[4].document.write("<p>So far so good</p>");  //--debug
                    334:        drawTree(1,bookmarkpal.bookmarks.p);     //----giving error: bookmarkpal not defined
                    335: //       parent.frames[4].document.write("<p>Still doing good, after DrawTree</p>");
1.1       tyszkabe  336:        parent.frames[4].document.write("</BODY>");
                    337: }
                    338: 
1.2       tyszkabe  339: //-----------------------------------------------------------------------------
                    340: // Saves bookmarks by building and then 'put'ing the string that generates the
                    341: // bookmarks
                    342: //-----------------------------------------------------------------------------
                    343: 
1.8       tyszkabe  344: //--------------recovers old bookmarks this is a debug function remove it later
                    345: function recover() {
                    346:    parent.frames[7].document.saveBookmarks.hiddenbookmarks.value='recover';
                    347:    parent.frames[7].document.saveBookmarks.submit();
                    348: }
                    349: 
                    350: 
1.2       tyszkabe  351: //----------------------------------------------------------starts save process
                    352: function save() {
1.8       tyszkabe  353: //   parent.frames[4].document.clear();                                    // debug
                    354: //   parent.frames[4].document.write("<P>Debug: Beginning save process...</P>");   // debug
                    355:    saveVar="this.bookmarks=new addFolder(\"Stuff\","+bookmarkpal.bookmarks.p.length+",\"bookmarks\");\n";
                    356:    saveTree("bookmarks",bookmarkpal.bookmarks.p);
                    357: //   parent.frames[4].document.write("<p>writing variable...</p>"+saveVar+"<p>...done</p>");      // debug
                    358:    parent.frames[7].document.saveBookmarks.hiddenbookmarks.value=saveVar;
1.3       tyszkabe  359:    return true;
1.2       tyszkabe  360: }
                    361: 
                    362: 
1.3       tyszkabe  363: //---------------------------------------------------------generate save string
1.2       tyszkabe  364: function saveTree(depth_string,folder) {
1.8       tyszkabe  365:    var n=0;                                    // n renumbers links because 
                    366:    for (var i=0; i<folder.length; i++) {       // of deleted links
1.2       tyszkabe  367:       if (folder[i].exists) {
                    368:          if (folder[i].state=="link") {
1.8       tyszkabe  369:             saveLink(depth_string,folder[i], n);
1.2       tyszkabe  370:          } else {
1.8       tyszkabe  371:             saveFolder(depth_string+".p["+n+"]",folder[i]);
                    372:             if (folder[i].p.length>=0) {
                    373:                saveTree(depth_string+".p["+n+"]",folder[i].p);
1.2       tyszkabe  374:             }
                    375:          }
1.8       tyszkabe  376: 	 n++;
1.2       tyszkabe  377:       }
                    378:    }
1.1       tyszkabe  379: }
1.2       tyszkabe  380: 
                    381: 
                    382: //-------------------------Writes javascript code for generating individual folder
                    383: function saveFolder(depth_string, folder) {
1.8       tyszkabe  384:        saveVar+="this."+depth_string+"=new addFolder(\""+folder.lname+"\","+folder.p.length+",\""+depth_string+"\");\n";
1.2       tyszkabe  385: }
                    386: 
                    387: 
                    388: //-------------------------Writes javascript code for generating individual link
1.8       tyszkabe  389: function saveLink(depth_string,link,newpos) {
                    390:        saveVar+="this."+depth_string+".p["+newpos+"]=new addLink(\""+link.lname+"\",\""+link.link+"\",\""+depth_string+"\","+newpos+");\n";
1.5       tyszkabe  391: }
                    392: 
                    393: 
                    394: 

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