--- loncom/html/res/adm/pages/bookmarkmenu/bookmarklib.js 2000/10/13 11:57:29 1.8 +++ loncom/html/res/adm/pages/bookmarkmenu/bookmarklib.js 2006/04/20 04:08:04 1.21 @@ -1,395 +1,636 @@ +// The LearningOnline Network with CAPA // bookmarklib.js +// +// $Id: bookmarklib.js,v 1.21 2006/04/20 04:08:04 albertel Exp $ +// +// Copyright Michigan State University Board of Trustees +// +// This file is part of the LearningOnline Network with CAPA (LON-CAPA). +// +// LON-CAPA is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// LON-CAPA is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with LON-CAPA; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// Functions combined with the HTML code in admbookmarks.pm -// and code in bookmarkmenu_toolbar.html +// /home/httpd/html/adm/gpl.txt // +// http://www.lon-capa.org/ +// +// +// This is a rewritten version of bookmarklib.js +// +// Functions to be combined with the HTML code found in +// admbookmarks.pm. The combination will provide a complete +// functionality for the bookmarkmenu in accordance to defined +// requirements. +// +// For further information and documentation regarding this program, +// please refer to bookmarkmenu_OOD.txt, the design documentation for +// bookmarkmenu. +// +// +// +// The perl module admbookmarks.pm interacts with this library by +// generating a page that includes bookmarklib.js and a JavaScript +// function initializeTree() that builds the the tree using successive +// newLink() and newFolder() calls and one cache=new newCache() call. +// The entire newLink()/newFolder() succession is the string that is +// stored in the userspace on Lon-Capa as bookmarks. +// +// +// Created on: 12-28-2000 by Benjamin Tyszka +// Edited: 12-29-2000 by Benjamin Tyszka +// mm-dd-yyyy by Xxxxxxxx Xxxxxx + + +//clienttitle="Enter title here";//debug +//clienthref="Enter url here"; //debug + +//function ugh_oh( msg, url, ln ) { +// alert("Error: "+msg+" in "+url+" at line: "+ln); +// return true; +//} + +//alert("Does alert even work?"); + +//window.onerror=ugh_oh; +//this.onerror=ugh_oh; -//------------------------------------------------------------------------------- -// Here are all of the bookmark methods: -//------------------------------------------------------------------------------- - -//-------------------------------------------------------Adds a link to an object -function addLink(name, link, address, position) { - this.lname = name; - this.link = link; - this.address = address; - this.position = position; - this.state = "link"; - this.icon = "/res/adm/pages/bookmarkmenu/link.gif"; - this.pressed = "/res/adm/pages/bookmarkmenu/link_pressed.gif"; - this.hover = hover; - this.remove = remove - this.exists = true; -} - -//-----------------------------------------------------Adds a folder to an object -function addFolder(name, size, address) { - this.p = new Array(); //BEN got rid of size in Array Agument - // Currently SIZE doesn't matter - // This probably works cross-platform - this.lname = name; - this.address = address; - this.state = "opened"; - this.icon = "/res/adm/pages/bookmarkmenu/folder_opened.gif"; - this.pressed = "/res/adm/pages/bookmarkmenu/folder_opened_pressed.gif"; - this.swapState = swapState; - this.clickFolder = clickFolder; - this.clickLink = clickLink; - this.hover = hover; - this.remove = remove; - this.bump = bump; - this.insertLink = insertLink; - this.insertFolder = insertFolder; - this.exists = true; + +//--------------------------------------------------------------------- +// Tree object +//--------------------------------------------------------------------- +// Basis for user's bookmarks and folders - All properties and methods +// pertaining to a user in general are found here. Refer to +// bookmarkmenu_OOD.txt for further documenation. +function newTree() { + this.redraw = redraw; + this.treeSave = treeSave; + this.bookmarks = new newFolder("bookmarks",true); + this.cache = new newCache(); +} + +//------------------------------------------refresh folder/link display +function redraw() { + image_num = -1; // reset to before (-1 not 0) the first image + with(frames[4].document) { + open(); //--------for 'compliant' browsers + clear(); //----------for Mozilla (Netscape6) + write("\n" ); + write("
\n" ); + write("" ); + write("" ); + write("" ); + write(""); + write("" ); + write("" ); + write( this.name+" | " ); + write("" ); + write("" ); + write(""); + write("" ); + write("" ); + write( this.name+" | " ); + } +// with (bendebugger.document) { +// write("
"); + write(""); + write(""); + write(""); + write(""); + write(this.name+" |
"); - image_num++; - parent.frames[4].document.write(""); - - parent.frames[4].document.write(""); - image_num++; - parent.frames[4].document.write(" | "+folder.lname+" |
So far so good
"); //--debug - drawTree(1,bookmarkpal.bookmarks.p); //----giving error: bookmarkpal not defined -// parent.frames[4].document.write("Still doing good, after DrawTree
"); - parent.frames[4].document.write(""); -} - -//----------------------------------------------------------------------------- -// Saves bookmarks by building and then 'put'ing the string that generates the -// bookmarks -//----------------------------------------------------------------------------- - -//--------------recovers old bookmarks this is a debug function remove it later -function recover() { - parent.frames[7].document.saveBookmarks.hiddenbookmarks.value='recover'; - parent.frames[7].document.saveBookmarks.submit(); -} - - -//----------------------------------------------------------starts save process -function save() { -// parent.frames[4].document.clear(); // debug -// parent.frames[4].document.write("Debug: Beginning save process...
"); // debug - saveVar="this.bookmarks=new addFolder(\"Stuff\","+bookmarkpal.bookmarks.p.length+",\"bookmarks\");\n"; - saveTree("bookmarks",bookmarkpal.bookmarks.p); -// parent.frames[4].document.write("writing variable...
"+saveVar+"...done
"); // debug - parent.frames[7].document.saveBookmarks.hiddenbookmarks.value=saveVar; - return true; + +//--------------------------------------------------------------------- +// Cache object +//--------------------------------------------------------------------- +// Contains everything related to dragging/dropping folers and links. +// Refer to bookmarkmenu_OOD.txt for further documentation. +function newCache() { + // Cache Properties + this.isLoaded = false; + this.state = ""; + this.lastImg = -1; //I don't know if I can do this yet. + //It doesn't seem to cause errors. + this.Icon = ""; + this.folder = new newFolder('cache',false); + // Cache Methods + this.cacheLoad = cacheLoad; + this.cacheEmpty = cacheEmpty; +} + +//----------------------------------------------Load cache for dragging +function cacheLoad(object1) { + if (object1.state=="folder") { +//alert('cacheLoad11 '+object1.name+' is now: '+this.folder.name); + frames[7].document.images[0].src = '/res/adm/pages/bookmarkmenu/folder_anim.gif'; + object2=object1.moveTo(this.folder); + this.folder=object2; +//alert('cacheLoad22 '+object1.name+' is now: '+this.folder.name); + } else { + frames[7].document.images[0].src = '/res/adm/pages/bookmarkmenu/link_anim.gif'; + this.folder = new newLink(object1.name,object1.url); + } + this.isLoaded = true; + object1.exists = false; } +//---------------------------Places Cache's contents in front of a link +function cacheEmpty(object1,position) { + object1.bump(position); + if (this.folder.state=="folder") { +//alert('cacheEmpty11 is emptying named: '+this.folder.name+' to: '+object1.p[position].name); + object2=this.folder.moveTo(object1.p[position]); + object1.p[position]=object2; +//alert('cacheEmpty22 is emptying named: '+this.folder.name+' to:'+object1.p[position].name); + } else { + object1.p[position] = new newLink(this.folder.name,this.folder.url); + } + frames[7].document.images[0].src = '/res/adm/pages/bookmarkmenu/folder_static.gif'; + this.isLoaded = false; + this.lastImg = -1; //I don't know if I can do this yet. + //It doesn't seem to cause errors + tree.redraw(); +} -//---------------------------------------------------------generate save string -function saveTree(depth_string,folder) { - var n=0; // n renumbers links because - for (var i=0; i