File:  [LON-CAPA] / loncom / javascriptlib / loncapa.js
Revision 1.1: download - view: text, annotated - select for diffs
Mon May 14 21:19:16 2001 UTC (23 years ago) by harris41
Branches: MAIN
CVS tags: stable_2001_fall, HEAD
beginning javascript library which should work
everywhere

    1: // loncapa.js
    2: //
    3: // This is a window handling library for the LON-CAPA
    4: // web interface.  This library interfaces with a variety
    5: // of web page handlers.  This is part of the LON-CAPA
    6: // project at http://www.lon-capa.org/
    7: //
    8: // Window status tracking
    9: // -1: not yet opened, no existing window object yet created
   10: // 0: closed
   11: // 1: open (or closed without using the close_window method)
   12: //
   13: // Methods
   14: // -------
   15: // open_window
   16: // close_window
   17: // check_window
   18: // change_window
   19: // change_window_by_submission
   20: 
   21: var status=new Array();
   22: status['abc123']=-1;
   23: status['def456']=-1;
   24: status['ghi789']=-1;
   25: var windows=new Array();
   26: 
   27: //-------------------------------------------------------- window attributes
   28: function window_attributes(name,type) {
   29:   if (name=='abc123') {
   30:     if (type=='target') {return '';}
   31:     if (type=='name') {return 'abc123';}
   32:     if (type=='options') {return 'width=360,height=165';}
   33:     return(true);
   34:   }
   35:   if (name=='def456') {
   36:     if (type=='target') {return '';}
   37:     if (type=='name') {return 'def456';}
   38:     if (type=='options') {return 'width=360,height=165';}
   39:     return(true);
   40:   }
   41:   if (name=='ghi789') {
   42:     if (type=='target') {return '';}
   43:     if (type=='name') {return 'ghi789';}
   44:     if (type=='options') {return 'width=360,height=165';}
   45:     return(true);
   46:   }
   47:   alert('undefined window '+name+' called for loncapa.js;'+
   48:         'see window_attributes function');
   49:   return(false);
   50: }
   51: //------------------------------------------------------------ open a window
   52: function open_window(name) {
   53:   if (window_attributes(name)&&(status[name]==-1||windows[name].closed)) {
   54:     windows[name]=window.open(window_attributes(name,'target'),
   55:                               window_attributes(name,'name'),
   56:                               window_attributes(name,'options'));
   57:     status[name]=1;
   58:   }
   59: }
   60: //-------------------------------------------------- close dependent windows
   61: function close_dependents(name) {
   62:   if (name=='THIS') {
   63:     close_window('abc123');
   64:     close_window('def456');
   65:     close_window('ghi789');
   66:   }
   67:   if (name=='abc123') {
   68:     close_window('ghi789');
   69:   }
   70: }
   71: //----------------------------------------------------------- close a window
   72: function close_window(name) {
   73:   close_dependents(name);
   74:   
   75:   if (name!="THIS" && window_attributes(name) && status[name]!=-1
   76:       && !windows[name].closed) {
   77:     windows[name].close();
   78:     status[name]=0;
   79:   }
   80: }
   81: //------------------------------------------------- check and focus a window
   82: function check_window(name) {
   83:   open_window(name);
   84:   windows[name].focus();
   85: }
   86: //---------------------------------------------------------- change a window
   87: function change_window(name) {
   88:   check_window(name);
   89: }
   90: //-------------------------------------------- change a window by submission
   91: function change_window_by_submission() {
   92:   check_window(name);
   93: }

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