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

1.1       tyszkabe    1: // bookmarklib.js
                      2: //
1.2       tyszkabe    3: // Functions combined with the HTML code in admbookmarks.pm
1.1       tyszkabe    4: //
                      5: 
                      6: 
                      7: //-------------------------------------------------------------------------------
                      8: // Here are all of the bookmark methods:
                      9: //-------------------------------------------------------------------------------
                     10: 
                     11: //-------------------------------------------------------Adds a link to an object
                     12: function addLink(name, link, address, position) {
                     13:        this.lname = name;
                     14:        this.link = link;
                     15:        this.address = address;
                     16:        this.position = position;
                     17:        this.state = "link";
1.2       tyszkabe   18:        this.icon = "/res/adm/pages/bookmarkmenu/link.gif";
                     19:        this.pressed = "/res/adm/pages/bookmarkmenu/link_pressed.gif";
1.1       tyszkabe   20:        this.hover = hover;
                     21:        this.remove = remove
                     22:        this.exists = true;
                     23: }
                     24: 
                     25: //-----------------------------------------------------Adds a folder to an object
                     26: function addFolder(name, size, address) {
                     27:        this.p = new Array(size);
                     28:        this.lname = name;
                     29:        this.address = address;
                     30:        this.state = "opened";
1.2       tyszkabe   31:        this.icon = "/res/adm/pages/bookmarkmenu/folder_opened.gif";
                     32:        this.pressed = "/res/adm/pages/bookmarkmenu/folder_opened_pressed.gif";
1.1       tyszkabe   33:        this.swapState = swapState;
                     34:        this.clickFolder = clickFolder;
                     35:        this.clickLink = clickLink;
                     36:        this.hover = hover;
                     37:        this.remove = remove;
                     38:        this.bump = bump;
                     39:        this.insertLink = insertLink;
                     40:        this.insertFolder = insertFolder;
                     41:        this.exists = true;
                     42: }
                     43: 
                     44: //-----------------------------------------Swaps folder state from open to closed
                     45: function swapState() {
                     46:        if (this.state == "closed") {
                     47:            this.state = "opened";
1.3       tyszkabe   48:            this.icon = "/res/adm/pages/bookmarkmenu/folder_opened.gif";
                     49:            this.pressed = "/res/adm/pages/bookmarkmenu/folder_opened_pressed.gif";
1.1       tyszkabe   50:        } else {
                     51:            this.state = "closed";
1.3       tyszkabe   52:            this.icon = "/res/adm/pages/bookmarkmenu/folder_closed.gif";
                     53:            this.pressed = "/res/adm/pages/bookmarkmenu/folder_closed_pressed.gif";
1.1       tyszkabe   54:        }
1.4       tyszkabe   55:        redrawTree();
1.1       tyszkabe   56:     }
                     57: 
                     58: //------------------------------------------swaps the dragged icon into the image
                     59: function hover( object ) {
                     60:     if ( dragCache != "" ) {
                     61:         object.src = this.pressed;
                     62:         parent.frames[4].document.images[lastDrug].src = lastIcon;
                     63:         lastIcon = this.icon;
                     64:         lastDrug = object.name;
                     65:     }
                     66: }
                     67: 
                     68: //------------------------------------------------------The click on link  method
                     69: function clickLink( object, position ) {
                     70:     if (dragCache=="") {                            //---------'pick up' the icon
                     71:         dragCache=object.src;
                     72:         lastIcon=this.p[position].icon;
                     73:         lastDrug=object.name;
                     74:         addressCache=new addLink(this.p[position].lname,this.p[position].link,this.p[position].address,position);
                     75:         this.p[position].remove();
                     76:     } else {                                        //--------'put down' the icon
                     77:         dragCache="";
                     78:         if ( addressCache.state == "link" ) {       //------differently if a link
                     79:           this.insertLink( position );
                     80:         } else {                                    //--------------than a folder
                     81:           this.insertFolder( position );
                     82:         }
                     83:         redrawTree();
                     84:     }
                     85: }
                     86: 
                     87: //-----------------------------------------------------The click on Folder method
                     88: function clickFolder( object ) {
                     89:     if (dragCache=="") {                            //---------'pick up' the icon
                     90:         dragCache=object.src;
                     91:         lastIcon=this.icon;
                     92:         lastDrug=object.name;
1.2       tyszkabe   93:         addressCache=new addFolder("lame_folder",2,"doesnotmatter"); //used to be (this.lname,this.p.length+1,this.address)
                     94:       shiftFolder(this,addressCache,1);               //this is  a whole new line
1.1       tyszkabe   95:         this.remove();
                     96:     } else {                                        //--------'put down' the icon
                     97:         dragCache = "";
                     98:            if ( addressCache.state == "link" ) {    //-----place link into folder
                     99:               this.insertLink( 1 );
                    100: //              this.p[ this.p.length ] = new addLink( addressCache.lname, addressCache.link, this.address, this.p.length );
                    101:            } else {                                 //---place folder into folder
                    102:                 this.insertFolder( 1 );
                    103: //              this.p[ this.p.length ] = new addFolder( addressCache.lname, addressCache.p.length, this.address+".p["+this.p.length+"]" );
                    104: //              this.p[ this.p.length ].p = addressCache.p;
                    105:            }
                    106:     redrawTree();
                    107:     }
                    108: }
                    109: 
                    110: //---------Folder method to place link in middle of other links (should simplify code)
                    111: function insertLink( position ) {
                    112:         this.bump( position );
                    113:         this.p[ position ] = new addLink( addressCache.lname, addressCache.link, this.address, position );
                    114: }
                    115: 
                    116: 
                    117: //---------------------------Recursive folder Method to bump items up one to make room 
                    118: //                                   for new item. Currently, bump doesn't always work.
                    119: function bump( position ) {
                    120: // ORIGINAL RECURSIVE VERSION has short-comings but may work better because of 'not exists'
                    121: //
                    122: //        if ( this.length >= position ) {
                    123: //           this.bump( position + 1 );
                    124: //        }
                    125: //        position;
                    126: //        this.p[ position + 1 ] = this.p[position ];
                    127: //
                    128: // NON RECURSIVE of the same thing (I'll probably stick with this).
                    129: // I can combine the creation and shifting if everything works out nicely
                    130: // Worry about what happens to the first link.
                    131:         var i=this.p.length;                   // First, create a new spot at the top.
                    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.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:         }
                    137:         this.p[i].exists=this.p[i-1].exists;                    // preserve existance
                    138:         i--;                                           // Second, shift others up one
                    139:         while ( i >= position + 1 ) {
                    140:            if ( this.p[i-1].state == "link" ) {
                    141:               this.p[ i ] = new addLink( this.p[ i-1 ].lname, this.p[i-1].link, this.p[i-1].address, i);
                    142:            } else {
                    143:               this.p[ i ] = new addFolder( this.p[ i-1 ].lname, this.p[i-1].p.length, this.address+".p["+ i +"]" );
                    144:                                                 // move all of the inner folder stuff
                    145:               shiftFolder( this.p[i-1], this, i);
                    146:            }
                    147: //           this.p[i].address = this.p[i-1].address;
                    148: //           this.p[i].exists = this.p[ i-1 ].exists;           // preserve existance
                    149:            i--;
                    150:         }
                    151: }
                    152: 
                    153: //-----------------------------------------------------------Opens the page
                    154: function clickOnBookmark(url) {
1.3       tyszkabe  155:        open(url,opener.clientwindow.name); // <------THIS IS REAL VERSION
                    156: //       opener.open(url);                    // <------THIS IS FAKE VERSION
1.1       tyszkabe  157: }
                    158: 
                    159: 
                    160: 
                    161: 
                    162: //-------------------------------------------------------------------------
                    163: // Now we have standard (non-method) functions
                    164: //-------------------------------------------------------------------------
                    165: 
                    166: 
                    167: //---------------------------------shifts contents of folder up one position
                    168: function shiftFolder(object1, object2, n) {
                    169:       object2.p[n] = new addFolder(object1.lname,object1.length,object2.address+".p["+n+"]");
                    170:       for (var i=1; i<object1.p.length; i++) {
                    171:         if (object1.p[i].state=="link") {
                    172:           object2.p[n].p[i]=new addLink(object1.p[i].lname,object1.p[i].link,object2.p[n].address,i);
                    173:         } else {
                    174:           object2.p[n].p[i]=new addFolder(object1.p[i].lname,object1.p[i].length,object2.address+".p["+n+"].p["+i+"]");
                    175:           shiftFolder(object1.p[i],object2.p[n],i);
                    176:         }
                    177:         object2.p[n].p[i].state=object1.p[i].state;
                    178:         object2.p[n].p[i].icon=object1.p[i].icon;
                    179:         object2.p[n].p[i].pressed=object1.p[i].pressed;
                    180:         object2.p[n].p[i].exists=object1.p[i].exists;      
                    181:       }
                    182:       object2.p[n].state=object1.state;
                    183:       object2.p[n].icon=object1.icon;
                    184:       object2.p[n].pressed=object1.pressed;
                    185:       object2.p[n].exists=object1.exists;      
                    186: }
                    187: 
                    188: 
                    189: //--------Method to place folder in middle of other links (this simplifies code)
                    190: function insertFolder(position) {
                    191:         this.bump(position);
                    192:         shiftFolder(addressCache.p[1],this,position);
                    193: }
                    194: 
                    195: 
                    196: //---------------------------delete link&folder from within other links&folders
                    197: function remove() {
                    198:         this.exists = false;
                    199: }
                    200: 
                    201: //---------------------Function that deletes link from dragging it to the trash
                    202: function clickTrash() {
                    203:         dragCache = "";
                    204:         redrawTree();
                    205: }
                    206: 
                    207: //-----------------------------------------------------------------------------
                    208: // These functions should be incorporated as methods
                    209: // and the trash should be a folder. I'll work on this later.
                    210: //-----------------------------------------------------------------------------
                    211: function hoverTrash() {
                    212: //        if ( dragCache != "" ) {
                    213: //           parent.frames[6].document.images[0].src = lastIcon;
                    214: //           lastIcon = "folder_trash.gif";
                    215: //        }       
                    216: }
                    217: //----------------------------------------------------------------------------
                    218: 
