/[suikacvs]/test/suikawebwww/style/text/wrap.xbl
Suika

Contents of /test/suikawebwww/style/text/wrap.xbl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Tue Dec 13 13:26:11 2005 UTC (20 years, 8 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +11 -1 lines
Spec style split

1 wakaba 1.2 <!DOCTYPE bindings [
2     <!ENTITY NS_WRAP "'http://suika.fam.cx/www/style/text/wrap#'">
3     ]>
4 wakaba 1.1 <bindings xmlns="http://www.mozilla.org/xbl">
5     <binding id="wbr-code">
6     <implementation>
7     <constructor type="application/x-javascript" xml:space="preserve">
8 wakaba 1.2 var targetNode = this;
9     window.addEventListener ('load', function () {
10     if (!targetNode.wrapWbrAdded ()) {
11     targetNode.setAttributeNS (&NS_WRAP;, 'wrap:wbrAdded', '1');
12     var resolver = document.createNSResolver (targetNode);
13 wakaba 1.1 var nodes = document.evaluate (
14 wakaba 1.2 'descendant::*/child::text () | child::text ()',
15     targetNode, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null
16 wakaba 1.1 );
17 wakaba 1.2 var pattern_before = targetNode.WrapPatternBefore;
18     var pattern_after = targetNode.WrapPatternAfter;
19 wakaba 1.1 var range = document.createRange ();
20 wakaba 1.4 var wbr = document.createElementNS
21     ('http://www.w3.org/1999/xhtml', "wbr");
22 wakaba 1.1 var lastIndex;
23 wakaba 1.2 for (var i = 0; i &lt; nodes.snapshotLength; i++) {
24 wakaba 1.1 var node = nodes.snapshotItem (i);
25     range.selectNode (node);
26 wakaba 1.2 while (node) {
27     var rangeString = range.toString ();
28     lastIndex = [rangeString.search (pattern_before)];
29     lastIndex[1] = RegExp.$1.length;
30     lastIndex[2] = rangeString.search (pattern_after);
31     lastIndex[3] = RegExp.$1.length;
32     var j;
33     if (lastIndex[0] != -1) {
34     if (lastIndex[2] != -1) {
35     j = lastIndex[2] > lastIndex[0] ? 0 : 1;
36     } else {
37     j = 0;
38     }
39     } else {
40     if (lastIndex[2] != -1) {
41     j = 1;
42     } else {
43     break;
44     }
45     }
46     if (j == 0) {
47     range.setStart (node, lastIndex[0]);
48     range.insertNode (wbr.cloneNode (false));
49     node = node.nextSibling.nextSibling.splitText (lastIndex[1]);
50     range.selectNode (node);
51     } else {
52     range.setStart (node, lastIndex[2] + lastIndex[3]);
53     range.insertNode (wbr.cloneNode (false));
54     node = node.nextSibling.nextSibling;
55     range.selectNode (node);
56     }
57 wakaba 1.1 }
58     }
59 wakaba 1.4 <![CDATA[
60     var fc = targetNode.firstChild;
61     if (fc && fc.nodeType == fc.TEXT_NODE &&
62     fc.data.length == 0) {
63     fc = fc.nextSibling;
64     }
65     if (fc && fc.nodeType == fc.ELEMENT_NODE &&
66     fc.localName && fc.localName == 'wbr' &&
67     fc.namespaceURI == 'http://www.w3.org/1999/xhtml') {
68     targetNode.removeChild (fc);
69     }
70 wakaba 1.5 fc = targetNode.lastChild;
71     if (fc && fc.nodeType == fc.TEXT_NODE &&
72     fc.data.length == 0) {
73     fc = fc.prevSibling;
74     }
75     if (fc && fc.nodeType == fc.ELEMENT_NODE &&
76     fc.localName && fc.localName == 'wbr' &&
77     fc.namespaceURI == 'http://www.w3.org/1999/xhtml') {
78     targetNode.removeChild (fc);
79     }
80 wakaba 1.4 ]]>
81 wakaba 1.1 range.detach ();
82     }
83 wakaba 1.2 }, false);
84 wakaba 1.1 </constructor>
85 wakaba 1.2 <field name="WrapPatternBefore">
86     <![CDATA[/([(<\[{]{1,10})/;]]>
87     </field>
88     <field name="WrapPatternAfter">
89     /([!"')\*\+,\-.\/:;=>?\]\^_`|}]{1,10})/;
90     </field>
91 wakaba 1.1 <method name="wrapWbrAdded">
92     <body>
93     <![CDATA[
94     const NS_WRAP = 'http://suika.fam.cx/www/style/text/wrap#';
95     if (this.getAttributeNS (NS_WRAP, 'wbrAdded') ||
96     this.getElementsByTagName ('wbr').length > 0) {
97     return true;
98     }
99     var parents = new Array (this.parentNode);
100     while (parents.length > 0) {
101     var node = parents.shift ();
102     if (node.nodeType == node.ELEMENT_NODE &&
103     node.getAttributeNS (NS_WRAP, 'wbrAdded')) {
104     return true;
105     } else if (node.parentNode) {
106     parents.push (node.parentNode);
107     }
108     }
109     return false;
110     ]]>
111     </body>
112     </method>
113 wakaba 1.2 </implementation>
114     </binding>
115     <binding id="wbr-uri" extends="#wbr-code">
116     <implementation>
117     <field name="WrapPatternBefore">
118     /([#(?\[]{1,10}|%..)/;
119     </field>
120     <field name="WrapPatternAfter">
121 wakaba 1.3 <![CDATA[/([!$&')\*\+,\-.\/:;=@\]_>]{1,10})/;]]>
122 wakaba 1.2 </field>
123     </implementation>
124     </binding>
125     <binding id="wbr-dotted" extends="#wbr-code">
126     <implementation>
127     <field name="WrapPatternBefore">
128     /([A-Z]+)/;
129     </field>
130     <field name="WrapPatternAfter">
131 wakaba 1.3 /([._@>-])/;
132 wakaba 1.2 </field>
133     </implementation>
134     </binding>
135     <binding id="wbr-qname" extends="#wbr-code">
136     <implementation>
137     <field name="WrapPatternBefore">
138 wakaba 1.5 /([A-Z][A-Z]+(?=[A-Z][a-z]|[^A-Za-z]|$)|[A-Z][a-z]+)/;
139 wakaba 1.2 </field>
140     <field name="WrapPatternAfter">
141 wakaba 1.4 /([._:->]+)(?!$)/;
142 wakaba 1.2 </field>
143 wakaba 1.1 </implementation>
144     </binding>
145     </bindings>
146     <!-- ***** BEGIN LICENSE BLOCK *****
147     - Version: MPL 1.1/GPL 2.0/LGPL 2.1
148     -
149     - The contents of this file are subject to the Mozilla Public License Version
150     - 1.1 (the "License"); you may not use this file except in compliance with
151     - the License. You may obtain a copy of the License at
152     - <http://www.mozilla.org/MPL/>
153     -
154     - Software distributed under the License is distributed on an "AS IS" basis,
155     - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
156     - for the specific language governing rights and limitations under the
157     - License.
158     -
159     - The Original Code is wrap.xbl code.
160     -
161     - The Initial Developer of the Original Code is Wakaba.
162     - Portions created by the Initial Developer are Copyright (C) 2005
163     - the Initial Developer. All Rights Reserved.
164     -
165     - Contributor(s):
166     - Wakaba <[email protected]>
167     -
168     - Alternatively, the contents of this file may be used under the terms of
169     - either the GNU General Public License Version 2 or later (the "GPL"), or
170     - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
171     - in which case the provisions of the GPL or the LGPL are applicable instead
172     - of those above. If you wish to allow use of your version of this file only
173     - under the terms of either the GPL or the LGPL, and not to allow others to
174     - use your version of this file under the terms of the MPL, indicate your
175     - decision by deleting the provisions above and replace them with the notice
176     - and other provisions required by the LGPL or the GPL. If you do not delete
177     - the provisions above, a recipient may use your version of this file under
178     - the terms of any one of the MPL, the GPL or the LGPL.
179     -
180     - ***** END LICENSE BLOCK ***** -->

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24