Annotation of loncom/html/res/adm/pages/bookmarkmenu/bookmarklib.js, revision 1.11
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.10 tyszkabe 213: var clienthref=opener.clientwindow.location.pathname;
1.6 tyszkabe 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>';
1.10 tyszkabe 224: instr+='<input type="button" value="Save" onclick="javascript:opener.addNewLink(newLink.title.value,newLink.address.value);">';
1.8 tyszkabe 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:
1.10 tyszkabe 232: //--------------------------------------Add the just-named link at end of bookmarks
1.8 tyszkabe 233: function addNewLink(title,address) {
1.10 tyszkabe 234: nextPosition=bookmarkpal.bookmarks.p.length;
235: bookmarkpal.bookmarks.p[nextPosition]=new addLink(title,address,"bookmarks",nextPosition);
236: add_link.close();
237: redrawTree();
238: }
239:
240: //-----------------------Add the just-named link and then position within bookmarks
241: function addNewLink_b(title,address) {
1.8 tyszkabe 242: dragCache="/res/adm/pages/bookmarkmenu/folder_opened.gif";
243: lastIcon="/res/adm/pages/bookmarkmenu/folder_opened.gif";
244: lastDrug="-1";
245: addressCache=new addLink(title,address,"doesnotmatter",1);
246: add_link.close();
247: }
248:
249: //----------------------------------------------------------------Add new Folder
250: function newFolder() {
251: add_link=window.open('','Link','width=360,height=165,scrollbars=0');
1.6 tyszkabe 252: savedoc=add_link.document;
1.8 tyszkabe 253: var instr='<html><head><title>New Folder</title></head><body bgcolor="#bbbbbb">';
254: instr+='<center><form method="post" name="newFolder">';
255: instr+='<table width="340" height="150" bgcolor="#ffffff" align="center">';
256: instr+='<tr><td>';
257: instr+='Folder Name:<br><input type="text" name="title" size="45" value=""><br>';
258: instr+='<center>';
1.10 tyszkabe 259: instr+='<input type="button" value="Save" onclick="javascript:opener.addNewFolder(newFolder.title.value);">';
1.7 tyszkabe 260: instr+='<input type="button" value="Close (no save)" onclick="javascript:window.close();">';
1.8 tyszkabe 261: instr+='</center></td></tr></table></form></center>';
1.6 tyszkabe 262: instr+='</body></html>';
263: savedoc.write(instr);
264: savedoc.close();
1.4 tyszkabe 265: }
1.1 tyszkabe 266:
1.10 tyszkabe 267: //----------------------Add the just-named folder at the end of the bookmarks list
1.8 tyszkabe 268: function addNewFolder(title) {
1.10 tyszkabe 269: nextPosition=bookmarkpal.bookmarks.p.length;
270: nextAddress="bookmarks.p["+nextPosition+"]";
271: bookmarkpal.bookmarks.p[nextPosition]=new addFolder(title,1,nextAddress);
272: add_link.close();
273: redrawTree();
274: }
275:
276: //---------------------------------Add the just-named folder and then position it
277: function addNewFolder_b(title) {
1.8 tyszkabe 278: dragCache="/res/adm/pages/bookmarkmenu/folder_opened.gif";
279: lastIcon="/res/adm/pages/bookmarkmenu/folder_opened.gif";
280: lastDrug="-1";
1.9 tyszkabe 281: addressCache=new addFolder("doesnotmatter",1,"doesnotmatter");
282: addressCache.p[0]=new addFolder(title,1,"doesnotmatter");
283: addressCache.p[0].exists=true; //this and line above are debug
1.8 tyszkabe 284: add_link.close();
285: }
286:
287:
288:
289:
290:
291:
292:
1.1 tyszkabe 293: //-----------------------------------------------------------------------------
294: // The following are construction functions.
295: //-----------------------------------------------------------------------------
296:
297: //--------------------------------------------------generate the Tree HTML code
298: function drawTree(depth, folder) {
1.8 tyszkabe 299: for (var i=0; i<folder.length; i++) {
1.1 tyszkabe 300: if (folder[i].exists) {
301: if (folder[i].state=="link") {
302: drawLink(depth,folder[i]);
303: } else {
304: drawFolder(depth,folder[i]);
305: if (folder[i].state=="opened" && folder[i].p.length>=0) {
306: drawTree(depth+1,folder[i].p);
307: }
308: }
309: }
310: }
311: }
312:
313: //----------------------------------------Writes HTML code for individual folder
314: function drawFolder(depth, folder) {
315: parent.frames[4].document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign=left nowrap>");
1.2 tyszkabe 316: 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 317: image_num++;
318: if ( depth != 1 ) {
319: image_num++;
1.2 tyszkabe 320: 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 321: }
322: 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>");
323: image_num++;
324: parent.frames[4].document.write("<TD valign=middle align=left nowrap><FONT face='Arial, Helvetica'> "+folder.lname+"</FONT></TABLE>");
325: }
326:
327: //--------------------------------------Writes HTML code for individual link
328: function drawLink(depth, folder) {
329: parent.frames[4].document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign = middle nowrap>");
330: image_num++;
1.2 tyszkabe 331: 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 332:
333: 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>");
334: image_num++;
335: 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>");
336: }
337:
338: //--------------------Calls Build and draws functions. This function also takes
339: // care of housekeeping
340: function initializeTree() {
1.5 tyszkabe 341: // bookmarkpal = new buildUserTree();
1.1 tyszkabe 342: redrawTree();
343: }
344:
345: //--------------------------------Redraws screen without initiallizing anything
346: function redrawTree() {
1.10 tyszkabe 347: parent.frames[4].document.clear(); //---although depreciated, mozilla still needs it
1.5 tyszkabe 348: parent.frames[4].document.open();
349: image_num=0;
1.1 tyszkabe 350: parent.frames[4].document.write("<BODY>");
1.5 tyszkabe 351: drawTree(1,bookmarkpal.bookmarks.p); //----giving error: bookmarkpal not defined
1.1 tyszkabe 352: parent.frames[4].document.write("</BODY>");
353: }
354:
1.2 tyszkabe 355: //-----------------------------------------------------------------------------
356: // Saves bookmarks by building and then 'put'ing the string that generates the
357: // bookmarks
358: //-----------------------------------------------------------------------------
359:
1.8 tyszkabe 360: //--------------recovers old bookmarks this is a debug function remove it later
361: function recover() {
362: parent.frames[7].document.saveBookmarks.hiddenbookmarks.value='recover';
363: parent.frames[7].document.saveBookmarks.submit();
364: }
365:
366:
1.2 tyszkabe 367: //----------------------------------------------------------starts save process
368: function save() {
1.8 tyszkabe 369: // parent.frames[4].document.clear(); // debug
370: // parent.frames[4].document.write("<P>Debug: Beginning save process...</P>"); // debug
1.11 ! tyszkabe 371: // saveVar="this.bookmarks=new addFolder(\"Stuff\","+bookmarkpal.bookmarks.p.length+",\"bookmarks\");\n";
! 372: saveVar=" ";
1.8 tyszkabe 373: saveTree("bookmarks",bookmarkpal.bookmarks.p);
374: // parent.frames[4].document.write("<p>writing variable...</p>"+saveVar+"<p>...done</p>"); // debug
375: parent.frames[7].document.saveBookmarks.hiddenbookmarks.value=saveVar;
1.3 tyszkabe 376: return true;
1.2 tyszkabe 377: }
378:
379:
1.3 tyszkabe 380: //---------------------------------------------------------generate save string
1.2 tyszkabe 381: function saveTree(depth_string,folder) {
1.8 tyszkabe 382: var n=0; // n renumbers links because
383: for (var i=0; i<folder.length; i++) { // of deleted links
1.2 tyszkabe 384: if (folder[i].exists) {
385: if (folder[i].state=="link") {
1.8 tyszkabe 386: saveLink(depth_string,folder[i], n);
1.2 tyszkabe 387: } else {
1.8 tyszkabe 388: saveFolder(depth_string+".p["+n+"]",folder[i]);
389: if (folder[i].p.length>=0) {
390: saveTree(depth_string+".p["+n+"]",folder[i].p);
1.2 tyszkabe 391: }
392: }
1.8 tyszkabe 393: n++;
1.2 tyszkabe 394: }
395: }
1.1 tyszkabe 396: }
1.2 tyszkabe 397:
398:
399: //-------------------------Writes javascript code for generating individual folder
400: function saveFolder(depth_string, folder) {
1.8 tyszkabe 401: saveVar+="this."+depth_string+"=new addFolder(\""+folder.lname+"\","+folder.p.length+",\""+depth_string+"\");\n";
1.2 tyszkabe 402: }
403:
404:
405: //-------------------------Writes javascript code for generating individual link
1.8 tyszkabe 406: function saveLink(depth_string,link,newpos) {
407: saveVar+="this."+depth_string+".p["+newpos+"]=new addLink(\""+link.lname+"\",\""+link.link+"\",\""+depth_string+"\","+newpos+");\n";
1.5 tyszkabe 408: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>