1.4       tyszkabe  219: //----------------------------------------------------------------Add new link
                    220: function newLink() {
                    221:    window.open("add_link.html","Link","width=400,height=200,scrollbars=0");
                    222: }
1.1       tyszkabe  223: 
                    224: //-----------------------------------------------------------------------------
                    225: // The following are construction functions.
                    226: //-----------------------------------------------------------------------------
                    227: 
                    228: //--------------------------------------------------generate the Tree HTML code
                    229: function drawTree(depth, folder) {
                    230:    for (var i=1; i<folder.length; i++) {
                    231:       if (folder[i].exists) {
                    232:          if (folder[i].state=="link") {
                    233:             drawLink(depth,folder[i]);
                    234:          } else {
                    235:             drawFolder(depth,folder[i]);
                    236:             if (folder[i].state=="opened" && folder[i].p.length>=0) {
                    237:                drawTree(depth+1,folder[i].p);
                    238:             }
                    239:          }
                    240:       }
                    241:    }
                    242: }
                    243: 
                    244: //----------------------------------------Writes HTML code for individual folder
                    245: function drawFolder(depth, folder) {
                    246:        parent.frames[4].document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign=left nowrap>");
1.2       tyszkabe  247:        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  248:        image_num++;
                    249:        if ( depth != 1 ) {
                    250:            image_num++;
1.2       tyszkabe  251:            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  252:        }
                    253:        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>");
                    254:        image_num++;
                    255:        parent.frames[4].document.write("<TD valign=middle align=left nowrap><FONT face='Arial, Helvetica'> "+folder.lname+"</FONT></TABLE>");
                    256: }
                    257: 
                    258: //--------------------------------------Writes HTML code for individual link
                    259: function drawLink(depth, folder) {
                    260:        parent.frames[4].document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign = middle nowrap>");
                    261:        image_num++;
1.2       tyszkabe  262:        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  263: 
                    264:        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>");
                    265:        image_num++;
                    266:        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>");
                    267: }
                    268: 
                    269: //--------------------Calls Build and draws functions. This function also takes
                    270: //                                                         care of housekeeping
                    271: function initializeTree() {
1.5     ! tyszkabe  272: //       bookmarkpal = new buildUserTree();
1.1       tyszkabe  273:        redrawTree();
                    274: }
                    275: 
                    276: //--------------------------------Redraws screen without initiallizing anything
                    277: function redrawTree() {
1.5     ! tyszkabe  278: //       parent.frames[4].document.clear();  //--Remove this line later. clear has depreciated from Javascript
        !           279:        parent.frames[4].document.open();
        !           280:        image_num=0;
1.1       tyszkabe  281:        parent.frames[4].document.write("<BODY>");
1.5     ! tyszkabe  282: //       parent.frames[4].document.write("<p>So far so good</p>");  //--debug
        !           283:        drawTree(1,bookmarkpal.bookmarks.p);     //----giving error: bookmarkpal not defined
        !           284: //       parent.frames[4].document.write("<p>Still doing good, after DrawTree</p>");
1.1       tyszkabe  285:        parent.frames[4].document.write("</BODY>");
                    286: }
                    287: 
