1 |
w |
1.1 |
<?xml version="1.0"?>
|
2 |
|
|
<bindings xmlns="http://www.mozilla.org/xbl">
|
3 |
|
|
<binding id="link-hlink">
|
4 |
|
|
<implementation>
|
5 |
|
|
<method name="linkizeHTML" type="application/x-javascript">
|
6 |
|
|
<parameter name="doc" />
|
7 |
|
|
<body><![CDATA[
|
8 |
|
|
const XHTML1NS = 'http://www.w3.org/1999/xhtml';
|
9 |
|
|
const HLinkNS = 'http://www.w3.org/2002/06/hlink';
|
10 |
|
|
const XLinkNS = 'http://www.w3.org/1999/xlink';
|
11 |
|
|
const tempNS = 'urn:x-suika-fam-cx:markup:temporary';
|
12 |
|
|
|
13 |
|
|
var eLinks = doc.getElementsByTagNameNS (XHTML1NS, 'link');
|
14 |
|
|
for (var i = 0; i < eLinks.length; i++)
|
15 |
|
|
if (eLinks[i].getAttribute ('type').toLowerCase () == 'application/x-hlink+xml'
|
16 |
|
|
&& eLinks[i].getAttribute ('rel') == 'stylesheet' //.match (/stylesheet/i)
|
17 |
|
|
) linkizeByHTMLLinkElement (eLinks[i]);
|
18 |
|
|
|
19 |
|
|
function linkizeByHTMLLinkElement (eLink) {
|
20 |
|
|
var oHLink = eLink.ownerDocument.createElementNS (XHTML1NS, 'object');
|
21 |
|
|
oHLink.setAttributeNS (tempNS, 'HLinkStatus', 100);
|
22 |
|
|
oHLink.setAttribute ('data', eLink.getAttribute ('href'));
|
23 |
|
|
//oHLink.setAttribute ('type', 'application/xml');
|
24 |
|
|
oHLink.style.display = 'inline';
|
25 |
|
|
oHLink.style.width = 0;
|
26 |
|
|
oHLink.style.height = 0;
|
27 |
|
|
oHLink.addEventListener ('load', function () {
|
28 |
|
|
var hlink = oHLink.contentDocument.getElementsByTagNameNS
|
29 |
|
|
(HLinkNS, 'hlink');
|
30 |
|
|
for (var k = 0; k < hlink.length; k++) linkizeElement (hlink[k]);
|
31 |
|
|
}, false);
|
32 |
|
|
eLink.ownerDocument.documentElement.appendChild (oHLink);
|
33 |
|
|
}
|
34 |
|
|
|
35 |
|
|
function linkizeElement (e) {
|
36 |
|
|
var elementNS = e.getAttribute ('namespace');
|
37 |
|
|
var elementType = e.getAttribute ('element');
|
38 |
|
|
var linkAttr = [];
|
39 |
w |
1.2 |
var linkAttrList = new Array ('locator', 'effect', 'actuate', 'mediaType', 'replacement');
|
40 |
w |
1.1 |
for (var k = 0; k < linkAttrList.length; k++) {
|
41 |
|
|
linkAttr[linkAttrList[k]] = [];
|
42 |
|
|
linkAttr[linkAttrList[k]].value = e.getAttribute (linkAttrList[k]);
|
43 |
|
|
if (linkAttr[linkAttrList[k]].value
|
44 |
|
|
&& linkAttr[linkAttrList[k]].value.substr (0,1) == '@') {
|
45 |
|
|
linkAttr[linkAttrList[k]].attrName = linkAttr[linkAttrList[k]].value.substr (1);
|
46 |
|
|
linkAttr[linkAttrList[k]].value = undefined;
|
47 |
|
|
}
|
48 |
|
|
}
|
49 |
|
|
var linkElements = document.getElementsByTagNameNS (elementNS, elementType);
|
50 |
|
|
for (var i = 0; i < linkElements.length; i++) {
|
51 |
|
|
var elFlag = 1*linkElements[i].getAttributeNS (tempNS, 'HLinkStatus');
|
52 |
|
|
if (elFlag < 20) {
|
53 |
|
|
var myLinkAttr = [];
|
54 |
|
|
for (var j = 0; j < linkAttrList.length; j++) {
|
55 |
|
|
myLinkAttr[linkAttrList[j]] = linkAttr[linkAttrList[j]].value;
|
56 |
|
|
if (linkAttr[linkAttrList[j]].attrName
|
57 |
|
|
&& linkElements[i].hasAttribute
|
58 |
|
|
(linkAttr[linkAttrList[j]].attrName)) {
|
59 |
|
|
myLinkAttr[linkAttrList[j]] = linkElements[i].getAttribute
|
60 |
|
|
(linkAttr[linkAttrList[j]].attrName);
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
if (myLinkAttr.locator != undefined) {
|
64 |
|
|
if (myLinkAttr.effect == 'embed' && myLinkAttr.actuate == 'onLoad'
|
65 |
|
|
&& myLinkAttr.locator != '' && myLinkAttr.locator.substr (0,1) != '#') {
|
66 |
|
|
var oEl = linkElements[i].ownerDocument.createElementNS (XHTML1NS, 'object');
|
67 |
|
|
linkElements[i].setAttributeNS (tempNS, 'HLinkStatus', elFlag+1);
|
68 |
|
|
oEl.setAttributeNS (tempNS, 'HLinkStatus', 100);
|
69 |
|
|
oEl.setAttribute ('data', myLinkAttr.locator);
|
70 |
|
|
oEl.setAttribute ('type', myLinkAttr.mediaType);
|
71 |
|
|
while (linkElements[i].childNodes.length) {
|
72 |
|
|
oEl.appendChild (linkElements[i].firstChild);
|
73 |
|
|
//linkElements[i].removeChild (linkElements[i].firstChild);
|
74 |
|
|
}
|
75 |
|
|
linkElements[i].appendChild(oEl);
|
76 |
w |
1.2 |
} else if (myLinkAttr.effect == 'replace' && myLinkAttr.replacement
|
77 |
|
|
&& myLinkAttr.actuate == 'onRequest') {
|
78 |
|
|
var aEl = linkElements[i].ownerDocument.createElementNS (XHTML1NS, 'a');
|
79 |
|
|
linkElements[i].setAttributeNS (tempNS, 'HLinkStatus', elFlag+1);
|
80 |
|
|
aEl.setAttributeNS (tempNS, 'HLinkStatus', 100);
|
81 |
|
|
aEl.setAttribute ('href', myLinkAttr.locator);
|
82 |
|
|
if (myLinkAttr.mediaType)
|
83 |
|
|
aEl.setAttribute ('type', myLinkAttr.mediaType);
|
84 |
|
|
aEl.setAttribute ('target', myLinkAttr.replacement);
|
85 |
|
|
while (linkElements[i].childNodes.length) {
|
86 |
|
|
aEl.appendChild (linkElements[i].firstChild);
|
87 |
|
|
}
|
88 |
|
|
linkElements[i].appendChild(aEl);
|
89 |
w |
1.1 |
} else {
|
90 |
|
|
linkElements[i].setAttributeNS (tempNS, 'HLinkStatus', elFlag+1);
|
91 |
|
|
linkElements[i].setAttributeNS (XLinkNS, 'type', 'simple');
|
92 |
|
|
if (myLinkAttr.effect == 'submit' || myLinkAttr.effect == 'map')
|
93 |
|
|
myLinkAttr.effect = 'other';
|
94 |
|
|
linkElements[i].setAttributeNS (XLinkNS, 'show', myLinkAttr.effect);
|
95 |
|
|
if (myLinkAttr.actuate == 'onRequestSecondary')
|
96 |
|
|
myLinkAttr.actuate = 'other';
|
97 |
|
|
linkElements[i].setAttributeNS (XLinkNS, 'actuate', myLinkAttr.actuate);
|
98 |
|
|
if (!myLinkAttr.locator) myLinkAttr.locator = '#';
|
99 |
|
|
linkElements[i].setAttributeNS (XLinkNS, 'href', myLinkAttr.locator);
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
]]></body>
|
106 |
|
|
</method>
|
107 |
|
|
<constructor type="application/x-javascript"><![CDATA[
|
108 |
|
|
var myThis = this;
|
109 |
|
|
window.addEventListener ('load', function () {myThis.linkizeHTML(document)}, false);
|
110 |
|
|
]]></constructor>
|
111 |
|
|
</implementation>
|
112 |
|
|
</binding>
|
113 |
|
|
<binding id="style-hlink">
|
114 |
|
|
<implementation>
|
115 |
|
|
<method name="linkize" type="application/x-javascript">
|
116 |
|
|
<parameter name="e" />
|
117 |
|
|
<body>
|
118 |
|
|
<![CDATA[
|
119 |
|
|
const tempNS = 'urn:x-suika-fam-cx:markup:temporary';
|
120 |
|
|
const XLinkNS = 'http://www.w3.org/1999/xlink';
|
121 |
|
|
const XHTML1NS = 'http://www.w3.org/1999/xhtml';
|
122 |
|
|
var elementNS = e.getAttribute ('namespace');
|
123 |
|
|
var elementType = e.getAttribute ('element');
|
124 |
|
|
var linkAttr = [];
|
125 |
|
|
var linkAttrList = new Array ('locator', 'effect', 'actuate', 'mediaType');
|
126 |
|
|
for (var i = 0; i < linkAttrList.length; i++) {
|
127 |
|
|
linkAttr[linkAttrList[i]] = [];
|
128 |
|
|
linkAttr[linkAttrList[i]].value = e.getAttribute (linkAttrList[i]);
|
129 |
|
|
if (linkAttr[linkAttrList[i]].value
|
130 |
|
|
&& linkAttr[linkAttrList[i]].value.substr (0,1) == '@') {
|
131 |
|
|
linkAttr[linkAttrList[i]].attrName = linkAttr[linkAttrList[i]].value.substr (1);
|
132 |
|
|
linkAttr[linkAttrList[i]].value = undefined;
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
var linkElements = document.getElementsByTagNameNS (elementNS, elementType);
|
136 |
|
|
for (var i = 0; i < linkElements.length; i++) {
|
137 |
|
|
var elFlag = linkElements[i].getAttributeNS (tempNS, 'HLinkStatus');
|
138 |
|
|
if (elFlag < 20) {
|
139 |
|
|
var myLinkAttr = [];
|
140 |
|
|
for (var j = 0; j < linkAttrList.length; j++) {
|
141 |
|
|
myLinkAttr[linkAttrList[j]] = linkAttr[linkAttrList[j]].value;
|
142 |
|
|
if (linkAttr[linkAttrList[j]].attrName
|
143 |
|
|
&& linkElements[i].hasAttribute
|
144 |
|
|
(linkAttr[linkAttrList[j]].attrName)) {
|
145 |
|
|
myLinkAttr[linkAttrList[j]] = linkElements[i].getAttribute
|
146 |
|
|
(linkAttr[linkAttrList[j]].attrName);
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
if (myLinkAttr.locator != undefined) {
|
150 |
|
|
if (myLinkAttr.effect == 'embed' && myLinkAttr.actuate == 'onLoad'
|
151 |
|
|
&& myLinkAttr.locator != '' && myLinkAttr.locator.substr (0,1) != '#') {
|
152 |
|
|
var oEl = linkElements[i].ownerDocument.createElementNS (XHTML1NS, 'object');
|
153 |
|
|
oEl.setAttributeNS (tempNS, 'HLinkStatus', 100);
|
154 |
|
|
oEl.setAttribute ('data', myLinkAttr.locator);
|
155 |
|
|
oEl.setAttribute ('type', myLinkAttr.mediaType);
|
156 |
|
|
while (linkElements[i].childNodes.length) {
|
157 |
|
|
oEl.appendChild (linkElements[i].firstChild);
|
158 |
|
|
//linkElements[i].removeChild (linkElements[i].firstChild);
|
159 |
|
|
}
|
160 |
|
|
linkElements[i].appendChild(oEl);
|
161 |
|
|
} else {
|
162 |
|
|
linkElements[i].setAttributeNS (tempNS, 'HLinkStatus', elFlag+1);
|
163 |
|
|
linkElements[i].setAttributeNS (XLinkNS, 'type', 'simple');
|
164 |
|
|
if (myLinkAttr.effect == 'submit' || myLinkAttr.effect == 'map')
|
165 |
|
|
myLinkAttr.effect = 'other';
|
166 |
|
|
linkElements[i].setAttributeNS (XLinkNS, 'show', myLinkAttr.effect);
|
167 |
|
|
if (myLinkAttr.actuate == 'onRequestSecondary')
|
168 |
|
|
myLinkAttr.actuate = 'other';
|
169 |
|
|
linkElements[i].setAttributeNS (XLinkNS, 'actuate', myLinkAttr.actuate);
|
170 |
|
|
if (!myLinkAttr.locator) myLinkAttr.locator = '#';
|
171 |
|
|
linkElements[i].setAttributeNS (XLinkNS, 'href', myLinkAttr.locator);
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
]]>
|
177 |
|
|
</body>
|
178 |
|
|
</method>
|
179 |
|
|
<constructor type="application/x-javascript">
|
180 |
|
|
<![CDATA[
|
181 |
|
|
var myThis = this;
|
182 |
|
|
window.addEventListener ('load', function () {myThis.linkize(myThis)}, false);
|
183 |
|
|
]]>
|
184 |
|
|
</constructor>
|
185 |
|
|
</implementation>
|
186 |
|
|
</binding>
|
187 |
|
|
</bindings>
|
188 |
|
|
<!-- ***** BEGIN LICENSE BLOCK *****
|
189 |
|
|
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
190 |
|
|
-
|
191 |
|
|
- The contents of this file are subject to the Mozilla Public License Version
|
192 |
|
|
- 1.1 (the "License"); you may not use this file except in compliance with
|
193 |
|
|
- the License. You may obtain a copy of the License at
|
194 |
|
|
- <http://www.mozilla.org/MPL/>
|
195 |
|
|
-
|
196 |
|
|
- Software distributed under the License is distributed on an "AS IS" basis,
|
197 |
|
|
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
198 |
|
|
- for the specific language governing rights and limitations under the
|
199 |
|
|
- License.
|
200 |
|
|
-
|
201 |
w |
1.2 |
- The Original Code is "HLink Memo" code.
|
202 |
w |
1.1 |
-
|
203 |
|
|
- The Initial Developer of the Original Code is Wakaba.
|
204 |
|
|
- Portions created by the Initial Developer are Copyright (C) 2003
|
205 |
|
|
- the Initial Developer. All Rights Reserved.
|
206 |
|
|
-
|
207 |
|
|
- Contributor(s):
|
208 |
|
|
- Wakaba <w@suika.fam.cx>
|
209 |
|
|
-
|
210 |
|
|
- Alternatively, the contents of this file may be used under the terms of
|
211 |
|
|
- either the GNU General Public License Version 2 or later (the "GPL"), or
|
212 |
|
|
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
213 |
|
|
- in which case the provisions of the GPL or the LGPL are applicable instead
|
214 |
|
|
- of those above. If you wish to allow use of your version of this file only
|
215 |
|
|
- under the terms of either the GPL or the LGPL, and not to allow others to
|
216 |
|
|
- use your version of this file under the terms of the MPL, indicate your
|
217 |
|
|
- decision by deleting the provisions above and replace them with the notice
|
218 |
|
|
- and other provisions required by the LGPL or the GPL. If you do not delete
|
219 |
|
|
- the provisions above, a recipient may use your version of this file under
|
220 |
|
|
- the terms of any one of the MPL, the GPL or the LGPL.
|
221 |
|
|
-
|
222 |
|
|
- ***** END LICENSE BLOCK ***** -->
|