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

  1. /**************************************************
  2. // note.js
  3. // Implementation file for note.xul
  4. // 
  5. // Description: 
  6. // Author: Gomita
  7. // Contributors: 
  8. // 
  9. // Version: 
  10. // License: see LICENSE.txt
  11. **************************************************/
  12.  
  13.  
  14.  
  15. const NS_XHTML = "http://www.w3.org/1999/xhtml";
  16.  
  17. var gID;
  18. var gRes;
  19.  
  20.  
  21.  
  22. function SN_init()
  23. {
  24.     gID = document.location.href.match(/\?id\=(\d{14})$/);
  25.     gID = RegExp.$1;
  26.     SBnote.sidebar = false;
  27.     SBnote.init();
  28.     SBRDF.init();
  29.     gRes = SBservice.RDF.GetResource("urn:scrapbook:item" + gID);
  30.     SBnote.edit(gRes);
  31.     SNtemplate.init();
  32.     SNfontSize.init();
  33.     if ( nsPreferences.getBoolPref("scrapbook.note.preview", false) ) SNpreview.show();
  34. }
  35.  
  36.  
  37. function SN_finalize(exit)
  38. {
  39.     SBnote.save(window);
  40.     nsPreferences.setBoolPref("scrapbook.note.preview", SNpreview.state);
  41.     nsPreferences.setIntPref("scrapbook.note.fontsize", SNfontSize.pixel);
  42.     if ( exit) window.location.href = "about:blank";
  43. }
  44.  
  45.  
  46. var SNpreview = {
  47.  
  48.     state : false,
  49.  
  50.     show : function()
  51.     {
  52.         SBnote.save();
  53.         SNtemplate.save();
  54.         var mySrc = SNtemplate.getTemplate();
  55.         if ( SBnote.editXUL.value.match(/\n/) ) {
  56.             var myTitle   = RegExp.leftContext;
  57.             var myContent = RegExp.rightContext;
  58.         } else {
  59.             var myTitle   = SBnote.editXUL.value;
  60.             var myContent = "";
  61.         }
  62.         myTitle = myTitle.replace(/</g, "<");
  63.         myTitle = myTitle.replace(/>/g, ">");
  64.         myTitle = myTitle.replace(/\"/g, """);
  65.         if ( document.getElementById("ScrapNoteToolbarA").getAttribute("checked") ) myContent = myContent.replace(/([^>])$/mg, "$1<br>");
  66.         mySrc = mySrc.replace(/<%NOTE_TITLE%>/g,   myTitle);
  67.         mySrc = mySrc.replace(/<%NOTE_CONTENT%>/g, myContent);
  68.         var myHTML = SBcommon.getScrapBookDir().clone();
  69.         myHTML.append("note.html");
  70.         SBcommon.writeFile(myHTML, mySrc, "UTF-8");
  71.         document.getElementById("ScrapNoteSplitter").hidden = false;
  72.         document.getElementById("ScrapNoteBrowser").hidden  = false;
  73.         document.getElementById("ScrapNoteHeader").lastChild.hidden = false;
  74.         document.getElementById("ScrapNoteBrowser").removeAttribute("src");
  75.         document.getElementById("ScrapNoteBrowser").setAttribute("src", SBcommon.convertFilePathToURL(myHTML.path));
  76.         this.state = true;
  77.     },
  78.  
  79.     exit : function()
  80.     {
  81.         document.getElementById("ScrapNoteSplitter").hidden = true;
  82.         document.getElementById("ScrapNoteBrowser").hidden  = true;
  83.         document.getElementById("ScrapNoteHeader").lastChild.hidden = true;
  84.         this.state = false;
  85.     },
  86.  
  87. };
  88.  
  89.  
  90. var SNtemplate = {
  91.  
  92.     editXUL  : null,
  93.     enable   : false,
  94.     toSave   : false,
  95.     tmplFile : null,
  96.  
  97.     dropListener : function() { SNtemplate.change(true); },
  98.  
  99.     init : function()
  100.     {
  101.         this.editXUL = document.getElementById("ScrapNoteTemplateTextbox");
  102.         this.editXUL.removeEventListener("dragdrop", this.dropListener, true);
  103.         this.editXUL.addEventListener("dragdrop",    this.dropListener, true);
  104.         this.tmplFile = SBcommon.getScrapBookDir().clone();
  105.         this.tmplFile.append("note_template.html");
  106.         if ( !this.tmplFile.exists() ) SBcommon.saveTemplateFile("chrome://scrapbook/content/template.html", this.tmplFile);
  107.     },
  108.  
  109.     show : function(willShow)
  110.     {
  111.         document.getElementById("ScrapNoteTemplate").hidden = !willShow;
  112.         document.getElementById("ScrapNoteEditor").hidden   = willShow;
  113.         this.enable = willShow;
  114.     },
  115.  
  116.     getTemplate : function()
  117.     {
  118.         var template = SBcommon.readFile(this.tmplFile);
  119.         template = SBcommon.convertStringToUTF8(template);
  120.         return template;
  121.     },
  122.  
  123.     load : function()
  124.     {
  125.         this.save();
  126.         this.show(true);
  127.         this.editXUL.value = this.getTemplate();
  128.         this.editXUL.focus();
  129.     },
  130.  
  131.     save : function()
  132.     {
  133.         if ( !this.toSave ) return;
  134.         var myCSS = SBcommon.getScrapBookDir().clone();
  135.         myCSS.append("note_template.html");
  136.         SBcommon.writeFile(myCSS, this.editXUL.value, "UTF-8");
  137.         this.change(false);
  138.     },
  139.  
  140.     exit : function(checkOff)
  141.     {
  142.         this.save();
  143.         this.show(false);
  144.         if ( checkOff ) document.getElementById("ScrapNoteToolbarT").setAttribute("checked", false);
  145.     },
  146.  
  147.     change : function(aBool)
  148.     {
  149.         this.toSave = aBool;
  150.         document.getElementById("ScrapNoteToolbarS").disabled = !aBool;
  151.     },
  152.  
  153. };
  154.  
  155.  
  156. var SNfontSize = {
  157.  
  158.     pixel : 16,
  159.  
  160.     init : function()
  161.     {
  162.         this.pixel = nsPreferences.getIntPref("scrapbook.note.fontsize", 16);
  163.         this.change(this.pixel);
  164.         document.getElementById("ScrapNoteToolbarF" + this.pixel).setAttribute("checked", true)
  165.     },
  166.  
  167.     change : function(aPixel)
  168.     {
  169.         this.pixel = aPixel;
  170.         var newStyle = "font-size: " + aPixel + "px; font-family: monospace;";
  171.         SBnote.editXUL.setAttribute("style", newStyle);
  172.         SNtemplate.editXUL.setAttribute("style", newStyle);
  173.     },
  174.  
  175. };
  176.  
  177.  
  178.