home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 August / PCpro_2005_08.ISO / files / firefox / ScrapBook.xpi / chrome / scrapbook.jar / content / view.js < prev    next >
Encoding:
JavaScript  |  2005-06-04  |  2.9 KB  |  97 lines

  1. /**************************************************
  2. // view.js
  3. // Implementation file for view.xul
  4. // 
  5. // Description: 
  6. // Author: Gomita
  7. // Contributors: 
  8. // 
  9. // Version: 
  10. // License: see LICENSE.txt
  11. **************************************************/
  12.  
  13.  
  14.  
  15. var gID, gRes;
  16.  
  17.  
  18.  
  19. function SB_initView()
  20. {
  21.     gID = document.location.href.match(/\?id\=(\d{14})$/);
  22.     gID = RegExp.$1;
  23.  
  24.     SBRDF.init();
  25.  
  26.     var ResURL = gID ? "urn:scrapbook:item" + gID : "urn:scrapbook:root";
  27.     gRes = SBservice.RDF.GetResource(ResURL);
  28.     var type = SBRDF.getProperty("type", gRes);
  29.     if ( type != "folder" )
  30.     {
  31.         window.location.href = SBcommon.getURL(gID, type);
  32.         return;
  33.     }
  34.  
  35.  
  36.     var htmlSrc = SB_getHTMLHead(SBRDF.getProperty("title", gRes));
  37.  
  38.     SBservice.RDFC.Init(SBRDF.data, gRes);
  39.     var ResList = SBservice.RDFC.GetElements();
  40.     while ( ResList.hasMoreElements() )
  41.     {
  42.         var aRes = ResList.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
  43.         var aID  = SBRDF.getProperty("id", aRes);
  44.         if ( SBservice.RDFCU.IsContainer(SBRDF.data, aRes) ) continue;
  45.         var aSBitem = new ScrapBookItem(aID);
  46.         aSBitem.title   = SBRDF.getProperty("title", aRes);
  47.         aSBitem.icon    = SBRDF.getProperty("icon", aRes);
  48.         aSBitem.source  = SBRDF.getProperty("source", aRes);
  49.         aSBitem.comment = SBRDF.getProperty("comment", aRes);
  50.         if ( !aSBitem.icon ) aSBitem.icon = SBcommon.getDefaultIcon(SBRDF.getProperty("type", aRes));
  51.         htmlSrc += SB_getHTMLBody(aSBitem);
  52.     }
  53.  
  54.     htmlSrc += SB_getHTMLFoot();
  55.  
  56.     var htmlFile = SBcommon.getScrapBookDir().clone();
  57.     htmlFile.append("collection.html");
  58.     if ( !htmlFile.exists() ) htmlFile.create(htmlFile.NORMAL_FILE_TYPE, 0666);
  59.     SBcommon.writeFile(htmlFile, htmlSrc, "UTF-8");
  60.     var htmlFilePath = SBservice.IO.newFileURI(htmlFile).spec;
  61.     window.location.href = htmlFilePath;
  62. }
  63.  
  64.  
  65. function SB_getHTMLHead(aTitle)
  66. {
  67.     var HTML = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n\n'
  68.              + '<html>\n\n'
  69.              + '<head>\n'
  70.              + '    <meta http-equiv="Content-Type" content="text/html;Charset=UTF-8">\n'
  71.              + '    <meta http-equiv="Content-Style-Type" content="text/css">\n'
  72.              + '    <title>' + aTitle + '</title>\n'
  73.              + '    <link rel="stylesheet" type="text/css" href="chrome://scrapbook/skin/collection.css" media="screen,print">\n'
  74.              + '</head>\n\n'
  75.              + '<body>\n\n';
  76.     return HTML;
  77. }
  78.  
  79.  
  80. function SB_getHTMLBody(aSBitem)
  81. {
  82.     var aSource = ( aSBitem.source.length > 100 ) ? aSBitem.source.substring(0,100) + "..." : aSBitem.source;
  83.     var aFilePath = './data/' + aSBitem.id + '/index.html';
  84.     var HTML = '<cite>' + aSBitem.title + ' <a href="' + aSBitem.source + '" target="_top">' + aSource + '</a></cite>\n'
  85.              + '<iframe src="' + aFilePath + '" onload="this.setAttribute(\'style\', \'height:\' + (this.contentDocument.height+30));"></iframe>\n';
  86.     return HTML;
  87. }
  88.  
  89.  
  90. function SB_getHTMLFoot()
  91. {
  92.     var HTML = '</body>\n\n' + '</html>\n';
  93.     return HTML;
  94. }
  95.  
  96.  
  97.