PK 5content/scrapbook/PK 5/f f content/scrapbook/about.js const kVERSION = "1.2.0.8"; const kBUILD_TEXT = " (Build ID 20061215)"; const kUPDATE_URL = "http://amb.vis.ne.jp/mozilla/scrapbook/update.rdf"; var gAboutString; var gUpdateImage; var gUpdateLabel; function SB_initAbout() { gAboutString = document.getElementById("sbAboutString"); gUpdateImage = document.getElementById("sbUpdateImage"); gUpdateLabel = document.getElementById("sbUpdateLabel"); document.getElementById("sbAboutVersion").value = "Version " + kVERSION + kBUILD_TEXT; gUpdateImage.src = "chrome://scrapbook/skin/status_busy.gif"; try { gUpdateLabel.value = gAboutString.getFormattedString("updatingMessage", ["ScrapBook"]); } catch(ex) { gUpdateLabel.value = gAboutString.getString("updatingMsg"); } setTimeout(SB_setUpdateInfo, 500); } function SB_visit(aElem) { var href = aElem.getAttribute("href"); if ( href.indexOf("@") > 0 ) sbCommonUtils.loadURL("mailto:" + href, false); else sbCommonUtils.loadURL(href, true); window.close(); } function SB_secret() { window.opener.top.document.getElementById("sidebar-box").width = window.opener.top.outerWidth < 800 ? 190 : 200; setTimeout(function() { window.opener.top.document.getElementById("statusbar-display").label = "Transferring data from www.mozilla.org..."; }, 0); } function SB_setUpdateInfo() { var req = new XMLHttpRequest(); req.open("GET", kUPDATE_URL + "?ver=" + kVERSION); req.onload = function(aEvent) { try { var latestVer = req.responseXML.getElementsByTagNameNS("http://www.mozilla.org/2004/em-rdf#", "version")[0].textContent; const VER_COMP = Components.classes['@mozilla.org/xpcom/version-comparator;1'].getService(Components.interfaces.nsIVersionComparator); if ( VER_COMP.compare(latestVer, kVERSION) > 0 ) { try { gUpdateLabel.value = gAboutString.getFormattedString("updateAvailableMessage", [latestVer, kVERSION]); } catch(ex) { gUpdateLabel.value = gAboutString.getFormattedString("updateAvailableMsg", [latestVer]); } gUpdateLabel.className = "link"; gUpdateLabel.style.fontWeight = "bold"; gUpdateLabel.onclick = function(){ sbCommonUtils.loadURL("http://amb.vis.ne.jp/mozilla/scrapbook/"); window.close(); }; } else { try { gUpdateLabel.setAttribute("value", gAboutString.getFormattedString("updateNoUpdateMessage", ["ScrapBook"])); } catch(ex) { gUpdateLabel.setAttribute("value", gAboutString.getString("updateNoUpdateMsg")); } } } catch(ex) { SB_onUpdateError(); } gUpdateImage.src = ""; }; try { req.setRequestHeader("User-Agent", "ScrapBook/" + kVERSION); req.overrideMimeType("application/xml"); req.send(null); } catch(ex) { req.abort(); SB_onUpdateError(); } } function SB_onUpdateError() { gUpdateLabel.value = gAboutString.getString("updateErrorMessage"); gUpdateImage.src = ""; } PK {5]]content/scrapbook/about.xul %mainDTD; %aboutDTD; %mozaboutDTD; ]> PK 5̏HOOcontent/scrapbook/fulltext.js var gCacheStatus; var gCacheString; var gCacheFile; function SB_initFT(type) { gCacheStatus = document.getElementById("sbCacheStatus"); gCacheString = document.getElementById("sbCacheString"); gCacheFile = sbCommonUtils.getScrapBookDir().clone(); gCacheFile.append("cache.rdf"); sbDataSource.init(); sbCacheSource.init(); switch ( type ) { case 'SEARCH' : sbSearchResult.exec(); break; case 'CACHE' : setTimeout(function() { sbCacheService.build(); }, 0); break; } } var sbSearchResult = { get CURRENT_TREEITEM() { return this.treeItems[document.getElementById("sbTree").currentIndex]; }, index : 0, count : 0, hit : 0, QueryStrings : { q : "", re : "", cs : "", ref : "" }, RegExpModifier : "", RegExpInclude : [], RegExpExclude : [], includeWords : [], excludeWords : [], resEnum : null, treeItems : [], targetFolders : [], exec : function() { var qs = document.location.href.match(/result\.xul\?(.*)$/); qs = RegExp.$1; var qa = qs.split("&"); for ( var i = 0; i < qa.length; i++ ) { this.QueryStrings[qa[i].split("=")[0]] = qa[i].split("=")[1]; } this.QueryStrings['q'] = decodeURIComponent(this.QueryStrings['q']); if ( this.QueryStrings['ref'].indexOf("urn:scrapbook:item") == 0 ) { var refRes = sbCommonUtils.RDF.GetResource(this.QueryStrings['ref']); var elt = document.getElementById("sbResultHeader").firstChild.nextSibling; elt.value += sbDataSource.getProperty(refRes, "title"); elt.hidden = false; this.targetFolders = sbDataSource.flattenResources(refRes, 1, true); for ( var i = 0; i < this.targetFolders.length; i++ ) { this.targetFolders[i] = this.targetFolders[i].Value; } } this.RegExpModifier = ( this.QueryStrings['cs'] != "true" ) ? "im" : "m"; if ( this.QueryStrings['re'] != "true" ) { var query = this.QueryStrings['q'].replace(/( |\u3000)+/g, " "); var quotePos1; var quotePos2; var quotedStr; while ( (quotePos1 = query.indexOf('"')) != -1 ) { quotedStr = query.substring(quotePos1+1, query.length); quotePos2 = quotedStr.indexOf('"'); if ( quotePos2 == -1 ) break; quotedStr = quotedStr.substring(0, quotePos2); var replaceStr = '"' + quotedStr + '"'; if ( quotePos1 >= 1 && query.charAt(quotePos1-1) == '-' ) { this.excludeWords.push(quotedStr); this.RegExpExclude.push( new RegExp(quotedStr, this.RegExpModifier) ); replaceStr = "-" + replaceStr; } else if ( quotedStr.length > 0 ) { this.includeWords.push(quotedStr); this.RegExpInclude.push( new RegExp(this.escapeRegExpSpecialChars(quotedStr), this.RegExpModifier) ); } query = query.replace(replaceStr, ""); } query = query.replace(/ +/g, " ").split(' '); for ( var i=0; i 0 ) { this.includeWords.push(word); this.RegExpInclude.push( new RegExp(this.escapeRegExpSpecialChars(word), this.RegExpModifier) ); } } if ( this.RegExpInclude.length == 0 ) return; } this.resEnum = sbCacheSource.container.GetElements(); this.count = sbCacheSource.container.GetCount(); setTimeout(function(){ sbSearchResult.next(); }, 10); }, next : function() { if ( this.resEnum.hasMoreElements() ) { if ( ++this.index % 100 == 0 ) { setTimeout(function(){ sbSearchResult.process(); }, 0); var msg = document.getElementById("sbMainString").getString("SCANNING") + "... (" + Math.round(this.index / this.count * 100) + " %)"; document.title = document.getElementById("sbResultHeader").firstChild.value = msg; } else { this.process(); } } else this.finalize(); }, process : function() { var res = this.resEnum.getNext().QueryInterface(Components.interfaces.nsIRDFResource); if ( res.Value == "urn:scrapbook:cache" ) return this.next(); var folder = sbCacheSource.getProperty(res, "folder"); if ( this.targetFolders.length > 0 ) { if ( folder && folder.indexOf("urn:scrapbook:item") != 0 ) { try { var target = sbCommonUtils.RDF.GetLiteral(folder); var prop = sbDataSource.data.ArcLabelsIn(target).getNext().QueryInterface(Components.interfaces.nsIRDFResource); var source = sbDataSource.data.GetSource(prop, target, true); folder = source.Value; } catch(ex) { } } if ( this.targetFolders.indexOf(folder) < 0 ) return this.next(); } var content = sbCacheSource.getProperty(res, "content"); var resURI = res.Value.split("#")[0]; var name = res.Value.split("#")[1] || "index"; res = sbCommonUtils.RDF.GetResource(resURI); if ( !sbDataSource.exists(res) ) return this.next(); var type = sbDataSource.getProperty(res, "type"); var title = sbDataSource.getProperty(res, "title"); var comment = sbDataSource.getProperty(res, "comment"); if ( this.QueryStrings['re'] == "true" ) { var re = new RegExp(this.QueryStrings['q'], this.RegExpModifier); var isMatchT = title.match(re); var isMatchM = comment.match(re); var isMatchC = content.match(re); } else { var willContinue = false; var tcc = [title, comment, content].join("\t"); for ( var x = 0; x < this.RegExpInclude.length; x++ ) { if ( !tcc.match(this.RegExpInclude[x]) ) { willContinue = true; break; } } if ( willContinue ) return this.next(); for ( x = 0; x < this.RegExpExclude.length; x++ ) { if ( tcc.match(this.RegExpExclude[x]) ) { willContinue = true; break; } } if ( willContinue ) return this.next(); var isMatchT = isMatchM = isMatchC = true; } if ( isMatchT || isMatchM || isMatchC ) { var icon = sbDataSource.getProperty(res, "icon"); if ( !icon ) icon = sbCommonUtils.getDefaultIcon(type); if ( folder.indexOf("urn:scrapbook:") == 0 ) folder = sbDataSource.getProperty(sbCommonUtils.RDF.GetResource(folder), "title"); sbSearchResult.treeItems.push([ title, this.extractRightContext(content), this.extractRightContext(comment).replace(/ __BR__ /g, " "), folder, name, resURI.substring(18), type, icon, ]); this.hit++; } return this.next(); }, finalize : function() { var colIDs = [ "sbTreeColTitle", "sbTreeColContent", "sbTreeColComment", "sbTreeColFolder", "sbTreeColName", ]; var treeView = new sbCustomTreeView(colIDs, this.treeItems); treeView.getImageSrc = function(row, col) { if ( col.index == 0 ) return this._items[row][7]; }; treeView.getCellProperties = function(row, col, properties) { if ( col.index != 0 ) return; properties.AppendElement(ATOM_SERVICE.getAtom(this._items[row][6])); }; document.getElementById("sbTree").view = treeView; var headerLabel1 = gCacheString.getFormattedString("RESULTS_FOUND", [this.hit] ); if ( this.QueryStrings['re'] == "true" ) { var headerLabel2 = gCacheString.getFormattedString("MATCHING", [ this.localizedQuotation(this.QueryStrings['q']) ]); } else { var includeQuoted = []; for ( var x = 0; x < this.includeWords.length; x++ ) { includeQuoted.push(this.localizedQuotation(this.includeWords[x])); } if ( includeQuoted.length > 0 ) includeQuoted = gCacheString.getFormattedString("INCLUDING", [includeQuoted.join(" ")]); var excludeQuoted = []; for ( var x = 0; x < this.excludeWords.length; x++ ) { excludeQuoted.push(this.localizedQuotation(this.excludeWords[x])); } if ( excludeQuoted.length > 0 ) excludeQuoted = gCacheString.getFormattedString("EXCLUDING", [excludeQuoted.join(" ")]); var headerLabel2 = includeQuoted + " " + excludeQuoted; } document.title = document.getElementById("sbResultHeader").firstChild.value = headerLabel1 + " : " + headerLabel2; }, extractRightContext : function(aString) { aString = aString.replace(/\r|\n|\t/g, " "); pattern = ( this.QueryStrings['re'] == "true" ) ? this.QueryStrings['q'] : this.includeWords[0]; var re = new RegExp("(" + pattern + ".*)", this.RegExpModifier); var ret = aString.match(re) ? RegExp.$1 : aString; return ( ret.length > 100 ) ? ret.substring(0, 100) : ret; }, escapeRegExpSpecialChars : function(aString) { return aString.replace(/([\*\+\?\.\^\/\$\\\|\[\]\{\}\(\)])/g, "\\$1"); }, localizedQuotation : function(aString) { return gCacheString.getFormattedString("QUOTATION", [aString]); }, forward : function(key) { if ( !this.CURRENT_TREEITEM ) return; var id = this.CURRENT_TREEITEM[5]; var url = this.CURRENT_TREEITEM[6] == "note" ? "chrome://scrapbook/content/note.xul?id=" + id : sbCommonUtils.getBaseHref(sbDataSource.data.URI) + "data/" + id + "/" + this.CURRENT_TREEITEM[4] + ".html"; switch ( key ) { case "O" : sbCommonUtils.loadURL(url, false); break; case "T" : sbCommonUtils.loadURL(url, true); break; case "P" : window.openDialog("chrome://scrapbook/content/property.xul", "", "modal,centerscreen,chrome" ,id); break; case "L" : var res = sbCommonUtils.RDF.GetResource("urn:scrapbook:item" + sbSearchResult.CURRENT_TREEITEM[5]); sbCommonUtils.WINDOW.getMostRecentWindow("navigator:browser").sbBrowserOverlay.locate(res); break; default : document.getElementById("sbBrowser").loadURI(url); break; } }, onDocumentLoad : function(aEvent) { aEvent.stopPropagation(); aEvent.preventDefault(); if ( this.QueryStrings["re"] == "true" ) this.includeWords = [this.QueryStrings['q']]; for ( var i = 0; i < this.includeWords.length; i++ ) { var colors = ["#FFFF33","#66FFFF","#90FF90","#FF9999","#FF99FF"]; sbKeywordHighlighter.exec(colors[i % colors.length], this.includeWords[i]); } }, }; function SB_exitResult() { window.location.href = document.getElementById("sbBrowser").currentURI.spec; } var sbCacheService = { index : 0, dataDir : null, resList : [], folders : [], uriHash : {}, _curResURI : "", build : function() { document.title = gCacheString.getString("BUILD_CACHE") + " - ScrapBook"; gCacheStatus.firstChild.value = gCacheString.getString("BUILD_CACHE_INIT"); sbCacheSource.refreshEntries(); this.dataDir = sbCommonUtils.getScrapBookDir().clone(); this.dataDir.append("data"); var contResList = sbDataSource.flattenResources(sbCommonUtils.RDF.GetResource("urn:scrapbook:root"), 1, true); for ( var i = 0; i < contResList.length; i++ ) { var resList = sbDataSource.flattenResources(contResList[i], 2, false); for ( var j = 0; j < resList.length; j++ ) { var type = sbDataSource.getProperty(resList[j], "type"); if ( type == "image" || type == "file" || type == "bookmark" ) continue; this.resList.push(resList[j]); this.folders.push(contResList[i].Value); } } this.processAsync(); }, processAsync : function() { var res = this.resList[this.index]; var id = sbDataSource.getProperty(res, "id"); var dir = this.dataDir.clone(); dir.append(id); gCacheStatus.firstChild.value = gCacheString.getString("BUILD_CACHE_UPDATE") + " " + sbDataSource.getProperty(res, "title"); gCacheStatus.lastChild.value = Math.round((this.index + 1) / this.resList.length * 100); this.inspectFile(dir, "index"); if ( sbDataSource.getProperty(res, "type") == "site" ) { var url2name = dir.clone(); url2name.append("sb-url2name.txt"); if ( url2name.exists() ) { url2name = sbCommonUtils.readFile(url2name).split("\n"); for ( var i = 0; i < url2name.length; i++ ) { if ( i > 256 ) break; var line = url2name[i].split("\t"); if ( !line[1] || line[1] == "index" ) continue; this.inspectFile(dir, line[1]); } } } if ( this._curResURI != this.folders[this.index] ) document.title = sbDataSource.getProperty(sbCommonUtils.RDF.GetResource(this.folders[this.index]), "title") || gCacheString.getString("BUILD_CACHE"); if ( ++this.index < this.resList.length ) setTimeout(function(){ sbCacheService.processAsync(); }, 0); else setTimeout(function(){ sbCacheService.finalize(); }, 0); }, inspectFile : function(aDir, aName) { var resource = sbCommonUtils.RDF.GetResource(this.resList[this.index].Value + "#" + aName); var contents = []; var num = 0; do { var file; var file1 = aDir.clone(); var file2 = aDir.clone(); file1.append(aName + ((num > 0) ? num : "") + ".html"); file2.append(aName + "_" + ((num > 0) ? num : "") + ".html"); if ( file1.exists() ) file = file1; else if ( file2.exists() ) file = file2; else break; if ( num == 0 && sbCacheSource.exists(resource) ) { if ( gCacheFile.lastModifiedTime > file.lastModifiedTime ) { this.uriHash[resource.Value] = true; sbCacheSource.updateEntry(resource, "folder", this.folders[this.index]); return; } } var content = sbCommonUtils.readFile(file); content = sbCommonUtils.convertToUnicode(content, sbDataSource.getProperty(this.resList[this.index], "chars")); contents.push(this.convertHTML2Text(content)); } while ( ++num < 10 ); contents = contents.join("\t").replace(/[\x00-\x1F\x7F]/g, " ").replace(/\s+/g, " "); if ( sbCacheSource.exists(resource) ) { sbCacheSource.updateEntry(resource, "folder", this.folders[this.index]); sbCacheSource.updateEntry(resource, "content", contents); } else { sbCacheSource.addEntry(resource, contents); } this.uriHash[resource.Value] = true; }, finalize : function() { document.title = gCacheString.getString("BUILD_CACHE_UPDATE"); for ( var uri in this.uriHash ) { if ( !this.uriHash[uri] && uri != "urn:scrapbook:cache" ) { gCacheStatus.firstChild.value = gCacheString.getString("BUILD_CACHE_REMOVE") + " " + uri; sbCacheSource.removeEntry(sbCommonUtils.RDF.GetResource(uri)); } } gCacheStatus.firstChild.value = gCacheString.getString("BUILD_CACHE_UPDATE") + "cache.rdf"; sbCacheSource.flush(); try { if ( window.arguments[0] ) sbCommonUtils.loadURL(window.arguments[0], true); } catch(ex) { } window.close(); }, convertHTML2Text : function(aStr) { var FORMAT_CONVERTER = Components.classes['@mozilla.org/widget/htmlformatconverter;1'].createInstance(Components.interfaces.nsIFormatConverter); var fromStr = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString); var toStr = { value: null }; fromStr.data = aStr; try { FORMAT_CONVERTER.convert("text/html", fromStr, fromStr.toString().length, "text/unicode", toStr, {}); toStr = toStr.value.QueryInterface(Components.interfaces.nsISupportsString); return toStr.toString(); } catch(ex) { return aStr; } }, }; var sbCacheSource = { dataSource : null, container : null, init : function() { if ( !gCacheFile.exists() ) gCacheFile.create(gCacheFile.NORMAL_FILE_TYPE, 0666); var filePath = sbCommonUtils.IO.newFileURI(gCacheFile).spec; this.dataSource = sbCommonUtils.RDF.GetDataSourceBlocking(filePath); this.container = Components.classes['@mozilla.org/rdf/container;1'].createInstance(Components.interfaces.nsIRDFContainer); try { this.container.Init(this.dataSource, sbCommonUtils.RDF.GetResource("urn:scrapbook:cache")); } catch(ex) { this.container = sbCommonUtils.RDFCU.MakeSeq(this.dataSource, sbCommonUtils.RDF.GetResource("urn:scrapbook:cache")); } }, refreshEntries : function() { var resEnum = this.dataSource.GetAllResources(); while ( resEnum.hasMoreElements() ) { var res = resEnum.getNext().QueryInterface(Components.interfaces.nsIRDFResource); if ( res.Value.indexOf("#") == -1 && res.Value != "urn:scrapbook:cache" ) this.removeEntry(res); else sbCacheService.uriHash[res.Value] = false; } this.container = sbCommonUtils.RDFCU.MakeSeq(this.dataSource, sbCommonUtils.RDF.GetResource("urn:scrapbook:cache")); }, addEntry : function(aRes, aContent) { aContent = sbDataSource.sanitize(aContent); this.container.AppendElement(aRes); this.dataSource.Assert(aRes, sbCommonUtils.RDF.GetResource(NS_SCRAPBOOK + "folder"), sbCommonUtils.RDF.GetLiteral(sbCacheService.folders[sbCacheService.index]), true); this.dataSource.Assert(aRes, sbCommonUtils.RDF.GetResource(NS_SCRAPBOOK + "content"), sbCommonUtils.RDF.GetLiteral(aContent), true); }, updateEntry : function(aRes, aProp, newVal) { newVal = sbDataSource.sanitize(newVal); aProp = sbCommonUtils.RDF.GetResource(NS_SCRAPBOOK + aProp); var oldVal = this.dataSource.GetTarget(aRes, aProp, true).QueryInterface(Components.interfaces.nsIRDFLiteral); newVal = sbCommonUtils.RDF.GetLiteral(newVal); this.dataSource.Change(aRes, aProp, oldVal, newVal); }, removeEntry : function(aRes) { this.container.RemoveElement(aRes, true); var names = this.dataSource.ArcLabelsOut(aRes); while ( names.hasMoreElements() ) { var name = names.getNext().QueryInterface(Components.interfaces.nsIRDFResource); var value = this.dataSource.GetTarget(aRes, name, true); this.dataSource.Unassert(aRes, name, value); } }, getProperty : function(aRes, aProp) { try { var retVal = this.dataSource.GetTarget(aRes, sbCommonUtils.RDF.GetResource(NS_SCRAPBOOK + aProp), true); return retVal.QueryInterface(Components.interfaces.nsIRDFLiteral).Value; } catch(ex) { return ""; } }, exists : function(aRes) { return (this.dataSource.ArcLabelsOut(aRes).hasMoreElements() && this.container.IndexOf(aRes) != -1); }, flush : function() { this.dataSource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush(); } }; var sbKeywordHighlighter = { word : "", frameList : [], searchRange : null, startPoint : null, endPoint : null, flattenFrames : function(aWindow) { var ret = [aWindow]; for ( var i = 0; i < aWindow.frames.length; i++ ) { ret = ret.concat(this.flattenFrames(aWindow.frames[i])); } return ret; }, exec : function(color, word) { this.word = word; var rootWin = document.getElementById("sbBrowser").contentWindow; this.frameList = this.flattenFrames(rootWin); for ( var i = 0; i < this.frameList.length; i++ ) { var doc = this.frameList[i].document; var body = doc.body; if ( !body ) return; var count = body.childNodes.length; this.searchRange = doc.createRange(); this.startPoint = doc.createRange(); this.endPoint = doc.createRange(); var baseNode = doc.createElement("span"); baseNode.setAttribute("style", "background-color: " + color + ";"); baseNode.setAttribute("id", "__firefox-findbar-search-id"); this.searchRange.setStart(body, 0); this.searchRange.setEnd(body, count); this.startPoint.setStart(body, 0); this.startPoint.setEnd(body, 0); this.endPoint.setStart(body, count); this.endPoint.setEnd(body, count); var retRange = null; var finder = Components.classes['@mozilla.org/embedcomp/rangefind;1'].createInstance().QueryInterface(Components.interfaces.nsIFind); while( (retRange = finder.Find(this.word, this.searchRange, this.startPoint, this.endPoint)) ) { var nodeSurround = baseNode.cloneNode(true); var node = this.highlightNode(retRange, nodeSurround); this.startPoint = node.ownerDocument.createRange(); this.startPoint.setStart(node, node.childNodes.length); this.startPoint.setEnd(node, node.childNodes.length); } } }, highlightNode : function(range, node) { var startContainer = range.startContainer; var startOffset = range.startOffset; var endOffset = range.endOffset; var docfrag = range.extractContents(); var before = startContainer.splitText(startOffset); var parent = before.parentNode; node.appendChild(docfrag); parent.insertBefore(node, before); return node; } }; PK m4z content/scrapbook/highlighter.js/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * * The Initial Developer of the Original Code is Joe Antao. * Portions created by the Initial Developer are Copyright (C) 2005 * the Initial Developer. All Rights Reserved. * * Contributor(s): Joe Antao * Gomita * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ var sbHighlighter = { /** * The position of a node in a range is necessary for creating a CSS * styled box around the range. */ nodePositionInRange : { SINGLE : 0, START : 1, MIDDLE : 2, END : 3 }, /** * Array of the default styles. */ get PRESET_STYLES() { return [ // [0] no styles "", // [1] kahki background with gold dashed border "background-color: #FFFF99; color: #000000; border: thin dashed #FFCC00;", // [2] limegreen underline "border-bottom: medium solid #33FF33;", // [3] skyblue border and background "background-color: #CCFFFF; color: #000000; border: 1px solid #0099FF;", // [4] yellow background "background-color: #FFFF00; color: #000000;", // [5] double violet border "border: medium double #993399;", // [6] white bold text with red background "background-color: #EE3311; color: #FFFFFF; font-weight: bold;", // [7] red text with strike-through "color: #FF0000; text-decoration: line-through; ", // [8] blue underline "border-bottom: 1px solid #3366FF;", ]; }, updatePopup : function() { var idx = document.getElementById("ScrapBookHighlighter").getAttribute("color") || 4; document.getElementById("ScrapBookHighlighter" + idx).setAttribute("checked", true); // decorate menuitems by cssTexts for ( idx = 4; idx > 0; idx-- ) { var cssText = nsPreferences.copyUnicharPref("scrapbook.highlighter.style." + idx, this.PRESET_STYLES[idx]); this.decorateElement(document.getElementById("ScrapBookHighlighter" + idx), cssText); } }, decorateElement : function(aElement, aCssText) { aElement.setAttribute("style", aCssText); aElement.setAttribute("tooltiptext", aCssText); }, set : function(aWindow, aSelection, aNodeName, aAttributes) { // 'for' loop allows for multiple ranges in selection for ( var r = 0; r < aSelection.rangeCount; ++r ) { var range = aSelection.getRangeAt( r ); var doc = aWindow.document; var startC = range.startContainer; var endC = range.endContainer; var sOffset = range.startOffset; var eOffset = range.endOffset; var sameNode = ( startC == endC ); if ( aNodeName == "a" && !sameNode ) { alert("ScrapBook ERROR: Can't attach link across tags."); return; } /* Surround every non-empty text node between startC and endC, but not including startC and endC, which we handle after this */ if ( ! sameNode || ! this._isTextNode( startC ) ) { var nodeWalker = doc.createTreeWalker( range.commonAncestorContainer, NodeFilter.SHOW_TEXT, this._acceptNode, false ); /* createTreeWalker returns rooted at range.commonAncestorContainer, so we move it to the range's start container. */ nodeWalker.currentNode = startC; /* Loop through the nodes between startC and endC, non-inclusive, surrounding the text nodes with new span nodes */ for ( var txtNode = nodeWalker.nextNode(); txtNode && txtNode != endC; txtNode = nodeWalker.nextNode() ) { nodeWalker.currentNode = this._wrapTextNodeWithSpan( doc, txtNode, this._createNode( aWindow, aNodeName, aAttributes, this.nodePositionInRange.MIDDLE ) ); } } /* If the endContainer (endC) is a text node, we split it, with the text node endC containing the first half, which includes all of the selected text, as well as any text that appears before the selection. (This can happen if endC is the same as startC). We can safely ignore the returned text node, since it does not contain any selected portion of the text. */ if ( this._isTextNode( endC ) ) endC.splitText( eOffset ); /* If endC != startC (i.e. not the same node), then endC will consist only of selected text (due to the split done above) and we can safely surround the entire node. If endC == startC then it's possible that there is text that is not part of the selection present in the node. */ if ( ! sameNode) this._wrapTextNodeWithSpan( doc, endC, this._createNode( aWindow, aNodeName, aAttributes, this.nodePositionInRange.END ) ); /* If startC == endC, then we have already removed any text trailing the selection, and only need to remove any text preceding the selection before surrounding it with our span. If startC != endC, then we need to split off any text preceding the selection. Both cases require the same action, but we need to differentiate between the two for CSS style reasons. ( e.g., when styling a box border around text, we need to know where the box starts, the middle, and ends ) */ if ( this._isTextNode( startC ) ) { var secondHalf = startC.splitText( sOffset ); if ( sameNode ) { this._wrapTextNodeWithSpan( doc, secondHalf, this._createNode( aWindow, aNodeName, aAttributes, this.nodePositionInRange.SINGLE ) ); } else { this._wrapTextNodeWithSpan( doc, secondHalf, this._createNode( aWindow, aNodeName, aAttributes, this.nodePositionInRange.START ) ); } } // collapse range to its end point. range.collapse( true ); } }, _isTextNode : function( aNode ) { return aNode.nodeType == aNode.TEXT_NODE; }, _acceptNode : function( aNode ) { /* If aNode is a TEXT_NODE and it contains only whitespace characters, we reject it */ if ( aNode.nodeType == aNode.TEXT_NODE && ! ( /[^\t\n\r ]/.test( aNode.nodeValue ) ) ) return NodeFilter.FILTER_REJECT; return NodeFilter.FILTER_ACCEPT; }, _createNode : function( aWindow, aNodeName, aAttributes, aNodePosInRange ) { var newNode = aWindow.document.createElement( aNodeName ); for ( var attr in aAttributes ) { newNode.setAttribute( attr, aAttributes[attr] ); } return newNode; }, _wrapTextNodeWithSpan : function( aDoc, aTextNode, aSpanNode ) { var clonedTextNode = aTextNode.cloneNode( false ); var nodeParent = aTextNode.parentNode; aSpanNode.appendChild( clonedTextNode ); nodeParent.replaceChild( aSpanNode, aTextNode ); return clonedTextNode; }, }; PK 5scontent/scrapbook/hlCustom.js var hlCustomizer = { get PREVIEW() { return document.getElementById("hlCustomPreview"); }, index : 4, presetIndex : 0, init : function() { document.documentElement.buttons = "accept,cancel,extra2"; if ( !window.arguments || window.arguments[0] < 1 || window.arguments[0] > 4 ) { window.close(); return; } this.index = window.arguments[0]; var cssText = nsPreferences.copyUnicharPref("scrapbook.highlighter.style." + this.index, sbHighlighter.PRESET_STYLES[this.index]); this.parseFromString(cssText); }, done : function() { nsPreferences.setUnicharPref("scrapbook.highlighter.style." + this.index, this.PREVIEW.style.cssText); window.opener.hlPrefService.shouldUpdate = true; }, update : function() { this.PREVIEW.setAttribute("style", this.parseToString()); }, broadcast : function() { var ret = [ document.getElementById("hlBackgroundEnabled").checked, document.getElementById("hlTextEnabled").checked, document.getElementById("hlBorderEnabled").checked ]; document.getElementById("hlBroadcast0").setAttribute("disabled", !ret[0]); document.getElementById("hlBroadcast1").setAttribute("disabled", !ret[1]); document.getElementById("hlBroadcast2").setAttribute("disabled", !ret[2]); return ret; }, parseFromString : function(cssText) { this.PREVIEW.setAttribute("style", cssText); document.getElementById("hlTextBold").checked = this.PREVIEW.style.fontWeight == "bold"; document.getElementById("hlTextItalic").checked = this.PREVIEW.style.fontStyle == "italic"; document.getElementById("hlTextStrike").checked = this.PREVIEW.style.textDecoration == "line-through"; document.getElementById("hlBackgroundEnabled").checked = this.PREVIEW.style.backgroundColor; document.getElementById("hlTextEnabled").checked = this.PREVIEW.style.color; document.getElementById("hlBorderEnabled").checked = this.PREVIEW.style.borderBottom; var bcList = this.broadcast(); if ( bcList[0] ) document.getElementById("hlBackgroundColor").color = this.PREVIEW.style.backgroundColor; if ( bcList[1] ) document.getElementById("hlTextColor").color = this.PREVIEW.style.color; if ( bcList[2] ) { document.getElementById("hlBorderColor").color = this.PREVIEW.style.borderBottomColor; document.getElementById("hlBorderType").selectedIndex = this.PREVIEW.style.borderTop ? 0 : 1; var elem = document.getElementsByAttribute("value", this.PREVIEW.style.borderBottomStyle); document.getElementById("hlBorderStyle").selectedIndex = elem.length > 0 ? elem[0].getAttribute("index") : 0; elem = document.getElementsByAttribute("value", this.PREVIEW.style.borderBottomWidth); document.getElementById("hlBorderWidth").selectedIndex = elem.length > 0 ? elem[0].getAttribute("index") : 0; } }, parseToString : function() { var bcList = this.broadcast(); var cssRules = []; if ( document.getElementById("hlTextBold").checked ) cssRules.push("font-weight:bold"); if ( document.getElementById("hlTextItalic").checked ) cssRules.push("font-style:italic"); if ( document.getElementById("hlTextStrike").checked ) cssRules.push("text-decoration:line-through"); if ( bcList[0] ) cssRules.push("background-color:" + (document.getElementById("hlBackgroundColor").color || "none")); if ( bcList[1] ) cssRules.push("color:" + (document.getElementById("hlTextColor").color || "none")); if ( bcList[2] ) { var borderType = document.getElementById("hlBorderType").selectedItem.value == "box" ? "border" : "border-bottom"; var borderStyle = document.getElementById("hlBorderStyle").selectedItem.value; var borderWidth = document.getElementById("hlBorderWidth").selectedItem.value; var borderColor = document.getElementById("hlBorderColor").color || "none"; cssRules.push(borderType + ":" + [borderWidth,borderStyle,borderColor].join(" ")); } return cssRules.join(";"); }, rotatePreset : function() { if ( ++this.presetIndex > 8 ) this.presetIndex = 0; var presetButton = document.getElementById("hlCustomizeDialog").getButton("extra2"); presetButton.label = presetButton.label.replace(/\s\d\/8$/, " " + this.presetIndex + "/8"); this.parseFromString(sbHighlighter.PRESET_STYLES[this.presetIndex]); }, }; PK ah4gcontent/scrapbook/hlCustom.xul %editorDTD; %settingDTD; %hlCustomDTD; ]> \n' + '\n\n' + '\n\n' + '\n\n'; return HTML; }, getHTMLBody : function(aRes) { var id = sbDataSource.getProperty(aRes, "id"); var title = sbDataSource.getProperty(aRes, "title"); var icon = sbDataSource.getProperty(aRes, "icon"); var type = sbDataSource.getProperty(aRes, "type"); if ( icon.match(/(\/data\/\d{14}\/.*$)/) ) icon = ".." + RegExp.$1; if ( !icon ) icon = sbCommonUtils.getFileName( sbCommonUtils.getDefaultIcon(type) ); title = title.replace(//g, ">"); if ( type == "folder" ) { return '' + title + '\n'; } else { var href = type == "bookmark" ? sbDataSource.getProperty(aRes, "source") : "../data/" + id + "/index.html"; var target = this.optionFrame ? ' target="main"' : ""; return '' + title + ''; } }, getHTMLFoot : function() { var HTML = "\n\n\n"; return HTML; }, getHTMLFrame : function() { var HTML = '\n\n' + '\n\n' + '\n' + ' \n' + ' ' + document.title + '\n' + '\n\n' + '\n' + ' \n' + ' \n' + '\n\n' + '\n'; return HTML; }, }; PK Q 5f?>>content/scrapbook/output.xul %mainDTD; %outputDTD; ]>