Annotation of loncom/html/res/adm/pages/bookmarkmenu/bookmarklib.js, revision 1.2
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.2 ! tyszkabe 48: this.icon = "/adm/res/pages/bookmarkmenu/folder_opened.gif";
! 49: this.pressed = "/adm/res/pages/bookmarkmenu/folder_opened_pressed.gif";
1.1 tyszkabe 50: } else {
51: this.state = "closed";
1.2 ! tyszkabe 52: this.icon = "/adm/res/pages/bookmarkmenu/folder_closed.gif";
! 53: this.pressed = "/adm/res/pages/bookmarkmenu/folder_closed_pressed.gif";
1.1 tyszkabe 54: }
55: redrawTree(1, bookmarkpal.bookmarks.p);
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) {
155: // opener.clientwindow.location(url); // <------THIS IS REAL VERSION
156: opener.open(url); // <------THIS IS FAKE VERSION
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:
219:
220: //-----------------------------------------------------------------------------
221: // The following are construction functions.
222: //-----------------------------------------------------------------------------
223:
224: //--------------------------------------------------generate the Tree HTML code
225: function drawTree(depth, folder) {
226: for (var i=1; i<folder.length; i++) {
227: if (folder[i].exists) {
228: if (folder[i].state=="link") {
229: drawLink(depth,folder[i]);
230: } else {
231: drawFolder(depth,folder[i]);
232: if (folder[i].state=="opened" && folder[i].p.length>=0) {
233: drawTree(depth+1,folder[i].p);
234: }
235: }
236: }
237: }
238: }
239:
240: //----------------------------------------Writes HTML code for individual folder
241: function drawFolder(depth, folder) {
242: parent.frames[4].document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign=left nowrap>");
1.2 ! tyszkabe 243: 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 244: image_num++;
245: if ( depth != 1 ) {
246: image_num++;
1.2 ! tyszkabe 247: 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 248: }
249: 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>");
250: image_num++;
251: parent.frames[4].document.write("<TD valign=middle align=left nowrap><FONT face='Arial, Helvetica'> "+folder.lname+"</FONT></TABLE>");
252: }
253:
254: //--------------------------------------Writes HTML code for individual link
255: function drawLink(depth, folder) {
256: parent.frames[4].document.write("<TABLE border=0 cellspacing=0 cellpadding=0><TR><TD valign = middle nowrap>");
257: image_num++;
1.2 ! tyszkabe 258: 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 259:
260: 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>");
261: image_num++;
262: 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>");
263: }
264:
265: //--------------------Calls Build and draws functions. This function also takes
266: // care of housekeeping
267: function initializeTree() {
268: // trash = new addFolder();
269: bookmarkpal = new buildUserTree();
270: redrawTree();
271: // parent.frames[5.document.write("HELLO WORLDS!!");
272: }
273:
274: //--------------------------------Redraws screen without initiallizing anything
275: function redrawTree() {
276: parent.frames[4].document.clear();
277: image_num = 0;
278: parent.frames[4].document.write("<BODY>");
279: drawTree(1, bookmarkpal.bookmarks.p);
280: parent.frames[4].document.write("</BODY>");
281: }
282:
1.2 ! tyszkabe 283: //-----------------------------------------------------------------------------
! 284: // Saves bookmarks by building and then 'put'ing the string that generates the
! 285: // bookmarks
! 286: //-----------------------------------------------------------------------------
! 287:
! 288: //----------------------------------------------------------starts save process
! 289: function save() {
! 290: saveTree("this.bookmarks",bookmarks);
! 291: }
! 292:
! 293:
! 294: //--------------------------------------------------------generate save string
! 295: function saveTree(depth_string,folder) {
! 296: for (var i=1; i<folder.length; i++) {
! 297: if (folder[i].exists) {
! 298: if (folder[i].state=="link") {
! 299: saveLink(depth_string,folder[i]);
! 300: } else {
! 301: saveFolder(depth_string,folder[i]);
! 302: if (folder[i].state=="opened" && folder[i].p.length>=0) {
! 303: saveTree(depth_string+".p["+i+"]",folder[i].p);
! 304: }
! 305: }
! 306: }
! 307: }
1.1 tyszkabe 308: }
1.2 ! tyszkabe 309:
! 310:
! 311: //-------------------------Writes javascript code for generating individual folder
! 312: function saveFolder(depth_string, folder) {
! 313: parent.frames[4].saveVar+=depth_string+"=new addfolder('"+folder.name+"',"+folder.p.length+",'"+folder.address+");\n";
! 314: }
! 315:
! 316:
! 317: //-------------------------Writes javascript code for generating individual link
! 318: function saveLink(depth_string,link) {
! 319: parent.frames[4].saveVar+=depth_string+"=new addlink('"+link.name+"',"+link.link+",'"+link.address+","+link.position+");\n";
! 320: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>