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

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