1.2       tyszkabe  288: //-----------------------------------------------------------------------------
                    289: // Saves bookmarks by building and then 'put'ing the string that generates the
                    290: // bookmarks
                    291: //-----------------------------------------------------------------------------
                    292: 
                    293: //----------------------------------------------------------starts save process
                    294: function save() {
1.5     ! tyszkabe  295:    parent.frames[4].document.clear();                                    // debug
1.4       tyszkabe  296:    parent.frames[4].document.write("<P>Debug: Beginning save process...</P>");   // debug
1.3       tyszkabe  297:    saveVar="this.bookmarks=new addFolder('Stuff',"+bookmarkpal.bookmarks.p.length+",'bookmarks')<br>\n";
                    298:    saveTree("this.bookmarks",bookmarkpal.bookmarks.p);
                    299:    parent.frames[4].document.write("<p>writing variable...</p>"+saveVar+"<p>...done</p>");      // debug
                    300:    parent.frames[7].document.saveBookmarks.hidden_bookmarks=saveVar;
                    301:    return true;
1.2       tyszkabe  302: }
                    303: 
                    304: 
1.3       tyszkabe  305: //---------------------------------------------------------generate save string
1.2       tyszkabe  306: function saveTree(depth_string,folder) {
                    307:    for (var i=1; i<folder.length; i++) {
                    308:       if (folder[i].exists) {
                    309:          if (folder[i].state=="link") {
1.3       tyszkabe  310:             saveLink(depth_string+".p["+i+"]",folder[i]);
1.2       tyszkabe  311:          } else {
1.3       tyszkabe  312:             saveFolder(depth_string+".p["+i+"]",folder[i]);
1.2       tyszkabe  313:             if (folder[i].state=="opened" && folder[i].p.length>=0) {
                    314:                saveTree(depth_string+".p["+i+"]",folder[i].p);
                    315:             }
                    316:          }
                    317:       }
                    318:    }
1.1       tyszkabe  319: }
1.2       tyszkabe  320: 
                    321: 
                    322: //-------------------------Writes javascript code for generating individual folder
                    323: function saveFolder(depth_string, folder) {
1.3       tyszkabe  324:        saveVar+=depth_string+"=new addfolder('"+folder.lname+"',"+folder.p.length+",'"+folder.address+"');<BR>\n";
1.2       tyszkabe  325: }
                    326: 
                    327: 
                    328: //-------------------------Writes javascript code for generating individual link
                    329: function saveLink(depth_string,link) {
1.3       tyszkabe  330:        saveVar+=depth_string+"=new addlink('"+link.lname+"','"+link.link+"','"+link.address+"',"+link.position+");<BR>\n";
1.5     ! tyszkabe  331: }
        !           332: 
        !           333: 
        !           334: 

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