3
nodePositionInRange : {
14
"background-color: #FFFF99; color: #000000; border: thin dashed #FFCC00;",
15
"border-bottom: medium solid #33FF33;",
16
"background-color: #CCFFFF; color: #000000; border: thin solid #0099FF;",
17
"background-color: #FFFF00; color: #000000;",
18
"border: medium double #993399;",
19
"background-color: #EE3311; color: #FFFFFF; font-weight: bold;",
20
"color: #FF0000; text-decoration: line-through;",
21
"border-bottom: thin solid #3366FF;",
25
updatePopup : function()
27
var idx = document.getElementById("ScrapBookHighlighter").getAttribute("color");
28
if (idx < 1 || idx > 4)
30
document.getElementById("ScrapBookHighlighter" + idx).setAttribute("checked", "true");
31
for ( idx = 4; idx > 0; idx-- )
33
var cssText = sbCommonUtils.copyUnicharPref("scrapbook.highlighter.style." + idx, this.PRESET_STYLES[idx]);
34
this.decorateElement(document.getElementById("ScrapBookHighlighter" + idx), cssText);
38
decorateElement : function(aElement, aCssText)
40
if (aElement.localName == "menuitem")
41
aElement = document.getAnonymousElementByAttribute(aElement, "class", "menu-iconic-text");
42
aElement.style.cssText = aCssText;
45
set : function(aWindow, aSelection, aNodeName, aAttributes)
47
for ( var r = 0; r < aSelection.rangeCount; ++r ) {
48
var range = aSelection.getRangeAt( r );
49
var doc = aWindow.document;
51
var startC = range.startContainer;
52
var endC = range.endContainer;
53
var sOffset = range.startOffset;
54
var eOffset = range.endOffset;
56
var sameNode = ( startC == endC );
58
if ( aNodeName == "a" && !sameNode )
60
alert("ScrapBook ERROR: Can't attach link across tags."); return;
63
if ( ! sameNode || ! this._isTextNode( startC ) ) {
66
= doc.createTreeWalker(
67
range.commonAncestorContainer,
73
nodeWalker.currentNode = startC;
75
for ( var txtNode = nodeWalker.nextNode();
76
txtNode && txtNode != endC;
77
txtNode = nodeWalker.nextNode()
80
nodeWalker.currentNode
81
= this._wrapTextNodeWithSpan(
88
this.nodePositionInRange.MIDDLE
94
if ( this._isTextNode( endC ) )
95
endC.splitText( eOffset );
98
this._wrapTextNodeWithSpan(
105
this.nodePositionInRange.END
109
if ( this._isTextNode( startC ) ) {
110
var secondHalf = startC.splitText( sOffset );
112
this._wrapTextNodeWithSpan(
119
this.nodePositionInRange.SINGLE
124
this._wrapTextNodeWithSpan(
131
this.nodePositionInRange.START
137
range.collapse( true );
143
_isTextNode : function( aNode )
145
return aNode.nodeType == aNode.TEXT_NODE;
148
_acceptNode : function( aNode )
150
if ( aNode.nodeType == aNode.TEXT_NODE
151
&& ! ( /[^\t\n\r ]/.test( aNode.nodeValue ) )
153
return NodeFilter.FILTER_REJECT;
155
return NodeFilter.FILTER_ACCEPT;
158
_createNode : function( aWindow, aNodeName, aAttributes, aNodePosInRange )
160
var newNode = aWindow.document.createElement( aNodeName );
161
for ( var attr in aAttributes )
163
newNode.setAttribute( attr, aAttributes[attr] );
168
_wrapTextNodeWithSpan : function( aDoc, aTextNode, aSpanNode )
170
var clonedTextNode = aTextNode.cloneNode( false );
171
var nodeParent = aTextNode.parentNode;
173
aSpanNode.appendChild( clonedTextNode );
174
nodeParent.replaceChild( aSpanNode, aTextNode );
176
return clonedTextNode;