home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / web_dev / files / mwjpp516.exe / %MAINDIR% / Tools / Bookmark / gotoPrevious.script < prev    next >
Encoding:
Text File  |  2001-06-19  |  1.4 KB  |  76 lines

  1. !!Script 
  2. // Copyright ⌐ 2001 - Miguel Angel Rojas
  3. // @Modified build 497 cm20010225
  4.  
  5. /**
  6. @Tool: gotoPrevious~goes to the previous bookmark.
  7. If previous bookmark does not exist, this will be the last.
  8. */
  9.  
  10. function DoCommand()
  11.     var bookmarkMap = getMapFile( "Bookmarks" );
  12.     
  13.     if ( bookmarkMap.count == 0 )
  14.     {
  15.         return;
  16.     }
  17.     
  18.     var currentBookmark = getGlobal( "currentBookmark", -1);
  19.     var list = getBookmarksAsList( bookmarkMap );
  20.     
  21.     if ( currentBookmark > 0 ) // is not the first
  22.     {
  23.         currentBookmark -= 1;
  24.     }
  25.     else
  26.     {
  27.         currentBookmark = list.count-1;
  28.     }
  29.     
  30.     var position = list.getPosition( currentBookmark );
  31.     
  32.     if ( position && position.valid )
  33.     {
  34.         setGlobal( "currentBookmark", currentBookmark );
  35.         
  36.         // alert( "gotoPrevious="+getGlobal( "currentBookmark" ) );
  37.         
  38.         var previous = list.getAt( position );
  39.         var bookmark = bookmarkMap.lookup( previous.value.hashKey );
  40.         if (bookmark)
  41.         {
  42.             if (bookmark.valid())
  43.             {
  44.                 bookmark.go();
  45.             }
  46.             
  47.         }
  48.     }
  49. }
  50.  
  51. function getBookmarksAsList( bookmarkMap )
  52.     var list = newList();
  53.     var position = bookmarkMap.getHeadPosition();
  54.     
  55.     while ( position && position.valid )
  56.     {
  57.         var next = bookmarkMap.getNext( position );
  58.         if (next.value.valid())
  59.         {
  60.             list.addTail(next);
  61.         }
  62.         else
  63.         {
  64.             bookmarkMap.remove(next.value.hashKey);
  65.         }
  66.     }
  67.     
  68.     list.sort(); // sort in order of creation
  69.  
  70.     return list;
  71. }
  72.  
  73. !!/Script
  74.