/[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.3 - (hide annotations) (download)
Sun Jul 10 08:43:43 2005 UTC (21 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.2: +2 -2 lines
> added

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24